Browse Source

ResetState fix

Tom Troppmann 3 years ago
parent
commit
50cc0fc78b

+ 2 - 2
src/algorithm/objectiveFunction/TopologieObjectiveFunction.java

@@ -12,7 +12,7 @@ public class TopologieObjectiveFunction {
 	//Parameters
 	
 	//weight for f_g(H)
-	static double w_eb = .5, w_holon=.1, w_selection = .1, w_grid = .4;
+	static double w_eb = .5, w_holon=.1, w_selection = .1, w_grid = .3;
 	
 	
 	//--> f_eb parameter
@@ -63,7 +63,7 @@ public class TopologieObjectiveFunction {
 	 * Here should all invariants be placed to be checked on initialization.
 	 */
 	private static void checkParameter() {
-		if(!(Math.abs(w_eb + w_holon + w_selection + w_selection + w_grid - 1) < 0.001)) {
+		if(!(Math.abs(w_eb + w_holon + w_selection + w_grid - 1) < 0.001)) {
 			System.err.println("ParameterError in ObjectiveFunction: Sum of all weights should be 1");
 		}
 	}

+ 51 - 16
src/api/TopologieAlgorithmFramework.java

@@ -474,21 +474,38 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 //			sum += evaluateNetwork() / times;
 //		}
 		runProgressbar.step();
+		//random solution
+//		double sum = 0;
+//		double step = 0.1;
+//		int steppsDone = 0;
+//		for(double actual = 0; actual <= 1 ; actual += step) {
+//			for(HolonSwitch hSwitch: switchList) {
+//				hSwitch.setManualMode(true);
+//				hSwitch.setManualState(Random.nextDouble() < actual);
+//			}
+//			control.calculateStateOnlyForCurrentTimeStep();
+//			DecoratedState actualstate = control.getSimManager().getActualDecorState();
+//			sum += evaluateState(actualstate);
+//			steppsDone++;
+//		}
+		//return sum /(double) steppsDone;
+		
 		double sum = 0;
-		double step = 0.1;
-		int steppsDone = 0;
-		for(double actual = 0; actual <= 1 ; actual += step) {
-			for(HolonSwitch hSwitch: switchList) {
-				hSwitch.setManualMode(true);
-				hSwitch.setManualState(Random.nextDouble() < actual);
-			}
-			control.calculateStateOnlyForCurrentTimeStep();
-			DecoratedState actualstate = control.getSimManager().getActualDecorState();
-			sum += evaluateState(actualstate);
-			steppsDone++;
+		for(HolonSwitch hSwitch: switchList) {
+			hSwitch.setManualMode(true);
+			hSwitch.setManualState(true);
 		}
-		
-		return sum /(double) steppsDone;
+		control.calculateStateOnlyForCurrentTimeStep();
+		DecoratedState actualstate = control.getSimManager().getActualDecorState();
+		sum += evaluateState(actualstate);
+		for(HolonSwitch hSwitch: switchList) {
+			hSwitch.setManualMode(true);
+			hSwitch.setManualState(false);
+		}
+		control.calculateStateOnlyForCurrentTimeStep();
+		actualstate = control.getSimManager().getActualDecorState();
+		sum += evaluateState(actualstate);
+		return sum / 2.0;
 	}
 	
 	
@@ -576,7 +593,8 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 		for(int r = 0; r < rounds; r++)
 		{	
 			
-			startTimer();	
+			resetState();
+			startTimer();
 			Individual  roundBest = executeAlgo();
 			if(cancel)return;
 			long executionTime = printElapsedTime();
@@ -585,7 +603,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 			runPrinter.println(stringStatFromActualState());
 			runPrinter.println("Result: " + roundBest.fitness + " ExecutionTime:" + executionTime);
 			runPrinter.closeStream();
-			//resetState();
+			
 			if(roundBest.fitness < runBest.fitness) runBest = roundBest;
 		}
 		
@@ -641,7 +659,24 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 	 */
 	private void resetState() {
 		control.getSimManager().resetFlexManagerForTimeStep(control.getModel().getCurIteration());
-		setState(resetChain.getLast());
+		if(!resetChain.isEmpty()) {
+			setState(resetChain.removeLast());			
+		}
+		//-->reset
+				accessWildcards.clear();
+				this.countForAccessMap = 0;
+				amountOfExistingCables = 0;
+				accessIntToObject.clear();
+				accessObjectToInt.clear();
+				cableSet.clear();
+				cableList.clear();
+				accessGroupNode.clear();
+				accessIntegerToWildcard.clear();
+				addedIndexCable.clear();
+				switchList.clear();
+				accessSwitchGroupNode.clear();
+				edgeList.clear();
+		//<---
 	}