[rules-users] Reg. Iterating over a list
Hi. I tried to identify relevant ways for some container specific operations like exists, forall (or foreach). Basically I have started using for software product line research, and specifically model checking over product line models. The initial results so fat ( considering the time I started) have been wonderful, alas I am tuck at this point. For example, consider : import java.util.List; import java.util.Arrays; import java.util.ArrayList; declare Project a : int b : int = 5 list : List = new java.util.ArrayList(java.util.Arrays.asList(1 , 2 , 3 , 4 , 5)) end Now that the element of Project - list is configured, I would like to perform some operations on it like: a) for each - for the list (Project - P; P.list), is each element is greater than 2? (or in essence - evaluating each element using a boolean expression). b) Similarly, a function like exists . for the list, is there any element for which this expression is satisfied - t > 2 && t < 5, where t is the iterator for the list. As the elements of the lists are mere numbers (in this case ints), I am not really aware/clear how I can use the Drools operations collect, for all etc. Previously I worked with Jess rule engine, and it has in built lambda functions which nicely provides list iterators and thus evaluating each element of the list against a boolean expression. I am at a very important point in my work, and any hint or solution will be highly appreciated. Many thanks :) Phani -- View this message in context: http://drools.46999.n3.nabble.com/Reg-Iterating-over-a-list-tp4019512.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Reg. Iterating over a list
Hi Thank you very much I partly succeeded using your suggestion. I particularly did the following: rule "list rule " agenda-group "Group 2" dialect "mvel" no-loop true when P : Project(isDefined(P.seq_B)) s : java.util.ArrayList() from collect ( Integer (!(this > 0 && this < 3)) from P.seq_A) //( Integer (this > 0 && this < 3) from P.seq_A); then System.out.println("Rule satisfied # " + P.seq_A); //modify(P) {seq_B = s}; end However, I would like to do every thing all at once in the LHS, or maybe RHS. This is because I have to work around similar functions like the following: 1) collect from collectionA with a boolean constraint into collectionB 2 ) similarly, collect everything that does not satisfy. Custom evaluators - sounds interesting. Sadly, I did not find it. Would be very much useful if you can share an example. Many thanks :) -- View this message in context: http://drools.46999.n3.nabble.com/Reg-Iterating-over-a-list-tp4019512p4019562.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Reg. Iterating over a list
Another issue I am stuck up is again a container operation (:( ). I have my rule something like this: //I have a global List defined as global java.util.ArrayList cList // Function isDefined as : function boolean isDefined(Object o) { return o != null; } //size as function int size(List list) { return list.size(); } //and finally append as function List append(List list, Number num) { list.add(num); return list; } rule "94" agenda-group "Group 2" dialect "mvel" no-loop true when P : Project() Project( isDefined(seq_A) && !(size(append(seq_A , 99 )) > 4)) then System.out.println("Rule not satisfied # " + 94 + setStatics() ); cList.add(94); end . I declared a type called "Project" which basically holds the variables seq_A, seq_B and everything else. I configured the value of seq_A using a rule - with agenda group as "Config rule". The problem with the rule is that, it is firing and activating a similar rule in a different agenda group. However, I am setting focus for each group separately and firing rules like the following: ksession.getAgenda().getAgendaGroup("Group Config").setFocus(); ksession.fireAllRules(); ksession.getAgenda().getAgendaGroup("Group 0").setFocus(); ksession.fireAllRules(); ksession.getAgenda().getAgendaGroup("Group 1").setFocus(); ksession.fireAllRules(); ksession.getAgenda().getAgendaGroup("Group 2").setFocus(); ksession.fireAllRules(); After the rules are fired, I am getting the value for P_seqA as [1, 2, 3, 4, 5, 199, 199], where as my intention was to to get [1, 2, 3, 4, 5, 199]. In essence, the append function is being called two times. This is the same case for any of the append (and prepend) operations, I am doing. This seems to be very confusing to me and I have already spend hours on this. I just do not want to activate rules outside the current agenda group. Many many thanks in advance :) -- View this message in context: http://drools.46999.n3.nabble.com/Reg-Iterating-over-a-list-tp4019512p4019563.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Reg. Iterating over a list
Oh Ok, I get the point. The engine evaluates all the patterns when the current rule is being evaluated. And I have (!size(append(list, number)) > 0) on the LHS, and so the append function is being evaluated. Is it possible to command the engine to not check patterns of a certain rules or certain agenda groups. BR Phani -- View this message in context: http://drools.46999.n3.nabble.com/Reg-Iterating-over-a-list-tp4019512p4019572.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Combining Drools Expert and Planner
Hi. Is it possible to combine Drools expert and planner to solve NP problems (or some kind of model checking). For example, I have a model described as a .drl file declare Project x : int end And, then I have a constraint (or rule) - something like this - rule " Rule on x" agenda-group "Group 2" dialect "mvel" no-loop true when P : Project(P.x > 5 && P.x < 7) then System.out.println("Rule satisfied"); end Is it possible to obtain a value propagation mechanism by combining with Planner, by which I finally get a value for x as 6 ? I am working on model checking for models that have various constraints, on boolean, int, real, strings, container types and also on types that are similar to C structs. There is hardly any reasoner/solver that does model checking for constraints on such a varied types of datatypes. I checked planner, but defining planning variables and stuff on score generation seemed to me a bit new and confusing. Thank you :) -- View this message in context: http://drools.46999.n3.nabble.com/Combining-Drools-Expert-and-Planner-tp4019871.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Declared Types with large number of fields
Hi. I am using declared types in .drl rule rule. When I kept the number of fields in a declared type low, drools works fine. When I am increasing the number of fields in a declared type to 300 or even more, drools raising an exception. Particularly, it is giving this. ava.lang.ClassFormatError: Too many arguments in method signature in class file com/sample/Project at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) at java.lang.ClassLoader.defineClass(ClassLoader.java:615) at org.drools.rule.JavaDialectRuntimeData$PackageClassLoader.fastFindClass(JavaDialectRuntimeData.java:615) at org.drools.util.CompositeClassLoader$CachingLoader.load(CompositeClassLoader.java:254) at org.drools.util.CompositeClassLoader$CachingLoader.load(CompositeClassLoader.java:237) at org.drools.util.CompositeClassLoader.loadClass(CompositeClassLoader.java:88) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) at org.drools.base.ClassTypeResolver.resolveType(ClassTypeResolver.java:155) at org.drools.compiler.PackageBuilder.processTypeDeclarations(PackageBuilder.java:2049) at org.drools.compiler.PackageBuilder.mergePackage(PackageBuilder.java:1218) at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:829) at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:467) at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:673) at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:45) at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:34) at com.sample.DroolsTest.readKnowledgeBase(DroolsTest.java:67) at com.sample.DroolsTest.main(DroolsTest.java:24) I suspect, it is something to do with creating class, constructor with so many arguments at run time. I am looking for a solution, something like declared types, or a workaround. The purpose for which I am using Drools limits to use the traditional Java classes, or defining a Java class. Also, is there any way, to perform calculations, or value propagations. That, Drools could assume some value to a variable given a certain constraint on it. For example, x > 6 && x < 9, Drools could assume x as 7 or 8 and fire rules? Thank you. Phani -- View this message in context: http://drools.46999.n3.nabble.com/Declared-Types-with-large-number-of-fields-tp4020076.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Speeding up Drools
HI. I am using declared types in my .drl file. I have a declared type with 1000 fields (using the Drools 5.5. beta, so 1000 fields is allowed). I have 100 rules. However, creating the stateful knowledge base is very slow. It is taking nearly 8 seconds. Can somebody tell me, suggest how can I speed up the process? Briefly, this is how I measured. long loadI = System.currentTimeMillis(); // load up the knowledge base KnowledgeBase kbase = readKnowledgeBase(); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); ksession.setGlobal("cList", new ArrayList()); FactType fact = kbase.getFactType("com.sample", "Project"); Object projIns = fact.newInstance(); ksession.insert(projIns); long loadO = System.currentTimeMillis(); System.out.println("time to load facts : " + ((loadO / 1000.0) - (loadI / 1000.0))); ksession.getAgenda().getAgendaGroup("Group Config").setFocus(); ksession.fireAllRules(); ksession.getAgenda().getAgendaGroup("Fact Config").setFocus(); ksession.fireAllRules(); ksession.getAgenda().getAgendaGroup("Group 0").setFocus(); ksession.fireAllRules(); ksession.getAgenda().getAgendaGroup("Group 1").setFocus(); ksession.fireAllRules(); ksession.getAgenda().getAgendaGroup("Group 2").setFocus(); ksession.fireAllRules(); Many thanks Phani -- View this message in context: http://drools.46999.n3.nabble.com/Speeding-up-Drools-tp4020132.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Iterating facts
Hi. 1) I could list all the facts via knowledge session.facthandle.iterator. 2) I could iterate over the objects contained in a fact. For example: List fFields = ksession.getKnowledgeBase().getFactType(pckg, "Project").getFields(); 3) I could get the name of the object and retrieve the contained value as a string if it is a primitive datatype - int, real, boolean. 4) The problem for me is I am not able to retrieve the values of the inner fields of an object. For example, fFields.get(0).get(projIns) - yields me C( a=1, bool=false, cc=0 ), I could retrieve this particular objects' name and also the inner fields' names, but not the contained values for a, bool and cc. I have tried java reflection, but no positive result so far. I am using declared types, with no metadata. Any other nice way to tackle this problem. Thank you. -- View this message in context: http://drools.46999.n3.nabble.com/Iterating-facts-tp4020214.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Reg. Rule parsing & MVEL Dialect
Hi. Is there any valid impression that MVEL parsing can cause performance bottlenecks as far is drools is concerned? Or to put it in a better way, I have 500 rules, patterns for each rule are bit complex, and my observations are that rule parsing (or grammar formation) is very time consuming. Would this be better if I use Java dialect. To be very precise my issue is, I have a type declaration with 1000 variables and 500 rules. Each rule has a complex pattern. It is taking lot of time to parse and for the grammar. And secondly, inserting an initial fact is tending to be time consuming. Many thanks. -- View this message in context: http://drools.46999.n3.nabble.com/Reg-Rule-parsing-MVEL-Dialect-tp4020730.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Constraints over Lists
Hi, I have a query reg. writing constraints over lists. Precisely heres what I m doing //Imports import java.util.List; import java.util.Set; import java.util.Arrays; import java.util.ArrayList; //My methods - functions function boolean isDefined(Object ob) { return ob != null; } function boolean neqq(List l1, List l2) { return l1 != l2; } //List declaration declare Project @typesafe (false) list1 : List list2 : List end //Initial declaration rule rule " Config rule " agenda-group "Group Config" dialect "mvel" no-loop true lock-on-active true when P : Project() then modify(P) { list1 = new java.util.ArrayList(java.util.Arrays.asList(10, 15, 20, 25)), list2 = new java.util.ArrayList(java.util.Arrays.asList(11, 2, 3, 4, 5, 10, 9, 8, 7)) }; update(P); end //Rule-constraint rule "listEq1" agenda-group "Group 2" dialect "mvel" no-loop true lock-on-active true when P : Project( isDefined(P.list1) && neqq(P.list1, new java.util.ArrayList(java.util.Arrays.asList(1, 2, 3))) ) then System.out.println("Lists are not equal - 1"); end //Rule - constraint 2 rule "listEq2" agenda-group "Group 2" dialect "mvel" no-loop true lock-on-active true when P : Project( isDefined(P.list1) && isDefined(P.list2) && neqq(P.list1, P.list2) ) then System.out.println("Lists are not equal - 2"); end ** If I remove the rule "listEq1", everything works fine, other it raises several exceptions like - Exception executing consequence for rule " Config rule " - cannot invoke method asList - cannot invoke method neqq Can anyone tell me whats going on here, whats the reason for this. Many thanks :) Phani -- View this message in context: http://drools.46999.n3.nabble.com/Constraints-over-Lists-tp4021715.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Constraints over Lists
Hi Thank you for the reply. That actually did not help. However, I found another way of writing the rule involving a method. It is as follows: rule "listEq1" when P : Project() eval( isDefined(P.list1) && neqq(P.getList1(), new ArrayList(Arrays.asList( new Object[] {1, 2, 3} then System.out.println("Lists are not equal - 1"); end Kind of strange, but works. -- View this message in context: http://drools.46999.n3.nabble.com/Constraints-over-Lists-tp4021715p4021753.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users