Pārlūkot izejas kodu

conflictdetection is running

Eren Yilmaz 6 gadi atpakaļ
vecāks
revīzija
b8760943d0
1 mainītis faili ar 46 papildinājumiem un 73 dzēšanām
  1. 46 73
      src/bk/ConflictDetection.java

+ 46 - 73
src/bk/ConflictDetection.java

@@ -52,32 +52,43 @@ public class ConflictDetection implements AlgorithmStage {
     // TODO: knoten highlighten
     // TODO: rekursion auf subgraphen
     // TODO: backwards actions
+    // TODO: work with breakpoints
     @Override
     public StageStatus forwardStep() {
-        // the line numbers are from Carstens
+        int old_line = pseudo_line;
+        
         switch (pseudo_line) {
         case 1:
             i += 1;
-            pseudo_line += 1;
+            if (i <= graph.getContainedLayers().size() - 2) {
+                pseudo_line += 1;
+            } else {
+                return StageStatus.FINISHED;
+            }
             break;
         case 2:
             k0 = 0;
             l = 0;
+            l1 = -1; // will be increased before first iteration
             pseudo_line += 1;
             break;
         case 3:
             l1 += 1;
-            pseudo_line += 1;
+            if (l1 < graph.getContainedLayers().get(i + 1).size()) {
+                pseudo_line += 1;
+            } else {
+                pseudo_line = 1;
+            }
             break;
         case 4:
             if (graph.getContainedLayers().get(i + 1).size() == l1 || incidentToInnerSegmentBetweenLiPlusOneAndLi()) {
                 pseudo_line += 1;
             } else {
-                pseudo_line = 3; // yes, that's a goto
+                pseudo_line = 3;
             }
             break;
         case 5:
-            k1 = graph.getContainedLayers().get(i + 1).size() - 1;
+            k1 = graph.getContainedLayers().get(i).size() - 1;
             pseudo_line += 1;
             break;
         case 6:
@@ -90,6 +101,7 @@ public class ConflictDetection implements AlgorithmStage {
         case 7:
             k1 = graph.getContainedLayers().get(i).indexOf(
                     graph.getContainedLayers().get(i + 1).get(l1).getSortedIncomingEdges().get(0).getSources().get(0));
+            pseudo_line = 9;
             break;
         case 9:
             if (l <= l1) {
@@ -97,12 +109,12 @@ public class ConflictDetection implements AlgorithmStage {
                 // initialize the for loop o next line
                 hidden_k -= 1; // because it will be increased next line
             } else {
-                pseudo_line = 15; // yes, that's a goto
+                pseudo_line = 15;
             }
             break;
         case 10:
             hidden_k += 1;
-            if (graph.getContainedLayers().get(i + 1).get(l).getSortedIncomingEdges().size() < hidden_k) {
+            if (hidden_k < graph.getContainedLayers().get(i + 1).get(l).getSortedIncomingEdges().size()) {
                 k = graph.getContainedLayers().get(i).indexOf(graph.getContainedLayers().get(i + 1).get(l)
                         .getSortedIncomingEdges().get(hidden_k).getSources().get(0));
                 pseudo_line += 1;
@@ -118,77 +130,38 @@ public class ConflictDetection implements AlgorithmStage {
             }
             pseudo_line = 10;
             break;
+        case 13:
+            l += 1;
+            pseudo_line = 9; 
+            break;
+        case 15:
+            k0 = k1;
+            pseudo_line = 3; 
+            break;
         }
-
-        int oldI = i;
-        int oldL1 = l1;
-        ((PseudoCodeNode) markNode.getParent()).setSelected(true);
-        CodeAction action = markNode.setSelected(true);
-        boolean breakPoint = action == CodeAction.STOP;
-
-        // last layer? finished?
-        if (i + 1 >= graph.getContainedLayers().size() - 1) {
-            ((PseudoCodeNode) markNode.getParent()).setSelected(false);
-            markNode.setSelected(false);
-            return StageStatus.FINISHED;
+        
+        if (old_line >= 2) {
+            graph.getContainedLayers().get(i+1).get(l).setSelected(null);
         }
-
-        LayeredGraphNode curr = graph.getContainedLayers().get(i + 1).get(l1);
-        curr.setSelected(null);
-        ArrayList<LayeredGraphEdge> edges = curr.getIncomingEdges();
-        LayeredGraphEdge dummyEdge = null;
-        for (LayeredGraphEdge e : edges) {
-            if (e.isDummyEdge()) {
-                dummyEdge = e;
-                break;
-            }
+        
+        if (old_line >= 3) {
+            graph.getContainedLayers().get(i+1).get(l1).setSelected(null);
         }
-
-        ArrayList<LayeredGraphEdge> conflicts = new ArrayList<>();
-        if (dummyEdge != null) {
-            for (LayeredGraphEdge e : edges) {
-                if (e.isDummyEdge()) {
-                    ArrayList<LayeredGraphEdge> conf = e.calcEdgeCrossings();
-                    for (LayeredGraphEdge ce : conf) {
-                        if (!ce.isDummyEdge())
-                            conflicts.add(ce);
-                    }
-                }
-            }
+        
+        if (old_line >= 2) {
+            graph.getContainedLayers().get(i).get(k0).setSelected(null);
         }
-        for (LayeredGraphEdge c : conflicts)
-            c.setConflicted(true, null);
-        StageStatus status = calcNextStatus();
-        actions.add(0, () -> {
-            i = oldI;
-            l1 = oldL1;
-            if (i + 1 < graph.getContainedLayers().size() - 1 && l1 > 0) {
-                LayeredGraphNode layde = graph.getContainedLayers().get(i + 1).get(l1 - 1);
-                layde.setSelected(null);
-            }
-            for (LayeredGraphEdge c : conflicts)
-                c.setConflicted(false, null);
-        });
-        if (status != StageStatus.FINISHED && breakPoint)
-            return StageStatus.BREAKPOINT;
-        if (action == CodeAction.SKIP && status != StageStatus.FINISHED)
-            return forwardStep();
-        return status;
-    }
-
-    private StageStatus calcNextStatus() {
-        l1++;
-        if (l1 >= graph.getContainedLayers().get(i + 1).size()) {
-            i++;
-            if (i >= graph.getContainedLayers().size() - 2) {
-                i--;
-                l1--;
-                ((PseudoCodeNode) markNode.getParent()).setSelected(false);
-                markNode.setSelected(false);
-                return StageStatus.FINISHED;
-            }
-            l1 = 0;
+        
+        if (old_line >= 5) {
+            graph.getContainedLayers().get(i).get(k1).setSelected(null);
+        }
+        
+        if ((pseudo_line == 10 && old_line == 11) || pseudo_line == 11) {
+            graph.getContainedLayers().get(i).get(k).setSelected(null);
         }
+        
+        System.out.println("going from line " + old_line +" to " + pseudo_line);
+        
         return StageStatus.UNFINISHED;
     }