Browse Source

Fixed a Bug that crashed the TopologieOptimizationEvaluation Function.

Troppmann, Tom 3 years ago
parent
commit
97718916f1

+ 24 - 6
src/algorithm/objectiveFunction/GraphMetrics.java

@@ -1,6 +1,7 @@
 package algorithm.objectiveFunction;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedList;
@@ -26,6 +27,9 @@ public class GraphMetrics {
 		public Vertex(int id){
 			this.id = id;
 		}
+		public String toString() {
+			return "" + id;
+		}
 	}
 	private static class Edge{
 		public int idA, idB;
@@ -42,6 +46,12 @@ public class GraphMetrics {
 		Edge[] E;
 		/**Only the Sources/Trains for disjoint Path no Switch or Node**/
 		Vertex[] S;
+		
+		public String toString() {
+			String vList = "V" + Arrays.toString(V);
+			String sList = "S" + Arrays.toString(S);
+			return vList + ", " + sList;
+		}
 	}
 	
 	
@@ -57,20 +67,24 @@ public class GraphMetrics {
 		List<Integer> sourcesList = new ArrayList<Integer>();
 		int count = 0;
 		for(Consumer con: net.getConsumerList()) {
-			objectToId.put(con.getModel(), count++);
+			objectToId.put(con.getModel(), count);
 			sourcesList.add(count);
+			count++;
 		}
 		for(Consumer con: net.getConsumerSelfSuppliedList()) {
-			objectToId.put(con.getModel(), count++);
+			objectToId.put(con.getModel(), count);
 			sourcesList.add(count);
+			count++;
 		}
 		for(Passiv pas: net.getPassivNoEnergyList()) {
-			objectToId.put(pas.getModel(), count++);
+			objectToId.put(pas.getModel(), count);
 			sourcesList.add(count);
+			count++;
 		}
 		for(Supplier sup: net.getSupplierList()) {
-			objectToId.put(sup.getModel(), count++);
+			objectToId.put(sup.getModel(), count);
 			sourcesList.add(count);
+			count++;
 		}
 		
 		
@@ -159,7 +173,7 @@ public class GraphMetrics {
 		 G.S[1] = new Vertex(1);
 		 G.S[2] = new Vertex(2);
 		 G.S[3] = new Vertex(3);
-
+		 System.out.println(G);
 		 System.out.println("minimumCut: " + minimumCut(G.V, G.E));
 		 System.out.println("AvgShortestDistance " + averageShortestDistance(G));
 		 System.out.println("DisjointPath " + averageEdgeDisjointPathProblem(G));
@@ -372,7 +386,11 @@ public class GraphMetrics {
 		 double sum = 0.0;
 		 for(int s = 0; s < G.S.length; s++) {
 			 for(int t = s; t < G.S.length; t++) {
-				 sum += D[G.S[s].id][G.S[t].id];					 
+				 try {
+					 sum += D[G.S[s].id][G.S[t].id];					 
+				 }catch(java.lang.ArrayIndexOutOfBoundsException E) {
+					 System.out.println(G);
+				 }
 			 }
 		 }
 		 //Returns the Average

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

@@ -178,7 +178,7 @@ public class TopologieObjectiveFunction {
 		for(DecoratedNetwork net: state.getNetworkList()) {
 			Graph G = GraphMetrics.convertDecoratedNetworkToGraph(net);
 			//We have to penalize single Networks;
-			if(G.V.length <= 1) {
+			if(G.V.length <= 1 || G.S.length <= 1) {
 				f_grid += lambda_avg_shortest_path + lambda_disjoint_path;
 				continue;
 			}

+ 0 - 19
src/ui/view/GUI.java

@@ -523,25 +523,6 @@ public class GUI implements CategoryListener {
 					Edge edgeHighlight = model.getSelectedEdge();
 					if (edgeHighlight != null) {
 						controller.removeEdgesOnCanvas(edgeHighlight);
-						// Look for a CPSNode with no Connections and delete
-						// them
-						if (edgeHighlight.getA().getClass() == Node.class
-								&& edgeHighlight.getA().getConnections().size() == 0) {
-							controller.delCanvasObject(edgeHighlight.getA(),
-									false);
-						}
-						if (edgeHighlight.getB().getClass() == Node.class
-								&& edgeHighlight.getB().getConnections().size() == 0) { // Look
-																						// on
-																						// the
-																						// other
-																						// end
-																						// of
-																						// the
-																						// cable
-							controller.delCanvasObject(edgeHighlight.getB(),
-									false);
-						}
 						((MyCanvas) canvasOrUpperNodeCanvas).edgeHighlight = null;
 					}
 					for (int j = 0; j < model.getSelectedCpsObjects().size(); j++) {