|
@@ -38,17 +38,10 @@ import javax.swing.JPanel;
|
|
|
public class SimulationManager {
|
|
|
int global = 0;
|
|
|
private Model model;
|
|
|
- private ArrayList<AbstractCpsObject> objectsToHandle;
|
|
|
- private ArrayList<SubNet> subNets;
|
|
|
- private ArrayList<CpsEdge> brokenEdges;
|
|
|
private HashMap<Integer, DecoratedState> saves = new HashMap<Integer, DecoratedState>();
|
|
|
private HashMap<Integer, VisualRepresentationalState> savesVisual = new HashMap<Integer, VisualRepresentationalState>();
|
|
|
- private MyCanvas canvas;
|
|
|
private int timeStep;
|
|
|
- private HashMap<Integer, Float> tagTable = new HashMap<>();
|
|
|
private FlexiblePane flexPane;
|
|
|
- private GUI gui;
|
|
|
- private HashMap<HolonElement, Float> flexDevicesTurnedOnThisTurn = new HashMap<>();
|
|
|
|
|
|
/**
|
|
|
* Constructor.
|
|
@@ -57,12 +50,8 @@ public class SimulationManager {
|
|
|
* Model
|
|
|
*/
|
|
|
SimulationManager(Model m) {
|
|
|
- canvas = null;
|
|
|
model = m;
|
|
|
- subNets = new ArrayList<>();
|
|
|
- brokenEdges = new ArrayList<>();
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
* calculates the flow of the edges and the supply for objects and consider old timesteps for burned cables.
|
|
|
*
|
|
@@ -118,9 +107,6 @@ public class SimulationManager {
|
|
|
DecoratedState stateFromThisTimestep = new DecoratedState(decorNetworks, leftOverDecoratedCables, listOfDecoratedSwitches, timestep);
|
|
|
saves.put(timestep, stateFromThisTimestep);
|
|
|
savesVisual.put(timestep, new VisualRepresentationalState(stateFromThisTimestep, minimumModel));
|
|
|
- canvas.repaint();
|
|
|
- gui.updateOutliners(getActualDecorState());//saves.getOrDefault(timestep, null);
|
|
|
-
|
|
|
}
|
|
|
/**
|
|
|
* Decorate a switch
|
|
@@ -220,196 +206,6 @@ public class SimulationManager {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- /**
|
|
|
- * add all battries.getOut() from a list of battries and return them
|
|
|
- * @param aL a List of HolonBattries likely from subnet.getBatteries()
|
|
|
- * @param x TimeStep
|
|
|
- * @return
|
|
|
- *
|
|
|
- */
|
|
|
- private float GetOutAllBatteries(ArrayList<HolonBattery> aL, int x)
|
|
|
- {
|
|
|
- float OutEnergy = 0;
|
|
|
- for(HolonBattery hB : aL)
|
|
|
- {
|
|
|
- //System.out.println("Iteration: "+ x +"OutBattery: "+ hB.getOutAtTimeStep(x-1));
|
|
|
- OutEnergy += hB.getOutAtTimeStep(x-1);
|
|
|
- }
|
|
|
- //System.out.println("Iteration: "+ x +"GetOutAllBatteries: "+ OutEnergy);
|
|
|
- return OutEnergy;
|
|
|
- }
|
|
|
- /**
|
|
|
- * search for all flexible devices in the network and turn them on, until
|
|
|
- * energy surplus = 0 or all devices have been examined.
|
|
|
- *
|
|
|
- * This code could be compressed (cases inside over- and underproduction are
|
|
|
- * the same), but we decided that it is better readable this way
|
|
|
- *
|
|
|
- * @param subNet
|
|
|
- * the subnet
|
|
|
- * @param energySurplus
|
|
|
- * the current surplus of energy
|
|
|
- */
|
|
|
- private void turnOnFlexibleDevices(SubNet subNet, float energySurplus,
|
|
|
- int timestep) {
|
|
|
- for (HolonObject holonOb : subNet.getObjects()) {
|
|
|
- for (HolonElement holonEl : holonOb.getElements()) {
|
|
|
-
|
|
|
- // if this element is flexible and active (can be considered for
|
|
|
- // calculations)
|
|
|
- if (holonEl.isFlexible() && holonEl.isActive()) {
|
|
|
- float energyAvailableSingle = holonEl
|
|
|
- .getEnergyAtTimeStep(timestep);
|
|
|
- float energyAvailableMultiple = energyAvailableSingle
|
|
|
- * holonEl.getAmount();
|
|
|
-
|
|
|
- // ------------- flexible consumer / OVERPRODUCTION
|
|
|
- // -------------
|
|
|
- if (energyAvailableMultiple < 0 && energySurplus > 0) {
|
|
|
-
|
|
|
- // if there is more wasted energy than energy that this
|
|
|
- // device can give, give all energy available
|
|
|
- if (Math.abs(energyAvailableMultiple) <= Math
|
|
|
- .abs(energySurplus)) {
|
|
|
- energySurplus += energyAvailableMultiple;
|
|
|
- // set the new energy consumption to the maximum
|
|
|
- holonEl.setEnergyPerElement(energyAvailableSingle);
|
|
|
- flexDevicesTurnedOnThisTurn.put(holonEl,
|
|
|
- energyAvailableMultiple);
|
|
|
- }
|
|
|
- // else: we just need to turn on part of the flexible
|
|
|
- // energy available
|
|
|
- else {
|
|
|
- float energyNeeded = -energySurplus;
|
|
|
- energySurplus += energyNeeded; // should give 0, but
|
|
|
- // was kept this was
|
|
|
- // for consistency
|
|
|
- // the energy needed divided through the amount of
|
|
|
- // elements
|
|
|
- holonEl.setEnergyPerElement(energyNeeded
|
|
|
- / holonEl.getAmount());
|
|
|
- flexDevicesTurnedOnThisTurn.put(holonEl,
|
|
|
- energyNeeded);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // ------------- flexible producer / UNDERPRODUCTION
|
|
|
- // -------------
|
|
|
- else if (energyAvailableMultiple > 0 && energySurplus < 0) {
|
|
|
-
|
|
|
- // if there is more energy needed than this device can
|
|
|
- // give, give all the energy available
|
|
|
- if (Math.abs(energyAvailableMultiple) <= Math
|
|
|
- .abs(energySurplus)) {
|
|
|
- energySurplus += energyAvailableMultiple;
|
|
|
- // set the new energy consumption to the maximum
|
|
|
- holonEl.setEnergyPerElement(energyAvailableSingle);
|
|
|
- flexDevicesTurnedOnThisTurn.put(holonEl,
|
|
|
- energyAvailableMultiple);
|
|
|
- }
|
|
|
- // else: we just need to turn on part of the flexible
|
|
|
- // energy available
|
|
|
- else {
|
|
|
- float energyNeeded = -energySurplus;
|
|
|
- int i = 0;
|
|
|
- energySurplus += energyNeeded; // should give 0, but
|
|
|
- // was kept this was
|
|
|
- // for consistency
|
|
|
- // the energy needed divided through the amount of
|
|
|
- // elements
|
|
|
- holonEl.setEnergyPerElement(energyNeeded
|
|
|
- / holonEl.getAmount());
|
|
|
- flexDevicesTurnedOnThisTurn.put(holonEl,
|
|
|
- energyNeeded);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (energySurplus == 0) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (energySurplus == 0) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Set Flow Simulation.
|
|
|
- *
|
|
|
- * @param sN
|
|
|
- * Subnet
|
|
|
- */
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * Set the Pseudo Tags.
|
|
|
- *
|
|
|
- * @param nodes
|
|
|
- * Array of AbstractCpsObjects
|
|
|
- */
|
|
|
- private void setPseudoTags(ArrayList<AbstractCpsObject> nodes,
|
|
|
- ArrayList<CpsEdge> edges) {
|
|
|
- for (AbstractCpsObject node : nodes) {
|
|
|
- node.recalculateTags();
|
|
|
- node.setPseudoTags(new ArrayList<>());
|
|
|
- }
|
|
|
- for (CpsEdge edge : edges) {
|
|
|
- edge.recalculateTags();
|
|
|
- edge.setPseudoTag(new ArrayList<>());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * copies the data of an array of Objects.
|
|
|
- *
|
|
|
- * @param toCopy
|
|
|
- * the ArrayList of CpsObjects co Copy
|
|
|
- */
|
|
|
- private void copyObjects(ArrayList<AbstractCpsObject> toCopy) {
|
|
|
- for (AbstractCpsObject cps : toCopy) {
|
|
|
- if (cps instanceof CpsUpperNode) {
|
|
|
- copyObjects(((CpsUpperNode) cps).getNodes());
|
|
|
- } else {
|
|
|
- objectsToHandle.add(cps);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * Set the Canvas.
|
|
|
- *
|
|
|
- * @param can
|
|
|
- * the Canvas
|
|
|
- */
|
|
|
- public void setCanvas(MyCanvas can) {
|
|
|
- canvas = can;
|
|
|
- }
|
|
|
- /**
|
|
|
- * Should be a better way to update the canvas -.-
|
|
|
- * @param can
|
|
|
- */
|
|
|
- public void updateCanvas() {
|
|
|
- canvas.repaint();
|
|
|
- }
|
|
|
- /**
|
|
|
- * Reset all Data to the current state of the Model.
|
|
|
- */
|
|
|
- public void reset() {
|
|
|
- objectsToHandle = new ArrayList<>();
|
|
|
- copyObjects(model.getObjectsOnCanvas());
|
|
|
- flexDevicesTurnedOnThisTurn = new HashMap<>();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* Get all Subnets.Not functional.
|
|
@@ -418,16 +214,9 @@ public class SimulationManager {
|
|
|
*/
|
|
|
@Deprecated
|
|
|
public ArrayList<SubNet> getSubNets() {
|
|
|
- return subNets;
|
|
|
+ return new ArrayList<SubNet>();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Get broken Edges
|
|
|
- */
|
|
|
- // public ArrayList<CpsEdge> getBrokenEdges() {
|
|
|
- // return brokenEdges;
|
|
|
- // }
|
|
|
-
|
|
|
|
|
|
|
|
|
public FlexiblePane getFlexiblePane() {
|
|
@@ -439,25 +228,19 @@ public class SimulationManager {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public DecoratedState getActualDecorStateWithOffSet(int offSet) {
|
|
|
- return getDecorState(timeStep + offSet);
|
|
|
- }
|
|
|
public DecoratedState getActualDecorState() {
|
|
|
return getDecorState(timeStep);
|
|
|
}
|
|
|
public VisualRepresentationalState getActualVisualRepresentationalState(){
|
|
|
return savesVisual.getOrDefault(timeStep, null);
|
|
|
}
|
|
|
+
|
|
|
public DecoratedState getDecorState(int timestep) {
|
|
|
return saves.getOrDefault(timestep, null);
|
|
|
}
|
|
|
-
|
|
|
- public void setGui(GUI gui) {
|
|
|
- this.gui = gui;
|
|
|
+ public VisualRepresentationalState getVisualRepresentationalState(int timestep) {
|
|
|
+ return savesVisual.getOrDefault(timestep, null);
|
|
|
}
|
|
|
|
|
|
- public HashMap<Integer, VisualRepresentationalState> getSavesVisual() {
|
|
|
- return savesVisual;
|
|
|
- }
|
|
|
|
|
|
}
|