|
@@ -29,7 +29,7 @@ public class SimulationManager {
|
|
*
|
|
*
|
|
* @param m Model
|
|
* @param m Model
|
|
*/
|
|
*/
|
|
- public SimulationManager(Model m) {
|
|
|
|
|
|
+ SimulationManager(Model m) {
|
|
canvas = null;
|
|
canvas = null;
|
|
model = m;
|
|
model = m;
|
|
subNets = new ArrayList<>();
|
|
subNets = new ArrayList<>();
|
|
@@ -41,7 +41,7 @@ public class SimulationManager {
|
|
*
|
|
*
|
|
* @param x current Iteration
|
|
* @param x current Iteration
|
|
*/
|
|
*/
|
|
- public void calculateStateForTimeStep(int x) {
|
|
|
|
|
|
+ void calculateStateForTimeStep(int x) {
|
|
reset();
|
|
reset();
|
|
timeStep = x;
|
|
timeStep = x;
|
|
searchForSubNets();
|
|
searchForSubNets();
|
|
@@ -55,7 +55,21 @@ public class SimulationManager {
|
|
float wastedEnergy = production + consumption;
|
|
float wastedEnergy = production + consumption;
|
|
|
|
|
|
float minConsumption = calculateMinimumEnergy(singleSubNet, timeStep);
|
|
float minConsumption = calculateMinimumEnergy(singleSubNet, timeStep);
|
|
|
|
+
|
|
|
|
+ // --------------- use flexible devices ---------------
|
|
|
|
+ // TODO: add global setting, whether the grid should react with flexible devices or whether it should not
|
|
|
|
+ if (wastedEnergy > 0) {
|
|
|
|
+ turnOnFlexibleDevices(singleSubNet, wastedEnergy);
|
|
|
|
+ // recompute after having examined all flexible devices
|
|
|
|
+ production = calculateEnergy("prod", singleSubNet, timeStep);
|
|
|
|
+ consumption = calculateEnergy("cons", singleSubNet, timeStep);
|
|
|
|
+ wastedEnergy = production + consumption;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // --------------- set flow simulation ---------------
|
|
setFlowSimulation(singleSubNet);
|
|
setFlowSimulation(singleSubNet);
|
|
|
|
+
|
|
|
|
+ // --------------- visualise graph ---------------
|
|
for (HolonObject hl : singleSubNet.getObjects()) {
|
|
for (HolonObject hl : singleSubNet.getObjects()) {
|
|
if (hl.getState() != HolonObject.NO_ENERGY
|
|
if (hl.getState() != HolonObject.NO_ENERGY
|
|
&& hl.getState() != HolonObject.PRODUCER) {
|
|
&& hl.getState() != HolonObject.PRODUCER) {
|
|
@@ -93,12 +107,24 @@ public class SimulationManager {
|
|
flexPane.recalculate();
|
|
flexPane.recalculate();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * search for all flexible devices in the network and turn them on, until wasted energy = 0
|
|
|
|
+ * or all devices have been examined
|
|
|
|
+ *
|
|
|
|
+ * @param sN the subnet
|
|
|
|
+ * @param wastedEnergy the currently wasted energy
|
|
|
|
+ */
|
|
|
|
+ void turnOnFlexibleDevices(SubNet sN, float wastedEnergy) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Set Flow Simulation.
|
|
* Set Flow Simulation.
|
|
*
|
|
*
|
|
* @param sN Subnet
|
|
* @param sN Subnet
|
|
*/
|
|
*/
|
|
- public void setFlowSimulation(SubNet sN) {
|
|
|
|
|
|
+ private void setFlowSimulation(SubNet sN) {
|
|
ArrayList<AbstractCpsObject> producers = new ArrayList<>();
|
|
ArrayList<AbstractCpsObject> producers = new ArrayList<>();
|
|
AbstractCpsObject tmp = null;
|
|
AbstractCpsObject tmp = null;
|
|
tagTable = new HashMap<>();
|
|
tagTable = new HashMap<>();
|
|
@@ -149,7 +175,7 @@ public class SimulationManager {
|
|
* @param nodes the nodes
|
|
* @param nodes the nodes
|
|
* @param iter the Iteration
|
|
* @param iter the Iteration
|
|
*/
|
|
*/
|
|
- public void setFlowSimRec(ArrayList<AbstractCpsObject> nodes, int iter) {
|
|
|
|
|
|
+ private void setFlowSimRec(ArrayList<AbstractCpsObject> nodes, int iter) {
|
|
ArrayList<AbstractCpsObject> newNodes = new ArrayList<>();
|
|
ArrayList<AbstractCpsObject> newNodes = new ArrayList<>();
|
|
ArrayList<CpsEdge> changedEdges = new ArrayList<>();
|
|
ArrayList<CpsEdge> changedEdges = new ArrayList<>();
|
|
AbstractCpsObject tmp;
|
|
AbstractCpsObject tmp;
|
|
@@ -208,7 +234,7 @@ public class SimulationManager {
|
|
*
|
|
*
|
|
* @param nodes Array of AbstractCpsObjects
|
|
* @param nodes Array of AbstractCpsObjects
|
|
*/
|
|
*/
|
|
- public void setPseudoTags(ArrayList<AbstractCpsObject> nodes, ArrayList<CpsEdge> edges) {
|
|
|
|
|
|
+ private void setPseudoTags(ArrayList<AbstractCpsObject> nodes, ArrayList<CpsEdge> edges) {
|
|
for (AbstractCpsObject node : nodes) {
|
|
for (AbstractCpsObject node : nodes) {
|
|
node.recalculateTags();
|
|
node.recalculateTags();
|
|
node.setPseudoTags(new ArrayList<>());
|
|
node.setPseudoTags(new ArrayList<>());
|
|
@@ -277,8 +303,8 @@ public class SimulationManager {
|
|
* @param visitedObj the visited Objects
|
|
* @param visitedObj the visited Objects
|
|
* @param visitedEdges the visited Edges
|
|
* @param visitedEdges the visited Edges
|
|
*/
|
|
*/
|
|
- public void resetConnections(AbstractCpsObject cps, ArrayList<Integer> visitedObj,
|
|
|
|
- ArrayList<CpsEdge> visitedEdges) {
|
|
|
|
|
|
+ private void resetConnections(AbstractCpsObject cps, ArrayList<Integer> visitedObj,
|
|
|
|
+ ArrayList<CpsEdge> visitedEdges) {
|
|
visitedObj.add(cps.getId());
|
|
visitedObj.add(cps.getId());
|
|
cps.resetTags();
|
|
cps.resetTags();
|
|
for (CpsEdge e : cps.getConnections()) {
|
|
for (CpsEdge e : cps.getConnections()) {
|
|
@@ -307,7 +333,7 @@ public class SimulationManager {
|
|
* @param x Integer
|
|
* @param x Integer
|
|
* @return The Energy
|
|
* @return The Energy
|
|
*/
|
|
*/
|
|
- public float calculateEnergy(String type, SubNet sN, int x) {
|
|
|
|
|
|
+ private float calculateEnergy(String type, SubNet sN, int x) {
|
|
float energy = 0;
|
|
float energy = 0;
|
|
for (HolonObject hl : sN.getObjects()) {
|
|
for (HolonObject hl : sN.getObjects()) {
|
|
if (type.equals("prod")) {
|
|
if (type.equals("prod")) {
|
|
@@ -336,7 +362,7 @@ public class SimulationManager {
|
|
* @param x Integer
|
|
* @param x Integer
|
|
* @return the Calculated minimum Energy
|
|
* @return the Calculated minimum Energy
|
|
*/
|
|
*/
|
|
- public float calculateMinimumEnergy(SubNet sN, int x) {
|
|
|
|
|
|
+ private float calculateMinimumEnergy(SubNet sN, int x) {
|
|
float min = 0;
|
|
float min = 0;
|
|
float minElement = 0;
|
|
float minElement = 0;
|
|
for (HolonObject hl : sN.getObjects()) {
|
|
for (HolonObject hl : sN.getObjects()) {
|
|
@@ -356,7 +382,7 @@ public class SimulationManager {
|
|
/**
|
|
/**
|
|
* generates all subNets from all objectsToHandle.
|
|
* generates all subNets from all objectsToHandle.
|
|
*/
|
|
*/
|
|
- public void searchForSubNets() {
|
|
|
|
|
|
+ private void searchForSubNets() {
|
|
subNets = new ArrayList<>();
|
|
subNets = new ArrayList<>();
|
|
brokenEdges.clear();
|
|
brokenEdges.clear();
|
|
boolean end = false;
|
|
boolean end = false;
|
|
@@ -387,7 +413,7 @@ public class SimulationManager {
|
|
* @param sN Subnets
|
|
* @param sN Subnets
|
|
* @return Subnet
|
|
* @return Subnet
|
|
*/
|
|
*/
|
|
- public SubNet buildSubNet(AbstractCpsObject cps, ArrayList<Integer> visited, SubNet sN) {
|
|
|
|
|
|
+ private SubNet buildSubNet(AbstractCpsObject cps, ArrayList<Integer> visited, SubNet sN) {
|
|
visited.add(cps.getId());
|
|
visited.add(cps.getId());
|
|
if (cps instanceof HolonObject) {
|
|
if (cps instanceof HolonObject) {
|
|
sN.getObjects().add((HolonObject) cps);
|
|
sN.getObjects().add((HolonObject) cps);
|
|
@@ -439,11 +465,9 @@ public class SimulationManager {
|
|
* @param current AbstractCpsObject
|
|
* @param current AbstractCpsObject
|
|
* @return boolean
|
|
* @return boolean
|
|
*/
|
|
*/
|
|
- public boolean legitState(AbstractCpsObject current) {
|
|
|
|
- if (current instanceof HolonSwitch) {
|
|
|
|
- return ((HolonSwitch) current).getState(timeStep);
|
|
|
|
- }
|
|
|
|
- return true;
|
|
|
|
|
|
+ private boolean legitState(AbstractCpsObject current) {
|
|
|
|
+ return !(current instanceof HolonSwitch)
|
|
|
|
+ || ((HolonSwitch) current).getState(timeStep);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -451,7 +475,7 @@ public class SimulationManager {
|
|
*
|
|
*
|
|
* @param id the Object ID
|
|
* @param id the Object ID
|
|
*/
|
|
*/
|
|
- public void removeFromToHandle(int id) {
|
|
|
|
|
|
+ private void removeFromToHandle(int id) {
|
|
for (int i = 0; i < objectsToHandle.size(); i++) {
|
|
for (int i = 0; i < objectsToHandle.size(); i++) {
|
|
if (objectsToHandle.get(i).getId() == id) {
|
|
if (objectsToHandle.get(i).getId() == id) {
|
|
objectsToHandle.remove(i);
|
|
objectsToHandle.remove(i);
|
|
@@ -475,7 +499,7 @@ public class SimulationManager {
|
|
*
|
|
*
|
|
* @param toCopy the ArrayList of CpsObjects co Copy
|
|
* @param toCopy the ArrayList of CpsObjects co Copy
|
|
*/
|
|
*/
|
|
- public void copyObjects(ArrayList<AbstractCpsObject> toCopy) {
|
|
|
|
|
|
+ private void copyObjects(ArrayList<AbstractCpsObject> toCopy) {
|
|
for (AbstractCpsObject cps : toCopy) {
|
|
for (AbstractCpsObject cps : toCopy) {
|
|
if (cps instanceof CpsUpperNode) {
|
|
if (cps instanceof CpsUpperNode) {
|
|
copyObjects(((CpsUpperNode) cps).getNodes());
|
|
copyObjects(((CpsUpperNode) cps).getNodes());
|
|
@@ -529,7 +553,7 @@ public class SimulationManager {
|
|
/**
|
|
/**
|
|
* Resets the State of all Edges
|
|
* Resets the State of all Edges
|
|
*/
|
|
*/
|
|
- public void resetEdges() {
|
|
|
|
|
|
+ private void resetEdges() {
|
|
for (CpsEdge e : brokenEdges) {
|
|
for (CpsEdge e : brokenEdges) {
|
|
e.setWorkingState(true);
|
|
e.setWorkingState(true);
|
|
}
|
|
}
|
|
@@ -538,7 +562,7 @@ public class SimulationManager {
|
|
/**
|
|
/**
|
|
* Resets the State for the whole Simulation Model
|
|
* Resets the State for the whole Simulation Model
|
|
*/
|
|
*/
|
|
- public void resetSimulation() {
|
|
|
|
|
|
+ void resetSimulation() {
|
|
reset();
|
|
reset();
|
|
resetEdges();
|
|
resetEdges();
|
|
}
|
|
}
|
|
@@ -555,18 +579,15 @@ public class SimulationManager {
|
|
/**
|
|
/**
|
|
* Get broken Edges
|
|
* Get broken Edges
|
|
*/
|
|
*/
|
|
- public ArrayList<CpsEdge> getBrokenEdges() {
|
|
|
|
- return brokenEdges;
|
|
|
|
- }
|
|
|
|
|
|
+// public ArrayList<CpsEdge> getBrokenEdges() {
|
|
|
|
+// return brokenEdges;
|
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
/**
|
|
* checks whether a given object is connected to an object inside the upperNode.
|
|
* checks whether a given object is connected to an object inside the upperNode.
|
|
* if yes, the state for the edge is changed in "connected" or "not connected"
|
|
* if yes, the state for the edge is changed in "connected" or "not connected"
|
|
- *
|
|
|
|
- * @param cps
|
|
|
|
- * @param cUNode
|
|
|
|
*/
|
|
*/
|
|
- public void checkForConnectedStates(AbstractCpsObject cps, CpsUpperNode cUNode, CpsEdge theEdge) {
|
|
|
|
|
|
+ private void checkForConnectedStates(AbstractCpsObject cps, CpsUpperNode cUNode, CpsEdge theEdge) {
|
|
AbstractCpsObject tmp;
|
|
AbstractCpsObject tmp;
|
|
for (CpsEdge edge : cps.getConnections()) {
|
|
for (CpsEdge edge : cps.getConnections()) {
|
|
if (edge.getA().getId() == cps.getId()) {
|
|
if (edge.getA().getId() == cps.getId()) {
|
|
@@ -589,7 +610,7 @@ public class SimulationManager {
|
|
return flexPane;
|
|
return flexPane;
|
|
}
|
|
}
|
|
|
|
|
|
- public void setFlexiblePane(FlexiblePane fp) {
|
|
|
|
|
|
+ void setFlexiblePane(FlexiblePane fp) {
|
|
flexPane = fp;
|
|
flexPane = fp;
|
|
}
|
|
}
|
|
|
|
|