[rules-users] Problem with Student - module example

Anstis, Michael (M.) manstis1 at ford.com
Mon Aug 20 09:06:21 EDT 2007


I assume you also insert s1 and m1 to working memory?

What if you re-write the rule as two patterns (there is an implicit AND
between patterns)

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

With kind regards,

Mike 

-----Original Message-----
From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Dave, Rajeev
Sent: 20 August 2007 13:02
To: Rules Users List
Subject: [rules-users] Problem with Student - module example

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


_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users




More information about the rules-users mailing list