|
@@ -39,30 +39,33 @@ public class Balancing {
|
|
|
public static PseudoCodeNode combine( JTree tree ) {
|
|
|
String[] vars = { "graph", "l", "l_min", "v", "positions", "min", "shift", "max", "width" };
|
|
|
|
|
|
+
|
|
|
PseudoCodeNode root = new PseudoCodeNode( "function combine( graph )", vars, tree, new FunctionDefinition( new String[]{ "graph" } ) ){
|
|
|
private static final long serialVersionUID = -3067185213650162055L;
|
|
|
|
|
|
@Override
|
|
|
public String getDebugOutput( Memory m )
|
|
|
{
|
|
|
- if( m.isSomewhereDefined( "v", Visibility.LOCAL ) )
|
|
|
+ if( m.isSomewhereDefined( "v", Visibility.LOCAL ) )
|
|
|
m.<LayeredGraphNode>read( "v", Visibility.LOCAL).setSelected( null );
|
|
|
return super.getDebugOutput( m );
|
|
|
}
|
|
|
};
|
|
|
+
|
|
|
root.add( new PseudoCodeNode( "-- Call combine of subgraphs --", vars, tree, new CodeLine() {
|
|
|
@Override
|
|
|
public ControlFlow runForward(Memory m) {
|
|
|
LayeredGraphNode graph = m.read( "graph", Visibility.LOCAL );
|
|
|
if( graph.parent() == null )
|
|
|
- graph.setColor( Color.BLACK, null );
|
|
|
- actions.add( (Memory mem) -> {
|
|
|
+ graph.setColor( Color.BLACK, null );
|
|
|
+ actions.push( (Memory mem) -> {
|
|
|
if( graph.parent() == null )
|
|
|
- graph.setColor( null, null );
|
|
|
+ graph.setColor( null, null );
|
|
|
});
|
|
|
return new ControlFlow( ControlFlow.STEP_OVER );
|
|
|
}
|
|
|
}));
|
|
|
+
|
|
|
PseudoCodeNode recursiveLoop = new PseudoCodeNode( "foreach v in graph do", vars, tree, new ForEachLoop<LayeredGraphNode>( "v" ) {
|
|
|
@Override
|
|
|
protected List<LayeredGraphNode> list(ReadOnlyMemory m) {
|
|
@@ -70,6 +73,7 @@ public class Balancing {
|
|
|
}
|
|
|
});
|
|
|
root.add( recursiveLoop );
|
|
|
+
|
|
|
PseudoCodeNode ifNode = new PseudoCodeNode( "if v has subgraph then", vars, tree, new IfLoop() {
|
|
|
@Override
|
|
|
protected boolean condition(ReadOnlyMemory m) {
|
|
@@ -77,8 +81,10 @@ public class Balancing {
|
|
|
}
|
|
|
} );
|
|
|
recursiveLoop.add( ifNode );
|
|
|
+
|
|
|
ifNode.add( new PseudoCodeNode( "call combine( v );", vars, tree, new FunctionCall( root, new String[]{ "v" } ) ) );
|
|
|
root.add( new PseudoCodeNode( "-- Align all Layouts to the one with the smallest width --", vars, tree, new Comment()));
|
|
|
+
|
|
|
root.add( new PseudoCodeNode( "max = [];", vars, tree, new DeclareVariable<HashMap<String,Integer>>( "max") {
|
|
|
@Override
|
|
|
protected HashMap<String,Integer> value(ReadOnlyMemory m) {
|
|
@@ -97,6 +103,7 @@ public class Balancing {
|
|
|
return new HashMap<String,Integer>();
|
|
|
}
|
|
|
}));
|
|
|
+
|
|
|
PseudoCodeNode firstLoop = new PseudoCodeNode( "foreach l in ['RIGHTMOST_LOWER', 'LEFTMOST_LOWER', 'RIGHTMOST_UPPER', 'LEFTMOST_UPPER'] do", vars, tree, new ForEachLoop<String>( "l" ) {
|
|
|
@Override
|
|
|
protected List<String> list(ReadOnlyMemory m) {
|
|
@@ -109,6 +116,7 @@ public class Balancing {
|
|
|
}
|
|
|
});
|
|
|
root.add( firstLoop );
|
|
|
+
|
|
|
firstLoop.add( new PseudoCodeNode( "min[l] = minimum x coordinate in l;", vars, tree, new CodeLine() {
|
|
|
@Override
|
|
|
public ControlFlow runForward(Memory m) {
|
|
@@ -120,6 +128,7 @@ public class Balancing {
|
|
|
return new ControlFlow( ControlFlow.STEP_OVER );
|
|
|
}
|
|
|
}));
|
|
|
+
|
|
|
firstLoop.add( new PseudoCodeNode( "max[l] = maximum x coordinate in l;", vars, tree, new CodeLine() {
|
|
|
@Override
|
|
|
public ControlFlow runForward(Memory m) {
|
|
@@ -131,6 +140,7 @@ public class Balancing {
|
|
|
return new ControlFlow( ControlFlow.STEP_OVER );
|
|
|
}
|
|
|
}));
|
|
|
+
|
|
|
firstLoop.add( new PseudoCodeNode( "width[l] = max[l] - min[l];", vars, tree, new CodeLine() {
|
|
|
@Override
|
|
|
public ControlFlow runForward(Memory m) {
|
|
@@ -142,6 +152,7 @@ public class Balancing {
|
|
|
return new ControlFlow( ControlFlow.STEP_OVER );
|
|
|
}
|
|
|
}));
|
|
|
+
|
|
|
root.add( new PseudoCodeNode( "l_min = l with width[l] == min(width);", vars, tree, new DeclareVariable<String>( "l_min" ) {
|
|
|
@Override
|
|
|
protected String value(ReadOnlyMemory m) {
|
|
@@ -158,12 +169,14 @@ public class Balancing {
|
|
|
return min;
|
|
|
}
|
|
|
}));
|
|
|
+
|
|
|
root.add( new PseudoCodeNode( "shift = [];", vars, tree, new DeclareVariable<HashMap<String,Integer>>( "shift") {
|
|
|
@Override
|
|
|
protected HashMap<String,Integer> value(ReadOnlyMemory m) {
|
|
|
return new HashMap<String,Integer>();
|
|
|
}
|
|
|
}));
|
|
|
+
|
|
|
PseudoCodeNode secondLoop = new PseudoCodeNode( "foreach l in ['RIGHTMOST_LOWER', 'LEFTMOST_LOWER', 'RIGHTMOST_UPPER', 'LEFTMOST_UPPER'] do", vars, tree, new ForEachLoop<String>( "l" ) {
|
|
|
@Override
|
|
|
protected List<String> list(ReadOnlyMemory m) {
|
|
@@ -176,6 +189,7 @@ public class Balancing {
|
|
|
}
|
|
|
});
|
|
|
root.add( secondLoop );
|
|
|
+
|
|
|
secondLoop.add( new PseudoCodeNode( "shift[l] = l.contains('RIGHT') ? min[l_min] - min[l] : max[l_min] - max[l];", vars, tree, new CodeLine() {
|
|
|
@Override
|
|
|
public ControlFlow runForward(Memory m) {
|
|
@@ -191,6 +205,7 @@ public class Balancing {
|
|
|
return new ControlFlow( ControlFlow.STEP_OVER );
|
|
|
}
|
|
|
}));
|
|
|
+
|
|
|
PseudoCodeNode thirdLoop = new PseudoCodeNode( "foreach v in graph do", vars, tree, new ForEachLoop<LayeredGraphNode>( "v" ) {
|
|
|
@Override
|
|
|
protected List<LayeredGraphNode> list(ReadOnlyMemory m) {
|
|
@@ -198,12 +213,14 @@ public class Balancing {
|
|
|
}
|
|
|
});
|
|
|
root.add( thirdLoop );
|
|
|
+
|
|
|
thirdLoop.add( new PseudoCodeNode( "positions = [];", vars, tree, new DeclareVariable<ArrayList<Integer>>( "positions") {
|
|
|
@Override
|
|
|
protected ArrayList<Integer> value(ReadOnlyMemory m) {
|
|
|
return new ArrayList<Integer>();
|
|
|
}
|
|
|
}));
|
|
|
+
|
|
|
PseudoCodeNode innerLoop = new PseudoCodeNode( "foreach l in ['RIGHTMOST_LOWER', 'LEFTMOST_LOWER', 'RIGHTMOST_UPPER', 'LEFTMOST_UPPER'] do", vars, tree, new ForEachLoop<String>( "l" ) {
|
|
|
@Override
|
|
|
protected List<String> list(ReadOnlyMemory m) {
|
|
@@ -215,6 +232,7 @@ public class Balancing {
|
|
|
return list;
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
innerLoop.add( new PseudoCodeNode( "positions.add(x[v] in l);", vars, tree, new CodeLine() {
|
|
|
@Override
|
|
|
public ControlFlow runForward(Memory m) {
|
|
@@ -228,6 +246,7 @@ public class Balancing {
|
|
|
}
|
|
|
}));
|
|
|
thirdLoop.add( innerLoop );
|
|
|
+
|
|
|
thirdLoop.add( new PseudoCodeNode( "positions = sort( positions );", vars, tree, new SetVariable<ArrayList<Integer>>( "positions" ) {
|
|
|
@Override
|
|
|
public ArrayList<Integer> value(ReadOnlyMemory m) {
|
|
@@ -239,6 +258,7 @@ public class Balancing {
|
|
|
return neu;
|
|
|
}
|
|
|
}));
|
|
|
+
|
|
|
thirdLoop.add( new PseudoCodeNode( "x[v] = (positions[1]+positions[2]) / 2;", vars, tree, new CodeLine() {
|
|
|
@Override
|
|
|
public ControlFlow runForward(Memory m) {
|
|
@@ -255,6 +275,7 @@ public class Balancing {
|
|
|
return root;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private static int calcMinX( LayeredGraphNode graph, LayoutType layout )
|
|
|
{
|
|
|
int minX = 0;
|
|
@@ -265,6 +286,7 @@ public class Balancing {
|
|
|
return minX;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private static int calcMaxX( LayeredGraphNode graph, LayoutType layout )
|
|
|
{
|
|
|
int maxX = 0;
|