|
@@ -14,6 +14,7 @@ import java.util.HashMap;
|
|
|
* @author Gruppe14
|
|
|
*/
|
|
|
public class SimulationManager {
|
|
|
+ int global = 0;
|
|
|
private Model model;
|
|
|
private ArrayList<AbstractCpsObject> objectsToHandle;
|
|
|
// private ArrayList<CpsEdge> allConnections;
|
|
@@ -60,7 +61,8 @@ public class SimulationManager {
|
|
|
// 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
|
|
|
+
|
|
|
+ // recompute after having examined/turned on all flexible devices
|
|
|
production = calculateEnergy("prod", singleSubNet, timeStep);
|
|
|
consumption = calculateEnergy("cons", singleSubNet, timeStep);
|
|
|
wastedEnergy = production + consumption;
|
|
@@ -107,16 +109,31 @@ public class SimulationManager {
|
|
|
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 subNet the subnet
|
|
|
* @param wastedEnergy the currently wasted energy
|
|
|
*/
|
|
|
- void turnOnFlexibleDevices(SubNet sN, float wastedEnergy) {
|
|
|
-
|
|
|
+ private void turnOnFlexibleDevices(SubNet subNet, float wastedEnergy) {
|
|
|
+ for (HolonObject holonOb : subNet.getObjects()) {
|
|
|
+ for (HolonElement holonEl : holonOb.getElements()) {
|
|
|
+ // if this element is flexible
|
|
|
+ float energyOfElement = holonEl.getEnergy();
|
|
|
+ if (holonEl.isFlexible() && energyOfElement < 0) {
|
|
|
+// if (energyOfElement <= wastedEnergy) {
|
|
|
+// holonEl.setActive(true);
|
|
|
+// wastedEnergy += energyOfElement;
|
|
|
+// }else{
|
|
|
+// }
|
|
|
+
|
|
|
+// System.out.println("el.getEnergy(): " + holonEl.getEnergy());
|
|
|
+// System.out.println("wasted: " + wastedEnergy);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+// System.out.println();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -245,57 +262,6 @@ public class SimulationManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// /**
|
|
|
-// * Print the nodes.
|
|
|
-// *
|
|
|
-// * @param nodes
|
|
|
-// * Array of AbstractCpsObject
|
|
|
-// */
|
|
|
-// public void printNodes(ArrayList<AbstractCpsObject> nodes) {
|
|
|
-// for (AbstractCpsObject node : nodes) {
|
|
|
-// System.out.println(node.getId());
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// /**
|
|
|
-// * Get String.
|
|
|
-// *
|
|
|
-// * @param tags
|
|
|
-// * the tags
|
|
|
-// * @return the String
|
|
|
-// */
|
|
|
-// public String getString(ArrayList<Integer> tags) {
|
|
|
-// String result = "";
|
|
|
-// for (Integer i : tags) {
|
|
|
-// result = result + ", " + i;
|
|
|
-// }
|
|
|
-// return result;
|
|
|
-// }
|
|
|
-
|
|
|
-// /**
|
|
|
-// * Merge the Lists.
|
|
|
-// *
|
|
|
-// * @param a
|
|
|
-// * first liust
|
|
|
-// * @param b
|
|
|
-// * second list
|
|
|
-// * @return the Result
|
|
|
-// */
|
|
|
-// public ArrayList<Integer> mergeLists(ArrayList<Integer> a, ArrayList<Integer> b) {
|
|
|
-// ArrayList<Integer> result = new ArrayList<>();
|
|
|
-// for (Integer i : a) {
|
|
|
-// if (!(result.contains(i))) {
|
|
|
-// result.add(i);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// for (Integer j : b) {
|
|
|
-// if (!(result.contains(j))) {
|
|
|
-// result.add(j);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return result;
|
|
|
-// }
|
|
|
-
|
|
|
/**
|
|
|
* Reset the Connection.
|
|
|
*
|
|
@@ -470,6 +436,17 @@ public class SimulationManager {
|
|
|
|| ((HolonSwitch) current).getState(timeStep);
|
|
|
}
|
|
|
|
|
|
+// /**
|
|
|
+// * ensures that objectsToHandle only contains HolonObjects.
|
|
|
+// */
|
|
|
+// public void cleanObjectsToHandle() {
|
|
|
+// for (int i = 0; i < objectsToHandle.size(); i++) {
|
|
|
+// if (!(objectsToHandle.get(i) instanceof HolonObject)) {
|
|
|
+// objectsToHandle.remove(i);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
/**
|
|
|
* removes an Object that already has been handled.
|
|
|
*
|
|
@@ -483,17 +460,6 @@ public class SimulationManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// /**
|
|
|
-// * ensures that objectsToHandle only contains HolonObjects.
|
|
|
-// */
|
|
|
-// public void cleanObjectsToHandle() {
|
|
|
-// for (int i = 0; i < objectsToHandle.size(); i++) {
|
|
|
-// if (!(objectsToHandle.get(i) instanceof HolonObject)) {
|
|
|
-// objectsToHandle.remove(i);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
/**
|
|
|
* copies the data of an array of Objects.
|
|
|
*
|
|
@@ -512,24 +478,29 @@ public class SimulationManager {
|
|
|
/**
|
|
|
* Prints the Components auf all subnets.
|
|
|
*/
|
|
|
- public void printNetsToConsole() {
|
|
|
+ private void printNetsToConsole() {
|
|
|
for (int i = 0; i < subNets.size(); i++) {
|
|
|
+ SubNet subNet = subNets.get(i);
|
|
|
System.out.println("SUBNET NR:" + i);
|
|
|
- System.out.println(" Objects:");
|
|
|
- for (int j = 0; j < subNets.get(i).getObjects().size(); j++) {
|
|
|
- HolonObject hl = subNets.get(i).getObjects().get(j);
|
|
|
- System.out.println(" " + hl.getName() + " " + hl.getId());
|
|
|
- }
|
|
|
- System.out.println(" Edges:");
|
|
|
- for (int j = 0; j < subNets.get(i).getEdges().size(); j++) {
|
|
|
- CpsEdge edge = subNets.get(i).getEdges().get(j);
|
|
|
- System.out.println(" " + edge.getA().getName() + " connected To " + edge.getB().getName());
|
|
|
- }
|
|
|
- System.out.println(" Switches:");
|
|
|
- for (int j = 0; j < subNets.get(i).getSwitches().size(); j++) {
|
|
|
- HolonSwitch sw = subNets.get(i).getSwitches().get(j);
|
|
|
- System.out.println(" " + sw.getName() + " " + sw.getId() + " State:" + sw.getActiveAt()[timeStep]);
|
|
|
- }
|
|
|
+ printSingleNetToConsole(subNet);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void printSingleNetToConsole(SubNet subNet) {
|
|
|
+ System.out.println(" Objects:");
|
|
|
+ for (int j = 0; j < subNet.getObjects().size(); j++) {
|
|
|
+ HolonObject hl = subNet.getObjects().get(j);
|
|
|
+ System.out.println(" " + hl.getName() + " " + hl.getId());
|
|
|
+ }
|
|
|
+ System.out.println(" Edges:");
|
|
|
+ for (int j = 0; j < subNet.getEdges().size(); j++) {
|
|
|
+ CpsEdge edge = subNet.getEdges().get(j);
|
|
|
+ System.out.println(" " + edge.getA().getName() + " connected To " + edge.getB().getName());
|
|
|
+ }
|
|
|
+ System.out.println(" Switches:");
|
|
|
+ for (int j = 0; j < subNet.getSwitches().size(); j++) {
|
|
|
+ HolonSwitch sw = subNet.getSwitches().get(j);
|
|
|
+ System.out.println(" " + sw.getName() + " " + sw.getId() + " State:" + sw.getActiveAt()[timeStep]);
|
|
|
}
|
|
|
}
|
|
|
|