Browse Source

fitness stuff

Rolf Egert 6 years ago
parent
commit
a975b51024
2 changed files with 24 additions and 27 deletions
  1. BIN
      examplenetworks/testholonsplit.holon
  2. 24 27
      src/psoAlgoCode/SGFunctions.java

BIN
examplenetworks/testholonsplit.holon


+ 24 - 27
src/psoAlgoCode/SGFunctions.java

@@ -45,6 +45,11 @@ public class SGFunctions {
 
 	}
 
+	
+	/**
+	 * The general fitnessfunction that calculates the overall fitness for the current state
+	 * @return
+	 */
 	public double calcValuewithSliderState() {
 		implementState();
 		HelpFunctions.calculateStateForTimeStepPSO(model, control);
@@ -55,8 +60,6 @@ public class SGFunctions {
 		nw_fitness = networkFitness();
 		object_fitness = holonObjectFitness();
 		
-	//	System.out.println("NW_fitness: " + nw_fitness +" objectFitness: " + object_fitness);
-		
 		value = nw_fitness + object_fitness;
 	
 		
@@ -65,7 +68,7 @@ public class SGFunctions {
 	}
 
 	/**
-	 * Calculates a fitness value for the overall abstract network
+	 * Calculates a fitness value based on the difference between supply and production for each individual subnet/Holon in the network
 	 * @return
 	 */
 	private double networkFitness() {
@@ -77,21 +80,17 @@ public class SGFunctions {
 			for (HolonObject holonObject : tmp) {
 			//	System.out.println("Current state: " +holonObject.getState());
 				if(holonObject.getNumberOfActiveElements() == 0)
-					result += 5000;
+					result += 1000;
 			}
-		//	float sn_prod =0;
-			//float sn_cons =0;
-			
+		
 			float production = control.getSimManager().calculateEnergyWithoutFlexDevices("prod",
 					subNet, model.getCurIteration());
 			float consumption = control.getSimManager().calculateEnergyWithoutFlexDevices("cons",
 					subNet, model.getCurIteration());
-			//System.out.println("current production: " + production + " current consumption: " + consumption);
 			
 		result += Math.abs(production+consumption);	
 		}
 		
-		//result = (tmp_sn.size() - 1) * 100;
 		
 		
 		
@@ -103,7 +102,7 @@ public class SGFunctions {
 	 */
 	private double holonFitness() {
 		double result = 0.0;
-		
+		//Currently not in use
 		return result;
 	}
 	/**
@@ -116,18 +115,17 @@ public class SGFunctions {
 
 		for (AbstractCpsObject obj : objList) {
 			if (obj instanceof HolonObject) {
-				/*float supply = ((HolonObject) obj).getCurrentSupply();
-				float energy =((HolonObject) obj).getMaxActiveEnergy();
-				float ownProduction = ((HolonObject) obj).getSelfMadeEnergy(model.getCurIteration());
-				float maxEnergy = ((HolonObject) obj).getMaxPossibleConsumption();
-				int elem = ((HolonObject) obj).getNumberOfActiveElements();
-			*/
+				
+				//There is no supply percentage for powerplants
 				if(!(obj.getName().contains("Plant"))) {
 					float suppPercentage = ((HolonObject) obj).getSuppliedPercentage();
+					
+					//Holon Object supply state based penalty
 					result += holonObjectSupplyPenaltyFunction(suppPercentage);
 					//result += holonObjectStatePenalty((HolonObject)obj);
 					
 				}
+					//Deactivated Holon Element penalty.
 					result += inactiveHolonElementPenalty((HolonObject)obj);
 		
 			}
@@ -146,16 +144,13 @@ public class SGFunctions {
 		float result = 0;
 		if(supplyPercentage == 1)
 			return result;
-		/*else if(supplyPercentage < 1)
-			result = (float) Math.pow(1/supplyPercentage, 2);
-		else result = (float) Math.pow(supplyPercentage,2) ;*/  
 		else if(supplyPercentage < 1 && supplyPercentage >= 0.25) // undersupplied inbetween 25% and 100%
 			result = (float) Math.pow(1/supplyPercentage, 2);
 		else if (supplyPercentage < 0.25) //undersupplied with less than 25%
-			result = (float) Math.pow(1/supplyPercentage,3);
+			result = (float) Math.pow(1/supplyPercentage,2);
 		else if (supplyPercentage < 1.25)  //Oversupplied less than 25%
-			result = (float) Math.pow(supplyPercentage,2) ;
-		else result = (float) Math.pow(supplyPercentage,3); //Oversupplied more than 25%
+			result = (float) Math.pow(supplyPercentage,3) ;
+		else result = (float) Math.pow(supplyPercentage,4); //Oversupplied more than 25%
 		
 		
 		if(Float.isInfinite(result) || Float.isNaN(result))
@@ -164,6 +159,11 @@ public class SGFunctions {
 		return result;
 	}
 	
+	/**
+	 * Function that returns the fitness depending on the number of elements deactivated in a single holon object
+	 * @param obj Holon Object that contains Holon Elements
+	 * @return fitness value for that object depending on the number of deactivated holon elements
+	 */
 	private double inactiveHolonElementPenalty(HolonObject obj) {
 		float result = 0;
 		int activeElements = obj.getNumberOfActiveElements();
@@ -171,11 +171,8 @@ public class SGFunctions {
 		
 		if(activeElements == maxElements)
 			result =0;
-		else result = (float) Math.pow((maxElements -activeElements),2)*10
-				;
-		/*else if(activeElements == 0) {
-			result = 0;*/
-		//}
+		else result = (float) Math.pow((maxElements -activeElements),2)*100;
+		
 		
 	return result;