|
@@ -343,117 +343,7 @@ public class SimulationManager {
|
|
|
* @param sN
|
|
|
* Subnet
|
|
|
*/
|
|
|
- private void setFlowSimulation(SubNet sN) {
|
|
|
- ArrayList<AbstractCpsObject> producers = new ArrayList<>();
|
|
|
- AbstractCpsObject tmp = null;
|
|
|
- tagTable = new HashMap<>();
|
|
|
-
|
|
|
- for (HolonObject hl : sN.getObjects()) {
|
|
|
- float energy = hl.getEnergyAtTimeStep(timeStep);
|
|
|
-
|
|
|
- if (energy > 0) {
|
|
|
- tagTable.put(hl.getId(), energy);
|
|
|
- hl.addTag(hl.getId());
|
|
|
- for (CpsEdge edge : hl.getConnections()) {
|
|
|
- if (edge.isWorking()) {
|
|
|
-
|
|
|
-
|
|
|
- AbstractCpsObject a = edge.getA();
|
|
|
- AbstractCpsObject b = edge.getB();
|
|
|
- if (a.getId() == hl.getId()) {
|
|
|
- b.addTag(hl.getId());
|
|
|
- tmp = b;
|
|
|
- }
|
|
|
- if (b.getId() == hl.getId()) {
|
|
|
- a.addTag(hl.getId());
|
|
|
- tmp = a;
|
|
|
- }
|
|
|
-
|
|
|
- edge.setFlow(edge.getFlow() + energy);
|
|
|
- edge.calculateState();
|
|
|
- edge.addTag(hl.getId());
|
|
|
- if (edge.isWorking() && !producers.contains(tmp)) {
|
|
|
- if (tmp instanceof HolonSwitch) {
|
|
|
- if (((HolonSwitch) tmp).getState(timeStep)) {
|
|
|
- producers.add(tmp);
|
|
|
- }
|
|
|
- } else if (!(tmp instanceof CpsUpperNode)) {
|
|
|
- producers.add(tmp);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- setFlowSimRec(producers, 0);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * Set Flow Simulation Rec.
|
|
|
- *
|
|
|
- * @param nodes
|
|
|
- * the nodes
|
|
|
- * @param iter
|
|
|
- * the Iteration
|
|
|
- */
|
|
|
- private void setFlowSimRec(ArrayList<AbstractCpsObject> nodes, int iter) {
|
|
|
- ArrayList<AbstractCpsObject> newNodes = new ArrayList<>();
|
|
|
- ArrayList<CpsEdge> changedEdges = new ArrayList<>();
|
|
|
- AbstractCpsObject tmp;
|
|
|
- if (nodes.size() != 0) {
|
|
|
- for (AbstractCpsObject cps : nodes) {
|
|
|
-
|
|
|
- if (legitState(cps)) {
|
|
|
- for (CpsEdge edge : cps.getConnections()) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (edge.isWorking()
|
|
|
- && (!(edge.containsTags(edge.getTags(),
|
|
|
- cps.getTag())))) {
|
|
|
- if (edge.getA().getId() == cps.getId()) {
|
|
|
- tmp = edge.getB();
|
|
|
- } else {
|
|
|
- tmp = edge.getA();
|
|
|
- }
|
|
|
- for (Integer tag : cps.getTag()) {
|
|
|
- if (!(edge.getTags().contains(tag))
|
|
|
- && !(edge.getPseudoTags().contains(tag))) {
|
|
|
- edge.setFlow(edge.getFlow()
|
|
|
- + tagTable.get(tag));
|
|
|
- edge.addTag(tag);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (!(tmp instanceof CpsUpperNode)) {
|
|
|
- for (Integer tag : tmp.getTag()) {
|
|
|
- if (!(edge.getTags().contains(tag))
|
|
|
- && tagTable.get(tag) != null
|
|
|
- && !(edge.getPseudoTags()
|
|
|
- .contains(tag))) {
|
|
|
- edge.setFlow(edge.getFlow()
|
|
|
- + tagTable.get(tag));
|
|
|
- edge.addPseudoTag(tag);
|
|
|
- changedEdges.add(edge);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- edge.calculateState();
|
|
|
- if (edge.isWorking()
|
|
|
- && !(tmp instanceof CpsUpperNode)) {
|
|
|
- tmp.addAllPseudoTags(cps.getTag());
|
|
|
- if (!newNodes.contains(tmp)) {
|
|
|
- newNodes.add(tmp);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- setPseudoTags(newNodes, changedEdges);
|
|
|
- setFlowSimRec(newNodes, iter + 1);
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
|
|
|
* Set the Pseudo Tags.
|
|
@@ -473,277 +363,8 @@ public class SimulationManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * Reset the Connection.
|
|
|
- *
|
|
|
- * @param cps
|
|
|
- * CpsObject
|
|
|
- * @param visitedObj
|
|
|
- * the visited Objects
|
|
|
- * @param visitedEdges
|
|
|
- * the visited Edges
|
|
|
- */
|
|
|
- private void resetConnections(AbstractCpsObject cps,
|
|
|
- ArrayList<Integer> visitedObj, ArrayList<CpsEdge> visitedEdges) {
|
|
|
- visitedObj.add(cps.getId());
|
|
|
- cps.resetTags();
|
|
|
- for (CpsEdge e : cps.getConnections()) {
|
|
|
- if (!(visitedEdges.contains(e))) {
|
|
|
- e.setFlow(0);
|
|
|
- e.calculateState();
|
|
|
- e.setTags(new ArrayList<>());
|
|
|
- visitedEdges.add(e);
|
|
|
- if (!(visitedObj.contains(e.getA().getId()))) {
|
|
|
- resetConnections(e.getA(), visitedObj, visitedEdges);
|
|
|
- e.getA().resetTags();
|
|
|
- }
|
|
|
- if (!(visitedObj.contains(e.getB().getId()))) {
|
|
|
- resetConnections(e.getB(), visitedObj, visitedEdges);
|
|
|
- e.getB().resetTags();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * calculates the energy of either all producers or consumers. Flexible
|
|
|
- * devices are filtered out
|
|
|
- *
|
|
|
- * @param type
|
|
|
- * Type
|
|
|
- * @param sN
|
|
|
- * Subnet
|
|
|
- * @param x
|
|
|
- * Integer
|
|
|
- * @return The Energy
|
|
|
- */
|
|
|
- private float calculateEnergyWithoutFlexDevices(String type, SubNet sN,
|
|
|
- int x) {
|
|
|
- float energy = 0;
|
|
|
- for (HolonObject hl : sN.getObjects()) {
|
|
|
- float currentEnergyWithoutFlexibles = hl
|
|
|
- .getCurrentEnergyAtTimeStepWithoutFlexiblesAndResetFlexibles(x);
|
|
|
-
|
|
|
- if (type.equals("prod")) {
|
|
|
- if (currentEnergyWithoutFlexibles > 0) {
|
|
|
- energy += currentEnergyWithoutFlexibles;
|
|
|
- hl.setState(HolonObject.PRODUCER);
|
|
|
- }
|
|
|
- }
|
|
|
- if (type.equals("cons")) {
|
|
|
- if (currentEnergyWithoutFlexibles < 0) {
|
|
|
- energy += currentEnergyWithoutFlexibles;
|
|
|
- hl.setState(HolonObject.NOT_SUPPLIED);
|
|
|
- }
|
|
|
- }
|
|
|
- if (currentEnergyWithoutFlexibles == 0) {
|
|
|
- hl.setState(HolonObject.NO_ENERGY);
|
|
|
- }
|
|
|
- }
|
|
|
- return energy;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * calculates the energy of either all producers or consumers. Flexible
|
|
|
- * devices are filtered out
|
|
|
- *
|
|
|
- * @param type
|
|
|
- * Type
|
|
|
- * @param sN
|
|
|
- * Subnet
|
|
|
- * @param x
|
|
|
- * Integer
|
|
|
- * @return The Energy
|
|
|
- */
|
|
|
- private float calculateEnergyWithFlexDevices(String type, SubNet sN, int x) {
|
|
|
- float energy = 0;
|
|
|
- for (HolonObject hl : sN.getObjects()) {
|
|
|
- float currentEnergy = hl.getEnergyAtTimeStep(x);
|
|
|
-
|
|
|
- if (type.equals("prod")) {
|
|
|
- if (currentEnergy > 0) {
|
|
|
- energy += currentEnergy;
|
|
|
- hl.setState(HolonObject.PRODUCER);
|
|
|
- }
|
|
|
- }
|
|
|
- if (type.equals("cons")) {
|
|
|
- if (currentEnergy < 0) {
|
|
|
- energy = energy + currentEnergy;
|
|
|
- hl.setState(HolonObject.NOT_SUPPLIED);
|
|
|
- }
|
|
|
- }
|
|
|
- if (currentEnergy == 0) {
|
|
|
- hl.setState(HolonObject.NO_ENERGY);
|
|
|
- }
|
|
|
- }
|
|
|
- return energy;
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- * Calculate the Minimum Energy of a Subnet.
|
|
|
- *
|
|
|
- * @param sN
|
|
|
- * Subnet
|
|
|
- * @param x
|
|
|
- * Integer
|
|
|
- * @return the Calculated minimum Energy of a Subnet
|
|
|
- */
|
|
|
- private float calculateMinimumEnergy(SubNet sN, int x) {
|
|
|
- float minimummConsumptionSubnet = 0;
|
|
|
- for (HolonObject hl : sN.getObjects()) {
|
|
|
- float minElement = 0;
|
|
|
-
|
|
|
- for (HolonElement he : hl.getElements()) {
|
|
|
- if (he.isActive()) {
|
|
|
- float overallEnergy = he.getOverallEnergyAtTimeStep(x);
|
|
|
- if (overallEnergy < 0) {
|
|
|
-
|
|
|
- minElement = overallEnergy;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- for (HolonElement he : hl.getElements()) {
|
|
|
- if (he.isActive()) {
|
|
|
- float overallEnergy = he.getOverallEnergyAtTimeStep(x);
|
|
|
|
|
|
- if (minElement < overallEnergy && overallEnergy < 0) {
|
|
|
-
|
|
|
- minElement = overallEnergy;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- minimummConsumptionSubnet += minElement;
|
|
|
- }
|
|
|
- System.out.println("MinimumEnergy = "+ minimummConsumptionSubnet);
|
|
|
- return minimummConsumptionSubnet;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * generates all subNets from all objectsToHandle.
|
|
|
- */
|
|
|
- private void searchForSubNets() {
|
|
|
- subNets = new ArrayList<>();
|
|
|
- brokenEdges.clear();
|
|
|
- boolean end = false;
|
|
|
- int i = 0;
|
|
|
- AbstractCpsObject cps;
|
|
|
- if (objectsToHandle.size() > 0) {
|
|
|
- while (!end) {
|
|
|
- cps = objectsToHandle.get(i);
|
|
|
- SubNet singleSubNet = new SubNet(new ArrayList<>(),
|
|
|
- new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
|
|
|
- singleSubNet = buildSubNet(cps, new ArrayList<>(), singleSubNet);
|
|
|
- if (singleSubNet.getObjects().size() + singleSubNet.getBatteries().size() != 0 ) {
|
|
|
- subNets.add(singleSubNet);
|
|
|
- }
|
|
|
- if (0 == objectsToHandle.size()) {
|
|
|
- end = true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * recursivly generates a subnet of all objects, that one specific object is
|
|
|
- * connected to.
|
|
|
- *
|
|
|
- * @param cps
|
|
|
- * AbstractCpsObject
|
|
|
- * @param visited
|
|
|
- * visited Array of Integer
|
|
|
- * @param sN
|
|
|
- * Subnets
|
|
|
- * @return Subnet
|
|
|
- */
|
|
|
- private SubNet buildSubNet(AbstractCpsObject cps,
|
|
|
- ArrayList<Integer> visited, SubNet sN) {
|
|
|
- visited.add(cps.getId());
|
|
|
- if (cps instanceof HolonObject) {
|
|
|
- sN.getObjects().add((HolonObject) cps);
|
|
|
- }
|
|
|
- if (cps instanceof HolonSwitch) {
|
|
|
- sN.getSwitches().add((HolonSwitch) cps);
|
|
|
- }
|
|
|
- if (cps instanceof HolonBattery) {
|
|
|
- sN.getBatteries().add((HolonBattery) cps);
|
|
|
- }
|
|
|
- removeFromToHandle(cps.getId());
|
|
|
- AbstractCpsObject a;
|
|
|
- AbstractCpsObject b;
|
|
|
- for (CpsEdge edge : cps.getConnections()) {
|
|
|
- if (edge.isWorking()) {
|
|
|
- a = edge.getA();
|
|
|
- b = edge.getB();
|
|
|
- if (!(cps instanceof HolonSwitch)) {
|
|
|
- if (!(sN.getEdges().contains(edge))) {
|
|
|
- sN.getEdges().add(edge);
|
|
|
- }
|
|
|
- }
|
|
|
- if (cps instanceof HolonSwitch
|
|
|
- && ((HolonSwitch) cps).getState(timeStep)) {
|
|
|
- if (!(sN.getEdges().contains(edge))) {
|
|
|
- sN.getEdges().add(edge);
|
|
|
- }
|
|
|
- }
|
|
|
- if (!visited.contains(a.getId()) && legitState(cps)
|
|
|
- && !(a instanceof CpsUpperNode)) {
|
|
|
- sN = buildSubNet(a, visited, sN);
|
|
|
- }
|
|
|
- if (!visited.contains(b.getId()) && legitState(cps)
|
|
|
- && !(b instanceof CpsUpperNode)) {
|
|
|
- sN = buildSubNet(b, visited, sN);
|
|
|
- }
|
|
|
- if (a instanceof CpsUpperNode && a.getId() != cps.getId()) {
|
|
|
- edge.setConnected(CpsEdge.CON_UPPER_NODE_NOT_INSIDE);
|
|
|
- checkForConnectedStates(b, (CpsUpperNode) a, edge);
|
|
|
- }
|
|
|
- if (b instanceof CpsUpperNode && b.getId() != cps.getId()) {
|
|
|
- edge.setConnected(CpsEdge.CON_UPPER_NODE_NOT_INSIDE);
|
|
|
- checkForConnectedStates(a, (CpsUpperNode) b, edge);
|
|
|
- }
|
|
|
- } else {
|
|
|
- brokenEdges.add(edge);
|
|
|
- }
|
|
|
- }
|
|
|
- return sN;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * is the Switch in a legitimate State.
|
|
|
- *
|
|
|
- * @param current
|
|
|
- * AbstractCpsObject
|
|
|
- * @return boolean
|
|
|
- */
|
|
|
- private boolean legitState(AbstractCpsObject current) {
|
|
|
- return !(current instanceof HolonSwitch)
|
|
|
- || ((HolonSwitch) current).getState(timeStep);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- * removes an Object that already has been handled.
|
|
|
- *
|
|
|
- * @param id
|
|
|
- * the Object ID
|
|
|
- */
|
|
|
- private void removeFromToHandle(int id) {
|
|
|
- for (int i = 0; i < objectsToHandle.size(); i++) {
|
|
|
- if (objectsToHandle.get(i).getId() == id) {
|
|
|
- objectsToHandle.remove(i);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
|
|
|
* copies the data of an array of Objects.
|
|
@@ -761,16 +382,7 @@ public class SimulationManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * Prints the Components auf all subnets.
|
|
|
- */
|
|
|
- private void printNetsToConsole() {
|
|
|
- for (int i = 0; i < subNets.size(); i++) {
|
|
|
- SubNet subNet = subNets.get(i);
|
|
|
- System.out.println("SUBNET NR:" + i);
|
|
|
- subNet.toString(timeStep);
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
|
|
|
* Set the Canvas.
|
|
@@ -797,28 +409,14 @@ public class SimulationManager {
|
|
|
flexDevicesTurnedOnThisTurn = new HashMap<>();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * Resets the State of all Edges
|
|
|
- */
|
|
|
- private void resetEdges() {
|
|
|
- for (CpsEdge e : brokenEdges) {
|
|
|
- e.setWorkingState(true);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- * Resets the State for the whole Simulation Model
|
|
|
- */
|
|
|
- void resetSimulation() {
|
|
|
- reset();
|
|
|
- resetEdges();
|
|
|
- }
|
|
|
|
|
|
|
|
|
- * Get all Subnets.
|
|
|
+ * Get all Subnets.Not functional.
|
|
|
*
|
|
|
* @return all Subnets
|
|
|
*/
|
|
|
+ @Deprecated
|
|
|
public ArrayList<SubNet> getSubNets() {
|
|
|
return subNets;
|
|
|
}
|
|
@@ -830,30 +428,7 @@ public class SimulationManager {
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
- * 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"
|
|
|
- */
|
|
|
- private void checkForConnectedStates(AbstractCpsObject cps,
|
|
|
- CpsUpperNode cUNode, CpsEdge theEdge) {
|
|
|
- AbstractCpsObject tmp;
|
|
|
- for (CpsEdge edge : cps.getConnections()) {
|
|
|
- if (edge.getA().getId() == cps.getId()) {
|
|
|
- tmp = edge.getB();
|
|
|
- } else {
|
|
|
- tmp = edge.getA();
|
|
|
- }
|
|
|
- if (cUNode.getNodes().contains(tmp)) {
|
|
|
- if (tmp instanceof CpsUpperNode) {
|
|
|
- checkForConnectedStates(cps, (CpsUpperNode) tmp, theEdge);
|
|
|
- } else {
|
|
|
- theEdge.setConnected(CpsEdge.CON_UPPER_NODE_AND_INSIDE);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
public FlexiblePane getFlexiblePane() {
|
|
|
return flexPane;
|