[jboss-svn-commits] JBL Code SVN: r18139 - labs/jbossrules/branches/drools-spring/drools-spring/drools-spring-examples/src/main/rules/org/drools/benchmark.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Jan 25 21:54:19 EST 2008


Author: mark.proctor at jboss.com
Date: 2008-01-25 21:54:19 -0500 (Fri, 25 Jan 2008)
New Revision: 18139

Added:
   labs/jbossrules/branches/drools-spring/drools-spring/drools-spring-examples/src/main/rules/org/drools/benchmark/manners.drl
Log:
JBRULES-1434 Drools Spring

Added: labs/jbossrules/branches/drools-spring/drools-spring/drools-spring-examples/src/main/rules/org/drools/benchmark/manners.drl
===================================================================
--- labs/jbossrules/branches/drools-spring/drools-spring/drools-spring-examples/src/main/rules/org/drools/benchmark/manners.drl	                        (rev 0)
+++ labs/jbossrules/branches/drools-spring/drools-spring/drools-spring-examples/src/main/rules/org/drools/benchmark/manners.drl	2008-01-26 02:54:19 UTC (rev 18139)
@@ -0,0 +1,112 @@
+package org.drools.benchmark.manners
+
+rule assignFirstSeat
+    when
+        context : Context( state == Context.START_UP )
+        guest : Guest()
+        count : Count()
+    then
+        String guestName = guest.getName();
+        
+        Seating seating =  new Seating( count.getValue(), 1, true, 1, guestName, 1, guestName);
+        insert( seating );
+        
+        Path path = new Path( count.getValue(), 1, guestName );
+        insert( path );
+        
+        count.setValue(  count.getValue() + 1 );        
+        update( count );
+
+		System.out.println( "assign first seat :  " + seating + " : " + path );
+
+        context.setState( Context.ASSIGN_SEATS );        
+        update( context );
+end
+
+rule findSeating
+   when 
+       context : Context( state == Context.ASSIGN_SEATS )
+       $s      : Seating( pathDone == true )
+       $g1     : Guest( name == $s.rightGuestName )
+       $g2     : Guest( sex != $g1.sex, hobby == $g1.hobby )
+
+       count   : Count()
+
+       not ( Path( id == $s.id, guestName == $g2.name) )
+       not ( Chosen( id == $s.id, guestName == $g2.name, hobby == $g1.hobby) )
+   then
+       int rightSeat = $s.getRightSeat();
+       int seatId = $s.getId();
+       int countValue = count.getValue();
+       
+       Seating seating = new Seating( countValue, seatId, false, rightSeat, $s.getRightGuestName(), rightSeat + 1, $g2.getName() );
+       insert( seating );     
+                            
+       Path path = new Path( countValue, rightSeat + 1, $g2.getName()  );
+       insert( path );
+       
+       Chosen chosen = new Chosen( seatId, $g2.getName(), $g1.getHobby() );
+       insert( chosen  );
+
+	   System.err.println( "find seating : " + seating + " : " + path + " : " + chosen);
+
+       count.setValue(  countValue + 1 );
+       update( count );       
+
+       context.setState( Context.MAKE_PATH );
+       update( context );
+end
+
+rule makePath
+    when 
+        Context( state == Context.MAKE_PATH )
+        Seating( seatingId:id, seatingPid:pid, pathDone == false )
+        Path( id == seatingPid, pathGuestName:guestName, pathSeat:seat )
+        not Path( id == seatingId, guestName == pathGuestName )
+    then
+        insert( new Path( seatingId, pathSeat, pathGuestName ) );
+end 
+
+rule pathDone
+    when
+        context : Context( state == Context.MAKE_PATH ) 
+        seating : Seating( pathDone == false ) 
+    then
+        seating.setPathDone( true ); 
+        update( seating );
+        
+        context.setState( Context.CHECK_DONE ); 
+		update( context );
+end
+
+
+rule areWeDone
+    when
+        context : Context( state == Context.CHECK_DONE ) 
+        LastSeat( lastSeat: seat )
+        Seating( rightSeat == lastSeat ) 
+    then
+        context.setState(Context.PRINT_RESULTS ); 
+        update( context );
+end
+
+rule continue
+    when
+        context : Context( state == Context.CHECK_DONE ) 
+    then
+        context.setState( Context.ASSIGN_SEATS ); 
+        update( context );
+end
+
+
+rule allDone
+    when
+        context : Context( state == Context.PRINT_RESULTS ) 
+    then
+    	System.out.println( "All Done" );
+end
+
+//query getResults
+//	context : Context( state == Context.PRINT_RESULTS ) 
+//end 
+ 
\ No newline at end of file




More information about the jboss-svn-commits mailing list