Browse Source

Improved Topologie

Still lots of bugs.
Tom Troppmann 3 years ago
parent
commit
b6adbb4ce6

+ 4 - 4
src/algorithm/objectiveFunction/TopologieObjectiveFunction.java

@@ -173,10 +173,10 @@ public class TopologieObjectiveFunction {
 		//System.out.println("f_grid:" + f_grid);
 		
 		
-		System.out.print(" f_eb(" + w_eb * squash(f_eb, k_eb) + ") ");
-		System.out.print(" f_holon(" + w_holon * squash(f_holon, k_holon)  + ") ");
-		System.out.print(" f_selection(" + w_selection * squash(f_selection, k_selection)  + ") ");
-		System.out.println(" f_grid(" + w_grid * f_grid + ") ");
+//		System.out.print(" f_eb(" + w_eb * squash(f_eb, k_eb) + ") ");
+//		System.out.print(" f_holon(" + w_holon * squash(f_holon, k_holon)  + ") ");
+//		System.out.print(" f_selection(" + w_selection * squash(f_selection, k_selection)  + ") ");
+//		System.out.println(" f_grid(" + w_grid * f_grid + ") ");
 		
 		/**
 		 * F_grid is already squashed

+ 1 - 1
src/algorithm/topologie/GaAlgorithm.java

@@ -88,7 +88,7 @@ public class GaAlgorithm extends TopologieAlgorithmFramework {
 
 	@Override
 	protected int getProgressBarMaxCount() {
-		return 0;
+		return rounds * maxGenerations * popsize + 1;
 	}
 
 	@Override

+ 23 - 7
src/api/TopologieAlgorithmFramework.java

@@ -49,6 +49,8 @@ import classes.Flexibility;
 import classes.HolonElement;
 import classes.HolonObject;
 import classes.HolonSwitch;
+import classes.IdCounterElem;
+import classes.Node;
 import classes.HolonElement.Priority;
 import ui.controller.Control;
 import ui.controller.FlexManager.FlexState;
@@ -451,7 +453,6 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 	
 	
 	protected double evaluatePosition(List<Integer> positionToEvaluate) {
-		runProgressbar.step();
 		control.getSimManager().resetFlexManagerForTimeStep(control.getModel().getCurIteration());
 		
 		setState(positionToEvaluate); // execution time critical
@@ -472,8 +473,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 //			}	
 //			sum += evaluateNetwork() / times;
 //		}
-		
-		System.out.println("-->");
+		runProgressbar.step();
 		double sum = 0;
 		double step = 0.1;
 		int steppsDone = 0;
@@ -487,7 +487,6 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 			sum += evaluateState(actualstate);
 			steppsDone++;
 		}
-		System.out.println("<--");
 		
 		return sum /(double) steppsDone;
 	}
@@ -751,6 +750,22 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 					accessGroupNode.put(hO, groupnode);
 				}
 			}
+			if(aCps instanceof HolonSwitch) {
+				HolonSwitch hSwitch = (HolonSwitch) aCps;
+				accessIntToObject.put(++countForAccessMap, hSwitch);
+				accessObjectToInt.put(hSwitch, countForAccessMap);
+				if(groupnode != null) {
+					accessGroupNode.put(hSwitch, groupnode);
+				}
+			}
+			if(aCps instanceof Node) {
+				Node node = (Node) aCps;
+				accessIntToObject.put(++countForAccessMap, node);
+				accessObjectToInt.put(node, countForAccessMap);
+				if(groupnode != null) {
+					accessGroupNode.put(node, groupnode);
+				}
+			}
 			else if(aCps instanceof GroupNode) {
 				generateAccess(((GroupNode)aCps).getNodes(), (GroupNode) aCps);
 			}
@@ -772,10 +787,10 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 			edgeList.add(edge);
 			//console.println("Cable from " + edge.getA().getName() + " to " + edge.getB().getName());
 			if(!accessObjectToInt.containsKey(edge.getA())) {
-				console.println("Node A from Edge[" + edge + "] not exist");
+				console.println("Node A [" + edge.getA() + "] from Edge[" + edge + "] not exist");
 				continue;
 			} else if (!accessObjectToInt.containsKey(edge.getB())) {
-				console.println("Node B from Edge[" + edge + "] not exist");
+				console.println("Node B [" + edge.getB() + "]from Edge[" + edge + "] not exist");
 				continue;
 			}
 			IndexCable cable = new IndexCable(accessObjectToInt.get(edge.getA()), accessObjectToInt.get(edge.getB()));
@@ -812,6 +827,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 			int middleX = (fromObject.getPosition().x +   toObject.getPosition().x)/2;
 			int middleY = (fromObject.getPosition().y +   toObject.getPosition().y)/2;
 			HolonSwitch newSwitch = new HolonSwitch("AddedSwitch");
+			newSwitch.setId(IdCounterElem.nextId());
 			newSwitch.setPosition(middleX, middleY);
 			//If fromObject is in Group
 			if(accessGroupNode.containsKey(fromObject)) {
@@ -823,7 +839,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 				groupnode.getNodes().add(newSwitch);
 				accessSwitchGroupNode.put(newSwitch, groupnode);
 			}else {
-				control.getModel().getObjectsOnCanvas().add(newSwitch);				
+				control.getModel().getObjectsOnCanvas().add(newSwitch);		
 			}
 			//else if toObject is in Group
 			this.switchList.add(newSwitch);

+ 0 - 5
src/classes/Edge.java

@@ -60,9 +60,6 @@ public class Edge {
         if(a == null) {
         	System.out.println("B == NULL");
         }
-        
-        this.a.addConnection(this);
-        this.b.addConnection(this);
         this.maxCapacity = 100;
         pseudoTags = new ArrayList<>();
     }
@@ -77,8 +74,6 @@ public class Edge {
     public Edge(AbstractCanvasObject a, AbstractCanvasObject b, float maxCap) {
         setA(a);
         setB(b);
-        this.a.addConnection(this);
-        this.b.addConnection(this);
         this.maxCapacity = maxCap;
         pseudoTags = new ArrayList<>();
     }

+ 3 - 1
src/ui/controller/MultiPurposeController.java

@@ -164,7 +164,9 @@ public class MultiPurposeController {
 	 *            the Map
 	 */
 	public <T> void decIdx(T key, HashMap<T, Integer> map) {
-
+		if(!map.containsKey(key)) {
+			return;
+		}
 		for (Entry<T, Integer> i : map.entrySet()) {
 			if (i.getValue() > map.get(key))
 				i.setValue(i.getValue() - 1);