[rules-users] Problem with Student - module example

Dave, Rajeev Rajeev.Dave at fmr.com
Mon Aug 20 08:01:46 EDT 2007


Given:
Student.java
public class Student {
    private String name;
    private ArrayList modules = new ArrayList();
...
}

Module.java
public class Module {
	private String name;
    private Student student;
    private int score;
...
}

Rule:
exists( $student : Student() && Module( student == $student && score >
40 ) )

Problem statement:
I assert 2 Students and 2 modules in the session
	Student s = new Student(), s1 = new Student();
      Module m = new Module(), m1 = new Module();
      m.setName("English"); m.setStudent(s); m.setScore(10);
      s.setName("abc"); s.addModule(m);
            
      m1.setName("English1"); m1.setStudent(s1); m1.setScore(50);
      s1.setName("xyz"); s1.addModule(m1);
      
	workingMemory.insert(m);
      workingMemory.insert(s);

Result:
I  get 2 activations. I am expecting only 1 activation as only xyz
student has score > 40

Am I missing something or is this a bug?

Rgds,
rajeev





More information about the rules-users mailing list