Browse Source

Adds new FlexPenalty.

Tom 5 years ago
parent
commit
6cba410a80
2 changed files with 31 additions and 2 deletions
  1. 1 0
      src/api/AlgorithmFrameworkFlex.java
  2. 30 2
      src/exampleAlgorithms/Evaluation.java

+ 1 - 0
src/api/AlgorithmFrameworkFlex.java

@@ -606,6 +606,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		if(!resetChain.isEmpty()) {
 			console.println("Resetting..");
 			setState(resetChain.getFirst());
+			control.getSimManager().resetFlexManagerForTimeStep(control.getModel().getCurIteration());
 			resetChain.clear();
 			control.resetSimulation();
 			control.setCurIteration(0);

+ 30 - 2
src/exampleAlgorithms/Evaluation.java

@@ -1,5 +1,6 @@
 package exampleAlgorithms;
 
+import classes.HolonElement.Priority;
 import classes.HolonObject;
 import ui.model.DecoratedNetwork;
 import ui.model.DecoratedState;
@@ -20,6 +21,9 @@ public class Evaluation {
 		double nw_fitness =0.0;
 		double object_fitness = 0.0;
 		double flexFitness = 0.0;
+		
+		double sigma = 6;
+		
 		// calculate network_fitness
 		for(DecoratedNetwork net : state.getNetworkList()) {
 			float production = net.getSupplierList().stream().map(supplier -> supplier.getEnergyToSupplyNetwork()).reduce(0.0f, (a, b) -> a + b);
@@ -38,9 +42,12 @@ public class Evaluation {
 			object_fitness += net.getSupplierList().stream().map(sup -> inactiveHolonElementPenalty(sup.getModel())).reduce(0.0, (a, b) -> (a + b));
 			object_fitness += net.getConsumerSelfSuppliedList().stream().map(con -> inactiveHolonElementPenalty(con.getModel())).reduce(0.0, (a, b) -> (a + b));
 		}
-		// calculate flexibility fitness
-		for(FlexWrapper flexWrapper :state.getFlexManager().getAllFlexWrapperWithState(FlexState.IN_USE)) {
+		// calculate flexibility fitness old cost flex
+		/*for(FlexWrapper flexWrapper :state.getFlexManager().getAllFlexWrapperWithState(FlexState.IN_USE)) {
 			flexFitness += flexWrapper.getFlex().cost / (double)flexWrapper.getFlex().getDuration();
+		}*/
+		for(FlexWrapper flexWrapper :state.getFlexManager().getAllFlexWrapperWithState(FlexState.IN_USE)) {
+			flexFitness += Math.pow(sigma, (double)priorityToInt(flexWrapper.getFlex().getElement().getPriority())) - 1;
 		}
 		
 		fitness = nw_fitness + object_fitness + flexFitness;
@@ -48,6 +55,27 @@ public class Evaluation {
 	}
 
 	
+	
+	
+	
+	private static int priorityToInt(Priority priority) {
+		switch(priority) {
+		case Essential:
+			return 3;
+		case High:
+			return 2;
+		case Medium:
+			return 1;
+		case Low:
+		default:		
+			return 0;
+		}
+	}
+
+
+
+
+
 	/**
 	 * Untouched:
 	 * Function that returns the fitness depending on the number of elements deactivated in a single holon object