Browse Source

Adds Average Result to AlgorithmLog

Troppmann, Tom 3 years ago
parent
commit
ec8cc36b60

+ 10 - 8
src/algorithm/binary/AcoAlgorithm.java

@@ -9,6 +9,7 @@ import javax.swing.JFrame;
 import algorithm.objectiveFunction.ObjectiveFunctionByCarlos;
 import api.AlgorithmFrameworkFlex;
 import ui.model.DecoratedState;
+import utility.StringFormat;
 
 public class AcoAlgorithm extends AlgorithmFrameworkFlex{
 	
@@ -80,7 +81,7 @@ public class AcoAlgorithm extends AlgorithmFrameworkFlex{
 		best.fitness = evaluatePosition(best.position);
 		List<Double> runList = new ArrayList<Double>();
 		runList.add(best.fitness);
-		console.print("Start with: " + best.fitness);
+		console.print("Start with: " + StringFormat.doubleFixedPlaces(2, best.fitness));
 		if(moreInformation)console.println("");
 		int problemSize = best.position.size();
 		if(problemSize == 0) return best;
@@ -93,7 +94,7 @@ public class AcoAlgorithm extends AlgorithmFrameworkFlex{
 			if(moreInformation)console.println("Generation" + generation + " start with Fitness: " + best.fitness);
 			for(Individual i : population) {
 				i.fitness = evaluatePosition(i.position);
-				if(moreInformation)console.println("Fitness" + i.fitness);
+				if(moreInformation)console.println("Fitness" + StringFormat.doubleFixedPlaces(2, i.fitness));
 				if(i.fitness < best.fitness) best = i;	
 			}
 			runList.add(best.fitness);
@@ -108,7 +109,7 @@ public class AcoAlgorithm extends AlgorithmFrameworkFlex{
 		}
 		
 		
-		console.println("   End With:" + best.fitness);
+		console.println("   End With:" + StringFormat.doubleFixedPlaces(2, best.fitness));
 		this.runList = runList;
 		return best;
 		
@@ -193,11 +194,12 @@ public class AcoAlgorithm extends AlgorithmFrameworkFlex{
 //		private int maxGenerations = 200;
 //		private double p = 0.3;
 //		private double convergenceFactorReset = 0.99;
-		return "AcoAlgo"+ " Rounds:" + rounds 
-				+ " maxGenerations:" + maxGenerations 
-				+ " popsize:" +  popsize
-				+ " vaporization:" +  p
-				+ " convergenceFactorReset:" +  convergenceFactorReset;
+		return "AcoAlgo"
+				+ " Rounds: " + rounds 
+				+ " Iterations: " + maxGenerations 
+				+ " Individuals: " +  popsize
+				+ " vaporization: " +  StringFormat.doubleAllPlaces(p)
+				+ " convergenceFactorReset: " +  StringFormat.doubleAllPlaces(convergenceFactorReset);
 	}
 
 

+ 15 - 20
src/algorithm/binary/GaAlgorithm.java

@@ -19,10 +19,8 @@ public class GaAlgorithm extends AlgorithmFrameworkFlex{
 	private int popsize = 20;
 	private int maxGenerations = 100;
 	private double tournamentSize = 2.0;
-	private double fixedSwapProbability = 0.02;
-	private boolean useFixedSpawProbability = false;
-	private double fixedMutateProbability = 0.02;
-	private boolean useFixedMutateProbability = false;
+	private double swapProbability = 0.02;
+	private double mutateProbability = 0.02;
 	private boolean useIntervalMutation = false;
 	private double mutateProbabilityInterval = 0.01;
 	private double maxMutationPercent = 0.01;
@@ -34,10 +32,8 @@ public class GaAlgorithm extends AlgorithmFrameworkFlex{
 		addIntParameter("popsize", popsize, intValue -> popsize = intValue, () -> popsize, 1);
 		addIntParameter("maxGenerations", maxGenerations, intValue -> maxGenerations = intValue, () -> maxGenerations, 1);
 		addDoubleParameter("tournamentSize", tournamentSize, doubleValue -> tournamentSize = doubleValue, () -> tournamentSize, 1.0);
-		addDoubleParameter("fixedSwapProbability", fixedSwapProbability, doubleValue -> fixedSwapProbability = doubleValue, () -> fixedSwapProbability, 0.0, 1.0);
-		addBooleanParameter("useFixedSpawProbability", useFixedSpawProbability, booleanValue -> useFixedSpawProbability = booleanValue);
-		addDoubleParameter("fixedMutateProbability", fixedMutateProbability, doubleValue -> fixedMutateProbability = doubleValue, () -> fixedMutateProbability, 0.0, 1.0);
-		addBooleanParameter("useFixedMutateProbability", useFixedMutateProbability, booleanValue -> useFixedMutateProbability = booleanValue);
+		addDoubleParameter("SwapProbability", swapProbability, doubleValue -> swapProbability = doubleValue, () -> swapProbability, 0.0, 1.0);
+		addDoubleParameter("MutateProbability", mutateProbability, doubleValue -> mutateProbability = doubleValue, () -> mutateProbability, 0.0, 1.0);
 		addBooleanParameter("useIntervalMutation", useIntervalMutation, booleanValue -> useIntervalMutation = booleanValue);
 		addDoubleParameter("mutateProbabilityInterval", mutateProbabilityInterval, doubleValue -> mutateProbabilityInterval = doubleValue, () -> mutateProbabilityInterval, 0.0, 1.0);
 		addDoubleParameter("maxMutationPercent", maxMutationPercent, doubleValue -> maxMutationPercent = doubleValue, () -> maxMutationPercent, 0.0, 1.0);
@@ -109,11 +105,10 @@ public class GaAlgorithm extends AlgorithmFrameworkFlex{
 	 * 
 	 */
 	private void mutate(Individual child, int problemSize) {
-		double probability = (this.useFixedMutateProbability) ? this.fixedMutateProbability : 1.0/(double)problemSize;
 		ListIterator<Boolean> iter = child.position.listIterator();
 		while(iter.hasNext()) {
 			boolean boolValue = iter.next();
-			if(Random.nextDouble() <=  probability) {
+			if(Random.nextDouble() <=  this.mutateProbability) {
 				iter.set(!boolValue);
 			}
 		}
@@ -162,13 +157,12 @@ public class GaAlgorithm extends AlgorithmFrameworkFlex{
 	 * Probability is set to 1/Problemsize when not changed.
 	 */
 	private void crossover(Individual childA, Individual childB, int problemSize) {
-		double probability = (this.useFixedSpawProbability) ? this.fixedSwapProbability : 1.0/(double)problemSize;
 		ListIterator<Boolean> iterA = childA.position.listIterator();
 		ListIterator<Boolean> iterB = childB.position.listIterator();
 		for(int i= 0; i < problemSize; i++) {
 			boolean boolA = iterA.next();
 			boolean boolB = iterB.next();
-			if(Random.nextDouble() <=  probability ) {
+			if(Random.nextDouble() <=  this.swapProbability ) {
 				//Swap 
 				iterA.set(boolB);
 				iterB.set(boolA);
@@ -240,16 +234,17 @@ public class GaAlgorithm extends AlgorithmFrameworkFlex{
 //		private boolean useIntervalMutation = true;
 //		private double mutateProbabilityInterval = 0.01;
 //		private double maxMutationPercent = 0.01;
-		return "GaAlgo"+ " Rounds:" + rounds 
-				+ " maxGenerations:" + maxGenerations
-				+ " popsize:" + popsize
-				+ " tournamentSize:" +  tournamentSize
-				+ (useFixedSpawProbability? " fixedSwapProbability:" +  fixedSwapProbability : " swapProbability:" + "1.0f/problemsize")
+		return "GaAlgo"
+				+ " Rounds: " + rounds 
+				+ " Iterations: " + maxGenerations
+				+ " Individuals: " + popsize
+				+ " TournamentSize: " +  tournamentSize
+				+ " SwapProbability: " +  swapProbability
 				+ (useIntervalMutation? 
-						(" mutateProbabilityInterval:" +  mutateProbabilityInterval
-						+ " maxMutationPercent:" +  maxMutationPercent)
+						(" MutateProbabilityInterval: " +  mutateProbabilityInterval
+						+ " MaxMutationPercent: " +  maxMutationPercent)
 						: 
-						(useFixedMutateProbability? " fixedMutateProbability:" +  fixedMutateProbability:" mutateProbability:" + "1.0f/problemsize"));
+						(" MutateProbability: " +  mutateProbability));
 	}
 
 	@Override

+ 225 - 80
src/api/AlgorithmFrameworkFlex.java

@@ -61,6 +61,7 @@ import ui.model.DecoratedSwitch.SwitchState;
 import ui.model.DecoratedNetwork;
 import ui.view.Console;
 import utility.ImageImport;
+import utility.StringFormat;
 
 public abstract class AlgorithmFrameworkFlex implements AddOn{
 	//Algo
@@ -103,6 +104,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 	//printing
 	private Printer runPrinter = new Printer(plottFileName());
 	protected List<Double> runList = new LinkedList<Double>();
+	private RunAverage avg = new RunAverage();
 
 	//Parameter
 	@SuppressWarnings("rawtypes")
@@ -525,7 +527,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		control.guiDisable(true);
 		runPrinter.openStream();
 		runPrinter.println("");
-		runPrinter.println("Start:" + stringStatFromActualState());
+		runPrinter.println("Start:" + stringStatFromRunValues(getRunValuesFromActualState()));
 		runPrinter.closeStream();
 		if(this.useStepping) {
 			initParameterStepping();
@@ -595,13 +597,13 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		console.println("BitLength: " + access.size());
 		resetChain.removeLast();
 		runPrinter.openStream();
-		runPrinter.println("");
 		runPrinter.println(algoInformationToPrint());
 		console.println(algoInformationToPrint());
 		runPrinter.closeStream();
 		runProgressbar.start();
 		Individual runBest = new Individual();
 		runBest.fitness = Double.MAX_VALUE;
+		this.avg = new RunAverage();
 		for(int r = 0; r < rounds; r++)
 		{	
 			startTimer();	
@@ -610,9 +612,12 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 			long executionTime = printElapsedTime();
 			setState(roundBest.position);
 			runPrinter.openStream();
-			runPrinter.println(runList.stream().map(Object::toString).collect(Collectors.joining(", ")));
-			runPrinter.println(stringStatFromActualState());
-			runPrinter.println("Result: " + roundBest.fitness + " ExecutionTime:" + executionTime);
+			runPrinter.println(runList.stream().map(value -> StringFormat.doubleFixedPlaces(2,value)).collect(Collectors.joining(", ")));
+			RunValues val = getRunValuesFromActualState();
+			val.result = roundBest.fitness;
+			val.executionTime = executionTime;
+			avg.addRun(val);
+			runPrinter.println("Result: " + StringFormat.doubleFixedPlaces(2,roundBest.fitness) + " ExecutionTime:" + executionTime + " " + stringStatFromRunValues(val));
 			runPrinter.closeStream();
 			resetState();
 			if(roundBest.fitness < runBest.fitness) runBest = roundBest;
@@ -622,9 +627,17 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		this.extractPositionAndAccess();
 		setState(runBest.position);
 		updateVisual();
-		console.println("Start: " + startFitness);
-		console.println("AlgoResult: " + runBest.fitness);
+		console.println("Start: " + StringFormat.doubleFixedPlaces(2,startFitness));
+		console.println("AlgoResult: " + StringFormat.doubleFixedPlaces(2,runBest.fitness));
 		if(this.algoUseFlexes)calculateAndPrintFlexInfos(control.getSimManager().getActualDecorState());
+		runPrinter.openStream();
+		if(rounds > 1) {
+			RunValues avgRun = avg.getAverage();
+			
+			runPrinter.println("Average.Result: " + StringFormat.doubleFixedPlaces(2, avgRun.result) + " Average.ExecutionTime:" + avgRun.executionTime + " "  + this.stringStatFromRunValues(avg.getAverage(), "Average."));
+		}
+		runPrinter.println("");
+		runPrinter.closeStream();
 	}
 	
 	
@@ -817,65 +830,54 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 	
 	
 	
-	
-	private String stringStatFromActualState() {
+	private RunValues getRunValuesFromActualState() {
+		RunValues val = new RunValues();
 		if(dGroupNode != null)
 		{
 			//GetActualDecoratedGroupNode
 			dGroupNode = control.getSimManager().getActualVisualRepresentationalState().getCreatedGroupNodes().get(dGroupNode.getModel());
-			int amountOfSupplier = dGroupNode.getAmountOfSupplier();
-			int amountOfConsumer = dGroupNode.getAmountOfConsumer();
-			int amountOfPassiv = dGroupNode.getAmountOfPassiv();
-			int amountOfObjects = amountOfSupplier + amountOfConsumer + amountOfPassiv;
-			int unSuppliedConsumer = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED);
-			int partiallySuppliedConsumer = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED);
-			int suppliedConsumer = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED);
-			int overSuppliedConsumer = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED);
+			val.producer = dGroupNode.getAmountOfSupplier();
+			val.consumer = dGroupNode.getAmountOfConsumer();
+			val.passiv = dGroupNode.getAmountOfPassiv();
+			val.objects = val.producer + val.consumer + val.passiv;
+			val.unsupplied = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED);
+			val.partiallySupplied = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED);
+			val.supplied = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED);
+			val.overSupplied = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED);
 			
 			
-			int activeElements = dGroupNode.getAmountOfAktiveElemntsFromHolonObjects();
-			int elements = dGroupNode.getAmountOfElemntsFromHolonObjects();
-			return	"HolonObjects["
-				+	" Producer: " + amountOfSupplier  + "/" + amountOfObjects + "("+ (float)amountOfSupplier/(float)amountOfObjects * 100 + "%)"
-				+	" Unsupplied: " + unSuppliedConsumer  + "/" + amountOfObjects + "("+ (float)unSuppliedConsumer/(float)amountOfObjects * 100 + "%)"
-				+	" PartiallySupplied: " + partiallySuppliedConsumer  + "/" + amountOfObjects + "("+ (float)partiallySuppliedConsumer/(float)amountOfObjects * 100 + "%)"
-				+	" Supplied: " + suppliedConsumer  + "/" + amountOfObjects + "("+ (float)suppliedConsumer/(float)amountOfObjects * 100 + "%)"
-				+	" Passiv: " + overSuppliedConsumer  + "/" + amountOfObjects + "("+ (float)overSuppliedConsumer/(float)amountOfObjects * 100 + "%)"
-				+  "]" + "   HolonElemnts["
-				+	" Active: " + activeElements  + "/" + elements + "("+ (float)activeElements/(float)elements * 100 + "%)"
-				+ "]";
+			val.activeElements = dGroupNode.getAmountOfAktiveElemntsFromHolonObjects();
+			val.elements = dGroupNode.getAmountOfElemntsFromHolonObjects();
+			//TODO what should be printed happen when only groupNode are selected
 		}
 		DecoratedState state = control.getSimManager().getActualDecorState();
-		int amountOfSupplier = 0, amountOfConsumer = 0, amountOfPassiv = 0, unSuppliedConsumer = 0, partiallySuppliedConsumer = 0, suppliedConsumer = 0, overSuppliedConsumer = 0;
-		int activeElements = 0, amountOfelements = 0;
-		int totalConsumption = 0, totalProduction = 0;
 		for(DecoratedNetwork net : state.getNetworkList()) {
-			amountOfConsumer += net.getAmountOfConsumer();
-			amountOfSupplier += net.getAmountOfSupplier();
-			amountOfPassiv += net.getAmountOfPassiv();
-			unSuppliedConsumer += net.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED);
-			partiallySuppliedConsumer += net.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED);
-			suppliedConsumer += net.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED);
-			overSuppliedConsumer += net.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED);
-			amountOfelements += net.getAmountOfElements();
-			activeElements += net.getAmountOfActiveElements();
-			totalConsumption += net.getTotalConsumption();
-			totalProduction += net.getTotalProduction();
+			val.consumer += net.getAmountOfConsumer();
+			val.producer += net.getAmountOfSupplier();
+			val.passiv += net.getAmountOfPassiv();
+			val.unsupplied += net.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED);
+			val.partiallySupplied += net.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED);
+			val.supplied += net.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED);
+			val.overSupplied += net.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED);
+			val.elements += net.getAmountOfElements();
+			val.activeElements += net.getAmountOfActiveElements();
+			val.consumption += net.getTotalConsumption();
+			val.production += net.getTotalProduction();
 		}
-		int amountOfObjects = amountOfSupplier + amountOfConsumer + amountOfPassiv;
-		int difference = Math.abs(totalProduction - totalConsumption);
+		val.objects = val.consumer + val.producer + val.passiv;
+		val.difference= Math.abs(val.production - val.consumption);
 		
 		
 		
 		List<Flexibility> flexActiveList = control.getSimManager().getActualFlexManager().getAllFlexWrapperWithState(FlexState.IN_USE).stream().map(flex -> flex.getFlex()).collect(Collectors.toList());
-		int amountActiveEssential = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Essential).count();
-		int amountActiveHigh = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.High).count();
-		int amountActiveMedium = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Medium).count();
-		int amountActiveLow = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Low).count();
-		int amountActiveFlexibilities = amountActiveEssential + amountActiveHigh + amountActiveMedium + amountActiveLow;
-		int amountHolons = state.getNetworkList().size();
-		int amountSwitch = state.getDecoratedSwitches().size();
-		int amountActiveSwitch = (int)state.getDecoratedSwitches().stream().filter(dswitch -> (dswitch.getState() == SwitchState.Closed)).count();
+		val.essentialFlex = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Essential).count();
+		val.highFlex = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.High).count();
+		val.mediumFlex = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Medium).count();
+		val.lowFlex = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Low).count();
+		val.flexebilities = val.essentialFlex + val.highFlex + val.mediumFlex + val.lowFlex;
+		val.holon = state.getNetworkList().size();
+		val.switches = state.getDecoratedSwitches().size();
+		val.activeSwitches = (int)state.getDecoratedSwitches().stream().filter(dswitch -> (dswitch.getState() == SwitchState.Closed)).count();
 		
 		DoubleSummaryStatistics overStat = state.getNetworkList().stream().flatMap(net -> {
 			return net.getConsumerList().stream().filter(con -> con.getState() == HolonObjectState.OVER_SUPPLIED);
@@ -885,39 +887,64 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 			return net.getConsumerList().stream().filter(con -> con.getState() == HolonObjectState.PARTIALLY_SUPPLIED);
 		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
 		
+		val.partiallyMin = filterInf(partiallyStat.getMin());
+		val.partiallyMax = filterInf(partiallyStat.getMax());
+		val.partiallyAverage = filterInf(partiallyStat.getAverage());
+		
+		val.overMin = filterInf(overStat.getMin());
+		val.overMax = filterInf(overStat.getMax());
+		val.overAverage = filterInf(overStat.getAverage());
+
+		return val;
 		
-		return	"HolonObjects["
-			+	" Passiv: " + percentage(amountOfPassiv, amountOfObjects)
-			+	" Producer: " + percentage(amountOfSupplier, amountOfObjects)
-			+	" Consumer: " + percentage(amountOfConsumer, amountOfObjects)
-			+	" Unsupplied: " + percentage(unSuppliedConsumer, amountOfConsumer)
-			+	" PartiallySupplied: " + percentage(partiallySuppliedConsumer, amountOfConsumer)
-			+ " with SupplyPercentage(Min: " + partiallyStat.getMin() 
-			+ " Max: "+ partiallyStat.getMax() 
-			+ " Average: " +partiallyStat.getAverage() +  ")"
-			+	" Supplied: " + percentage(suppliedConsumer, amountOfConsumer)
-			+	" Over: " + percentage(overSuppliedConsumer, amountOfConsumer)
-			+ " with SupplyPercentage(Min: " + overStat.getMin() 
-			+ " Max: "+ overStat.getMax() 
-			+ " Average: " + overStat.getAverage() +  ")"
-			+  "]" + "   HolonElemnts["
-			+	" Active: " + percentage(activeElements, amountOfelements)
-			+ "]" + "Flexibilities_active[" 
-			+ " Essential: " + percentage(amountActiveEssential, amountActiveFlexibilities)
-			+ " High: " + percentage(amountActiveHigh, amountActiveFlexibilities)
-			+ " Medium: " + percentage(amountActiveMedium, amountActiveFlexibilities)
-			+ " Low: " + percentage(amountActiveLow, amountActiveFlexibilities)
-			+ "]" + " activeSwitches:" + percentage(amountActiveSwitch,amountSwitch)
-			+ " Holons: " + amountHolons
-			+ " totalConsumption: " + totalConsumption
-			+ " totalProduction: " + totalProduction
-			+ " difference: " + difference;
+	}
+	
+	
+	private double filterInf(double value) {
+		if(value == Double.NEGATIVE_INFINITY || value == Double.POSITIVE_INFINITY || value == Double.NaN) {
+			return 0;
+		}else {
+			return value;
+		}
+	}
+	
+	private String stringStatFromRunValues(RunValues val){
+		return stringStatFromRunValues(val , "");
+	}
+	
+	private String stringStatFromRunValues(RunValues val, String prefix) {
+		return	prefix +"Passiv: " + percentage(val.passiv, val.objects)
+			+ " " + prefix +"Producer: " + percentage(val.producer, val.objects)
+			+ " " +	prefix +"Consumer: " + percentage(val.consumer, val.objects)
+			+ " " +	prefix +"Unsupplied: " + percentage(val.unsupplied, val.objects)
+			+ " " +	prefix +"Partially: " + percentage(val.partiallySupplied, val.objects)
+			+ " " +	prefix +"Over: " + percentage(val.overSupplied, val.objects)
+			+ " " +	prefix +"Supplied: " + percentage(val.supplied, val.objects)
+			+ " " +	prefix +"Partially.SupplyPercentage.Min: " + StringFormat.doubleFixedPlaces(2, val.partiallyMin) 
+			+ " " +	prefix +"Partially.SupplyPercentage.Max: "+ StringFormat.doubleFixedPlaces(2, val.partiallyMax) 
+			+ " " +	prefix +"Partially.SupplyPercentage.Average: " + StringFormat.doubleFixedPlaces(2, val.partiallyAverage)
+			+ " " + prefix +"Over.SupplyPercentage.Min: " + StringFormat.doubleFixedPlaces(2, val.overMin) 
+			+ " " +	prefix +"Over.SupplyPercentage.Max: "+ StringFormat.doubleFixedPlaces(2, val.overMax) 
+			+ " " +	prefix +"Over.SupplyPercentage.Average: " + StringFormat.doubleFixedPlaces(2, val.overAverage)
+			+ " " +	prefix +"HolonElemnts.Active:" + percentage(val.activeElements, val.elements)
+			+ " " +	prefix +"Flexibilities.Essential: " + percentage(val.essentialFlex, val.flexebilities)
+			+ " " + prefix +"Flexibilities.High: " + percentage(val.highFlex, val.flexebilities)
+			+ " " +	prefix +"Flexibilities.Medium: " + percentage(val.mediumFlex, val.flexebilities)
+			+ " " +	prefix +"Flexibilities.Low: " + percentage(val.lowFlex, val.flexebilities)
+			+ " " +	prefix +"Switches.Active:" + percentage(val.activeSwitches,val.switches)
+			+ " " +	prefix +"Holons: " + val.holon
+			+ " " + prefix +"TotalConsumption: " + val.consumption
+			+ " " + prefix +"TotalProduction: " + val.production
+			+ " " + prefix +"Difference: " + val.difference;
 		
 	}
 	
 	
-	private String percentage(int actual, int max) {
-		return  actual  + "/" + max + "("+ (float)actual/(float)max * 100 + "%)";
+	private String percentage(double numerator , double denominator) {
+		if((int)denominator == 0) {
+			return "-%";
+		}
+		return  StringFormat.doubleTwoPlaces(numerator)   + "/" + StringFormat.doubleTwoPlaces(denominator) + " "+ StringFormat.doubleFixedPlaces(2,(float)numerator /(float)denominator * 100) + "%";
 	}
 	
 
@@ -1006,6 +1033,124 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		}
 	}
 		
+	
+	private class RunValues{
+		public double result;
+		public double executionTime;
+		
+		public double objects;
+		public double passiv;
+		public double consumer;
+		public double supplied;
+		public double producer;
+		public double unsupplied;
+		public double partiallySupplied;
+		public double overSupplied;
+
+		public double partiallyMin;
+		public double partiallyMax;
+		public double partiallyAverage;
+		public double overMin;
+		public double overMax;
+		public double overAverage;
+		
+		public double activeElements;
+		public double elements;
+		
+		public double essentialFlex;
+		public double highFlex;
+		public double mediumFlex;
+		public double lowFlex;
+		public double flexebilities;
+		
+		public double switches;
+		public double activeSwitches;
+		
+		public double holon;
+		public double consumption;
+		public double production;
+		public double difference;
+	}
+	
+	
+	private class RunAverage{
+		private int runCount = 0;
+		//Values
+		private RunValues sum = new RunValues();
+		
+		public void addRun(RunValues val) {
+			sum.result += val.result;
+			sum.executionTime += val.executionTime;
+			sum.passiv += val.passiv;
+			sum.consumer += val.consumer;
+			sum.producer += val.producer;
+			sum.unsupplied += val.unsupplied;
+			sum.partiallySupplied += val.partiallySupplied;
+			sum.overSupplied += val.overSupplied;
+			sum.activeElements += val.activeElements;
+			sum.elements += val.elements;
+			sum.essentialFlex += val.essentialFlex;
+			sum.highFlex += val.highFlex;
+			sum.mediumFlex += val.mediumFlex;
+			sum.lowFlex += val.lowFlex;
+			sum.flexebilities += val.flexebilities;
+			sum.holon += val.holon;
+			sum.switches += val.switches;
+			sum.activeSwitches += val.activeSwitches;
+			sum.consumption += val.consumption;
+			sum.production += val.production;
+			sum.difference += val.difference;
+			sum.objects += val.objects;
+			sum.supplied += val.supplied;
+			sum.partiallyMin += val.partiallyMin;
+			sum.partiallyMax += val.partiallyMax;
+			sum.partiallyAverage += val.partiallyAverage;
+			sum.overMin += val.overMin;
+			sum.overMax += val.overMax;
+			sum.overAverage += val.overAverage;
+			
+			runCount++;
+		}
+		public RunValues getAverage() {
+			RunValues avg = new RunValues();
+			if(runCount == 0) {
+				return avg;
+			}
+			avg.result = sum.result / runCount;
+			avg.executionTime = sum.executionTime / runCount;
+			avg.passiv = sum.passiv / runCount;
+			avg.consumer = sum.consumer / runCount;
+			avg.producer = sum.producer / runCount;
+			avg.unsupplied = sum.unsupplied / runCount;
+			avg.partiallySupplied = sum.partiallySupplied / runCount;
+			avg.overSupplied = sum.overSupplied / runCount;
+			avg.activeElements = sum.activeElements / runCount;
+			avg.elements = sum.elements / runCount;
+			avg.essentialFlex = sum.essentialFlex / runCount;
+			avg.highFlex = sum.highFlex / runCount;
+			avg.mediumFlex = sum.mediumFlex / runCount;
+			avg.lowFlex = sum.lowFlex / runCount;
+			avg.flexebilities = sum.flexebilities / runCount;
+			avg.holon = sum.holon / runCount;
+			avg.switches = sum.switches / runCount;
+			avg.activeSwitches = sum.activeSwitches / runCount;
+			avg.consumption = sum.consumption / runCount;
+			avg.production = sum.production / runCount;
+			avg.difference = sum.difference / runCount;
+			avg.objects = sum.objects / runCount;
+			avg.supplied = sum.supplied / runCount;
+			avg.supplied = sum.supplied / runCount;	
+			avg.partiallyMin = sum.partiallyMin / runCount;
+			avg.partiallyMax = sum.partiallyMax / runCount;
+			avg.partiallyAverage = sum.partiallyAverage / runCount;
+			avg.overMin = sum.overMin / runCount;
+			avg.overMax = sum.overMax / runCount;
+			avg.overAverage = sum.overAverage / runCount;		
+			return avg;
+		}
+	}
+	
+	
 	private enum AccessType {None, HolonElement, Switch, Flexibility, KillSwitch};
 	/**
 	 * A Wrapper Class for Access HolonElement and HolonSwitch in one Element and not have to split the List.

+ 35 - 0
src/utility/StringFormat.java

@@ -0,0 +1,35 @@
+package utility;
+
+import java.math.RoundingMode;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.Locale;
+
+public class StringFormat {
+	
+	private static DecimalFormat formatter;
+	private static DecimalFormat twoFormatter;
+	
+	static {
+		NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
+		formatter = (DecimalFormat) nf;
+		formatter.applyPattern("#.###########");
+		formatter.setRoundingMode(RoundingMode.UP);
+		
+		twoFormatter = (DecimalFormat) nf;
+		twoFormatter.applyPattern("#.##");
+		twoFormatter.setRoundingMode(RoundingMode.UP);
+	}
+	public static String doubleFixedPlaces(int places, double value) {
+		return String.format(Locale.US, "%." +  places  + "f", value);
+	}
+	
+	public static String doubleTwoPlaces(double value) {
+		return twoFormatter.format(value);
+	}
+	
+	
+	public static String doubleAllPlaces(double value) {
+		return formatter.format(value);
+	}
+}