golf.drl

来自「jboss规则引擎」· DRL 代码 · 共 56 行

DRL
56
字号
package org.drools.examples;

import org.drools.examples.GolfingExample.Golfer;

rule "find solution"
    when
        // There is a golfer named Fred, 
        // Whose positions is $p1
        Golfer( $fredsName : name == "Fred", 
                $fredsPosition : position, 
                $fredsColor : color  )

  		// The golfer to Fred's immediate right
  		// is wearing blue pants
        Golfer( $unknownsName : name != "Fred", 
                $unknownsPosition :  position == ( new Integer( $fredsPosition.intValue() + 1 ) ),
                $unknownsColor : color == "blue",
                color != $fredsColor )

        // Joe is in position 2  		          
        Golfer( $joesName : name == "Joe", 
                $joesPosition  : position == 2, 
                position != $fredsPosition,
                $joesColor : color != $fredsColor )

 		// Bob is wearing plaid pants        
        Golfer( $bobsName : name == "Bob", 
                name != $unknownsName,
                $bobsPosition : position != $fredsPosition,
                position != $unknownsPosition,              
                position != $joesPosition,                                                  
                $bobsColor : color == "plaid",
                color != $fredsColor,
                color != $joesColor,
                color != $unknownsColor )
 		  		
        // Tom isn't in position 1 or 4
        // and isn't wearing orange	
        Golfer( $tomsName : name == "Tom", 
                $tomsPosition : position != 1,
                position != 4,
                position != $fredsPosition,
                position != $joesPosition, 
                position != $bobsPosition,                                
                $tomsColor : color != "orange",
                color != "blue",
                color != $fredsColor,
                color != $joesColor,
                color != $bobsColor )                
	then
        System.out.println( "Fred " + $fredsPosition + " " + $fredsColor );
        System.out.println( "Joe " + $joesPosition + " " + $joesColor );
        System.out.println( "Bob " + $bobsPosition + " " + $bobsColor );
        System.out.println( "Tom " + $tomsPosition + " " + $tomsColor );   
end    

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?