|
@@ -31,8 +31,10 @@ import com.google.gson.JsonSyntaxException;
|
|
|
|
|
|
import api.Algorithm;
|
|
import api.Algorithm;
|
|
import classes.AbstractCpsObject;
|
|
import classes.AbstractCpsObject;
|
|
|
|
+import classes.CpsUpperNode;
|
|
import classes.HolonElement;
|
|
import classes.HolonElement;
|
|
import classes.HolonObject;
|
|
import classes.HolonObject;
|
|
|
|
+import classes.HolonSwitch;
|
|
import ui.controller.Control;
|
|
import ui.controller.Control;
|
|
import ui.model.Model;
|
|
import ui.model.Model;
|
|
|
|
|
|
@@ -108,12 +110,7 @@ public class Randomizer implements Algorithm {
|
|
if(file == null) return;
|
|
if(file == null) return;
|
|
readMsgFromJSONwithGSON(file, holonObjectCatalog);
|
|
readMsgFromJSONwithGSON(file, holonObjectCatalog);
|
|
List<HolonObject> consumerList = new ArrayList<HolonObject>();
|
|
List<HolonObject> consumerList = new ArrayList<HolonObject>();
|
|
- for (AbstractCpsObject aCps : control.getModel().getObjectsOnCanvas()) {
|
|
|
|
- if (aCps instanceof HolonObject) {
|
|
|
|
- HolonObject hO = (HolonObject) aCps;
|
|
|
|
- if(hO.getEnergyAtTimeStep(control.getModel().getCurIteration()) < 0)consumerList.add(hO);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ rollOutNodes(control.getModel().getObjectsOnCanvas(), consumerList, control.getModel().getCurIteration());
|
|
consumerList.forEach(con -> {
|
|
consumerList.forEach(con -> {
|
|
con.getElements().clear();
|
|
con.getElements().clear();
|
|
int randomAmountOfElementsToAdd = Random.nextIntegerInRange(minAmountOfElements, maxAmountOfElements + 1);
|
|
int randomAmountOfElementsToAdd = Random.nextIntegerInRange(minAmountOfElements, maxAmountOfElements + 1);
|
|
@@ -124,6 +121,22 @@ public class Randomizer implements Algorithm {
|
|
control.calculateStateAndVisualForCurrentTimeStep();
|
|
control.calculateStateAndVisualForCurrentTimeStep();
|
|
control.updateCanvas();
|
|
control.updateCanvas();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private void rollOutNodes(List<AbstractCpsObject> nodes, List<HolonObject> consumerList, int timeStep) {
|
|
|
|
+ for (AbstractCpsObject aCps : nodes) {
|
|
|
|
+ if (aCps instanceof HolonObject) {
|
|
|
|
+ HolonObject hO = (HolonObject) aCps;
|
|
|
|
+ if(hO.getEnergyAtTimeStep(control.getModel().getCurIteration()) < 0)consumerList.add(hO);
|
|
|
|
+ }
|
|
|
|
+ else if(aCps instanceof CpsUpperNode) {
|
|
|
|
+ rollOutNodes(((CpsUpperNode)aCps).getNodes(), consumerList ,timeStep );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public JPanel getAlgorithmPanel() {
|
|
public JPanel getAlgorithmPanel() {
|
|
return content;
|
|
return content;
|
|
@@ -217,6 +230,11 @@ public class Randomizer implements Algorithm {
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
public File openCatalogFile() {
|
|
public File openCatalogFile() {
|
|
JFileChooser fileChooser = new JFileChooser();
|
|
JFileChooser fileChooser = new JFileChooser();
|
|
fileChooser.setCurrentDirectory(new File(System.getProperty("user.dir")+"/src/"));
|
|
fileChooser.setCurrentDirectory(new File(System.getProperty("user.dir")+"/src/"));
|