org.drools.benchmark.waltzdb.waltzdb.drl Maven / Gradle / Ivy
The newest version!
#created on: 02/11/2006
package org.drools.benchmark.waltzdb
import org.drools.benchmark.waltzdb.Stage;
import org.drools.benchmark.waltzdb.Line;
import org.drools.benchmark.waltzdb.Edge;
import org.drools.benchmark.waltzdb.EdgeLabel;
import org.drools.benchmark.waltzdb.Junction;
import org.drools.benchmark.waltzdb.Label;
import org.drools.benchmark.waltzdb.Illegal;
/*
# Reverse the edges
#(p reverse_edges
# (stage ^value duplicate)
# (line ^p1 ^p2 )
# -->
# (make edge ^p1 ^p2 ^joined false)
# (make edge ^p1 ^p2 ^joined false)
# (remove 2))
*/
rule "reverse_edges"
when
Stage( value == Stage.DUPLICATE )
$line : Line( $p1:p1, $p2:p2 )
then
System.out.println( "Edge " + $p1 + " " + $p2 );
System.out.println( "Edge " + $p2 + " " + $p1 );
insert( new Edge( $p1, $p2, false ) );
insert( new Edge( $p2, $p1, false ) );
retract( $line );
end
# Reversing is done
#(p done_reversing
# (stage ^value duplicate)
# - (line)
# -->
# (modify 1 ^value detect_junctions))
rule "done_reversing"
when
$stage : Stage( value == Stage.DUPLICATE )
not ( Line( ) )
then
modify( $stage ) {setValue( Stage.DETECT_JUNCTIONS )}
System.out.println( "Stage.DETECT_JUNCTIONS" );
end
/*
(p make_3_junction
(stage ^value detect_junctions)
(edge ^p1 ^p2 ^joined false)
(edge ^p1 ^p2 { <> } ^joined false)
(edge ^p1 ^p2 { <> <> } ^joined false)
-->
(make junction
^type 3j
^name (make_3_junction )
^base_point
^visited no)
(modify 2 ^type 3j ^joined true)
(modify 3 ^type 3j ^joined true)
(modify 4 ^type 3j ^joined true))
*/
rule "make_3_junction"
when
Stage( value == Stage.DETECT_JUNCTIONS )
$edge1 : Edge( $basePoint : p1, $p1 : p2, joined == false )
$edge2 : Edge( p1 == $basePoint, $p2 : p2 != $p1, joined == false )
$edge3 : Edge( p1 == $basePoint, $p3 : p2 != $p1, p2 != $p2, joined == false )
then
Junction junction = new Junction( $basePoint, "3j", "make_3_junction " + $basePoint + " " + $p1 + " " + " " + $p2 + " " + $p3, "no" );
insert( junction );
System.out.println( junction.toString( ) );
modify( $edge1 ) {setJoined( true ), setType( "3j" )}
modify( $edge2 ) {setJoined( true ), setType( "3j" )}
modify( $edge3 ) {setJoined( true ), setType( "3j" )}
end
/*
(p make_L
(stage ^value detect_junctions)
(edge ^p1 ^p2 ^joined false)
(edge ^p1 ^p2 { <> } ^joined false)
- (edge ^p1 ^p2 {<> <> })
-->
(make junction
^type 2j
^name L
^base_point
^p1
^p2
^visited no)
(modify 2 ^type 2j ^joined true)
(modify 3 ^type 2j ^joined true))
*/
rule "make_L"
when
Stage( value == Stage.DETECT_JUNCTIONS )
$edge1 : Edge( $basePoint : p1, $p2 : p2, joined == false )
$edge2 : Edge( p1 == $basePoint, $p3 : p2 != $p2, joined == false )
not( Edge( p1 == $basePoint, p2 != $p2, p2 != $p3 ) )
then
Junction junction = new Junction( "2j", "L", $basePoint, $p2, $p3, "no" );
insert( junction );
System.out.println( junction.toString() );
modify( $edge1 ) {setJoined( true ), setType( "2j" )}
modify( $edge2 ) {setJoined( true ), setType( "2j" )}
end
/*
(p done_detecting
(stage ^value detect_junctions)
- (edge ^joined false)
-->
(modify 1 ^value find_initial_boundary))
*/
rule "done_detecting"
when
$stage : Stage( value == Stage.DETECT_JUNCTIONS )
not( Edge ( joined == false ) )
then
modify( $stage ) {setValue( Stage.FIND_INITIAL_BOUNDARY )}
System.out.println( "Stage: FIND_INITIAL_BOUNDARY" );
end
/*
(p initial_boundary_junction_L
(stage ^value find_initial_boundary)
(junction ^type 2j ^base_point ^p1 ^p2 )
(edge ^p1 ^p2 )
(edge ^p1 ^p2 )
-(junction ^base_point > )
-->
(modify 2 ^visited yes)
(make edge_label ^p1 ^p2 ^l_name B ^l_id 1)
(make edge_label ^p1 ^p2 ^l_name B ^l_id 1)
(modify 1 ^value find_second_boundary))
*/
rule "initial_boundary_junction_L"
when
$stage : Stage( value == Stage.FIND_INITIAL_BOUNDARY )
$junction : Junction( type == "2j", $basePoint : basePoint, $p1 : p1, $p2 : p2 )
Edge( p1 == $basePoint, p2 == $p1 )
Edge( p1 == $basePoint, p2 == $p2 )
not Junction( type == "2j", basePoint > $basePoint )//type == "2j" not in original
then
modify( $junction ) {setVisited( "yes" )}
insert( new EdgeLabel( $basePoint, $p1, "B", "1" ) );
insert( new EdgeLabel( $basePoint, $p2, "B", "1" ) );
modify( $stage ) {setValue( Stage.FIND_SECOND_BOUDARY )}
System.out.println( "Stage.FIND_SECOND_BOUDARY" );
end
/*
(p initial_boundary_junction_arrow
(stage ^value find_initial_boundary)
(junction ^type 3j ^name arrow ^base_point ^p1 ^p2 ^p3 )
(edge ^p1 ^p2 )
(edge ^p1 ^p2 )
(edge ^p1 ^p2 )
-(junction ^base_point > )
-->
(modify 2 ^visited yes)
(make edge_label ^p1 ^p2 ^l_name B ^l_id 14)
(make edge_label ^p1 ^p2 ^l_name + ^l_id 14)
(make edge_label ^p1 ^p2 ^l_name B ^l_id 14)
(modify 1 ^value find_second_boundary))
*/
rule "initial_boundary_junction_arrow"
when
$stage : Stage( value == Stage.FIND_INITIAL_BOUNDARY )
$junction : Junction( type == "3j", name == "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 ) //@FIXME, is this correct? I changed edge2 to edge3
not ( Junction( basePoint > $basePoint ) )
then
modify( $junction ) {setVisited( "yes" )}
insert( new EdgeLabel( $basePoint, $p1, "B", "14" ) );
insert( new EdgeLabel( $basePoint, $p2, "+", "14" ) );
insert( new EdgeLabel( $basePoint, $p3, "B", "14" ) );
modify( $stage ) {setValue( Stage.FIND_SECOND_BOUDARY )}
System.out.println( "Stage.FIND_SECOND_BOUDARY" );
end
/*
(p second_boundary_junction_L
(stage ^value find_second_boundary)
(junction ^type 2j ^base_point ^p1 ^p2 )
(edge ^p1 ^p2 )
(edge ^p1 ^p2 )
-(junction ^base_point < )
-->
(modify 2 ^visited yes)
(make edge_label ^p1 ^p2 ^l_name B ^l_id 1)
(make edge_label ^p1 ^p2 ^l_name B ^l_id 1)
(modify 1 ^value labeling))
*/
rule "second_boundary_junction_L"
when
$stage : Stage( value == Stage.FIND_SECOND_BOUDARY )
$junction : Junction( type == "2j", $basePoint : basePoint, $p1 : p1, $p2 : p2 )
Edge( p1 == $basePoint, p2 == $p1)
Edge( p1 == $basePoint, p2 == $p2)
not (Junction ( basePoint < $basePoint ) )
then
modify( $junction ) {setVisited( "yes" )}
insert( new EdgeLabel( $basePoint, $p1, "B", "1" ) );
insert( new EdgeLabel($basePoint, $p2, "B", "1" ) );
modify( $stage ) {setValue( Stage.LABELING )}
System.out.println( "Stage.LABELING" );
end
/*
(p second_boundary_junction_arrow
(stage ^value find_second_boundary)
(junction ^type 3j ^name arrow ^base_point ^p1 ^p2 ^p3 )
(edge ^p1 ^p2 )
(edge ^p1 ^p2 )
(edge ^p1 ^p2 )
-(junction ^base_point < )
-->
(modify 2 ^visited yes)
(make edge_label ^p1 ^p2 ^l_name B ^l_id 14)
(make edge_label ^p1 ^p2 ^l_name + ^l_id 14)
(make edge_label ^p1 ^p2 ^l_name B ^l_id 14)
(modify 1 ^value labeling))
*/
rule "second_boundary_junction_arrow"
when
$stage : Stage( value == Stage.FIND_SECOND_BOUDARY )
$junction : Junction( type == "3j", name == "arrow", $basePoint : basePoint, $p1 : p1, $p2 : p2, $p3 : p3 )
Edge( p1 == $basePoint, p2 == $p1 )
Edge( p1 == $basePoint, p2 == $p2 )
Edge( p1 == $basePoint, p2 == $p3 )
not ( Junction( basePoint < $basePoint ) )
then
modify( $junction ) {setVisited( "yes" )}
insert( new EdgeLabel( $basePoint, $p1, "B", "14" ) );
insert( new EdgeLabel( $basePoint, $p2, "+", "14" ) );
insert( new EdgeLabel( $basePoint, $p3, "B", "14" ) );
modify( $stage ) {setValue( Stage.LABELING )}
System.out.println( "Stage.LABELING" );
end
/*
(p start_visit_3_junction
(stage ^value labeling)
(junction ^base_point ^type 3j ^p1 ^p2 ^p3 ^visited no)
-->
(modify 1 ^value visiting_3j)
(modify 2 ^visited now))
*/
rule "start_visit_3_junction"
when
$stage : Stage( value == Stage.LABELING )
$junction : Junction( type == "3j", $basePoint : basePoint, $p1 : p1, $p2 : p2, $p3 : p3, visited == "no" )
then
modify( $stage ) {setValue( Stage.VISITING_3J )}
modify( $junction ) {setVisited( "now" )}
System.out.println( "Stage.VISITING_3J" );
end
/*
(p visit_3j_0
(stage ^value visiting_3j)
(junction ^name ^base_point ^p1 ^p2 ^p3 ^visited now)
(label ^name ^id ^n1 ^n2 ^n3 )
(edge_label ^p1 ^p2 ^l_name )
(edge_label ^p1 ^p2 ^l_name )
(edge_label ^p1 ^p2 ^l_name )
-(edge_label ^p1 ^l_id )
-->
; (write edge_label (crlf))
; (write edge_label (crlf))
; (write edge_label (crlf))
(make edge_label ^p1 ^p2 ^l_name ^l_id )
(make edge_label ^p1 ^p2 ^l_name ^l_id )
(make edge_label ^p1 ^p2 ^l_name ^l_id ))
*/
rule "visit_3j_0"
when
Stage( value == Stage.VISITING_3J )
Junction( $name : name, $basePoint : basePoint, $p1 : p1, $p2 : p2, $p3 : p3, visited == "now" )
Label(name == $name, $id : id, $n1 : n1, $n2 : n2, $n3 : n3 )
EdgeLabel( p1 == $p1, p2 == $basePoint, labelName == $n1 )
EdgeLabel( p1 == $p2, p2 == $basePoint, labelName == $n2 )
EdgeLabel( p1 == $p3, p2 == $basePoint, labelName == $n3 )
not ( EdgeLabel( p1 == $basePoint, labelId == $id ) )
then
System.out.println( "EdgeLabel " + $basePoint + " " + $p1 + " " + $n1 + " " + $id );
System.out.println( "EdgeLabel " + $basePoint + " " + $p2 + " " + $n2 + " " + $id );
System.out.println( "EdgeLabel " + $basePoint + " " + $p3 + " " + $n3 + " " + $id );
insert( new EdgeLabel( $basePoint, $p1, $n1, $id ) );
insert( new EdgeLabel( $basePoint, $p2, $n2, $id ) );
insert( new EdgeLabel( $basePoint, $p3, $n3, $id ) );
end
/*
(p visit_3j_1
(stage ^value visiting_3j)
(junction ^name ^base_point ^p1 ^p2 ^p3 ^visited now)
(label ^name ^id ^n1 ^n2 ^n3 )
-(edge_label ^p1 ^p2 )
(edge_label ^p1 ^p2 ^l_name )
(edge_label ^p1 ^p2 ^l_name )
-(edge_label ^p1 ^l_id )
-->
; (write edge_label (crlf))
; (write edge_label (crlf))
; (write edge_label (crlf))
(make edge_label ^p1 ^p2 ^l_name ^l_id )
(make edge_label ^p1 ^p2 ^l_name ^l_id )
(make edge_label ^p1 ^p2 ^l_name ^l_id ))
*/
rule "visit_3j_1"
when
Stage( value == Stage.VISITING_3J )
Junction( $name : name, $basePoint : basePoint, $p1 : p1, $p2 : p2, $p3 : p3, visited == "now" )
Label( name == $name, $id : id, $n1 : n1, $n2 : n2, $n3 : n3 )
not ( EdgeLabel( p1 == $p1, p2 == $basePoint ) )
EdgeLabel( p1 == $p2, p2 == $basePoint, labelName == $n2 )
EdgeLabel( p1 == $p3, p2 == $basePoint, labelName == $n3 )
not ( EdgeLabel( p1 == $basePoint, labelId == $id ) )
then
System.out.println( "EdgeLabel " + $basePoint + " " + $p1 + " " + $n1 + " " + $id );
System.out.println( "EdgeLabel " + $basePoint + " " + $p2 + " " + $n2 + " " + $id );
System.out.println( "EdgeLabel " + $basePoint + " " + $p3 + " " + $n3 + " " + $id );
insert( new EdgeLabel( $basePoint, $p1, $n1, $id ) );
insert( new EdgeLabel( $basePoint, $p2, $n2, $id ) );
insert( new EdgeLabel( $basePoint, $p3, $n3, $id ) );
end
/*
(p visit_3j_2
(stage ^value visiting_3j)
(junction ^name ^base_point ^p1 ^p2 ^p3 ^visited now)
(label ^name ^id ^n1 ^n2 ^n3 )
(edge_label ^p1 ^p2 ^l_name )
-(edge_label ^p1 ^p2 )
(edge_label ^p1 ^p2 ^l_name )
-(edge_label ^p1 ^l_id )
-->
; (write edge_label (crlf))
; (write edge_label (crlf))
; (write edge_label (crlf))
(make edge_label ^p1 ^p2 ^l_name ^l_id )
(make edge_label ^p1 ^p2 ^l_name ^l_id )
(make edge_label ^p1 ^p2 ^l_name ^l_id ))
*/
rule "visit_3j_2"
when
Stage( value == Stage.VISITING_3J )
Junction( $name : name, $basePoint : basePoint, $p1 : p1, $p2 : p2, $p3 : p3, visited == "now" )
Label( name == $name, $id : id, $n1 : n1, $n2 : n2, $n3 : n3 )
EdgeLabel( p1 == $p1, p2 == $basePoint, labelName == $n1 )
not ( EdgeLabel( p1 == $p2, p2 == $basePoint ) )
EdgeLabel( p1 == $p3, p2 == $basePoint, labelName == $n3 )
not ( EdgeLabel( p1 == $basePoint, labelId == $id ) )
then
System.out.println( "EdgeLabel " + $basePoint + " " + $p1 + " " + $n1 + " " + $id );
System.out.println( "EdgeLabel " + $basePoint + " " + $p2 + " " + $n2 + " " + $id );
System.out.println( "EdgeLabel " + $basePoint + " " + $p3 + " " + $n3 + " " + $id );
insert( new EdgeLabel( $basePoint, $p1, $n1, $id ) );
insert( new EdgeLabel( $basePoint, $p2, $n2, $id ) );
insert( new EdgeLabel( $basePoint, $p3, $n3, $id ) );
end
/*
(p visit_3j_3
(stage ^value visiting_3j)
(junction ^name ^base_point ^p1 ^p2 ^p3 ^visited now)
(label ^name ^id ^n1 ^n2 ^n3 )
-(edge_label ^p1 ^p2 )
-(edge_label ^p1 ^p2 )
(edge_label ^p1 ^p2 ^l_name )
-(edge_label ^p1 ^l_id )
-->
; (write edge_label (crlf))
; (write edge_label