Bläddra i källkod

FlexManager removed

TomTroppmann 2 år sedan
förälder
incheckning
aef918c110

+ 5 - 5
src/addon/InformationPanel.java

@@ -23,6 +23,7 @@ import javax.swing.JTextField;
 
 import api.AddOn;
 import model.Flexibility;
+import model.Flexibility.FlexState;
 import model.HolonElement;
 import model.HolonElement.Priority;
 import ui.controller.Control;
@@ -247,16 +248,15 @@ public class InformationPanel implements AddOn {
 			return net.getConsumerList().stream().filter(con -> con.getState() == HolonObjectState.OVER_SUPPLIED);
 		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
 		
-		//TODO(Tom2021-12-1) allOfferedFlex
-		List<Flexibility> allOfferedFlex = new ArrayList<>();
+		List<Flexibility> flexList = control.getModel().getAllFlexibilities();
+		List<Flexibility> allOfferedFlex = flexList.stream().filter(flex -> flex.getState().equals(FlexState.OFFERED)).toList();
 		amountEssential = (int)allOfferedFlex.stream().filter(flex -> flex.getElement().getPriority() == Priority.Essential).count();
 		amountHigh = (int)allOfferedFlex.stream().filter(flex -> flex.getElement().getPriority() == Priority.High).count();
 		amountMedium = (int)allOfferedFlex.stream().filter(flex -> flex.getElement().getPriority() == Priority.Medium).count();
 		amountLow = (int)allOfferedFlex.stream().filter(flex -> flex.getElement().getPriority() == Priority.Low).count();
 		this.amountFlexibilities = amountEssential + amountHigh + amountMedium + amountLow;
 		
-		//TODO(Tom2021-12-1) allFlexinUse
-		List<Flexibility> flexActiveList = new ArrayList<>();
+		List<Flexibility> flexActiveList = flexList.stream().filter(flex -> flex.getState().equals(FlexState.IN_USE)).toList();
 		amountActiveEssential = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Essential).count();
 		amountActiveHigh = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.High).count();
 		amountActiveMedium = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Medium).count();
@@ -267,7 +267,7 @@ public class InformationPanel implements AddOn {
 		
 		
 		amountHolons = dState.getNetworkList().size();
-		List<HolonElement> listHolonElements = control.getModel().getAllHolonElemnts();
+		List<HolonElement> listHolonElements = control.getModel().getAllHolonElements();
 		this.amountHolonElements = listHolonElements.size();
 		List<HolonElement> listAcitveHolonElemnts = listHolonElements.stream().filter(ele -> ele.active).collect(Collectors.toList());
 		this.amountActiveHolonElements = listAcitveHolonElemnts.size();

+ 4 - 2
src/addon/RandomOfferdFlexibility.java

@@ -27,6 +27,7 @@ import javax.swing.JSlider;
 import javax.swing.text.NumberFormatter;
 import api.AddOn;
 import model.Flexibility;
+import model.Flexibility.FlexState;
 import model.HolonElement.Priority;
 import ui.controller.Control;
 
@@ -324,8 +325,9 @@ public class RandomOfferdFlexibility implements AddOn {
 		}
 		control.calculateStateAndVisualForCurrentTimeStep();
 		control.updateCanvas();
-		//TODO(Tom2021-12-1) calculate All Offered Flex
-		List<Flexibility> allOfferedFlex = new ArrayList<>();
+		List<Flexibility> flexList = control.getModel().getAllFlexibilities();
+		List<Flexibility> allOfferedFlex = flexList.stream().filter(flex -> flex.getState().equals(FlexState.OFFERED)).toList();
+
 		low.flexList = allOfferedFlex.stream().filter(flex -> flex.getElement().getPriority() == Priority.Low).collect(Collectors.toList());
 		medium.flexList = allOfferedFlex.stream().filter(flex -> flex.getElement().getPriority() == Priority.Medium).collect(Collectors.toList());
 		high.flexList = allOfferedFlex.stream().filter(flex -> flex.getElement().getPriority() == Priority.High).collect(Collectors.toList());

+ 3 - 3
src/algorithm/example/FlexExample.java

@@ -34,6 +34,7 @@ import model.GroupNode;
 import model.HolonElement;
 import model.HolonObject;
 import model.HolonSwitch;
+import model.Flexibility.FlexState;
 import model.HolonElement.Priority;
 import ui.controller.Control;
 import ui.model.DecoratedGroupNode;
@@ -345,8 +346,8 @@ public class FlexExample implements AddOn {
 				if(production > consumption) continue;
 				if(difference == 0)continue;
 				Set<HolonElement> allHolonElemntsInThisNetwork = createListOfAllHolonElemnts(net);
-				//TODO(Tom2021-12-1) AllOfferedFlex
-				List<Flexibility> allOfferedFlex = new ArrayList<>();
+				List<Flexibility> flexList = control.getModel().getAllFlexibilities();
+				List<Flexibility> allOfferedFlex = flexList.stream().filter(flex -> flex.getState().equals(FlexState.OFFERED)).toList();
 				List<Flexibility> allFlexThatGetMeEnergy = allOfferedFlex.stream().filter(flexWrapper -> (flexWrapper.energyReleased() > 0)).collect(Collectors.toList());
 				float amountOfAllEnergyOffered = sumEnergyAvailable(allFlexThatGetMeEnergy);
 				println("amountOfAllFlexEnergyOffered:" + amountOfAllEnergyOffered);
@@ -438,7 +439,6 @@ public class FlexExample implements AddOn {
 
 	
 		private float sumEnergyAvailable(List<Flexibility> flexList) {
-			//TODO(Tom2021-12-1) is this nessesary
 			HashMap<HolonElement, Flexibility> dublicateFilter = new HashMap<HolonElement, Flexibility>();
 			flexList.stream().forEach(flex -> dublicateFilter.put(flex.getElement(), flex));
 			return dublicateFilter.values().stream().map(flex -> flex.energyReleased()).reduce(0.0f,Float::sum);

+ 4 - 6
src/algorithm/objective_function/Evaluation.java

@@ -3,8 +3,7 @@ package algorithm.objective_function;
 import ui.model.DecoratedNetwork;
 import ui.model.DecoratedState;
 import model.HolonObject;
-
-import java.util.ArrayList;
+import model.Flexibility.FlexState;
 import java.util.List;
 
 import model.Flexibility;
@@ -47,10 +46,9 @@ public class Evaluation {
 		/*for(FlexWrapper flexWrapper :state.getFlexManager().getAllFlexWrapperWithState(FlexState.IN_USE)) {
 			flexFitness += flexWrapper.cost / (double)flexWrapper.getDuration();
 		}*/
-		//TODO(Tom2021-12-1) getAllFlexInUse
-		List<Flexibility> getAllFlexInUse = new ArrayList<>();
-		for(Flexibility flexWrapper : getAllFlexInUse) {
-			flexFitness += Math.pow(sigma, (double)priorityToInt(flexWrapper.getElement().getPriority())) - 1;
+		List<Flexibility> getAllFlexInUse = state.getAllFlex().filter(flex -> flex.getState().equals(FlexState.IN_USE)).toList();
+		for(Flexibility flex : getAllFlexInUse) {
+			flexFitness += Math.pow(sigma, (double)priorityToInt(flex.getElement().getPriority())) - 1;
 		}
 		
 		fitness = nw_fitness + object_fitness + flexFitness;

+ 4 - 5
src/algorithm/objective_function/ObjectiveFunctionByCarlos.java

@@ -1,9 +1,9 @@
 package algorithm.objective_function;
 
-import java.util.ArrayList;
 import java.util.List;
 
 import model.Flexibility;
+import model.Flexibility.FlexState;
 import model.HolonElement.Priority;
 import ui.model.DecoratedNetwork;
 import ui.model.DecoratedState;
@@ -116,16 +116,15 @@ public class ObjectiveFunctionByCarlos {
 		//calculate f_pro the penalty function for priority usage 
 		// for each active flexibility punish
 		
-		//TODO(Tom2021-12-1): get allFlexOfferedThisTimeStep
-		List<Flexibility> allFlexOfferedThisTimeStep = new ArrayList<>();
+		List<Flexibility> allFlexOrdered = state.getAllFlex().filter(flex -> flex.getState().equals(FlexState.IN_USE)).toList();
 		double f_pro = 0;
-		f_pro = allFlexOfferedThisTimeStep.stream().map(flex -> Math.pow(theta, priorityToDouble(flex.getElement().getPriority()) ) - 1.0).reduce(0.0, Double::sum);
+		f_pro = allFlexOrdered.stream().map(flex -> Math.pow(theta, priorityToDouble(flex.getElement().getPriority()) ) - 1.0).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 : allFlexOfferedThisTimeStep) {
+		for(Flexibility flex : allFlexOrdered) {
 			double f_unre =  unresponsivnessPenalty(flex.getSpeed());
 			double f_cool = cooldownPenalty(flex.getCooldown());
 			double f_dur = durationPenalty(flex.getDuration());

+ 10 - 12
src/api/AlgorithmFrameworkFlex.java

@@ -48,6 +48,7 @@ import algorithm.objective_function.ObjectiveFunctionByCarlos;
 import algorithm.objective_function.SwitchObjectiveFunction;
 import model.AbstractCanvasObject;
 import model.Flexibility;
+import model.Flexibility.FlexState;
 import model.GroupNode;
 import model.HolonElement;
 import model.HolonObject;
@@ -643,9 +644,8 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 	
 	private void calculateAndPrintFlexInfos(DecoratedState state) {
 		int amountOfUsedFlex = 0;
-		//TODO(Tom2021-12-1) calculate amounf of Flexes
-		Stream<Flexibility> allFlex = Stream.empty();
-		int amountOfFlex = (int)allFlex.count(); 
+		List<Flexibility> allFlex = state.getAllFlex().toList();
+		int amountOfFlex = allFlex.size(); 
 		float cost = 0;
 		int consumingFlex = 0;
 		float consumingFlexEnergy = 0.0f;
@@ -656,8 +656,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		int amountHigh = 0;
 		int amountMedium = 0;
 		int amountLow = 0;
-		//TODO(Tom2021-12-1) calculate all flex in use
-		Stream<Flexibility> allFlexInUse = Stream.empty();
+		Stream<Flexibility> allFlexInUse = allFlex.stream().filter(flex -> flex.getState().equals(FlexState.IN_USE));
 		Iterator<Flexibility> iterInUseFlex =  allFlexInUse.iterator();
 		while(iterInUseFlex.hasNext()) {
 			Flexibility flex = iterInUseFlex.next();
@@ -781,16 +780,15 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		rollOutNodes((dGroupNode != null)? dGroupNode.getModel().getNodes() :model.getObjectsOnCanvas(), initialState, model.getActualTimeStep());			
 		resetChain.add(initialState);
 		if(algoUseFlexes) {		
-			//TODO(Tom2021-12-1) allOfferedFLex
-			List<Flexibility> allOfferedFLex = new ArrayList<>();
+			List<Flexibility> flexList = model.getAllFlexibilities();
+			List<Flexibility> allOfferedFLex = flexList.stream().filter(flex -> flex.getState() == FlexState.OFFERED).toList();
 			for(Flexibility flex :allOfferedFLex){
 				//flex.getFlex().getElement().parentObject;
 				AccessWrapper killSwitchAccess = this.algoUseKillSwitch ? this.accessKillSwitch.get(flex.getElement().parentObject): null;;
 				access.add(new AccessWrapper(flex, killSwitchAccess));
 				initialState.add(false);
 			}
-			//TODO(Tom2021-12-1) allInUseFLex
-			List<Flexibility> allInUseFLex = new ArrayList<>();
+			List<Flexibility> allInUseFLex = flexList.stream().filter(flex -> flex.getState() == FlexState.IN_USE).toList();
 			for(Flexibility flex : allInUseFLex){
 				AccessWrapper killSwitchAccess = this.algoUseKillSwitch ? this.accessKillSwitch.get(flex.getElement().parentObject): null;
 				access.add(new AccessWrapper(flex, killSwitchAccess));
@@ -878,8 +876,9 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		val.difference= Math.abs(val.production - val.consumption);
 		
 		
-		//TODO(Tom2021-12-1) flexActiveList;
-		List<Flexibility> flexActiveList = new ArrayList<>();
+		List<Flexibility> flexList = control.getModel().getAllFlexibilities();
+		List<Flexibility> flexActiveList = flexList.stream().filter(flex -> flex.getState().equals(FlexState.IN_USE)).toList();
+
 		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();
@@ -1217,7 +1216,6 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 					break;
 				case Flexibility:
 					if(state && (!algoUseKillSwitch || (algoUseKillSwitch && !correspondingKillSwitch.getLastState()))) {
-						//TODO(Tom2021-12-1) order Flex
 						flex.order();
 					}
 					break;

+ 8 - 4
src/model/Flexibility.java

@@ -145,13 +145,17 @@ public class Flexibility {
 	//TODO(Tom2021-12-1) public -> package 
 	public boolean cancel() {
 		if(activationTime == timestep) {
-			state=FlexState.OFFERED;
-			durationEndTime = -1;
-			coolDownEndTime = -1;
+			reset();
 			return true;
 		}
 		return false;
-	}	
+	}
+	//TODO(Tom2021-12-2) public -> package 
+	public void reset() {
+		durationEndTime = -1;
+		coolDownEndTime = -1;
+		state=revalidateState();
+	}
 	public boolean canActivate() {
 		return remainingTimeTillActivation() == 0;
 	}

+ 1 - 1
src/model/HolonObject.java

@@ -106,7 +106,7 @@ public class HolonObject extends AbstractCanvasObject {
      * @param timestep is the TimeStep to compare the HolonElements.
      * @return The Energy of the HolonObject.
      */
-    public void calculateState(int timestep)
+    public void calculateEnergy(int timestep)
     {
     	elements.forEach(ele -> ele.calculateState(timestep));
     	actualEnergy = elements.stream().map(element -> element.getActualEnergy()).reduce(0.0f, Float::sum);

+ 2 - 1
src/ui/controller/Control.java

@@ -514,6 +514,7 @@ public class Control {
 	 */
 	public void calculateStateAndVisualForTimeStep(int x) {
 		simulationManager.calculateStateForTimeStep(x, true);
+		//TODO(Tom2021-12-2): Convert to Events
 		updateOutliner();
 		updateFlexWindow();
 		this.updateCanvas();
@@ -524,7 +525,7 @@ public class Control {
 	 * the default "is working" state
 	 */
 	public void resetSimulation() {
-		System.out.println("RESET SIMULATION");
+		model.resetFlexibilities();
 	}
 
 	/**

+ 1 - 2
src/ui/controller/SimulationManager.java

@@ -93,8 +93,7 @@ public class SimulationManager {
 			doAnotherLoop = false;
 			list = calculateNetworks(minimumModel, timestep, leftOver);
 			for(MinimumNetwork net : list) {
-				
-				float energyOnCables = net.getHolonObjectList().stream().filter(object -> object.getActualEnergy() > 0.0f).map(object -> object.getActualEnergy()).reduce(0.0f, ((a,b) -> a + b));
+				float energyOnCables = net.getHolonObjectList().stream().map(object -> object.getActualEnergy()).filter(energy -> energy > 0.0f).reduce(0.0f, (Float::sum));
 				//find the cable with the energy supplied from his two connected objects are the biggest, from all cables that the network give more energy than the cablecapacity. 
 				IntermediateCableWithState cable = net.getEdgeList().stream().filter(aCable -> energyOnCables > aCable.getModel().maxCapacity && !aCable.getModel().isUnlimitedCapacity()).max((lhs,rhs) -> Float.compare(lhs.getEnergyFromConneted(), rhs.getEnergyFromConneted())).orElse(null);
 				if(cable != null) {

+ 255 - 244
src/ui/model/DecoratedNetwork.java

@@ -1,9 +1,7 @@
 package ui.model;
 
 import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-
+import java.util.stream.Stream;
 import model.HolonElement;
 import model.HolonObject;
 import ui.model.DecoratedCable.CableState;
@@ -17,219 +15,224 @@ public class DecoratedNetwork {
 	private ArrayList<Passiv> passivNoEnergyList = new ArrayList<Passiv>();
 	private ArrayList<DecoratedCable> decoratedCableList = new ArrayList<DecoratedCable>();
 
-	public DecoratedNetwork(MinimumNetwork minimumNetwork, int Iteration, FairnessModel actualFairnessModel){	
-		switch(actualFairnessModel) {
+	public DecoratedNetwork(MinimumNetwork minimumNetwork, int Iteration, FairnessModel actualFairnessModel) {
+		switch (actualFairnessModel) {
 		case AllEqual:
 			calculateAllEqualNetwork(minimumNetwork, Iteration);
 			break;
 		case MininumDemandFirst:
 		default:
 			calculateMinimumDemandFirstNetwork(minimumNetwork, Iteration);
-			break;		
+			break;
 		}
 	}
 
-
-	//Getter:
+	// Getter:
 	public ArrayList<Supplier> getSupplierList() {
 		return supplierList;
 	}
 
-
 	public ArrayList<Consumer> getConsumerList() {
 		return consumerList;
 	}
 
-
 	public ArrayList<Consumer> getConsumerSelfSuppliedList() {
 		return consumerSelfSuppliedList;
 	}
 
-
 	public ArrayList<Passiv> getPassivNoEnergyList() {
 		return passivNoEnergyList;
 	}
-	public ArrayList<DecoratedCable> getDecoratedCableList(){
+
+	public ArrayList<DecoratedCable> getDecoratedCableList() {
 		return decoratedCableList;
 	}
-	
-	
-	//Calculations:
+
+	// Calculations:
 	private void calculateMinimumDemandFirstNetwork(MinimumNetwork minimumNetwork, int Iteration) {
 		categorize(minimumNetwork, Iteration);
-		//Sort SupplierList according to the EnergyToSupplyNetwork maximum first.
-		//Sort ConsumerList according to the MinimumConsumingElementEnergy minimum first.
-		supplierList.sort((Supplier lhs,Supplier rhs) -> -Float.compare(lhs.getEnergyToSupplyNetwork(), rhs.getEnergyToSupplyNetwork()));
-		consumerList.sort((Consumer lhs,Consumer rhs) -> Float.compare(lhs.getMinimumConsumingElementEnergy()  , rhs.getMinimumConsumingElementEnergy()));
-		//consumerList.forEach((con) -> System.out.println(con.getMinimumConsumingElementEnergy()));
-		//consumerList.forEach((con) -> System.out.println("AfterSorting" + con));
-		float energyToSupplyInTheNetwork = supplierList.stream().map(supplier -> supplier.getEnergyToSupplyNetwork() - supplier.getEnergySupplied()).reduce( 0.0f, (a, b) -> a + b);
+		// Sort SupplierList according to the EnergyToSupplyNetwork maximum first.
+		// Sort ConsumerList according to the MinimumConsumingElementEnergy minimum
+		// first.
+		supplierList.sort((Supplier lhs,
+				Supplier rhs) -> -Float.compare(lhs.getEnergyToSupplyNetwork(), rhs.getEnergyToSupplyNetwork()));
+		consumerList.sort((Consumer lhs, Consumer rhs) -> Float.compare(lhs.getMinimumConsumingElementEnergy(),
+				rhs.getMinimumConsumingElementEnergy()));
+		// consumerList.forEach((con) ->
+		// System.out.println(con.getMinimumConsumingElementEnergy()));
+		// consumerList.forEach((con) -> System.out.println("AfterSorting" + con));
+		float energyToSupplyInTheNetwork = supplierList.stream()
+				.map(supplier -> supplier.getEnergyToSupplyNetwork() - supplier.getEnergySupplied())
+				.reduce(0.0f, (a, b) -> a + b);
 		decorateCable(minimumNetwork, energyToSupplyInTheNetwork);
-		
-		outerLoop:
-			for(Consumer con : consumerList)
-			{
-				//gehe Supplier list durch wer ihn supplien kann.
-				for(Supplier sup : supplierList) {
-					float  energyRdyToSupply = sup.getEnergyToSupplyNetwork() - sup.getEnergySupplied();
-					if(energyRdyToSupply == 0.0f) continue;
-					float energyNeededForMinimumConsumingElement=con.getMinimumConsumingElementEnergy()-con.getEnergyFromNetwork();
-					if(energyNeededForMinimumConsumingElement>energyToSupplyInTheNetwork) {
-						//Dont supply a minimumElement when you cant supply it fully
-						break outerLoop;
-					}
-					if(energyRdyToSupply>=energyNeededForMinimumConsumingElement) {
-						energyToSupplyInTheNetwork -= energyNeededForMinimumConsumingElement;
-						supply(con, sup, energyNeededForMinimumConsumingElement);
+
+		outerLoop: for (Consumer con : consumerList) {
+			// gehe Supplier list durch wer ihn supplien kann.
+			for (Supplier sup : supplierList) {
+				float energyRdyToSupply = sup.getEnergyToSupplyNetwork() - sup.getEnergySupplied();
+				if (energyRdyToSupply == 0.0f)
+					continue;
+				float energyNeededForMinimumConsumingElement = con.getMinimumConsumingElementEnergy()
+						- con.getEnergyFromNetwork();
+				if (energyNeededForMinimumConsumingElement > energyToSupplyInTheNetwork) {
+					// Dont supply a minimumElement when you cant supply it fully
+					break outerLoop;
+				}
+				if (energyRdyToSupply >= energyNeededForMinimumConsumingElement) {
+					energyToSupplyInTheNetwork -= energyNeededForMinimumConsumingElement;
+					supply(con, sup, energyNeededForMinimumConsumingElement);
+					continue outerLoop;
+				} else {
+					energyToSupplyInTheNetwork -= energyRdyToSupply;
+					supply(con, sup, energyRdyToSupply);
+				}
+			}
+			// No more Energy in the network
+			break;
+		}
+		// consumerList.forEach((con) -> System.out.println("AfterSuppliing
+		// MinimumDemand " + con));
+
+		// Sort ConsumerList according to the EnergyNeeded to supply fully after minimum
+		// Demand First.
+		consumerList.sort((Consumer lhs, Consumer rhs) -> Float.compare(
+				lhs.getEnergyNeededFromNetwork() - lhs.getEnergyFromNetwork(),
+				rhs.getEnergyNeededFromNetwork() - rhs.getEnergyFromNetwork()));
+		// Supply consumer fully
+		outerLoop: for (Consumer con : consumerList) {
+			// gehe Supplier list durch wer ihn supplien kann.
+			for (Supplier sup : supplierList) {
+				float energyRdyToSupply = sup.getEnergyToSupplyNetwork() - sup.getEnergySupplied();
+				if (energyRdyToSupply == 0.0f)
+					continue;
+				float energyNeededForFullySupply = con.getEnergyNeededFromNetwork() - con.getEnergyFromNetwork();
+				if (energyNeededForFullySupply == 0.0f)
+					continue outerLoop;
+				if (energyRdyToSupply >= energyNeededForFullySupply) {
+					supply(con, sup, energyNeededForFullySupply);
+					continue outerLoop;
+				} else {
+					supply(con, sup, energyRdyToSupply);
+				}
+			}
+			// No more Energy in the network
+			break;
+		}
+		// consumerList.forEach((con) -> System.out.println("AfterFullySuplieing" +
+		// con));
+		// If Energy Left Supply all equal
+		// Count EnergyLeft
+		float energyLeft = supplierList.stream()
+				.map(supplier -> supplier.getEnergyToSupplyNetwork() - supplier.getEnergySupplied())
+				.reduce(0.0f, (a, b) -> a + b);
+		// System.out.println("EnergyLeft: " + energyLeft);
+		if (energyLeft > 0.0f && (consumerList.size() + consumerSelfSuppliedList.size() != 0)) {
+			float equalAmountOfEnergyToSupply = energyLeft
+					/ ((float) (consumerList.size() + consumerSelfSuppliedList.size()));
+			outerLoop: for (Consumer con : consumerList) {
+				// gehe Supplier list durch wer ihn supplien kann.
+				for (Supplier sup : supplierList) {
+					float energyRdyToSupply = sup.getEnergyToSupplyNetwork() - sup.getEnergySupplied();
+					if (energyRdyToSupply == 0.0f)
+						continue;
+					float energyNeededToSupplyConsumerTheEqualAmount = equalAmountOfEnergyToSupply
+							+ con.getEnergyNeededFromNetwork() - con.getEnergyFromNetwork();
+					if (energyRdyToSupply >= energyNeededToSupplyConsumerTheEqualAmount) {
+						supply(con, sup, energyNeededToSupplyConsumerTheEqualAmount);
 						continue outerLoop;
-					}else
-					{
-						energyToSupplyInTheNetwork -= energyRdyToSupply;
+					} else {
 						supply(con, sup, energyRdyToSupply);
 					}
 				}
-				//No more Energy in the network
+				// No more Energy in the network
 				break;
 			}
-		//consumerList.forEach((con) -> System.out.println("AfterSuppliing MinimumDemand " + con));
-		
-		//Sort ConsumerList according to the EnergyNeeded to supply fully after minimum Demand First.
-		consumerList.sort((Consumer lhs,Consumer rhs) -> Float.compare(lhs.getEnergyNeededFromNetwork()-lhs.getEnergyFromNetwork() , rhs.getEnergyNeededFromNetwork()-rhs.getEnergyFromNetwork() ));
-		//Supply consumer fully 
-		outerLoop:
-			for(Consumer con : consumerList)
-			{
-				//gehe Supplier list durch wer ihn supplien kann.
-				for(Supplier sup : supplierList) {
-					float  energyRdyToSupply = sup.getEnergyToSupplyNetwork() - sup.getEnergySupplied();
-					if(energyRdyToSupply == 0.0f) continue;
-					float energyNeededForFullySupply = con.getEnergyNeededFromNetwork() - con.getEnergyFromNetwork();
-					if(energyNeededForFullySupply == 0.0f) continue outerLoop;
-					if(energyRdyToSupply>=energyNeededForFullySupply) {
-						supply(con, sup, energyNeededForFullySupply);
+			outerLoop: for (Consumer con : consumerSelfSuppliedList) {
+				// gehe Supplier list durch wer ihn supplien kann.
+				for (Supplier sup : supplierList) {
+					float energyRdyToSupply = sup.getEnergyToSupplyNetwork() - sup.getEnergySupplied();
+					if (energyRdyToSupply == 0.0f)
+						continue;
+					float energyNeededToSupplyConsumerTheEqualAmount = equalAmountOfEnergyToSupply
+							+ con.getEnergyNeededFromNetwork() - con.getEnergyFromNetwork();
+					if (energyRdyToSupply >= energyNeededToSupplyConsumerTheEqualAmount) {
+						supply(con, sup, energyNeededToSupplyConsumerTheEqualAmount);
 						continue outerLoop;
-					}else
-					{
+					} else {
 						supply(con, sup, energyRdyToSupply);
 					}
+
 				}
-				//No more Energy in the network
+				// No more Energy in the network
 				break;
 			}
-		//consumerList.forEach((con) -> System.out.println("AfterFullySuplieing" + con));
-		//If Energy Left Supply all equal
-		//Count EnergyLeft
-		float energyLeft = supplierList.stream().map(supplier -> supplier.getEnergyToSupplyNetwork() - supplier.getEnergySupplied()).reduce( 0.0f, (a, b) -> a + b);
-		//System.out.println("EnergyLeft: " +  energyLeft);
-		if(energyLeft > 0.0f && (consumerList.size() + consumerSelfSuppliedList.size() != 0))
-		{
-			float equalAmountOfEnergyToSupply = energyLeft / ((float)(consumerList.size() + consumerSelfSuppliedList.size()));
-			outerLoop:
-				for(Consumer con : consumerList)
-				{
-					//gehe Supplier list durch wer ihn supplien kann.
-					for(Supplier sup : supplierList) {
-						float  energyRdyToSupply = sup.getEnergyToSupplyNetwork() - sup.getEnergySupplied();
-						if(energyRdyToSupply == 0.0f) continue;
-						float energyNeededToSupplyConsumerTheEqualAmount = equalAmountOfEnergyToSupply +con.getEnergyNeededFromNetwork()- con.getEnergyFromNetwork();
-						if(energyRdyToSupply>=energyNeededToSupplyConsumerTheEqualAmount) {
-							supply(con, sup, energyNeededToSupplyConsumerTheEqualAmount);
-							continue outerLoop;
-						}else
-						{
-							supply(con, sup, energyRdyToSupply);
-						}
-					}
-					//No more Energy in the network
-					break;
-				}
-			outerLoop:
-				for(Consumer con : consumerSelfSuppliedList)
-				{
-					//gehe Supplier list durch wer ihn supplien kann.
-					for(Supplier sup : supplierList) {
-						float  energyRdyToSupply = sup.getEnergyToSupplyNetwork() - sup.getEnergySupplied();
-						if(energyRdyToSupply == 0.0f) continue;
-						float energyNeededToSupplyConsumerTheEqualAmount = equalAmountOfEnergyToSupply +con.getEnergyNeededFromNetwork()- con.getEnergyFromNetwork();
-						if(energyRdyToSupply>=energyNeededToSupplyConsumerTheEqualAmount) {
-							supply(con, sup, energyNeededToSupplyConsumerTheEqualAmount);
-							continue outerLoop;
-						}else
-						{
-							supply(con, sup, energyRdyToSupply);
-						}
-						
-					}
-					//No more Energy in the network
-					break;
-				}
 		}
-		//consumerList.forEach((con) -> System.out.println("AfterOverSuppleiing" + con));
-		
-		//consumerSelfSuppliedList.forEach((con) -> System.out.println("AfterOverSuppleiing" + con));
-		
+		// consumerList.forEach((con) -> System.out.println("AfterOverSuppleiing" +
+		// con));
+
+		// consumerSelfSuppliedList.forEach((con) ->
+		// System.out.println("AfterOverSuppleiing" + con));
+
 		calculateStates();
 	}
 
-
 	private void decorateCable(MinimumNetwork minimumNetwork, float energyToSupplyInTheNetwork) {
-		//DecoratedCables
-		//Minimum demand first:
-		for(IntermediateCableWithState edge: minimumNetwork.getEdgeList()) {		
-			decoratedCableList.add(new DecoratedCable(edge.getModel(), edge.getState(), (edge.getState() == CableState.Working) ? energyToSupplyInTheNetwork : 0.0f));
+		// DecoratedCables
+		// Minimum demand first:
+		for (IntermediateCableWithState edge : minimumNetwork.getEdgeList()) {
+			decoratedCableList.add(new DecoratedCable(edge.getModel(), edge.getState(),
+					(edge.getState() == CableState.Working) ? energyToSupplyInTheNetwork : 0.0f));
 		}
 	}
 
-
-
 	private void calculateAllEqualNetwork(MinimumNetwork minimumNetwork, int Iteration) {
 		categorize(minimumNetwork, Iteration);
-		float energyToSupplyInTheNetwork = supplierList.stream().map(supplier -> supplier.getEnergyToSupplyNetwork() - supplier.getEnergySupplied()).reduce( 0.0f, (a, b) -> a + b);
-		float energyForEachConsumer = (consumerList.size() != 0) ? energyToSupplyInTheNetwork / consumerList.size() : 0.0f;
+		float energyToSupplyInTheNetwork = supplierList.stream()
+				.map(supplier -> supplier.getEnergyToSupplyNetwork() - supplier.getEnergySupplied())
+				.reduce(0.0f, (a, b) -> a + b);
+		float energyForEachConsumer = (consumerList.size() != 0) ? energyToSupplyInTheNetwork / consumerList.size()
+				: 0.0f;
 		decorateCable(minimumNetwork, energyToSupplyInTheNetwork);
-		//Supply consumer equal 
-		outerLoop:
-		for(Consumer con : consumerList)
-		{
-			//gehe Supplier list durch wer ihn supplien kann.
+		// Supply consumer equal
+		outerLoop: for (Consumer con : consumerList) {
+			// gehe Supplier list durch wer ihn supplien kann.
 			float energyNeededForEqualSupply = energyForEachConsumer;
-			for(Supplier sup : supplierList) {
-				float  energyRdyToSupply = sup.getEnergyToSupplyNetwork() - sup.getEnergySupplied();
-				if(energyRdyToSupply == 0.0f) continue;
-				if(energyRdyToSupply>=energyNeededForEqualSupply) {
+			for (Supplier sup : supplierList) {
+				float energyRdyToSupply = sup.getEnergyToSupplyNetwork() - sup.getEnergySupplied();
+				if (energyRdyToSupply == 0.0f)
+					continue;
+				if (energyRdyToSupply >= energyNeededForEqualSupply) {
 					supply(con, sup, energyNeededForEqualSupply);
 					continue outerLoop;
-				}else
-				{
+				} else {
 					supply(con, sup, energyRdyToSupply);
 					energyNeededForEqualSupply -= energyRdyToSupply;
 				}
 			}
-			//No more Energy in the network
+			// No more Energy in the network
 			break;
 		}
 		calculateStates();
 	}
 
 	private void calculateStates() {
-		//CalculateStates:
+		// CalculateStates:
 		supplierList.forEach(sup -> sup.setState(HolonObjectState.PRODUCER));
 		passivNoEnergyList.forEach(sup -> sup.setState(HolonObjectState.NO_ENERGY));
-		for(Consumer con : this.consumerList)
-		{
+		for (Consumer con : this.consumerList) {
 			setConsumerState(con);
 		}
-		for(Consumer con : this.consumerSelfSuppliedList)
-		{
+		for (Consumer con : this.consumerSelfSuppliedList) {
 			setConsumerState(con);
 		}
 	}
+
 	private void categorize(MinimumNetwork minimumNetwork, int Iteration) {
-		//Categorize
-		for(HolonObject hObject: minimumNetwork.getHolonObjectList()) {
+		// Categorize
+		for (HolonObject hObject : minimumNetwork.getHolonObjectList()) {
 			float energyNeeded = hObject.getEnergyNeededFromConsumingElements();
 			float energySelfProducing = hObject.getEnergySelfProducingFromProducingElements();
-			if(energyNeeded < energySelfProducing) {
+			if (energyNeeded < energySelfProducing) {
 				Supplier sup = new Supplier(hObject, energySelfProducing - energyNeeded, energyNeeded);
 				supplierList.add(sup);
 			} else if (energyNeeded > energySelfProducing) {
@@ -239,8 +242,8 @@ public class DecoratedNetwork {
 				con.setEnergyFromConsumingElemnets(hObject.getEnergyNeededFromConsumingElements());
 				con.setEnergySelfSupplied(hObject.getEnergySelfProducingFromProducingElements());
 				consumerList.add(con);
-			}else if(energyNeeded == energySelfProducing) {
-				
+			} else if (energyNeeded == energySelfProducing) {
+
 				if (energySelfProducing == 0.0f) {
 					Passiv pas = new Passiv(hObject);
 					passivNoEnergyList.add(pas);
@@ -252,208 +255,216 @@ public class DecoratedNetwork {
 					con.setEnergySelfSupplied(hObject.getEnergySelfProducingFromProducingElements());
 					consumerSelfSuppliedList.add(con);
 				}
-				
+
 			}
 		}
 	}
-	
-	
+
 	private void setConsumerState(Consumer con) {
-		if(con.getEnergySelfSupplied() + con.getEnergyFromNetwork() > con.getEnergyFromConsumingElemnets()) {
+		if (con.getEnergySelfSupplied() + con.getEnergyFromNetwork() > con.getEnergyFromConsumingElemnets()) {
 			con.setState(HolonObjectState.OVER_SUPPLIED);
-		}else if(con.getEnergySelfSupplied() + con.getEnergyFromNetwork() == con.getEnergyFromConsumingElemnets()) {
+		} else if (con.getEnergySelfSupplied() + con.getEnergyFromNetwork() == con.getEnergyFromConsumingElemnets()) {
 			con.setState(HolonObjectState.SUPPLIED);
-		}else if(con.getEnergySelfSupplied() + con.getEnergyFromNetwork() >= con.getMinimumConsumingElementEnergy()) {
+		} else if (con.getEnergySelfSupplied() + con.getEnergyFromNetwork() >= con.getMinimumConsumingElementEnergy()) {
 			con.setState(HolonObjectState.PARTIALLY_SUPPLIED);
-		}else {
+		} else {
 			con.setState(HolonObjectState.NOT_SUPPLIED);
 		}
 	}
-	
-	
+
 	/**
 	 * No Checks.
+	 * 
 	 * @param con
 	 * @param sup
 	 * @param energy
 	 */
 	private void supply(Consumer con, Supplier sup, float energy) {
-		sup.getConsumerList().add(sup.new ConsumerListEntry(con , energy));
+		sup.getConsumerList().add(sup.new ConsumerListEntry(con, energy));
 		sup.setEnergySupplied(sup.getEnergySupplied() + energy);
 		con.getSupplierList().add(con.new SupplierListEntry(sup, energy));
 		con.setEnergyFromNetwork(con.getEnergyFromNetwork() + energy);
 	}
 
+	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)
+				+ passivNoEnergyList.stream().map(object -> object.getModel().getNumberOfElements()).reduce(0,
+						Integer::sum);
+	}
 
-	
-	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)+
-				passivNoEnergyList.stream().map(object -> object.getModel().getNumberOfElements()).reduce(0, Integer::sum);
-	}
-	
-	
-	
-	
-	
-	
-	
 	public int getAmountOfConsumer() {
 		return consumerList.size() + this.consumerSelfSuppliedList.size();
 	}
 
-
 	public int getAmountOfSupplier() {
 		return supplierList.size();
 	}
 
-
 	public int getAmountOfConsumerWithState(HolonObjectState state) {
-		return (int) (consumerList.stream().filter(con -> con.getState() == state).count() + consumerSelfSuppliedList.stream().filter(con -> con.getState() == state).count());
+		return (int) (consumerList.stream().filter(con -> con.getState() == state).count()
+				+ consumerSelfSuppliedList.stream().filter(con -> con.getState() == state).count());
 	}
 
-
 	public int getAmountOfPassiv() {
 		return passivNoEnergyList.size();
 	}
+
 	public int getAmountOfHolonObjects() {
 		return getAmountOfConsumer() + getAmountOfSupplier() + getAmountOfPassiv();
 	}
-	
-	
+
 	public float getTotalConsumption() {
-		float energy = consumerList.stream().map(con -> con.getEnergyFromConsumingElemnets()).reduce(0.f, Float::sum) + consumerSelfSuppliedList.stream().map(con -> con.getEnergyFromConsumingElemnets()).reduce(0.f, Float::sum);
-		energy += supplierList.stream().map(sup -> sup.getEnergySelfConsuming()).reduce(0.f,  Float::sum);
+		float energy = consumerList.stream().map(con -> con.getEnergyFromConsumingElemnets()).reduce(0.f, Float::sum)
+				+ consumerSelfSuppliedList.stream().map(con -> con.getEnergyFromConsumingElemnets()).reduce(0.f,
+						Float::sum);
+		energy += supplierList.stream().map(sup -> sup.getEnergySelfConsuming()).reduce(0.f, Float::sum);
 		return energy;
 	}
-	
-	public float getAverageConsumptionInNetworkForHolonObject(){
-		return getTotalConsumption() / (float)getAmountOfHolonObjects();
+
+	public float getAverageConsumptionInNetworkForHolonObject() {
+		return getTotalConsumption() / (float) getAmountOfHolonObjects();
 	}
-	
+
 	public float getTotalProduction() {
-		float energy = consumerList.stream().map(con -> con.getEnergySelfSupplied()).reduce(0.f, Float::sum) + consumerSelfSuppliedList.stream().map(con -> con.getEnergySelfSupplied()).reduce(0.f, Float::sum);
-		energy += supplierList.stream().map(sup -> sup.getEnergyProducing()).reduce(0.f,  Float::sum);
+		float energy = consumerList.stream().map(con -> con.getEnergySelfSupplied()).reduce(0.f, Float::sum)
+				+ consumerSelfSuppliedList.stream().map(con -> con.getEnergySelfSupplied()).reduce(0.f, Float::sum);
+		energy += supplierList.stream().map(sup -> sup.getEnergyProducing()).reduce(0.f, Float::sum);
 		return energy;
 	}
-	
+
 	public float getAverageProductionInNetworkForHolonObject() {
-		return getTotalProduction() /  (float) getAmountOfHolonObjects();
+		return getTotalProduction() / (float) getAmountOfHolonObjects();
 	}
-	
+
 	/**
 	 * returns the Varianz in Poduction
+	 * 
 	 * @return
 	 */
 	public float getVarianzInProductionInNetworkForHolonObjects() {
 		float average = getAverageProductionInNetworkForHolonObject();
-		float sum = consumerList.stream().map(con -> squared(con.getEnergySelfSupplied() - average)).reduce(0.f, Float::sum) 
-				+ consumerSelfSuppliedList.stream().map(con -> squared(con.getEnergySelfSupplied() - average)).reduce(0.f, Float::sum)
-				+ supplierList.stream().map(sup -> squared(sup.getEnergyProducing() - average)).reduce(0.f,  Float::sum);
+		float sum = consumerList.stream().map(con -> squared(con.getEnergySelfSupplied() - average)).reduce(0.f,
+				Float::sum)
+				+ consumerSelfSuppliedList.stream().map(con -> squared(con.getEnergySelfSupplied() - average))
+						.reduce(0.f, Float::sum)
+				+ supplierList.stream().map(sup -> squared(sup.getEnergyProducing() - average)).reduce(0.f, Float::sum);
 		return sum / (float) getAmountOfHolonObjects();
 	}
-	
-	
+
 	public float getDeviationInProductionInNetworkForHolonObjects() {
-		return (float)Math.sqrt(getVarianzInProductionInNetworkForHolonObjects());
+		return (float) Math.sqrt(getVarianzInProductionInNetworkForHolonObjects());
 	}
-	
-	
+
 	public float getVarianzInConsumptionInNetworkForHolonObjects() {
 		float average = getAverageConsumptionInNetworkForHolonObject();
-		float sum = consumerList.stream().map(con -> squared(con.getEnergyFromConsumingElemnets() - average)).reduce(0.f, Float::sum) 
-				+ consumerSelfSuppliedList.stream().map(con -> squared(con.getEnergyFromConsumingElemnets() - average)).reduce(0.f, Float::sum)
-				+ supplierList.stream().map(sup -> squared(sup.getEnergySelfConsuming() - average)).reduce(0.f,  Float::sum);
+		float sum = consumerList.stream().map(con -> squared(con.getEnergyFromConsumingElemnets() - average))
+				.reduce(0.f, Float::sum)
+				+ consumerSelfSuppliedList.stream().map(con -> squared(con.getEnergyFromConsumingElemnets() - average))
+						.reduce(0.f, Float::sum)
+				+ supplierList.stream().map(sup -> squared(sup.getEnergySelfConsuming() - average)).reduce(0.f,
+						Float::sum);
 		return sum / (float) getAmountOfHolonObjects();
 	}
-	
+
 	public float getDeviationInConsumptionInNetworkForHolonObjects() {
-		return (float)Math.sqrt(getVarianzInConsumptionInNetworkForHolonObjects());
+		return (float) Math.sqrt(getVarianzInConsumptionInNetworkForHolonObjects());
+	}
+
+	// HelperFunction
+
+	public Stream<HolonElement> getElementStream() {
+		return Stream.concat(consumerList.stream().flatMap(con -> con.getModel().getElements().stream()),
+				Stream.concat(consumerSelfSuppliedList.stream().flatMap(con -> con.getModel().getElements().stream()),
+						Stream.concat(supplierList.stream().flatMap(con -> con.getModel().getElements().stream()),
+								passivNoEnergyList.stream().flatMap(con -> con.getModel().getElements().stream()))));
 	}
-	
-	//HelperFunction
+
 	/**
 	 * 
 	 * @return a list of energy
 	 */
-	public List<Float> getListOfEnergyThatIsOfferedByFlexibilitiesInThisNetwork() {
-		List<HolonElement> eleList = consumerList.stream().flatMap(con-> con.getModel().getElements().stream()).collect(Collectors.toList());
-		eleList.addAll(consumerSelfSuppliedList.stream().flatMap(con-> con.getModel().getElements().stream()).collect(Collectors.toList()));
-		eleList.addAll(supplierList.stream().flatMap(con-> con.getModel().getElements().stream()).collect(Collectors.toList()));
-		eleList.addAll(passivNoEnergyList.stream().flatMap(con-> con.getModel().getElements().stream()).collect(Collectors.toList()));
-		return  eleList.stream().filter(ele -> (ele.flexList.stream().anyMatch(flex -> flex.offered)) ).map(ele -> -ele.getActualEnergy() ).collect(Collectors.toList()) ;
+	public Stream<Float> getListOfEnergyThatIsOfferedByFlexibilitiesInThisNetwork() {
+		return getElementStream()
+				.filter(ele -> (ele.flexList.stream().anyMatch(flex -> flex.offered)))
+				.map(ele -> -ele.getActualEnergy());
 	}
-	
-	public List<Float> getListOfEnergyInProductionThatIsOfferedByFlexibilitiesInThisNetwork(){
-		return getListOfEnergyThatIsOfferedByFlexibilitiesInThisNetwork().stream().filter(value -> (value > 0.f)).collect(Collectors.toList());
+
+	public Stream<Float> getListOfEnergyInProductionThatIsOfferedByFlexibilitiesInThisNetwork() {
+		return getListOfEnergyThatIsOfferedByFlexibilitiesInThisNetwork().filter(value -> (value > 0.f));
 	}
-	public List<Float> getListOfEnergyInConsumptionThatIsOfferedByFlexibilitiesInThisNetwork(){
-		return getListOfEnergyThatIsOfferedByFlexibilitiesInThisNetwork().stream().filter(value -> (value < 0.f)).map(value -> -value).collect(Collectors.toList());
+
+	public Stream<Float> getListOfEnergyInConsumptionThatIsOfferedByFlexibilitiesInThisNetwork() {
+		return getListOfEnergyThatIsOfferedByFlexibilitiesInThisNetwork().filter(value -> (value < 0.f))
+				.map(value -> -value);
 	}
-	
+
 	public float getFlexibilityProductionCapacity() {
-		return getListOfEnergyInProductionThatIsOfferedByFlexibilitiesInThisNetwork().stream().reduce(0.f, Float::sum);
+		return getListOfEnergyInProductionThatIsOfferedByFlexibilitiesInThisNetwork().reduce(0.f, Float::sum);
 	}
+
 	public float getFlexibilityConsumptionCapacity() {
-		return getListOfEnergyInConsumptionThatIsOfferedByFlexibilitiesInThisNetwork().stream().reduce(0.f, Float::sum);
+		return getListOfEnergyInConsumptionThatIsOfferedByFlexibilitiesInThisNetwork().reduce(0.f, Float::sum);
 	}
-	
-	
+
 	public int getAmountOfProductionFlexibilities() {
-		return getListOfEnergyInProductionThatIsOfferedByFlexibilitiesInThisNetwork().size();
+		return (int)getListOfEnergyInProductionThatIsOfferedByFlexibilitiesInThisNetwork().count();
 	}
+
 	public int getAmountOfConsumptionFlexibilities() {
-		return getListOfEnergyInConsumptionThatIsOfferedByFlexibilitiesInThisNetwork().size();
+		return (int)getListOfEnergyInConsumptionThatIsOfferedByFlexibilitiesInThisNetwork().count();
 	}
-	
+
 	public float getAverageFlexibilityProduction() {
 		int amount = getAmountOfProductionFlexibilities();
-		 return (amount > 0)? getFlexibilityProductionCapacity() / (float)amount : 0.f;
+		return (amount > 0) ? getFlexibilityProductionCapacity() / (float) amount : 0.f;
 	}
-	
+
 	public float getAverageFlexibilityConsumption() {
 		int amount = getAmountOfConsumptionFlexibilities();
-		 return (amount > 0)? getFlexibilityConsumptionCapacity() / (float)amount : 0.f;
+		return (amount > 0) ? getFlexibilityConsumptionCapacity() / (float) amount : 0.f;
 	}
-	
+
 	public float getVarianzInFlexibilitieConsumption() {
 		float average = getAverageFlexibilityConsumption();
-		float sum = getListOfEnergyInConsumptionThatIsOfferedByFlexibilitiesInThisNetwork().stream().map(energy -> squared(energy - average)).reduce(0.f, Float::sum);
+		float sum = getListOfEnergyInConsumptionThatIsOfferedByFlexibilitiesInThisNetwork()
+				.map(energy -> squared(energy - average)).reduce(0.f, Float::sum);
 		int amountOfFlexibilities = getAmountOfConsumptionFlexibilities();
-		return (amountOfFlexibilities > 0)? sum / (float) amountOfFlexibilities : 0.f;
+		return (amountOfFlexibilities > 0) ? sum / (float) amountOfFlexibilities : 0.f;
 	}
-	
-	
+
 	public float getVarianzInFlexibilitieProduction() {
 		float average = getAverageFlexibilityProduction();
-		float sum = getListOfEnergyInProductionThatIsOfferedByFlexibilitiesInThisNetwork().stream().map(energy -> squared(energy - average)).reduce(0.f, Float::sum);
+		float sum = getListOfEnergyInProductionThatIsOfferedByFlexibilitiesInThisNetwork()
+				.map(energy -> squared(energy - average)).reduce(0.f, Float::sum);
 		int amountOfFlexibilities = getAmountOfProductionFlexibilities();
-		return (amountOfFlexibilities > 0)? sum / (float) amountOfFlexibilities : 0.f;
+		return (amountOfFlexibilities > 0) ? sum / (float) amountOfFlexibilities : 0.f;
 	}
-	
+
 	public float getDiviationInFlexibilityConsumption() {
 		return (float) Math.sqrt(getVarianzInFlexibilitieConsumption());
 	}
+
 	public float getDiviationInFlexibilityProduction() {
 		return (float) Math.sqrt(getVarianzInFlexibilitieProduction());
 	}
-	
-	//Help Function
+
+	// Help Function
 	private float squared(float input) {
 		return (float) Math.pow(input, 2);
 	}
-	
-	
-	
-	
-	
-	
+
 }

+ 7 - 0
src/ui/model/DecoratedState.java

@@ -1,6 +1,9 @@
 package ui.model;
 
 import java.util.ArrayList;
+import java.util.stream.Stream;
+
+import model.Flexibility;
 
 public class DecoratedState {
 	int timestepOfState;
@@ -25,4 +28,8 @@ public class DecoratedState {
 	public int getTimestepOfState() {
 		return timestepOfState;
 	}
+	
+	public Stream<Flexibility> getAllFlex(){
+		return networkList.stream().flatMap(network -> network.getElementStream().flatMap(ele -> ele.flexList.stream()));
+	}
 }

+ 2 - 2
src/ui/model/MinimumModel.java

@@ -43,7 +43,6 @@ public class MinimumModel {
 		for (AbstractCanvasObject aCps : abstractObjectList) {
 			if (aCps instanceof HolonObject) {
 				HolonObject hObject = (HolonObject) aCps;
-				hObject.calculateState(timestep);
 				holonObjectList.add(hObject);
 			}
 			else if (aCps instanceof Node) nodeList.add((Node) aCps);
@@ -68,13 +67,14 @@ public class MinimumModel {
 				inGroupEdges.put(edge, list);
 			}
 		}
+		//Calculate Energy of HolonObjects
+		holonObjectList.forEach(obj -> obj.calculateEnergy(timestep));
 	}
 
 	private void addGroupNodeObjects(GroupNode aUpperNode, int timestep) {
 		for(AbstractCanvasObject aCps : aUpperNode.getNodes()) {
 			if (aCps instanceof HolonObject) {
 				HolonObject hObject = (HolonObject) aCps;
-				hObject.calculateState(timestep);
 				holonObjectList.add(hObject);
 			}
 			else if (aCps instanceof Node) nodeList.add((Node) aCps);

+ 10 - 1
src/ui/model/Model.java

@@ -17,6 +17,7 @@ import adapter.PairAdapter;
 import adapter.PositionAdapter;
 import model.AbstractCanvasObject;
 import model.Edge;
+import model.Flexibility;
 import model.GroupNode;
 import model.HolonElement;
 import model.HolonObject;
@@ -455,10 +456,18 @@ public class Model {
     }
 
 
-    public List<HolonElement> getAllHolonElemnts() {
+    public List<HolonElement> getAllHolonElements() {
     	return getAllHolonObjectsOnCanvas().stream().flatMap(hO -> hO.getElements().stream()).collect(Collectors.toList());
     }
     
+    public List<Flexibility> getAllFlexibilities() {
+    	return getAllHolonObjectsOnCanvas().stream().flatMap(hO -> hO.getElements().stream().flatMap(ele -> ele.flexList.stream())).collect(Collectors.toList());
+    }
+    
+    public void resetFlexibilities() {
+    	getAllFlexibilities().forEach(flex -> flex.reset());
+    }
+    
     
     public ArrayList<HolonObject> getAllHolonObjectsOnCanvas(){
 		ArrayList<HolonObject> objectToReturn = new ArrayList<HolonObject>();

+ 1 - 2
src/ui/view/information/HolonInformationPanel.java

@@ -31,7 +31,6 @@ import model.Flexibility;
 import model.GroupNode;
 import model.HolonElement;
 import model.HolonObject;
-import model.HolonElement.Priority;
 import preferences.ColorPreference;
 import ui.controller.Control;
 import ui.model.Consumer;
@@ -45,7 +44,7 @@ import utility.FormatFloat;
 public class HolonInformationPanel extends JPanel {
 	private Predicate<DecoratedHolonObject> stateFilter = (object) -> true;// = (object) -> object.getState() ==
 																			// HolonObjectState.PRODUCER;
-	private Predicate<HolonElement> priorityFilter = (ele) -> ele.getPriority() == Priority.Low;
+	private Predicate<HolonElement> priorityFilter = (ele) -> true;
 	private final int defaultWidth = 50;
 	private final int defaultHeight = 200;
 

+ 20 - 34
src/ui/view/window/FlexWindow.java

@@ -70,8 +70,8 @@ public class FlexWindow extends JFrame {
 	
 	private JTabbedPane contentPanel = new JTabbedPane();
 	private JScrollPane usageViewPanel;
-	
-	private Control controller;
+	private int boxWidth = 70;
+	private Control control;
 	private Model model;
 	
 	public boolean isClosed = false;
@@ -93,7 +93,7 @@ public class FlexWindow extends JFrame {
 	
 	public FlexWindow(JFrame parentFrame, ui.controller.Control  controller){
 		this.intermediateFlex.name = "name";
-		this.controller = controller;
+		this.control = controller;
 		this.model = controller.getModel();
 		//InitWindow
 		createMenuBar();
@@ -161,11 +161,9 @@ public class FlexWindow extends JFrame {
 		
 		
 		for(int i = 0; i<5; i++){
-			
-			
-			//TODO(Tom2021-12-1): listOfFlexWithState
-			//flexmanager.getAllFlexWrapperWithState(titles[i]);
-			List<Flexibility> listOfFlexWithState = new ArrayList<>();
+			final int titileIndex = i;
+			List<Flexibility> flexList = control.getModel().getAllFlexibilities();
+			List<Flexibility> listOfFlexWithState = flexList.stream().filter(flex -> flex.getState().equals(titles[titileIndex])).toList();
 			JLabel label = new JLabel(titles[i].toString() + "[" + listOfFlexWithState.size()+ "]");									
 			GridBagConstraints labelC = new GridBagConstraints();
 			labelC.gridx = 1;
@@ -207,21 +205,6 @@ public class FlexWindow extends JFrame {
 		c.weightx = 0.0;
 		c.weighty = 1;
 		gridbagPanel.add(spacer, c);
-		
-		
-		
-		
-		
-		
-		
-		
-		
-		
-		
-	
-		
-		
-
 	}
 
 	
@@ -229,31 +212,33 @@ public class FlexWindow extends JFrame {
 
 	private void createFlexPanel(JPanel listPanel, List<Flexibility> flexList) {
 		listPanel.setBackground(Color.white);
+		Insets insets = new Insets(2,2,2,2);		
+		int panelWidth = Math.max(boxWidth, this.getWidth() - 90);
+		int maxButtonsPerLine = panelWidth / boxWidth;
 		
-		Insets insets = new Insets(2,2,2,2);
 		
-		//String[] flexesString = flexWrapperList.stream().map(flexWrapper -> flexWrapper.name).toArray(String[]::new);
 		int i = 0;
 		for(Flexibility flex: flexList) {
 			GridBagConstraints c = new GridBagConstraints();
-			c.gridx = Math.floorMod(i, 5);
+			c.gridx = Math.floorMod(i, maxButtonsPerLine);
 			c.weightx = 0.0;	
 			c.insets = insets;
 			JButton labelButton = new JButton(flex.name);
-			labelButton.setPreferredSize(new Dimension(70,70));
+			labelButton.setPreferredSize(new Dimension(boxWidth,boxWidth));
 			labelButton.setBorder(BorderFactory.createLineBorder(Color.black));
 			listPanel.add(labelButton, c);
 			labelButton.addActionListener(clicked ->{
 				flex.order();
-				controller.calculateStateAndVisualForCurrentTimeStep();
-				controller.updateCanvas();
+				control.calculateStateAndVisualForCurrentTimeStep();
+				control.updateCanvas();
 			});
 			labelButton.setToolTipText(createToolTipp(flex));
+			i++;
 		}
 		//AddSpacer
 		JLabel spacer = new JLabel();
 		GridBagConstraints c = new GridBagConstraints();
-		c.gridx = 5;
+		c.gridx = maxButtonsPerLine;
 		c.gridy = 0;
 		c.fill = GridBagConstraints.VERTICAL;
 		c.weightx = 1;
@@ -273,7 +258,7 @@ public class FlexWindow extends JFrame {
 	+ "Cooldown: " + actual.getCooldown() + "<br>"
 	//+ "Speed: " + actual.speed + "<br>"
 	+ "Cost: " + actual.cost + "<br>"
-	+ "BrigtMir: " + actual.energyReleased() + "<br>"
+	+ "EnergyReleased: " + actual.energyReleased() + "<br>"
 	+ "Constrains: " + actual.constrainList.stream().map(constrain -> constrain.getName()).collect(Collectors.joining( "," )) + "<br>"
 	+ "</html>";
 		
@@ -387,7 +372,8 @@ public class FlexWindow extends JFrame {
 	}
 	
 	public void updateSelectedPanel() {
-		//TODO(Tom2021-12-1) UpdateFLex
+		//TODO(Tom2021-12-1) Update Flex Window is slow
+		//Should not remove add so many Components
 		
 		listOfAllSelectedHolonObjects.removeAllChildren();
 		//Init with HolonObjects
@@ -467,7 +453,7 @@ public class FlexWindow extends JFrame {
 		Flexibility toDeleteFlex =(Flexibility) JOptionPane.showInputDialog(this, "Select to Delete Flexibility:", "Flexibility?",  JOptionPane.OK_OPTION,new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)) , allFlexes, "");
 		if(toDeleteFlex != null) {
 			toDeleteFlex.getElement().flexList.remove(toDeleteFlex);
-			controller.getSimManager().calculateStateForTimeStep(model.getActualTimeStep(), true);
+			control.getSimManager().calculateStateForTimeStep(model.getActualTimeStep(), true);
 			updateSelectedPanel();
 		}
 	}
@@ -690,7 +676,7 @@ public class FlexWindow extends JFrame {
 			
 			
 			//if(!model.getSelectedCpsObjects().contains(holonObjectSelector.getSelectedItem()))model.getSelectedCpsObjects().add((AbstractCpsObject)holonObjectSelector.getSelectedItem());
-			controller.getSimManager().calculateStateForTimeStep(model.getActualTimeStep(), true);
+			control.getSimManager().calculateStateForTimeStep(model.getActualTimeStep(), true);
 			
 			update();
 			addDialog.dispose();