All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.drools.examples.golf.drl Maven / Gradle / Ivy

The newest version!
package org.drools.examples;

dialect "mvel"

import org.drools.examples.GolfingExample.Golfer;

rule "find solution"
    when
        // There is a golfer named Fred,
        // Whose positions is $p1
        $fred : Golfer( name == "Fred" )

        // Joe is in position 2
        $joe : Golfer( name == "Joe",
                position == 2,
                position != $fred.position,
                color != $fred.color )

 		// Bob is wearing plaid pants
        $bob : Golfer( name == "Bob",
                position != $fred.position,
                position != $joe.position,
                color == "plaid",
                color != $fred.color,
                color != $joe.color )

        // Tom isn't in position 1 or 4
        // and isn't wearing orange
        $tom : Golfer( name == "Tom",
                position != 1,
                position != 4,
                position != $fred.position,
                position != $joe.position,
                position != $bob.position,
                color != "orange",
                //color != "blue",
                color != $fred.color,
                color != $joe.color,
                color != $bob.color )

  		// The golfer to Fred's immediate right
  		// is wearing blue pants
        Golfer( position == ( $fred.position + 1 ),
                      color == "blue",
                      this in ( $joe, $bob, $tom ) )

	then
        System.out.println( "Fred " + $fred.getPosition() + " " + $fred.getColor() );
        System.out.println( "Joe " + $joe.getPosition() + " " + $joe.getColor() );
        System.out.println( "Bob " + $bob.getPosition() + " " + $bob.getColor() );
        System.out.println( "Tom " + $tom.getPosition() + " " + $tom.getColor() );
end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy