Re: [rules-users] Fact Execution Order
by Nawrocki, Dan (IS)
I want to control the order of firing for facts that match a single
rule. I'm using Drools 5.0.1. Is there any way to do this?
My problem can be boiled down as follows. I have an array structure
that I want to conditionally copy to a new array structure. I would
like to order of the destination array to match the source array. The
code to insert facts into working memory increments in ascending order.
It is equivalent to:
for( Object o : sourceArray )
ksess.insert( convertToMyFact( o ) );
I have constructed my rules as such:
rule "rule1"
when
$f : MyFact( prop == "testVal" )
then
copyToDestination( $f.prop, $f.index );
end
After running, however, the destination array appears in reverse order:
source[0] == destination[5]
source[1] == destination[4]
source[2] == destination[3]
source[3] == destination[2]
source[4] == destination[1]
source[5] == destination[0]
Which seems to make sense if the facts are evaluated as if they were
popped off a stack. Is there any way to force Drools to use a list
instead? Or should I just insert facts in reverse order?
I would like the order:
source[0] == destination[0]
source[1] == destination[1]
etc.
Thanks,
Dan
14 years, 3 months
Error: unable to resolve method
by xalperte
I'm having a problem a little odd trying to fire rules using the Guvnor.
In Guvnor I have a package named package kobo.regularSafaris, inside this
package I have defined rules (with some DSL definitions), a decision table
(xls) and two functions.
The problem is that when I'm trying to call the functions in the consequence
of a rule I'm having the following error:
org.drools.runtime.rule.ConsequenceException: [Error: unable to resolve
method:
kobo.regularSafaris.AddBookingPayment.addBookingPayment(kobo.regularSafaris.BookingRequest,
java.lang.Integer, java.lang.Integer) [arglength=3]]
[Near : {... Unknown ....}]
^
[Line: 1, Column: 0]
at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:23)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:943)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:885)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1086)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:660)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:632)
at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:187)
at
com.rudder.packages.test.rules.PricesRulesTestCase.testNobelLowSeasonPrices(PricesRulesTestCase.java:108)
The function definition is as follows:
function void addBookingPayment(BookingRequest request, int days, int
percentage) {
PaymentPolicy payment = new PaymentPolicy();
payment.setPercentage(percentage);
if( days > 0 ) {
DateMidnight dueDate = new
DateMidnight(request.getDepartureDate().getTime()).minusDays(days);
payment.setType("DEFERRED");
payment.setDueDate(dueDate.toDate());
} else {
payment.setType("NOW");
payment.setDueDate(null);
}
List payments = request.getBookingData().getPayments();
if(payments == null) {
payments = new ArrayList();
request.getBookingData().setPayments(payments);
}
payments.add(payment);
}
And the rule that is calling the function is the following:
rule "Def. Deferred Payment for Credit Operator"
dialect "mvel"
when
$request: BookingRequest()
user: User(type == "Professional") from $request.user
eval($request.getBookingData().getPayments() == null) || ArrayList(size ==
0) from $request.bookingData.payments
eval( "true".equals($request.getUser().getTags().get("hasCredit")))
eval( (new
DateMidnight($request.getDepartureDate().getTime())).minusDays(35).toDate().after(new
Date()))
then
addBookingPayment($request, 35, 100);
end
It seems that the system is adding an extra "AddBookingPayment" to the
package name and this is causing the problem. Why is doing that? how can i
solve this?
Thanks in advance
--
View this message in context: http://n3.nabble.com/Error-unable-to-resolve-method-tp108194p108194.html
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 3 months
Re: [rules-users] Nesting rules in Drools 5.x
by Greg Barton
I think this is fixed in trunk.
GreG
On Jan 3, 2010, at 0:56, orchid <maya.pollack(a)gmail.com> wrote:
Hi All,
I'm trying to nest the LHS of rules in the following way:
rule "Rule_stilton"
when
$c : Cheese (type == "stilton")
then
$c.addRuleToList( "Rule_stilton" );
System.out.println("Rule_stilton was fired");
end
rule "Rule_price" extends "Rule_stilton"
when
Cheese(price <= 6.00) from $c
then
$c.addRuleToList( "Rule_price" );
System.out.println("Rule_price was fired");
End
The class Cheese contains a list field of matching rules of that instance
and a public function 'addRuleToList', which adds the rule name into that
list.
I get build error: "Unable to find declaration in list while generating the
consequence invoker". Is there some other way to reach that?
Thanks in advance.
Any help will be appreciated.
--
View this message in context: http://n3.nabble.com/Nesting-rules-in-Drools-5-x-tp106902p106902.html
Sent from the Drools - User mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
14 years, 3 months
How to check an array field from LHS of a rule
by orchid
Hi All,
I'm using Drools 5.x. I have the following class:
public class Machine{
...
private List rules = new ArrayList();
...
}
The 'rules' list holds strings. I would like from my rule to check whether
that list contains the string "rule2".
I've tried doing this in the following ways, but get compilation error:
rule "rule1"
when
/*1st attempt:*/ $m:Machine(rules contains "rule2")
/*2nd attempt:*/ $m:Machine(rules.contains("rule2") )
then
...
What am I doing wrong?
Thanks in advance !!!
--
View this message in context: http://n3.nabble.com/How-to-check-an-array-field-from-LHS-of-a-rule-tp104...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 3 months
Nesting rules in Drools 5.x
by orchid
Hi All,
I'm trying to nest the LHS of rules in the following way:
rule "Rule_stilton"
when
$c : Cheese (type == "stilton")
then
$c.addRuleToList( "Rule_stilton" );
System.out.println("Rule_stilton was fired");
end
rule "Rule_price" extends "Rule_stilton"
when
Cheese(price <= 6.00) from $c
then
$c.addRuleToList( "Rule_price" );
System.out.println("Rule_price was fired");
End
The class Cheese contains a list field of matching rules of that instance
and a public function 'addRuleToList', which adds the rule name into that
list.
I get build error: "Unable to find declaration in list while generating the
consequence invoker". Is there some other way to reach that?
Thanks in advance.
Any help will be appreciated.
--
View this message in context: http://n3.nabble.com/Nesting-rules-in-Drools-5-x-tp106902p106902.html
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 3 months
Quantification of possible planner/solver solutions
by Pete Carapetyan
Geoffrey:
It is a source of fascination to me that you were able to come up with
a number for how many possible planner combinations there were for
each planner/solver example.
For example, where this kind of calculation comes from or how to derive my own ?
Example from Drools Solver Manual:
Set # students # exams/topics # periods # rooms #
possible solutions
exam_comp_set1 7883 607 54 7
1.11000574474221096210367623e+1052
14 years, 3 months