소스 검색

Pseudocode funktioniert bei Conflict Detection

Kolja Strohm 6 년 전
부모
커밋
45029ec3e3
2개의 변경된 파일140개의 추가작업 그리고 34개의 파일을 삭제
  1. 4 6
      src/animation/AnimatedAlgorithm.java
  2. 136 28
      src/bk/ConflictDetection.java

+ 4 - 6
src/animation/AnimatedAlgorithm.java

@@ -44,31 +44,29 @@ public abstract class AnimatedAlgorithm extends Thread implements AlgorithmStage
                 switch( ac.getNextAction() )
                 {
                 case FORWARD:
-                    forwardStep();
+                    if( forwardStep() == StageStatus.FINISHED )
+                        ac.setContinuous( false );
                     update();
                     break;
                 case FORWARD_OUT:
                     forwardStepOut();
-                    graph.unselectGraph();
                     update();
                     break;
                 case FORWARD_OVER:
                     forwardStepOver();
-                    graph.unselectGraph();
                     update();
                     break;
                 case BACKWARD:
-                    backwardStep();
+                    if( backwardStep() == StageStatus.FINISHED )
+                        ac.setContinuous( false );
                     update();
                     break;
                 case BACKWARD_OUT:
                     backwardStepOut();
-                    graph.unselectGraph();
                     update();
                     break;
                 case BACKWARD_OVER:
                     backwardStepOver();
-                    graph.unselectGraph();
                     update();
                     break;
                 default:

+ 136 - 28
src/bk/ConflictDetection.java

@@ -1,6 +1,5 @@
 package bk;
 
-import java.util.ArrayList;
 import java.util.Stack;
 
 import javax.swing.JTree;
@@ -9,7 +8,6 @@ import animation.AlgorithmStage;
 import animation.BackwardAction;
 import animation.PseudoCodeNode;
 import animation.PseudoCodeNode.CodeAction;
-import bk.ExtremalLayoutCalc.LayoutType;
 import graph.LayeredGraphEdge;
 import graph.LayeredGraphNode;
 import lib.TextLayoutHelper;
@@ -36,7 +34,9 @@ public class ConflictDetection implements AlgorithmStage {
      * line number in Carstens' pseudocode listing 3.1
      */
     private int pseudo_line;
-    private PseudoCodeNode markNode;
+    private PseudoCodeNode lines[];
+    private boolean breakPoint;
+    private boolean skip;
 
     public ConflictDetection(LayeredGraphNode graph) {
         this.graph = graph;
@@ -49,6 +49,8 @@ public class ConflictDetection implements AlgorithmStage {
         k = 0;
         hidden_k = 0;
         pseudo_line = 1;
+        breakPoint = false;
+        skip = false;
     }
 
 
@@ -73,6 +75,11 @@ public class ConflictDetection implements AlgorithmStage {
             if (i <= graph.getContainedLayers().size() - 2) {
                 pseudo_line++;
             } else {
+                for( PseudoCodeNode p : lines )
+                {
+                    if( p != null )
+                        p.setSelected( false );
+                }
                 return StageStatus.FINISHED;
             }
             break;
@@ -208,7 +215,10 @@ public class ConflictDetection implements AlgorithmStage {
         }
 
         selectNodes(pseudo_line);
-
+        if( breakPoint )
+            return StageStatus.BREAKPOINT;
+        if( skip )
+            return forwardStep();
         return StageStatus.UNFINISHED;
     }
 
@@ -232,62 +242,160 @@ public class ConflictDetection implements AlgorithmStage {
         if (next_line == 10 || next_line == 11) {
             graph.getContainedLayers().get(i).get(k).setSelected(null);
         }
+        breakPoint = false;
+        skip = false;
+        for( PseudoCodeNode p : lines )
+        {
+            if( p != null )
+                p.setSelected( false );
+        }
+        markCode( lines[ next_line - 1 ] );
+    }
+    
+    private int getCodeDepth( PseudoCodeNode n )
+    {
+        if( n == lines[ 0 ] )
+            return 0;
+        return 1 + getCodeDepth( (PseudoCodeNode)n.getParent() );
+    }
+    
+    private void markCode( PseudoCodeNode n )
+    {
+        if( !n.hasSelectedSubnode() )
+        {
+            CodeAction action = n.setSelected( true );
+            breakPoint |= action == CodeAction.STOP;
+            skip |= action == CodeAction.SKIP;
+        }
+        else
+        {
+            CodeAction action = n.setSelected( true );
+            skip |= action == CodeAction.SKIP;
+        }
+        if( n == lines[ 0 ] )
+            return;
+        markCode( (PseudoCodeNode)n.getParent() );
     }
 
     @Override
     public StageStatus backwardStep() {
-        ((PseudoCodeNode) markNode.getParent()).setSelected(true);
-        CodeAction action = markNode.setSelected(true);
-        boolean breakPoint = action == CodeAction.STOP;
         if (actions.size() == 0) {
-            ((PseudoCodeNode) markNode.getParent()).setSelected(false);
-            markNode.setSelected(false);
+            for( PseudoCodeNode p : lines )
+            {
+                if( p != null )
+                    p.setSelected( false );
+            }
             return StageStatus.FINISHED;
         }
         actions.pop().reverse();
-        if (breakPoint)
+        if( breakPoint )
             return StageStatus.BREAKPOINT;
-        if (action == CodeAction.SKIP)
-            return backwardStep();
+        if( skip )
+            return forwardStep();
         return StageStatus.UNFINISHED;
     }
 
     @Override
     public PseudoCodeNode createPseudocodeTree(JTree tree) {
         PseudoCodeNode root = new PseudoCodeNode("Preprocessing (mark type 1 conflicts)", tree);
-        PseudoCodeNode loopNode = new PseudoCodeNode("Loop through all nodes...", tree);
-        markNode = new PseudoCodeNode(
-                "If non-inner segment crosses an inner segment whose target is this node, mark the non-inner segment as conflicted",
-                tree);
-        loopNode.add(markNode);
-        root.add(loopNode);
+        lines = new PseudoCodeNode[15];
+        lines[ 0 ] = new PseudoCodeNode( "for i=1 to |L|-2 do", tree );
+        lines[ 1 ] = new PseudoCodeNode( "k0 = 0; l = 0;", tree );
+        lines[ 0 ].add( lines[ 1 ] );
+        lines[ 2 ] = new PseudoCodeNode( "for l1=0 to |L[i+1]|-1 do", tree );
+        lines[ 0 ].add( lines[ 2 ] );
+        lines[ 3 ] = new PseudoCodeNode( "if l1==|L[i+1]|-1 or L[i+1][l1] incident to inner segment between L[i+1] and L[i] then", tree );
+        lines[ 2 ].add( lines[ 3 ] );
+        lines[ 4 ] = new PseudoCodeNode( "k1 = |Li|-1;", tree );
+        lines[ 3 ].add( lines[ 4 ] );
+        lines[ 5 ] = new PseudoCodeNode( "if L[i+1][l1] incident to inner segment between L[i+1] and L[i] then", tree );
+        lines[ 3 ].add( lines[ 5 ] );
+        lines[ 6 ] = new PseudoCodeNode( "k1 = pos(pred(L[i+1][l1])[0]);", tree );
+        lines[ 5 ].add( lines[ 6 ] );
+        lines[ 8 ] = new PseudoCodeNode( "while l <= l1 do", tree );
+        lines[ 3 ].add( lines[ 8 ] );
+        lines[ 9 ] = new PseudoCodeNode( "foreach v in pred(L[i+1][l]) do", tree );
+        lines[ 8 ].add( lines[ 9 ] );
+        lines[ 10 ] = new PseudoCodeNode( "if k < k0 or k > k1 then mark segment (v,L[i+1][l]);", tree );
+        lines[ 9 ].add( lines[ 10 ] );
+        lines[ 12 ] = new PseudoCodeNode( "l = l+1;", tree );
+        lines[ 8 ].add( lines[ 12 ] );
+        lines[ 14 ] = new PseudoCodeNode( "k0 = k1;", tree );
+        lines[ 3 ].add( lines[ 14 ] );
+        root.add( lines[ 0 ] );
         return root;
     }
 
     @Override
     public StageStatus forwardStepOver() {
-        return forwardStep();
+        int depth = getCodeDepth( lines[ pseudo_line - 1 ] );
+        do
+        {
+            switch( forwardStep() )
+            {
+            case BREAKPOINT:
+                return StageStatus.BREAKPOINT;
+            case FINISHED:
+                return StageStatus.FINISHED;
+            case UNFINISHED:
+                break;
+            }
+        } while( depth < getCodeDepth( lines[ pseudo_line - 1 ] ) );
+        return StageStatus.UNFINISHED;
     }
 
     @Override
     public StageStatus forwardStepOut() {
-        StageStatus status = StageStatus.UNFINISHED;
-        while (status == StageStatus.UNFINISHED)
-            status = forwardStep();
-        return status;
+        int depth = getCodeDepth( lines[ pseudo_line - 1 ] );
+        do
+        {
+            switch( forwardStep() )
+            {
+            case BREAKPOINT:
+                return StageStatus.BREAKPOINT;
+            case FINISHED:
+                return StageStatus.FINISHED;
+            case UNFINISHED:
+                break;
+            }
+        } while( depth <= getCodeDepth( lines[ pseudo_line - 1 ] ) );
+        return StageStatus.UNFINISHED;
     }
 
     @Override
     public StageStatus backwardStepOver() {
-        return backwardStep();
+        int depth = getCodeDepth( lines[ pseudo_line - 1 ] );
+        do
+        {
+            switch( backwardStep() )
+            {
+            case BREAKPOINT:
+                return StageStatus.BREAKPOINT;
+            case FINISHED:
+                return StageStatus.FINISHED;
+            case UNFINISHED:
+                break;
+            }
+        } while( depth < getCodeDepth( lines[ pseudo_line - 1 ] ) );
+        return StageStatus.UNFINISHED;
     }
 
     @Override
     public StageStatus backwardStepOut() {
-        StageStatus status = StageStatus.UNFINISHED;
-        while (status == StageStatus.UNFINISHED)
-            status = backwardStep();
-        return status;
+        int depth = getCodeDepth( lines[ pseudo_line - 1 ] );
+        do
+        {
+            switch( backwardStep() )
+            {
+            case BREAKPOINT:
+                return StageStatus.BREAKPOINT;
+            case FINISHED:
+                return StageStatus.FINISHED;
+            case UNFINISHED:
+                break;
+            }
+        } while( depth <= getCodeDepth( lines[ pseudo_line - 1 ] ) );
+        return StageStatus.UNFINISHED;
     }
 
     @Override