|
@@ -107,23 +107,23 @@ public class ConflictDetection {
|
|
|
PseudoCodeNode root = new PseudoCodeNode( "function mark_conflicts( graph )", vars, tree, new FunctionDefinition( params ) );
|
|
|
PseudoCodeNode text = new PseudoCodeNode( "-- mark conflicts in subgraphs --", vars, tree, new Comment() );
|
|
|
root.add( text );
|
|
|
- // Für jeden Knoten im Graphen
|
|
|
+ // F�r jeden Knoten im Graphen
|
|
|
PseudoCodeNode foreach = new PseudoCodeNode( "foreach n in graph.getContainedNodes() do", vars, tree, new ForEachLoop<LayeredGraphNode>( "n" ) {
|
|
|
- @Override
|
|
|
- protected List<LayeredGraphNode> list(ReadOnlyMemory m) {
|
|
|
- return m.<LayeredGraphNode>read( "graph", Visibility.LOCAL ).getContainedNodes();
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ protected List<LayeredGraphNode> list(ReadOnlyMemory m) {
|
|
|
+ return m.<LayeredGraphNode>read( "graph", Visibility.LOCAL ).getContainedNodes();
|
|
|
+ }
|
|
|
} );
|
|
|
root.add( foreach );
|
|
|
// Falls der Knoten einen Subgraphen hat
|
|
|
PseudoCodeNode ifNode = new PseudoCodeNode( "if n has subgraph then", vars, tree, new IfLoop() {
|
|
|
- @Override
|
|
|
- protected boolean condition(ReadOnlyMemory m) {
|
|
|
- return m.<LayeredGraphNode>read( "n", Visibility.LOCAL ).getContainedLayers().size() > 0;
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ protected boolean condition(ReadOnlyMemory m) {
|
|
|
+ return m.<LayeredGraphNode>read( "n", Visibility.LOCAL ).getContainedLayers().size() > 0;
|
|
|
+ }
|
|
|
} );
|
|
|
foreach.add( ifNode );
|
|
|
- // Rufe die Funktion rekursiv für den Subgraphen auf
|
|
|
+ // Rufe die Funktion rekursiv f�r den Subgraphen auf
|
|
|
PseudoCodeNode call = new PseudoCodeNode( "call mark_conflicts( n );", vars, tree, new FunctionCall( root, new String[]{ "n" } ) );
|
|
|
ifNode.add( call );
|
|
|
text = new PseudoCodeNode( "-- mark conflicts in graph --", vars, tree, new Comment() );
|
|
@@ -136,122 +136,122 @@ public class ConflictDetection {
|
|
|
}
|
|
|
} );
|
|
|
root.add( init );
|
|
|
- // Für jeden Layerindex vom 2. bis zum vorletzten (nur hier können innere Segmente auftreten)
|
|
|
+ // F�r jeden Layerindex vom 2. bis zum vorletzten (nur hier k�nnen innere Segmente auftreten)
|
|
|
PseudoCodeNode outerLoop = new PseudoCodeNode( "for i=1 to |L|-2 do", vars, tree, new ForLoop( "i" ) {
|
|
|
- @Override
|
|
|
- protected int minimum( ReadOnlyMemory m ) {
|
|
|
- return 1;
|
|
|
- }
|
|
|
- @Override
|
|
|
- protected int maximum( ReadOnlyMemory m ) {
|
|
|
- return m.<ArrayList<ArrayList<LayeredGraphNode>>>read( "L", Visibility.LOCAL ).size() - 2;
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ protected int minimum( ReadOnlyMemory m ) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ protected int maximum( ReadOnlyMemory m ) {
|
|
|
+ return m.<ArrayList<ArrayList<LayeredGraphNode>>>read( "L", Visibility.LOCAL ).size() - 2;
|
|
|
+ }
|
|
|
} );
|
|
|
root.add( outerLoop );
|
|
|
// Initialisiere lokale Variablen
|
|
|
PseudoCodeNode line = new PseudoCodeNode( "k0 = 0; l = 0;", vars, tree, new CodeLine() {
|
|
|
- @Override
|
|
|
- public ControlFlow runForward(Memory m) {
|
|
|
- m.declare( "k0", 0, Visibility.LOCAL ); // deklariere die Variablen im aktuellen Stack Frame
|
|
|
- m.declare( "l", 0, Visibility.LOCAL );
|
|
|
- actions.push( (Memory mem) -> { // Merkt sich die Rückgängig-mach-Aktion
|
|
|
- mem.undeclare( "k0", Visibility.LOCAL );
|
|
|
- mem.undeclare( "l", Visibility.LOCAL );
|
|
|
- } );
|
|
|
- return new ControlFlow( ControlFlow.STEP_OVER );
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public ControlFlow runForward(Memory m) {
|
|
|
+ m.declare( "k0", 0, Visibility.LOCAL ); // deklariere die Variablen im aktuellen Stack Frame
|
|
|
+ m.declare( "l", 0, Visibility.LOCAL );
|
|
|
+ actions.push( (Memory mem) -> { // Merkt sich die R�ckg�ngig-mach-Aktion
|
|
|
+ mem.undeclare( "k0", Visibility.LOCAL );
|
|
|
+ mem.undeclare( "l", Visibility.LOCAL );
|
|
|
+ } );
|
|
|
+ return new ControlFlow( ControlFlow.STEP_OVER );
|
|
|
+ }
|
|
|
} );
|
|
|
outerLoop.add( line );
|
|
|
- // Für eine genauere Beschreibung des Algoritmus zum markieren von Konflikten siehe Karstens Paper (link in Dokumentation)
|
|
|
+ // F�r eine genauere Beschreibung des Algoritmus zum markieren von Konflikten siehe Karstens Paper (link in Dokumentation)
|
|
|
PseudoCodeNode innerLoop = new PseudoCodeNode( "for l1=0 to |L[i+1]|-1 do", vars, tree, new ForLoop( "l1" ) {
|
|
|
- @Override
|
|
|
- protected int minimum(ReadOnlyMemory m) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- @Override
|
|
|
- protected int maximum(ReadOnlyMemory m) {
|
|
|
- return m.<ArrayList<ArrayList<LayeredGraphNode>>>read( "L", Visibility.LOCAL ).get( m.<Integer>read( "i", Visibility.LOCAL ) + 1 ).size() - 1;
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ protected int minimum(ReadOnlyMemory m) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ protected int maximum(ReadOnlyMemory m) {
|
|
|
+ return m.<ArrayList<ArrayList<LayeredGraphNode>>>read( "L", Visibility.LOCAL ).get( m.<Integer>read( "i", Visibility.LOCAL ) + 1 ).size() - 1;
|
|
|
+ }
|
|
|
} );
|
|
|
outerLoop.add( innerLoop );
|
|
|
ifNode = 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", vars, tree, new IfLoop() {
|
|
|
- @Override
|
|
|
- protected boolean condition(ReadOnlyMemory m) {
|
|
|
- return m.<Integer>read( "l1", Visibility.LOCAL ) == m.<LayeredGraphNode>read( "graph", Visibility.LOCAL ).getContainedLayers().get( m.<Integer>read( "i", Visibility.LOCAL ) + 1).size() - 1 ||
|
|
|
- incidentToInnerSegmentBetweenLiPlusOneAndLi( m );
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ protected boolean condition(ReadOnlyMemory m) {
|
|
|
+ return m.<Integer>read( "l1", Visibility.LOCAL ) == m.<LayeredGraphNode>read( "graph", Visibility.LOCAL ).getContainedLayers().get( m.<Integer>read( "i", Visibility.LOCAL ) + 1).size() - 1 ||
|
|
|
+ incidentToInnerSegmentBetweenLiPlusOneAndLi( m );
|
|
|
+ }
|
|
|
} );
|
|
|
innerLoop.add( ifNode );
|
|
|
line = new PseudoCodeNode( "k1 = |L[i]|-1;", vars, tree, new DeclareVariable<Integer>( "k1" ) {
|
|
|
- @Override
|
|
|
- protected Integer value(ReadOnlyMemory m) {
|
|
|
- return (int)m.<ArrayList<ArrayList<LayeredGraphNode>>>read( "L", Visibility.LOCAL ).get( m.read( "i", Visibility.LOCAL ) ).size() - 1;
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ protected Integer value(ReadOnlyMemory m) {
|
|
|
+ return (int)m.<ArrayList<ArrayList<LayeredGraphNode>>>read( "L", Visibility.LOCAL ).get( m.read( "i", Visibility.LOCAL ) ).size() - 1;
|
|
|
+ }
|
|
|
} );
|
|
|
ifNode.add( line );
|
|
|
PseudoCodeNode innerIfNode = new PseudoCodeNode( "if L[i+1][l1] incident to inner segment between L[i+1] and L[i] then", vars, tree, new IfLoop() {
|
|
|
- @Override
|
|
|
- protected boolean condition(ReadOnlyMemory m) {
|
|
|
- return incidentToInnerSegmentBetweenLiPlusOneAndLi( m ); // Prüfe ob ein inneres Segment da ist
|
|
|
- }
|
|
|
- } );
|
|
|
+ @Override
|
|
|
+ protected boolean condition(ReadOnlyMemory m) {
|
|
|
+ return incidentToInnerSegmentBetweenLiPlusOneAndLi( m ); // Pr�fe ob ein inneres Segment da ist
|
|
|
+ }
|
|
|
+ } );
|
|
|
ifNode.add( innerIfNode );
|
|
|
|
|
|
line = new PseudoCodeNode( "k1 = pos(pred(L[i+1][l1])[0]);", vars, tree, new SetVariable<Integer>( "k1" ) {
|
|
|
- @Override
|
|
|
- protected Integer value(ReadOnlyMemory m) {
|
|
|
- return (int)m.<LayeredGraphNode>read( "graph", Visibility.LOCAL ).getContainedLayers().get( m.read( "i", Visibility.LOCAL ) ).indexOf(
|
|
|
- m.<LayeredGraphNode>read( "graph", Visibility.LOCAL ).getContainedLayers().get( m.<Integer>read( "i", Visibility.LOCAL ) + 1 ).get( m.read( "l1", Visibility.LOCAL ) ).getSortedIncomingEdges().get( 0 ).getSources().get( 0 ) );
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ protected Integer value(ReadOnlyMemory m) {
|
|
|
+ return (int)m.<LayeredGraphNode>read( "graph", Visibility.LOCAL ).getContainedLayers().get( m.read( "i", Visibility.LOCAL ) ).indexOf(
|
|
|
+ m.<LayeredGraphNode>read( "graph", Visibility.LOCAL ).getContainedLayers().get( m.<Integer>read( "i", Visibility.LOCAL ) + 1 ).get( m.read( "l1", Visibility.LOCAL ) ).getSortedIncomingEdges().get( 0 ).getSources().get( 0 ) );
|
|
|
+ }
|
|
|
} );
|
|
|
innerIfNode.add( line );
|
|
|
PseudoCodeNode whileLoop = new PseudoCodeNode( "while l <= l1 do", vars, tree, new WhileLoop() {
|
|
|
- @Override
|
|
|
- protected boolean condition( ReadOnlyMemory m ) {
|
|
|
- return m.<Integer>read( "l", Visibility.LOCAL ) <= m.<Integer>read( "l1", Visibility.LOCAL );
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ protected boolean condition( ReadOnlyMemory m ) {
|
|
|
+ return m.<Integer>read( "l", Visibility.LOCAL ) <= m.<Integer>read( "l1", Visibility.LOCAL );
|
|
|
+ }
|
|
|
} );
|
|
|
ifNode.add( whileLoop );
|
|
|
foreach = new PseudoCodeNode( "foreach v in pred(L[i+1][l]) do", vars, tree, new ForEachLoop<LayeredGraphEdge>( "v" ) {
|
|
|
- @Override
|
|
|
- protected List<LayeredGraphEdge> list(ReadOnlyMemory m) {
|
|
|
- return m.<LayeredGraphNode>read( "graph", Visibility.LOCAL ).getContainedLayers().get( m.<Integer>read( "i", Visibility.LOCAL ) + 1 ).get( m.read( "l", Visibility.LOCAL ) ).getIncomingEdges();
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ protected List<LayeredGraphEdge> list(ReadOnlyMemory m) {
|
|
|
+ return m.<LayeredGraphNode>read( "graph", Visibility.LOCAL ).getContainedLayers().get( m.<Integer>read( "i", Visibility.LOCAL ) + 1 ).get( m.read( "l", Visibility.LOCAL ) ).getIncomingEdges();
|
|
|
+ }
|
|
|
} );
|
|
|
whileLoop.add( foreach );
|
|
|
innerIfNode = new PseudoCodeNode( "if pos(v) < k0 or pos(v) > k1 then", vars, tree, new IfLoop() {
|
|
|
- @Override
|
|
|
- protected boolean condition(ReadOnlyMemory m) {
|
|
|
- int k = m.<LayeredGraphNode>read( "graph", Visibility.LOCAL ).getContainedLayers().get( m.read( "i", Visibility.LOCAL ) ).indexOf( m.<LayeredGraphEdge>read( "v", Visibility.LOCAL ).getSources().get( 0 ) );
|
|
|
- return k < m.<Integer>read( "k0", Visibility.LOCAL ) || k > m.<Integer>read( "k1", Visibility.LOCAL );
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ protected boolean condition(ReadOnlyMemory m) {
|
|
|
+ int k = m.<LayeredGraphNode>read( "graph", Visibility.LOCAL ).getContainedLayers().get( m.read( "i", Visibility.LOCAL ) ).indexOf( m.<LayeredGraphEdge>read( "v", Visibility.LOCAL ).getSources().get( 0 ) );
|
|
|
+ return k < m.<Integer>read( "k0", Visibility.LOCAL ) || k > m.<Integer>read( "k1", Visibility.LOCAL );
|
|
|
+ }
|
|
|
} );
|
|
|
foreach.add( innerIfNode );
|
|
|
line = new PseudoCodeNode( "mark segment (v,L[i+1][l]);", vars, tree, new CodeLine() {
|
|
|
- @Override
|
|
|
- public ControlFlow runForward(Memory m) {
|
|
|
- LayeredGraphEdge e = m.read( "v", Visibility.LOCAL );
|
|
|
- boolean old = e.isConflicted( LayoutType.LEFTMOST_UPPER );
|
|
|
- e.setConflicted( true, null ); // Markiere die Kante als Konflicted
|
|
|
- actions.add( (Memory mem) -> {
|
|
|
- e.setConflicted( old, null ); // Rückwärts
|
|
|
- });
|
|
|
- return new ControlFlow( ControlFlow.STEP_OVER );
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public ControlFlow runForward(Memory m) {
|
|
|
+ LayeredGraphEdge e = m.read( "v", Visibility.LOCAL );
|
|
|
+ boolean old = e.isConflicted( LayoutType.LEFTMOST_UPPER );
|
|
|
+ e.setConflicted( true, null ); // Markiere die Kante als Konflicted
|
|
|
+ actions.add( (Memory mem) -> {
|
|
|
+ e.setConflicted( old, null ); // R�ckw�rts
|
|
|
+ });
|
|
|
+ return new ControlFlow( ControlFlow.STEP_OVER );
|
|
|
+ }
|
|
|
} );
|
|
|
innerIfNode.add( line );
|
|
|
line = new PseudoCodeNode( "l = l+1;", vars, tree, new SetVariable<Integer>( "l" ) {
|
|
|
- @Override
|
|
|
- protected Integer value(ReadOnlyMemory m) {
|
|
|
- return (int)m.<Integer>read( "l", Visibility.LOCAL ) + 1;
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ protected Integer value(ReadOnlyMemory m) {
|
|
|
+ return (int)m.<Integer>read( "l", Visibility.LOCAL ) + 1;
|
|
|
+ }
|
|
|
} );
|
|
|
whileLoop.add( line );
|
|
|
line = new PseudoCodeNode( "k0 = k1;", vars, tree, new SetVariable<Integer>( "k0" ) {
|
|
|
- @Override
|
|
|
- protected Integer value(ReadOnlyMemory m) {
|
|
|
- return (int)m.<Integer>read( "k1", Visibility.LOCAL );
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ protected Integer value(ReadOnlyMemory m) {
|
|
|
+ return (int)m.<Integer>read( "k1", Visibility.LOCAL );
|
|
|
+ }
|
|
|
} );
|
|
|
ifNode.add( line );
|
|
|
return root;
|