[jboss-svn-commits] JBL Code SVN: r5279 - labs/jbossrules/trunk/drools-examples/src/main/rules/org/drools/benchmark/waltz

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Jul 25 15:19:43 EDT 2006


Author: mark.proctor at jboss.com
Date: 2006-07-25 15:19:41 -0400 (Tue, 25 Jul 2006)
New Revision: 5279

Modified:
   labs/jbossrules/trunk/drools-examples/src/main/rules/org/drools/benchmark/waltz/waltz.drl
Log:
-fixed line endings

Modified: labs/jbossrules/trunk/drools-examples/src/main/rules/org/drools/benchmark/waltz/waltz.drl
===================================================================
--- labs/jbossrules/trunk/drools-examples/src/main/rules/org/drools/benchmark/waltz/waltz.drl	2006-07-25 15:38:56 UTC (rev 5278)
+++ labs/jbossrules/trunk/drools-examples/src/main/rules/org/drools/benchmark/waltz/waltz.drl	2006-07-25 19:19:41 UTC (rev 5279)
@@ -1,489 +1,489 @@
-#created on: 25/03/2006
-package org.drools.integrationtests.waltz
-
-import org.drools.benchmark.waltz.Stage
-import org.drools.benchmark.waltz.Line
-import org.drools.benchmark.waltz.Edge
-import org.drools.benchmark.waltz.Junction
-import org.drools.benchmark.waltz.WaltzUtil
-
-# the starting rule
-rule "begin waltz"
-	when
-		$stage : Stage(value == Stage.START)
-	then 
-	    assert (new Line( 122,  107));
-	    assert (new Line( 107, 2207));
-    	assert (new Line(2207, 3204));
-    	assert (new Line(3204, 6404));
-    	assert (new Line(2216, 2207));
-    	assert (new Line(3213, 3204));
-    	assert (new Line(2216, 3213));
-    	assert (new Line( 107, 2601));
-    	assert (new Line(2601, 7401));
-    	assert (new Line(6404, 7401));
-    	assert (new Line(3213, 6413));
-    	assert (new Line(6413, 6404));
-    	assert (new Line(7416, 7401));
-    	assert (new Line(5216, 6413));
-    	assert (new Line(2216, 5216));
-    	assert (new Line( 122, 5222));
-    	assert (new Line(5222, 7416));
-    	assert (new Line(5222, 5216));
-    	$stage.setValue(Stage.DUPLICATE);
-    	modify ( $stage );
-    	System.out.println("Waltz started");
-    	System.out.println("Stage: duplicate");
-end
-
-#If the duplicate flag is set, and there is still a line in WM, delete the line
-#and add two edges. One edge runs from p1 to p2 and the other runs from p2 to
-#p1.  We then plot the edge.
-rule "reverse edges"
-	when
-		Stage(value == Stage.DUPLICATE)
-		$line : Line ( $p1:p1, $p2:p2 )
-	then 
-		System.out.println("Draw "+$p1+" "+$p2);
-		assert( new Edge ( $p1.intValue(), $p2.intValue(), false, Edge.NIL, false ) );
-		assert( new Edge ( $p2.intValue(), $p1.intValue(), false, Edge.NIL, false ) );
-		retract( $line ); 
-end
-
-#If the duplicating flag is set, and there are no more lines, then remove the
-#duplicating flag and set the make junctions flag.
-rule "reversing done" salience -10
-	when
-        $stage: Stage ( value == Stage.DUPLICATE )
-	then
-        $stage.setValue ( Stage.DETECT_JUNCTIONS );
-        modify($stage);
-    	System.out.println("Stage: detect junctions");
-end
-
-#If three edges meet at a point and none of them have already been joined in
-#a junction, then make the corresponding type of junction and label the
-#edges joined.  This production calls make-3_junction to determine
-#what type of junction it is based on the angles inscribed by the
-#intersecting edges
-rule "make 3 junction" salience 10
-	when
-        Stage ( value == Stage.DETECT_JUNCTIONS )
-        $edge1: Edge( $basePoint:p1, $edge1P2:p2, joined==false )
-        $edge2: Edge( p1==$basePoint, $edge2P2:p2 != $edge1P2, joined == false )
-        $edge3: Edge( p1==$basePoint, $edge3P2:p2 != $edge1P2, p2 != $edge2P2, joined == false )
-	then
-	    Junction junction = WaltzUtil.make_3_junction ( $basePoint.intValue(), $edge1P2.intValue(), $edge2P2.intValue(), $edge3P2.intValue() );
-	    assert( junction );
-	    $edge1.setJoined(true);
-	    $edge2.setJoined(true);
-	    $edge3.setJoined(true);
-	    modify( $edge1 );
-	    modify( $edge2 );
-	    modify( $edge3 );
-end
-
-#If two, and only two, edges meet that have not already been joined, then
-#the junction is an "L"
-rule "make L"
-	when
-        Stage ( value == Stage.DETECT_JUNCTIONS )
-        $edge1: Edge( $basePoint:p1, $edge1P2:p2, joined==false )
-        $edge2: Edge( p1==$basePoint, $edge2P2:p2 != $edge1P2, joined == false )
-        not Edge( p1==$basePoint, p2 != $edge1P2, p2 != $edge2P2 )
-	then
-	    assert( new Junction($edge1P2.intValue(), $edge2P2.intValue(), 0, $basePoint.intValue(), Junction.L) );
-	    $edge1.setJoined(true);
-	    $edge2.setJoined(true);
-	    modify( $edge1 );
-	    modify( $edge2 );
-end
-
-#If the detect junctions flag is set, and there are no more un_joined edges,
-#set the find_initial_boundary flag
-rule "detecting done" salience -10
-    when
-        $stage : Stage ( value == Stage.DETECT_JUNCTIONS )
- 	then
- 	    $stage.setValue( Stage.FIND_INITIAL_BOUNDARY );
- 	    modify( $stage );
-    	System.out.println("Stage: find initial boundary");
-end
-
-#If the initial boundary junction is an L, then we know it's labelling
-rule "initial boundary junction L"
-	when
-	    $stage : Stage ( value == Stage.FIND_INITIAL_BOUNDARY )
-	             Junction( type == Junction.L, $basePoint:basePoint, $p1:p1, $p2:p2 )
-	    $edge1 : Edge ( p1 == $basePoint, p2 == $p1 )
-	    $edge2 : Edge ( p1 == $basePoint, p2 == $p2 )
-        not Junction( $bp:basePoint > $basePoint )
-	then
-	    $edge1.setLabel( Edge.B );
-	    $edge2.setLabel( Edge.B );
-	    $stage.setValue( Stage.FIND_SECOND_BOUNDARY );
-	    modify( $edge1 );
-	    modify( $edge2 );
-	    modify( $stage );
-    	System.out.println("Stage: find second boundary");
-end
-
-# Ditto for an arrow
-rule "initial boundary junction arrow"
-	when
-	    $stage : Stage ( value == Stage.FIND_INITIAL_BOUNDARY )
-	             Junction( type == Junction.ARROW, $basePoint:basePoint, $p1:p1, $p2:p2, $p3:p3 )
-	    $edge1 : Edge ( p1 == $basePoint, p2 == $p1 )
-	    $edge2 : Edge ( p1 == $basePoint, p2 == $p2 )
-	    $edge3 : Edge ( p1 == $basePoint, p2 == $p3 )
-        not Junction( $bp:basePoint > $basePoint )
-	then
-	    $edge1.setLabel( Edge.B );
-	    $edge2.setLabel( Edge.PLUS );
-	    $edge3.setLabel( Edge.B );
-	    $stage.setValue( Stage.FIND_SECOND_BOUNDARY );
-	    modify( $edge1 );
-	    modify( $edge2 );
-	    modify( $edge3 );
-	    modify( $stage );
-    	System.out.println("Stage: find second boundary");
-end
-
-# If we have already found the first boundary point, then find the second
-# boundary point, and label it.
-rule "second boundary junction L"
-	when
-	    $stage : Stage ( value == Stage.FIND_SECOND_BOUNDARY )
-	             Junction( type == Junction.L, $basePoint:basePoint, $p1:p1, $p2:p2 )
-	    $edge1 : Edge ( p1 == $basePoint, p2 == $p1 )
-	    $edge2 : Edge ( p1 == $basePoint, p2 == $p2 )
-        not Junction( $bp:basePoint < $basePoint )
-	then
-	    $edge1.setLabel( Edge.B );
-	    $edge2.setLabel( Edge.B );
-	    $stage.setValue( Stage.LABELING );
-	    modify( $edge1 );
-	    modify( $edge2 );
-	    modify( $stage );
-    	System.out.println("Stage: labeling");
-end
-
-# Ditto for arrow
-rule "second boundary junction arrow"
-	when
-	    $stage : Stage ( value == Stage.FIND_SECOND_BOUNDARY )
-	             Junction( type == Junction.ARROW, $basePoint:basePoint, $p1:p1, $p2:p2, $p3:p3 )
-	    $edge1 : Edge ( p1 == $basePoint, p2 == $p1 )
-	    $edge2 : Edge ( p1 == $basePoint, p2 == $p2 )
-	    $edge3 : Edge ( p1 == $basePoint, p2 == $p3 )
-        not Junction( $bp:basePoint < $basePoint )
-	then
-	    $edge1.setLabel( Edge.B );
-	    $edge2.setLabel( Edge.PLUS );
-	    $edge3.setLabel( Edge.B );
-	    $stage.setValue( Stage.LABELING );
-	    modify( $edge1 );
-	    modify( $edge2 );
-	    modify( $edge3 );
-	    modify( $stage );
-    	System.out.println("Stage: labeling");
-end
- 
-# If we have an edge whose label we already know definitely, then
-# label the corresponding edge in the other direction
-rule "match edge"
-	when
-	    Stage( value == Stage.LABELING )
-        $edge1: Edge( $p1:p1, $p2:p2, $label:label != Edge.NIL )
-        $edge2: Edge( p1 == $p2, p2 == $p1, label == Edge.NIL )
-	then
-	    $edge1.setPlotted( true );
-	    $edge2.setLabel( $label );
-	    $edge2.setPlotted( true );
-	    modify( $edge1 );
-	    modify( $edge2 );
-	    System.out.println("Plot "+$label+" "+$p1+" "+$p2);
-end
-
-# The following productions propogate the possible labellings of the edges
-# based on the labellings of edges incident on adjacent junctions.  Since
-# from the initial boundary productions, we have determined the labellings of
-# of atleast two junctions, this propogation will label all of the junctions
-# with the possible labellings.  The search space is pruned due to filtering,
-# i.e.(not only label a junction in the ways physically possible based on the
-# labellings of adjacent junctions.
-rule "label L"
-	when
-	    Stage( value == Stage.LABELING )
-	    Junction( type == Junction.L, $basePoint:basePoint )
-        Edge( $p1:p1, $p2:p2, $label:label -> ( $label.equals(Edge.PLUS) || $label.equals(Edge.MINUS) ) )
-        $edge: Edge( p1 == $p1, p2 != $p2, label == Edge.NIL )
-	then
-	    $edge.setLabel( Edge.B );
-	    modify( $edge );
-end 
- 
-rule "label tee A" salience 5
-	when
-        Stage( value == Stage.LABELING )
-        Junction( type == Junction.TEE, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
-        $edge1: Edge( p1 == $bp, p2 == $p1, label == Edge.NIL )
-        $edge2: Edge( p1 == $bp, p2 == $p3 )
-	then
-	    $edge1.setLabel( Edge.B );
-	    $edge2.setLabel( Edge.B );
-	    modify( $edge1 );
-	    modify( $edge2 );
-end 
-
-
-rule "label tee B"
-	when
-        Stage( value == Stage.LABELING )
-        Junction( type == Junction.TEE, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
-        $edge1: Edge( p1 == $bp, p2 == $p1 )
-        $edge2: Edge( p1 == $bp, p2 == $p3, label == Edge.NIL )
-	then
-	    $edge1.setLabel( Edge.B );
-	    $edge2.setLabel( Edge.B );
-	    modify( $edge1 );
-	    modify( $edge2 );
-end
-
-rule "label fork 1"
-	when
-        Stage( value == Stage.LABELING )
-        Junction( type == Junction.FORK, $bp:basePoint )
-        Edge( p1 == $bp, $p1:p2, label == Edge.PLUS )
-        $edge1: Edge( p1 == $bp, $p2:p2 != $p1, label == Edge.NIL )
-        $edge2: Edge( p1 == $bp, $p3:p2 != $p1, p2 != $p2 )
-	then
-	    $edge1.setLabel( Edge.PLUS );
-	    $edge2.setLabel( Edge.PLUS );
-	    modify( $edge1 );
-	    modify( $edge2 );
-end
-
-rule "label fork 2"
-	when
-        Stage( value == Stage.LABELING )
-        Junction( type == Junction.FORK, $bp:basePoint )
-        Edge( p1 == $bp, $p1:p2, label == Edge.B )
-        Edge( p1 == $bp, $p2:p2 != $p1, label == Edge.MINUS )
-        $edge: Edge( p1 == $bp, $p3:p2 != $p1, p2 != $p2, label == Edge.NIL )
-	then
-	    $edge.setLabel( Edge.B );
-	    modify( $edge );
-end
-
-rule "label fork 3"
-	when
-        Stage( value == Stage.LABELING )
-        Junction( type == Junction.FORK, $bp:basePoint )
-        Edge( p1 == $bp, $p1:p2, label == Edge.B )
-        Edge( p1 == $bp, $p2:p2 != $p1, label == Edge.B )
-        $edge: Edge( p1 == $bp, $p3:p2 != $p1, p2 != $p2, label == Edge.NIL )
-	then
-	    $edge.setLabel( Edge.MINUS );
-	    modify( $edge );
-end
-
-rule "label fork 4"
-	when
-        Stage( value == Stage.LABELING )
-        Junction( type == Junction.FORK, $bp:basePoint )
-        Edge( p1 == $bp, $p1:p2, label == Edge.MINUS )
-        Edge( p1 == $bp, $p2:p2 != $p1, label == Edge.MINUS )
-        $edge: Edge( p1 == $bp, $p3:p2 != $p1, p2 != $p2, label == Edge.NIL )
-	then
-	    $edge.setLabel( Edge.MINUS );
-	    modify( $edge );
-end
- 
-rule "label arrow 1A" salience 5
-	when
-        Stage( value == Stage.LABELING )
-        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
-        Edge( p1 == $bp, p2 == $p1, $label:label -> ( $label.equals(Edge.B) || $label.equals(Edge.MINUS) ) )
-        $edge1: Edge( p1 == $bp, p2 == $p2, label == Edge.NIL )
-        $edge2: Edge( p1 == $bp, p2 == $p3 )
-	then
-	    $edge1.setLabel( Edge.PLUS );
-	    $edge2.setLabel( $label );
-	    modify( $edge1 );
-	    modify( $edge2 );
-end
- 
-rule "label arrow 1B" 
-	when
-        Stage( value == Stage.LABELING )
-        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
-        Edge( p1 == $bp, p2 == $p1, $label:label -> ( $label.equals(Edge.B) || $label.equals(Edge.MINUS) ) )
-        $edge1: Edge( p1 == $bp, p2 == $p2 )
-        $edge2: Edge( p1 == $bp, p2 == $p3, label == Edge.NIL )
-	then
-	    $edge1.setLabel( Edge.PLUS );
-	    $edge2.setLabel( $label );
-	    modify( $edge1 );
-	    modify( $edge2 );
-end
- 
-rule "label arrow 2A" salience 5 
-	when
-        Stage( value == Stage.LABELING )
-        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
-        Edge( p1 == $bp, p2 == $p3, $label:label -> ( $label.equals(Edge.B) || $label.equals(Edge.MINUS) ) )
-        $edge1: Edge( p1 == $bp, p2 == $p2, label == Edge.NIL )
-        $edge2: Edge( p1 == $bp, p2 == $p1 )
-	then
-	    $edge1.setLabel( Edge.PLUS );
-	    $edge2.setLabel( $label );
-	    modify( $edge1 );
-	    modify( $edge2 );
-end
- 
-rule "label arrow 2B"
-	when
-        Stage( value == Stage.LABELING )
-        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
-        Edge( p1 == $bp, p2 == $p3, $label:label -> ( $label.equals(Edge.B) || $label.equals(Edge.MINUS) ) )
-        $edge1: Edge( p1 == $bp, p2 == $p2 )
-        $edge2: Edge( p1 == $bp, p2 == $p1, label == Edge.NIL )
-	then
-	    $edge1.setLabel( Edge.PLUS );
-	    $edge2.setLabel( $label );
-	    modify( $edge1 );
-	    modify( $edge2 );
-end
- 
-rule "label arrow 3A" salience 5 
-	when
-        Stage( value == Stage.LABELING )
-        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
-        Edge( p1 == $bp, p2 == $p1, label == Edge.PLUS )
-        $edge1: Edge( p1 == $bp, p2 == $p2, label == Edge.NIL )
-        $edge2: Edge( p1 == $bp, p2 == $p3 )
-	then
-	    $edge1.setLabel( Edge.MINUS );
-	    $edge2.setLabel( Edge.PLUS );
-	    modify( $edge1 );
-	    modify( $edge2 );
-end
- 
-rule "label arrow 3B" 
-	when
-        Stage( value == Stage.LABELING )
-        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
-        Edge( p1 == $bp, p2 == $p1, label == Edge.PLUS )
-        $edge1: Edge( p1 == $bp, p2 == $p2 )
-        $edge2: Edge( p1 == $bp, p2 == $p3, label == Edge.NIL )
-	then
-	    $edge1.setLabel( Edge.MINUS );
-	    $edge2.setLabel( Edge.PLUS );
-	    modify( $edge1 );
-	    modify( $edge2 );
-end
- 
-rule "label arrow 4A" salience 5 
-	when
-        Stage( value == Stage.LABELING )
-        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
-        Edge( p1 == $bp, p2 == $p3, label == Edge.PLUS )
-        $edge1: Edge( p1 == $bp, p2 == $p2, label == Edge.NIL )
-        $edge2: Edge( p1 == $bp, p2 == $p1 )
-	then
-	    $edge1.setLabel( Edge.MINUS );
-	    $edge2.setLabel( Edge.PLUS );
-	    modify( $edge1 );
-	    modify( $edge2 );
-end
- 
-rule "label arrow 4B" 
-	when
-        Stage( value == Stage.LABELING )
-        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
-        Edge( p1 == $bp, p2 == $p3, label == Edge.PLUS )
-        $edge1: Edge( p1 == $bp, p2 == $p2 )
-        $edge2: Edge( p1 == $bp, p2 == $p1, label == Edge.NIL )
-	then
-	    $edge1.setLabel( Edge.MINUS );
-	    $edge2.setLabel( Edge.PLUS );
-	    modify( $edge1 );
-	    modify( $edge2 );
-end
- 
-rule "label arrow 5A" salience 5 
-	when
-        Stage( value == Stage.LABELING )
-        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
-        Edge( p1 == $bp, p2 == $p2, label == Edge.MINUS )
-        $edge1: Edge( p1 == $bp, p2 == $p1 )
-        $edge2: Edge( p1 == $bp, p2 == $p3, label == Edge.NIL )
-	then
-	    $edge1.setLabel( Edge.PLUS );
-	    $edge2.setLabel( Edge.PLUS );
-	    modify( $edge1 );
-	    modify( $edge2 );
-end
-
-rule "label arrow 5B" 
-	when
-        Stage( value == Stage.LABELING )
-        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
-        Edge( p1 == $bp, p2 == $p2, label == Edge.MINUS )
-        $edge1: Edge( p1 == $bp, p2 == $p1, label == Edge.NIL )
-        $edge2: Edge( p1 == $bp, p2 == $p3 )
-	then
-	    $edge1.setLabel( Edge.PLUS );
-	    $edge2.setLabel( Edge.PLUS );
-	    modify( $edge1 );
-	    modify( $edge2 );
-end
- 
-# The conflict resolution mechanism will only execute a production if no
-# productions that are more complicated are satisfied.  This production is
-# simple, so all of the above dictionary productions will fire before this
-# change of state production
-rule "done labeling" salience -10
-	when
-        $stage: Stage( value == Stage.LABELING )
-	then
-        $stage.setValue( Stage.PLOT_REMAINING_EDGES );
-        modify( $stage );
-    	System.out.println("Stage: plot remaining edges");
-end
-
-# At this point, some labellings may have not been plotted, so plot them
-rule "plot remaining"
-	when
-	    Stage( value == Stage.PLOT_REMAINING_EDGES )
-	    $edge: Edge( plotted == false, $label:label != Edge.NIL, $p1:p1, $p2:p2 )
-	then
-	    System.out.println("Plot "+$label+" "+$p1+" "+$p2);
-	    $edge.setPlotted( true );
-	    modify( $edge );
-end
-
-# If we have been un able to label an edge, assume that it is a boundary.
-# This is a total Kludge, but what the hell. (if we assume only valid drawings
-# will be given for labeling, this assumption generally is true!)
-rule "plot boundaries"
-    when
-	    Stage( value == Stage.PLOT_REMAINING_EDGES )
-	    $edge: Edge( plotted == false, label == Edge.NIL, $p1:p1, $p2:p2 )
-	then
-	    System.out.println("Plot B "+$p1+" "+$p2);
-	    $edge.setPlotted( true );
-	    modify( $edge );
-end
-
-# If there is no more work to do, then we are done and flag it.
-rule "done plotting" salience -10
-	when
-	    $stage: Stage( value == Stage.PLOT_REMAINING_EDGES )
-	then
-	    $stage.setValue( Stage.DONE );
-	    modify( $stage );
-    	System.out.println("Stage: done");
-end
- 
+#created on: 25/03/2006
+package org.drools.integrationtests.waltz
+
+import org.drools.benchmark.waltz.Stage
+import org.drools.benchmark.waltz.Line
+import org.drools.benchmark.waltz.Edge
+import org.drools.benchmark.waltz.Junction
+import org.drools.benchmark.waltz.WaltzUtil
+
+# the starting rule
+rule "begin waltz"
+	when
+		$stage : Stage(value == Stage.START)
+	then 
+	    assert (new Line( 122,  107));
+	    assert (new Line( 107, 2207));
+    	assert (new Line(2207, 3204));
+    	assert (new Line(3204, 6404));
+    	assert (new Line(2216, 2207));
+    	assert (new Line(3213, 3204));
+    	assert (new Line(2216, 3213));
+    	assert (new Line( 107, 2601));
+    	assert (new Line(2601, 7401));
+    	assert (new Line(6404, 7401));
+    	assert (new Line(3213, 6413));
+    	assert (new Line(6413, 6404));
+    	assert (new Line(7416, 7401));
+    	assert (new Line(5216, 6413));
+    	assert (new Line(2216, 5216));
+    	assert (new Line( 122, 5222));
+    	assert (new Line(5222, 7416));
+    	assert (new Line(5222, 5216));
+    	$stage.setValue(Stage.DUPLICATE);
+    	modify ( $stage );
+    	System.out.println("Waltz started");
+    	System.out.println("Stage: duplicate");
+end
+
+#If the duplicate flag is set, and there is still a line in WM, delete the line
+#and add two edges. One edge runs from p1 to p2 and the other runs from p2 to
+#p1.  We then plot the edge.
+rule "reverse edges"
+	when
+		Stage(value == Stage.DUPLICATE)
+		$line : Line ( $p1:p1, $p2:p2 )
+	then 
+		System.out.println("Draw "+$p1+" "+$p2);
+		assert( new Edge ( $p1.intValue(), $p2.intValue(), false, Edge.NIL, false ) );
+		assert( new Edge ( $p2.intValue(), $p1.intValue(), false, Edge.NIL, false ) );
+		retract( $line ); 
+end
+
+#If the duplicating flag is set, and there are no more lines, then remove the
+#duplicating flag and set the make junctions flag.
+rule "reversing done" salience -10
+	when
+        $stage: Stage ( value == Stage.DUPLICATE )
+	then
+        $stage.setValue ( Stage.DETECT_JUNCTIONS );
+        modify($stage);
+    	System.out.println("Stage: detect junctions");
+end
+
+#If three edges meet at a point and none of them have already been joined in
+#a junction, then make the corresponding type of junction and label the
+#edges joined.  This production calls make-3_junction to determine
+#what type of junction it is based on the angles inscribed by the
+#intersecting edges
+rule "make 3 junction" salience 10
+	when
+        Stage ( value == Stage.DETECT_JUNCTIONS )
+        $edge1: Edge( $basePoint:p1, $edge1P2:p2, joined==false )
+        $edge2: Edge( p1==$basePoint, $edge2P2:p2 != $edge1P2, joined == false )
+        $edge3: Edge( p1==$basePoint, $edge3P2:p2 != $edge1P2, p2 != $edge2P2, joined == false )
+	then
+	    Junction junction = WaltzUtil.make_3_junction ( $basePoint.intValue(), $edge1P2.intValue(), $edge2P2.intValue(), $edge3P2.intValue() );
+	    assert( junction );
+	    $edge1.setJoined(true);
+	    $edge2.setJoined(true);
+	    $edge3.setJoined(true);
+	    modify( $edge1 );
+	    modify( $edge2 );
+	    modify( $edge3 );
+end
+
+#If two, and only two, edges meet that have not already been joined, then
+#the junction is an "L"
+rule "make L"
+	when
+        Stage ( value == Stage.DETECT_JUNCTIONS )
+        $edge1: Edge( $basePoint:p1, $edge1P2:p2, joined==false )
+        $edge2: Edge( p1==$basePoint, $edge2P2:p2 != $edge1P2, joined == false )
+        not Edge( p1==$basePoint, p2 != $edge1P2, p2 != $edge2P2 )
+	then
+	    assert( new Junction($edge1P2.intValue(), $edge2P2.intValue(), 0, $basePoint.intValue(), Junction.L) );
+	    $edge1.setJoined(true);
+	    $edge2.setJoined(true);
+	    modify( $edge1 );
+	    modify( $edge2 );
+end
+
+#If the detect junctions flag is set, and there are no more un_joined edges,
+#set the find_initial_boundary flag
+rule "detecting done" salience -10
+    when
+        $stage : Stage ( value == Stage.DETECT_JUNCTIONS )
+ 	then
+ 	    $stage.setValue( Stage.FIND_INITIAL_BOUNDARY );
+ 	    modify( $stage );
+    	System.out.println("Stage: find initial boundary");
+end
+
+#If the initial boundary junction is an L, then we know it's labelling
+rule "initial boundary junction L"
+	when
+	    $stage : Stage ( value == Stage.FIND_INITIAL_BOUNDARY )
+	             Junction( type == Junction.L, $basePoint:basePoint, $p1:p1, $p2:p2 )
+	    $edge1 : Edge ( p1 == $basePoint, p2 == $p1 )
+	    $edge2 : Edge ( p1 == $basePoint, p2 == $p2 )
+        not Junction( $bp:basePoint > $basePoint )
+	then
+	    $edge1.setLabel( Edge.B );
+	    $edge2.setLabel( Edge.B );
+	    $stage.setValue( Stage.FIND_SECOND_BOUNDARY );
+	    modify( $edge1 );
+	    modify( $edge2 );
+	    modify( $stage );
+    	System.out.println("Stage: find second boundary");
+end
+
+# Ditto for an arrow
+rule "initial boundary junction arrow"
+	when
+	    $stage : Stage ( value == Stage.FIND_INITIAL_BOUNDARY )
+	             Junction( type == Junction.ARROW, $basePoint:basePoint, $p1:p1, $p2:p2, $p3:p3 )
+	    $edge1 : Edge ( p1 == $basePoint, p2 == $p1 )
+	    $edge2 : Edge ( p1 == $basePoint, p2 == $p2 )
+	    $edge3 : Edge ( p1 == $basePoint, p2 == $p3 )
+        not Junction( $bp:basePoint > $basePoint )
+	then
+	    $edge1.setLabel( Edge.B );
+	    $edge2.setLabel( Edge.PLUS );
+	    $edge3.setLabel( Edge.B );
+	    $stage.setValue( Stage.FIND_SECOND_BOUNDARY );
+	    modify( $edge1 );
+	    modify( $edge2 );
+	    modify( $edge3 );
+	    modify( $stage );
+    	System.out.println("Stage: find second boundary");
+end
+
+# If we have already found the first boundary point, then find the second
+# boundary point, and label it.
+rule "second boundary junction L"
+	when
+	    $stage : Stage ( value == Stage.FIND_SECOND_BOUNDARY )
+	             Junction( type == Junction.L, $basePoint:basePoint, $p1:p1, $p2:p2 )
+	    $edge1 : Edge ( p1 == $basePoint, p2 == $p1 )
+	    $edge2 : Edge ( p1 == $basePoint, p2 == $p2 )
+        not Junction( $bp:basePoint < $basePoint )
+	then
+	    $edge1.setLabel( Edge.B );
+	    $edge2.setLabel( Edge.B );
+	    $stage.setValue( Stage.LABELING );
+	    modify( $edge1 );
+	    modify( $edge2 );
+	    modify( $stage );
+    	System.out.println("Stage: labeling");
+end
+
+# Ditto for arrow
+rule "second boundary junction arrow"
+	when
+	    $stage : Stage ( value == Stage.FIND_SECOND_BOUNDARY )
+	             Junction( type == Junction.ARROW, $basePoint:basePoint, $p1:p1, $p2:p2, $p3:p3 )
+	    $edge1 : Edge ( p1 == $basePoint, p2 == $p1 )
+	    $edge2 : Edge ( p1 == $basePoint, p2 == $p2 )
+	    $edge3 : Edge ( p1 == $basePoint, p2 == $p3 )
+        not Junction( $bp:basePoint < $basePoint )
+	then
+	    $edge1.setLabel( Edge.B );
+	    $edge2.setLabel( Edge.PLUS );
+	    $edge3.setLabel( Edge.B );
+	    $stage.setValue( Stage.LABELING );
+	    modify( $edge1 );
+	    modify( $edge2 );
+	    modify( $edge3 );
+	    modify( $stage );
+    	System.out.println("Stage: labeling");
+end
+ 
+# If we have an edge whose label we already know definitely, then
+# label the corresponding edge in the other direction
+rule "match edge"
+	when
+	    Stage( value == Stage.LABELING )
+        $edge1: Edge( $p1:p1, $p2:p2, $label:label != Edge.NIL )
+        $edge2: Edge( p1 == $p2, p2 == $p1, label == Edge.NIL )
+	then
+	    $edge1.setPlotted( true );
+	    $edge2.setLabel( $label );
+	    $edge2.setPlotted( true );
+	    modify( $edge1 );
+	    modify( $edge2 );
+	    System.out.println("Plot "+$label+" "+$p1+" "+$p2);
+end
+
+# The following productions propogate the possible labellings of the edges
+# based on the labellings of edges incident on adjacent junctions.  Since
+# from the initial boundary productions, we have determined the labellings of
+# of atleast two junctions, this propogation will label all of the junctions
+# with the possible labellings.  The search space is pruned due to filtering,
+# i.e.(not only label a junction in the ways physically possible based on the
+# labellings of adjacent junctions.
+rule "label L"
+	when
+	    Stage( value == Stage.LABELING )
+	    Junction( type == Junction.L, $basePoint:basePoint )
+        Edge( $p1:p1, $p2:p2, $label:label -> ( $label.equals(Edge.PLUS) || $label.equals(Edge.MINUS) ) )
+        $edge: Edge( p1 == $p1, p2 != $p2, label == Edge.NIL )
+	then
+	    $edge.setLabel( Edge.B );
+	    modify( $edge );
+end 
+ 
+rule "label tee A" salience 5
+	when
+        Stage( value == Stage.LABELING )
+        Junction( type == Junction.TEE, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
+        $edge1: Edge( p1 == $bp, p2 == $p1, label == Edge.NIL )
+        $edge2: Edge( p1 == $bp, p2 == $p3 )
+	then
+	    $edge1.setLabel( Edge.B );
+	    $edge2.setLabel( Edge.B );
+	    modify( $edge1 );
+	    modify( $edge2 );
+end 
+
+
+rule "label tee B"
+	when
+        Stage( value == Stage.LABELING )
+        Junction( type == Junction.TEE, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
+        $edge1: Edge( p1 == $bp, p2 == $p1 )
+        $edge2: Edge( p1 == $bp, p2 == $p3, label == Edge.NIL )
+	then
+	    $edge1.setLabel( Edge.B );
+	    $edge2.setLabel( Edge.B );
+	    modify( $edge1 );
+	    modify( $edge2 );
+end
+
+rule "label fork 1"
+	when
+        Stage( value == Stage.LABELING )
+        Junction( type == Junction.FORK, $bp:basePoint )
+        Edge( p1 == $bp, $p1:p2, label == Edge.PLUS )
+        $edge1: Edge( p1 == $bp, $p2:p2 != $p1, label == Edge.NIL )
+        $edge2: Edge( p1 == $bp, $p3:p2 != $p1, p2 != $p2 )
+	then
+	    $edge1.setLabel( Edge.PLUS );
+	    $edge2.setLabel( Edge.PLUS );
+	    modify( $edge1 );
+	    modify( $edge2 );
+end
+
+rule "label fork 2"
+	when
+        Stage( value == Stage.LABELING )
+        Junction( type == Junction.FORK, $bp:basePoint )
+        Edge( p1 == $bp, $p1:p2, label == Edge.B )
+        Edge( p1 == $bp, $p2:p2 != $p1, label == Edge.MINUS )
+        $edge: Edge( p1 == $bp, $p3:p2 != $p1, p2 != $p2, label == Edge.NIL )
+	then
+	    $edge.setLabel( Edge.B );
+	    modify( $edge );
+end
+
+rule "label fork 3"
+	when
+        Stage( value == Stage.LABELING )
+        Junction( type == Junction.FORK, $bp:basePoint )
+        Edge( p1 == $bp, $p1:p2, label == Edge.B )
+        Edge( p1 == $bp, $p2:p2 != $p1, label == Edge.B )
+        $edge: Edge( p1 == $bp, $p3:p2 != $p1, p2 != $p2, label == Edge.NIL )
+	then
+	    $edge.setLabel( Edge.MINUS );
+	    modify( $edge );
+end
+
+rule "label fork 4"
+	when
+        Stage( value == Stage.LABELING )
+        Junction( type == Junction.FORK, $bp:basePoint )
+        Edge( p1 == $bp, $p1:p2, label == Edge.MINUS )
+        Edge( p1 == $bp, $p2:p2 != $p1, label == Edge.MINUS )
+        $edge: Edge( p1 == $bp, $p3:p2 != $p1, p2 != $p2, label == Edge.NIL )
+	then
+	    $edge.setLabel( Edge.MINUS );
+	    modify( $edge );
+end
+ 
+rule "label arrow 1A" salience 5
+	when
+        Stage( value == Stage.LABELING )
+        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
+        Edge( p1 == $bp, p2 == $p1, $label:label -> ( $label.equals(Edge.B) || $label.equals(Edge.MINUS) ) )
+        $edge1: Edge( p1 == $bp, p2 == $p2, label == Edge.NIL )
+        $edge2: Edge( p1 == $bp, p2 == $p3 )
+	then
+	    $edge1.setLabel( Edge.PLUS );
+	    $edge2.setLabel( $label );
+	    modify( $edge1 );
+	    modify( $edge2 );
+end
+ 
+rule "label arrow 1B" 
+	when
+        Stage( value == Stage.LABELING )
+        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
+        Edge( p1 == $bp, p2 == $p1, $label:label -> ( $label.equals(Edge.B) || $label.equals(Edge.MINUS) ) )
+        $edge1: Edge( p1 == $bp, p2 == $p2 )
+        $edge2: Edge( p1 == $bp, p2 == $p3, label == Edge.NIL )
+	then
+	    $edge1.setLabel( Edge.PLUS );
+	    $edge2.setLabel( $label );
+	    modify( $edge1 );
+	    modify( $edge2 );
+end
+ 
+rule "label arrow 2A" salience 5 
+	when
+        Stage( value == Stage.LABELING )
+        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
+        Edge( p1 == $bp, p2 == $p3, $label:label -> ( $label.equals(Edge.B) || $label.equals(Edge.MINUS) ) )
+        $edge1: Edge( p1 == $bp, p2 == $p2, label == Edge.NIL )
+        $edge2: Edge( p1 == $bp, p2 == $p1 )
+	then
+	    $edge1.setLabel( Edge.PLUS );
+	    $edge2.setLabel( $label );
+	    modify( $edge1 );
+	    modify( $edge2 );
+end
+ 
+rule "label arrow 2B"
+	when
+        Stage( value == Stage.LABELING )
+        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
+        Edge( p1 == $bp, p2 == $p3, $label:label -> ( $label.equals(Edge.B) || $label.equals(Edge.MINUS) ) )
+        $edge1: Edge( p1 == $bp, p2 == $p2 )
+        $edge2: Edge( p1 == $bp, p2 == $p1, label == Edge.NIL )
+	then
+	    $edge1.setLabel( Edge.PLUS );
+	    $edge2.setLabel( $label );
+	    modify( $edge1 );
+	    modify( $edge2 );
+end
+ 
+rule "label arrow 3A" salience 5 
+	when
+        Stage( value == Stage.LABELING )
+        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
+        Edge( p1 == $bp, p2 == $p1, label == Edge.PLUS )
+        $edge1: Edge( p1 == $bp, p2 == $p2, label == Edge.NIL )
+        $edge2: Edge( p1 == $bp, p2 == $p3 )
+	then
+	    $edge1.setLabel( Edge.MINUS );
+	    $edge2.setLabel( Edge.PLUS );
+	    modify( $edge1 );
+	    modify( $edge2 );
+end
+ 
+rule "label arrow 3B" 
+	when
+        Stage( value == Stage.LABELING )
+        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
+        Edge( p1 == $bp, p2 == $p1, label == Edge.PLUS )
+        $edge1: Edge( p1 == $bp, p2 == $p2 )
+        $edge2: Edge( p1 == $bp, p2 == $p3, label == Edge.NIL )
+	then
+	    $edge1.setLabel( Edge.MINUS );
+	    $edge2.setLabel( Edge.PLUS );
+	    modify( $edge1 );
+	    modify( $edge2 );
+end
+ 
+rule "label arrow 4A" salience 5 
+	when
+        Stage( value == Stage.LABELING )
+        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
+        Edge( p1 == $bp, p2 == $p3, label == Edge.PLUS )
+        $edge1: Edge( p1 == $bp, p2 == $p2, label == Edge.NIL )
+        $edge2: Edge( p1 == $bp, p2 == $p1 )
+	then
+	    $edge1.setLabel( Edge.MINUS );
+	    $edge2.setLabel( Edge.PLUS );
+	    modify( $edge1 );
+	    modify( $edge2 );
+end
+ 
+rule "label arrow 4B" 
+	when
+        Stage( value == Stage.LABELING )
+        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
+        Edge( p1 == $bp, p2 == $p3, label == Edge.PLUS )
+        $edge1: Edge( p1 == $bp, p2 == $p2 )
+        $edge2: Edge( p1 == $bp, p2 == $p1, label == Edge.NIL )
+	then
+	    $edge1.setLabel( Edge.MINUS );
+	    $edge2.setLabel( Edge.PLUS );
+	    modify( $edge1 );
+	    modify( $edge2 );
+end
+ 
+rule "label arrow 5A" salience 5 
+	when
+        Stage( value == Stage.LABELING )
+        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
+        Edge( p1 == $bp, p2 == $p2, label == Edge.MINUS )
+        $edge1: Edge( p1 == $bp, p2 == $p1 )
+        $edge2: Edge( p1 == $bp, p2 == $p3, label == Edge.NIL )
+	then
+	    $edge1.setLabel( Edge.PLUS );
+	    $edge2.setLabel( Edge.PLUS );
+	    modify( $edge1 );
+	    modify( $edge2 );
+end
+
+rule "label arrow 5B" 
+	when
+        Stage( value == Stage.LABELING )
+        Junction( type == Junction.ARROW, $bp:basePoint, $p1:p1, $p2:p2, $p3:p3 )
+        Edge( p1 == $bp, p2 == $p2, label == Edge.MINUS )
+        $edge1: Edge( p1 == $bp, p2 == $p1, label == Edge.NIL )
+        $edge2: Edge( p1 == $bp, p2 == $p3 )
+	then
+	    $edge1.setLabel( Edge.PLUS );
+	    $edge2.setLabel( Edge.PLUS );
+	    modify( $edge1 );
+	    modify( $edge2 );
+end
+ 
+# The conflict resolution mechanism will only execute a production if no
+# productions that are more complicated are satisfied.  This production is
+# simple, so all of the above dictionary productions will fire before this
+# change of state production
+rule "done labeling" salience -10
+	when
+        $stage: Stage( value == Stage.LABELING )
+	then
+        $stage.setValue( Stage.PLOT_REMAINING_EDGES );
+        modify( $stage );
+    	System.out.println("Stage: plot remaining edges");
+end
+
+# At this point, some labellings may have not been plotted, so plot them
+rule "plot remaining"
+	when
+	    Stage( value == Stage.PLOT_REMAINING_EDGES )
+	    $edge: Edge( plotted == false, $label:label != Edge.NIL, $p1:p1, $p2:p2 )
+	then
+	    System.out.println("Plot "+$label+" "+$p1+" "+$p2);
+	    $edge.setPlotted( true );
+	    modify( $edge );
+end
+
+# If we have been un able to label an edge, assume that it is a boundary.
+# This is a total Kludge, but what the hell. (if we assume only valid drawings
+# will be given for labeling, this assumption generally is true!)
+rule "plot boundaries"
+    when
+	    Stage( value == Stage.PLOT_REMAINING_EDGES )
+	    $edge: Edge( plotted == false, label == Edge.NIL, $p1:p1, $p2:p2 )
+	then
+	    System.out.println("Plot B "+$p1+" "+$p2);
+	    $edge.setPlotted( true );
+	    modify( $edge );
+end
+
+# If there is no more work to do, then we are done and flag it.
+rule "done plotting" salience -10
+	when
+	    $stage: Stage( value == Stage.PLOT_REMAINING_EDGES )
+	then
+	    $stage.setValue( Stage.DONE );
+	    modify( $stage );
+    	System.out.println("Stage: done");
+end
+ 




More information about the jboss-svn-commits mailing list