Bladeren bron

Merge remote-tracking branch 'origin/master'

Eren Yilmaz 6 jaren geleden
bovenliggende
commit
dd5ba07c87

+ 68 - 68
papergraph.json

@@ -5,74 +5,74 @@
             {"name":"2"}
         ],
         [
-            {"name":"d1"},
-            {"name":"d2"},
-            {"name":"d3"},
+            {"name":"d1", "dummy":"true"},
+            {"name":"d2", "dummy":"true"},
+            {"name":"d3", "dummy":"true"},
             {"name":"3"},
-            {"name":"d4"}
+            {"name":"d4", "dummy":"true"}
         ],
         [
-            {"name":"d5"},
-            {"name":"d6"},
+            {"name":"d5", "dummy":"true"},
+            {"name":"d6", "dummy":"true"},
             {"name":"4"},
             {"name":"5"},
-            {"name":"d7"},
-            {"name":"d8"}
+            {"name":"d7", "dummy":"true"},
+            {"name":"d8", "dummy":"true"}
         ],
         [
-            {"name":"d9"},
-            {"name":"d10"},
+            {"name":"d9", "dummy":"true"},
+            {"name":"d10", "dummy":"true"},
             {"name":"6"},
             {"name":"7"},
-            {"name":"d11"},
-            {"name":"d12"}
+            {"name":"d11", "dummy":"true"},
+            {"name":"d12", "dummy":"true"}
         ],
         [
-            {"name":"d13"},
-            {"name":"d14"},
+            {"name":"d13", "dummy":"true"},
+            {"name":"d14", "dummy":"true"},
             {"name":"8"},
-            {"name":"d15"},
-            {"name":"d16"},
+            {"name":"d15", "dummy":"true"},
+            {"name":"d16", "dummy":"true"},
             {"name":"9"},
-            {"name":"d17"},
-            {"name":"d18"}
+            {"name":"d17", "dummy":"true"},
+            {"name":"d18", "dummy":"true"}
         ],
         [
-            {"name":"d19"},
-            {"name":"d20"},
+            {"name":"d19", "dummy":"true"},
+            {"name":"d20", "dummy":"true"},
             {"name":"10"},
             {"name":"11"},
-            {"name":"d21"},
-            {"name":"d22"},
+            {"name":"d21", "dummy":"true"},
+            {"name":"d22", "dummy":"true"},
             {"name":"12"},
-            {"name":"d23"},
-            {"name":"d24"}
+            {"name":"d23", "dummy":"true"},
+            {"name":"d24", "dummy":"true"}
         ],
         [
             {"name":"13"},
-            {"name":"d25"},
+            {"name":"d25", "dummy":"true"},
             {"name":"14"},
             {"name":"15"},
             {"name":"16"},
-            {"name":"d26"},
-            {"name":"d27"},
-            {"name":"d28"},
-            {"name":"d29"}
+            {"name":"d26", "dummy":"true"},
+            {"name":"d27", "dummy":"true"},
+            {"name":"d28", "dummy":"true"},
+            {"name":"d29", "dummy":"true"}
         ],
         [
             {"name":"17"},
-            {"name":"d30"},
+            {"name":"d30", "dummy":"true"},
             {"name":"18"},
             {"name":"19"},
-            {"name":"d31"},
+            {"name":"d31", "dummy":"true"},
             {"name":"20"},
-            {"name":"d32"}
+            {"name":"d32", "dummy":"true"}
         ],
         [
             {"name":"21"},
             {"name":"22"},
-            {"name":"d33"},
-            {"name":"d34"}
+            {"name":"d33", "dummy":"true"},
+            {"name":"d34", "dummy":"true"}
         ],
         [
             {"name":"23"}
@@ -80,71 +80,71 @@
     ],
     "edges": [
         {"source":"1","target":"3"},
-        {"source":"1","target":"d1"},
-        {"source":"1","target":"d2"},
-        {"source":"1","target":"d3"},
+        {"source":"1","target":"d1", "dummy":"true"},
+        {"source":"1","target":"d2", "dummy":"true"},
+        {"source":"1","target":"d3", "dummy":"true"},
         {"source":"2","target":"3"},
-        {"source":"2","target":"d4"},
-        {"source":"d1","target":"d5"},
-        {"source":"d2","target":"d6"},
+        {"source":"2","target":"d4", "dummy":"true"},
+        {"source":"d1","target":"d5", "dummy":"true"},
+        {"source":"d2","target":"d6", "dummy":"true"},
         {"source":"d3","target":"4"},
         {"source":"3","target":"4"},
         {"source":"3","target":"5"},
-        {"source":"3","target":"d7"},
-        {"source":"d4","target":"d8"},
-        {"source":"d5","target":"d9"},
-        {"source":"d6","target":"d10"},
+        {"source":"3","target":"d7", "dummy":"true"},
+        {"source":"d4","target":"d8", "dummy":"true"},
+        {"source":"d5","target":"d9", "dummy":"true"},
+        {"source":"d6","target":"d10", "dummy":"true"},
         {"source":"4","target":"6"},
         {"source":"5","target":"7"},
-        {"source":"d7","target":"d11"},
-        {"source":"d8","target":"d12"},
-        {"source":"d9","target":"d13"},
-        {"source":"d10","target":"d14"},
+        {"source":"d7","target":"d11", "dummy":"true"},
+        {"source":"d8","target":"d12", "dummy":"true"},
+        {"source":"d9","target":"d13", "dummy":"true"},
+        {"source":"d10","target":"d14", "dummy":"true"},
         {"source":"6","target":"8"},
-        {"source":"6","target":"d15"},
-        {"source":"6","target":"d16"},
+        {"source":"6","target":"d15", "dummy":"true"},
+        {"source":"6","target":"d16", "dummy":"true"},
         {"source":"7","target":"9"},
-        {"source":"d11","target":"d17"},
-        {"source":"d12","target":"d18"},
-        {"source":"d13","target":"d19"},
-        {"source":"d14","target":"d20"},
+        {"source":"d11","target":"d17", "dummy":"true"},
+        {"source":"d12","target":"d18", "dummy":"true"},
+        {"source":"d13","target":"d19", "dummy":"true"},
+        {"source":"d14","target":"d20", "dummy":"true"},
         {"source":"8","target":"10"},
         {"source":"8","target":"11"},
-        {"source":"d15","target":"d21"},
-        {"source":"d16","target":"d22"},
+        {"source":"d15","target":"d21", "dummy":"true"},
+        {"source":"d16","target":"d22", "dummy":"true"},
         {"source":"9","target":"12"},
-        {"source":"d17","target":"d23"},
-        {"source":"d18","target":"d24"},
+        {"source":"d17","target":"d23", "dummy":"true"},
+        {"source":"d18","target":"d24", "dummy":"true"},
         {"source":"d19","target":"13"},
-        {"source":"d20","target":"d25"},
+        {"source":"d20","target":"d25", "dummy":"true"},
         {"source":"10","target":"13"},
         {"source":"10","target":"14"},
         {"source":"10","target":"15"},
         {"source":"11","target":"15"},
         {"source":"11","target":"16"},
         {"source":"d21","target":"16"},
-        {"source":"d22","target":"d26"},
-        {"source":"12","target":"d27"},
-        {"source":"d23","target":"d28"},
-        {"source":"d24","target":"d29"},
+        {"source":"d22","target":"d26", "dummy":"true"},
+        {"source":"12","target":"d27", "dummy":"true"},
+        {"source":"d23","target":"d28", "dummy":"true"},
+        {"source":"d24","target":"d29", "dummy":"true"},
         {"source":"13","target":"17"},
         {"source":"14","target":"17"},
         {"source":"14","target":"18"},
         {"source":"16","target":"18"},
         {"source":"16","target":"19"},
         {"source":"16","target":"20"},
-        {"source":"d25","target":"d30"},
-        {"source":"d26","target":"d31"},
+        {"source":"d25","target":"d30", "dummy":"true"},
+        {"source":"d26","target":"d31", "dummy":"true"},
         {"source":"d27","target":"20"},
-        {"source":"d28","target":"d32"},
+        {"source":"d28","target":"d32", "dummy":"true"},
         {"source":"d29","target":"20"},
         {"source":"18","target":"21"},
         {"source":"19","target":"22"},
         {"source":"d30","target":"21"},
-        {"source":"d31","target":"d33"},
+        {"source":"d31","target":"d33", "dummy":"true"},
         {"source":"21","target":"23"},
         {"source":"22","target":"23"},
-        {"source":"d32","target":"d34"},
+        {"source":"d32","target":"d34", "dummy":"true"},
         {"source":"d33","target":"23"},
         {"source":"d34","target":"23"}
     ]

+ 5 - 2
save_err1.json

@@ -1,7 +1,7 @@
 {
 	"layers":[
 		[
-            {"name":"0"},
+			{"name":"0"},
 			{"name":"1"},
 			{"name":"2"}
 		],
@@ -12,10 +12,13 @@
 		],
 		[
 			{"name":"6"},
-			{"name":"7"}
+			{"name":"7"},
+			{"name":"8"}
 		]
 	],
 	"edges":[
+        {"source":"4","target":"6"},
+        {"source":"4","target":"8"},
         {"source":"0","target":"5"},
 		{"source":"1","target":"5"},
 		{"source":"2","target":"5"},

+ 12 - 2
src/Algorithms/Animated/BK/BKNodePlacement.java

@@ -18,6 +18,7 @@ public class BKNodePlacement extends AnimatedAlgorithm {
 	
 	private enum State
 	{
+		CONFLICTS,
 		LAYOUT1,
 		LAYOUT2,
 		LAYOUT3,
@@ -25,13 +26,15 @@ public class BKNodePlacement extends AnimatedAlgorithm {
 		COMBINE
 	}
 	
+	private ConflictDetection conftion;
 	private State state;
 	private ExtremalLayoutCalc layouts[];
 	private Combine combine;
 	
 	public BKNodePlacement(AnimationController controller, LayeredGraphNode graph) {
 		super(controller, graph);
-		state = State.LAYOUT1;
+		state = State.CONFLICTS;
+		conftion = new ConflictDetection( graph );
 		layouts = new ExtremalLayoutCalc[ 4 ];
 		layouts[ 0 ] = new ExtremalLayoutCalc( ExtremalLayoutCalc.LayoutType.TOP_BOTTOM_LEFT, graph );
 		layouts[ 1 ] = new ExtremalLayoutCalc( ExtremalLayoutCalc.LayoutType.TOP_BOTTOM_RIGHT, graph );
@@ -44,6 +47,10 @@ public class BKNodePlacement extends AnimatedAlgorithm {
 	public StageStatus forwardStep() {
 		switch( state )
 		{
+		case CONFLICTS:
+			if( conftion.forwardStep() == StageStatus.FINISHED )
+				state = State.LAYOUT1;
+			break;
 		case LAYOUT1:
 			if( layouts[ 0 ].forwardStep() == AlgorithmStage.StageStatus.FINISHED )
 				state = State.LAYOUT2;
@@ -70,8 +77,11 @@ public class BKNodePlacement extends AnimatedAlgorithm {
 	public StageStatus backwardStep() {
 		switch( state )
 		{
+		case CONFLICTS:
+			return conftion.backwardStep();
 		case LAYOUT1:
-			return layouts[ 0 ].backwardStep();
+			if( layouts[ 0 ].backwardStep() == StageStatus.FINISHED )
+				state = State.CONFLICTS;
 		case LAYOUT2:
 			if( layouts[ 1 ].backwardStep() == AlgorithmStage.StageStatus.FINISHED )
 				state = State.LAYOUT1;

+ 1 - 1
src/Algorithms/Animated/BK/Compaction.java

@@ -161,8 +161,8 @@ public class Compaction implements AlgorithmStage{
 					else 
 					{ // w = align[w]
 						LayeredGraphNode oldW = sf.w;
-						sf.v.setSelected( layout );
 						sf.w = sf.w.getAlignedTo( layout );
+						sf.w.setSelected( layout );
 						if( sf.w == sf.v ) // schleifenabbruchbedingung
 						{ //abbrechen, placeblock beendet
                             System.out.println( "return place_block( " + sf.v + " )" );

+ 46 - 12
src/Algorithms/Animated/BK/ConflictDetection.java

@@ -4,6 +4,7 @@ import java.util.ArrayList;
 
 import Algorithms.Animated.AlgorithmStage;
 import Algorithms.Animated.BackwardAction;
+import Model.LayeredGraphEdge;
 import Model.LayeredGraphNode;
 
 public class ConflictDetection implements AlgorithmStage {
@@ -11,26 +12,59 @@ public class ConflictDetection implements AlgorithmStage {
     private LayeredGraphNode graph;
     private ArrayList< BackwardAction > actions;
     
-    
     private int i;
-    private int l;
     private int l1;
-    private int k0;
     
     ConflictDetection( LayeredGraphNode graph )
     {
         this.graph = graph;
         actions = new ArrayList<>();
         i = 1;
-        k0 = 0;
-        l = 0;
         l1 = 0;
     }
     
     @Override
     public StageStatus forwardStep() {
-        //if( l1 == graph.getContainedLayers().get( i + 1 ).size() - 1 || )
-        return calcNextStatus();
+    	int oldI = i;
+    	int oldL1 = l1;
+    	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;
+    		}
+    	}
+    	ArrayList< LayeredGraphEdge > conflicts = new ArrayList<>();
+        if( dummyEdge != null )
+        {
+    		for( LayeredGraphEdge e : edges )
+    		{
+    			if( e.isDummyEdge() )
+    			{
+    				ArrayList< LayeredGraphEdge > conf = e.calcConflictedEdges();
+    				for( LayeredGraphEdge ce : conf )
+    				{
+    					if( !ce.isDummyEdge() )
+    						conflicts.add( ce );
+    				}
+    			}
+    		}
+        }
+        for( LayeredGraphEdge c : conflicts )
+        	c.setConflicted( true, null );
+    	StageStatus status =  calcNextStatus();
+    	actions.add( ()->{
+    		i = oldI;
+    		l1 = oldL1;
+            for( LayeredGraphEdge c : conflicts )
+            	c.setConflicted( false, null );
+    	});
+    	return status;
     }
     
     private StageStatus calcNextStatus()
@@ -46,16 +80,16 @@ public class ConflictDetection implements AlgorithmStage {
                 return StageStatus.FINISHED;
             }
             l1 = 0;
-            k0 = 0;
-            l = 0;
         }
         return StageStatus.UNFINISHED;
     }
 
     @Override
     public StageStatus backwardStep() {
-        // TODO Auto-generated method stub
-        return null;
+        if( actions.size() == 0 )
+        	return StageStatus.FINISHED;
+        actions.get( 0 ).reverse();
+        actions.remove( 0 );
+        return StageStatus.UNFINISHED;
     }
-
 }

+ 3 - 0
src/Algorithms/RandomGraphGenerator.java

@@ -52,6 +52,7 @@ public class RandomGraphGenerator {
             node = parent.createNode( null );
         if( ( Math.random() <= pSubgraph && depth < maxDepth ) || depth == 0 )
         {
+            int index = 0;
             int layer = (int)( Math.random() * ( maxLayer - minLayer ) ) + minLayer;
             for( int i = 0; i < layer; i++ )
             {
@@ -68,6 +69,8 @@ public class RandomGraphGenerator {
                                 node.createSimpleEdge( null, n2, n );
                         }
                     }
+                    n.setName( "" + (index+1) );
+                    index++;
                 }
             }
         }

+ 8 - 1
src/IO/Reader.java

@@ -57,6 +57,10 @@ public class Reader {
 		LayeredGraphNode newNode = new LayeredNode( null, null );
 		if( parent != null )
 			newNode = parent.createNode( null );
+		if( node.has( "dummy" ) && node.getBoolean( "dummy" ) )
+		{
+			newNode.setDummyNode( true );
+		}
         if( node.has( "name" ) )
         {
             if( parent != null && parent.findNodeByName( node.getString( "name" ) ) != null )
@@ -96,7 +100,10 @@ public class Reader {
             throw new JSONException( edge + " is no valid Layered Graph Edge." );
         if( parent.findNodeByName( edge.getString( "target" ) ) == null )
             throw new JSONException( edge + " is no valid Layered Graph Edge." );
-		return parent.createSimpleEdge( null, parent.findNodeByName( edge.getString( "source" ) ), parent.findNodeByName( edge.getString( "target" ) ) );
+        LayeredGraphEdge newEdge = parent.createSimpleEdge( null, parent.findNodeByName( edge.getString( "source" ) ), parent.findNodeByName( edge.getString( "target" ) ) );
+        if( parent.findNodeByName( edge.getString( "source" ) ).isDummyNode() && parent.findNodeByName( edge.getString( "target" ) ).isDummyNode() )
+        	newEdge.setDummyEdge();
+		return newEdge;
 	}
 	
 	private ArrayList<LayeredGraphNode> parseLayer( JSONArray layer, LayeredGraphNode parent ) throws JSONException

+ 2 - 0
src/IO/Writer.java

@@ -64,6 +64,8 @@ public class Writer {
         }
         node.put( "edges", edges );
         node.put( "name", graph.getName() );
+        if( graph.isDummyNode() )
+        	node.put( "dummy", "true" );
         return node;
     }
     

+ 2 - 2
src/Main.java

@@ -13,9 +13,9 @@ import View.MainView;
 public class Main {
 
 	public static void main(String[] args) {
-		Reader r = new Reader( "save_err1.json" );
+		Reader r = new Reader( "papergraph.json" );
 		LayeredGraphNode graph = r.readInputGraph();
-	    //RandomGraphGenerator r = new RandomGraphGenerator( 1, 1, 2, 2, 4, 4, 2 );
+	    //RandomGraphGenerator r = new RandomGraphGenerator( 0.1, 0.2, 5,5, 5, 5, 1 );
 	    //LayeredGraphNode graph = r.createRandomNode( null, 0 );
 	    //SweepCrossingMinimizer cminzer = new SweepCrossingMinimizer();
 	    //for( int i = 0; i < 10; i++ )

+ 2 - 0
src/Model/LayeredGraphNode.java

@@ -39,6 +39,8 @@ public interface LayeredGraphNode {
     public void update();
     public void setSelected( LayoutType layoutType );
     public boolean isSelected( LayoutType layout );
+    public void setDummyNode( boolean dummy );
+    public boolean isDummyNode();
     
     /**
      * Setzt den Index des Layers, zu dem der Knoten geh�ren soll

+ 14 - 0
src/Model/LayeredNode.java

@@ -23,6 +23,7 @@ public class LayeredNode implements LayeredGraphNode {
     // for this node
     private ElkNode original;
     private LayeredGraphNode parent;
+    private boolean dummy;
     
     private class LayoutInfo
     {
@@ -76,6 +77,19 @@ public class LayeredNode implements LayeredGraphNode {
             l.shift = Double.POSITIVE_INFINITY;
             l.xUndef = true;
         }
+        dummy = false;
+    }
+    
+    @Override
+    public void setDummyNode( boolean dummy )
+    {
+    	this.dummy = dummy;
+    }
+    
+    @Override
+    public boolean isDummyNode()
+    {
+    	return dummy;
     }
 
     @Override

+ 2 - 0
src/View/EdgeView.java

@@ -89,6 +89,8 @@ public class EdgeView extends JPanel {
         ((Graphics2D)g).setStroke(new BasicStroke(1));
         //System.out.println( "Clipping: x:" + g.getClip().getBounds().getX() + " y:" + g.getClip().getBounds().getY() + " w:" + g.getClip().getBounds().getWidth() + " h:" + g.getClip().getBounds().getHeight() );
         g.setColor( Color.GREEN );
+        if( model.isConflicted( layout ) )
+        	g.setColor( Color.RED );
         ArrayList<Point> bps = model.getLinePoints( layout );
         for( int i = 1; i < bps.size(); i++ )
         {