|
@@ -35,7 +35,11 @@ import classes.HolonElement;
|
|
|
import classes.HolonObject;
|
|
|
import classes.HolonSwitch;
|
|
|
import ui.controller.Control;
|
|
|
+import ui.controller.FlexManager.FlexState;
|
|
|
+import ui.controller.FlexManager.FlexWrapper;
|
|
|
import ui.model.DecoratedGroupNode;
|
|
|
+import ui.model.DecoratedNetwork;
|
|
|
+import ui.model.DecoratedState;
|
|
|
import ui.model.Model;
|
|
|
|
|
|
public class FlexExample implements Algorithm {
|
|
@@ -268,14 +272,35 @@ public class FlexExample implements Algorithm {
|
|
|
private void executeDemoAlgo() {
|
|
|
extractPositionAndAccess();
|
|
|
int actualIteration = control.getModel().getCurIteration();
|
|
|
- print("AlgoStart....");
|
|
|
-
|
|
|
- print("AlgoEnde....");
|
|
|
+ println("AlgoStart....");
|
|
|
+ control.calculateStateAndVisualForCurrentTimeStep();
|
|
|
+ DecoratedState actualstate = control.getSimManager().getActualDecorState();
|
|
|
+ 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);
|
|
|
+ boolean toMuchEnergy = production - consumption > 0;
|
|
|
+ boolean notEnoughEnergy = production - consumption > 0;
|
|
|
+ if(notEnoughEnergy)
|
|
|
+ println("production:" + production + " consumption:" + consumption + " difference:" + difference);
|
|
|
+ List<FlexWrapper> allOfferedFlex = control.getSimManager().getActualFlexManager().getAllFlexWrapperWithState(FlexState.OFFERED);
|
|
|
+ List<FlexWrapper> allFlexThatGetMeEnergy = allOfferedFlex.stream().filter(flexWrapper -> (flexWrapper.getFlex().bringtmir() > 0)).collect(Collectors.toList());
|
|
|
+ float energyICanOrder = allFlexThatGetMeEnergy.stream().map(flexWrapper -> flexWrapper.getFlex().bringtmir()).reduce(0.0f,(a, b) -> a + b);
|
|
|
+ println("canOrder: " + energyICanOrder);
|
|
|
+ List<FlexWrapper> orderedOfferedFlexes = allFlexThatGetMeEnergy.stream().sorted((flex1, flex2) -> Float.compare(flex1.getFlex().bringtmir(), flex2.getFlex().bringtmir())).collect(Collectors.toList());
|
|
|
+ for(FlexWrapper flex : orderedOfferedFlexes){
|
|
|
+ System.out.println(flex.getFlex().name +" " +flex.getFlex().bringtmir());
|
|
|
+ if(flex.getFlex().bringtmir() > difference) break;
|
|
|
+ flex.order();
|
|
|
+ difference -= Math.abs(flex.getFlex().bringtmir());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ println("AlgoEnde....");
|
|
|
updateVisual();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
|
|
|
* Method to get the current Position alias a ListOf Booleans for aktive settings on the Objects on the Canvas.
|
|
|
* Also initialize the Access Hashmap to swap faster positions.
|