Browse Source

Big Changes in Algo and fitnessFunction

Tom Troppmann 4 years ago
parent
commit
b0fdafbf8a

+ 64 - 7
src/api/AlgorithmFrameworkFlex.java

@@ -18,7 +18,6 @@ import java.util.List;
 import java.util.Locale;
 import java.util.function.BiFunction;
 import java.util.function.Consumer;
-import java.util.function.DoubleConsumer;
 import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
@@ -44,6 +43,7 @@ import classes.Flexibility;
 import classes.HolonElement;
 import classes.HolonObject;
 import classes.HolonSwitch;
+import classes.HolonElement.Priority;
 import ui.controller.Control;
 import ui.controller.FlexManager.FlexState;
 import ui.controller.FlexManager.FlexWrapper;
@@ -51,11 +51,13 @@ import ui.model.DecoratedGroupNode;
 import ui.model.DecoratedState;
 import ui.model.Model;
 import ui.model.DecoratedHolonObject.HolonObjectState;
+import ui.model.DecoratedSwitch.SwitchState;
+import ui.model.DecoratedNetwork;
 import ui.view.Console;
 
 public abstract class AlgorithmFrameworkFlex implements AddOn{
 	//Algo
-	protected int rounds = 3;
+	protected int rounds = 1;
 	
 	
 	
@@ -72,7 +74,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 	//access
 	private ArrayList<AccessWrapper> access;
 	LinkedList<List<Boolean>> resetChain = new LinkedList<List<Boolean>>();
-	boolean algoUseElements = true, algoUseSwitches = true, algoUseFlexes = true;
+	boolean algoUseElements = false, algoUseSwitches = true, algoUseFlexes = true;
 	
 	//time
 	private long startTime;
@@ -478,6 +480,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		cancel = false;
 		control.guiDisable(true);
 		runPrinter.openStream();
+		runPrinter.println("");
 		runPrinter.println("Start:" + stringStatFromActualState());
 		if(this.useStepping) {
 			initParameterStepping();
@@ -542,7 +545,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		double startFitness = evaluatePosition(extractPositionAndAccess());
 		console.println("BitLength: " + access.size());
 		resetChain.removeLast();
-		
+		runPrinter.println("");
 		runPrinter.println(algoInformationToPrint());
 		runProgressbar.start();
 		Individual runBest = new Individual();
@@ -555,7 +558,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 			long executionTime = printElapsedTime();
 			runPrinter.println(runList.stream().map(Object::toString).collect(Collectors.joining(", ")));
 			runPrinter.println(stringStatFromActualState());
-			runPrinter.println("ExecutionTime:" + executionTime);
+			runPrinter.println("Result: " + roundBest.fitness + " ExecutionTime:" + executionTime);
 			if(cancel)return;
 			resetState();
 			if(roundBest.fitness < runBest.fitness) runBest = roundBest;
@@ -773,12 +776,66 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 				+	" Active: " + activeElements  + "/" + elements + "("+ (float)activeElements/(float)elements * 100 + "%)"
 				+ "]";
 		}
+		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();
+		}
+		int amountOfObjects = amountOfSupplier + amountOfConsumer + amountOfPassiv;
+		int difference = Math.abs(totalProduction - totalConsumption);
+		
+		
+		
+		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();
+		
+		
+		return	"HolonObjects["
+			+	" Passiv: " + percentage(amountOfPassiv, amountOfObjects)
+			+	" Producer: " + percentage(amountOfSupplier, amountOfObjects)
+			+	" Consumer: " + percentage(amountOfConsumer, amountOfObjects)
+			+	" Unsupplied: " + percentage(unSuppliedConsumer, amountOfConsumer)
+			+	" PartiallySupplied: " + percentage(partiallySuppliedConsumer, amountOfObjects)
+			+	" Supplied: " + percentage(suppliedConsumer, amountOfConsumer)
+			+	" Over: " + percentage(overSuppliedConsumer, amountOfConsumer)
+			+  "]" + "   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;
 		
-		return "[No GroupNode Use == No detailed Info]";
 	}
 	
 	
-	
+	private String percentage(int actual, int max) {
+		return  actual  + "/" + max + "("+ (float)actual/(float)max * 100 + "%)";
+	}
 	
 
 	

+ 6 - 0
src/classes/Flexibility.java

@@ -97,6 +97,12 @@ public class Flexibility {
 	
 	
 	
+	public int getSpeed() {
+		return speed;
+	}
+	public void setSpeed(int speed) {
+		this.speed = speed;
+	}
 	@Override
 	public String toString() {
 		return "Flexibility: " + name + " from [HolonElement: " + element.getEleName() + " ID:" + element.getId()+"]";

+ 1 - 1
src/exampleAlgorithms/AcoAlgorithm.java

@@ -52,7 +52,7 @@ public class AcoAlgorithm extends AlgorithmFrameworkFlex{
 	
 	@Override
 	protected double evaluateState(DecoratedState actualstate) {
-		return Evaluation.getFitnessValueForState(actualstate);
+		return ObjectiveFunctionByCarlos.getFitnessValueForState(actualstate);
 	}
 
 

+ 1 - 0
src/exampleAlgorithms/Evaluation.java

@@ -120,6 +120,7 @@ public class Evaluation {
 		else {
 			result = Math.pow(6,(Math.abs((100 - (supplyPercentage*100)))/50 + 2)) - Math.pow(6, 2);
 		}
+		if(result > 1000)System.out.println("supplyPenalty(" + supplyPercentage + ")=" + result);
 		
 		return result;
 	}

+ 1 - 1
src/exampleAlgorithms/GaAlgorithm.java

@@ -55,7 +55,7 @@ public class GaAlgorithm extends AlgorithmFrameworkFlex{
 	
 	@Override
 	protected double evaluateState(DecoratedState actualstate) {
-		return Evaluation.getFitnessValueForState(actualstate);
+		return ObjectiveFunctionByCarlos.getFitnessValueForState(actualstate);
 	}
 
 

+ 13 - 5
src/exampleAlgorithms/InformationPanel.java

@@ -9,6 +9,7 @@ import java.awt.Insets;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
+import java.util.Random;
 import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
@@ -82,7 +83,7 @@ public class InformationPanel implements AddOn {
 
 
 
-
+	Random r = new Random();
 
 
 
@@ -192,7 +193,7 @@ public class InformationPanel implements AddOn {
 	void updateEntrys() {
 		calculateValues();
 		entryList.forEach(entry -> entry.update());
-		printInfos();
+		//printInfos();
 	}
 	
 	
@@ -243,7 +244,7 @@ public class InformationPanel implements AddOn {
 		amountActiveLow = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Low).count();
 		this.amountActiveFlexibilities = amountActiveEssential + amountActiveHigh + amountActiveMedium + amountActiveLow;
 		VisualRepresentationalState visualState =control.getSimManager().getActualVisualRepresentationalState();
-		amountGroupNodes = visualState.getAmountOfHolons();
+		amountGroupNodes = visualState.getAmountfOfGroupNodes();
 		
 		
 		amountHolons = dState.getNetworkList().size();
@@ -296,11 +297,18 @@ public class InformationPanel implements AddOn {
 			
 			
 		}
-		
+		dState.getFlexManager().getAllFlexWrapper().stream().map(flexWrapper -> flexWrapper.getFlex()).forEach(flex -> {
+			flex.setCooldown(getRandomNumberInRange(0, 60*60*24));
+			flex.setDuration(getRandomNumberInRange(0, 60*60));
+			flex.setSpeed(getRandomNumberInRange(0, 120));
+		});
 		
 	}
 	
-	
+	private int getRandomNumberInRange(int min, int max) {
+		
+		return r.nextInt((max - min) + 1) + min;
+	}
 	
 	
 

+ 127 - 57
src/exampleAlgorithms/ObjectiveFunctionByCarlos.java

@@ -4,46 +4,50 @@ import ui.model.DecoratedNetwork;
 import ui.model.DecoratedState;
 import java.lang.Exception;
 
+import classes.Flexibility;
+import classes.HolonElement.Priority;
+
 public class ObjectiveFunctionByCarlos {
-	//Parameter
-	static float lambda;
+	//Parameters
+	
 	//weight for f_g(H)
-	static float w1 = .2f, w2 = .2f, w3 = .2f, w4 = .2f, w5=.2f;
+	static double w_eb = .35f, w_state = .35f, w_pro = .1f, w_perf = .1f, w5=.1f;
+	
 	//kappas for squashing function
-	static float k1 = .2f, k2 = .2f, k3 = .2f, k4 = .2f, k5=.2f;
+	static double k_eb = 1000000.f, k_state = 30000, k_pro = 2100, k_perf = 1100, k_holon= 200000;
+	
+	//theta for f_pro
+	static double theta = 3;
 	
+	//kappas for f_perf:
+	static double kappa_f_unre = 120;
+	static double kappa_f_cool = 60*60*24;
+	static double kappa_f_dur = 60*60;
 	
+	//lambdas for f_perf:
+	static double lambda_f_unre = 10;
+	static double lambda_f_cool = 10;
+	static double lambda_f_dur = 10;
 	
 	
-	//pre-calculated parameters:
+	
+	
+	//pre-calculated parameters for partial function terms:
 	/** 
 	 * Pre calculated for the squash function
 	 * <br>
 	 *  {@link ObjectiveFunctionByCarlos#squash}
 	 */
-	static float squash_subtract = 1.0f / (1.f + (float) Math.exp(5.0));
-	
+	static double squash_subtract = 1.0f / (1.f + (float) Math.exp(5.0));
+	static double range_for_kappa_f_unre = range(kappa_f_unre);
+	static double range_for_kappa_f_cool = range(kappa_f_cool);
+	static double range_for_kappa_f_dur = range(kappa_f_dur);
 	
 	
 	static {
-        //pre-calculations
-		System.out.println("Precalculations");
-		
-		
-		
-		double doubleBaseTest = Math.exp(300);
-		double doubleMax =  Double.MAX_VALUE;
-		float floatBaseTest = (float)Math.exp(300);
-		float floatMax =  Float.MAX_VALUE;
-		
-		
-		System.out.println("floatMax" + floatMax);
-		System.out.println("floatBaseTest" + floatBaseTest);
-		System.out.println("doubleMax" + doubleMax);
-		System.out.println("doubleBaseTest" + doubleBaseTest);
-		
-		
+        //init
 		checkParameter();
+		double k = 9.14E72;
     }
 	
 	/**
@@ -51,7 +55,7 @@ public class ObjectiveFunctionByCarlos {
 	 * Here should all invariants be placed to be checked on initialization.
 	 */
 	private static void checkParameter() {
-		if(!(Math.abs(w1 + w2 + w3 + w4 + w5 - 1) < 0.001)) {
+		if(!(Math.abs(w_eb + w_state + w_pro + w_perf + w5 - 1) < 0.001)) {
 			System.err.println("ParameterError in ObjectiveFunction: w1 + w2 + w3 + w4 + w5 should be 1");
 		}
 	}
@@ -66,7 +70,7 @@ public class ObjectiveFunctionByCarlos {
 	 * 
 	 * 
 	 * @param state
-	 * @return f_g
+	 * @return f_g value between 0 and 100
 	 */
 	static public float getFitnessValueForState(DecoratedState state) {
 		
@@ -75,7 +79,7 @@ public class ObjectiveFunctionByCarlos {
 		//TODO: Hier sollte zwischen den Netzwerken verschiedenen Holons unterschieden werden dies ist in den Formeln nicht wiedergegeben
 		// Kann somit schlechte und gute Netzwerke ausgleichen
 		// Implementierung ist wie im paper.
-		float f_eb = 0;
+		double f_eb = 0;
 		//sum over all objects
 		for(DecoratedNetwork net : state.getNetworkList()) {
 			f_eb += net.getConsumerList().stream().map(con -> con.getEnergySelfSupplied() - con.getEnergyFromConsumingElemnets()).reduce(0.f, Float::sum);
@@ -83,65 +87,131 @@ public class ObjectiveFunctionByCarlos {
 			f_eb += net.getSupplierList().stream().map(sup -> sup.getEnergyProducing() - sup.getEnergySelfConsuming()).reduce(0.f, Float::sum);
 		}
 		//abs
-		f_eb = (float) Math.abs(f_eb);
+		f_eb = Math.abs(f_eb);
 		
 		//Calculate f_state the penalty function for the supply state
-		float f_state = 0;
+		double f_state = 0;
 		for(DecoratedNetwork net : state.getNetworkList()) {
-			f_state += net.getConsumerList().stream().map(con -> supplyPenalty(con.getSupplyBarPercentage())).reduce(0.f, Float::sum);
+			f_state += net.getConsumerList().stream().map(con -> supplyPenalty(con.getSupplyBarPercentage())).reduce(0., Double::sum);
 		}
-			
-		
 		
+		//calculate f_pro the penalty function for priority usage 
+		// for each active flexibility punish
+		double f_pro = 0;
+		f_pro = state.getFlexManager().getAllFlexesOrderedThisTimeStep().stream().map(flex -> Math.pow(theta, priorityToDouble(flex.getElement().getPriority()) )).reduce(0.0, Double::sum);
 		
+		//calculate f_perf the penalty function for the quality of a flexibility used
 		
+		// and the subfuction f_unre, f_cool, f_dur
+		double f_perf = 0;
+		for(Flexibility flex : state.getFlexManager().getAllFlexesOrderedThisTimeStep()) {
+			double f_unre =  unresponsivnessPenalty(flex.getSpeed());
+			double f_cool = cooldownPenalty(flex.getCooldown());
+			double f_dur = durationPenalty(flex.getDuration());
+			f_perf += f_unre + f_cool + f_dur;
+		}
 		
+		//calculate f_holon
+		double f_holon = 0;
+		for(DecoratedNetwork net : state.getNetworkList()) {
+			double f_elements_diviation_production = net.getDiviationInProductionInNetworkForHolonObjects();
+			double f_elements_diviation_consumption = net.getDiviationInProductionInNetworkForHolonObjects();
+			double f_flexibility_diviation_consumption = net.getDiviationInFlexibilityConsumption();
+			double f_flexibility_diviation_production = net.getDiviationInFlexibilityProduction();
+			
+			
+			double con = net.getTotalConsumption();
+			double prod = net.getTotalProduction();
+			double f_change_positive = (con > 0.0)? net.getFlexibilityProductionCapacity() / con : 0.0;
+			double f_change_negativ = (prod > 0.0)? net.getFlexibilityConsumptionCapacity() / prod: 0.0;
+			
+			f_holon += f_elements_diviation_production + f_elements_diviation_consumption 
+					+ f_flexibility_diviation_consumption + f_flexibility_diviation_production + f_change_positive +f_change_negativ;
+		}
 		
 		
 		
 		
+//		System.out.print( "f_eb=" + f_eb);
+//		System.out.print( " f_state=" + f_state);
+//		System.out.print( " f_pro=" + f_pro);
+//		System.out.print( " f_perf=" + f_perf);
+//		System.out.println( " f_holon=" + f_holon);
 		
 		
-		return 0.0f + lambda;
+		return (float) (w_eb * squash(f_eb, k_eb) + w_state * squash(f_state, k_state) + w_pro * squash(f_pro, k_pro) + w_perf * squash(f_perf, k_perf) + w5 * squash(f_holon, k_holon));
 	}
 	
-	
+
 	/**
-	 * 
+	 * The squashing function in paper
 	 * @param x the input
 	 * @param kappa the corresponding kappa
 	 * @return
 	 */
-	static public float squash(float x, float kappa) {
-		return 100.f/(1.0f + (float)Math.exp(-(10.f * (x - kappa/2.f))/ kappa)) - squash_subtract;
+	static public double squash(double x, double kappa) {
+		return 100.f/(1.0f + Math.exp(-(10.f * (x - kappa/2.f))/ kappa)) - squash_subtract;
 	}
 	
 	/**
-	 * 
-	 * @param supplyPercentage from 0 to 1
+	 * f_sup in paper
+	 * @param supply from 0 to 1
 	 * @return
 	 */
-	static public float supplyPenalty(float supplyPercentage) {
-		float f_base = base(supplyPercentage);
-		return (float)(Math.pow(f_base, 100 - 100 * supplyPercentage) - Math.pow(f_base, 2)); 
+	static public double supplyPenalty(double supply) {
+		double supplyPercentage = 100 * supply;
+		//	double test = (supplyPercentage < 100) ? -0.5 * supplyPercentage + 50: supplyPercentage - 100;
+		return (supplyPercentage < 100) ? -0.5 * supplyPercentage + 50: supplyPercentage - 100;
 	}
+	
 	/**
-	 * TODO: f_base wird im Paper mit e angegeben. f_eb mit exp() warum nicht einheitlich?
-	 * 
-	 * @param supplyPercentage from 0 to 1
-	 * @return 5 or 6 but with fancy math 
+	 * prio function in the paper
+	 * @param priority
+	 * @return
 	 */
-	static public float  base(float supplyPercentage) {
-		//TODO: Fancy kann aber leicht zu overflow fürhen denn e1000 ist zu groß für double max double 1.7976931348623157E308 und max float 3.4028235E38
-		//Oder BigDecimal aber müsste echt nicht sein.
-		double euler = Math.exp(1000.0 - 1000.0 * supplyPercentage);
-		return (float) ((5 * euler  + 6 ) /  (euler + 1));
-		
-		
-		
-		//Suggestion 
-		// return (supplyPercentage < 1.0f)? 5.0: 6.0; einfach und gut 
-		
+	private static double priorityToDouble(Priority priority) {
+		switch(priority) {
+		case Essential:
+			return 3.;
+		case High:
+			return 2.;
+		case Medium:
+			return 1.;
+		case Low:
+		default:		
+			return 0.;
+		}
 	}
 	
+	/**
+	 * Attention Math.log calcultae ln not log
+	 * @param kappa
+	 * @return
+	 */
+	private static double range(double kappa) {
+		return kappa / Math.log(Math.pow(2.0, 0.05) - 1.0 );
+	}
+	/**
+	 * f_unre
+	 * @param unresponsiv
+	 * @return
+	 */
+	private static double unresponsivnessPenalty(double unresponsiv) {
+		return (2.0 * lambda_f_unre) / Math.exp(- unresponsiv/ range_for_kappa_f_unre) - lambda_f_unre;
+	}
+	/**
+	 * f_cool
+	 * @param cooldown
+	 * @return
+	 */
+	private static double cooldownPenalty(double cooldown) {
+		return (2.0 * lambda_f_cool) / Math.exp(- cooldown/ range_for_kappa_f_cool) - lambda_f_cool;
+	}
+
+	
+	private static double durationPenalty(double duration) {
+		double lambda_dur_times2 = 2.0 * lambda_f_dur;
+		return - lambda_dur_times2 / Math.exp(- duration/ range_for_kappa_f_dur) + lambda_dur_times2;
+	}
+
 }

+ 8 - 9
src/exampleAlgorithms/PsoAlgorithm.java

@@ -15,13 +15,13 @@ public class PsoAlgorithm extends AlgorithmFrameworkFlex{
 	//Parameter for Algo with default Values:
 	private int swarmSize = 20; 
 	private int maxIterations = 100; 
-	private double limit = 0.01; 
 	private double dependency = 2.07; 
 	private int mutationInterval = 1;
 	private boolean useIntervalMutation = true;
 	private double mutateProbabilityInterval = 0.01;
 	private double maxMutationPercent = 0.01;
 	private double c1, c2, w;
+	private boolean moreInformation = false;
 	
 	
 	
@@ -42,15 +42,15 @@ public class PsoAlgorithm extends AlgorithmFrameworkFlex{
 		addIntParameter("maxIterations", maxIterations, intValue -> maxIterations = intValue, () -> maxIterations, 1);
 		addIntParameter("mutationInterval", mutationInterval, intValue -> mutationInterval = intValue, () -> mutationInterval, 0);
 		addDoubleParameter("dependency", dependency, doubleValue -> dependency = doubleValue, () -> dependency, 2.001, 2.4);
-		addDoubleParameter("limit", limit, doubleValue -> limit = doubleValue, () -> limit, 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);
+		addBooleanParameter("moreInformation", moreInformation , booleanValue -> moreInformation = booleanValue);
 	}
 	
 	@Override
 	protected double evaluateState(DecoratedState actualstate) {
-		return Evaluation.getFitnessValueForState(actualstate);
+		return ObjectiveFunctionByCarlos.getFitnessValueForState(actualstate);
 	}
 
 
@@ -112,12 +112,12 @@ public class PsoAlgorithm extends AlgorithmFrameworkFlex{
 				
 				if(this.useIntervalMutation) {
 					boolean allowMutation = (Random.nextDouble() <  this.mutateProbabilityInterval);
-					TreeSet<Integer> mutationLocation = null;
-					if(allowMutation)mutationLocation = locationsToMutate(dimensions);
+					TreeSet<Integer> mutationLocationSet = null;
+					if(allowMutation)mutationLocationSet = locationsToMutate(dimensions);
 					for(int index = 0; index < dimensions; index++) {
 						updateVelocity(particle, index, globalBest);
 						updateGenotype(particle, index);
-						if(allowMutation &&mutationAllowed == 0 && iteration != 0 && mutationLocation.contains(index))mutation(particle, index);
+						if(allowMutation &&mutationAllowed == 0 && iteration != 0 && mutationLocationSet.contains(index))mutation(particle, index);
 						decode(particle, index);
 					}
 				}else {					
@@ -170,6 +170,7 @@ public class PsoAlgorithm extends AlgorithmFrameworkFlex{
 	private void evaluation(Individual globalBest, List<Particle> swarm) {
 		for(Particle p: swarm) {
 			double localEvaluationValue = evaluatePosition(p.xPhenotype);
+			if(moreInformation) console.println("Fitness " + localEvaluationValue);
 			p.checkNewEvaluationValue(localEvaluationValue);
 			if(localEvaluationValue < globalBest.fitness) {
 				globalBest.fitness = localEvaluationValue;
@@ -261,9 +262,7 @@ public class PsoAlgorithm extends AlgorithmFrameworkFlex{
 				+ " mutationInterval:" +  mutationInterval
 				+ (useIntervalMutation? 
 						(" mutateProbabilityInterval:" +  mutateProbabilityInterval
-						+ " maxMutationPercent:" +  maxMutationPercent)
-						: 
-						(" limit(mutationProbability):" +  limit));
+						+ " maxMutationPercent:" +  maxMutationPercent) : "");
 	}
 	
 	

+ 4 - 1
src/ui/model/Consumer.java

@@ -68,7 +68,10 @@ public class Consumer extends DecoratedHolonObject {
 	}
 
 	public float getSupplyBarPercentage() {
-		return (getEnergyFromNetwork()+ this.getEnergySelfSupplied())/(getEnergyNeededFromNetwork()+ this.getEnergySelfSupplied());
+//		double test = (getEnergyFromConsumingElemnets() > 0.001) ? (getEnergyFromNetwork()+ this.getEnergySelfSupplied())/getEnergyFromConsumingElemnets() : 1.0f;
+//		System.out.println("SupplyBar = [" +getEnergyFromConsumingElemnets() + "] is " + test);
+//		return (float) test;
+		return (getEnergyFromConsumingElemnets() > 0.001) ? (getEnergyFromNetwork()+ this.getEnergySelfSupplied())/getEnergyFromConsumingElemnets() : 1.0f;
 	}
 	public void setEnergySelfSupplied(float energySelfSupplied) {
 		this.energySelfSupplied = energySelfSupplied;

+ 20 - 0
src/ui/model/DecoratedNetwork.java

@@ -287,6 +287,26 @@ public class DecoratedNetwork {
 	}
 
 
+	
+	public int  getAmountOfActiveElements() {
+		
+		return supplierList.stream().map(object -> object.getModel().getNumberOfActiveElements()).reduce(0, Integer::sum)+
+				consumerList.stream().map(object -> object.getModel().getNumberOfActiveElements()).reduce(0, Integer::sum)+
+				consumerSelfSuppliedList.stream().map(object -> object.getModel().getNumberOfActiveElements()).reduce(0, Integer::sum);
+	}
+	public int  getAmountOfElements() {
+		
+		return supplierList.stream().map(object -> object.getModel().getNumberOfElements()).reduce(0, Integer::sum)+
+				consumerList.stream().map(object -> object.getModel().getNumberOfElements()).reduce(0, Integer::sum)+
+				consumerSelfSuppliedList.stream().map(object -> object.getModel().getNumberOfElements()).reduce(0, Integer::sum);
+	}
+	
+	
+	
+	
+	
+	
+	
 	public int getAmountOfConsumer() {
 		return consumerList.size() + this.consumerSelfSuppliedList.size();
 	}

+ 3 - 3
src/ui/model/VisualRepresentationalState.java

@@ -278,7 +278,7 @@ public class VisualRepresentationalState {
 	
 	
 	
-	public int getAmountOfHolons() {
+	public int getAmountfOfGroupNodes() {
 		return groupNodeList.stream().map(groupNode -> groupNode.getAmountOfGroupNodes()).reduce(0, Integer::sum);
 	}
 	
@@ -294,10 +294,10 @@ public class VisualRepresentationalState {
 	}
 	
 	public float getAverageConsumption() {
-		return getConsumptionFromConsumer() / (float)getAmountOfHolons();
+		return getConsumptionFromConsumer() / (float)getAmountfOfGroupNodes();
 	}
 	public float getAverageProduction() {
-		return getProductionFromSupplier() / (float)getAmountOfHolons();
+		return getProductionFromSupplier() / (float)getAmountfOfGroupNodes();
 	}