|
@@ -15,14 +15,16 @@ import java.text.NumberFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.DoubleSummaryStatistics;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Queue;
|
|
|
import java.util.function.BiFunction;
|
|
|
import java.util.function.Consumer;
|
|
|
import java.util.function.Supplier;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
import javax.swing.BorderFactory;
|
|
|
import javax.swing.Box;
|
|
@@ -74,13 +76,19 @@ public abstract class AlgorithmFrameworkFlex implements AddOn {
|
|
|
private JPanel borderPanel = new JPanel();
|
|
|
|
|
|
// Settings groupNode
|
|
|
- private DecoratedGroupNode dGroupNode = null;
|
|
|
+
|
|
|
+ protected DecoratedGroupNode dGroupNode = null;
|
|
|
|
|
|
// access
|
|
|
- private ArrayList<AccessWrapper> access;
|
|
|
- private HashMap<HolonObject, AccessWrapper> accessKillSwitch = new HashMap<HolonObject, AccessWrapper>();
|
|
|
- LinkedList<List<Boolean>> resetChain = new LinkedList<List<Boolean>>();
|
|
|
- boolean algoUseElements = false, algoUseSwitches = true, algoUseFlexes = true, algoUseKillSwitch = true;
|
|
|
+ protected ArrayList<AccessWrapper> access;
|
|
|
+ protected LinkedList<List<Boolean>> resetChain = new LinkedList<List<Boolean>>();
|
|
|
+ protected boolean algoUseElements = false;
|
|
|
+
|
|
|
+ protected boolean algoUseSwitches = true;
|
|
|
+
|
|
|
+ protected boolean algoUseFlexes = true;
|
|
|
+
|
|
|
+ protected boolean algoUseKillSwitch = true;
|
|
|
|
|
|
// time
|
|
|
private long startTime;
|
|
@@ -747,68 +755,86 @@ public abstract class AlgorithmFrameworkFlex implements AddOn {
|
|
|
*/
|
|
|
protected List<Boolean> extractPositionAndAccess() {
|
|
|
Model model = control.getModel();
|
|
|
- this.accessKillSwitch = new HashMap<HolonObject, AccessWrapper>();
|
|
|
access = new ArrayList<AccessWrapper>();
|
|
|
List<Boolean> initialState = new ArrayList<Boolean>();
|
|
|
- rollOutNodes((dGroupNode != null) ? dGroupNode.getModel().getNodes() : model.getObjectsOnCanvas(), initialState,
|
|
|
- model.getCurIteration());
|
|
|
- resetChain.add(initialState);
|
|
|
- if (algoUseFlexes) {
|
|
|
- for (FlexWrapper flex : control.getSimManager().getActualFlexManager()
|
|
|
- .getAllFlexWrapperWithState(FlexState.OFFERED)) {
|
|
|
- // flex.getFlex().getElement().parentObject;
|
|
|
- AccessWrapper killSwitchAccess = this.algoUseKillSwitch
|
|
|
- ? this.accessKillSwitch.get(flex.getFlex().getElement().parentObject)
|
|
|
- : null;
|
|
|
- ;
|
|
|
- access.add(new AccessWrapper(flex.getFlex(), killSwitchAccess));
|
|
|
- initialState.add(false);
|
|
|
- }
|
|
|
- for (FlexWrapper flex : control.getSimManager().getActualFlexManager()
|
|
|
- .getAllFlexWrapperWithState(FlexState.IN_USE)) {
|
|
|
- AccessWrapper killSwitchAccess = this.algoUseKillSwitch
|
|
|
- ? this.accessKillSwitch.get(flex.getFlex().getElement().parentObject)
|
|
|
- : null;
|
|
|
- access.add(new AccessWrapper(flex.getFlex(), killSwitchAccess));
|
|
|
- initialState.add(true);
|
|
|
- }
|
|
|
+ List<AbstractCanvasObject> nodes = (dGroupNode != null) ? dGroupNode.getModel().getNodes()
|
|
|
+ : model.getObjectsOnCanvas();
|
|
|
+ Map<Boolean, List<AbstractCanvasObject>> map = nodes.stream()
|
|
|
+ .collect(Collectors.partitioningBy(aCps -> aCps instanceof GroupNode));
|
|
|
+ Queue<GroupNode> groupNodeQueue = new LinkedList<GroupNode>();
|
|
|
+ rollOutNodes(map.get(false).stream(), map.get(true).stream().map(aCps -> (GroupNode) aCps), groupNodeQueue,
|
|
|
+ initialState, model.getCurIteration());
|
|
|
+ while (!groupNodeQueue.isEmpty()) {
|
|
|
+ rollOutQueue(groupNodeQueue, initialState, model.getCurIteration());
|
|
|
}
|
|
|
- // console.println(access.stream().map(Object::toString).collect(Collectors.joining(",
|
|
|
- // ")));
|
|
|
+ resetChain.add(initialState);
|
|
|
return initialState;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+<<<<<<< HEAD
|
|
|
* Method to extract the Informations recursively out of the Model.
|
|
|
+=======
|
|
|
+ * Method to extract the Informations per Layer out of the Model.
|
|
|
+>>>>>>> refs/heads/Greedy
|
|
|
*
|
|
|
* @param nodes
|
|
|
* @param positionToInit
|
|
|
* @param timeStep
|
|
|
*/
|
|
|
- private void rollOutNodes(List<AbstractCanvasObject> nodes, List<Boolean> positionToInit, int timeStep) {
|
|
|
- for (AbstractCanvasObject aCps : nodes) {
|
|
|
+
|
|
|
+ protected void rollOutNodes(Stream<AbstractCanvasObject> nodesExceptGroupNodes, Stream<GroupNode> groupNodes,
|
|
|
+ Queue<GroupNode> queue, List<Boolean> positionToInit, int timeStep) {
|
|
|
+ nodesExceptGroupNodes.forEach(aCps -> {
|
|
|
+
|
|
|
if (aCps instanceof HolonObject) {
|
|
|
HolonObject hObject = (HolonObject) aCps;
|
|
|
AccessWrapper killSwitchAccess = new AccessWrapper(hObject);
|
|
|
if (this.algoUseKillSwitch) {
|
|
|
- positionToInit.add(false);
|
|
|
- access.add(killSwitchAccess);
|
|
|
- accessKillSwitch.put(hObject, killSwitchAccess);
|
|
|
+
|
|
|
+ positionToInit.add(0, false);
|
|
|
+ access.add(0, killSwitchAccess);
|
|
|
+
|
|
|
}
|
|
|
if (this.algoUseElements) {
|
|
|
for (HolonElement hE : hObject.getElements()) {
|
|
|
- positionToInit.add(hE.isActive());
|
|
|
- access.add(new AccessWrapper(hE, killSwitchAccess));
|
|
|
+
|
|
|
+ positionToInit.add(0, hE.isActive());
|
|
|
+ access.add(0, new AccessWrapper(hE, killSwitchAccess));
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (this.algoUseFlexes) {
|
|
|
+ for (HolonElement hE : hObject.getElements()) {
|
|
|
+ for(Flexibility flex : hE.flexList) {
|
|
|
+ switch(control.getSimManager().getActualFlexManager().getFlexWrapperFromFlexibility(flex).getState()) {
|
|
|
+ case IN_USE:
|
|
|
+ case ON_COOLDOWN:
|
|
|
+ positionToInit.add(0, true);
|
|
|
+ access.add(0, new AccessWrapper(flex, killSwitchAccess));
|
|
|
+ break;
|
|
|
+ case OFFERED:
|
|
|
+ positionToInit.add(0, false);
|
|
|
+ access.add(0, new AccessWrapper(flex, killSwitchAccess));
|
|
|
+ break;
|
|
|
+ case NOT_OFFERED:
|
|
|
+ case UNAVAILABLE:
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
} else if (aCps instanceof HolonSwitch && algoUseSwitches) {
|
|
|
HolonSwitch sw = (HolonSwitch) aCps;
|
|
|
- positionToInit.add(sw.getState(timeStep));
|
|
|
- access.add(new AccessWrapper(sw));
|
|
|
- } else if (aCps instanceof GroupNode) {
|
|
|
- rollOutNodes(((GroupNode) aCps).getNodes(), positionToInit, timeStep);
|
|
|
+ positionToInit.add(0, sw.getState(timeStep));
|
|
|
+ access.add(0, new AccessWrapper(sw));
|
|
|
}
|
|
|
- }
|
|
|
+ });
|
|
|
+ queue.addAll(groupNodes.collect(Collectors.toList()));
|
|
|
}
|
|
|
|
|
|
private void printAddtionalHolonInformation() {
|
|
@@ -858,6 +884,12 @@ public abstract class AlgorithmFrameworkFlex implements AddOn {
|
|
|
count++;
|
|
|
}
|
|
|
}
|
|
|
+ protected void rollOutQueue(Queue<GroupNode> queue, List<Boolean> positionToInit, int timeStep) {
|
|
|
+ Map<Boolean, List<AbstractCanvasObject>> map = queue.remove().getNodes().stream()
|
|
|
+ .collect(Collectors.partitioningBy(aCps -> aCps instanceof GroupNode));
|
|
|
+ rollOutNodes(map.get(false).stream(), map.get(true).stream().map(aCps -> (GroupNode) aCps), queue,
|
|
|
+ positionToInit, timeStep);
|
|
|
+ }
|
|
|
|
|
|
private RunValues getRunValuesFromActualState() {
|
|
|
RunValues val = new RunValues();
|
|
@@ -1004,6 +1036,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn {
|
|
|
count = 0;
|
|
|
isActive = true;
|
|
|
progressBar.setValue(0);
|
|
|
+
|
|
|
progressBar.setMaximum(getProgressBarMaxCount());
|
|
|
}
|
|
|
|
|
@@ -1189,7 +1222,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn {
|
|
|
* A Wrapper Class for Access HolonElement and HolonSwitch in one Element and
|
|
|
* not have to split the List.
|
|
|
*/
|
|
|
- private class AccessWrapper {
|
|
|
+ public class AccessWrapper {
|
|
|
private AccessType type;
|
|
|
private List<Boolean> intialStatesOfElementForKilllSwitch;
|
|
|
|
|
@@ -1271,7 +1304,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn {
|
|
|
case HolonElement:
|
|
|
return "HolonElement";
|
|
|
case Switch:
|
|
|
- return "Switch";
|
|
|
+ return "Switch" + hSwitch.getId();
|
|
|
case Flexibility:
|
|
|
return "Flexibility";
|
|
|
case KillSwitch:
|