|
@@ -9,6 +9,7 @@ import java.text.NumberFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Hashtable;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import javax.swing.BorderFactory;
|
|
|
import javax.swing.BoxLayout;
|
|
@@ -29,6 +30,7 @@ import com.google.gson.JsonIOException;
|
|
|
import com.google.gson.JsonParser;
|
|
|
import com.google.gson.JsonSyntaxException;
|
|
|
import com.google.gson.annotations.Expose;
|
|
|
+import com.google.gson.annotations.SerializedName;
|
|
|
|
|
|
import api.AddOn;
|
|
|
import classes.AbstractCpsObject;
|
|
@@ -36,6 +38,7 @@ import classes.Constrain;
|
|
|
import classes.CpsUpperNode;
|
|
|
import classes.Flexibility;
|
|
|
import classes.HolonElement;
|
|
|
+import classes.HolonElement.Priority;
|
|
|
import classes.HolonObject;
|
|
|
import classes.HolonSwitch;
|
|
|
import ui.controller.Control;
|
|
@@ -122,9 +125,9 @@ public class Randomizer implements AddOn {
|
|
|
readCatalogFromJson(file, holonElementCatalog);
|
|
|
holonElementCatalog.forEach(con -> con.checkValues());
|
|
|
|
|
|
- List<HolonObject> consumerList = new ArrayList<HolonObject>();
|
|
|
- rollOutNodes(control.getModel().getObjectsOnCanvas(), consumerList, control.getModel().getCurIteration());
|
|
|
- consumerList.forEach(con -> {
|
|
|
+ List<HolonObject> holonObjectList = new ArrayList<HolonObject>();
|
|
|
+ rollOutNodes(control.getModel().getObjectsOnCanvas(), holonObjectList, control.getModel().getCurIteration());
|
|
|
+ holonObjectList.forEach(con -> {
|
|
|
con.getElements().clear();
|
|
|
int randomAmountOfElementsToAdd = Random.nextIntegerInRange(minAmountOfElements, maxAmountOfElements + 1);
|
|
|
for(int i = 0; i < randomAmountOfElementsToAdd; i++) {
|
|
@@ -134,13 +137,16 @@ public class Randomizer implements AddOn {
|
|
|
});
|
|
|
control.calculateStateAndVisualForCurrentTimeStep();
|
|
|
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);
|
|
|
+
|
|
|
+ consumerList.add(hO);
|
|
|
}
|
|
|
else if(aCps instanceof CpsUpperNode) {
|
|
|
rollOutNodes(((CpsUpperNode)aCps).getNodes(), consumerList ,timeStep );
|
|
@@ -167,6 +173,9 @@ public class Randomizer implements AddOn {
|
|
|
public int minAmount;
|
|
|
public int maxAmount;
|
|
|
public float energy;
|
|
|
+
|
|
|
+ public String priority;
|
|
|
+
|
|
|
|
|
|
public double flexChance;
|
|
|
@Expose
|
|
@@ -192,6 +201,7 @@ public class Randomizer implements AddOn {
|
|
|
HolonElement ele = new HolonElement(name, Random.nextIntegerInRange(minAmount, maxAmount + 1), energy , model);
|
|
|
ele.setActive(active);
|
|
|
if(Random.nextDouble() < flexChance)addFlex(ele, nameOfHolonObject);
|
|
|
+ ele.setPriority(Priority.valueOf(priority));
|
|
|
return ele;
|
|
|
}
|
|
|
|