Troppmann, Tom 3 years ago
parent
commit
0c381b34cf

+ 1 - 1
src/algorithm/topologie/AcoAlgorithm.java

@@ -96,7 +96,7 @@ public class AcoAlgorithm extends TopologieAlgorithmFramework {
 
 	@Override
 	protected String plottFileName() {
-		return "ga-topologie.txt";
+		return "aco-topologie.txt";
 	}
 	/**
 	 * tj1 is the pheromon level in the j position

+ 8 - 26
src/api/AlgorithmFrameworkFlex.java

@@ -450,30 +450,9 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 	
 	protected double evaluatePosition(List<Boolean> positionToEvaluate) {
 		runProgressbar.step();
-//		long startTime = System.currentTimeMillis(), endTime;
-		control.getSimManager().resetFlexManagerForTimeStep(control.getModel().getCurIteration()); // execution time critical
-//		endTime = System.currentTimeMillis();
-//		console.print(" a:" + (endTime - startTime)); 
-//		startTime = endTime;
 		setState(positionToEvaluate); // execution time critical
-//		endTime = System.currentTimeMillis();
-//		console.print(" b:" + (endTime - startTime)); 
-//		startTime = endTime;
-		control.calculateStateOnlyForCurrentTimeStep();
-//		endTime = System.currentTimeMillis();
-//		console.print(" c:" + (endTime - startTime)); 
-//		startTime = endTime;
 		DecoratedState actualstate = control.getSimManager().getActualDecorState();
-//		endTime = System.currentTimeMillis();
-//		console.print(" d:" + (endTime - startTime)); 
-//		startTime = endTime;
 		double result = evaluateState(actualstate);
-//		endTime = System.currentTimeMillis();
-//		console.print(" e:" + (endTime - startTime)); 
-//		startTime = endTime;
-//		long inUse = actualstate.getFlexManager().getAllFlexWrapperWithState(FlexState.IN_USE).size();
-//		long all = actualstate.getFlexManager().getAllFlexWrapper().size();
-//		console.println(" [" + inUse + "/" + all + "]");
 		return result;
 	}
 
@@ -561,11 +540,11 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		runBest.fitness = Double.MAX_VALUE;
 		for(int r = 0; r < rounds; r++)
 		{	
-			
 			startTimer();	
 			Individual  roundBest = executeAlgo();
 			if(cancel)return;
 			long executionTime = printElapsedTime();
+			setState(roundBest.position);
 			runPrinter.openStream();
 			runPrinter.println(runList.stream().map(Object::toString).collect(Collectors.joining(", ")));
 			runPrinter.println(stringStatFromActualState());
@@ -667,7 +646,6 @@ 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);
@@ -688,7 +666,6 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 	 * Sets the Model back to its original State before the LAST run.
 	 */
 	private void resetState() {
-		control.getSimManager().resetFlexManagerForTimeStep(control.getModel().getCurIteration());
 		setState(resetChain.getLast());
 	}
 
@@ -698,11 +675,12 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 	 * @param position
 	 */
 	private void setState(List<Boolean> position) {
+		control.getSimManager().resetFlexManagerForTimeStep(control.getModel().getCurIteration());
 		int i = 0;
 		for(Boolean bool: position) {
 			access.get(i++).setState(bool);
 		}
-		
+		control.calculateStateOnlyForCurrentTimeStep();
 }
 
 
@@ -836,7 +814,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 			+	" Producer: " + percentage(amountOfSupplier, amountOfObjects)
 			+	" Consumer: " + percentage(amountOfConsumer, amountOfObjects)
 			+	" Unsupplied: " + percentage(unSuppliedConsumer, amountOfConsumer)
-			+	" PartiallySupplied: " + percentage(partiallySuppliedConsumer, amountOfObjects)
+			+	" PartiallySupplied: " + percentage(partiallySuppliedConsumer, amountOfConsumer)
 			+ " with SupplyPercentage(Min: " + partiallyStat.getMin() 
 			+ " Max: "+ partiallyStat.getMax() 
 			+ " Average: " +partiallyStat.getAverage() +  ")"
@@ -1076,6 +1054,10 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 			position = c.position.stream().collect(Collectors.toList());
 			fitness = c.fitness;
 		}
+		
+		String positionToString() {
+			return position.stream().map(bool -> (bool?"1":"0")).collect(Collectors.joining());
+		}
 	}
 	
 	protected class ParameterStepping<T>{

+ 7 - 11
src/api/TopologieAlgorithmFramework.java

@@ -496,20 +496,12 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 	
 	
 	protected double evaluatePosition(List<Integer> positionToEvaluate) {
-		control.getSimManager().resetFlexManagerForTimeStep(control.getModel().getCurIteration());
-		
 		setState(positionToEvaluate); // execution time critical
-
 		return evaluateNetwork();
 	}
 
 	private double evaluateNetwork() {
 		runProgressbar.step();
-		for(HolonSwitch hSwitch: switchList) {
-			hSwitch.setManualMode(true);
-			hSwitch.setManualState(false);
-		}
-		control.calculateStateOnlyForCurrentTimeStep();
 		DecoratedState actualstate = control.getSimManager().getActualDecorState();
 		return evaluateState(actualstate, calculateAmountOfAddedSwitches(), addedCableMeter(), false);
 	}
@@ -610,8 +602,8 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 		runPrinter.openStream();
 		runPrinter.println("");
 		runPrinter.println(algoInformationToPrint());
-		console.println(algoInformationToPrint());
 		runPrinter.closeStream();
+		console.println(algoInformationToPrint());
 		runProgressbar.start();
 		Individual runBest = new Individual();
 		runBest.fitness = Double.MAX_VALUE;
@@ -623,6 +615,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 			Individual  roundBest = executeAlgo();
 			if(cancel)return;
 			long executionTime = printElapsedTime();
+			setState(roundBest.position);
 			runPrinter.openStream();
 			runPrinter.println(runList.stream().map(Object::toString).collect(Collectors.joining(", ")));
 			runPrinter.println(stringStatFromActualState());
@@ -667,7 +660,6 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 		if(!resetChain.isEmpty()) {
 			console.println("Resetting..");
 			setState(resetChain.getFirst());
-			control.getSimManager().resetFlexManagerForTimeStep(control.getModel().getCurIteration());
 			resetChain.clear();
 			control.resetSimulation();
 			control.setCurIteration(0);
@@ -688,7 +680,6 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 	 * Sets the Model back to its original State before the LAST run.
 	 */
 	private void resetState() {
-		control.getSimManager().resetFlexManagerForTimeStep(control.getModel().getCurIteration());
 		if(!resetChain.isEmpty()) {
 			setState(resetChain.removeLast());			
 		}
@@ -716,6 +707,11 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 		for(int i = 3 * amountOfNewCables + amountOfExistingCables; i < position.size(); i++) {
 			accessWildcards.get(count++).setState(position.get(i));
 		}
+		for(HolonSwitch hSwitch: switchList) {
+			hSwitch.setManualMode(true);
+			hSwitch.setManualState(false);
+		}
+		control.calculateStateOnlyForCurrentTimeStep();
 }