|
@@ -4,6 +4,14 @@ import classes.*;
|
|
|
import classes.comparator.EnergyMinToMaxComparator;
|
|
|
import classes.comparator.MinEnergyComparator;
|
|
|
import classes.comparator.WeakestBattery;
|
|
|
+import ui.model.CableWithState;
|
|
|
+import ui.model.DecoratedCable;
|
|
|
+import ui.model.CableWithState.CableState;
|
|
|
+import ui.model.DecoratedNetwork;
|
|
|
+import ui.model.DecoratedState;
|
|
|
+import ui.model.DecoratedSwitch;
|
|
|
+import ui.model.MinimumModel;
|
|
|
+import ui.model.MinimumNetwork;
|
|
|
import ui.model.Model;
|
|
|
import ui.view.FlexiblePane;
|
|
|
import ui.view.MyCanvas;
|
|
@@ -11,6 +19,8 @@ import ui.view.MyCanvas;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
+
|
|
|
+import javax.swing.JPanel;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -25,6 +35,10 @@ public class SimulationManager {
|
|
|
// private ArrayList<CpsEdge> allConnections;
|
|
|
private ArrayList<SubNet> subNets;
|
|
|
private ArrayList<CpsEdge> brokenEdges;
|
|
|
+
|
|
|
+ private ArrayList<DecoratedNetwork> decorNetworks = new ArrayList<DecoratedNetwork>();
|
|
|
+ private DecoratedState decorState;
|
|
|
+ private MinimumModel minimumModel = null;
|
|
|
private MyCanvas canvas;
|
|
|
private int timeStep;
|
|
|
private HashMap<Integer, Float> tagTable = new HashMap<>();
|
|
@@ -60,282 +74,321 @@ public class SimulationManager {
|
|
|
/**
|
|
|
* calculates the flow of the edges and the supply for objects.
|
|
|
*
|
|
|
- * @param x
|
|
|
+ * @param timestep
|
|
|
* current Iteration
|
|
|
*/
|
|
|
- void calculateStateForTimeStep(int x) {
|
|
|
- reset();
|
|
|
- timeStep = x;
|
|
|
- searchForSubNets();
|
|
|
- for (SubNet singleSubNet : subNets) {
|
|
|
- if(singleSubNet.getObjects().size() == 0)
|
|
|
- {
|
|
|
- resetConnections(singleSubNet.getBatteries().get(0),
|
|
|
- new ArrayList<>(), new ArrayList<>());
|
|
|
- }else
|
|
|
- {
|
|
|
- resetConnections(singleSubNet.getObjects().get(0),
|
|
|
- new ArrayList<>(), new ArrayList<>());
|
|
|
- }
|
|
|
-
|
|
|
+ void calculateStateForTimeStep(int timestep) {
|
|
|
+ System.out.println("Calculate Timestep: " + timestep);
|
|
|
+ timeStep = timestep;
|
|
|
+ decorNetworks.clear();
|
|
|
+ ArrayList<MinimumNetwork> list = new ArrayList<MinimumNetwork>();
|
|
|
+ minimumModel = new MinimumModel(model.getObjectsOnCanvas(), model.getEdgesOnCanvas());
|
|
|
+ //set all working:
|
|
|
+ for(CableWithState cable : minimumModel.getEdgeList()) {
|
|
|
+ cable.setState(CableState.Working);
|
|
|
}
|
|
|
- for (SubNet singleSubNet : subNets) {
|
|
|
- float production = calculateEnergyWithoutFlexDevices("prod",
|
|
|
- singleSubNet, timeStep);
|
|
|
- float consumption = calculateEnergyWithoutFlexDevices("cons",
|
|
|
- singleSubNet, timeStep);
|
|
|
- // surplus of energy is computed by sum, since consumption is a
|
|
|
- // negative value
|
|
|
- float energySurplus = production + consumption;
|
|
|
-
|
|
|
-
|
|
|
- //float minConsumption = calculateMinimumEnergy(singleSubNet, timeStep);
|
|
|
-
|
|
|
- // --------------- use flexible devices ---------------
|
|
|
- if (energySurplus != 0 && model.useFlexibleDevices()) {
|
|
|
- turnOnFlexibleDevices(singleSubNet, energySurplus, x);
|
|
|
-
|
|
|
- // if (!flexDevicesTurnedOnThisTurn.isEmpty()) {
|
|
|
- // System.out.println("The following devices were turned on in this turn: ");
|
|
|
- // System.out.println(flexDevicesTurnedOnThisTurn.toString());
|
|
|
- // }
|
|
|
-
|
|
|
- // recompute after having examined/turned on all flexible
|
|
|
- // devices
|
|
|
- production = calculateEnergyWithFlexDevices("prod",
|
|
|
- singleSubNet, timeStep);
|
|
|
- consumption = calculateEnergyWithFlexDevices("cons",
|
|
|
- singleSubNet, timeStep);
|
|
|
- energySurplus = production + consumption;
|
|
|
- }
|
|
|
-
|
|
|
- // --------------- set flow simulation ---------------
|
|
|
- setFlowSimulation(singleSubNet);
|
|
|
-
|
|
|
- // --------------- visualise graph ---------------
|
|
|
-
|
|
|
- /**
|
|
|
- * production of subnets, that might be partially turned on/off
|
|
|
- */
|
|
|
- float currentProduction = production;
|
|
|
- /**
|
|
|
- * HolonObjects that can be partially Supplied but might be fully
|
|
|
- * Supplied
|
|
|
- */
|
|
|
- /*
|
|
|
- ArrayList<HolonObject> partiallySuppliedList = new ArrayList<HolonObject>();
|
|
|
- /**
|
|
|
- * HolonObjects that can get the spare energy
|
|
|
- */
|
|
|
-//
|
|
|
-// ArrayList<HolonObject> notSuppliedList = new ArrayList<HolonObject>();
|
|
|
- /**
|
|
|
- * Number of HolonObjects that need to be supplied
|
|
|
- */
|
|
|
-// long numberOfConsumers = singleSubNet.getObjects().stream()
|
|
|
-// .filter(hl -> (hl.getState() != HolonObject.NO_ENERGY
|
|
|
-// && hl.getState() != HolonObject.PRODUCER && hl
|
|
|
-// .getConnectedTo().stream()
|
|
|
-// .filter(e -> (e.getFlow() > 0)).count() > 0))
|
|
|
-// .count();
|
|
|
- /**
|
|
|
- * energy each HolonObject receives in AlleEqualModus
|
|
|
- */
|
|
|
-
|
|
|
- if(energySurplus >= 0)
|
|
|
- {
|
|
|
- //Supply all consumer
|
|
|
- for(HolonObject hO : singleSubNet.getObjects())
|
|
|
- {
|
|
|
- float neededEnergy = hO.getCurrentEnergyAtTimeStep(x);
|
|
|
- if(neededEnergy < 0)
|
|
|
- {
|
|
|
- hO.setCurrentSupply(-neededEnergy);
|
|
|
- currentProduction -= -neededEnergy; //Subtract the Energy from the Production
|
|
|
- }
|
|
|
- }
|
|
|
- //Supply all Batterys with the left currentProduction
|
|
|
- singleSubNet.getBatteries().sort(new WeakestBattery(x));//Sort all batteries by the Value of ther StateOfCharge/Capasity
|
|
|
- for(HolonBattery hB : singleSubNet.getBatteries())
|
|
|
- {
|
|
|
- float energyToCollect = hB.getInAtTimeStep(x-1);
|
|
|
- if(currentProduction >= energyToCollect)
|
|
|
- {
|
|
|
- //change StateofCharge soc = soc + energyToCollect
|
|
|
- hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) + energyToCollect, x);
|
|
|
- currentProduction -= energyToCollect;
|
|
|
- }else
|
|
|
- {
|
|
|
- //change StateofCharge soc = soc + currentProduction
|
|
|
- hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) + currentProduction, x);
|
|
|
- currentProduction = 0;
|
|
|
- //no break must be calculatet for all break; //because no more energy
|
|
|
- }
|
|
|
- }
|
|
|
- //Over_Supply all consumer equal
|
|
|
- long nOConsumer = singleSubNet.getObjects().stream().filter(hl -> (hl.getCurrentEnergyAtTimeStep(x) < 0)).count();
|
|
|
- if(nOConsumer != 0)
|
|
|
- {
|
|
|
- //energy to seperated equal
|
|
|
- float EnergyOverSupplyPerHolonObject = currentProduction / nOConsumer;
|
|
|
- for(HolonObject hO : singleSubNet.getObjects())
|
|
|
- {
|
|
|
- float neededEnergy = hO.getCurrentEnergyAtTimeStep(x);
|
|
|
- if(neededEnergy < 0)
|
|
|
- {
|
|
|
- hO.setCurrentSupply(hO.getCurrentSupply() + EnergyOverSupplyPerHolonObject);
|
|
|
- }
|
|
|
- }
|
|
|
- currentProduction = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //Check all Battries what they can provide
|
|
|
- if(energySurplus + GetOutAllBatteries(singleSubNet.getBatteries(), x) >= 0)
|
|
|
- {
|
|
|
- singleSubNet.getBatteries().sort(new WeakestBattery(x));//.reverse();
|
|
|
- Collections.reverse(singleSubNet.getBatteries()); //most supplyed first
|
|
|
- //Get the NEEDED energy
|
|
|
- for(HolonBattery hB : singleSubNet.getBatteries())
|
|
|
- {
|
|
|
- float neededEnergyFromBattery = currentProduction + consumption; //Energy is negativ
|
|
|
- float maxEnergyAvailable = hB.getOutAtTimeStep(x-1); //energy is positiv
|
|
|
- if(maxEnergyAvailable >= -neededEnergyFromBattery)
|
|
|
- {
|
|
|
- //change StateofCharge soc = soc - -neededEnergyFromBattery
|
|
|
- hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) - -neededEnergyFromBattery, x);
|
|
|
- currentProduction += -neededEnergyFromBattery;
|
|
|
- //no break must be calculatet for all beabreak; //When a energy can supply the last needed energy break;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //change StateofCharge soc = soc - maxEnergyAvailable
|
|
|
- hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) - maxEnergyAvailable, x);
|
|
|
- currentProduction += maxEnergyAvailable;
|
|
|
- }
|
|
|
- }
|
|
|
- //Supply all consumer all ar in state Supplied no one is oversupplied because
|
|
|
- // just the energy that is needed is gained from the batteries
|
|
|
- for(HolonObject hO : singleSubNet.getObjects())
|
|
|
- {
|
|
|
- float neededEnergy = hO.getCurrentEnergyAtTimeStep(x);
|
|
|
- if(neededEnergy < 0)
|
|
|
- {
|
|
|
- hO.setCurrentSupply(-neededEnergy);
|
|
|
- currentProduction -= -neededEnergy; //Subtract the Energy from the Production
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else //Objects have to be partially supplied
|
|
|
- {
|
|
|
- //Get all Energy out of battries as possible
|
|
|
- for(HolonBattery hB : singleSubNet.getBatteries())
|
|
|
- {
|
|
|
- float maxEnergyAvailable = hB.getOutAtTimeStep(x-1); //energy is positiv
|
|
|
- //change StateofCharge soc = soc - maxEnergyAvailable
|
|
|
- hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) - maxEnergyAvailable, x);
|
|
|
- currentProduction += maxEnergyAvailable;
|
|
|
- }
|
|
|
- //Calc
|
|
|
- singleSubNet.getObjects().stream().forEach(hl -> hl.setCurrentSupply(0));
|
|
|
- if(model.getFairnessModel() == fairnessAllEqual)
|
|
|
- {
|
|
|
- long nOConsumer = singleSubNet.getObjects().stream().filter(hl -> (hl.getCurrentEnergyAtTimeStep(x) < 0)).count();
|
|
|
- float energyPerHolonObject = 0;
|
|
|
- if (nOConsumer != 0)
|
|
|
- energyPerHolonObject = currentProduction / nOConsumer;
|
|
|
- for(HolonObject hO : singleSubNet.getObjects())
|
|
|
- {
|
|
|
- if(hO.getCurrentEnergyAtTimeStep(x) < 0) //Just Consumer need Energy
|
|
|
- {
|
|
|
- hO.setCurrentSupply(energyPerHolonObject);
|
|
|
- currentProduction -= energyPerHolonObject; //Subtract the Energy from the Production
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else //(model.getFairnessModel() == fairnessMininumDemandFirst)
|
|
|
- {
|
|
|
- singleSubNet.getObjects().sort(new MinEnergyComparator(x));
|
|
|
- //SupplyAllMinimumEnergy
|
|
|
- for(HolonObject hO : singleSubNet.getObjects())
|
|
|
- {
|
|
|
- if(hO.checkIfPartiallySupplied(x))continue;
|
|
|
- if(hO.getCurrentEnergyAtTimeStep(x) > 0)continue;
|
|
|
- float minEnergy = -hO.getMinEnergy(x); //Energy from getMinEnergy is negative -> convert to positive
|
|
|
- if(minEnergy <= currentProduction)
|
|
|
- {
|
|
|
- hO.setCurrentSupply(minEnergy);
|
|
|
- currentProduction -= minEnergy;
|
|
|
- }else
|
|
|
- {
|
|
|
- hO.setCurrentSupply(currentProduction);
|
|
|
- currentProduction = 0;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- singleSubNet.getObjects().sort(new EnergyMinToMaxComparator(x));
|
|
|
- //supplyFullytillEnd ... because its cant be fully supplied
|
|
|
- for(HolonObject hO : singleSubNet.getObjects())
|
|
|
- {
|
|
|
-
|
|
|
- float actualSupplyEnergy = hO.getCurrentSupply();
|
|
|
- float neededEnergy = -hO.getCurrentEnergyAtTimeStep(x) - actualSupplyEnergy;
|
|
|
- if(neededEnergy <= 0)continue; //Producer or No EnergyNeeded
|
|
|
- if(neededEnergy <= currentProduction)
|
|
|
- {
|
|
|
- hO.setCurrentSupply(neededEnergy+actualSupplyEnergy);
|
|
|
- currentProduction -= neededEnergy;
|
|
|
- }else
|
|
|
- {
|
|
|
- hO.setCurrentSupply(currentProduction+actualSupplyEnergy);
|
|
|
- currentProduction = 0;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- //Visualize the Color
|
|
|
- for(HolonObject hO : singleSubNet.getObjects())
|
|
|
- {
|
|
|
- float neededEnergy = -hO.getCurrentEnergyAtTimeStep(x); // convert negative energy in positive for calculations
|
|
|
- if(neededEnergy < 0)
|
|
|
- {
|
|
|
- hO.setState(HolonObject.PRODUCER);
|
|
|
- }
|
|
|
- else if(neededEnergy > 0)
|
|
|
- {
|
|
|
- float currentSupply = hO.getCurrentSupply() ;
|
|
|
- if(currentSupply > neededEnergy)
|
|
|
- {
|
|
|
- hO.setState(HolonObject.OVER_SUPPLIED);
|
|
|
- }else if (currentSupply == neededEnergy)
|
|
|
- {
|
|
|
- hO.setState(HolonObject.SUPPLIED);
|
|
|
- }else if (currentSupply < neededEnergy)
|
|
|
- {
|
|
|
- float minEnergy = -hO.getMinEnergy(x);
|
|
|
- if(currentSupply >= minEnergy || hO.getSelfMadeEnergy(x) >= minEnergy )
|
|
|
- {
|
|
|
- hO.setState(HolonObject.PARTIALLY_SUPPLIED);
|
|
|
- }else
|
|
|
- {
|
|
|
- hO.setState(HolonObject.NOT_SUPPLIED);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else if(neededEnergy == 0)
|
|
|
- {
|
|
|
- hO.setState(HolonObject.NO_ENERGY);
|
|
|
+ ArrayList<CableWithState> leftOver = new ArrayList<CableWithState>();
|
|
|
+ boolean doAnotherLoop = true;
|
|
|
+ while(doAnotherLoop) {
|
|
|
+ doAnotherLoop = false;
|
|
|
+ list = CalculataModel.calculateNetworks(minimumModel, timestep, leftOver);
|
|
|
+ for(MinimumNetwork net : list) {
|
|
|
+ float energyOnCables = net.getHolonObjectList().stream().filter(object -> object.getEnergyAtTimeStep(timestep) > 0.0f).map(object -> object.getEnergyAtTimeStep(timestep)).reduce(0.0f, ((a,b) -> a + b));
|
|
|
+ //find the cable with the energy supplied from his two connected objects are the biggest, from all cables that the network give more energy than the cablecapacity.
|
|
|
+ CableWithState cable = net.getEdgeList().stream().filter(aCable -> energyOnCables > aCable.getModel().getCapacity()).max((lhs,rhs) -> Float.compare(lhs.getEnergyFromConnetedAtTimestep(timestep), rhs.getEnergyFromConnetedAtTimestep(timestep))).orElse(null);
|
|
|
+ if(cable != null) {
|
|
|
+ cable.setState(CableState.Burned);
|
|
|
+ doAnotherLoop = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ for (MinimumNetwork net : list) {
|
|
|
+ decorNetworks.add(new DecoratedNetwork(net, timestep));
|
|
|
+ }
|
|
|
+ ArrayList<DecoratedCable> leftOverDecoratedCables = new ArrayList<DecoratedCable>();
|
|
|
+
|
|
|
+ for(CableWithState cable: leftOver) {
|
|
|
+ leftOverDecoratedCables.add(new DecoratedCable(cable.getModel(), CableWithState.convertCableStateToDecoratedCableState(cable.getState()), 0.0f));
|
|
|
+ }
|
|
|
+ ArrayList<DecoratedSwitch> listOfDecoratedSwitches = CalculataModel.decorateSwitches(minimumModel, timestep);
|
|
|
+ decorState = new DecoratedState(decorNetworks, leftOverDecoratedCables, listOfDecoratedSwitches);
|
|
|
canvas.repaint();
|
|
|
- flexPane.recalculate();
|
|
|
+// for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {
|
|
|
+// System.out.println(ste);
|
|
|
+//// }
|
|
|
+// reset();
|
|
|
+// timeStep = x;
|
|
|
+// searchForSubNets();
|
|
|
+// for (SubNet singleSubNet : subNets) {
|
|
|
+// if(singleSubNet.getObjects().size() == 0)
|
|
|
+// {
|
|
|
+// resetConnections(singleSubNet.getBatteries().get(0),
|
|
|
+// new ArrayList<>(), new ArrayList<>());
|
|
|
+// }else
|
|
|
+// {
|
|
|
+// resetConnections(singleSubNet.getObjects().get(0),
|
|
|
+// new ArrayList<>(), new ArrayList<>());
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+// for (SubNet singleSubNet : subNets) {
|
|
|
+// float production = calculateEnergyWithoutFlexDevices("prod",
|
|
|
+// singleSubNet, timeStep);
|
|
|
+// float consumption = calculateEnergyWithoutFlexDevices("cons",
|
|
|
+// singleSubNet, timeStep);
|
|
|
+// // surplus of energy is computed by sum, since consumption is a
|
|
|
+// // negative value
|
|
|
+// float energySurplus = production + consumption;
|
|
|
+//
|
|
|
+//
|
|
|
+// //float minConsumption = calculateMinimumEnergy(singleSubNet, timeStep);
|
|
|
+//
|
|
|
+// // --------------- use flexible devices ---------------
|
|
|
+// if (energySurplus != 0 && model.useFlexibleDevices()) {
|
|
|
+// turnOnFlexibleDevices(singleSubNet, energySurplus, x);
|
|
|
+//
|
|
|
+// // if (!flexDevicesTurnedOnThisTurn.isEmpty()) {
|
|
|
+// // System.out.println("The following devices were turned on in this turn: ");
|
|
|
+// // System.out.println(flexDevicesTurnedOnThisTurn.toString());
|
|
|
+// // }
|
|
|
+//
|
|
|
+// // recompute after having examined/turned on all flexible
|
|
|
+// // devices
|
|
|
+// production = calculateEnergyWithFlexDevices("prod",
|
|
|
+// singleSubNet, timeStep);
|
|
|
+// consumption = calculateEnergyWithFlexDevices("cons",
|
|
|
+// singleSubNet, timeStep);
|
|
|
+// energySurplus = production + consumption;
|
|
|
+// }
|
|
|
+//
|
|
|
+// // --------------- set flow simulation ---------------
|
|
|
+// setFlowSimulation(singleSubNet);
|
|
|
+//
|
|
|
+// // --------------- visualise graph ---------------
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * production of subnets, that might be partially turned on/off
|
|
|
+// */
|
|
|
+// float currentProduction = production;
|
|
|
+// /**
|
|
|
+// * HolonObjects that can be partially Supplied but might be fully
|
|
|
+// * Supplied
|
|
|
+// */
|
|
|
+// /*
|
|
|
+// ArrayList<HolonObject> partiallySuppliedList = new ArrayList<HolonObject>();
|
|
|
+// /**
|
|
|
+// * HolonObjects that can get the spare energy
|
|
|
+// */
|
|
|
+////
|
|
|
+//// ArrayList<HolonObject> notSuppliedList = new ArrayList<HolonObject>();
|
|
|
+// /**
|
|
|
+// * Number of HolonObjects that need to be supplied
|
|
|
+// */
|
|
|
+//// long numberOfConsumers = singleSubNet.getObjects().stream()
|
|
|
+//// .filter(hl -> (hl.getState() != HolonObject.NO_ENERGY
|
|
|
+//// && hl.getState() != HolonObject.PRODUCER && hl
|
|
|
+//// .getConnectedTo().stream()
|
|
|
+//// .filter(e -> (e.getFlow() > 0)).count() > 0))
|
|
|
+//// .count();
|
|
|
+// /**
|
|
|
+// * energy each HolonObject receives in AlleEqualModus
|
|
|
+// */
|
|
|
+//
|
|
|
+// if(energySurplus >= 0)
|
|
|
+// {
|
|
|
+// //Supply all consumer
|
|
|
+// for(HolonObject hO : singleSubNet.getObjects())
|
|
|
+// {
|
|
|
+// float neededEnergy = hO.getCurrentEnergyAtTimeStep(x);
|
|
|
+// if(neededEnergy < 0)
|
|
|
+// {
|
|
|
+// hO.setCurrentSupply(-neededEnergy);
|
|
|
+// currentProduction -= -neededEnergy; //Subtract the Energy from the Production
|
|
|
+// }
|
|
|
+// }
|
|
|
+// //Supply all Batterys with the left currentProduction
|
|
|
+// singleSubNet.getBatteries().sort(new WeakestBattery(x));//Sort all batteries by the Value of ther StateOfCharge/Capasity
|
|
|
+// for(HolonBattery hB : singleSubNet.getBatteries())
|
|
|
+// {
|
|
|
+// float energyToCollect = hB.getInAtTimeStep(x-1);
|
|
|
+// if(currentProduction >= energyToCollect)
|
|
|
+// {
|
|
|
+// //change StateofCharge soc = soc + energyToCollect
|
|
|
+// hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) + energyToCollect, x);
|
|
|
+// currentProduction -= energyToCollect;
|
|
|
+// }else
|
|
|
+// {
|
|
|
+// //change StateofCharge soc = soc + currentProduction
|
|
|
+// hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) + currentProduction, x);
|
|
|
+// currentProduction = 0;
|
|
|
+// //no break must be calculatet for all break; //because no more energy
|
|
|
+// }
|
|
|
+// }
|
|
|
+// //Over_Supply all consumer equal
|
|
|
+// long nOConsumer = singleSubNet.getObjects().stream().filter(hl -> (hl.getCurrentEnergyAtTimeStep(x) < 0)).count();
|
|
|
+// if(nOConsumer != 0)
|
|
|
+// {
|
|
|
+// //energy to seperated equal
|
|
|
+// float EnergyOverSupplyPerHolonObject = currentProduction / nOConsumer;
|
|
|
+// for(HolonObject hO : singleSubNet.getObjects())
|
|
|
+// {
|
|
|
+// float neededEnergy = hO.getCurrentEnergyAtTimeStep(x);
|
|
|
+// if(neededEnergy < 0)
|
|
|
+// {
|
|
|
+// hO.setCurrentSupply(hO.getCurrentSupply() + EnergyOverSupplyPerHolonObject);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// currentProduction = 0;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// //Check all Battries what they can provide
|
|
|
+// if(energySurplus + GetOutAllBatteries(singleSubNet.getBatteries(), x) >= 0)
|
|
|
+// {
|
|
|
+// singleSubNet.getBatteries().sort(new WeakestBattery(x));//.reverse();
|
|
|
+// Collections.reverse(singleSubNet.getBatteries()); //most supplyed first
|
|
|
+// //Get the NEEDED energy
|
|
|
+// for(HolonBattery hB : singleSubNet.getBatteries())
|
|
|
+// {
|
|
|
+// float neededEnergyFromBattery = currentProduction + consumption; //Energy is negativ
|
|
|
+// float maxEnergyAvailable = hB.getOutAtTimeStep(x-1); //energy is positiv
|
|
|
+// if(maxEnergyAvailable >= -neededEnergyFromBattery)
|
|
|
+// {
|
|
|
+// //change StateofCharge soc = soc - -neededEnergyFromBattery
|
|
|
+// hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) - -neededEnergyFromBattery, x);
|
|
|
+// currentProduction += -neededEnergyFromBattery;
|
|
|
+// //no break must be calculatet for all beabreak; //When a energy can supply the last needed energy break;
|
|
|
+// }
|
|
|
+// else
|
|
|
+// {
|
|
|
+// //change StateofCharge soc = soc - maxEnergyAvailable
|
|
|
+// hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) - maxEnergyAvailable, x);
|
|
|
+// currentProduction += maxEnergyAvailable;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// //Supply all consumer all ar in state Supplied no one is oversupplied because
|
|
|
+// // just the energy that is needed is gained from the batteries
|
|
|
+// for(HolonObject hO : singleSubNet.getObjects())
|
|
|
+// {
|
|
|
+// float neededEnergy = hO.getCurrentEnergyAtTimeStep(x);
|
|
|
+// if(neededEnergy < 0)
|
|
|
+// {
|
|
|
+// hO.setCurrentSupply(-neededEnergy);
|
|
|
+// currentProduction -= -neededEnergy; //Subtract the Energy from the Production
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// else //Objects have to be partially supplied
|
|
|
+// {
|
|
|
+// //Get all Energy out of battries as possible
|
|
|
+// for(HolonBattery hB : singleSubNet.getBatteries())
|
|
|
+// {
|
|
|
+// float maxEnergyAvailable = hB.getOutAtTimeStep(x-1); //energy is positiv
|
|
|
+// //change StateofCharge soc = soc - maxEnergyAvailable
|
|
|
+// hB.setStateOfChargeAtTimeStep(hB.getStateOfChargeAtTimeStep(x-1) - maxEnergyAvailable, x);
|
|
|
+// currentProduction += maxEnergyAvailable;
|
|
|
+// }
|
|
|
+// //Calc
|
|
|
+// singleSubNet.getObjects().stream().forEach(hl -> hl.setCurrentSupply(0));
|
|
|
+// if(model.getFairnessModel() == fairnessAllEqual)
|
|
|
+// {
|
|
|
+// long nOConsumer = singleSubNet.getObjects().stream().filter(hl -> (hl.getCurrentEnergyAtTimeStep(x) < 0)).count();
|
|
|
+// float energyPerHolonObject = 0;
|
|
|
+// if (nOConsumer != 0)
|
|
|
+// energyPerHolonObject = currentProduction / nOConsumer;
|
|
|
+// for(HolonObject hO : singleSubNet.getObjects())
|
|
|
+// {
|
|
|
+// if(hO.getCurrentEnergyAtTimeStep(x) < 0) //Just Consumer need Energy
|
|
|
+// {
|
|
|
+// hO.setCurrentSupply(energyPerHolonObject);
|
|
|
+// currentProduction -= energyPerHolonObject; //Subtract the Energy from the Production
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// else //(model.getFairnessModel() == fairnessMininumDemandFirst)
|
|
|
+// {
|
|
|
+// singleSubNet.getObjects().sort(new MinEnergyComparator(x));
|
|
|
+// //SupplyAllMinimumEnergy
|
|
|
+// for(HolonObject hO : singleSubNet.getObjects())
|
|
|
+// {
|
|
|
+// if(hO.checkIfPartiallySupplied(x))continue;
|
|
|
+// if(hO.getCurrentEnergyAtTimeStep(x) > 0)continue;
|
|
|
+// float minEnergy = -hO.getMinEnergy(x); //Energy from getMinEnergy is negative -> convert to positive
|
|
|
+// if(minEnergy <= currentProduction)
|
|
|
+// {
|
|
|
+// hO.setCurrentSupply(minEnergy);
|
|
|
+// currentProduction -= minEnergy;
|
|
|
+// }else
|
|
|
+// {
|
|
|
+// hO.setCurrentSupply(currentProduction);
|
|
|
+// currentProduction = 0;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// singleSubNet.getObjects().sort(new EnergyMinToMaxComparator(x));
|
|
|
+// //supplyFullytillEnd ... because its cant be fully supplied
|
|
|
+// for(HolonObject hO : singleSubNet.getObjects())
|
|
|
+// {
|
|
|
+//
|
|
|
+// float actualSupplyEnergy = hO.getCurrentSupply();
|
|
|
+// float neededEnergy = -hO.getCurrentEnergyAtTimeStep(x) - actualSupplyEnergy;
|
|
|
+// if(neededEnergy <= 0)continue; //Producer or No EnergyNeeded
|
|
|
+// if(neededEnergy <= currentProduction)
|
|
|
+// {
|
|
|
+// hO.setCurrentSupply(neededEnergy+actualSupplyEnergy);
|
|
|
+// currentProduction -= neededEnergy;
|
|
|
+// }else
|
|
|
+// {
|
|
|
+// hO.setCurrentSupply(currentProduction+actualSupplyEnergy);
|
|
|
+// currentProduction = 0;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+// //Visualize the Color
|
|
|
+// for(HolonObject hO : singleSubNet.getObjects())
|
|
|
+// {
|
|
|
+// float neededEnergy = -hO.getCurrentEnergyAtTimeStep(x); // convert negative energy in positive for calculations
|
|
|
+// if(neededEnergy < 0)
|
|
|
+// {
|
|
|
+// hO.setState(HolonObject.PRODUCER);
|
|
|
+// }
|
|
|
+// else if(neededEnergy > 0)
|
|
|
+// {
|
|
|
+// float currentSupply = hO.getCurrentSupply() ;
|
|
|
+// if(currentSupply > neededEnergy)
|
|
|
+// {
|
|
|
+// hO.setState(HolonObject.OVER_SUPPLIED);
|
|
|
+// }else if (currentSupply == neededEnergy)
|
|
|
+// {
|
|
|
+// hO.setState(HolonObject.SUPPLIED);
|
|
|
+// }else if (currentSupply < neededEnergy)
|
|
|
+// {
|
|
|
+// float minEnergy = -hO.getMinEnergy(x);
|
|
|
+// if(currentSupply >= minEnergy || hO.getSelfMadeEnergy(x) >= minEnergy )
|
|
|
+// {
|
|
|
+// hO.setState(HolonObject.PARTIALLY_SUPPLIED);
|
|
|
+// }else
|
|
|
+// {
|
|
|
+// hO.setState(HolonObject.NOT_SUPPLIED);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// else if(neededEnergy == 0)
|
|
|
+// {
|
|
|
+// hO.setState(HolonObject.NO_ENERGY);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// canvas.repaint();
|
|
|
+// flexPane.recalculate();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -975,4 +1028,17 @@ public class SimulationManager {
|
|
|
flexPane = fp;
|
|
|
}
|
|
|
|
|
|
+ public ArrayList<DecoratedNetwork> getDecorNetworks() {
|
|
|
+ return decorNetworks;
|
|
|
+ }
|
|
|
+
|
|
|
+ public MinimumModel getMinimumModel() {
|
|
|
+ return minimumModel;
|
|
|
+ }
|
|
|
+
|
|
|
+ public DecoratedState getDecorState() {
|
|
|
+ return decorState;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|