Browse Source

WIP compiles| NO calculations | NO algorithms

Removes DecoratedStates
TomTroppmann 2 years ago
parent
commit
7df3310fb4
30 changed files with 1968 additions and 2432 deletions
  1. 82 85
      src/holeg/addon/InformationPanel.java
  2. 3 2
      src/holeg/addon/RandomSwitch.java
  3. 49 65
      src/holeg/algorithm/binary/BaseLine.java
  4. 19 20
      src/holeg/algorithm/example/DemoAlgo.java
  5. 80 89
      src/holeg/algorithm/example/FlexExample.java
  6. 33 33
      src/holeg/algorithm/objective_function/Evaluation.java
  7. 83 85
      src/holeg/algorithm/objective_function/GraphMetrics.java
  8. 82 81
      src/holeg/algorithm/objective_function/ObjectiveFunctionByCarlos.java
  9. 23 23
      src/holeg/algorithm/objective_function/SwitchObjectiveFunction.java
  10. 137 137
      src/holeg/algorithm/objective_function/TopologieObjectiveFunction.java
  11. 3 3
      src/holeg/algorithm/topologie/AcoAlgorithm.java
  12. 3 3
      src/holeg/algorithm/topologie/GaAlgorithm.java
  13. 3 3
      src/holeg/algorithm/topologie/PsoAlgorithm.java
  14. 85 92
      src/holeg/api/AlgorithmFrameworkFlex.java
  15. 119 127
      src/holeg/api/TopologieAlgorithmFramework.java
  16. 30 23
      src/holeg/model/HolonSwitch.java
  17. 1 1
      src/holeg/ui/controller/CanvasController.java
  18. 0 2
      src/holeg/ui/controller/Control.java
  19. 10 47
      src/holeg/ui/controller/SimulationManager.java
  20. 0 203
      src/holeg/ui/model/DecoratedGroupNode.java
  21. 470 471
      src/holeg/ui/model/DecoratedNetwork.java.orig
  22. 0 36
      src/holeg/ui/model/DecoratedState.java
  23. 0 24
      src/holeg/ui/model/DecoratedSwitch.java
  24. 0 41
      src/holeg/ui/model/ExitCable.java
  25. 0 44
      src/holeg/ui/model/IntermediateCalculationCable.java
  26. 35 0
      src/holeg/ui/model/PriorityCount.java
  27. 246 252
      src/holeg/ui/view/canvas/Canvas.java
  28. 166 204
      src/holeg/ui/view/information/FilterableGroupNode.java
  29. 119 132
      src/holeg/ui/view/information/HolonInformationPanel.java
  30. 87 104
      src/holeg/ui/view/window/Outliner.java

+ 82 - 85
src/holeg/addon/InformationPanel.java

@@ -27,11 +27,8 @@ import holeg.model.HolonElement;
 import holeg.model.Flexibility.FlexState;
 import holeg.model.HolonElement.Priority;
 import holeg.ui.controller.Control;
-import holeg.ui.model.DecoratedState;
-import holeg.ui.model.VisualRepresentationalState;
-import holeg.ui.model.DecoratedHolonObject.HolonObjectState;
-import holeg.ui.model.DecoratedSwitch.SwitchState;
 
+//TODO(Tom2022-01-13): Fix information Panel
 public class InformationPanel implements AddOn {
 	Control control;
 	
@@ -225,87 +222,87 @@ public class InformationPanel implements AddOn {
 	
 	
 	void calculateValues(){
-		DecoratedState dState = control.getSimManager().getActualDecorState().get();
-		amountConsumer = dState.getNetworkList().stream().map(net -> net.getAmountOfConsumer()).reduce(0, Integer::sum);
-		this.amountSwitch = dState.getDecoratedSwitches().size();
-		amountActiveSwitch = (int)dState.getDecoratedSwitches().stream().filter(dswitch -> (dswitch.getState() == SwitchState.Closed)).count();
-		amountInactiveSwitch = amountSwitch - amountActiveSwitch;
-		this.amountUnderSupplied = dState.getNetworkList().stream().map(net -> net.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED)).reduce(0, Integer::sum);
-		this.amountPatiallySupplied = dState.getNetworkList().stream().map(net -> net.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED)).reduce(0, Integer::sum);
-		
-		this.amountFullySupplied = dState.getNetworkList().stream().map(net -> net.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED)).reduce(0, Integer::sum);
-		this.amountOversupllied = dState.getNetworkList().stream().map(net -> net.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED)).reduce(0, Integer::sum);
-		amountSupplier = dState.getNetworkList().stream().map(net -> net.getAmountOfSupplier()).reduce(0, Integer::sum);
-		amountPassiv = dState.getNetworkList().stream().map(net -> net.getAmountOfPassiv()).reduce(0, Integer::sum);
-		
-		this.amountHolonObjects = amountConsumer + amountSupplier + amountPassiv;
-		
-		partiallySuppliedStats = dState.getNetworkList().stream().flatMap(net -> {
-			return net.getConsumerList().stream().filter(con -> con.getState() == HolonObjectState.PARTIALLY_SUPPLIED);
-		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
-		
-		overSuppliedStats = dState.getNetworkList().stream().flatMap(net -> {
-			return net.getConsumerList().stream().filter(con -> con.getState() == HolonObjectState.OVER_SUPPLIED);
-		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
-		
-		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;
-		
-		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();
-		amountActiveLow = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Low).count();
-		this.amountActiveFlexibilities = amountActiveEssential + amountActiveHigh + amountActiveMedium + amountActiveLow;
-		VisualRepresentationalState visualState =control.getSimManager().getActualVisualRepresentationalState().get();
-		amountGroupNodes = visualState.getAmountfOfGroupNodes();
-		
-		
-		amountHolons = dState.getNetworkList().size();
-		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();
-		this.amountInactiveHolonElements = amountHolonElements - amountActiveHolonElements;
-		this.amountElementLow = (int) listHolonElements.stream().filter(ele -> ele.getPriority() == Priority.Low).count();
-		this.amountElementMedium= (int) listHolonElements.stream().filter(ele -> ele.getPriority() == Priority.Medium).count();
-		this.amountElementHigh = (int) listHolonElements.stream().filter(ele -> ele.getPriority() == Priority.High).count();
-		this.amountElementEssential = (int) listHolonElements.stream().filter(ele -> ele.getPriority() == Priority.Essential).count();
-		this.amountElementActiveLow = (int) listAcitveHolonElemnts.stream().filter(ele -> ele.getPriority() == Priority.Low).count();
-		this.amountElementActiveMedium= (int) listAcitveHolonElemnts.stream().filter(ele -> ele.getPriority() == Priority.Medium).count();
-		this.amountElementActiveHigh = (int) listAcitveHolonElemnts.stream().filter(ele -> ele.getPriority() == Priority.High).count();
-		this.amountElementActiveEssential = (int) listAcitveHolonElemnts.stream().filter(ele -> ele.getPriority() == Priority.Essential).count();
-		this.amountElementInactiveLow = amountElementLow - amountElementActiveLow;
-		this.amountElementInactiveMedium= amountElementMedium - amountElementActiveMedium;
-		this.amountElementInactiveHigh = amountElementHigh - amountElementActiveHigh;
-		this.amountElementInactiveEssential = amountElementEssential - amountElementActiveEssential;
-		
-		
-		
-		//int cost = 0;
-		int consumingFlex = 0;
-		//float consumingFlexEnergy = 0.0f;
-		int producingFlex = 0;
-		//float producingFlexEnergy = 0.0f;
-		//int maxCooldown = 0;
-		for(Flexibility flex :allOfferedFlex) {
-//			cost += flex.cost;
-			float energy = flex.energyReleased();
-			if(energy < 0) {
-				consumingFlex++;
-//				consumingFlexEnergy += -energy;
-			}else {
-				producingFlex++;
-//				producingFlexEnergy += energy;
-			}
-		}
-		this.amountConsumingFlexibilities = consumingFlex;
-		this.amountProducingFlexibilities = producingFlex;
+//		DecoratedState dState = control.getSimManager().getActualDecorState().get();
+//		amountConsumer = dState.getNetworkList().stream().map(net -> net.getAmountOfConsumer()).reduce(0, Integer::sum);
+//		this.amountSwitch = dState.getDecoratedSwitches().size();
+//		amountActiveSwitch = (int)dState.getDecoratedSwitches().stream().filter(dswitch -> (dswitch.getState() == SwitchState.Closed)).count();
+//		amountInactiveSwitch = amountSwitch - amountActiveSwitch;
+//		this.amountUnderSupplied = dState.getNetworkList().stream().map(net -> net.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED)).reduce(0, Integer::sum);
+//		this.amountPatiallySupplied = dState.getNetworkList().stream().map(net -> net.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED)).reduce(0, Integer::sum);
+//		
+//		this.amountFullySupplied = dState.getNetworkList().stream().map(net -> net.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED)).reduce(0, Integer::sum);
+//		this.amountOversupllied = dState.getNetworkList().stream().map(net -> net.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED)).reduce(0, Integer::sum);
+//		amountSupplier = dState.getNetworkList().stream().map(net -> net.getAmountOfSupplier()).reduce(0, Integer::sum);
+//		amountPassiv = dState.getNetworkList().stream().map(net -> net.getAmountOfPassiv()).reduce(0, Integer::sum);
+//		
+//		this.amountHolonObjects = amountConsumer + amountSupplier + amountPassiv;
+//		
+//		partiallySuppliedStats = dState.getNetworkList().stream().flatMap(net -> {
+//			return net.getConsumerList().stream().filter(con -> con.getState() == HolonObjectState.PARTIALLY_SUPPLIED);
+//		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
+//		
+//		overSuppliedStats = dState.getNetworkList().stream().flatMap(net -> {
+//			return net.getConsumerList().stream().filter(con -> con.getState() == HolonObjectState.OVER_SUPPLIED);
+//		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
+//		
+//		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;
+//		
+//		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();
+//		amountActiveLow = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Low).count();
+//		this.amountActiveFlexibilities = amountActiveEssential + amountActiveHigh + amountActiveMedium + amountActiveLow;
+//		VisualRepresentationalState visualState =control.getSimManager().getActualVisualRepresentationalState().get();
+//		amountGroupNodes = visualState.getAmountfOfGroupNodes();
+//		
+//		
+//		amountHolons = dState.getNetworkList().size();
+//		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();
+//		this.amountInactiveHolonElements = amountHolonElements - amountActiveHolonElements;
+//		this.amountElementLow = (int) listHolonElements.stream().filter(ele -> ele.getPriority() == Priority.Low).count();
+//		this.amountElementMedium= (int) listHolonElements.stream().filter(ele -> ele.getPriority() == Priority.Medium).count();
+//		this.amountElementHigh = (int) listHolonElements.stream().filter(ele -> ele.getPriority() == Priority.High).count();
+//		this.amountElementEssential = (int) listHolonElements.stream().filter(ele -> ele.getPriority() == Priority.Essential).count();
+//		this.amountElementActiveLow = (int) listAcitveHolonElemnts.stream().filter(ele -> ele.getPriority() == Priority.Low).count();
+//		this.amountElementActiveMedium= (int) listAcitveHolonElemnts.stream().filter(ele -> ele.getPriority() == Priority.Medium).count();
+//		this.amountElementActiveHigh = (int) listAcitveHolonElemnts.stream().filter(ele -> ele.getPriority() == Priority.High).count();
+//		this.amountElementActiveEssential = (int) listAcitveHolonElemnts.stream().filter(ele -> ele.getPriority() == Priority.Essential).count();
+//		this.amountElementInactiveLow = amountElementLow - amountElementActiveLow;
+//		this.amountElementInactiveMedium= amountElementMedium - amountElementActiveMedium;
+//		this.amountElementInactiveHigh = amountElementHigh - amountElementActiveHigh;
+//		this.amountElementInactiveEssential = amountElementEssential - amountElementActiveEssential;
+//		
+//		
+//		
+//		//int cost = 0;
+//		int consumingFlex = 0;
+//		//float consumingFlexEnergy = 0.0f;
+//		int producingFlex = 0;
+//		//float producingFlexEnergy = 0.0f;
+//		//int maxCooldown = 0;
+//		for(Flexibility flex :allOfferedFlex) {
+////			cost += flex.cost;
+//			float energy = flex.energyReleased();
+//			if(energy < 0) {
+//				consumingFlex++;
+////				consumingFlexEnergy += -energy;
+//			}else {
+//				producingFlex++;
+////				producingFlexEnergy += energy;
+//			}
+//		}
+//		this.amountConsumingFlexibilities = consumingFlex;
+//		this.amountProducingFlexibilities = producingFlex;
 		
 	}
 	

+ 3 - 2
src/holeg/addon/RandomSwitch.java

@@ -12,6 +12,7 @@ import javax.swing.JPanel;
 import javax.swing.JSlider;
 
 import holeg.api.AddOn;
+import holeg.model.HolonSwitch.SwitchMode;
 import holeg.ui.controller.Control;
 
 public class RandomSwitch implements AddOn {
@@ -62,11 +63,11 @@ public class RandomSwitch implements AddOn {
 	private void run() {
 		control.getModel().getCanvas().getAllSwitchObjectsRecursive().forEach(s -> {
 			// Set to Manual Mode
-			s.setManualMode(true);
+			s.setMode(SwitchMode.Manual);
 			// Generate a random number between 0 and 1
 			double randomDouble = Math.random();
 			if (randomDouble < randomChance) {
-				s.setManualState(!s.getManualState());
+				s.flipManualState();
 			}
 		});
 		control.calculateStateAndVisualForCurrentTimeStep();

+ 49 - 65
src/holeg/algorithm/binary/BaseLine.java

@@ -8,6 +8,7 @@ import java.awt.image.BufferedImage;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Optional;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -29,10 +30,9 @@ import holeg.model.GroupNode;
 import holeg.model.HolonElement;
 import holeg.model.HolonObject;
 import holeg.model.HolonSwitch;
+import holeg.model.HolonSwitch.SwitchMode;
+import holeg.model.HolonSwitch.SwitchState;
 import holeg.ui.controller.Control;
-import holeg.ui.model.DecoratedGroupNode;
-import holeg.ui.model.DecoratedNetwork;
-import holeg.ui.model.DecoratedState;
 import holeg.ui.model.Model;
 
 
@@ -45,7 +45,7 @@ public class BaseLine implements AddOn {
 	
 	//Settings For GroupNode using and cancel
 	private boolean useGroupNode = false;
-	private DecoratedGroupNode dGroupNode = null;
+	private Optional<GroupNode> groupNode = Optional.empty();
 	private boolean cancel = false;
 
 
@@ -222,15 +222,12 @@ public class BaseLine implements AddOn {
 		textArea.append(message  + "\n");
 	}
 	private void selectGroupNode() {
-		control.getSimManager().getActualVisualRepresentationalState().ifPresent(state -> {
-			Object[] possibilities = state.getCreatedGroupNodes().values().stream().map(aCps -> new Handle<DecoratedGroupNode>(aCps)).toArray();
-			@SuppressWarnings("unchecked")
-			Handle<DecoratedGroupNode> selected = (Handle<DecoratedGroupNode>) JOptionPane.showInputDialog(content, "Select GroupNode:", "GroupNode?",  JOptionPane.OK_OPTION,new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)) , possibilities, "");
-			if(selected != null) {
-				println("Selected: " + selected);
-				dGroupNode = selected.object;
-			}
-		});
+		Object[] possibilities = control.getModel().getCanvas().getAllGroupNodeObjectsRecursive().toArray();
+		GroupNode selected = (GroupNode) JOptionPane.showInputDialog(content, "Select GroupNode:", "GroupNode?",  JOptionPane.OK_OPTION,new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)) , possibilities, "");
+		if(selected != null) {
+			println("Selected: " + selected);
+			groupNode = Optional.of(selected);
+		}
 		
 	}
 	
@@ -277,38 +274,38 @@ public class BaseLine implements AddOn {
 		if(closeSwitches)setAllSwitchesClosed();
 		setHolonElemntsAktiv();
 		control.calculateStateAndVisualForCurrentTimeStep();
-		DecoratedState actualstate = control.getSimManager().getActualDecorState().get();	
-		for(DecoratedNetwork net : actualstate.getNetworkList()) {
-			float production = net.getSupplierList().stream().map(supplier -> supplier.getEnergyToSupplyNetwork()).reduce(0.0f, (a, b) -> a + b);
-			float consumption = net.getConsumerList().stream().map(con -> con.getEnergyNeededFromNetwork()).reduce(0.0f, (a, b) -> a + b);
-			float difference = Math.abs(production - consumption);
-			println("production:" + production + "  consumption:" + consumption);
-			if(!(production < consumption))continue;
-			if(net.getConsumerList().isEmpty() && net.getConsumerSelfSuppliedList().isEmpty())continue;
-			//Stream.concat(net.getConsumerList().stream(), net.getConsumerSelfSuppliedList().stream());
-			int consumerWihtMaxNumberElements = Stream.concat(net.getConsumerList().stream(), net.getConsumerSelfSuppliedList().stream()).map(con -> con.getModel().getNumberOfElements()).max((lhs,rhs) ->Integer.compare(lhs, rhs)).orElse(0);
-			println("consumerWihtMaxNumberElements:" + consumerWihtMaxNumberElements);
-			for(int inAktiveCount = 0;inAktiveCount <= consumerWihtMaxNumberElements; inAktiveCount++) {
-				println("inAktiveCount:" + inAktiveCount);
-				final int inAktiveCountFinal = inAktiveCount;
-				List<HolonObject> conList = Stream.concat(net.getConsumerList().stream(), net.getConsumerSelfSuppliedList().stream()).map(con -> con.getModel()).filter(object -> objectList.contains(object)).filter(object -> (object.getNumberOfInActiveElements() == inAktiveCountFinal)).collect(Collectors.toList());
-				conList.sort((a,b) -> Float.compare(a.getMaximumConsumingElementEnergy(), b.getMaximumConsumingElementEnergy()));
-				consumer:
-				for(HolonObject con: conList) {
-					//println("Consumer" + con);
-					List<HolonElement> sortedElementList = con.getElements().filter(ele -> ele.active && ele.isConsumer()).sorted((a,b) -> -Float.compare(-a.getActualEnergy(), -b.getActualEnergy())).collect(Collectors.toList());
-					for(HolonElement element: sortedElementList) {
-						float elementConsumption = -element.getActualEnergy();
-						if(elementConsumption <= difference) {
-							println("elementConsumption:" + elementConsumption);
-							difference -= elementConsumption;
-							element.active = false;
-							continue consumer;
-						}
-					}
-				}
-			}
-		}
+//		DecoratedState actualstate = control.getSimManager().getActualDecorState().get();	
+//		for(DecoratedNetwork net : actualstate.getNetworkList()) {
+//			float production = net.getSupplierList().stream().map(supplier -> supplier.getEnergyToSupplyNetwork()).reduce(0.0f, (a, b) -> a + b);
+//			float consumption = net.getConsumerList().stream().map(con -> con.getEnergyNeededFromNetwork()).reduce(0.0f, (a, b) -> a + b);
+//			float difference = Math.abs(production - consumption);
+//			println("production:" + production + "  consumption:" + consumption);
+//			if(!(production < consumption))continue;
+//			if(net.getConsumerList().isEmpty() && net.getConsumerSelfSuppliedList().isEmpty())continue;
+//			//Stream.concat(net.getConsumerList().stream(), net.getConsumerSelfSuppliedList().stream());
+//			int consumerWihtMaxNumberElements = Stream.concat(net.getConsumerList().stream(), net.getConsumerSelfSuppliedList().stream()).map(con -> con.getModel().getNumberOfElements()).max((lhs,rhs) ->Integer.compare(lhs, rhs)).orElse(0);
+//			println("consumerWihtMaxNumberElements:" + consumerWihtMaxNumberElements);
+//			for(int inAktiveCount = 0;inAktiveCount <= consumerWihtMaxNumberElements; inAktiveCount++) {
+//				println("inAktiveCount:" + inAktiveCount);
+//				final int inAktiveCountFinal = inAktiveCount;
+//				List<HolonObject> conList = Stream.concat(net.getConsumerList().stream(), net.getConsumerSelfSuppliedList().stream()).map(con -> con.getModel()).filter(object -> objectList.contains(object)).filter(object -> (object.getNumberOfInActiveElements() == inAktiveCountFinal)).collect(Collectors.toList());
+//				conList.sort((a,b) -> Float.compare(a.getMaximumConsumingElementEnergy(), b.getMaximumConsumingElementEnergy()));
+//				consumer:
+//				for(HolonObject con: conList) {
+//					//println("Consumer" + con);
+//					List<HolonElement> sortedElementList = con.getElements().filter(ele -> ele.active && ele.isConsumer()).sorted((a,b) -> -Float.compare(-a.getActualEnergy(), -b.getActualEnergy())).collect(Collectors.toList());
+//					for(HolonElement element: sortedElementList) {
+//						float elementConsumption = -element.getActualEnergy();
+//						if(elementConsumption <= difference) {
+//							println("elementConsumption:" + elementConsumption);
+//							difference -= elementConsumption;
+//							element.active = false;
+//							continue consumer;
+//						}
+//					}
+//				}
+//			}
+//		}
 		updateVisual();
 	}
 
@@ -323,8 +320,8 @@ public class BaseLine implements AddOn {
 	}
 	private void setAllSwitchesClosed() {
 		for(HolonSwitch hSwitch : switchList) {
-			hSwitch.setManualMode(true);
-			hSwitch.setManualState(true);
+			hSwitch.setMode(SwitchMode.Manual);
+			hSwitch.setManualState(SwitchState.Closed);
 		}
 		
 	}
@@ -340,7 +337,7 @@ public class BaseLine implements AddOn {
 		objectList = new ArrayList<HolonObject>();
 		initialState = new ArrayList<Boolean>(); 
 		access= new HashMap<Integer, AccessWrapper>();
-		rollOutNodes((useGroupNode && (dGroupNode != null))? dGroupNode.getModel().getObjectsInThisLayer() :model.getCanvas().getObjectsInThisLayer(), initialState, model.getCurrentIteration());
+		rollOutNodes((useGroupNode && groupNode.isPresent())? groupNode.get().getObjectsInThisLayer() :model.getCanvas().getObjectsInThisLayer(), initialState, model.getCurrentIteration());
 		return initialState;
 	}
 	/**
@@ -359,7 +356,7 @@ public class BaseLine implements AddOn {
 				objectList.add(hO);
 			}
 			else if (aCps instanceof HolonSwitch sw) {
-				positionToInit.add(sw.getState(timeStep));
+				positionToInit.add(sw.getState().isClosed());
 				switchList.add(sw);
 				access.put(positionToInit.size() - 1 , new AccessWrapper(sw));
 			}
@@ -380,7 +377,7 @@ public class BaseLine implements AddOn {
 			objectList.add(hObject);
 		});
 		groupNode.getAllSwitchObjectsRecursive().forEach(sw -> {
-			positionToInit.add(sw.getState(timeStep));
+			positionToInit.add(sw.getState().isClosed());
 			switchList.add(sw);
 			access.put(positionToInit.size() - 1 , new AccessWrapper(sw));
 		});
@@ -437,8 +434,8 @@ public class BaseLine implements AddOn {
 			if(type == HOLONELEMENT) {
 				hElement.active = state;
 			}else{//is switch
-				hSwitch.setManualMode(true);
-				hSwitch.setManualState(state);
+				hSwitch.setMode(SwitchMode.Manual);
+				hSwitch.setManualState(state ? SwitchState.Closed : SwitchState.Open);
 			}
 				
 		}
@@ -447,17 +444,4 @@ public class BaseLine implements AddOn {
 		}
 	}
 	
-	
-	
-	
-	private   class  Handle<T>{
-		public T object;
-		Handle(T object){
-			this.object = object;
-		}
-		public String toString() {
-			return object.toString();
-		}
-	}
-	
 }

+ 19 - 20
src/holeg/algorithm/example/DemoAlgo.java

@@ -9,6 +9,7 @@ import java.text.NumberFormat;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Stream;
 
@@ -32,8 +33,9 @@ import holeg.model.GroupNode;
 import holeg.model.HolonElement;
 import holeg.model.HolonObject;
 import holeg.model.HolonSwitch;
+import holeg.model.HolonSwitch.SwitchMode;
+import holeg.model.HolonSwitch.SwitchState;
 import holeg.ui.controller.Control;
-import holeg.ui.model.DecoratedGroupNode;
 import holeg.ui.model.Model;
 
 public class DemoAlgo implements AddOn {
@@ -42,7 +44,7 @@ public class DemoAlgo implements AddOn {
 		
 		//Settings For GroupNode using and cancel
 		private boolean useGroupNode = false;
-		private DecoratedGroupNode dGroupNode = null;
+		private Optional<GroupNode> groupNode = Optional.empty();
 		private boolean cancel = false;
 
 
@@ -259,15 +261,12 @@ public class DemoAlgo implements AddOn {
 			textArea.append(message  + "\n");
 		}
 		private void selectGroupNode() {
-			control.getSimManager().getActualVisualRepresentationalState().ifPresent(state -> {
-				Object[] possibilities = state.getCreatedGroupNodes().values().stream().map(aCps -> new Handle<DecoratedGroupNode>(aCps)).toArray();
-				@SuppressWarnings("unchecked")
-				Handle<DecoratedGroupNode> selected = (Handle<DecoratedGroupNode>) JOptionPane.showInputDialog(content, "Select GroupNode:", "GroupNode?",  JOptionPane.OK_OPTION,new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)) , possibilities, "");
-				if(selected != null) {
-					println("Selected: " + selected);
-					dGroupNode = selected.object;
-				}
-			});
+			Object[] possibilities = control.getModel().getCanvas().getAllGroupNodeObjectsRecursive().toArray();
+			GroupNode selected = (GroupNode) JOptionPane.showInputDialog(content, "Select GroupNode:", "GroupNode?",  JOptionPane.OK_OPTION,new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)) , possibilities, "");
+			if(selected != null) {
+				println("Selected: " + selected);
+				groupNode = Optional.of(selected);
+			}
 			
 		}
 		private void startTimer(){
@@ -329,9 +328,9 @@ public class DemoAlgo implements AddOn {
 		}
 		private void setAllSwitchesClosed() {
 			for(HolonSwitch hSwitch : switchList) {
-				if(hSwitch.getManualMode() == false) counter++;
-				hSwitch.setManualMode(true);
-				hSwitch.setManualState(true);
+				if(hSwitch.getManualState().isOpen()) counter++;
+				hSwitch.setMode(SwitchMode.Manual);
+				hSwitch.setManualState(SwitchState.Closed);
 			}
 			
 		}
@@ -347,7 +346,7 @@ public class DemoAlgo implements AddOn {
 			objectList = new ArrayList<HolonObject>();
 			initialState = new ArrayList<Boolean>(); 
 			access= new HashMap<Integer, AccessWrapper>();
-			rollOutNodes((useGroupNode && (dGroupNode != null))? dGroupNode.getModel().getObjectsInThisLayer() :model.getCanvas().getObjectsInThisLayer(), initialState, model.getCurrentIteration());
+			rollOutNodes((useGroupNode && groupNode.isPresent())? groupNode.get().getObjectsInThisLayer() :model.getCanvas().getObjectsInThisLayer(), initialState, model.getCurrentIteration());
 			return initialState;
 		}
 		/**
@@ -366,7 +365,7 @@ public class DemoAlgo implements AddOn {
 					objectList.add(hO);
 				}
 				else if (aCps instanceof HolonSwitch sw) {
-					positionToInit.add(sw.getState(timeStep));
+					positionToInit.add(sw.getState().isClosed());
 					switchList.add(sw);
 					access.put(positionToInit.size() - 1 , new AccessWrapper(sw));
 				}
@@ -387,7 +386,7 @@ public class DemoAlgo implements AddOn {
 				objectList.add(hObject);
 			});
 			groupNode.getAllSwitchObjectsRecursive().forEach(sw -> {
-				positionToInit.add(sw.getState(timeStep));
+				positionToInit.add(sw.getState().isClosed());
 				switchList.add(sw);
 				access.put(positionToInit.size() - 1 , new AccessWrapper(sw));
 			});
@@ -466,13 +465,13 @@ public class DemoAlgo implements AddOn {
 				if(type == HOLONELEMENT) {
 					hElement.active = state;
 				}else{//is switch
-					hSwitch.setManualMode(true);
-					hSwitch.setManualState(state);
+					hSwitch.setMode(SwitchMode.Manual);
+					hSwitch.setManualState(state? SwitchState.Closed: SwitchState.Open);
 				}
 					
 			}
 			public boolean getState(int timeStep) {
-				return (type == HOLONELEMENT)?hElement.active:hSwitch.getState(timeStep);
+				return (type == HOLONELEMENT)?hElement.active:hSwitch.getState().isClosed();
 			}
 			public int getType() {
 				return type;

+ 80 - 89
src/holeg/algorithm/example/FlexExample.java

@@ -11,6 +11,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -34,21 +35,20 @@ import holeg.model.Flexibility;
 import holeg.model.GroupNode;
 import holeg.model.HolonElement;
 import holeg.model.HolonObject;
+import holeg.model.HolonObject.HolonObjectState;
+import holeg.model.HolonSwitch.SwitchMode;
+import holeg.model.HolonSwitch.SwitchState;
 import holeg.model.HolonSwitch;
 import holeg.model.Flexibility.FlexState;
 import holeg.model.HolonElement.Priority;
 import holeg.ui.controller.Control;
-import holeg.ui.model.DecoratedGroupNode;
-import holeg.ui.model.DecoratedNetwork;
-import holeg.ui.model.DecoratedState;
 import holeg.ui.model.Model;
-import holeg.ui.model.DecoratedHolonObject.HolonObjectState;
 
 public class FlexExample implements AddOn {
 		
 		//Settings For GroupNode using and cancel
 		private boolean useGroupNode = false;
-		private DecoratedGroupNode dGroupNode = null;
+		private Optional<GroupNode> groupnode = Optional.empty();
 		private boolean cancel = false;
 		private boolean overAllTimeSteps = false;
 		
@@ -286,15 +286,13 @@ public class FlexExample implements AddOn {
 			textArea.append(message  + "\n");
 		}
 		private void selectGroupNode() {
-			control.getSimManager().getActualVisualRepresentationalState().ifPresent(state -> {
-				Object[] possibilities = state.getCreatedGroupNodes().values().stream().map(aCps -> new Handle<DecoratedGroupNode>(aCps)).toArray();
-				@SuppressWarnings("unchecked")
-				Handle<DecoratedGroupNode> selected = (Handle<DecoratedGroupNode>) JOptionPane.showInputDialog(content, "Select GroupNode:", "GroupNode?",  JOptionPane.OK_OPTION,new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)) , possibilities, "");
-				if(selected != null) {
-					println("Selected: " + selected);
-					dGroupNode = selected.object;
-				}
-			});
+			Object[] possibilities = control.getModel().getCanvas().getAllGroupNodeObjectsRecursive().toArray();
+			@SuppressWarnings("unchecked")
+			GroupNode selected = (GroupNode) JOptionPane.showInputDialog(content, "Select GroupNode:", "GroupNode?",  JOptionPane.OK_OPTION,new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)) , possibilities, "");
+			if(selected != null) {
+				println("Selected: " + selected);
+				groupnode = Optional.of(selected);
+			}
 			
 		}
 		private void startTimer(){
@@ -339,73 +337,73 @@ public class FlexExample implements AddOn {
 			println("TimeStep:" + actualIteration);
 			control.calculateStateOnlyForCurrentTimeStep();
 			List<Priority> priorityListASC = createPriorityListASC();
-			DecoratedState actualstate = control.getSimManager().getActualDecorState().get();	
-			for(DecoratedNetwork net : actualstate.getNetworkList()) {
-				float production = net.getSupplierList().stream().map(supplier -> supplier.getEnergyToSupplyNetwork()).reduce(0.0f, (a, b) -> a + b);
-				float consumption = net.getConsumerList().stream().map(con -> con.getEnergyNeededFromNetwork()).reduce(0.0f, (a, b) -> a + b);
-				float difference = Math.abs(production - consumption);
-				println("production: " + production);
-				println("consumption: " + consumption);
-				println("difference: " + difference);
-				if(production > consumption) continue;
-				if(difference == 0)continue;
-				Set<HolonElement> allHolonElemntsInThisNetwork = createListOfAllHolonElemnts(net);
-				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);
-				//ShuddownPriorities
-				for(Priority emergencyShutDownPriority: priorityListASC) {
-					if(amountOfAllEnergyOffered >= difference) break; 
-					println("ShutDown: " + emergencyShutDownPriority);
-					difference -= shutDownAllConsumerElementsWithPriority(allHolonElemntsInThisNetwork, emergencyShutDownPriority, result);
-				}
-				
-				//SortFlexes
-				allFlexThatGetMeEnergy.sort((flex1, flex2) -> Float.compare(flex1.cost / flex1.energyReleased(), flex2.cost / flex2.energyReleased()));
-				//OrderFlexes
-				float costForThisTimeStep = 0f;
-				int amountflexActivated = 0;
-				for(Flexibility flex : allFlexThatGetMeEnergy) {
-					if(!flex.canOrder()) continue;
-					float energy = flex.energyReleased();
-					if(energy <= difference) {
-						println("energyGained:" + energy);
-						difference -= energy;
-						costForThisTimeStep += flex.cost;
-						flex.order();
-						amountflexActivated++;
-						continue;
-					}
-				}
-				result.activatedFlex += 	amountflexActivated;
-				
-				println("Activated FlexThisTimeStep: "+ amountflexActivated+"   CostForThisTimeStep:" + costForThisTimeStep);
-				result.totalCost += costForThisTimeStep;
-			}
+//			DecoratedState actualstate = control.getSimManager().getActualDecorState().get();	
+//			for(DecoratedNetwork net : actualstate.getNetworkList()) {
+//				float production = net.getSupplierList().stream().map(supplier -> supplier.getEnergyToSupplyNetwork()).reduce(0.0f, (a, b) -> a + b);
+//				float consumption = net.getConsumerList().stream().map(con -> con.getEnergyNeededFromNetwork()).reduce(0.0f, (a, b) -> a + b);
+//				float difference = Math.abs(production - consumption);
+//				println("production: " + production);
+//				println("consumption: " + consumption);
+//				println("difference: " + difference);
+//				if(production > consumption) continue;
+//				if(difference == 0)continue;
+//				Set<HolonElement> allHolonElemntsInThisNetwork = createListOfAllHolonElemnts(net);
+//				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);
+//				//ShuddownPriorities
+//				for(Priority emergencyShutDownPriority: priorityListASC) {
+//					if(amountOfAllEnergyOffered >= difference) break; 
+//					println("ShutDown: " + emergencyShutDownPriority);
+//					difference -= shutDownAllConsumerElementsWithPriority(allHolonElemntsInThisNetwork, emergencyShutDownPriority, result);
+//				}
+//				
+//				//SortFlexes
+//				allFlexThatGetMeEnergy.sort((flex1, flex2) -> Float.compare(flex1.cost / flex1.energyReleased(), flex2.cost / flex2.energyReleased()));
+//				//OrderFlexes
+//				float costForThisTimeStep = 0f;
+//				int amountflexActivated = 0;
+//				for(Flexibility flex : allFlexThatGetMeEnergy) {
+//					if(!flex.canOrder()) continue;
+//					float energy = flex.energyReleased();
+//					if(energy <= difference) {
+//						println("energyGained:" + energy);
+//						difference -= energy;
+//						costForThisTimeStep += flex.cost;
+//						flex.order();
+//						amountflexActivated++;
+//						continue;
+//					}
+//				}
+//				result.activatedFlex += 	amountflexActivated;
+//				
+//				println("Activated FlexThisTimeStep: "+ amountflexActivated+"   CostForThisTimeStep:" + costForThisTimeStep);
+//				result.totalCost += costForThisTimeStep;
+//			}
 			calculateStateResult(result);
 		}
 		private void calculateStateResult(RunResult result) {
 			control.calculateStateOnlyForCurrentTimeStep();
-			RunResult.TimeStepStateResult timeStepState = result.addTimeStepStateResult();
-			
-			for(DecoratedNetwork network: control.getSimManager().getActualDecorState().get().getNetworkList()) {
-				timeStepState.amountOfConsumer += network.getAmountOfConsumer();
-				timeStepState.amountOfConsumerOverSupplied += network.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED);
-				timeStepState.amountOfConsumerPartiallySupplied += network.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED);
-				timeStepState.amountOfConsumerSupplied += network.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED);
-				timeStepState.amountOfConsumerUnSupplied += network.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED);
-				timeStepState.amountOfPassiv += network.getAmountOfPassiv();
-				timeStepState.amountOfProducer += network.getAmountOfSupplier();	
-			}
-			println("Producer: " + timeStepState.amountOfProducer);
-			println("Consumer: " + timeStepState.amountOfConsumer);
-			println("ConsumerOverSupplied: " + timeStepState.amountOfConsumerOverSupplied);
-			println("ConsumerSupplied: " + timeStepState.amountOfConsumerSupplied);
-			println("ConsumerPartiallySupplied: " + timeStepState.amountOfConsumerPartiallySupplied);
-			println("ConsumerUnSupplied: " + timeStepState.amountOfConsumerUnSupplied);
-			println("ConsumerUnSupplied: " + timeStepState.amountOfPassiv);
+//			RunResult.TimeStepStateResult timeStepState = result.addTimeStepStateResult();
+//			
+//			for(DecoratedNetwork network: control.getSimManager().getActualDecorState().get().getNetworkList()) {
+//				timeStepState.amountOfConsumer += network.getAmountOfConsumer();
+//				timeStepState.amountOfConsumerOverSupplied += network.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED);
+//				timeStepState.amountOfConsumerPartiallySupplied += network.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED);
+//				timeStepState.amountOfConsumerSupplied += network.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED);
+//				timeStepState.amountOfConsumerUnSupplied += network.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED);
+//				timeStepState.amountOfPassiv += network.getAmountOfPassiv();
+//				timeStepState.amountOfProducer += network.getAmountOfSupplier();	
+//			}
+//			println("Producer: " + timeStepState.amountOfProducer);
+//			println("Consumer: " + timeStepState.amountOfConsumer);
+//			println("ConsumerOverSupplied: " + timeStepState.amountOfConsumerOverSupplied);
+//			println("ConsumerSupplied: " + timeStepState.amountOfConsumerSupplied);
+//			println("ConsumerPartiallySupplied: " + timeStepState.amountOfConsumerPartiallySupplied);
+//			println("ConsumerUnSupplied: " + timeStepState.amountOfConsumerUnSupplied);
+//			println("ConsumerUnSupplied: " + timeStepState.amountOfPassiv);
 		}
 		private void calculateAllResults(RunResult result) {
 			println("----------");
@@ -433,13 +431,6 @@ public class FlexExample implements AddOn {
 			println("Gained " + energyGained + "Energy from Shutdown with Priority:" + emergencyShutDownPriority + " AmountOfShutDowned HolonElements: " + shutdownCount);
 			return energyGained;
 		}
-		private Set<HolonElement> createListOfAllHolonElemnts(DecoratedNetwork net) {
-			Set<HolonElement> allHolonElemntsInThisNetwork = new HashSet<HolonElement>();
-			allHolonElemntsInThisNetwork.addAll(net.getConsumerList().stream().flatMap(con -> con.getModel().getElements()).collect(Collectors.toList()));
-			allHolonElemntsInThisNetwork.addAll(net.getConsumerSelfSuppliedList().stream().flatMap(con -> con.getModel().getElements()).collect(Collectors.toList()));
-			allHolonElemntsInThisNetwork.addAll(net.getSupplierList().stream().flatMap(con -> con.getModel().getElements()).collect(Collectors.toList()));
-			return allHolonElemntsInThisNetwork;
-		}
 
 	
 		private float sumEnergyAvailable(List<Flexibility> flexList) {
@@ -467,7 +458,7 @@ public class FlexExample implements AddOn {
 			objectList = new ArrayList<HolonObject>();
 			initialState = new ArrayList<Boolean>();
 			access= new HashMap<Integer, AccessWrapper>();
-			rollOutNodes((useGroupNode && (dGroupNode != null))? dGroupNode.getModel().getObjectsInThisLayer() :model.getCanvas().getObjectsInThisLayer(), initialState, model.getCurrentIteration());			
+			rollOutNodes((useGroupNode && (groupnode.isPresent()))? groupnode.get().getObjectsInThisLayer() :model.getCanvas().getObjectsInThisLayer(), initialState, model.getCurrentIteration());			
 			resetChain.add(initialState); 
 			return initialState;
 		}
@@ -487,7 +478,7 @@ public class FlexExample implements AddOn {
 					objectList.add(hO);
 				}
 				else if (aCps instanceof HolonSwitch sw) {
-					positionToInit.add(sw.getState(timeStep));
+					positionToInit.add(sw.getState().isClosed());
 					switchList.add(sw);
 					access.put(positionToInit.size() - 1 , new AccessWrapper(sw));
 				}
@@ -508,7 +499,7 @@ public class FlexExample implements AddOn {
 				objectList.add(hObject);
 			});
 			groupNode.getAllSwitchObjectsRecursive().forEach(sw -> {
-				positionToInit.add(sw.getState(timeStep));
+				positionToInit.add(sw.getState().isClosed());
 				switchList.add(sw);
 				access.put(positionToInit.size() - 1 , new AccessWrapper(sw));
 			});
@@ -564,8 +555,8 @@ public class FlexExample implements AddOn {
 				if(type == HOLONELEMENT) {
 					hElement.active = state;
 				}else{//is switch
-					hSwitch.setManualMode(true);
-					hSwitch.setManualState(state);
+					hSwitch.setMode(SwitchMode.Manual);
+					hSwitch.setManualState(state ? SwitchState.Closed : SwitchState.Open);
 				}
 					
 			}

+ 33 - 33
src/holeg/algorithm/objective_function/Evaluation.java

@@ -4,12 +4,12 @@ import java.util.List;
 
 import holeg.model.Flexibility;
 import holeg.model.HolonObject;
+import holeg.model.HolonObject.HolonObjectState;
 import holeg.model.Flexibility.FlexState;
 import holeg.model.HolonElement.Priority;
-import holeg.ui.model.DecoratedNetwork;
-import holeg.ui.model.DecoratedState;
-import holeg.ui.model.DecoratedHolonObject.HolonObjectState;
+import holeg.ui.model.Model;
 
+//TODO(Tom2022-01-13) Fix Evaluation
 public class Evaluation {
 	
 	/**
@@ -17,41 +17,41 @@ public class Evaluation {
 	 * @param state
 	 * @return
 	 */
-	public static double getFitnessValueForState(DecoratedState state) {
+	public static double getFitnessValueForState(Model model) {
 		double fitness = 0.0;
 		double nw_fitness =0.0;
 		double object_fitness = 0.0;
 		double flexFitness = 0.0;
 		
-		double sigma = 9;
-		
-		// calculate network_fitness
-		for(DecoratedNetwork net : state.getNetworkList()) {
-			float production = net.getSupplierList().stream().map(supplier -> supplier.getEnergyToSupplyNetwork()).reduce(0.0f, (a, b) -> a + b);
-			float consumption = net.getConsumerList().stream().map(con -> con.getEnergyNeededFromNetwork()).reduce(0.0f, (a, b) -> a + b);
-			nw_fitness += Math.abs((production - consumption)/100); //Energy is now everywhere positive
-		}
-		
-		// calculate object_fitness
-		for(DecoratedNetwork net : state.getNetworkList()) {
-
-			object_fitness += net.getConsumerList().stream().map(con -> holonObjectSupplyPenaltyFunction(con.getSupplyBarPercentage()) /*+ inactiveHolonElementPenalty(con.getModel())*/).reduce(0.0, (a, b) -> (a + b));
-			object_fitness += net.getConsumerList().stream().map(con -> StateToDouble(con.getState())).reduce(0.0, (a,b) -> (a+b));
-			//object_fitness += net.getPassivNoEnergyList().stream().map(sup -> inactiveHolonElementPenalty(sup.getModel())).reduce(0.0, (a, b) -> (a + b));
-			//object_fitness += net.getSupplierList().stream().map(sup -> inactiveHolonElementPenalty(sup.getModel())).reduce(0.0, (a, b) -> (a + b));
-			//object_fitness += net.getConsumerSelfSuppliedList().stream().map(con -> inactiveHolonElementPenalty(con.getModel())).reduce(0.0, (a, b) -> (a + b));
-
-		}
-		// calculate flexibility fitness old cost flex
-		/*for(FlexWrapper flexWrapper :state.getFlexManager().getAllFlexWrapperWithState(FlexState.IN_USE)) {
-			flexFitness += flexWrapper.cost / (double)flexWrapper.getDuration();
-		}*/
-		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;
+//		double sigma = 9;
+//		
+//		// calculate network_fitness
+//		for(DecoratedNetwork net : state.getNetworkList()) {
+//			float production = net.getSupplierList().stream().map(supplier -> supplier.getEnergyToSupplyNetwork()).reduce(0.0f, (a, b) -> a + b);
+//			float consumption = net.getConsumerList().stream().map(con -> con.getEnergyNeededFromNetwork()).reduce(0.0f, (a, b) -> a + b);
+//			nw_fitness += Math.abs((production - consumption)/100); //Energy is now everywhere positive
+//		}
+//		
+//		// calculate object_fitness
+//		for(DecoratedNetwork net : state.getNetworkList()) {
+//
+//			object_fitness += net.getConsumerList().stream().map(con -> holonObjectSupplyPenaltyFunction(con.getSupplyBarPercentage()) /*+ inactiveHolonElementPenalty(con.getModel())*/).reduce(0.0, (a, b) -> (a + b));
+//			object_fitness += net.getConsumerList().stream().map(con -> StateToDouble(con.getState())).reduce(0.0, (a,b) -> (a+b));
+//			//object_fitness += net.getPassivNoEnergyList().stream().map(sup -> inactiveHolonElementPenalty(sup.getModel())).reduce(0.0, (a, b) -> (a + b));
+//			//object_fitness += net.getSupplierList().stream().map(sup -> inactiveHolonElementPenalty(sup.getModel())).reduce(0.0, (a, b) -> (a + b));
+//			//object_fitness += net.getConsumerSelfSuppliedList().stream().map(con -> inactiveHolonElementPenalty(con.getModel())).reduce(0.0, (a, b) -> (a + b));
+//
+//		}
+//		// calculate flexibility fitness old cost flex
+//		/*for(FlexWrapper flexWrapper :state.getFlexManager().getAllFlexWrapperWithState(FlexState.IN_USE)) {
+//			flexFitness += flexWrapper.cost / (double)flexWrapper.getDuration();
+//		}*/
+//		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;
 		return fitness;
 	}
 

+ 83 - 85
src/holeg/algorithm/objective_function/GraphMetrics.java

@@ -11,13 +11,11 @@ import java.util.logging.Logger;
 
 import holeg.model.AbstractCanvasObject;
 import holeg.model.HolonSwitch;
-import holeg.ui.model.Consumer;
-import holeg.ui.model.DecoratedNetwork;
-import holeg.ui.model.Passiv;
-import holeg.ui.model.Supplier;
+import holeg.ui.model.Model;
 
 import java.util.Set;
 
+//TODO(Tom2022-01-13) Fix GraphMetrics
 public class GraphMetrics {
 	private static final Logger log = Logger.getLogger(GraphMetrics.class.getName());
 	
@@ -61,94 +59,94 @@ public class GraphMetrics {
 	 * @param net
 	 * @return a equivalent Graph to the DecoratedNetwork
 	 */
-	public static Graph convertDecoratedNetworkToGraph(DecoratedNetwork net) {
+	public static Graph convertDecoratedNetworkToGraph(Model model) {
 		Graph G = new Graph();
 		HashMap<AbstractCanvasObject, Integer> objectToId = new HashMap<>();
 		List<Integer> sourcesList = new ArrayList<Integer>();
 		int count = 0;
-		for(Consumer con: net.getConsumerList()) {
-			objectToId.put(con.getModel(), count);
-			sourcesList.add(count);
-			count++;
-		}
-		for(Consumer con: net.getConsumerSelfSuppliedList()) {
-			objectToId.put(con.getModel(), count);
-			sourcesList.add(count);
-			count++;
-		}
-		for(Passiv pas: net.getPassivNoEnergyList()) {
-			objectToId.put(pas.getModel(), count);
-			sourcesList.add(count);
-			count++;
-		}
-		for(Supplier sup: net.getSupplierList()) {
-			objectToId.put(sup.getModel(), count);
-			sourcesList.add(count);
-			count++;
-		}
-		
+//		for(Consumer con: net.getConsumerList()) {
+//			objectToId.put(con.getModel(), count);
+//			sourcesList.add(count);
+//			count++;
+//		}
+//		for(Consumer con: net.getConsumerSelfSuppliedList()) {
+//			objectToId.put(con.getModel(), count);
+//			sourcesList.add(count);
+//			count++;
+//		}
+//		for(Passiv pas: net.getPassivNoEnergyList()) {
+//			objectToId.put(pas.getModel(), count);
+//			sourcesList.add(count);
+//			count++;
+//		}
+//		for(Supplier sup: net.getSupplierList()) {
+//			objectToId.put(sup.getModel(), count);
+//			sourcesList.add(count);
+//			count++;
+//		}
+//		
 		
 		
 		//Generate EdgeList 
-		List<Edge> edgeList = new ArrayList<Edge>();
-		for(holeg.model.Edge cable : net.getDecoratedCableList()){
-			
-			AbstractCanvasObject objectA = cable.getA();
-			AbstractCanvasObject objectB = cable.getB();
-			if(objectA == null) {
-				log.warning("Edge: " + cable + "objectA == null");
-				continue;
-			}
-			if(objectB == null) {
-				log.warning("Edge: " + cable + "objectB == null");
-				continue;
-			}
-			
-			//SpecialCase for open switches
-			if(objectA instanceof HolonSwitch sw && !sw.getManualState()) {
-				continue;
-			}
-			if(objectB instanceof HolonSwitch sw && !sw.getManualState()) {
-				continue;
-			}
-			
-			int idA = -1;
-			if(objectToId.containsKey(objectA)) {
-				idA = objectToId.get(objectA);
-			}else {
-				idA = count;
-				objectToId.put(objectA, count++);
-			}
-			int idB = -1;
-			if(objectToId.containsKey(objectB)) {
-				idB = objectToId.get(objectB);
-			}else {
-				idB = count;
-				objectToId.put(objectB, count++);
-			}
-			double length = cable.getLength();
-			edgeList.add(new Edge(idA, idB, length));
-		}
-		//Generate EdgeArray
-		G.E = new Edge[edgeList.size()];
-		for(int i=0;i<edgeList.size();i++)
-	    {
-				G.E[i] =  edgeList.get(i);
-	    }
-		//Generate VertexArray
-		G.V = new Vertex[objectToId.size()];
-		int entryCount = 0;
-		for(Entry<AbstractCanvasObject, Integer> entry : objectToId.entrySet()) {
-			G.V[entryCount] =  new Vertex(entry.getValue());
-			entryCount++;
-		}
-		//Generate Sources Array
-		int sourceCount = 0;
-		G.S = new Vertex[sourcesList.size()];
-		for(int source : sourcesList) {
-			G.S[sourceCount] = new Vertex(source);
-			sourceCount++;
-		}
+//		List<Edge> edgeList = new ArrayList<Edge>();
+//		for(holeg.model.Edge cable : net.getDecoratedCableList()){
+//			
+//			AbstractCanvasObject objectA = cable.getA();
+//			AbstractCanvasObject objectB = cable.getB();
+//			if(objectA == null) {
+//				log.warning("Edge: " + cable + "objectA == null");
+//				continue;
+//			}
+//			if(objectB == null) {
+//				log.warning("Edge: " + cable + "objectB == null");
+//				continue;
+//			}
+//			
+//			//SpecialCase for open switches
+//			if(objectA instanceof HolonSwitch sw && !sw.getManualState()) {
+//				continue;
+//			}
+//			if(objectB instanceof HolonSwitch sw && !sw.getManualState()) {
+//				continue;
+//			}
+//			
+//			int idA = -1;
+//			if(objectToId.containsKey(objectA)) {
+//				idA = objectToId.get(objectA);
+//			}else {
+//				idA = count;
+//				objectToId.put(objectA, count++);
+//			}
+//			int idB = -1;
+//			if(objectToId.containsKey(objectB)) {
+//				idB = objectToId.get(objectB);
+//			}else {
+//				idB = count;
+//				objectToId.put(objectB, count++);
+//			}
+//			double length = cable.getLength();
+//			edgeList.add(new Edge(idA, idB, length));
+//		}
+//		//Generate EdgeArray
+//		G.E = new Edge[edgeList.size()];
+//		for(int i=0;i<edgeList.size();i++)
+//	    {
+//				G.E[i] =  edgeList.get(i);
+//	    }
+//		//Generate VertexArray
+//		G.V = new Vertex[objectToId.size()];
+//		int entryCount = 0;
+//		for(Entry<AbstractCanvasObject, Integer> entry : objectToId.entrySet()) {
+//			G.V[entryCount] =  new Vertex(entry.getValue());
+//			entryCount++;
+//		}
+//		//Generate Sources Array
+//		int sourceCount = 0;
+//		G.S = new Vertex[sourcesList.size()];
+//		for(int source : sourcesList) {
+//			G.S[sourceCount] = new Vertex(source);
+//			sourceCount++;
+//		}
 		return G;
 	}
 	

+ 82 - 81
src/holeg/algorithm/objective_function/ObjectiveFunctionByCarlos.java

@@ -6,8 +6,7 @@ import java.util.logging.Logger;
 import holeg.model.Flexibility;
 import holeg.model.Flexibility.FlexState;
 import holeg.model.HolonElement.Priority;
-import holeg.ui.model.DecoratedNetwork;
-import holeg.ui.model.DecoratedState;
+import holeg.ui.model.Model;
 
 public class ObjectiveFunctionByCarlos {
 	// Parameters
@@ -81,85 +80,87 @@ public class ObjectiveFunctionByCarlos {
 	 * @param state
 	 * @return f_g value between 0 and 100
 	 */
-	static public double getFitnessValueForState(DecoratedState state) {
-
-		// Calculate f_eb the penalty for unbalenced energy in the network
-		double f_eb = 0;
-		// sum over all objects
-		for (DecoratedNetwork net : state.getNetworkList()) {
-			double netEnergyDifference = 0;
-			netEnergyDifference += net.getConsumerList().stream()
-					.map(con -> con.getEnergySelfSupplied() - con.getEnergyFromConsumingElemnets())
-					.reduce(0.f, Float::sum);
-			netEnergyDifference += net.getConsumerSelfSuppliedList().stream()
-					.map(con -> con.getEnergySelfSupplied() - con.getEnergyFromConsumingElemnets())
-					.reduce(0.f, Float::sum);
-			netEnergyDifference += net.getSupplierList().stream()
-					.map(sup -> sup.getEnergyProducing() - sup.getEnergySelfConsuming()).reduce(0.f, Float::sum);
-			// abs
-			f_eb += Math.abs(netEnergyDifference);
-		}
-
-		// Calculate f_state the penalty function for the supply state
-		double f_state = 0;
-		for (DecoratedNetwork net : state.getNetworkList()) {
-			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
-
-		List<Flexibility> allFlexOrdered = state.getAllFlex().filter(flex -> flex.getState().equals(FlexState.IN_USE))
-				.toList();
-		double f_pro = 0;
-		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 : allFlexOrdered) {
-			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.getDeviationInProductionInNetworkForHolonObjects();
-			double f_elements_diviation_consumption = net.getDeviationInProductionInNetworkForHolonObjects();
-			double f_flexibility_diviation_consumption = net.getDiviationInFlexibilityConsumption();
-			double f_flexibility_diviation_production = net.getDiviationInFlexibilityProduction();
-
-			double con = net.getTotalConsumption();
-			double prod = net.getTotalProduction();
-			double flexcapProd = net.getFlexibilityProductionCapacity();
-			double flexcapCon = net.getFlexibilityConsumptionCapacity();
-			double f_change_positive = lambda_f_change
-					- lambda_f_change * Math.min(1, (con > 0.0) ? flexcapProd / con : 1.0);
-			double f_change_negativ = lambda_f_change
-					- lambda_f_change * Math.min(1, (prod > 0.0) ? flexcapCon / prod : 1.0);
-
-			double f_element = f_elements_diviation_production + f_elements_diviation_consumption;
-			double f_flexibility = f_flexibility_diviation_consumption + f_flexibility_diviation_production;
-			double f_change = f_change_positive + f_change_negativ;
-
-			f_holon += f_element + f_flexibility + f_change;
-		}
-		double q1 = squash(f_eb, k_eb);
-		double q2 = squash(f_state, k_state);
-		double q3 = squash(f_pro, k_pro);
-		double q4 = squash(f_perf, k_perf);
-		double q5 = squash(f_holon, k_holon);
-		log.finer("f_eb= " + f_eb + " f_state= " + f_state + " f_pro= " + f_pro + " f_perf= " + f_perf + " f_holon= "
-				+ f_holon + " q1= " + q1 + " q2= " + q2 + " q3= " + q3 + " q4= " + q4 + " q5= " + q5);
-
-		return w_eb * q1 + w_state * q2 + w_pro * q3 + w_perf * q4 + w_holon * q5;
+	//TODO(Tom2022-01-13) Fix ObjectiveFunctionByCarlos
+	static public double getFitnessValueForState(Model model) {
+
+//		// Calculate f_eb the penalty for unbalenced energy in the network
+//		double f_eb = 0;
+//		// sum over all objects
+//		for (DecoratedNetwork net : state.getNetworkList()) {
+//			double netEnergyDifference = 0;
+//			netEnergyDifference += net.getConsumerList().stream()
+//					.map(con -> con.getEnergySelfSupplied() - con.getEnergyFromConsumingElemnets())
+//					.reduce(0.f, Float::sum);
+//			netEnergyDifference += net.getConsumerSelfSuppliedList().stream()
+//					.map(con -> con.getEnergySelfSupplied() - con.getEnergyFromConsumingElemnets())
+//					.reduce(0.f, Float::sum);
+//			netEnergyDifference += net.getSupplierList().stream()
+//					.map(sup -> sup.getEnergyProducing() - sup.getEnergySelfConsuming()).reduce(0.f, Float::sum);
+//			// abs
+//			f_eb += Math.abs(netEnergyDifference);
+//		}
+//
+//		// Calculate f_state the penalty function for the supply state
+//		double f_state = 0;
+//		for (DecoratedNetwork net : state.getNetworkList()) {
+//			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
+//
+//		List<Flexibility> allFlexOrdered = state.getAllFlex().filter(flex -> flex.getState().equals(FlexState.IN_USE))
+//				.toList();
+//		double f_pro = 0;
+//		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 : allFlexOrdered) {
+//			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.getDeviationInProductionInNetworkForHolonObjects();
+//			double f_elements_diviation_consumption = net.getDeviationInProductionInNetworkForHolonObjects();
+//			double f_flexibility_diviation_consumption = net.getDiviationInFlexibilityConsumption();
+//			double f_flexibility_diviation_production = net.getDiviationInFlexibilityProduction();
+//
+//			double con = net.getTotalConsumption();
+//			double prod = net.getTotalProduction();
+//			double flexcapProd = net.getFlexibilityProductionCapacity();
+//			double flexcapCon = net.getFlexibilityConsumptionCapacity();
+//			double f_change_positive = lambda_f_change
+//					- lambda_f_change * Math.min(1, (con > 0.0) ? flexcapProd / con : 1.0);
+//			double f_change_negativ = lambda_f_change
+//					- lambda_f_change * Math.min(1, (prod > 0.0) ? flexcapCon / prod : 1.0);
+//
+//			double f_element = f_elements_diviation_production + f_elements_diviation_consumption;
+//			double f_flexibility = f_flexibility_diviation_consumption + f_flexibility_diviation_production;
+//			double f_change = f_change_positive + f_change_negativ;
+//
+//			f_holon += f_element + f_flexibility + f_change;
+//		}
+//		double q1 = squash(f_eb, k_eb);
+//		double q2 = squash(f_state, k_state);
+//		double q3 = squash(f_pro, k_pro);
+//		double q4 = squash(f_perf, k_perf);
+//		double q5 = squash(f_holon, k_holon);
+//		log.finer("f_eb= " + f_eb + " f_state= " + f_state + " f_pro= " + f_pro + " f_perf= " + f_perf + " f_holon= "
+//				+ f_holon + " q1= " + q1 + " q2= " + q2 + " q3= " + q3 + " q4= " + q4 + " q5= " + q5);
+//
+//		return w_eb * q1 + w_state * q2 + w_pro * q3 + w_perf * q4 + w_holon * q5;
+		return 0;
 	}
 
 	/**

+ 23 - 23
src/holeg/algorithm/objective_function/SwitchObjectiveFunction.java

@@ -1,7 +1,7 @@
 package holeg.algorithm.objective_function;
 
-import holeg.ui.model.DecoratedNetwork;
-import holeg.ui.model.DecoratedState;
+import holeg.ui.model.Model;
+
 public class SwitchObjectiveFunction {
 	
 	//weights
@@ -11,29 +11,29 @@ public class SwitchObjectiveFunction {
 	static double squash_subtract = 1.0f / (1.f + (float) Math.exp(5.0));
 	
 	
-	
-	static public float getFitnessValueForState(DecoratedState state) {
+	//TODO(Tom2022-01-13) Fix SwitchObjectiveFunction
+	static public float getFitnessValueForState(Model model) {
 		double f_eb = 0;
 		double f_state = 0;
-		double elementCountInNetwork = state.getNetworkList().stream().map(net -> net.getAmountOfElements()).reduce(0, Integer::sum);
-		//sum over all objects
-		for(DecoratedNetwork net : state.getNetworkList()) {
-			
-			//weigt
-			double w_network = net.getAmountOfElements()/elementCountInNetwork;
-			
-			//f_eb
-			double netEnergyDifference = 0;
-			netEnergyDifference += net.getConsumerList().stream().map(con -> con.getEnergySelfSupplied() - con.getEnergyFromConsumingElemnets()).reduce(0.f, Float::sum);
-			netEnergyDifference += net.getConsumerSelfSuppliedList().stream().map(con -> con.getEnergySelfSupplied() - con.getEnergyFromConsumingElemnets()).reduce(0.f, Float::sum);
-			netEnergyDifference += net.getSupplierList().stream().map(sup -> sup.getEnergyProducing() - sup.getEnergySelfConsuming()).reduce(0.f, Float::sum);
-			//abs
-			f_eb += w_network * Math.abs(netEnergyDifference);
-			
-			
-			//f_state
-			f_state += w_network * net.getConsumerList().stream().map(con -> supplyPenalty(con.getSupplyBarPercentage())).reduce(0., Double::sum);
-		}
+//		double elementCountInNetwork = state.getNetworkList().stream().map(net -> net.getAmountOfElements()).reduce(0, Integer::sum);
+//		//sum over all objects
+//		for(DecoratedNetwork net : state.getNetworkList()) {
+//			
+//			//weigt
+//			double w_network = net.getAmountOfElements()/elementCountInNetwork;
+//			
+//			//f_eb
+//			double netEnergyDifference = 0;
+//			netEnergyDifference += net.getConsumerList().stream().map(con -> con.getEnergySelfSupplied() - con.getEnergyFromConsumingElemnets()).reduce(0.f, Float::sum);
+//			netEnergyDifference += net.getConsumerSelfSuppliedList().stream().map(con -> con.getEnergySelfSupplied() - con.getEnergyFromConsumingElemnets()).reduce(0.f, Float::sum);
+//			netEnergyDifference += net.getSupplierList().stream().map(sup -> sup.getEnergyProducing() - sup.getEnergySelfConsuming()).reduce(0.f, Float::sum);
+//			//abs
+//			f_eb += w_network * Math.abs(netEnergyDifference);
+//			
+//			
+//			//f_state
+//			f_state += w_network * net.getConsumerList().stream().map(con -> supplyPenalty(con.getSupplyBarPercentage())).reduce(0., Double::sum);
+//		}
 		return (float) (w_eb*squash(f_eb, k_eb) + w_state*squash(f_state, k_state));
 	}
 	

+ 137 - 137
src/holeg/algorithm/objective_function/TopologieObjectiveFunction.java

@@ -5,9 +5,7 @@ import java.util.Locale;
 import java.util.logging.Logger;
 
 import holeg.algorithm.objective_function.GraphMetrics.Graph;
-import holeg.ui.model.DecoratedHolonObject;
-import holeg.ui.model.DecoratedNetwork;
-import holeg.ui.model.DecoratedState;
+import holeg.ui.model.Model;
 import holeg.utility.math.decimal.Sampler;
 
 public class TopologieObjectiveFunction {
@@ -100,141 +98,143 @@ public class TopologieObjectiveFunction {
 	 * @param moreInformation if more prints should be made
 	 * @return f_g value between 0 and 100
 	 */
-	static public float getFitnessValueForState(DecoratedState state, int amountOfAddedSwitch, double addedCableMeters, boolean moreInformation) {
-		
-		
-
-		//Calculate f_eb the penalty for unbalenced energy in the network
-		double f_eb = 0;
-		for(DecoratedNetwork net : state.getNetworkList()) {
-			//abs
-			f_eb += Math.abs(net.getTotalConsumption() - net.getTotalProduction());
-		}
-		//Average?
-		f_eb /= state.getNetworkList().size();
-		
-		
-		
-		
-		double f_maximum = 0;
-		for(DecoratedNetwork net : state.getNetworkList()) {
-			double prod = net.getTotalProduction();
-			double con = net.getTotalConsumption();
-			if(prod == 0 || con == 0) {
-				f_maximum += lambda_max;
-			}else {
-				f_maximum += lambda_max * (Math.abs(prod - con)/Math.max(prod, con));				
-			}
-		}
-		//Average?
-		f_maximum /= state.getNetworkList().size();
-		
-		//calculate f_holon
-		double f_holon = 0;
-		for(DecoratedNetwork net : state.getNetworkList()) {
-			double f_elements_deviation_production = net.getDeviationInProductionInNetworkForHolonObjects();
-			double f_elements_deviation_consumption = net.getDeviationInConsumptionInNetworkForHolonObjects();
-			double f_element = f_elements_deviation_production+f_elements_deviation_consumption;
-			f_holon += f_element;
-		}
-		f_holon /= state.getNetworkList().size();
-		
-		//calculating f_selection
-		double f_selection = calculateTopologieCost(state, amountOfAddedSwitch, addedCableMeters);
-		//if(moreInformation)LOGGER.info("CostForWildcards:" + cost + ", CostSwitches(#" + amountOfAddedSwitch +"):" + cost_switch * amountOfAddedSwitch + ", CostCables(" +addedCableMeters+ "m):" + cost_of_cable_per_meter * addedCableMeters);
-		
-		
-		//calculating f_grid
-		double f_grid = 0;
-		//each network is a holon
-		for(DecoratedNetwork net: state.getNetworkList()) {
-			Graph G = GraphMetrics.convertDecoratedNetworkToGraph(net);
-			//We have to penalize single Networks;
-			if(G.V.length <= 1 || G.S.length <= 1) {
-				f_grid += lambda_avg_shortest_path;// + lambda_disjoint_path;
-				continue;
-			}
-		
-			double avgShortestPath = GraphMetrics.averageShortestDistance(G);
-			//double disjpointPaths = GraphMetrics.averageEdgeDisjointPathProblem(G);
-			if(useLog) {
-				averageLog.addSample("avgShortestPath", (float)avgShortestPath);
-			}
-			f_grid += avgShortestPathPenalty(avgShortestPath);// + disjoinPathPenalty(disjpointPaths);
-		}
-		//take average to encourage splitting
-		f_grid /= state.getNetworkList().size();
-		
-		
-		
-		
-		if(moreInformation) {
-			printWeightedValues(f_eb, f_maximum, f_holon, f_selection, f_grid);
-			if(useLog) {
-				log.info(averageLog.toString());
-			}
-		}
-		//printUnsquashedValues(f_eb, f_maximum, f_holon, f_selection, f_grid);
-		if(useLog) {
-			averageLog.addSample("Unsquashed f_eb", (float)f_eb);
-			averageLog.addSample("Unsquashed f_maximum", (float)f_maximum);
-			averageLog.addSample("Unsquashed f_holon", (float)f_holon);
-			averageLog.addSample("Unsquashed f_selection", (float)f_selection);
-			averageLog.addSample("Unsquashed f_grid", (float)f_grid);
-		}
-		return (float) (w_eb * squash(f_eb, k_eb) 
-				+ w_max * squash(f_maximum, k_max) 
-				+ w_holon * squash(f_holon, k_holon) 
-				+ w_selection * squash(f_selection, k_selection) 
-				+ w_grid * squash(f_grid, k_grid));
-	}
-
-	public static double calculateTopologieCost(DecoratedState state, int amountOfAddedSwitch,
-			double addedCableMeters) {
-		double cost = calculateWildcardCost(state);
-		cost += calculateAddedSwitchCost(amountOfAddedSwitch);
-		cost += calculateAddedCableCost(addedCableMeters);		
-		return cost;
-	}
-
-	public static double calculateAddedCableCost(double addedCableMeters) {
-		return cost_of_cable_per_meter * addedCableMeters;
-	}
-
-	public static double calculateAddedSwitchCost(int amountOfAddedSwitch) {
-		return cost_switch * amountOfAddedSwitch;
-	}
-
-	public static double calculateWildcardCost(DecoratedState state) {
-		double cost = 0;
-		for(DecoratedNetwork net : state.getNetworkList()) {
-			for(DecoratedHolonObject dHobject : net.getConsumerList()) {
-				if(dHobject.getModel().getName().contains("Wildcard")){
-					if(dHobject.getModel().getName().length() > 9) {
-						String costString = dHobject.getModel().getName().substring(9);
-						cost += Double.parseDouble(costString);
-					}
-				}
-			}
-			for(DecoratedHolonObject dHobject : net.getConsumerSelfSuppliedList()) {
-				if(dHobject.getModel().getName().contains("Wildcard")){
-					if(dHobject.getModel().getName().length() > 9) {
-						String costString = dHobject.getModel().getName().substring(9);
-						cost += Double.parseDouble(costString);
-					}
-				}
-			}
-			for(DecoratedHolonObject dHobject : net.getSupplierList()) {
-				if(dHobject.getModel().getName().contains("Wildcard")){
-					if(dHobject.getModel().getName().length() > 9) {
-						String costString = dHobject.getModel().getName().substring(9);
-						cost += Double.parseDouble(costString);
-					}
-				}
-			}
-		}
-		return cost;
+	//TODO(Tom2022-01-13) Fix TopologyFitnessFunction
+	static public float getFitnessValueForState(Model model, int amountOfAddedSwitch, double addedCableMeters, boolean moreInformation) {
+//		
+//		
+//
+//		//Calculate f_eb the penalty for unbalenced energy in the network
+//		double f_eb = 0;
+//		for(DecoratedNetwork net : state.getNetworkList()) {
+//			//abs
+//			f_eb += Math.abs(net.getTotalConsumption() - net.getTotalProduction());
+//		}
+//		//Average?
+//		f_eb /= state.getNetworkList().size();
+//		
+//		
+//		
+//		
+//		double f_maximum = 0;
+//		for(DecoratedNetwork net : state.getNetworkList()) {
+//			double prod = net.getTotalProduction();
+//			double con = net.getTotalConsumption();
+//			if(prod == 0 || con == 0) {
+//				f_maximum += lambda_max;
+//			}else {
+//				f_maximum += lambda_max * (Math.abs(prod - con)/Math.max(prod, con));				
+//			}
+//		}
+//		//Average?
+//		f_maximum /= state.getNetworkList().size();
+//		
+//		//calculate f_holon
+//		double f_holon = 0;
+//		for(DecoratedNetwork net : state.getNetworkList()) {
+//			double f_elements_deviation_production = net.getDeviationInProductionInNetworkForHolonObjects();
+//			double f_elements_deviation_consumption = net.getDeviationInConsumptionInNetworkForHolonObjects();
+//			double f_element = f_elements_deviation_production+f_elements_deviation_consumption;
+//			f_holon += f_element;
+//		}
+//		f_holon /= state.getNetworkList().size();
+//		
+//		//calculating f_selection
+//		double f_selection = calculateTopologieCost(state, amountOfAddedSwitch, addedCableMeters);
+//		//if(moreInformation)LOGGER.info("CostForWildcards:" + cost + ", CostSwitches(#" + amountOfAddedSwitch +"):" + cost_switch * amountOfAddedSwitch + ", CostCables(" +addedCableMeters+ "m):" + cost_of_cable_per_meter * addedCableMeters);
+//		
+//		
+//		//calculating f_grid
+//		double f_grid = 0;
+//		//each network is a holon
+//		for(DecoratedNetwork net: state.getNetworkList()) {
+//			Graph G = GraphMetrics.convertDecoratedNetworkToGraph(net);
+//			//We have to penalize single Networks;
+//			if(G.V.length <= 1 || G.S.length <= 1) {
+//				f_grid += lambda_avg_shortest_path;// + lambda_disjoint_path;
+//				continue;
+//			}
+//		
+//			double avgShortestPath = GraphMetrics.averageShortestDistance(G);
+//			//double disjpointPaths = GraphMetrics.averageEdgeDisjointPathProblem(G);
+//			if(useLog) {
+//				averageLog.addSample("avgShortestPath", (float)avgShortestPath);
+//			}
+//			f_grid += avgShortestPathPenalty(avgShortestPath);// + disjoinPathPenalty(disjpointPaths);
+//		}
+//		//take average to encourage splitting
+//		f_grid /= state.getNetworkList().size();
+//		
+//		
+//		
+//		
+//		if(moreInformation) {
+//			printWeightedValues(f_eb, f_maximum, f_holon, f_selection, f_grid);
+//			if(useLog) {
+//				log.info(averageLog.toString());
+//			}
+//		}
+//		//printUnsquashedValues(f_eb, f_maximum, f_holon, f_selection, f_grid);
+//		if(useLog) {
+//			averageLog.addSample("Unsquashed f_eb", (float)f_eb);
+//			averageLog.addSample("Unsquashed f_maximum", (float)f_maximum);
+//			averageLog.addSample("Unsquashed f_holon", (float)f_holon);
+//			averageLog.addSample("Unsquashed f_selection", (float)f_selection);
+//			averageLog.addSample("Unsquashed f_grid", (float)f_grid);
+//		}
+//		return (float) (w_eb * squash(f_eb, k_eb) 
+//				+ w_max * squash(f_maximum, k_max) 
+//				+ w_holon * squash(f_holon, k_holon) 
+//				+ w_selection * squash(f_selection, k_selection) 
+//				+ w_grid * squash(f_grid, k_grid));
+		return 0;
 	}
+//
+//	public static double calculateTopologieCost(DecoratedState state, int amountOfAddedSwitch,
+//			double addedCableMeters) {
+//		double cost = calculateWildcardCost(state);
+//		cost += calculateAddedSwitchCost(amountOfAddedSwitch);
+//		cost += calculateAddedCableCost(addedCableMeters);		
+//		return cost;
+//	}
+//
+//	public static double calculateAddedCableCost(double addedCableMeters) {
+//		return cost_of_cable_per_meter * addedCableMeters;
+//	}
+//
+//	public static double calculateAddedSwitchCost(int amountOfAddedSwitch) {
+//		return cost_switch * amountOfAddedSwitch;
+//	}
+//
+//	public static double calculateWildcardCost(DecoratedState state) {
+//		double cost = 0;
+//		for(DecoratedNetwork net : state.getNetworkList()) {
+//			for(DecoratedHolonObject dHobject : net.getConsumerList()) {
+//				if(dHobject.getModel().getName().contains("Wildcard")){
+//					if(dHobject.getModel().getName().length() > 9) {
+//						String costString = dHobject.getModel().getName().substring(9);
+//						cost += Double.parseDouble(costString);
+//					}
+//				}
+//			}
+//			for(DecoratedHolonObject dHobject : net.getConsumerSelfSuppliedList()) {
+//				if(dHobject.getModel().getName().contains("Wildcard")){
+//					if(dHobject.getModel().getName().length() > 9) {
+//						String costString = dHobject.getModel().getName().substring(9);
+//						cost += Double.parseDouble(costString);
+//					}
+//				}
+//			}
+//			for(DecoratedHolonObject dHobject : net.getSupplierList()) {
+//				if(dHobject.getModel().getName().contains("Wildcard")){
+//					if(dHobject.getModel().getName().length() > 9) {
+//						String costString = dHobject.getModel().getName().substring(9);
+//						cost += Double.parseDouble(costString);
+//					}
+//				}
+//			}
+//		}
+//		return cost;
+//	}
 
 	private static String doubleToString(double value) {
 		return String.format (Locale.US, "%.2f", value);

+ 3 - 3
src/holeg/algorithm/topologie/AcoAlgorithm.java

@@ -7,7 +7,7 @@ import java.util.ListIterator;
 
 import holeg.algorithm.objective_function.TopologieObjectiveFunction;
 import holeg.api.TopologieAlgorithmFramework;
-import holeg.ui.model.DecoratedState;
+import holeg.ui.model.Model;
 import holeg.utility.math.Random;
 
 public class AcoAlgorithm extends TopologieAlgorithmFramework {
@@ -32,8 +32,8 @@ public class AcoAlgorithm extends TopologieAlgorithmFramework {
 
 	}
 	@Override
-	protected double evaluateState(DecoratedState actualstate, int amountOfAddedSwitch, double addedCableMeters, boolean moreInformation) {
-		return TopologieObjectiveFunction.getFitnessValueForState(actualstate, amountOfAddedSwitch, addedCableMeters, moreInformation);
+	protected double evaluateState(Model model, int amountOfAddedSwitch, double addedCableMeters, boolean moreInformation) {
+		return TopologieObjectiveFunction.getFitnessValueForState(model, amountOfAddedSwitch, addedCableMeters, moreInformation);
 	}
 
 	@Override

+ 3 - 3
src/holeg/algorithm/topologie/GaAlgorithm.java

@@ -9,7 +9,7 @@ import java.util.TreeSet;
 
 import holeg.algorithm.objective_function.TopologieObjectiveFunction;
 import holeg.api.TopologieAlgorithmFramework;
-import holeg.ui.model.DecoratedState;
+import holeg.ui.model.Model;
 import holeg.utility.math.Random;
 
 public class GaAlgorithm extends TopologieAlgorithmFramework {
@@ -42,8 +42,8 @@ public class GaAlgorithm extends TopologieAlgorithmFramework {
 	
 	}
 	@Override
-	protected double evaluateState(DecoratedState actualstate, int amountOfAddedSwitch, double addedCableMeters, boolean moreInformation) {
-		return TopologieObjectiveFunction.getFitnessValueForState(actualstate, amountOfAddedSwitch, addedCableMeters, moreInformation);
+	protected double evaluateState(Model model, int amountOfAddedSwitch, double addedCableMeters, boolean moreInformation) {
+		return TopologieObjectiveFunction.getFitnessValueForState(model, amountOfAddedSwitch, addedCableMeters, moreInformation);
 	}
 
 	@Override

+ 3 - 3
src/holeg/algorithm/topologie/PsoAlgorithm.java

@@ -9,7 +9,7 @@ import java.util.stream.Collectors;
 
 import holeg.algorithm.objective_function.TopologieObjectiveFunction;
 import holeg.api.TopologieAlgorithmFramework;
-import holeg.ui.model.DecoratedState;
+import holeg.ui.model.Model;
 import holeg.utility.math.Maths;
 import holeg.utility.math.Random;
 
@@ -51,8 +51,8 @@ public class PsoAlgorithm extends TopologieAlgorithmFramework {
 
 	
 	@Override
-	protected double evaluateState(DecoratedState actualstate, int amountOfAddedSwitch, double addedCableMeters, boolean moreInformation) {
-		return TopologieObjectiveFunction.getFitnessValueForState(actualstate, amountOfAddedSwitch, addedCableMeters, moreInformation);
+	protected double evaluateState(Model model, int amountOfAddedSwitch, double addedCableMeters, boolean moreInformation) {
+		return TopologieObjectiveFunction.getFitnessValueForState(model, amountOfAddedSwitch, addedCableMeters, moreInformation);
 	}
 
 	@Override

+ 85 - 92
src/holeg/api/AlgorithmFrameworkFlex.java

@@ -20,6 +20,7 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
+import java.util.Optional;
 import java.util.function.BiFunction;
 import java.util.function.Consumer;
 import java.util.function.Supplier;
@@ -52,14 +53,12 @@ import holeg.model.HolonObject;
 import holeg.model.HolonSwitch;
 import holeg.preferences.ImagePreference;
 import holeg.model.Flexibility.FlexState;
+import holeg.model.GroupNode;
 import holeg.model.HolonElement.Priority;
+import holeg.model.HolonSwitch.SwitchMode;
+import holeg.model.HolonSwitch.SwitchState;
 import holeg.ui.controller.Control;
-import holeg.ui.model.DecoratedGroupNode;
-import holeg.ui.model.DecoratedNetwork;
-import holeg.ui.model.DecoratedState;
 import holeg.ui.model.Model;
-import holeg.ui.model.DecoratedHolonObject.HolonObjectState;
-import holeg.ui.model.DecoratedSwitch.SwitchState;
 import holeg.ui.view.component.Console;
 import holeg.utility.image.Import;
 import holeg.utility.math.decimal.Format;
@@ -77,7 +76,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 	
 	
 	//Settings groupNode
-	private DecoratedGroupNode dGroupNode = null;
+	private Optional<GroupNode> groupNode = Optional.empty();
 	
 	
 	//access
@@ -494,32 +493,29 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 	
 	
 	private void selectGroupNode() {
-		control.getSimManager().getActualVisualRepresentationalState().ifPresent(state -> {
-			Object[] possibilities = state.getCreatedGroupNodes().values().stream().map(aCps -> new Handle<DecoratedGroupNode>(aCps)).toArray();
-			@SuppressWarnings("unchecked")
-			Handle<DecoratedGroupNode> selected = (Handle<DecoratedGroupNode>) JOptionPane.showInputDialog(content, "Select GroupNode:", "GroupNode?",  JOptionPane.OK_OPTION,new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)) , possibilities, "");
-			if(selected != null) {
-				console.println("Selected: " + selected);
-				dGroupNode = selected.object;
-			}
-		});
+		Object[] possibilities = control.getModel().getCanvas().getAllGroupNodeObjectsRecursive().toArray();
+		@SuppressWarnings("unchecked")
+		GroupNode selected = (GroupNode) JOptionPane.showInputDialog(content, "Select GroupNode:", "GroupNode?",  JOptionPane.OK_OPTION,new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)) , possibilities, "");
+		if(selected != null) {
+			console.println("Selected: " + selected);
+			groupNode = Optional.of(selected);
+		}
 	}
 	
 	protected double evaluatePosition(List<Boolean> positionToEvaluate) {
 		runProgressbar.step();
 		setState(positionToEvaluate); // execution time critical
-		DecoratedState actualstate = control.getSimManager().getActualDecorState().get();
-		double result = evaluateState(actualstate);
+		double result = evaluateState();
 		return result;
 	}
 
-	private double evaluateState(DecoratedState actualstate) {
+	private double evaluateState() {
 		switch(this.evaluationFunction) {
 		case Switch:
-			return SwitchObjectiveFunction.getFitnessValueForState(actualstate);
+			return SwitchObjectiveFunction.getFitnessValueForState(control.getModel());
 		case Normal:
 		default:
-			return ObjectiveFunctionByCarlos.getFitnessValueForState(actualstate);
+			return ObjectiveFunctionByCarlos.getFitnessValueForState(control.getModel());
 		}
 		
 	}
@@ -631,7 +627,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		updateVisual();
 		console.println("Start: " + Format.doubleFixedPlaces(2,startFitness));
 		console.println("AlgoResult: " + Format.doubleFixedPlaces(2,runBest.fitness));
-		if(this.algoUseFlexes)calculateAndPrintFlexInfos(control.getSimManager().getActualDecorState().get());
+		if(this.algoUseFlexes)calculateAndPrintFlexInfos();
 		runPrinter.openStream();
 		if(rounds > 1) {
 			RunValues avgRun = avg.getAverage();
@@ -643,9 +639,9 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 	}
 	
 	
-	private void calculateAndPrintFlexInfos(DecoratedState state) {
+	private void calculateAndPrintFlexInfos() {
 		int amountOfUsedFlex = 0;
-		List<Flexibility> allFlex = state.getAllFlex().toList();
+		List<Flexibility> allFlex = control.getModel().getAllFlexibilities();
 		int amountOfFlex = allFlex.size(); 
 		float cost = 0;
 		int consumingFlex = 0;
@@ -804,10 +800,10 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 	
 
 	private void rollOutNodes(List<Boolean> positionToInit) {
-		boolean groupNodeSelected = dGroupNode != null;
+		boolean groupNodeSelected = groupNode.isPresent();
 		int timeStep = control.getModel().getCurrentIteration();
-		Stream<HolonObject> holonObjects = groupNodeSelected ? dGroupNode.getModel().getAllHolonObjectsRecursive() : control.getModel().getCanvas().getAllHolonObjectsRecursive();
-		Stream<HolonSwitch> holonSwitches = groupNodeSelected ? dGroupNode.getModel().getAllSwitchObjectsRecursive(): control.getModel().getCanvas().getAllSwitchObjectsRecursive();
+		Stream<HolonObject> holonObjects = groupNodeSelected ? groupNode.get().getAllHolonObjectsRecursive() : control.getModel().getCanvas().getAllHolonObjectsRecursive();
+		Stream<HolonSwitch> holonSwitches = groupNodeSelected ? groupNode.get().getAllSwitchObjectsRecursive(): control.getModel().getCanvas().getAllSwitchObjectsRecursive();
 		holonObjects.forEach(hObject -> {
 			AccessWrapper killSwitchAccess = new AccessWrapper(hObject);
 			if(this.algoUseKillSwitch) {
@@ -824,7 +820,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		});
 		
 		holonSwitches.forEach(sw -> {
-			positionToInit.add(sw.getState(timeStep));
+			positionToInit.add(sw.getState().isClosed());
 			access.add(new AccessWrapper(sw));
 		});
 	}
@@ -832,72 +828,69 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 
 	
 	
-	
+	//TODO(Tom2022-01-13) fix print
 	private RunValues getRunValuesFromActualState() {
 		RunValues val = new RunValues();
-		if(dGroupNode != null)
-		{
-			//GetActualDecoratedGroupNode
-			dGroupNode = control.getSimManager().getActualVisualRepresentationalState().get().getCreatedGroupNodes().get(dGroupNode.getModel());
-			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);
-			
+		//TODO(Tom2021-12-1) what should be printed happen when only groupNode are selected
+		groupNode.ifPresent(groupnode -> {
+//			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);
+//			
+//			
+//			val.activeElements = dGroupNode.getAmountOfAktiveElemntsFromHolonObjects();
+//			val.elements = dGroupNode.getAmountOfElemntsFromHolonObjects();
 			
-			val.activeElements = dGroupNode.getAmountOfAktiveElemntsFromHolonObjects();
-			val.elements = dGroupNode.getAmountOfElemntsFromHolonObjects();
-			//TODO(Tom2021-12-1) what should be printed happen when only groupNode are selected
-		}
-		DecoratedState state = control.getSimManager().getActualDecorState().get();
-		for(DecoratedNetwork net : state.getNetworkList()) {
-			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();
-		}
-		val.objects = val.consumer + val.producer + val.passiv;
-		val.difference= Math.abs(val.production - val.consumption);
-		
-		
-		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();
-		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);
-		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
-		
-		DoubleSummaryStatistics partiallyStat = state.getNetworkList().stream().flatMap(net -> {
-			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());
+		});
+//		for(DecoratedNetwork net : state.getNetworkList()) {
+//			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();
+//		}
+//		val.objects = val.consumer + val.producer + val.passiv;
+//		val.difference= Math.abs(val.production - val.consumption);
+//		
+//		
+//		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();
+//		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);
+//		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
+//		
+//		DoubleSummaryStatistics partiallyStat = state.getNetworkList().stream().flatMap(net -> {
+//			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;
 		
@@ -1206,8 +1199,8 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 					}
 					break;
 				case Switch:
-					hSwitch.setManualMode(true);
-					hSwitch.setManualState(state);
+					hSwitch.setMode(SwitchMode.Manual);
+					hSwitch.setManualState(state ? SwitchState.Closed: SwitchState.Open);
 					break;
 				case Flexibility:
 					if(state && (!algoUseKillSwitch || (algoUseKillSwitch && !correspondingKillSwitch.getLastState()))) {

+ 119 - 127
src/holeg/api/TopologieAlgorithmFramework.java

@@ -12,7 +12,6 @@ import java.math.RoundingMode;
 import java.text.NumberFormat;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.DoubleSummaryStatistics;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedList;
@@ -48,14 +47,11 @@ import holeg.model.GroupNode;
 import holeg.model.HolonObject;
 import holeg.model.HolonSwitch;
 import holeg.model.Node;
+import holeg.model.HolonSwitch.SwitchMode;
+import holeg.model.HolonSwitch.SwitchState;
 import holeg.preferences.ImagePreference;
 import holeg.ui.controller.Control;
-import holeg.ui.model.DecoratedGroupNode;
-import holeg.ui.model.DecoratedNetwork;
-import holeg.ui.model.DecoratedState;
 import holeg.ui.model.Model;
-import holeg.ui.model.DecoratedHolonObject.HolonObjectState;
-import holeg.ui.model.DecoratedSwitch.SwitchState;
 import holeg.ui.view.component.Console;
 import holeg.ui.view.main.Category;
 
@@ -75,7 +71,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 	
 	
 	//Settings groupNode
-	private DecoratedGroupNode dGroupNode = null;
+	private Optional<GroupNode> groupNode = Optional.empty();
 	
 	
 	//access
@@ -225,10 +221,10 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 	private void toggleSwitches() {
 		List<HolonSwitch> allSwitchList = control.getModel().getCanvas().getAllSwitchObjectsRecursive().toList();
 		if(allSwitchList.isEmpty()) return;
-		boolean set = allSwitchList.get(0).getState(control.getModel().getCurrentIteration());
+		SwitchState set = allSwitchList.get(0).getManualState();
 		allSwitchList.forEach(hSwitch -> {
-			hSwitch.setManualMode(true);
-			hSwitch.setManualState(!set);
+			hSwitch.setMode(SwitchMode.Manual);
+			hSwitch.setManualState(SwitchState.opposite(set));
 		});
 		updateVisual();
 	}
@@ -494,21 +490,24 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 
 	private double evaluateNetwork() {
 		runProgressbar.step();
-		DecoratedState actualstate = control.getSimManager().getActualDecorState().get();
-		return evaluateState(actualstate, calculateAmountOfAddedSwitches(), addedCableMeter(), false);
+		return evaluateState(control.getModel(), calculateAmountOfAddedSwitches(), addedCableMeter(), false);
 	}
 	private double evaluateNetworkAndPrint() {
 		runProgressbar.step();
-		for(HolonSwitch hSwitch: switchList) {
-			hSwitch.setManualMode(true);
-			hSwitch.setManualState(false);
-		}
+		openAllSwitchInSwitchList();
 		control.calculateStateOnlyForCurrentTimeStep();
-		DecoratedState actualstate = control.getSimManager().getActualDecorState().get();
-		return evaluateState(actualstate, calculateAmountOfAddedSwitches(), addedCableMeter(), true);
+		return evaluateState(control.getModel() ,calculateAmountOfAddedSwitches(), addedCableMeter(), true);
+	}
+	
+	private void openAllSwitchInSwitchList() {
+		for(HolonSwitch hSwitch: switchList) {
+			hSwitch.setMode(SwitchMode.Manual);
+			hSwitch.setManualState(SwitchState.Open);
+		}	
 	}
 	
 	
+	
 	private double addedCableMeter() {
 		return addedIndexCable.values().stream().reduce(0.0, Double::sum);
 	}
@@ -517,7 +516,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 		return (int)this.switchList.stream().filter(sw -> sw.getName().contains("AddedSwitch")).count();
 	}
 	
-	protected abstract double evaluateState(DecoratedState actualstate, int amountOfAddedSwitch, double addedCableMeter, boolean moreInfromation);
+	protected abstract double evaluateState(Model model, int amountOfAddedSwitch, double addedCableMeter, boolean moreInfromation);
 
 	
 	private void run() {
@@ -618,10 +617,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 		}
 		
 		setState(runBest.position);
-		for(HolonSwitch hSwitch: switchList) {
-			hSwitch.setManualMode(true);
-			hSwitch.setManualState(false);
-		}
+		openAllSwitchInSwitchList();
 		updateVisual();
 		evaluateNetworkAndPrint();
 		console.println("Start: " + startFitness);
@@ -698,10 +694,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 		for(int i = 3 * amountOfNewCables + amountOfExistingCables; i < position.size(); i++) {
 			accessWildcards.get(count++).setState(position.get(i));
 		}
-		for(HolonSwitch hSwitch: switchList) {
-			hSwitch.setManualMode(true);
-			hSwitch.setManualState(false);
-		}
+		openAllSwitchInSwitchList();
 		control.calculateStateOnlyForCurrentTimeStep();
 }
 
@@ -922,107 +915,106 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 		edgeList.clear();
 	}
 	
-	
+	//TODO(Tom2022-01-13): Fix print
 	private String stringStatFromActualState() {
-		if(dGroupNode != null)
-		{
-			//GetActualDecoratedGroupNode
-			dGroupNode = control.getSimManager().getActualVisualRepresentationalState().get().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);
-			
-			
-			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 + "%)"
-				+ "]";
-		}
-		DecoratedState state = control.getSimManager().getActualDecorState().get();
-		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);
-		
-		
-		
-		int amountHolons = state.getNetworkList().size();
-		int amountSwitch = state.getDecoratedSwitches().size();
-		int amountActiveSwitch = (int)state.getDecoratedSwitches().stream().filter(dswitch -> (dswitch.getState() == SwitchState.Closed)).count();
-		
-		int addedSwitches = calculateAmountOfAddedSwitches();
-		double addedCableMeters = addedCableMeter();
-		double wildcardCost = TopologieObjectiveFunction.calculateWildcardCost(state);
-		double cableCost = TopologieObjectiveFunction.calculateWildcardCost(state);
-		double switchCost = TopologieObjectiveFunction.calculateWildcardCost(state);
-		double totalCost = wildcardCost + cableCost + switchCost;
-		
-		DoubleSummaryStatistics overStat = state.getNetworkList().stream().flatMap(net -> {
-			return net.getConsumerList().stream().filter(con -> con.getState() == HolonObjectState.OVER_SUPPLIED);
-		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
-		
-		DoubleSummaryStatistics partiallyStat = state.getNetworkList().stream().flatMap(net -> {
-			return net.getConsumerList().stream().filter(con -> con.getState() == HolonObjectState.PARTIALLY_SUPPLIED);
-		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
-		
-		return	"HolonObjects["
-			+ " Passiv: " + percentage(amountOfPassiv, amountOfObjects)
-			+ " Producer: " + percentage(amountOfSupplier, amountOfObjects)
-			+ " Consumer: " + percentage(amountOfConsumer, amountOfObjects)
-			+ " Unsupplied: " + percentage(unSuppliedConsumer, amountOfConsumer)
-			+ " PartiallySupplied: " + percentage(partiallySuppliedConsumer, amountOfObjects) 
-			+ " 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)
-			+ "]" 
-			+ " activeSwitches:" + percentage(amountActiveSwitch,amountSwitch)
-			+ " Holons: " + amountHolons
-			+ " totalConsumption: " + totalConsumption
-			+ " totalProduction: " + totalProduction
-			+ " difference: " + difference
-			+ " Topologie["
-			+ " addedCableMeters:" + addedCableMeters
-			+ " addedSwitches: " + addedSwitches
-			+ " totalCost: " + totalCost + "("
-			+ " wildcardCost: " + wildcardCost
-			+ " cableCost: " + cableCost
-			+ " switchCost: " + switchCost
-			+  ")]"
-			;
-		
+//		if(groupNode != null)
+//		{
+//			//GetActualDecoratedGroupNode
+//			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);
+//			
+//			
+//			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 + "%)"
+//				+ "]";
+//		}
+//		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);
+//		
+//		
+//		
+//		int amountHolons = state.getNetworkList().size();
+//		int amountSwitch = state.getDecoratedSwitches().size();
+//		int amountActiveSwitch = (int)state.getDecoratedSwitches().stream().filter(dswitch -> (dswitch.getState() == SwitchState.Closed)).count();
+//		
+//		int addedSwitches = calculateAmountOfAddedSwitches();
+//		double addedCableMeters = addedCableMeter();
+//		double wildcardCost = TopologieObjectiveFunction.calculateWildcardCost(state);
+//		double cableCost = TopologieObjectiveFunction.calculateWildcardCost(state);
+//		double switchCost = TopologieObjectiveFunction.calculateWildcardCost(state);
+//		double totalCost = wildcardCost + cableCost + switchCost;
+//		
+//		DoubleSummaryStatistics overStat = state.getNetworkList().stream().flatMap(net -> {
+//			return net.getConsumerList().stream().filter(con -> con.getState() == HolonObjectState.OVER_SUPPLIED);
+//		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
+//		
+//		DoubleSummaryStatistics partiallyStat = state.getNetworkList().stream().flatMap(net -> {
+//			return net.getConsumerList().stream().filter(con -> con.getState() == HolonObjectState.PARTIALLY_SUPPLIED);
+//		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
+//		
+//		return	"HolonObjects["
+//			+ " Passiv: " + percentage(amountOfPassiv, amountOfObjects)
+//			+ " Producer: " + percentage(amountOfSupplier, amountOfObjects)
+//			+ " Consumer: " + percentage(amountOfConsumer, amountOfObjects)
+//			+ " Unsupplied: " + percentage(unSuppliedConsumer, amountOfConsumer)
+//			+ " PartiallySupplied: " + percentage(partiallySuppliedConsumer, amountOfObjects) 
+//			+ " 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)
+//			+ "]" 
+//			+ " activeSwitches:" + percentage(amountActiveSwitch,amountSwitch)
+//			+ " Holons: " + amountHolons
+//			+ " totalConsumption: " + totalConsumption
+//			+ " totalProduction: " + totalProduction
+//			+ " difference: " + difference
+//			+ " Topologie["
+//			+ " addedCableMeters:" + addedCableMeters
+//			+ " addedSwitches: " + addedSwitches
+//			+ " totalCost: " + totalCost + "("
+//			+ " wildcardCost: " + wildcardCost
+//			+ " cableCost: " + cableCost
+//			+ " switchCost: " + switchCost
+//			+  ")]"
+//			;
+//		
+		return "";
 	}
 	
 	

+ 30 - 23
src/holeg/model/HolonSwitch.java

@@ -22,17 +22,32 @@ public class HolonSwitch extends AbstractCanvasObject implements TimelineDepende
 
 	
 	public enum SwitchState {
-		Open, Closed
+		Open, Closed;
+		public static SwitchState opposite(SwitchState state) {
+			switch(state) {
+			case Closed:
+				return Open;
+			case Open:
+			default:
+				return Closed;
+			}
+		}
+		public boolean isOpen() {
+			return this == Open;
+		}
+		public boolean isClosed() {
+			return this == Closed;
+		}
 	}
 
-	public enum SwitchOperatingMode {
-		Manuel, Auto
+	public enum SwitchMode {
+		Manual, Auto
 	}
 
 	@Expose
-	private SwitchOperatingMode mode = SwitchOperatingMode.Auto;
+	private SwitchMode mode = SwitchMode.Auto;
 	@Expose
-	private SwitchState manuelState = SwitchState.Closed;
+	private SwitchState manualState = SwitchState.Closed;
 	@Expose
 	private int localPeriod;
 	@Expose
@@ -88,16 +103,8 @@ public class HolonSwitch extends AbstractCanvasObject implements TimelineDepende
 	/**
 	 * Calculates the state of the Switch.
 	 */
-	public void toggleStateManuel() {
-		switch(manuelState) {
-		case Closed:
-			manuelState = SwitchState.Open;
-			break;
-		case Open:
-		default:
-			manuelState = SwitchState.Closed;
-			break;
-		}
+	public void flipManualState() {
+		manualState = SwitchState.opposite(manualState);
 	}
 	
 	/*
@@ -109,9 +116,9 @@ public class HolonSwitch extends AbstractCanvasObject implements TimelineDepende
 		switch (mode) {
 		case Auto:
 			state = activeAt[IndexTranslator.getEffectiveIndex(this, timestep)] ? SwitchState.Open : SwitchState.Closed;
-		case Manuel:
+		case Manual:
 		default:
-			state =  manuelState;
+			state =  manualState;
 		}
 	}
 	public SwitchState getState() {
@@ -145,20 +152,20 @@ public class HolonSwitch extends AbstractCanvasObject implements TimelineDepende
 		graphPoints.add(new Vec2f(1, 1));
 	}
 
-	public SwitchOperatingMode getMode() {
+	public SwitchMode getMode() {
 		return mode;
 	}
 
-	public void setMode(SwitchOperatingMode mode) {
+	public void setMode(SwitchMode mode) {
 		this.mode = mode;
 	}
 
-	public SwitchState getManuelState() {
-		return manuelState;
+	public SwitchState getManualState() {
+		return manualState;
 	}
 
-	public void setManuelState(SwitchState manuelState) {
-		this.manuelState = manuelState;
+	public void setManualState(SwitchState manuelState) {
+		this.manualState = manuelState;
 	}
 
 	// interfaces.GraphEditable

+ 1 - 1
src/holeg/ui/controller/CanvasController.java

@@ -22,7 +22,7 @@ import holeg.utility.math.vector.Vec2i;
  * 
  * @author Gruppe14
  */
-//TODO remove CanvasController and merge with NodeController
+//TODO(Tom2022-01-11): remove CanvasController and merge with NodeController
 @Deprecated
 public class CanvasController {
 

+ 0 - 2
src/holeg/ui/controller/Control.java

@@ -461,8 +461,6 @@ public class Control {
 		try {
 			saveController.writeCategory(categoryDir + "Category.json");
 		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
 		}
 	}
 

+ 10 - 47
src/holeg/ui/controller/SimulationManager.java

@@ -1,22 +1,16 @@
 package holeg.ui.controller;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.ListIterator;
-import java.util.Optional;
 import java.util.logging.Logger;
 
 import holeg.model.*;
 import holeg.model.Edge.EdgeState;
-import holeg.ui.model.DecoratedNetwork;
-import holeg.ui.model.DecoratedState;
-import holeg.ui.model.DecoratedSwitch;
+import holeg.model.HolonSwitch.SwitchState;
 import holeg.ui.model.MinimumModel;
 import holeg.ui.model.MinimumNetwork;
 import holeg.ui.model.Model;
-import holeg.ui.model.VisualRepresentationalState;
-import holeg.ui.model.DecoratedSwitch.SwitchState;
 import holeg.ui.model.Model.FairnessModel;
 
 /**
@@ -27,8 +21,6 @@ import holeg.ui.model.Model.FairnessModel;
 public class SimulationManager {
 	private static final Logger log = Logger.getLogger(SimulationManager.class.getName());
 	private Model model;
-	private int timeStep;
-	public Optional<DecoratedState> actualDecorState = Optional.empty();
 
 	/**
 	 * Constructor.
@@ -49,7 +41,6 @@ public class SimulationManager {
 	 */
 	public void calculateStateForTimeStep(int timestep, boolean updateVisual) {
 		log.fine("Calculate");
-		timeStep = timestep;
 		long start = System.currentTimeMillis();
 		ArrayList<MinimumNetwork> list = new ArrayList<MinimumNetwork>();
 		MinimumModel minimumModel = new MinimumModel(model.getCanvas(), model.getEdgesOnCanvas(),
@@ -76,38 +67,22 @@ public class SimulationManager {
 				}
 			}
 		} while (doAnotherLoop);
-		ArrayList<DecoratedNetwork> decorNetworks = new ArrayList<DecoratedNetwork>();
-		FairnessModel actualFairnessModel = model.getFairnessModel();
-		for (MinimumNetwork net : list) {
-			decorNetworks.add(new DecoratedNetwork(net, timestep, actualFairnessModel));
-		}
+//		ArrayList<DecoratedNetwork> decorNetworks = new ArrayList<DecoratedNetwork>();
+//		FairnessModel actualFairnessModel = model.getFairnessModel();
+//		for (MinimumNetwork net : list) {
+//			decorNetworks.add(new DecoratedNetwork(net, timestep, actualFairnessModel));
+//		}
 
 		for (Edge cable : leftOver) {
 			cable.setActualFlow(0.0f);
 		}
-		ArrayList<DecoratedSwitch> listOfDecoratedSwitches = decorateSwitches(minimumModel, timestep);
-		DecoratedState stateFromThisTimestep = new DecoratedState(decorNetworks, leftOver, listOfDecoratedSwitches,
-				timestep);
-		actualDecorState = Optional.of(stateFromThisTimestep);
+//		DecoratedState stateFromThisTimestep = new DecoratedState(decorNetworks, leftOver,
+//				timestep);
+//		actualDecorState = Optional.of(stateFromThisTimestep);
 		long end = System.currentTimeMillis();
 		log.finer("Simulation: " + (end - start) + "ms");
 	}
 
-	/**
-	 * Decorate a switch
-	 * 
-	 * @param minModel
-	 * @param iteration
-	 * @return
-	 */
-	public static ArrayList<DecoratedSwitch> decorateSwitches(MinimumModel minModel, int iteration) {
-		ArrayList<DecoratedSwitch> aListOfDecoratedSwitches = new ArrayList<DecoratedSwitch>();
-		for (HolonSwitch hSwitch : minModel.getSwitchList()) {
-			aListOfDecoratedSwitches.add(
-					new DecoratedSwitch(hSwitch, hSwitch.getState(iteration) ? SwitchState.Closed : SwitchState.Open));
-		}
-		return aListOfDecoratedSwitches;
-	}
 
 	/**
 	 * SubFunction to calculate the Networks from the model.
@@ -150,7 +125,7 @@ public class SimulationManager {
 					actualNetwork.getNodeAndSwitches().add(lookAtNeighbor);
 				}
 				// When HolonSwitch Check if closed
-				if (!(lookAtNeighbor instanceof HolonSwitch sw) || sw.getState(Iteration)) {
+				if (!(lookAtNeighbor instanceof HolonSwitch sw) || sw.getState() == SwitchState.Closed) {
 					populateListOfNeighbors(edgeList, lookAtNeighbor, actualNetwork, neighbors);
 				}
 
@@ -199,16 +174,4 @@ public class SimulationManager {
 		}
 	}
 
-	public Optional<DecoratedState> getActualDecorState() {
-		return actualDecorState;
-	}
-
-	public Optional<VisualRepresentationalState> getActualVisualRepresentationalState() {
-		return Optional.ofNullable(savesVisual.get(timeStep));
-	}
-
-	public Optional<VisualRepresentationalState> getVisualRepresentationalState(int timestep) {
-		return Optional.ofNullable(savesVisual.get(timestep));
-	}
-
 }

+ 0 - 203
src/holeg/ui/model/DecoratedGroupNode.java

@@ -1,203 +0,0 @@
-package holeg.ui.model;
-
-import java.util.ArrayList;
-import java.util.stream.Stream;
-
-import holeg.model.Edge;
-import holeg.model.Flexibility;
-import holeg.model.GroupNode;
-import holeg.model.HolonElement;
-import holeg.model.HolonObject;
-import holeg.model.HolonObject.HolonObjectState;
-import holeg.model.Node;
-import jdk.jfr.Unsigned;
-
-/**
- * For the @VisualRepresentationalState only.
- * 
- * @author Tom
- *
- */
-public class DecoratedGroupNode {
-	private GroupNode model;
-	private ArrayList<Supplier> supplierList= new ArrayList<>(); 
-	private ArrayList<Passiv> passivList= new ArrayList<>(); 
-	private ArrayList<Consumer> consumerList= new ArrayList<>(); 
-	private ArrayList<Node> nodeList= new ArrayList<>(); 
-	/**
-	 * Cables that only exist on that group node. From a object in that group node
-	 * to a object in that group Node. Not exit the group node (a layer down).
-	 */
-	private ArrayList<Edge> internCableList= new ArrayList<>(); 
-	/**
-	 * Cables that exit this group node (a Layer Up). From a object in this group
-	 * node to a object in a upper layer.
-	 */
-	private ArrayList<ExitCable> exitCableList= new ArrayList<>(); 
-	private ArrayList<DecoratedSwitch> switchList= new ArrayList<>(); 
-	private ArrayList<DecoratedGroupNode> groupNodeList= new ArrayList<>(); 
-
-	public DecoratedGroupNode(GroupNode model) {
-		this.model = model;
-	}
-
-	public GroupNode getModel() {
-		return model;
-	}
-
-	public ArrayList<Supplier> getSupplierList() {
-		return supplierList;
-	}
-
-	public ArrayList<Passiv> getPassivList() {
-		return passivList;
-	}
-
-	public ArrayList<Consumer> getConsumerList() {
-		return consumerList;
-	}
-
-	public ArrayList<Node> getNodeList() {
-		return nodeList;
-	}
-
-	public ArrayList<Edge> getInternCableList() {
-		return internCableList;
-	}
-
-	public ArrayList<ExitCable> getExitCableList() {
-		return exitCableList;
-	}
-
-	public ArrayList<DecoratedSwitch> getSwitchList() {
-		return switchList;
-	}
-
-	public ArrayList<DecoratedGroupNode> getGroupNodeList() {
-		return groupNodeList;
-	}
-
-	// Returns the amount of holons and count himself
-	public int getAmountOfGroupNodes() {
-		return 1 + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfGroupNodes()).reduce(0, Integer::sum);
-	}
-
-	public Stream<Flexibility> getFlexibilitiesStream() {
-
-		Stream<Flexibility> flexInChildGorupNode = this.groupNodeList.stream()
-				.flatMap(groupNode -> groupNode.getFlexibilitiesStream());
-
-		Stream<Flexibility> flexInThisGorupNode = objectStream()
-				.flatMap(object -> object.getModel().getElements().flatMap(ele -> ele.flexList.stream()));
-
-		return Stream.concat(flexInChildGorupNode, flexInThisGorupNode);
-	}
-
-	public Stream<DecoratedHolonObject> objectStream() {
-		return Stream.concat(Stream.concat(this.consumerList.stream(), this.supplierList.stream()),
-				this.passivList.stream());
-	}
-
-	// Gather Informations:
-	public int getAmountOfSupplier() {
-		return supplierList.size()
-				+ groupNodeList.stream().map(groupNode -> groupNode.getAmountOfSupplier()).reduce(0, Integer::sum);
-	}
-
-	public int getAmountOfConsumer() {
-		return consumerList.size()
-				+ groupNodeList.stream().map(groupNode -> groupNode.getAmountOfConsumer()).reduce(0, Integer::sum);
-	}
-
-	public int getAmountOfPassiv() {
-		return passivList.size()
-				+ groupNodeList.stream().map(groupNode -> groupNode.getAmountOfPassiv()).reduce(0, Integer::sum);
-	}
-
-	public int getAmountOfConsumerWithState(HolonObjectState state) {
-		return ((int) consumerList.stream().map(con -> con.getState()).filter(rightState -> (rightState == state))
-				.count())
-				+ groupNodeList.stream().map(groupNode -> groupNode.getAmountOfConsumerWithState(state)).reduce(0,
-						Integer::sum);
-	}
-
-	public int getAmountOfElemntsFromHolonObjects() {
-		return objectStream().map(object -> (int)object.getModel().getElements().count()).reduce(0, Integer::sum)
-				+ groupNodeList.stream().map(groupNode -> groupNode.getAmountOfElemntsFromHolonObjects()).reduce(0,
-						Integer::sum);
-	}
-
-	public PriorityCounts getPriorityCounts() {
-		PriorityCounts priority = new PriorityCounts();
-		objectStream().forEach(object -> object.getModel().getElements().forEach(ele -> priority.Count(ele)));
-		groupNodeList.stream().forEach(groupNode -> priority.Add(groupNode.getPriorityCounts()));
-		return priority;
-	}
-
-	public class PriorityCounts {
-		@Unsigned
-		public int low, medium, high, essential;
-
-		public void Add(PriorityCounts other) {
-			low += other.low;
-			medium += other.medium;
-			high += other.high;
-			essential += other.essential;
-		}
-
-		public void Count(HolonElement element) {
-			switch (element.getPriority()) {
-			case Essential:
-				essential++;
-				break;
-			case High:
-				high++;
-				break;
-			case Medium:
-				medium++;
-				break;
-			case Low:
-				low++;
-				break;
-			default:
-				break;
-
-			}
-		}
-	}
-
-	public int getAmountOfAktiveElemntsFromHolonObjects() {
-		return objectStream().map(object -> object.getModel().getNumberOfActiveElements()).reduce(0,
-						Integer::sum)
-				+ groupNodeList.stream().map(groupNode -> groupNode.getAmountOfAktiveElemntsFromHolonObjects())
-						.reduce(0, Integer::sum);
-	}
-
-	public float getConsumptionFromConsumer() {
-		return consumerList.stream().map(con -> con.getEnergyNeededFromNetwork()).reduce(0.f, Float::sum)
-				+ groupNodeList.stream().map(groupNode -> groupNode.getConsumptionFromConsumer()).reduce(0.f,
-						Float::sum);
-	}
-
-	public float getProductionFromSupplier() {
-		return supplierList.stream().map(sup -> sup.getEnergyToSupplyNetwork()).reduce(0.f, Float::sum) + groupNodeList
-				.stream().map(groupNode -> groupNode.getProductionFromSupplier()).reduce(0.f, Float::sum);
-	}
-
-	public float getAverageConsumption() {
-		return getConsumptionFromConsumer() / (float) getAmountOfGroupNodes();
-	}
-
-	public float getAverageProduction() {
-		return getProductionFromSupplier() / (float) getAmountOfGroupNodes();
-	}
-
-	public String toString() {
-		return "GroupNode" + model.getId() + " with [Supplier:" + getAmountOfSupplier() + ", NotSupplied:"
-				+ getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED) + ", PartiallySupplied:"
-				+ getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED) + ", Supplied:"
-				+ getAmountOfConsumerWithState(HolonObjectState.SUPPLIED) + ", OverSupplied:"
-				+ getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED) + ", Passiv:" + getAmountOfPassiv()
-				+ "]";
-	}
-}

+ 470 - 471
src/holeg/ui/model/DecoratedNetwork.java → src/holeg/ui/model/DecoratedNetwork.java.orig

@@ -1,471 +1,470 @@
-package holeg.ui.model;
-
-import java.util.ArrayList;
-import java.util.stream.Stream;
-
-import holeg.model.Edge;
-import holeg.model.HolonElement;
-import holeg.model.HolonObject;
-import holeg.model.HolonObject.HolonObjectState;
-import holeg.ui.model.Model.FairnessModel;
-
-public class DecoratedNetwork {
-	private ArrayList<Supplier> supplierList = new ArrayList<Supplier>();
-	private ArrayList<Consumer> consumerList = new ArrayList<Consumer>();
-	private ArrayList<Consumer> consumerSelfSuppliedList = new ArrayList<Consumer>();
-	private ArrayList<Passiv> passivNoEnergyList = new ArrayList<Passiv>();
-	private ArrayList<Edge> edgeList = new ArrayList<Edge>();
-
-	public DecoratedNetwork(MinimumNetwork minimumNetwork, int Iteration, FairnessModel actualFairnessModel) {
-		switch (actualFairnessModel) {
-		case AllEqual:
-			calculateAllEqualNetwork(minimumNetwork, Iteration);
-			break;
-		case MininumDemandFirst:
-		default:
-			calculateMinimumDemandFirstNetwork(minimumNetwork, Iteration);
-			break;
-		}
-	}
-
-	// 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<Edge> getDecoratedCableList() {
-		return edgeList;
-	}
-
-	// 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);
-		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);
-					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 {
-						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));
-
-		calculateStates();
-	}
-
-	private void decorateCable(MinimumNetwork minimumNetwork, float energyToSupplyInTheNetwork) {
-		// DecoratedCables
-		// Minimum demand first:
-		this.edgeList = minimumNetwork.getEdgeList();
-		for (Edge edge : edgeList) {
-			edge.setActualFlow(energyToSupplyInTheNetwork);
-		}
-	}
-
-	private void calculateAllEqualNetwork(MinimumNetwork minimumNetwork, int Iteration) {
-		categorize(minimumNetwork, Iteration);
-		float energyToSupplyInTheNetwork = supplierList.stream()
-				.map(supplier -> supplier.getEnergyToSupplyNetwork() - supplier.getEnergySupplied())
-				.reduce(0.0f, Float::sum);
-		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.
-			float energyNeededForEqualSupply = energyForEachConsumer;
-			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 {
-					supply(con, sup, energyRdyToSupply);
-					energyNeededForEqualSupply -= energyRdyToSupply;
-				}
-			}
-			// No more Energy in the network
-			break;
-		}
-		calculateStates();
-	}
-
-	private void calculateStates() {
-		// CalculateStates:
-		supplierList.forEach(sup -> sup.setState(HolonObjectState.PRODUCER));
-		passivNoEnergyList.forEach(sup -> sup.setState(HolonObjectState.NO_ENERGY));
-		for (Consumer con : this.consumerList) {
-			setConsumerState(con);
-		}
-		for (Consumer con : this.consumerSelfSuppliedList) {
-			setConsumerState(con);
-		}
-	}
-
-	private void categorize(MinimumNetwork minimumNetwork, int Iteration) {
-		// Categorize
-		for (HolonObject hObject : minimumNetwork.getHolonObjectList()) {
-			float energyNeeded = hObject.getEnergyNeededFromConsumingElements();
-			float energySelfProducing = hObject.getEnergySelfProducingFromProducingElements();
-			if (energyNeeded < energySelfProducing) {
-				Supplier sup = new Supplier(hObject, energySelfProducing - energyNeeded, energyNeeded);
-				supplierList.add(sup);
-			} else if (energyNeeded > energySelfProducing) {
-				Consumer con = new Consumer(hObject);
-				con.setEnergyNeededFromNetwork(energyNeeded - energySelfProducing);
-				con.setMinimumConsumingElementEnergy(hObject.getMinimumConsumingElementEnergy());
-				con.setEnergyFromConsumingElemnets(hObject.getEnergyNeededFromConsumingElements());
-				con.setEnergySelfSupplied(hObject.getEnergySelfProducingFromProducingElements());
-				consumerList.add(con);
-			} else if (energyNeeded == energySelfProducing) {
-
-				if (energySelfProducing == 0.0f) {
-					Passiv pas = new Passiv(hObject);
-					passivNoEnergyList.add(pas);
-				} else {
-					Consumer con = new Consumer(hObject);
-					con.setEnergyNeededFromNetwork(0.0f);
-					con.setMinimumConsumingElementEnergy(hObject.getMinimumConsumingElementEnergy());
-					con.setEnergyFromConsumingElemnets(hObject.getEnergyNeededFromConsumingElements());
-					con.setEnergySelfSupplied(hObject.getEnergySelfProducingFromProducingElements());
-					consumerSelfSuppliedList.add(con);
-				}
-
-			}
-		}
-	}
-
-	private void setConsumerState(Consumer con) {
-		if (con.getEnergySelfSupplied() + con.getEnergyFromNetwork() > con.getEnergyFromConsumingElemnets()) {
-			con.setState(HolonObjectState.OVER_SUPPLIED);
-		} else if (con.getEnergySelfSupplied() + con.getEnergyFromNetwork() == con.getEnergyFromConsumingElemnets()) {
-			con.setState(HolonObjectState.SUPPLIED);
-		} else if (con.getEnergySelfSupplied() + con.getEnergyFromNetwork() >= con.getMinimumConsumingElementEnergy()) {
-			con.setState(HolonObjectState.PARTIALLY_SUPPLIED);
-		} 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.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 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());
-	}
-
-	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);
-		return energy;
-	}
-
-	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);
-		return energy;
-	}
-
-	public float getAverageProductionInNetworkForHolonObject() {
-		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);
-		return sum / (float) getAmountOfHolonObjects();
-	}
-
-	public float getDeviationInProductionInNetworkForHolonObjects() {
-		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);
-		return sum / (float) getAmountOfHolonObjects();
-	}
-
-	public float getDeviationInConsumptionInNetworkForHolonObjects() {
-		return (float) Math.sqrt(getVarianzInConsumptionInNetworkForHolonObjects());
-	}
-
-	// HelperFunction
-
-	public Stream<HolonElement> getElementStream() {
-		return Stream.concat(consumerList.stream().flatMap(con -> con.getModel().getElements()),
-				Stream.concat(consumerSelfSuppliedList.stream().flatMap(con -> con.getModel().getElements()),
-						Stream.concat(supplierList.stream().flatMap(con -> con.getModel().getElements()),
-								passivNoEnergyList.stream().flatMap(con -> con.getModel().getElements()))));
-	}
-
-	/**
-	 * 
-	 * @return a list of energy
-	 */
-	public Stream<Float> getListOfEnergyThatIsOfferedByFlexibilitiesInThisNetwork() {
-		return getElementStream()
-				.filter(ele -> (ele.flexList.stream().anyMatch(flex -> flex.offered)))
-				.map(ele -> -ele.getActualEnergy());
-	}
-
-	public Stream<Float> getListOfEnergyInProductionThatIsOfferedByFlexibilitiesInThisNetwork() {
-		return getListOfEnergyThatIsOfferedByFlexibilitiesInThisNetwork().filter(value -> (value > 0.f));
-	}
-
-	public Stream<Float> getListOfEnergyInConsumptionThatIsOfferedByFlexibilitiesInThisNetwork() {
-		return getListOfEnergyThatIsOfferedByFlexibilitiesInThisNetwork().filter(value -> (value < 0.f))
-				.map(value -> -value);
-	}
-
-	public float getFlexibilityProductionCapacity() {
-		return getListOfEnergyInProductionThatIsOfferedByFlexibilitiesInThisNetwork().reduce(0.f, Float::sum);
-	}
-
-	public float getFlexibilityConsumptionCapacity() {
-		return getListOfEnergyInConsumptionThatIsOfferedByFlexibilitiesInThisNetwork().reduce(0.f, Float::sum);
-	}
-
-	public int getAmountOfProductionFlexibilities() {
-		return (int)getListOfEnergyInProductionThatIsOfferedByFlexibilitiesInThisNetwork().count();
-	}
-
-	public int getAmountOfConsumptionFlexibilities() {
-		return (int)getListOfEnergyInConsumptionThatIsOfferedByFlexibilitiesInThisNetwork().count();
-	}
-
-	public float getAverageFlexibilityProduction() {
-		int amount = getAmountOfProductionFlexibilities();
-		return (amount > 0) ? getFlexibilityProductionCapacity() / (float) amount : 0.f;
-	}
-
-	public float getAverageFlexibilityConsumption() {
-		int amount = getAmountOfConsumptionFlexibilities();
-		return (amount > 0) ? getFlexibilityConsumptionCapacity() / (float) amount : 0.f;
-	}
-
-	public float getVarianzInFlexibilitieConsumption() {
-		float average = getAverageFlexibilityConsumption();
-		float sum = getListOfEnergyInConsumptionThatIsOfferedByFlexibilitiesInThisNetwork()
-				.map(energy -> squared(energy - average)).reduce(0.f, Float::sum);
-		int amountOfFlexibilities = getAmountOfConsumptionFlexibilities();
-		return (amountOfFlexibilities > 0) ? sum / (float) amountOfFlexibilities : 0.f;
-	}
-
-	public float getVarianzInFlexibilitieProduction() {
-		float average = getAverageFlexibilityProduction();
-		float sum = getListOfEnergyInProductionThatIsOfferedByFlexibilitiesInThisNetwork()
-				.map(energy -> squared(energy - average)).reduce(0.f, Float::sum);
-		int amountOfFlexibilities = getAmountOfProductionFlexibilities();
-		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
-	private float squared(float input) {
-		return (float) Math.pow(input, 2);
-	}
-
-}
+package holeg.ui.model;
+
+import java.util.ArrayList;
+import java.util.stream.Stream;
+
+import holeg.model.Edge;
+import holeg.model.HolonElement;
+import holeg.model.HolonObject;
+import holeg.model.HolonObject.HolonObjectState;
+import holeg.ui.model.Model.FairnessModel;
+public class DecoratedNetwork {
+//	private ArrayList<Supplier> supplierList = new ArrayList<Supplier>();
+//	private ArrayList<Consumer> consumerList = new ArrayList<Consumer>();
+//	private ArrayList<Consumer> consumerSelfSuppliedList = new ArrayList<Consumer>();
+//	private ArrayList<Passiv> passivNoEnergyList = new ArrayList<Passiv>();
+	private ArrayList<Edge> edgeList = new ArrayList<Edge>();
+
+	public DecoratedNetwork(MinimumNetwork minimumNetwork, int Iteration, FairnessModel actualFairnessModel) {
+		switch (actualFairnessModel) {
+		case AllEqual:
+			calculateAllEqualNetwork(minimumNetwork, Iteration);
+			break;
+		case MininumDemandFirst:
+		default:
+			calculateMinimumDemandFirstNetwork(minimumNetwork, Iteration);
+			break;
+		}
+	}
+
+//	// 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<Edge> getDecoratedCableList() {
+		return edgeList;
+	}
+
+	// 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);
+		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);
+					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 {
+						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));
+
+		calculateStates();
+	}
+
+	private void decorateCable(MinimumNetwork minimumNetwork, float energyToSupplyInTheNetwork) {
+		// DecoratedCables
+		// Minimum demand first:
+		this.edgeList = minimumNetwork.getEdgeList();
+		for (Edge edge : edgeList) {
+			edge.setActualFlow(energyToSupplyInTheNetwork);
+		}
+	}
+
+	private void calculateAllEqualNetwork(MinimumNetwork minimumNetwork, int Iteration) {
+		categorize(minimumNetwork, Iteration);
+		float energyToSupplyInTheNetwork = supplierList.stream()
+				.map(supplier -> supplier.getEnergyToSupplyNetwork() - supplier.getEnergySupplied())
+				.reduce(0.0f, Float::sum);
+		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.
+			float energyNeededForEqualSupply = energyForEachConsumer;
+			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 {
+					supply(con, sup, energyRdyToSupply);
+					energyNeededForEqualSupply -= energyRdyToSupply;
+				}
+			}
+			// No more Energy in the network
+			break;
+		}
+		calculateStates();
+	}
+
+	private void calculateStates() {
+		// CalculateStates:
+		supplierList.forEach(sup -> sup.setState(HolonObjectState.PRODUCER));
+		passivNoEnergyList.forEach(sup -> sup.setState(HolonObjectState.NO_ENERGY));
+		for (Consumer con : this.consumerList) {
+			setConsumerState(con);
+		}
+		for (Consumer con : this.consumerSelfSuppliedList) {
+			setConsumerState(con);
+		}
+	}
+
+	private void categorize(MinimumNetwork minimumNetwork, int Iteration) {
+		// Categorize
+		for (HolonObject hObject : minimumNetwork.getHolonObjectList()) {
+			float energyNeeded = hObject.getEnergyNeededFromConsumingElements();
+			float energySelfProducing = hObject.getEnergySelfProducingFromProducingElements();
+			if (energyNeeded < energySelfProducing) {
+				Supplier sup = new Supplier(hObject, energySelfProducing - energyNeeded, energyNeeded);
+				supplierList.add(sup);
+			} else if (energyNeeded > energySelfProducing) {
+				Consumer con = new Consumer(hObject);
+				con.setEnergyNeededFromNetwork(energyNeeded - energySelfProducing);
+				con.setMinimumConsumingElementEnergy(hObject.getMinimumConsumingElementEnergy());
+				con.setEnergyFromConsumingElemnets(hObject.getEnergyNeededFromConsumingElements());
+				con.setEnergySelfSupplied(hObject.getEnergySelfProducingFromProducingElements());
+				consumerList.add(con);
+			} else if (energyNeeded == energySelfProducing) {
+
+				if (energySelfProducing == 0.0f) {
+					Passiv pas = new Passiv(hObject);
+					passivNoEnergyList.add(pas);
+				} else {
+					Consumer con = new Consumer(hObject);
+					con.setEnergyNeededFromNetwork(0.0f);
+					con.setMinimumConsumingElementEnergy(hObject.getMinimumConsumingElementEnergy());
+					con.setEnergyFromConsumingElemnets(hObject.getEnergyNeededFromConsumingElements());
+					con.setEnergySelfSupplied(hObject.getEnergySelfProducingFromProducingElements());
+					consumerSelfSuppliedList.add(con);
+				}
+
+			}
+		}
+	}
+
+	private void setConsumerState(Consumer con) {
+		if (con.getEnergySelfSupplied() + con.getEnergyFromNetwork() > con.getEnergyFromConsumingElemnets()) {
+			con.setState(HolonObjectState.OVER_SUPPLIED);
+		} else if (con.getEnergySelfSupplied() + con.getEnergyFromNetwork() == con.getEnergyFromConsumingElemnets()) {
+			con.setState(HolonObjectState.SUPPLIED);
+		} else if (con.getEnergySelfSupplied() + con.getEnergyFromNetwork() >= con.getMinimumConsumingElementEnergy()) {
+			con.setState(HolonObjectState.PARTIALLY_SUPPLIED);
+		} 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.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 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());
+	}
+
+	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);
+		return energy;
+	}
+
+	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);
+		return energy;
+	}
+
+	public float getAverageProductionInNetworkForHolonObject() {
+		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);
+		return sum / (float) getAmountOfHolonObjects();
+	}
+
+	public float getDeviationInProductionInNetworkForHolonObjects() {
+		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);
+		return sum / (float) getAmountOfHolonObjects();
+	}
+
+	public float getDeviationInConsumptionInNetworkForHolonObjects() {
+		return (float) Math.sqrt(getVarianzInConsumptionInNetworkForHolonObjects());
+	}
+
+	// HelperFunction
+
+	public Stream<HolonElement> getElementStream() {
+		return Stream.concat(consumerList.stream().flatMap(con -> con.getModel().getElements()),
+				Stream.concat(consumerSelfSuppliedList.stream().flatMap(con -> con.getModel().getElements()),
+						Stream.concat(supplierList.stream().flatMap(con -> con.getModel().getElements()),
+								passivNoEnergyList.stream().flatMap(con -> con.getModel().getElements()))));
+	}
+
+	/**
+	 * 
+	 * @return a list of energy
+	 */
+	public Stream<Float> getListOfEnergyThatIsOfferedByFlexibilitiesInThisNetwork() {
+		return getElementStream()
+				.filter(ele -> (ele.flexList.stream().anyMatch(flex -> flex.offered)))
+				.map(ele -> -ele.getActualEnergy());
+	}
+
+	public Stream<Float> getListOfEnergyInProductionThatIsOfferedByFlexibilitiesInThisNetwork() {
+		return getListOfEnergyThatIsOfferedByFlexibilitiesInThisNetwork().filter(value -> (value > 0.f));
+	}
+
+	public Stream<Float> getListOfEnergyInConsumptionThatIsOfferedByFlexibilitiesInThisNetwork() {
+		return getListOfEnergyThatIsOfferedByFlexibilitiesInThisNetwork().filter(value -> (value < 0.f))
+				.map(value -> -value);
+	}
+
+	public float getFlexibilityProductionCapacity() {
+		return getListOfEnergyInProductionThatIsOfferedByFlexibilitiesInThisNetwork().reduce(0.f, Float::sum);
+	}
+
+	public float getFlexibilityConsumptionCapacity() {
+		return getListOfEnergyInConsumptionThatIsOfferedByFlexibilitiesInThisNetwork().reduce(0.f, Float::sum);
+	}
+
+	public int getAmountOfProductionFlexibilities() {
+		return (int)getListOfEnergyInProductionThatIsOfferedByFlexibilitiesInThisNetwork().count();
+	}
+
+	public int getAmountOfConsumptionFlexibilities() {
+		return (int)getListOfEnergyInConsumptionThatIsOfferedByFlexibilitiesInThisNetwork().count();
+	}
+
+	public float getAverageFlexibilityProduction() {
+		int amount = getAmountOfProductionFlexibilities();
+		return (amount > 0) ? getFlexibilityProductionCapacity() / (float) amount : 0.f;
+	}
+
+	public float getAverageFlexibilityConsumption() {
+		int amount = getAmountOfConsumptionFlexibilities();
+		return (amount > 0) ? getFlexibilityConsumptionCapacity() / (float) amount : 0.f;
+	}
+
+	public float getVarianzInFlexibilitieConsumption() {
+		float average = getAverageFlexibilityConsumption();
+		float sum = getListOfEnergyInConsumptionThatIsOfferedByFlexibilitiesInThisNetwork()
+				.map(energy -> squared(energy - average)).reduce(0.f, Float::sum);
+		int amountOfFlexibilities = getAmountOfConsumptionFlexibilities();
+		return (amountOfFlexibilities > 0) ? sum / (float) amountOfFlexibilities : 0.f;
+	}
+
+	public float getVarianzInFlexibilitieProduction() {
+		float average = getAverageFlexibilityProduction();
+		float sum = getListOfEnergyInProductionThatIsOfferedByFlexibilitiesInThisNetwork()
+				.map(energy -> squared(energy - average)).reduce(0.f, Float::sum);
+		int amountOfFlexibilities = getAmountOfProductionFlexibilities();
+		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
+	private float squared(float input) {
+		return input * input;
+	}
+
+}

+ 0 - 36
src/holeg/ui/model/DecoratedState.java

@@ -1,36 +0,0 @@
-package holeg.ui.model;
-
-import java.util.ArrayList;
-import java.util.stream.Stream;
-
-import holeg.model.Edge;
-import holeg.model.Flexibility;
-
-public class DecoratedState {
-	int timestepOfState;
-	ArrayList<DecoratedNetwork> networkList;
-	ArrayList<Edge> leftOverEdges;
-	ArrayList<DecoratedSwitch> decoratedSwitches;
-	public DecoratedState(ArrayList<DecoratedNetwork> networkList, ArrayList<Edge> leftOverEdges, ArrayList<DecoratedSwitch> decoratedSwitches, int timestepOfState){
-		this.networkList = networkList;
-		this.leftOverEdges = leftOverEdges;
-		this.decoratedSwitches = decoratedSwitches;
-		this.timestepOfState = timestepOfState;
-	}
-	public ArrayList<DecoratedNetwork> getNetworkList() {
-		return networkList;
-	}
-	public ArrayList<Edge> getLeftOverEdges() {
-		return leftOverEdges;
-	}
-	public ArrayList<DecoratedSwitch> getDecoratedSwitches() {
-		return decoratedSwitches;
-	}
-	public int getTimestepOfState() {
-		return timestepOfState;
-	}
-	
-	public Stream<Flexibility> getAllFlex(){
-		return networkList.stream().flatMap(network -> network.getElementStream().flatMap(ele -> ele.flexList.stream()));
-	}
-}

+ 0 - 24
src/holeg/ui/model/DecoratedSwitch.java

@@ -1,24 +0,0 @@
-package holeg.ui.model;
-
-import holeg.model.HolonSwitch;
-
-public class DecoratedSwitch {
-	public enum SwitchState{
-		Closed, Open
-	}
-	private SwitchState state;
-	private HolonSwitch model;
-	public DecoratedSwitch(HolonSwitch hSwitch, SwitchState state){
-		this.model = hSwitch;
-		this.state = state;
-	}
-	public SwitchState getState() {
-		return state;
-	}
-
-	public HolonSwitch getModel() {
-		return model;
-	}
-
-	
-}

+ 0 - 41
src/holeg/ui/model/ExitCable.java

@@ -1,41 +0,0 @@
-package holeg.ui.model;
-
-import holeg.model.AbstractCanvasObject;
-import holeg.model.Edge;
-/**
- * For the Visual State.
- * @author Tom
- *
- */
-public class ExitCable {
-	//Classification 
-	public enum ExitCableState {
-		UP, DOWN, DOWNUP, DOWNDOWN
-	}
-	private ExitCableState state;
-	//GroupNode or AbstractCpsObject
-	private AbstractCanvasObject start;
-	private AbstractCanvasObject finish;
-	private Edge edge;
-	
-	public ExitCable(ExitCableState state, AbstractCanvasObject start, AbstractCanvasObject finish, Edge edge) {
-		this.state = state;
-		this.start = start;
-		this.finish = finish;
-		this.edge = edge;
-	}
-
-	public ExitCableState getState() {
-		return state;
-	}
-	public AbstractCanvasObject getStart() {
-		return start;
-	}
-	public AbstractCanvasObject getFinish() {
-		return finish;
-	}
-	public Edge getEdge() {
-		return edge;
-	}
-
-}

+ 0 - 44
src/holeg/ui/model/IntermediateCalculationCable.java

@@ -1,44 +0,0 @@
-package holeg.ui.model;
-
-import holeg.model.AbstractCanvasObject;
-import holeg.model.Edge;
-import holeg.model.GroupNode;
-
-/**
- * A VisualRepresentation to represent a connection from a UpperNode to a AbstactCpsObject, but actually the UpperNode is not connected.
- * @author Tom
- *
- */
-public class IntermediateCalculationCable {
-	private AbstractCanvasObject outsideObject;
-	private AbstractCanvasObject insideObject;
-	private GroupNode getInsideUpperNode;
-	private GroupNode getOutsideUpperNode;
-	private Edge edge;
-	public IntermediateCalculationCable(Edge edge, GroupNode getInsideUpperNode,GroupNode getOutsideUpperNode, AbstractCanvasObject insideObject, AbstractCanvasObject outsideObject){
-		this.edge = edge;
-		this.getInsideUpperNode = getInsideUpperNode;
-		this.getOutsideUpperNode = getOutsideUpperNode;
-		this.insideObject = insideObject;
-		this.outsideObject = outsideObject;
-	}
-	public AbstractCanvasObject getOusideObject() {
-		return outsideObject;
-	}
-	public AbstractCanvasObject getInsideObject() {
-		return insideObject;
-	}
-	public GroupNode getInsideUpperNode() {
-		return getInsideUpperNode;
-	}
-	public Edge getEdge() {
-		return edge;
-	}
-	public GroupNode getOutsideUpperNode() {
-		return getOutsideUpperNode;
-	}
-	public String toString() {
-		return edge.toString();
-	}
-
-}

+ 35 - 0
src/holeg/ui/model/PriorityCount.java

@@ -0,0 +1,35 @@
+package holeg.ui.model;
+
+import holeg.model.HolonElement;
+import jdk.jfr.Unsigned;
+
+public class PriorityCount {
+	@Unsigned
+	public int low, medium, high, essential;
+
+	public void add(PriorityCount other) {
+		low += other.low;
+		medium += other.medium;
+		high += other.high;
+		essential += other.essential;
+	}
+	public void count(HolonElement element) {
+		switch (element.getPriority()) {
+		case Essential:
+			essential++;
+			break;
+		case High:
+			high++;
+			break;
+		case Medium:
+			medium++;
+			break;
+		case Low:
+			low++;
+			break;
+		default:
+			break;
+
+		}
+	}
+}

+ 246 - 252
src/holeg/ui/view/canvas/Canvas.java

@@ -33,21 +33,13 @@ import holeg.model.Edge;
 import holeg.model.GroupNode;
 import holeg.model.HolonObject;
 import holeg.model.HolonObject.HolonObjectState;
+import holeg.model.HolonSwitch.SwitchMode;
 import holeg.model.HolonSwitch;
 import holeg.model.Node;
 import holeg.preferences.ColorPreference;
 import holeg.preferences.ImagePreference;
 import holeg.ui.controller.Control;
-import holeg.ui.model.Consumer;
-import holeg.ui.model.DecoratedGroupNode;
-import holeg.ui.model.DecoratedHolonObject;
-import holeg.ui.model.DecoratedSwitch;
-import holeg.ui.model.DecoratedSwitch.SwitchState;
-import holeg.ui.model.ExitCable;
 import holeg.ui.model.GuiSettings;
-import holeg.ui.model.Passiv;
-import holeg.ui.model.Supplier;
-import holeg.ui.model.VisualRepresentationalState;
 import holeg.ui.view.inspector.UnitGraph;
 import holeg.utility.image.Import;
 import holeg.utility.math.vector.Vec2i;
@@ -268,158 +260,158 @@ public class Canvas extends AbstractCanvas implements MouseListener, MouseMotion
 
 
 
-	protected void paintCanvasObject(Graphics2D g, DecoratedHolonObject decoratedHolonObject) {
-		Vec2i pos = decoratedHolonObject.getModel().getPosition();
-		Color statecolor = ColorPreference.HolonObject.getStateColor(decoratedHolonObject.getState());
-		g.setColor(statecolor);
-		g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() - GuiSettings.getPictureScaleDiv2(),
-				GuiSettings.getPictureScale(), GuiSettings.getPictureScale());
-		drawCanvasObject(g, decoratedHolonObject.getModel().getImage(), pos);
-	}
-
-	protected void drawCanvasObjectString(Graphics2D g, Vec2i posOfCanvasObject, float energy) {
-		g.setColor(Color.BLACK);
-		g.setFont(new Font("TimesNewRoman", Font.PLAIN, (int) (GuiSettings.getPictureScale() / 4f)));
-		g.drawString((energy > 0) ? "+" + Float.toString(energy) : Float.toString(energy),
-				posOfCanvasObject.getX() - GuiSettings.getPictureScaleDiv2(),
-				posOfCanvasObject.getY() - GuiSettings.getPictureScaleDiv2() - 1);
-	}
-
-	protected void paintConsumer(Graphics2D g, Consumer con) {
-		paintCanvasObject(g, con);
-		drawCanvasObjectString(g, con.getModel().getPosition(), -con.getEnergyNeededFromNetwork());
-		if (GuiSettings.showSupplyBars) {
-			paintSupplyBar(g, con.getSupplyBarPercentage(), ColorPreference.HolonObject.getStateColor(con.getState()),
-					con.getModel().getPosition());
-		}
-	}
-
-	protected void paintSupplier(Graphics2D g, Supplier sup) {
-		paintCanvasObject(g, sup);
-		drawCanvasObjectString(g, sup.getModel().getPosition(), sup.getEnergyToSupplyNetwork());
-	}
-
-	protected void drawCanvasObject(Graphics2D g, String Image, Vec2i pos) {
-		g.drawImage(Import.loadImage(Image, GuiSettings.getPictureScale(), GuiSettings.getPictureScale()),
-				pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() - GuiSettings.getPictureScaleDiv2(), GuiSettings.getPictureScale(),
-				GuiSettings.getPictureScale(), null);
-	}
-
-	protected void paintCable(Graphics2D g, Edge cable, boolean isSelected) {
-		Vec2i start = cable.getA().getPosition();
-		Vec2i end = cable.getB().getPosition();
-		float currentEnergy = cable.getActualFlow();
-		float capacity = cable.maxCapacity;
-		boolean unlimited = cable.isUnlimitedCapacity();
-		switch (cable.getState()) {
-		case Burned:
-			g.setColor(ColorPreference.Edge.Burned);
-			g.setStroke(new BasicStroke(2));
-			break;
-		case Working:
-			g.setColor(ColorPreference.Edge.Working);
-			g.setStroke(new BasicStroke(unlimited ? 2f : (currentEnergy / capacity * 2f) + 1));
-			break;
-		}
-		if (isSelected) {
-			g.setColor(Color.lightGray);
-		}
-		g.drawLine(start.getX(), start.getY(), end.getX(), end.getY());
-		if (showConnectionInformation) {
-			Vec2i middle = new Vec2i((start.getX() + end.getX()) / 2, (start.getY() + end.getY()) / 2);
-			g.setFont(new Font("TimesRoman", Font.PLAIN, Math.max((int) (GuiSettings.getPictureScale() / 3.5f), 10)));
-			g.drawString(currentEnergy + "/" + (unlimited ? "\u221E" : capacity), middle.getX(), middle.getY());
-		}
-	}
-
-	protected void paintSwitch(Graphics2D g, DecoratedSwitch dSwitch) {
-		drawCanvasObject(g, dSwitch.getState() == SwitchState.Open ? HolonSwitch.getSwitchOpenImage()
-				: HolonSwitch.getSwitchClosedImage(), dSwitch.getModel().getPosition());
-	}
-
-	protected void paintExitCable(Graphics2D g, ExitCable eCable) {
-		Vec2i start = eCable.getStart().getPosition();
-		Vec2i end = eCable.getFinish().getPosition();
-		float currentEnergy;
-		float capacity = eCable.getEdge().maxCapacity;
-		boolean unlimited = eCable.getEdge().isUnlimitedCapacity();
-		if(eCable.getEdge().getState() == null) {
-			System.err.print(eCable.getEdge());
-		}
-		switch (eCable.getEdge().getState()) {
-		case Burned:
-			currentEnergy = 0.0f;
-			g.setColor(Color.RED);
-			g.setStroke(new BasicStroke(2));
-			break;
-		case Working:
-		default:
-			currentEnergy = eCable.getEdge().getActualFlow();
-			g.setColor(new Color(13, 175, 28));
-			g.setStroke(new BasicStroke(unlimited ? 2f : (currentEnergy / capacity * 2f) + 1));
-			break;
-		}
-		g.drawLine(start.getX(), start.getY(), end.getX(), end.getY());
-		Vec2i middle = new Vec2i((start.getX() + end.getX()) / 2, (start.getY() + end.getY()) / 2);
-		g.setFont(new Font("TimesRoman", Font.PLAIN, Math.max((int) (GuiSettings.getPictureScale() / 3.5f), 10)));
-		g.drawString(currentEnergy + "/" + (unlimited ? "\u221E" : capacity), middle.getX(), middle.getY());
-	}
-
-	protected void paintGroupNode(Graphics2D g, DecoratedGroupNode dGroupNode) {
-		Vec2i pos = dGroupNode.getModel().getPosition();
-		g.setColor(Color.lightGray);
-		g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() - GuiSettings.getPictureScaleDiv2(),
-				GuiSettings.getPictureScale(), GuiSettings.getPictureScale());
-		drawCanvasObject(g, ImagePreference.Canvas.GroupNode, pos);
-		paintGroupNodeBar(g, dGroupNode, pos);
-	}
-
-	private void paintGroupNodeBar(Graphics2D g, DecoratedGroupNode dGroupNode, Vec2i pos) {
-		// +1, -2, -1 little Adjustment for pixel perfect alignment
-		int barWidth = (int) (GuiSettings.getPictureScale());
-		int barHeight = (int) (GuiSettings.getPictureScale() / 5);
-		g.setColor(Color.WHITE);
-		g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1, (int) barWidth,
-				barHeight);
-		float[] percentages = getGroupNodeBarPercentages(dGroupNode);
-
-		for (int i = 5; i >= 0; i--) {
-			g.setColor(colors[i]);
-			g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1,
-					(int) (barWidth * percentages[i] - 1), barHeight);
-		}
-//		g.setColor(color);
-//		g.fillRect(pos.getX() - GuiSettings.GetPictureScaleDiv2(), pos.getY() + GuiSettings.GetPictureScaleDiv2() - 1, (int) (barWidth * (percentage < 1 ? percentage : 1.0f) - 1), barHeight);
-		g.setColor(Color.BLACK);
-		g.setStroke(new BasicStroke(1));
-		g.drawRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1, barWidth - 1,
-				barHeight);
-	}
-
-	/**
-	 * HardCoded Stuff dont try at Home ;)
-	 * 
-	 * @param dGroupNode
-	 * @return
-	 */
-	public float[] getGroupNodeBarPercentages(DecoratedGroupNode dGroupNode) {
-		int[] amountOfObjects = new int[6];
-		amountOfObjects[0] = dGroupNode.getAmountOfSupplier();
-		amountOfObjects[1] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED);
-		amountOfObjects[2] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED);
-		amountOfObjects[3] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED);
-		amountOfObjects[4] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED);
-		amountOfObjects[5] = dGroupNode.getAmountOfPassiv();
-		int countHolonObjects = amountOfObjects[0] + amountOfObjects[1] + amountOfObjects[2] + amountOfObjects[3]
-				+ amountOfObjects[4] + amountOfObjects[5];
-		float[] percentages = new float[6];
-		int count = 0;
-		for (int i = 0; i < 6; i++) {
-			count += amountOfObjects[i];
-			percentages[i] = (float) count / (float) countHolonObjects;
-		}
-		return percentages;
-	}
+//	protected void paintCanvasObject(Graphics2D g, DecoratedHolonObject decoratedHolonObject) {
+//		Vec2i pos = decoratedHolonObject.getModel().getPosition();
+//		Color statecolor = ColorPreference.HolonObject.getStateColor(decoratedHolonObject.getState());
+//		g.setColor(statecolor);
+//		g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() - GuiSettings.getPictureScaleDiv2(),
+//				GuiSettings.getPictureScale(), GuiSettings.getPictureScale());
+//		drawCanvasObject(g, decoratedHolonObject.getModel().getImage(), pos);
+//	}
+//
+//	protected void drawCanvasObjectString(Graphics2D g, Vec2i posOfCanvasObject, float energy) {
+//		g.setColor(Color.BLACK);
+//		g.setFont(new Font("TimesNewRoman", Font.PLAIN, (int) (GuiSettings.getPictureScale() / 4f)));
+//		g.drawString((energy > 0) ? "+" + Float.toString(energy) : Float.toString(energy),
+//				posOfCanvasObject.getX() - GuiSettings.getPictureScaleDiv2(),
+//				posOfCanvasObject.getY() - GuiSettings.getPictureScaleDiv2() - 1);
+//	}
+//
+//	protected void paintConsumer(Graphics2D g, Consumer con) {
+//		paintCanvasObject(g, con);
+//		drawCanvasObjectString(g, con.getModel().getPosition(), -con.getEnergyNeededFromNetwork());
+//		if (GuiSettings.showSupplyBars) {
+//			paintSupplyBar(g, con.getSupplyBarPercentage(), ColorPreference.HolonObject.getStateColor(con.getState()),
+//					con.getModel().getPosition());
+//		}
+//	}
+//
+//	protected void paintSupplier(Graphics2D g, Supplier sup) {
+//		paintCanvasObject(g, sup);
+//		drawCanvasObjectString(g, sup.getModel().getPosition(), sup.getEnergyToSupplyNetwork());
+//	}
+//
+//	protected void drawCanvasObject(Graphics2D g, String Image, Vec2i pos) {
+//		g.drawImage(Import.loadImage(Image, GuiSettings.getPictureScale(), GuiSettings.getPictureScale()),
+//				pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() - GuiSettings.getPictureScaleDiv2(), GuiSettings.getPictureScale(),
+//				GuiSettings.getPictureScale(), null);
+//	}
+//
+//	protected void paintCable(Graphics2D g, Edge cable, boolean isSelected) {
+//		Vec2i start = cable.getA().getPosition();
+//		Vec2i end = cable.getB().getPosition();
+//		float currentEnergy = cable.getActualFlow();
+//		float capacity = cable.maxCapacity;
+//		boolean unlimited = cable.isUnlimitedCapacity();
+//		switch (cable.getState()) {
+//		case Burned:
+//			g.setColor(ColorPreference.Edge.Burned);
+//			g.setStroke(new BasicStroke(2));
+//			break;
+//		case Working:
+//			g.setColor(ColorPreference.Edge.Working);
+//			g.setStroke(new BasicStroke(unlimited ? 2f : (currentEnergy / capacity * 2f) + 1));
+//			break;
+//		}
+//		if (isSelected) {
+//			g.setColor(Color.lightGray);
+//		}
+//		g.drawLine(start.getX(), start.getY(), end.getX(), end.getY());
+//		if (showConnectionInformation) {
+//			Vec2i middle = new Vec2i((start.getX() + end.getX()) / 2, (start.getY() + end.getY()) / 2);
+//			g.setFont(new Font("TimesRoman", Font.PLAIN, Math.max((int) (GuiSettings.getPictureScale() / 3.5f), 10)));
+//			g.drawString(currentEnergy + "/" + (unlimited ? "\u221E" : capacity), middle.getX(), middle.getY());
+//		}
+//	}
+//
+//	protected void paintSwitch(Graphics2D g, DecoratedSwitch dSwitch) {
+//		drawCanvasObject(g, dSwitch.getState() == SwitchState.Open ? HolonSwitch.getSwitchOpenImage()
+//				: HolonSwitch.getSwitchClosedImage(), dSwitch.getModel().getPosition());
+//	}
+//
+//	protected void paintExitCable(Graphics2D g, ExitCable eCable) {
+//		Vec2i start = eCable.getStart().getPosition();
+//		Vec2i end = eCable.getFinish().getPosition();
+//		float currentEnergy;
+//		float capacity = eCable.getEdge().maxCapacity;
+//		boolean unlimited = eCable.getEdge().isUnlimitedCapacity();
+//		if(eCable.getEdge().getState() == null) {
+//			System.err.print(eCable.getEdge());
+//		}
+//		switch (eCable.getEdge().getState()) {
+//		case Burned:
+//			currentEnergy = 0.0f;
+//			g.setColor(Color.RED);
+//			g.setStroke(new BasicStroke(2));
+//			break;
+//		case Working:
+//		default:
+//			currentEnergy = eCable.getEdge().getActualFlow();
+//			g.setColor(new Color(13, 175, 28));
+//			g.setStroke(new BasicStroke(unlimited ? 2f : (currentEnergy / capacity * 2f) + 1));
+//			break;
+//		}
+//		g.drawLine(start.getX(), start.getY(), end.getX(), end.getY());
+//		Vec2i middle = new Vec2i((start.getX() + end.getX()) / 2, (start.getY() + end.getY()) / 2);
+//		g.setFont(new Font("TimesRoman", Font.PLAIN, Math.max((int) (GuiSettings.getPictureScale() / 3.5f), 10)));
+//		g.drawString(currentEnergy + "/" + (unlimited ? "\u221E" : capacity), middle.getX(), middle.getY());
+//	}
+//
+//	protected void paintGroupNode(Graphics2D g, DecoratedGroupNode dGroupNode) {
+//		Vec2i pos = dGroupNode.getModel().getPosition();
+//		g.setColor(Color.lightGray);
+//		g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() - GuiSettings.getPictureScaleDiv2(),
+//				GuiSettings.getPictureScale(), GuiSettings.getPictureScale());
+//		drawCanvasObject(g, ImagePreference.Canvas.GroupNode, pos);
+//		paintGroupNodeBar(g, dGroupNode, pos);
+//	}
+//
+//	private void paintGroupNodeBar(Graphics2D g, DecoratedGroupNode dGroupNode, Vec2i pos) {
+//		// +1, -2, -1 little Adjustment for pixel perfect alignment
+//		int barWidth = (int) (GuiSettings.getPictureScale());
+//		int barHeight = (int) (GuiSettings.getPictureScale() / 5);
+//		g.setColor(Color.WHITE);
+//		g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1, (int) barWidth,
+//				barHeight);
+//		float[] percentages = getGroupNodeBarPercentages(dGroupNode);
+//
+//		for (int i = 5; i >= 0; i--) {
+//			g.setColor(colors[i]);
+//			g.fillRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1,
+//					(int) (barWidth * percentages[i] - 1), barHeight);
+//		}
+////		g.setColor(color);
+////		g.fillRect(pos.getX() - GuiSettings.GetPictureScaleDiv2(), pos.getY() + GuiSettings.GetPictureScaleDiv2() - 1, (int) (barWidth * (percentage < 1 ? percentage : 1.0f) - 1), barHeight);
+//		g.setColor(Color.BLACK);
+//		g.setStroke(new BasicStroke(1));
+//		g.drawRect(pos.getX() - GuiSettings.getPictureScaleDiv2(), pos.getY() + GuiSettings.getPictureScaleDiv2() - 1, barWidth - 1,
+//				barHeight);
+//	}
+//
+//	/**
+//	 * HardCoded Stuff dont try at Home ;)
+//	 * 
+//	 * @param dGroupNode
+//	 * @return
+//	 */
+//	public float[] getGroupNodeBarPercentages(DecoratedGroupNode dGroupNode) {
+//		int[] amountOfObjects = new int[6];
+//		amountOfObjects[0] = dGroupNode.getAmountOfSupplier();
+//		amountOfObjects[1] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED);
+//		amountOfObjects[2] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED);
+//		amountOfObjects[3] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED);
+//		amountOfObjects[4] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED);
+//		amountOfObjects[5] = dGroupNode.getAmountOfPassiv();
+//		int countHolonObjects = amountOfObjects[0] + amountOfObjects[1] + amountOfObjects[2] + amountOfObjects[3]
+//				+ amountOfObjects[4] + amountOfObjects[5];
+//		float[] percentages = new float[6];
+//		int count = 0;
+//		for (int i = 0; i < 6; i++) {
+//			count += amountOfObjects[i];
+//			percentages[i] = (float) count / (float) countHolonObjects;
+//		}
+//		return percentages;
+//	}
 
 	private void paintSupplyBar(Graphics2D g, float percentage, Color color, Vec2i pos) {
 		// +1, -2, -1 little Adjustment for pixel perfect alignment
@@ -469,96 +461,96 @@ public class Canvas extends AbstractCanvas implements MouseListener, MouseMotion
 
 	public void paintComponent(Graphics g) {
 		super.paintComponent(g);
-		Graphics2D g2d = (Graphics2D) g;
-		g2d.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
-		// -->Old code TODO(Tom2021-12-1): remove
-		if (drawEdge) {
-			g2d.setColor(Color.BLACK);
-			g2d.setStroke(new BasicStroke(1));
-			g2d.drawLine(tempCps.getPosition().getX(), tempCps.getPosition().getY(), x, y);
-		}
-		// <--
-		// timstep:
-		g.setFont(new Font("TimesNewRoman", Font.PLAIN, Math.max((int) (GuiSettings.getPictureScale() / 3.5f), 10)));
-		g2d.setColor(Color.BLACK);
-		
-		Optional<VisualRepresentationalState> optVisualState = control.getSimManager().getActualVisualRepresentationalState();
-		// VisualState Representation:
-		if (optVisualState.isEmpty()) {
-			return;
-		}
-		VisualRepresentationalState visualState = optVisualState.get();
-		
-		for (ExitCable cable : visualState.getExitCableList()) {
-			paintExitCable(g2d, cable);
-		}
-		for (Edge cable : visualState.getCableList()) {
-			paintCable(g2d, cable, GuiSettings.getSelectedEdges().contains(cable));
-		}
-		for (DecoratedGroupNode dGroupNode : visualState.getGroupNodeList()) {
-			paintGroupNode(g2d, dGroupNode);
-		}
-		log.info(visualState.getConsumerList().stream().map(Object::toString).collect(Collectors.joining(", ")));
-		for (Consumer con : visualState.getConsumerList()) {
-			paintConsumer(g2d, con);
-		}
-		log.info(visualState.getSupplierList().stream().map(Object::toString).collect(Collectors.joining(", ")));
-		for (Supplier sup : visualState.getSupplierList()) {
-			paintSupplier(g2d, sup);
-		}
-		for (Passiv pas : visualState.getPassivList()) {
-			paintCanvasObject(g2d, pas);
-		}
-		for (DecoratedSwitch dSwitch : visualState.getSwitchList()) {
-			paintSwitch(g2d, dSwitch);
-		}
-		for (Node node : visualState.getNodeList()) {
-			drawCanvasObject(g2d, ImagePreference.Canvas.Node.Unselected, node.getPosition());
-		}
-
-		// -->oldCode
-		if (doMark) {
-			g2d.setColor(Color.BLACK);
-			g2d.setStroke(new BasicStroke(0));
-			drawMarker(g2d);
-		}
-		// Test Selection
-		// Objects:
-		g2d.setColor(Color.BLUE);
-		g2d.setStroke(new BasicStroke(1));
-		Color transparentGrey = ColorPreference.Panel.ObjectSelection;
-		for (AbstractCanvasObject aCps : GuiSettings.getSelectedObjects()) {
-			if (aCps instanceof Node) {
-				Vec2i pos = aCps.getPosition();
-				g2d.setColor(transparentGrey);
-				g2d.fillOval(pos.getX() - (int) (GuiSettings.getPictureScaleDiv2()),
-						pos.getY() - (int) (GuiSettings.getPictureScaleDiv2()), GuiSettings.getPictureScale(), GuiSettings.getPictureScale());
-				g2d.setColor(Color.LIGHT_GRAY);
-				g2d.setStroke(new BasicStroke(2));
-				g2d.drawOval(pos.getX() - (int) (GuiSettings.getPictureScaleDiv2()),
-						pos.getY() - (int) (GuiSettings.getPictureScaleDiv2()), GuiSettings.getPictureScale(), GuiSettings.getPictureScale());
-			} else {
-				Vec2i pos = aCps.getPosition();
-				g2d.setColor(transparentGrey);
-				g2d.fillRect(pos.getX() - (int) (GuiSettings.getPictureScaleDiv2() * 1.5f),
-						pos.getY() - (int) (GuiSettings.getPictureScaleDiv2() * 1.5f), (int) (GuiSettings.getPictureScale() * 1.5f),
-						(int) (GuiSettings.getPictureScale() * 1.5f));
-				g2d.setColor(Color.LIGHT_GRAY);
-				g2d.setStroke(new BasicStroke(2));
-				g2d.drawRect(pos.getX() - (int) (GuiSettings.getPictureScaleDiv2() * 1.5f),
-						pos.getY() - (int) (GuiSettings.getPictureScaleDiv2() * 1.5f), (int) (GuiSettings.getPictureScale() * 1.5f),
-						(int) (GuiSettings.getPictureScale() * 1.5f));
-			}
-
-		}
-		// maybeReplace:
-		if (mayBeReplaced != null) {
-			g2d.setColor(Color.RED);
-			Vec2i pos = mayBeReplaced.getPosition();
-			g2d.drawImage(Import.loadImage(ImagePreference.Canvas.ReplaceSymbol), pos.getX() + GuiSettings.getPictureScaleDiv2(),
-					pos.getY() - GuiSettings.getPictureScale(), GuiSettings.getPictureScaleDiv2(), GuiSettings.getPictureScaleDiv2(), null);
-		}
-		// <-- OldCode
+//		Graphics2D g2d = (Graphics2D) g;
+//		g2d.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
+//		// -->Old code TODO(Tom2021-12-1): remove
+//		if (drawEdge) {
+//			g2d.setColor(Color.BLACK);
+//			g2d.setStroke(new BasicStroke(1));
+//			g2d.drawLine(tempCps.getPosition().getX(), tempCps.getPosition().getY(), x, y);
+//		}
+//		// <--
+//		// timstep:
+//		g.setFont(new Font("TimesNewRoman", Font.PLAIN, Math.max((int) (GuiSettings.getPictureScale() / 3.5f), 10)));
+//		g2d.setColor(Color.BLACK);
+//		
+//		Optional<VisualRepresentationalState> optVisualState = control.getSimManager().getActualVisualRepresentationalState();
+//		// VisualState Representation:
+//		if (optVisualState.isEmpty()) {
+//			return;
+//		}
+//		VisualRepresentationalState visualState = optVisualState.get();
+//		
+//		for (ExitCable cable : visualState.getExitCableList()) {
+//			paintExitCable(g2d, cable);
+//		}
+//		for (Edge cable : visualState.getCableList()) {
+//			paintCable(g2d, cable, GuiSettings.getSelectedEdges().contains(cable));
+//		}
+//		for (DecoratedGroupNode dGroupNode : visualState.getGroupNodeList()) {
+//			paintGroupNode(g2d, dGroupNode);
+//		}
+//		log.info(visualState.getConsumerList().stream().map(Object::toString).collect(Collectors.joining(", ")));
+//		for (Consumer con : visualState.getConsumerList()) {
+//			paintConsumer(g2d, con);
+//		}
+//		log.info(visualState.getSupplierList().stream().map(Object::toString).collect(Collectors.joining(", ")));
+//		for (Supplier sup : visualState.getSupplierList()) {
+//			paintSupplier(g2d, sup);
+//		}
+//		for (Passiv pas : visualState.getPassivList()) {
+//			paintCanvasObject(g2d, pas);
+//		}
+//		for (DecoratedSwitch dSwitch : visualState.getSwitchList()) {
+//			paintSwitch(g2d, dSwitch);
+//		}
+//		for (Node node : visualState.getNodeList()) {
+//			drawCanvasObject(g2d, ImagePreference.Canvas.Node.Unselected, node.getPosition());
+//		}
+//
+//		// -->oldCode
+//		if (doMark) {
+//			g2d.setColor(Color.BLACK);
+//			g2d.setStroke(new BasicStroke(0));
+//			drawMarker(g2d);
+//		}
+//		// Test Selection
+//		// Objects:
+//		g2d.setColor(Color.BLUE);
+//		g2d.setStroke(new BasicStroke(1));
+//		Color transparentGrey = ColorPreference.Panel.ObjectSelection;
+//		for (AbstractCanvasObject aCps : GuiSettings.getSelectedObjects()) {
+//			if (aCps instanceof Node) {
+//				Vec2i pos = aCps.getPosition();
+//				g2d.setColor(transparentGrey);
+//				g2d.fillOval(pos.getX() - (int) (GuiSettings.getPictureScaleDiv2()),
+//						pos.getY() - (int) (GuiSettings.getPictureScaleDiv2()), GuiSettings.getPictureScale(), GuiSettings.getPictureScale());
+//				g2d.setColor(Color.LIGHT_GRAY);
+//				g2d.setStroke(new BasicStroke(2));
+//				g2d.drawOval(pos.getX() - (int) (GuiSettings.getPictureScaleDiv2()),
+//						pos.getY() - (int) (GuiSettings.getPictureScaleDiv2()), GuiSettings.getPictureScale(), GuiSettings.getPictureScale());
+//			} else {
+//				Vec2i pos = aCps.getPosition();
+//				g2d.setColor(transparentGrey);
+//				g2d.fillRect(pos.getX() - (int) (GuiSettings.getPictureScaleDiv2() * 1.5f),
+//						pos.getY() - (int) (GuiSettings.getPictureScaleDiv2() * 1.5f), (int) (GuiSettings.getPictureScale() * 1.5f),
+//						(int) (GuiSettings.getPictureScale() * 1.5f));
+//				g2d.setColor(Color.LIGHT_GRAY);
+//				g2d.setStroke(new BasicStroke(2));
+//				g2d.drawRect(pos.getX() - (int) (GuiSettings.getPictureScaleDiv2() * 1.5f),
+//						pos.getY() - (int) (GuiSettings.getPictureScaleDiv2() * 1.5f), (int) (GuiSettings.getPictureScale() * 1.5f),
+//						(int) (GuiSettings.getPictureScale() * 1.5f));
+//			}
+//
+//		}
+//		// maybeReplace:
+//		if (mayBeReplaced != null) {
+//			g2d.setColor(Color.RED);
+//			Vec2i pos = mayBeReplaced.getPosition();
+//			g2d.drawImage(Import.loadImage(ImagePreference.Canvas.ReplaceSymbol), pos.getX() + GuiSettings.getPictureScaleDiv2(),
+//					pos.getY() - GuiSettings.getPictureScale(), GuiSettings.getPictureScaleDiv2(), GuiSettings.getPictureScaleDiv2(), null);
+//		}
+//		// <-- OldCode
 	}
 
 	@Override
@@ -675,7 +667,9 @@ public class Canvas extends AbstractCanvas implements MouseListener, MouseMotion
 			boolean doubleclick = doubleClick();
 			if (doubleclick && tempCps instanceof HolonSwitch sw && MouseEvent.BUTTON3 != e.getButton()
 					&& tempCps != null) {
-				sw.switchState();
+				
+				sw.setMode(SwitchMode.Manual);
+				sw.flipManualState();
 			}
 			if (doubleclick && tempCps != null && tempCps instanceof GroupNode groupnode) {
 				control.getGui().openNewUpperNodeTab(groupnode);

+ 166 - 204
src/holeg/ui/view/information/FilterableGroupNode.java

@@ -11,13 +11,6 @@ import holeg.model.GroupNode;
 import holeg.model.HolonElement;
 import holeg.model.HolonObject.HolonObjectState;
 import holeg.model.Node;
-import holeg.ui.model.Consumer;
-import holeg.ui.model.DecoratedGroupNode;
-import holeg.ui.model.DecoratedHolonObject;
-import holeg.ui.model.DecoratedSwitch;
-import holeg.ui.model.ExitCable;
-import holeg.ui.model.Passiv;
-import holeg.ui.model.Supplier;
 import jdk.jfr.Unsigned;
 
 /**
@@ -26,203 +19,172 @@ import jdk.jfr.Unsigned;
  * @author Tom
  *
  */
+//TODO(Tom2022-01-13): Fix or remove
 public class FilterableGroupNode {
-	private GroupNode model;
-	private ArrayList<Supplier> supplierList = new ArrayList<>();
-	private ArrayList<Passiv> passivList = new ArrayList<>();
-	private ArrayList<Consumer> consumerList = new ArrayList<>();
-	private ArrayList<Node> nodeList = new ArrayList<>();
-	/**
-	 * Cables that only exist on that group node. From a object in that group node
-	 * to a object in that group Node. Not exit the group node (a layer down).
-	 */
-	private ArrayList<Edge> internCableList = new ArrayList<>();
-	/**
-	 * Cables that exit this group node (a Layer Up). From a object in this group
-	 * node to a object in a upper layer.
-	 */
-	private ArrayList<ExitCable> exitCableList = new ArrayList<>();
-	private ArrayList<DecoratedSwitch> switchList = new ArrayList<>();
-	private ArrayList<FilterableGroupNode> groupNodeList = new ArrayList<>();
-
-	public FilterableGroupNode(GroupNode model, int iteration) {
-		this.model = model;
-	}
-
-	public FilterableGroupNode(DecoratedGroupNode dGroupNode, int iteration) {
-		model = dGroupNode.getModel();
-		supplierList = dGroupNode.getSupplierList();
-		passivList = dGroupNode.getPassivList();
-		consumerList = dGroupNode.getConsumerList();
-		nodeList = dGroupNode.getNodeList();
-		internCableList = dGroupNode.getInternCableList();
-		exitCableList = dGroupNode.getExitCableList();
-		switchList = dGroupNode.getSwitchList();
-		groupNodeList = (ArrayList<FilterableGroupNode>) dGroupNode.getGroupNodeList().stream()
-				.map(node -> new FilterableGroupNode(node, iteration)).collect(Collectors.toList());
-	}
-
-	public GroupNode getModel() {
-		return model;
-	}
-
-	public ArrayList<Supplier> getSupplierList() {
-		return supplierList;
-	}
-
-	public ArrayList<Passiv> getPassivList() {
-		return passivList;
-	}
-
-	public ArrayList<Consumer> getConsumerList() {
-		return consumerList;
-	}
-
-	public ArrayList<Node> getNodeList() {
-		return nodeList;
-	}
-
-	public ArrayList<Edge> getInternCableList() {
-		return internCableList;
-	}
-
-	public ArrayList<ExitCable> getExitCableList() {
-		return exitCableList;
-	}
-
-	public ArrayList<DecoratedSwitch> getSwitchList() {
-		return switchList;
-	}
-
-	public ArrayList<FilterableGroupNode> getGroupNodeList() {
-		return groupNodeList;
-	}
-
-	// Returns the amount of holons and count himself
-	public int getAmountOfGroupNodes() {
-		return groupNodeList.stream().map(groupNode -> groupNode.getAmountOfGroupNodes()).reduce(1, Integer::sum);
-	}
-
-	public Stream<Flexibility> getFlexibilitiesStream(Predicate<DecoratedHolonObject> stateFilter,
-			Predicate<HolonElement> priorityFilter) {
-
-		Stream<Flexibility> flexInChildGorupNode = this.groupNodeList.stream()
-				.flatMap(groupNode -> groupNode.getFlexibilitiesStream(stateFilter, priorityFilter));
-
-		Stream<Flexibility> flexInThisGorupNode = objectStream().filter(stateFilter).flatMap(object -> object.getModel()
-				.getElements().filter(priorityFilter).flatMap(ele -> ele.flexList.stream()));
-
-		return Stream.concat(flexInChildGorupNode, flexInThisGorupNode);
-	}
-
-	public Stream<DecoratedHolonObject> objectStream() {
-		return Stream.concat(Stream.concat(this.consumerList.stream(), this.supplierList.stream()),
-				this.passivList.stream());
-	}
-
-	// Gather Informations:
-	public int getAmountOfSupplier(Predicate<DecoratedHolonObject> stateFilter) {
-		return (int) supplierList.stream().filter(stateFilter).count() + groupNodeList.stream()
-				.map(groupNode -> groupNode.getAmountOfSupplier(stateFilter)).reduce(0, Integer::sum);
-	}
-
-	public int getAmountOfConsumer(Predicate<DecoratedHolonObject> stateFilter) {
-		return (int) consumerList.stream().filter(stateFilter).count() + groupNodeList.stream()
-				.map(groupNode -> groupNode.getAmountOfConsumer(stateFilter)).reduce(0, Integer::sum);
-	}
-
-	public int getAmountOfPassiv(Predicate<DecoratedHolonObject> stateFilter) {
-		return (int) passivList.stream().filter(stateFilter).count() + groupNodeList.stream()
-				.map(groupNode -> groupNode.getAmountOfPassiv(stateFilter)).reduce(0, Integer::sum);
-	}
-
-	public int getAmountOfConsumerWithState(Predicate<DecoratedHolonObject> stateFilter, HolonObjectState state) {
-		return ((int) consumerList.stream().filter(stateFilter).map(con -> con.getState())
-				.filter(rightState -> (rightState == state)).count())
-				+ groupNodeList.stream().map(groupNode -> groupNode.getAmountOfConsumerWithState(stateFilter, state))
-						.reduce(0, Integer::sum);
-	}
-
-	public PriorityCounts getPriorityCounts(Predicate<DecoratedHolonObject> stateFilter) {
-		PriorityCounts priority = new PriorityCounts();
-		objectStream().filter(stateFilter)
-				.forEach(object -> object.getModel().getElements().forEach(ele -> priority.Count(ele)));
-		groupNodeList.stream().forEach(groupNode -> priority.Add(groupNode.getPriorityCounts(stateFilter)));
-		return priority;
-	}
-
-	public class PriorityCounts {
-		@Unsigned
-		public int low, medium, high, essential;
-
-		public void Add(PriorityCounts other) {
-			low += other.low;
-			medium += other.medium;
-			high += other.high;
-			essential += other.essential;
-		}
-
-		public void Count(HolonElement element) {
-			switch (element.getPriority()) {
-			case Essential:
-				essential++;
-				break;
-			case High:
-				high++;
-				break;
-			case Medium:
-				medium++;
-				break;
-			case Low:
-				low++;
-				break;
-			default:
-				break;
-
-			}
-		}
-	}
-
-	public int getAmountOfElementsFromHolonObjects(Predicate<DecoratedHolonObject> stateFilter,
-			Predicate<HolonElement> priorityFilter) {
-		return objectStream().filter(stateFilter)
-				.map(object -> (int) object.getModel().getElements().filter(priorityFilter).count())
-				.reduce(0, Integer::sum)
-				+ groupNodeList.stream()
-						.map(groupNode -> groupNode.getAmountOfElementsFromHolonObjects(stateFilter, priorityFilter))
-						.reduce(0, Integer::sum);
-	}
-
-	public int getAmountOfAktiveElementsFromHolonObjects(Predicate<DecoratedHolonObject> stateFilter,
-			Predicate<HolonElement> priorityFilter) {
-		return objectStream().filter(stateFilter)
-				.map(object -> (int) object.getModel().getElements().filter(priorityFilter).count())
-				.reduce(0, Integer::sum)
-				+ groupNodeList.stream().map(
-						groupNode -> groupNode.getAmountOfAktiveElementsFromHolonObjects(stateFilter, priorityFilter))
-						.reduce(0, Integer::sum);
-	}
-
-	public float getConsumption(Predicate<DecoratedHolonObject> stateFilter, Predicate<HolonElement> priorityFilter) {
-		return ((Stream<DecoratedHolonObject>) Stream.concat(this.consumerList.stream(), supplierList.stream()))
-				.filter(stateFilter)
-				.map(con -> con.getModel().getElements()
-						.filter(priorityFilter.and(ele -> ele.getActualEnergy() < 0))
-						.map(ele -> -ele.getActualEnergy()).reduce(0.0f, Float::sum))
-				.reduce(0.f, Float::sum)
-				+ groupNodeList.stream().map(groupNode -> groupNode.getConsumption(stateFilter, priorityFilter))
-						.reduce(0.f, Float::sum);
-	}
-
-	public float getProduction(Predicate<DecoratedHolonObject> stateFilter, Predicate<HolonElement> priorityFilter) {
-		return ((Stream<DecoratedHolonObject>) Stream.concat(this.consumerList.stream(), supplierList.stream()))
-				.filter(stateFilter)
-				.map(con -> con.getModel().getElements()
-						.filter(priorityFilter.and(ele -> ele.getActualEnergy() > 0))
-						.map(ele -> ele.getActualEnergy()).reduce(0.0f, Float::sum))
-				.reduce(0.f, Float::sum)
-				+ groupNodeList.stream().map(groupNode -> groupNode.getProduction(stateFilter, priorityFilter))
-						.reduce(0.f, Float::sum);
-	}
+//	private GroupNode model;
+//	private ArrayList<Supplier> supplierList = new ArrayList<>();
+//	private ArrayList<Passiv> passivList = new ArrayList<>();
+//	private ArrayList<Consumer> consumerList = new ArrayList<>();
+//	private ArrayList<Node> nodeList = new ArrayList<>();
+//	/**
+//	 * Cables that only exist on that group node. From a object in that group node
+//	 * to a object in that group Node. Not exit the group node (a layer down).
+//	 */
+//	private ArrayList<Edge> internCableList = new ArrayList<>();
+//	/**
+//	 * Cables that exit this group node (a Layer Up). From a object in this group
+//	 * node to a object in a upper layer.
+//	 */
+//	private ArrayList<ExitCable> exitCableList = new ArrayList<>();
+//	private ArrayList<DecoratedSwitch> switchList = new ArrayList<>();
+//	private ArrayList<FilterableGroupNode> groupNodeList = new ArrayList<>();
+//
+//	public FilterableGroupNode(GroupNode model, int iteration) {
+//		this.model = model;
+//	}
+//
+//	public FilterableGroupNode(DecoratedGroupNode dGroupNode, int iteration) {
+//		model = dGroupNode.getModel();
+//		supplierList = dGroupNode.getSupplierList();
+//		passivList = dGroupNode.getPassivList();
+//		consumerList = dGroupNode.getConsumerList();
+//		nodeList = dGroupNode.getNodeList();
+//		internCableList = dGroupNode.getInternCableList();
+//		exitCableList = dGroupNode.getExitCableList();
+//		switchList = dGroupNode.getSwitchList();
+//		groupNodeList = (ArrayList<FilterableGroupNode>) dGroupNode.getGroupNodeList().stream()
+//				.map(node -> new FilterableGroupNode(node, iteration)).collect(Collectors.toList());
+//	}
+//
+//	public GroupNode getModel() {
+//		return model;
+//	}
+//
+//	public ArrayList<Supplier> getSupplierList() {
+//		return supplierList;
+//	}
+//
+//	public ArrayList<Passiv> getPassivList() {
+//		return passivList;
+//	}
+//
+//	public ArrayList<Consumer> getConsumerList() {
+//		return consumerList;
+//	}
+//
+//	public ArrayList<Node> getNodeList() {
+//		return nodeList;
+//	}
+//
+//	public ArrayList<Edge> getInternCableList() {
+//		return internCableList;
+//	}
+//
+//	public ArrayList<ExitCable> getExitCableList() {
+//		return exitCableList;
+//	}
+//
+//	public ArrayList<DecoratedSwitch> getSwitchList() {
+//		return switchList;
+//	}
+//
+//	public ArrayList<FilterableGroupNode> getGroupNodeList() {
+//		return groupNodeList;
+//	}
+//
+//	// Returns the amount of holons and count himself
+//	public int getAmountOfGroupNodes() {
+//		return groupNodeList.stream().map(groupNode -> groupNode.getAmountOfGroupNodes()).reduce(1, Integer::sum);
+//	}
+//
+//	public Stream<Flexibility> getFlexibilitiesStream(Predicate<DecoratedHolonObject> stateFilter,
+//			Predicate<HolonElement> priorityFilter) {
+//
+//		Stream<Flexibility> flexInChildGorupNode = this.groupNodeList.stream()
+//				.flatMap(groupNode -> groupNode.getFlexibilitiesStream(stateFilter, priorityFilter));
+//
+//		Stream<Flexibility> flexInThisGorupNode = objectStream().filter(stateFilter).flatMap(object -> object.getModel()
+//				.getElements().filter(priorityFilter).flatMap(ele -> ele.flexList.stream()));
+//
+//		return Stream.concat(flexInChildGorupNode, flexInThisGorupNode);
+//	}
+//
+//	public Stream<DecoratedHolonObject> objectStream() {
+//		return Stream.concat(Stream.concat(this.consumerList.stream(), this.supplierList.stream()),
+//				this.passivList.stream());
+//	}
+//
+//	// Gather Informations:
+//	public int getAmountOfSupplier(Predicate<DecoratedHolonObject> stateFilter) {
+//		return (int) supplierList.stream().filter(stateFilter).count() + groupNodeList.stream()
+//				.map(groupNode -> groupNode.getAmountOfSupplier(stateFilter)).reduce(0, Integer::sum);
+//	}
+//
+//	public int getAmountOfConsumer(Predicate<DecoratedHolonObject> stateFilter) {
+//		return (int) consumerList.stream().filter(stateFilter).count() + groupNodeList.stream()
+//				.map(groupNode -> groupNode.getAmountOfConsumer(stateFilter)).reduce(0, Integer::sum);
+//	}
+//
+//	public int getAmountOfPassiv(Predicate<DecoratedHolonObject> stateFilter) {
+//		return (int) passivList.stream().filter(stateFilter).count() + groupNodeList.stream()
+//				.map(groupNode -> groupNode.getAmountOfPassiv(stateFilter)).reduce(0, Integer::sum);
+//	}
+//
+//	public int getAmountOfConsumerWithState(Predicate<DecoratedHolonObject> stateFilter, HolonObjectState state) {
+//		return ((int) consumerList.stream().filter(stateFilter).map(con -> con.getState())
+//				.filter(rightState -> (rightState == state)).count())
+//				+ groupNodeList.stream().map(groupNode -> groupNode.getAmountOfConsumerWithState(stateFilter, state))
+//						.reduce(0, Integer::sum);
+//	}
+//
+//	public PriorityCounts getPriorityCounts(Predicate<DecoratedHolonObject> stateFilter) {
+//		PriorityCounts priority = new PriorityCounts();
+//		objectStream().filter(stateFilter)
+//				.forEach(object -> object.getModel().getElements().forEach(ele -> priority.count(ele)));
+//		groupNodeList.stream().forEach(groupNode -> priority.add(groupNode.getPriorityCounts(stateFilter)));
+//		return priority;
+//	}
+//
+//	public int getAmountOfElementsFromHolonObjects(Predicate<DecoratedHolonObject> stateFilter,
+//			Predicate<HolonElement> priorityFilter) {
+//		return objectStream().filter(stateFilter)
+//				.map(object -> (int) object.getModel().getElements().filter(priorityFilter).count())
+//				.reduce(0, Integer::sum)
+//				+ groupNodeList.stream()
+//						.map(groupNode -> groupNode.getAmountOfElementsFromHolonObjects(stateFilter, priorityFilter))
+//						.reduce(0, Integer::sum);
+//	}
+//
+//	public int getAmountOfAktiveElementsFromHolonObjects(Predicate<DecoratedHolonObject> stateFilter,
+//			Predicate<HolonElement> priorityFilter) {
+//		return objectStream().filter(stateFilter)
+//				.map(object -> (int) object.getModel().getElements().filter(priorityFilter).count())
+//				.reduce(0, Integer::sum)
+//				+ groupNodeList.stream().map(
+//						groupNode -> groupNode.getAmountOfAktiveElementsFromHolonObjects(stateFilter, priorityFilter))
+//						.reduce(0, Integer::sum);
+//	}
+//
+//	public float getConsumption(Predicate<DecoratedHolonObject> stateFilter, Predicate<HolonElement> priorityFilter) {
+//		return ((Stream<DecoratedHolonObject>) Stream.concat(this.consumerList.stream(), supplierList.stream()))
+//				.filter(stateFilter)
+//				.map(con -> con.getModel().getElements()
+//						.filter(priorityFilter.and(ele -> ele.getActualEnergy() < 0))
+//						.map(ele -> -ele.getActualEnergy()).reduce(0.0f, Float::sum))
+//				.reduce(0.f, Float::sum)
+//				+ groupNodeList.stream().map(groupNode -> groupNode.getConsumption(stateFilter, priorityFilter))
+//						.reduce(0.f, Float::sum);
+//	}
+//
+//	public float getProduction(Predicate<DecoratedHolonObject> stateFilter, Predicate<HolonElement> priorityFilter) {
+//		return ((Stream<DecoratedHolonObject>) Stream.concat(this.consumerList.stream(), supplierList.stream()))
+//				.filter(stateFilter)
+//				.map(con -> con.getModel().getElements()
+//						.filter(priorityFilter.and(ele -> ele.getActualEnergy() > 0))
+//						.map(ele -> ele.getActualEnergy()).reduce(0.0f, Float::sum))
+//				.reduce(0.f, Float::sum)
+//				+ groupNodeList.stream().map(groupNode -> groupNode.getProduction(stateFilter, priorityFilter))
+//						.reduce(0.f, Float::sum);
+//	}
 
 }

+ 119 - 132
src/holeg/ui/view/information/HolonInformationPanel.java

@@ -36,18 +36,13 @@ import holeg.model.HolonObject;
 import holeg.model.HolonObject.HolonObjectState;
 import holeg.preferences.ColorPreference;
 import holeg.ui.controller.Control;
-import holeg.ui.model.Consumer;
-import holeg.ui.model.DecoratedGroupNode;
-import holeg.ui.model.DecoratedHolonObject;
-import holeg.ui.model.Passiv;
-import holeg.ui.model.Supplier;
-import holeg.ui.model.VisualRepresentationalState;
 import holeg.utility.math.decimal.Format;
 import holeg.ui.model.GuiSettings;
 
+//TODO(Tom2022-01-13): Fix;
 public class HolonInformationPanel extends JPanel {
 	private static final Logger log = Logger.getLogger(JPanel.class.getName());
-	private Predicate<DecoratedHolonObject> stateFilter = (object) -> true;// = (object) -> object.getState() ==
+	//private Predicate<DecoratedHolonObject> stateFilter = (object) -> true;// = (object) -> object.getState() ==
 																			// HolonObjectState.PRODUCER;
 	private Predicate<HolonElement> priorityFilter = (ele) -> true;
 	private final int defaultWidth = 50;
@@ -109,142 +104,134 @@ public class HolonInformationPanel extends JPanel {
 		
 		FilterableGroupNode decoratedGroupNode = filteredGroupNode.get();
 		// UPDATE SUPPLY STATE
-		int producerAmount = decoratedGroupNode.getAmountOfSupplier(stateFilter);
-		int overSuppliedAmount = decoratedGroupNode.getAmountOfConsumerWithState(stateFilter,
-				HolonObjectState.OVER_SUPPLIED);
-		int suppliedAmount = decoratedGroupNode.getAmountOfConsumerWithState(stateFilter, HolonObjectState.SUPPLIED);
-		int partiallySuppliedAmount = decoratedGroupNode.getAmountOfConsumerWithState(stateFilter,
-				HolonObjectState.PARTIALLY_SUPPLIED);
-		int notSuppliedAmount = decoratedGroupNode.getAmountOfConsumerWithState(stateFilter,
-				HolonObjectState.NOT_SUPPLIED);
-		int noEnergyAmount = decoratedGroupNode.getAmountOfPassiv(stateFilter);
-
-		supplyChart.updatePieSeries("Producer", producerAmount);
-		supplyChart.updatePieSeries("Over supplied", overSuppliedAmount);
-		supplyChart.updatePieSeries("Supplied", suppliedAmount);
-		supplyChart.updatePieSeries("Partial supplied", partiallySuppliedAmount);
-		supplyChart.updatePieSeries("Not supplied", notSuppliedAmount);
-		supplyChart.updatePieSeries("No energy", noEnergyAmount);
-		updateToolTips(panelHolonObject);
+//		int producerAmount = decoratedGroupNode.getAmountOfSupplier(stateFilter);
+//		int overSuppliedAmount = decoratedGroupNode.getAmountOfConsumerWithState(stateFilter,
+//				HolonObjectState.OVER_SUPPLIED);
+//		int suppliedAmount = decoratedGroupNode.getAmountOfConsumerWithState(stateFilter, HolonObjectState.SUPPLIED);
+//		int partiallySuppliedAmount = decoratedGroupNode.getAmountOfConsumerWithState(stateFilter,
+//				HolonObjectState.PARTIALLY_SUPPLIED);
+//		int notSuppliedAmount = decoratedGroupNode.getAmountOfConsumerWithState(stateFilter,
+//				HolonObjectState.NOT_SUPPLIED);
+//		int noEnergyAmount = decoratedGroupNode.getAmountOfPassiv(stateFilter);
+//
+//		supplyChart.updatePieSeries("Producer", producerAmount);
+//		supplyChart.updatePieSeries("Over supplied", overSuppliedAmount);
+//		supplyChart.updatePieSeries("Supplied", suppliedAmount);
+//		supplyChart.updatePieSeries("Partial supplied", partiallySuppliedAmount);
+//		supplyChart.updatePieSeries("Not supplied", notSuppliedAmount);
+//		supplyChart.updatePieSeries("No energy", noEnergyAmount);
 
 		// UPDATE PRIORITYS
-		holeg.ui.view.information.FilterableGroupNode.PriorityCounts priorityCounts = decoratedGroupNode
-				.getPriorityCounts(stateFilter);
-
-		priorityChart.updatePieSeries("Essential", priorityCounts.essential);
-		priorityChart.updatePieSeries("High", priorityCounts.high);
-		priorityChart.updatePieSeries("Medium", priorityCounts.medium);
-		priorityChart.updatePieSeries("Low", priorityCounts.low);
-		boolean hasPriority = priorityCounts.essential + priorityCounts.high + priorityCounts.medium
-				+ priorityCounts.low > 0;
-		priorityChart.updatePieSeries("No Data", hasPriority ? 0 : 1);
-		updateToolTips(panelPriority);
+//		holeg.ui.view.information.FilterableGroupNode.PriorityCounts priorityCounts = decoratedGroupNode
+//				.getPriorityCounts(stateFilter);
+//
+//		priorityChart.updatePieSeries("Essential", priorityCounts.essential);
+//		priorityChart.updatePieSeries("High", priorityCounts.high);
+//		priorityChart.updatePieSeries("Medium", priorityCounts.medium);
+//		priorityChart.updatePieSeries("Low", priorityCounts.low);
+//		boolean hasPriority = priorityCounts.essential + priorityCounts.high + priorityCounts.medium
+//				+ priorityCounts.low > 0;
+//		priorityChart.updatePieSeries("No Data", hasPriority ? 0 : 1);
+//		updateToolTips(panelPriority);
 
 		// UPDATE PRODUCTION
-		float production = decoratedGroupNode.getProduction(stateFilter, priorityFilter);
-		float consumption = decoratedGroupNode.getConsumption(stateFilter, priorityFilter);
-		log.info("production" + production + " consumption" + consumption);
-		float difference = Math.abs(production - consumption);
-		energyChart.updatePieSeries("Production", production);
-		energyChart.updatePieSeries("Consumption", consumption);
-		differenceEnergyLabelAmount.setText(Format.doubleFixedPlaces(1, difference));
-		updateToolTips(panelEnergy);
-
-		// UPDATE FLEXIBILITIES
-		int inUse = 0;
-		int offered = 0;
-		int onCooldown = 0;
-		int notOffered = 0;
-		int unavailable = 0;
-
-		Stream<Flexibility> flexWrapperStream = decoratedGroupNode.getFlexibilitiesStream(stateFilter, priorityFilter);
-		List<Flexibility> flexList = flexWrapperStream.collect(Collectors.toList());
-		for (Flexibility flex : flexList) {
-			switch (flex.getState()) {
-			case IN_USE:
-				inUse++;
-				break;
-			case NOT_OFFERED:
-				notOffered++;
-				break;
-			case OFFERED:
-				offered++;
-				break;
-			case ON_COOLDOWN:
-				onCooldown++;
-				break;
-			case UNAVAILABLE:
-				unavailable++;
-				break;
-			default:
-				break;
-
-			}
-		}
-		flexibilityChart.updatePieSeries("Offered", offered);
-		flexibilityChart.updatePieSeries("In use", inUse);
-		flexibilityChart.updatePieSeries("On cooldown", onCooldown);
-		flexibilityChart.updatePieSeries("Not offered", notOffered);
-		flexibilityChart.updatePieSeries("Unavailable", unavailable);
-		boolean hasFlex = offered + inUse + onCooldown + notOffered + unavailable > 0;
-		flexibilityChart.updatePieSeries("No Data", hasFlex ? 0 : 1);
-		updateToolTips(panelFlexibility);
-
-		// UPDATE ActiveInActive
-		int activeAmount = decoratedGroupNode.getAmountOfAktiveElementsFromHolonObjects(stateFilter, priorityFilter);
-		int inactiveAmounts = decoratedGroupNode.getAmountOfElementsFromHolonObjects(stateFilter, priorityFilter)
-				- activeAmount;
-		activeChart.updatePieSeries("Active", activeAmount);
-		activeChart.updatePieSeries("Inactive", inactiveAmounts);
-		updateToolTips(panelActive);
+//		float production = decoratedGroupNode.getProduction(stateFilter, priorityFilter);
+//		float consumption = decoratedGroupNode.getConsumption(stateFilter, priorityFilter);
+//		log.info("production" + production + " consumption" + consumption);
+//		float difference = Math.abs(production - consumption);
+//		energyChart.updatePieSeries("Production", production);
+//		energyChart.updatePieSeries("Consumption", consumption);
+//		differenceEnergyLabelAmount.setText(Format.doubleFixedPlaces(1, difference));
+//
+//		// UPDATE FLEXIBILITIES
+//		int inUse = 0;
+//		int offered = 0;
+//		int onCooldown = 0;
+//		int notOffered = 0;
+//		int unavailable = 0;
+//
+//		Stream<Flexibility> flexWrapperStream = decoratedGroupNode.getFlexibilitiesStream(stateFilter, priorityFilter);
+//		List<Flexibility> flexList = flexWrapperStream.collect(Collectors.toList());
+//		for (Flexibility flex : flexList) {
+//			switch (flex.getState()) {
+//			case IN_USE:
+//				inUse++;
+//				break;
+//			case NOT_OFFERED:
+//				notOffered++;
+//				break;
+//			case OFFERED:
+//				offered++;
+//				break;
+//			case ON_COOLDOWN:
+//				onCooldown++;
+//				break;
+//			case UNAVAILABLE:
+//				unavailable++;
+//				break;
+//			default:
+//				break;
+//
+//			}
+//		}
+//		flexibilityChart.updatePieSeries("Offered", offered);
+//		flexibilityChart.updatePieSeries("In use", inUse);
+//		flexibilityChart.updatePieSeries("On cooldown", onCooldown);
+//		flexibilityChart.updatePieSeries("Not offered", notOffered);
+//		flexibilityChart.updatePieSeries("Unavailable", unavailable);
+//		boolean hasFlex = offered + inUse + onCooldown + notOffered + unavailable > 0;
+//		flexibilityChart.updatePieSeries("No Data", hasFlex ? 0 : 1);
+//		// UPDATE ActiveInActive
+//		int activeAmount = decoratedGroupNode.getAmountOfAktiveElementsFromHolonObjects(stateFilter, priorityFilter);
+//		int inactiveAmounts = decoratedGroupNode.getAmountOfElementsFromHolonObjects(stateFilter, priorityFilter)
+//				- activeAmount;
+//		activeChart.updatePieSeries("Active", activeAmount);
+//		activeChart.updatePieSeries("Inactive", inactiveAmounts);
 
 		this.revalidate();
 		this.repaint();
 	}
 
-	private void updateToolTips(XChartPanel<PieChart> chart) {
-		log.info("UpdatetoolTips");
-		
-	}
 
 	private Optional<FilterableGroupNode> multiSelectionToFilterableGroupNode() {
-		FilterableGroupNode temp = new FilterableGroupNode(new GroupNode("Temp"),
-				control.getModel().getCurrentIteration());
-
-		Optional<VisualRepresentationalState> visState = control.getSimManager().getActualVisualRepresentationalState();
-		if(visState.isEmpty()) {
-			return Optional.empty();
-		}
-		
-		// GroupNodes
-		HashMap<GroupNode, DecoratedGroupNode> accessMapGroupNode = visState.get().getCreatedGroupNodes();
-		List<FilterableGroupNode> groupNodeList = GuiSettings.getSelectedObjects().stream()
-				.filter(object -> object instanceof GroupNode).map(object -> accessMapGroupNode.get(object))
-				.map(node -> new FilterableGroupNode(node, control.getModel().getCurrentIteration()))
-				.collect(Collectors.toList());
-
-		temp.getGroupNodeList().addAll(groupNodeList);
-
-		// HolonObjects
-		HashMap<HolonObject, DecoratedHolonObject> accessMapHolonObject = visState.get().createdHolonObjects;
-		List<DecoratedHolonObject> holonObjectList = GuiSettings.getSelectedObjects().stream()
-				.filter(object -> object instanceof HolonObject).map(object -> accessMapHolonObject.get(object))
-				.collect(Collectors.toList());
-
-		for (DecoratedHolonObject object : holonObjectList) {
-			switch (object.getState()) {
-			case NO_ENERGY:
-				temp.getPassivList().add((Passiv) object);
-				break;
-			case PRODUCER:
-				temp.getSupplierList().add((Supplier) object);
-				break;
-			default:
-				temp.getConsumerList().add((Consumer) object);
-				break;
-			}
-		}
-		return Optional.of(temp);
+//		FilterableGroupNode temp = new FilterableGroupNode(new GroupNode("Temp"),
+//				control.getModel().getCurrentIteration());
+
+//		Optional<VisualRepresentationalState> visState = control.getSimManager().getActualVisualRepresentationalState();
+//		if(visState.isEmpty()) {
+//			return Optional.empty();
+//		}
+//		
+//		// GroupNodes
+//		HashMap<GroupNode, DecoratedGroupNode> accessMapGroupNode = visState.get().getCreatedGroupNodes();
+//		List<FilterableGroupNode> groupNodeList = GuiSettings.getSelectedObjects().stream()
+//				.filter(object -> object instanceof GroupNode).map(object -> accessMapGroupNode.get(object))
+//				.map(node -> new FilterableGroupNode(node, control.getModel().getCurrentIteration()))
+//				.collect(Collectors.toList());
+//
+//		temp.getGroupNodeList().addAll(groupNodeList);
+//
+//		// HolonObjects
+//		HashMap<HolonObject, DecoratedHolonObject> accessMapHolonObject = visState.get().createdHolonObjects;
+//		List<DecoratedHolonObject> holonObjectList = GuiSettings.getSelectedObjects().stream()
+//				.filter(object -> object instanceof HolonObject).map(object -> accessMapHolonObject.get(object))
+//				.collect(Collectors.toList());
+//
+//		for (DecoratedHolonObject object : holonObjectList) {
+//			switch (object.getState()) {
+//			case NO_ENERGY:
+//				temp.getPassivList().add((Passiv) object);
+//				break;
+//			case PRODUCER:
+//				temp.getSupplierList().add((Supplier) object);
+//				break;
+//			default:
+//				temp.getConsumerList().add((Consumer) object);
+//				break;
+//			}
+//		}
+//		return Optional.of(temp);
+		return Optional.empty();
 	}
 
 

+ 87 - 104
src/holeg/ui/view/window/Outliner.java

@@ -21,22 +21,11 @@ import holeg.model.Edge;
 import holeg.preferences.ColorPreference;
 import holeg.preferences.ImagePreference;
 import holeg.ui.controller.Control;
-import holeg.ui.model.Consumer;
-import holeg.ui.model.DecoratedNetwork;
-import holeg.ui.model.DecoratedState;
-import holeg.ui.model.DecoratedSwitch;
 import holeg.ui.model.MinimumNetwork;
 import holeg.ui.model.Model;
-import holeg.ui.model.Passiv;
-import holeg.ui.model.Supplier;
 import holeg.utility.image.Import;
 import holeg.utility.listener.WindowClosingListener;
 
-
-
-
-
-
 public class Outliner extends JFrame {
 	private static final Logger log = Logger.getLogger(Outliner.class.getName());
 	Control control;
@@ -45,7 +34,8 @@ public class Outliner extends JFrame {
 	JPanel statePanel = new JPanel(new BorderLayout());
 	ArrayList<MinimumNetwork> list;
 	Runnable update = this::update;
-	public Outliner(JFrame parentFrame, Model model, Control control){ 
+
+	public Outliner(JFrame parentFrame, Model model, Control control) {
 		setBounds(0, 0, 400, parentFrame.getHeight());
 		this.setIconImage(Import.loadImage(ImagePreference.Logo, 30, 30));
 		this.setTitle("Outliner");
@@ -55,20 +45,15 @@ public class Outliner extends JFrame {
 		update();
 		this.getContentPane().add(tabbedPane);
 		this.addWindowListener((WindowClosingListener) e -> {
-		  control.OnCanvasUpdate.removeListener(update);
+			control.OnCanvasUpdate.removeListener(update);
 		});
 		control.OnCanvasUpdate.addListener(update);
 		tabbedPane.addTab("List", listPanel);
 		tabbedPane.addTab("State", statePanel);
 	}
-	
-	
-	public void update() {
-		control.getSimManager().getActualDecorState().ifPresent(this::repaintWithDecoratedState);
-	}
 
-	public void repaintWithDecoratedState(DecoratedState decoratedState) {
-		//tabbedPane.removeAll();
+	public void update() {
+		// tabbedPane.removeAll();
 		listPanel.removeAll();
 		statePanel.removeAll();
 		DefaultMutableTreeNode topListPanel = new DefaultMutableTreeNode();
@@ -81,53 +66,51 @@ public class Outliner extends JFrame {
 		topListPanel.add(nodes);
 		topListPanel.add(cables);
 		DefaultMutableTreeNode topStatePanel = new DefaultMutableTreeNode();
-		
-		for(DecoratedSwitch dSwitch: decoratedState.getDecoratedSwitches()) {
-			switches.add(new DefaultMutableTreeNode(dSwitch.getModel().getName()));
-		}
-		
-		/*for(CpsNode node: decoratedState.getNodeList()) {
-			nodes.add(new DefaultMutableTreeNode(node.getName()));
-		}*/
-		
-		for(DecoratedNetwork dNet: decoratedState.getNetworkList()) {
-			DefaultMutableTreeNode network = new DefaultMutableTreeNode("Network");
-			if(!dNet.getConsumerList().isEmpty() || !dNet.getConsumerSelfSuppliedList().isEmpty()) {
-				DefaultMutableTreeNode consumer = new DefaultMutableTreeNode("ConsumerList");
-				for (Consumer con : dNet.getConsumerList()) {
-					DefaultMutableTreeNode consumerNode = new ColoredTreeNode(con.toString(),con.getState().toString(), ColorPreference.HolonObject.getStateColor(con.getState()) );
-					consumer.add(consumerNode);
-					objects.add(new DefaultMutableTreeNode(con.getModel().getName()));
-				}
-				for (Consumer con : dNet.getConsumerSelfSuppliedList()) {
-					DefaultMutableTreeNode consumerNode = new DefaultMutableTreeNode(con.toString() + con.getState());
-					consumer.add(consumerNode);
-					objects.add(new DefaultMutableTreeNode(con.getModel().getName()));
-				}
-				network.add(consumer);
-			}
-			if(!dNet.getSupplierList().isEmpty()) {
-				DefaultMutableTreeNode supplier = new DefaultMutableTreeNode("SupplierList");
-				for (Supplier sup : dNet.getSupplierList()) {
-					supplier.add(new DefaultMutableTreeNode(sup.toString()));
-					objects.add(new DefaultMutableTreeNode(sup.getModel().getName()));
-				}
-				network.add(supplier);
-			}
-			for(Passiv pas: dNet.getPassivNoEnergyList()) {
-				objects.add(new DefaultMutableTreeNode(pas.getModel().getName()));
-			}
-			topStatePanel.add(network);
-			for(Edge cable : dNet.getDecoratedCableList()) {
-				cables.add(new DefaultMutableTreeNode(cable.toString()));
-			}
-		}
-		
-		for(Edge cable : decoratedState.getLeftOverEdges()) {
-			cables.add(new DefaultMutableTreeNode(cable.toString()));
-		}
-		
-		
+
+		Model model = control.getModel();
+		model.getCanvas().getAllSwitchObjectsRecursive().forEach(hS -> {
+			switches.add(new DefaultMutableTreeNode(hS.getName()));
+		});
+
+		//TODO(Tom2022-01-13): Fix Outliner
+//		for (DecoratedNetwork dNet : decoratedState.getNetworkList()) {
+//			DefaultMutableTreeNode network = new DefaultMutableTreeNode("Network");
+//			if (!dNet.getConsumerList().isEmpty() || !dNet.getConsumerSelfSuppliedList().isEmpty()) {
+//				DefaultMutableTreeNode consumer = new DefaultMutableTreeNode("ConsumerList");
+//				for (Consumer con : dNet.getConsumerList()) {
+//					DefaultMutableTreeNode consumerNode = new ColoredTreeNode(con.toString(), con.getState().toString(),
+//							ColorPreference.HolonObject.getStateColor(con.getState()));
+//					consumer.add(consumerNode);
+//					objects.add(new DefaultMutableTreeNode(con.getModel().getName()));
+//				}
+//				for (Consumer con : dNet.getConsumerSelfSuppliedList()) {
+//					DefaultMutableTreeNode consumerNode = new DefaultMutableTreeNode(con.toString() + con.getState());
+//					consumer.add(consumerNode);
+//					objects.add(new DefaultMutableTreeNode(con.getModel().getName()));
+//				}
+//				network.add(consumer);
+//			}
+//			if (!dNet.getSupplierList().isEmpty()) {
+//				DefaultMutableTreeNode supplier = new DefaultMutableTreeNode("SupplierList");
+//				for (Supplier sup : dNet.getSupplierList()) {
+//					supplier.add(new DefaultMutableTreeNode(sup.toString()));
+//					objects.add(new DefaultMutableTreeNode(sup.getModel().getName()));
+//				}
+//				network.add(supplier);
+//			}
+//			for (Passiv pas : dNet.getPassivNoEnergyList()) {
+//				objects.add(new DefaultMutableTreeNode(pas.getModel().getName()));
+//			}
+//			topStatePanel.add(network);
+//			for (Edge cable : dNet.getDecoratedCableList()) {
+//				cables.add(new DefaultMutableTreeNode(cable.toString()));
+//			}
+//		}
+//
+//		for (Edge cable : decoratedState.getLeftOverEdges()) {
+//			cables.add(new DefaultMutableTreeNode(cable.toString()));
+//		}
+
 		JTree listTree = new JTree(topListPanel);
 		signIconsForTree(listTree);
 		listTree.setRootVisible(false);
@@ -136,7 +119,7 @@ public class Outliner extends JFrame {
 		}
 		JScrollPane listScroller = new JScrollPane(listTree);
 		listPanel.add(listScroller);
-		
+
 		JTree stateTree = new JTree(topStatePanel);
 		signIconsForTree(stateTree);
 		stateTree.setRootVisible(false);
@@ -144,31 +127,26 @@ public class Outliner extends JFrame {
 			stateTree.expandRow(i);
 		}
 		statePanel.add(new JScrollPane(stateTree));
-		
-		listPanel.revalidate();;
+
+		listPanel.revalidate();
+		;
 		statePanel.revalidate();
 		listPanel.repaint();
 	}
 
-
-
-
-
-
 	private void signIconsForTree(JTree t) {
-		ImageIcon ClosedIcon = new ImageIcon(Import.loadImage(ImagePreference.Button.Outliner.Closed,9,9));
-		ImageIcon OpenIcon = new ImageIcon(Import.loadImage(ImagePreference.Button.Outliner.Open,9,9));
-		ImageIcon LeafIcon = new ImageIcon(Import.loadImage(ImagePreference.Button.Outliner.Leaf,9,9));
-		if (ClosedIcon != null && OpenIcon != null && LeafIcon!= null) {
-		    DefaultTreeCellRenderer renderer = 
-		        new DefaultTreeCellRenderer();
-		    renderer.setClosedIcon(ClosedIcon);
-		    renderer.setOpenIcon(OpenIcon);
-		    renderer.setLeafIcon(LeafIcon);
-		    t.setCellRenderer(renderer);
+		ImageIcon ClosedIcon = new ImageIcon(Import.loadImage(ImagePreference.Button.Outliner.Closed, 9, 9));
+		ImageIcon OpenIcon = new ImageIcon(Import.loadImage(ImagePreference.Button.Outliner.Open, 9, 9));
+		ImageIcon LeafIcon = new ImageIcon(Import.loadImage(ImagePreference.Button.Outliner.Leaf, 9, 9));
+		if (ClosedIcon != null && OpenIcon != null && LeafIcon != null) {
+			DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
+			renderer.setClosedIcon(ClosedIcon);
+			renderer.setOpenIcon(OpenIcon);
+			renderer.setLeafIcon(LeafIcon);
+			t.setCellRenderer(renderer);
 		}
 	}
-	
+
 	class MyTreeModelListener implements TreeModelListener {
 
 		@Override
@@ -190,41 +168,46 @@ public class Outliner extends JFrame {
 		public void treeStructureChanged(TreeModelEvent tmE) {
 			log.info("treeStructureChanged");
 		}
-	
+
 	}
 
-	
-	
-	class ColoredTreeNode extends DefaultMutableTreeNode{
+	class ColoredTreeNode extends DefaultMutableTreeNode {
 		private Color color;
+
 		public ColoredTreeNode(String string, String state, Color color) {
-			//"<html>Some text <font color='red'>" + "bla" + "some text in red</font></html>"
-			//Integer.toHexString(color.getRGB()).substring(2)
-			//String c = string + "<html><font bgcolor='#132122'>" + state +"</font></html>";
-			super(( "<html>" + string + "<font bgcolor='#" + Integer.toHexString(color.getRGB()).substring(2) + "'>" + state +"</font></html>"));
-			//this.color = color;
+			// "<html>Some text <font color='red'>" + "bla" + "some text in
+			// red</font></html>"
+			// Integer.toHexString(color.getRGB()).substring(2)
+			// String c = string + "<html><font bgcolor='#132122'>" + state
+			// +"</font></html>";
+			super(("<html>" + string + "<font bgcolor='#" + Integer.toHexString(color.getRGB()).substring(2) + "'>"
+					+ state + "</font></html>"));
+			// this.color = color;
 		}
-		public Color getColor(){
+
+		public Color getColor() {
 			return color;
 		}
+
 		public void setColor(Color color) {
 			this.color = color;
 		}
-		
+
 	}
-	
+
 	class AbstractCpsObjectInfo {
 		private AbstractCanvasObject aCps;
-		AbstractCpsObjectInfo(AbstractCanvasObject aCps){
+
+		AbstractCpsObjectInfo(AbstractCanvasObject aCps) {
 			this.aCps = aCps;
 		}
+
 		@Override
-		public String toString(){
-			return aCps.getName() + " Id:"+ aCps.getId();
+		public String toString() {
+			return aCps.getName() + " Id:" + aCps.getId();
 		}
-		
-		public AbstractCanvasObject getAbstractCpsObject()
-		{
+
+		public AbstractCanvasObject getAbstractCpsObject() {
 			return aCps;
 		}
 	}