|
@@ -1,5 +1,6 @@
|
|
|
package Algorithms.Animated.BK;
|
|
|
|
|
|
+import java.awt.Color;
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
import Algorithms.Animated.AlgorithmStep;
|
|
@@ -11,6 +12,7 @@ public class BlockCalc implements AlgorithmStep {
|
|
|
|
|
|
private int layerIndex;
|
|
|
private int nodeIndex;
|
|
|
+ private int r;
|
|
|
private LayeredGraphNode graph;
|
|
|
private ArrayList< ArrayList< BKNodePlacement > > subgraphAlgs;
|
|
|
private ArrayList< BackwordAction > backwards;
|
|
@@ -20,6 +22,7 @@ public class BlockCalc implements AlgorithmStep {
|
|
|
this.graph = graph;
|
|
|
layerIndex = 0;
|
|
|
nodeIndex = 0;
|
|
|
+ r = 0;
|
|
|
subgraphAlgs = new ArrayList<>();
|
|
|
for( ArrayList<LayeredGraphNode> l : graph.getContainedLayers() )
|
|
|
{
|
|
@@ -52,14 +55,44 @@ public class BlockCalc implements AlgorithmStep {
|
|
|
});
|
|
|
return calcNextState();
|
|
|
}
|
|
|
- for( LayeredGraphEdge e : incommingEdges )
|
|
|
+ int[] ms = {(incommingEdges.size() + 1) / 2, (int)( (incommingEdges.size() + 1) / 2.0 + 0.5 )};
|
|
|
+ boolean backwardsAdded = false;
|
|
|
+ for( int m : ms )
|
|
|
{
|
|
|
- // TODO
|
|
|
+ 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 ) )
|
|
|
+ {
|
|
|
+ LayeredGraphNode oldAlignU = u.getAlignedTo();
|
|
|
+ Color oldColorCurrent = current.getColor();
|
|
|
+ LayeredGraphNode oldRootCurrent = current.getRoot();
|
|
|
+ LayeredGraphNode oldAlignCurrent = current.getAlignedTo();
|
|
|
+ int oldR = r;
|
|
|
+ u.setAlignTo( current );
|
|
|
+ current.setColor( u.getRoot().getColor() );
|
|
|
+ current.setRoot( u.getRoot() );
|
|
|
+ current.setAlignTo( current.getRoot() );
|
|
|
+ r = graph.getContainedLayers().get( layerIndex - 1 ).indexOf( u );
|
|
|
+ backwards.add( 0, () -> {
|
|
|
+ System.out.println( "Stepping Backwards..." );
|
|
|
+ u.setAlignTo( oldAlignU );
|
|
|
+ current.setColor( oldColorCurrent );
|
|
|
+ current.setRoot( oldRootCurrent );
|
|
|
+ current.setAlignTo( oldAlignCurrent );
|
|
|
+ r = oldR;
|
|
|
+ });
|
|
|
+ backwardsAdded = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if( !backwardsAdded )
|
|
|
+ {
|
|
|
+ backwards.add( 0, () -> {
|
|
|
+ System.out.println( "Performing Empty Backwards Step..." );
|
|
|
+ });
|
|
|
}
|
|
|
- backwards.add( 0, () -> {
|
|
|
- System.out.println( "Stepping Backwards..." );
|
|
|
- // TODO
|
|
|
- });
|
|
|
current.update();
|
|
|
return calcNextState();
|
|
|
}
|
|
@@ -76,6 +109,11 @@ public class BlockCalc implements AlgorithmStep {
|
|
|
{
|
|
|
layerIndex++;
|
|
|
nodeIndex = 0;
|
|
|
+ int oldR = r;
|
|
|
+ r = 0;
|
|
|
+ backwards.add(0, ()->{
|
|
|
+ this.r = oldR;
|
|
|
+ });
|
|
|
}
|
|
|
return StepStatus.UNFINISHED;
|
|
|
}
|
|
@@ -114,6 +152,8 @@ public class BlockCalc implements AlgorithmStep {
|
|
|
if( nodeIndex < 0 )
|
|
|
{
|
|
|
layerIndex--;
|
|
|
+ backwards.get( 0 ).reverse();
|
|
|
+ backwards.remove( 0 );
|
|
|
nodeIndex = graph.getContainedLayers().get( layerIndex ).size() - 1;
|
|
|
}
|
|
|
return StepStatus.UNFINISHED;
|