|
@@ -93,14 +93,13 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
|
|
|
|
|
|
private HashSet<IndexCable> cableSet = new HashSet<IndexCable>();
|
|
|
private ArrayList<IndexCable> cableList = new ArrayList<IndexCable>();
|
|
|
- private HashSet<IndexCable> addedIndexCable = new HashSet<IndexCable>();
|
|
|
+ private HashMap<IndexCable, Double> addedIndexCable = new HashMap<IndexCable, Double>();
|
|
|
private int countForAccessMap = 0;
|
|
|
private int amountOfExistingCables = 0;
|
|
|
private ArrayList<HolonSwitch> switchList = new ArrayList<HolonSwitch>();
|
|
|
private HashMap<HolonSwitch, GroupNode> accessSwitchGroupNode = new HashMap<HolonSwitch, GroupNode>();
|
|
|
private ArrayList<Edge> edgeList = new ArrayList<Edge>();
|
|
|
|
|
|
-
|
|
|
boolean algoUseElements = false, algoUseSwitches = true, algoUseFlexes = true;
|
|
|
|
|
|
//time
|
|
@@ -196,6 +195,12 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
|
|
|
|
|
|
JButton runButton = new JButton("Run");
|
|
|
runButton.addActionListener(actionEvent -> {
|
|
|
+ if(runThread.isAlive()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ reset();
|
|
|
+ this.resetAllList();
|
|
|
+ resetChain.clear();
|
|
|
Runnable task = () -> run();
|
|
|
runThread = new Thread(task);
|
|
|
runThread.start();
|
|
@@ -461,55 +466,26 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
|
|
|
}
|
|
|
|
|
|
private double evaluateNetwork() {
|
|
|
-
|
|
|
- // Not possible due exponentiak growing
|
|
|
-// double times = Math.pow(2, switchList.size());
|
|
|
-// double sum = 0;
|
|
|
-// for(int i = 0; i < times; i++) {
|
|
|
-// int positionInBitString = 0;
|
|
|
-// for(HolonSwitch hSwitch: switchList) {
|
|
|
-// boolean result = ((i >> positionInBitString++) & 1) != 0;
|
|
|
-// hSwitch.setManualState(result);
|
|
|
-// }
|
|
|
-// sum += evaluateNetwork() / times;
|
|
|
-// }
|
|
|
runProgressbar.step();
|
|
|
- //random solution
|
|
|
-// double sum = 0;
|
|
|
-// double step = 0.1;
|
|
|
-// int steppsDone = 0;
|
|
|
-// for(double actual = 0; actual <= 1 ; actual += step) {
|
|
|
-// for(HolonSwitch hSwitch: switchList) {
|
|
|
-// hSwitch.setManualMode(true);
|
|
|
-// hSwitch.setManualState(Random.nextDouble() < actual);
|
|
|
-// }
|
|
|
-// control.calculateStateOnlyForCurrentTimeStep();
|
|
|
-// DecoratedState actualstate = control.getSimManager().getActualDecorState();
|
|
|
-// sum += evaluateState(actualstate);
|
|
|
-// steppsDone++;
|
|
|
-// }
|
|
|
- //return sum /(double) steppsDone;
|
|
|
-
|
|
|
- double sum = 0;
|
|
|
- for(HolonSwitch hSwitch: switchList) {
|
|
|
- hSwitch.setManualMode(true);
|
|
|
- hSwitch.setManualState(true);
|
|
|
- }
|
|
|
- control.calculateStateOnlyForCurrentTimeStep();
|
|
|
- DecoratedState actualstate = control.getSimManager().getActualDecorState();
|
|
|
- sum += evaluateState(actualstate);
|
|
|
for(HolonSwitch hSwitch: switchList) {
|
|
|
hSwitch.setManualMode(true);
|
|
|
hSwitch.setManualState(false);
|
|
|
}
|
|
|
control.calculateStateOnlyForCurrentTimeStep();
|
|
|
- actualstate = control.getSimManager().getActualDecorState();
|
|
|
- sum += evaluateState(actualstate);
|
|
|
- return sum / 2.0;
|
|
|
+ DecoratedState actualstate = control.getSimManager().getActualDecorState();
|
|
|
+ return evaluateState(actualstate, calculateAmountOfAddedSwitches(), addedCableMeter(), false);
|
|
|
}
|
|
|
|
|
|
|
|
|
- protected abstract double evaluateState(DecoratedState actualstate);
|
|
|
+ private double addedCableMeter() {
|
|
|
+ return addedIndexCable.values().stream().reduce(0.0, Double::sum);
|
|
|
+ }
|
|
|
+
|
|
|
+ private int calculateAmountOfAddedSwitches() {
|
|
|
+ return (int)this.switchList.stream().filter(sw -> sw.getName().contains("AddedSwitch")).count();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected abstract double evaluateState(DecoratedState actualstate, int amountOfAddedSwitch, double addedCableMeter, boolean moreInfromation);
|
|
|
|
|
|
|
|
|
private void run() {
|
|
@@ -662,21 +638,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
|
|
|
if(!resetChain.isEmpty()) {
|
|
|
setState(resetChain.removeLast());
|
|
|
}
|
|
|
- //-->reset
|
|
|
- accessWildcards.clear();
|
|
|
- this.countForAccessMap = 0;
|
|
|
- amountOfExistingCables = 0;
|
|
|
- accessIntToObject.clear();
|
|
|
- accessObjectToInt.clear();
|
|
|
- cableSet.clear();
|
|
|
- cableList.clear();
|
|
|
- accessGroupNode.clear();
|
|
|
- accessIntegerToWildcard.clear();
|
|
|
- addedIndexCable.clear();
|
|
|
- switchList.clear();
|
|
|
- accessSwitchGroupNode.clear();
|
|
|
- edgeList.clear();
|
|
|
- //<---
|
|
|
+ resetAllList();
|
|
|
}
|
|
|
|
|
|
|
|
@@ -712,21 +674,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
|
|
|
protected List<Integer> extractPositionAndAccess() {
|
|
|
Model model = control.getModel();
|
|
|
|
|
|
- //-->reset
|
|
|
- accessWildcards.clear();
|
|
|
- this.countForAccessMap = 0;
|
|
|
- amountOfExistingCables = 0;
|
|
|
- accessIntToObject.clear();
|
|
|
- accessObjectToInt.clear();
|
|
|
- cableSet.clear();
|
|
|
- cableList.clear();
|
|
|
- accessGroupNode.clear();
|
|
|
- accessIntegerToWildcard.clear();
|
|
|
- addedIndexCable.clear();
|
|
|
- switchList.clear();
|
|
|
- accessSwitchGroupNode.clear();
|
|
|
- edgeList.clear();
|
|
|
- //<---
|
|
|
+ resetAllList();
|
|
|
Category category = control.searchCategory("Wildcards");
|
|
|
if(category != null) {
|
|
|
for(int count = 0; count < category.getObjects().size(); count++ ) {
|
|
@@ -763,6 +711,29 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
|
|
|
//console.println(cableSet.stream().map(Object::toString).collect(Collectors.f(", ")));
|
|
|
return initialState;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void resetAllList() {
|
|
|
+ //-->reset
|
|
|
+ accessWildcards.clear();
|
|
|
+ this.countForAccessMap = 0;
|
|
|
+ amountOfExistingCables = 0;
|
|
|
+ accessIntToObject.clear();
|
|
|
+ accessObjectToInt.clear();
|
|
|
+ cableSet.clear();
|
|
|
+ cableList.clear();
|
|
|
+ accessGroupNode.clear();
|
|
|
+ accessIntegerToWildcard.clear();
|
|
|
+ addedIndexCable.clear();
|
|
|
+ switchList.clear();
|
|
|
+ accessSwitchGroupNode.clear();
|
|
|
+ edgeList.clear();
|
|
|
+ //<---
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
@@ -779,7 +750,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
|
|
|
HolonObject hO = (HolonObject) aCps;
|
|
|
accessIntToObject.put(++countForAccessMap, hO);
|
|
|
accessObjectToInt.put(hO, countForAccessMap);
|
|
|
- if(hO.getName().equals("Wildcard")) {
|
|
|
+ if(hO.getName().contains("Wildcard")) {
|
|
|
accessWildcards.add(new AccessWrapper(hO));
|
|
|
}
|
|
|
if(groupnode != null) {
|
|
@@ -848,11 +819,11 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
|
|
|
}
|
|
|
IndexCable cable = new IndexCable(index0, index1);
|
|
|
//if cable is in existing cables
|
|
|
- if(cableSet.contains(cable) || addedIndexCable.contains(cable)) {
|
|
|
+ if(cableSet.contains(cable) || addedIndexCable.values().contains(cable)) {
|
|
|
return;
|
|
|
}
|
|
|
generateEdgeFromIndexCable(cable, switchBetween);
|
|
|
- addedIndexCable.add(cable);
|
|
|
+ addedIndexCable.put(cable, cable.getLength());
|
|
|
}
|
|
|
|
|
|
private void generateEdgeFromIndexCable(IndexCable cable, boolean switchBetween){
|
|
@@ -1109,7 +1080,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * A Wrapper Class for Access HolonElement and HolonSwitch in one Element and not have to split the List.
|
|
|
+ * A Wrapper Class to access wildcards
|
|
|
*/
|
|
|
private class AccessWrapper {
|
|
|
int state = 0;
|
|
@@ -1121,19 +1092,29 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
|
|
|
public void setState(int state) {
|
|
|
if(this.state != state) {
|
|
|
this.state = state;
|
|
|
- wildcard.getElements().clear();
|
|
|
if(state > 0) {
|
|
|
+ wildcard.getElements().clear();
|
|
|
HolonObject hO = (HolonObject)accessIntegerToWildcard.get(state);
|
|
|
if(hO == null) {
|
|
|
console.println("null set state(" + state + ")");
|
|
|
}else {
|
|
|
- wildcard.getElements().addAll(hO.getElements());
|
|
|
+ if(hO.getName().contains(":")) {
|
|
|
+ wildcard.setName("Wildcard" + hO.getName().substring(hO.getName().lastIndexOf(":")));
|
|
|
+ }else {
|
|
|
+ wildcard.setName("Wildcard");
|
|
|
+ }
|
|
|
+ wildcard.getElements().addAll(hO.getElements());
|
|
|
+ wildcard.setImage(hO.getImage());
|
|
|
}
|
|
|
+ }else {
|
|
|
+ resetState();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
public void resetState() {
|
|
|
state = 0;
|
|
|
+ wildcard.setName("Wildcard");
|
|
|
+ wildcard.setImage("/Images/home-2.png");
|
|
|
wildcard.getElements().clear();
|
|
|
}
|
|
|
|
|
@@ -1313,5 +1294,8 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
|
|
|
public String toString() {
|
|
|
return "{" + first + "," + second + "}";
|
|
|
}
|
|
|
+ public double getLength() {
|
|
|
+ return accessIntToObject.get(first).getPosition().Distance(accessIntToObject.get(second).getPosition());
|
|
|
+ }
|
|
|
}
|
|
|
}
|