📄 waltz.drl
字号:
#created on: 25/03/2006package org.drools.integrationtests.waltzimport org.drools.integrationtests.waltz.Stageimport org.drools.integrationtests.waltz.Lineimport org.drools.integrationtests.waltz.Edgeimport org.drools.integrationtests.waltz.Junctionimport org.drools.integrationtests.waltz.WaltzUtil# the starting rulerule "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 edgesrule "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 flagrule "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 labellingrule "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 arrowrule "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 arrowrule "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 directionrule "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 )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -