Explorar el Código

block calculation um konflike ergänzt

Kolja Strohm hace 6 años
padre
commit
6b91dfb956

+ 10 - 2
src/Algorithms/Animated/BK/BlockCalc.java

@@ -64,9 +64,15 @@ public class BlockCalc implements AlgorithmStep {
 		    if( current.getAlignedTo() == current )
 		    {
                 LayeredGraphNode u = incommingEdges.get( m - 1 ).getSources().get( 0 );
-		        // TODO detect conflicts
-		        if( r < graph.getContainedLayers().get( layerIndex - 1 ).indexOf( u ) )
+                ArrayList<LayeredGraphEdge> conflicts = incommingEdges.get( m - 1 ).calcConflictedEdges();
+		        if( !incommingEdges.get( m - 1 ).isConflicted() && r < graph.getContainedLayers().get( layerIndex - 1 ).indexOf( u ) )
 		        {
+		        	ArrayList< Boolean > oldConflicts = new ArrayList<>();
+		        	for( LayeredGraphEdge e : conflicts )
+		        	{
+		        		oldConflicts.add( e.isConflicted() );
+		        		e.setConflicted( true );
+		        	}
 		            LayeredGraphNode oldAlignU = u.getAlignedTo();
 		            Color oldColorCurrent = current.getColor();
 		            LayeredGraphNode oldRootCurrent = current.getRoot();
@@ -80,6 +86,8 @@ public class BlockCalc implements AlgorithmStep {
 		            int oldStep = step++;
 		            backwards.add( 0, () -> {
 		                System.out.println( "Stepping Backwards... (Step " + oldStep + ")" );
+			        	for( int i = 0; i < conflicts.size(); i++ )
+			        		conflicts.get( i ).setConflicted( oldConflicts.get( i ) );
 		                u.setAlignTo( oldAlignU );
 		                current.setColor( oldColorCurrent );
 		                current.setRoot( oldRootCurrent );

+ 3 - 0
src/Algorithms/Animated/BK/Compaction.java

@@ -40,6 +40,7 @@ public class Compaction implements AlgorithmStep{
 	
 	@Override
 	public StepStatus forwardStep() {
+		int acSize = actions.size();
 		if( state == CompactionState.PLACE_BLOCKS )
 		{
 			if( stack.size() == 0 )
@@ -196,6 +197,8 @@ public class Compaction implements AlgorithmStep{
 			if( vIndex >= graph.getContainedNodes().size() )
 				return StepStatus.FINISHED;
 		}
+		if( actions.size() != acSize + 1 )
+			System.out.println( "ERROR" );
 		return StepStatus.UNFINISHED;
 	}
 

+ 38 - 0
src/Model/LayeredEdge.java

@@ -20,6 +20,7 @@ public class LayeredEdge implements LayeredGraphEdge {
     boolean reversed;
     boolean dummy;
     ArrayList< Point > bindPoints;
+    boolean conflicted;
     
     public LayeredEdge( ElkEdge original, ArrayList< LayeredGraphNode > sources, ArrayList< LayeredGraphNode > targets, LayeredGraphNode graph )
     {
@@ -32,8 +33,45 @@ public class LayeredEdge implements LayeredGraphEdge {
         bindPoints = new ArrayList<>();
         bindPoints.add( null );
         bindPoints.add( null );
+        conflicted = false;
     }
 
+    @Override
+    public boolean isConflicted()
+    {
+    	return conflicted;
+    }
+    
+    @Override
+    public ArrayList<LayeredGraphEdge> calcConflictedEdges()
+    {
+    	ArrayList<LayeredGraphEdge> list = new ArrayList<>();
+    	ArrayList<LayeredGraphNode> l = graph.getContainedLayers().get( sources.get( 0 ).getLayer() );
+    	ArrayList<LayeredGraphNode> l2 = graph.getContainedLayers().get( targets.get( 0 ).getLayer() );
+    	int startIndex = l.indexOf( sources.get( 0 ) );
+    	int endIndex = l2.indexOf( targets.get( 0 ) );
+    	for( int i = 0; i < l.size(); i++ )
+    	{
+    		if( i == startIndex )
+    			continue;
+    		for( LayeredGraphEdge e : l.get( i ).getOutgoingEdges() )
+    		{
+    			int i2 = l2.indexOf( e.getTargets().get( 0 ) );
+    			if( i2 == endIndex )
+    				continue;
+    			if( i < startIndex && i2 > endIndex || i > startIndex && i2 < endIndex )
+    				list.add( e );
+    		}
+    	}
+    	return list;
+    };
+    
+    @Override
+    public void setConflicted( boolean conflicted )
+    {
+    	this.conflicted = conflicted;
+    }
+    
     @Override
     public void setStartPoint( int x, int y )
     {

+ 4 - 0
src/Model/LayeredGraphEdge.java

@@ -17,6 +17,10 @@ public interface LayeredGraphEdge {
      */
     ElkEdge getOriginalEdge();
     
+    
+    public boolean isConflicted();
+    public ArrayList<LayeredGraphEdge> calcConflictedEdges();
+    public void setConflicted( boolean conflicted );
     /**
      * Entfernt diese Kante vom Graphen
      */

+ 10 - 7
src/View/NodeView.java

@@ -64,19 +64,22 @@ public class NodeView extends JPanel {
 	@Override
 	public void paintComponent( Graphics g )
 	{
-		if( model.isSelected() )
-		{
-			g.setColor( Color.GRAY );
-			g.fillRect( 0, 0, getWidth()-1, getHeight()-1 );
-		}
-		else
+		/*else
 		{
 			g.setColor( Color.WHITE );
 			g.fillRect( 0, 0, getWidth()-1, getHeight()-1 );
-		}
+		}*/
 		Graphics2D g2 = (Graphics2D)g;
 		g2.setColor( model.getColor() );
 		g2.setStroke(new BasicStroke(5));
+		if( model.getContainedNodes().size() == 0 )
+			g2.fillRect( 0, 0, getWidth()-1, getHeight()-1 );
+		if( model.isSelected() )
+		{
+			g.setColor( Color.GRAY );
+			g.fillRect( 0, 0, getWidth()-1, getHeight()-1 );
+		}
+		g2.setColor( model.getColor() );
 		g2.drawRect( 0, 0, getWidth()-1, getHeight()-1 );
 	}
 }