Future events
by lexsoto
Hello:
I have this rule:
An event is inserted that has a timestamp in the future, the rule is fired.
This looks like a bug, because the sliding time window has not yet met the
timestamp of the event.
I expect the rule to fire not immediately but only when the time reaches the
event time.
Is my assumption/understanding correct?
--
View this message in context: http://drools.46999.n3.nabble.com/Future-events-tp3826236p3826236.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years
[rule-users]Drools Fact Management with Large Dataset in RDBMS
by CW
Thank you in advance for your time reading this post first.
I have to make my rules work with databases with TB of data, so fact
management become a major issue when I design my system. Currently I have
several main programs which use both stateful and stateless sessions. I
would like to collect some good practices to manage the insertion and
disposal of facts so that I can keep my working memory healthy. Below are
some of my findings in this forum:
1. Insert only relevant facts into working memory with the use of "data
preparation" rule together with Drools pipeline (hibernate, mybatis, etc).
An excellent example from manstis in the post
http://drools.46999.n3.nabble.com/Applying-rules-on-the-data-in-an-RDBMS-...
---------------------
rule "bootstrap"
salience -100
when
$list : List( ) from placeHolder.namedQuery("Smurfs")
then
for(ExternalObject o : $list ) {
insert( o );
}
end
--------------------
2. Use "insertlogical" instead of "insert" when inserting facts in rule
3. Implement "garbage collection" rule to clean up unwanted facts
I would like to ask:
1. if there are any other suggestion on optimizing fact management?
2. is there a way for the rule engine to directly operate on data in
database (perhaps with some other plugin?)
Thanks again!
--
View this message in context: http://drools.46999.n3.nabble.com/rule-users-Drools-Fact-Management-with-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years
Nesting prefix-or and prefix-and causing parsing problem
by Patrik Dufresne
Hi,
I have a problem with nesting prefix-and and prefix-or. I found a bug in
JIRA but it been fixed in drools expert 5.0. Here is snippet to reproduce
the problem (based on the original rule). I get the following error :
java.lang.RuntimeException: [48,5]: [ERR 102] Line 48:5 mismatched input
'EmployeePreferredShift' in rule "assign-preferred-position"
declare EntityA
number : int
end
declare EntityB
number : int
end
declare EntityC
number : int
end
rule "and-or-snippet"
dialect "java"
when
EntityA(
$number : number)
not ( and
EntityB (
number == $number )
( or
( and
EntityC (
number < $number)
not EntityB (
number == 4)
)
not EntityC (
number == 10 )
)
EntityA (
number <= $number )
( or
not EntityC (
number >= $number)
( and
EntityC (
number == 4 || number >=10 )
not EntityB (
number == -3)
not EntityB (
number == -10 )
)
)
not EntityB(
number == 0)
)
then
System.out.println("Working");
end
Patrik Dufresne
14 years
Drools and Jersey
by mike
Hi there,
I am trying to make rest calls from Drools. For that I am using Jersey
http://jersey.java.net/. I cannot no get it to work if I use mvel,
otherwise it works fine.
Here is a sample rule:
----------------------------------------------------------
import com.sun.jersey.api.client.Client;
dialect "mvel"
rule "create Rest Client"
then new Client();
end
----------------------------------------------------------
I would love to be able to use mvel since it curves java syntax :)
Thank you
Mike
14 years
drools arithmetics without eval()
by fx242
I have a question regarding eval() use. My rulebase is around ~3k rules, most
of them are auto-generated by templates, and they end up looking like this:
rule "CONFIG_114"
salience 0
when
client: Client()
contextProd: PortfolioProduct(prodAdded == true, productId ==
"PROFESSIONAL")
Number(qty_00001: intValue) from accumulate(pp:
PortfolioProduct(productId in ("BOX_001"), prodAdded == true), count(pp))
Number(qty_00002: intValue) from accumulate(pp:
PortfolioProduct(productId in ("BOX_002"), prodAdded == true), count(pp))
Number(qty_00003: intValue) from accumulate(pp:
PortfolioProduct(productId in ("BOX_003"), prodAdded == true), count(pp))
Number(qty_00004: intValue) from accumulate(pp:
PortfolioProduct(productId in ("BOX_004"), prodAdded == true), count(pp))
Number(qty_00005: intValue) from accumulate(pp:
PortfolioProduct(productId in ("BOX_005"), prodAdded == true), count(pp))
eval(qty_00001 == 1)
not(eval(qty_00002 >= (qty_00003 + qty_00004 + qty_00005)))
then
balance(kcontext, contextProd, qty_00002, ">=", (qty_00003 + qty_00004 +
qty_00005));
end
These rules have all one or two evals in the end, comparing product
quantities that are present in the Working Memory.
My question is: Is there any better way to write this kind of rules without
resorting to eval()?
I'm currently getting hit (in performance terms) by over-using these, so I
wonder if there is a better way to do this.
Thanks!
Tiago Lopes
--
View this message in context: http://drools.46999.n3.nabble.com/drools-arithmetics-without-eval-tp38232...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years
Problem with temporal operations spanning daylight to standard time
by lhorton
Most of the USA went from Standard Time to Daylight Time this past weekend.
We use some of the temporal operations in our rules, mainly to do
calculations of date differences by whole days, and some of the calculations
are wrong. The ones in error involve comparing dates where one is standard
time and one is daylight savings time. I wrote a small test case to prove
this.
I have a simple Person class:
public class Person {
private Date birthdate;
private int status;
public Date getBirthdate() {
return birthdate;
}
public void setBirthdate(Date birthdate) {
this.birthdate = birthdate;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
}
and a simple drl file:
package com.drools.resources;
import com.drools.person.Person;
import java.util.Date;
import java.util.Calendar;
global Long now
rule "Birthday Rule"
dialect "mvel"
when
$person : Person(birthdate != null)
Date($bDate : time before[3d] now) from $person.birthdate
then
$person.setStatus(3);
end
rule "Debug Birthday Rule"
dialect "mvel"
when
$person : Person(birthdate != null)
then
System.out.println("now is " + new Date(now));
System.out.println("birthdate is " + $person.getBirthdate());
end
and two tests:
@Test
public void testTemporalJanuary() throws Exception {
KnowledgeBase base =
createKnowledgeBaseFromRulesFile("src/com/drools/resources/temporal.drl");
StatelessKnowledgeSession kSession =
createStatelessKnowledgeSession(base);
// test january - both dates are standard time
Date now = new Date(2012-1900, 00, 13);
kSession.getGlobals().set("now", now.getTime());
Person p = new Person();
p.setStatus(0);
p.setBirthdate(new Date(2012-1900, 00, 10));
kSession.execute(p);
assertTrue(p.getStatus() == 3);
}
@Test
public void testTemporalMarch() throws Exception {
KnowledgeBase base =
createKnowledgeBaseFromRulesFile("src/com/drools/resources/temporal.drl");
StatelessKnowledgeSession kSession =
createStatelessKnowledgeSession(base);
// test March: one day standard, the other is daylight
Date now = new Date(2012-1900, 02, 13);
kSession.getGlobals().set("now", now.getTime());
Person p = new Person();
p.setStatus(0);
p.setBirthdate(new Date(2012-1900, 02, 10));
kSession.execute(p);
assertTrue(p.getStatus() == 3);
}
the first test (testTemporalJanuary) compares January 13 to January 10, and
it passes (matches the before[3d] condition).
the second test (testTemporalMarch, which is the same except for using March
instead of January) fails.
The output of the debug rule for these tests is:
now is Fri Jan 13 00:00:00 PST 2012
birthdate is Tue Jan 10 00:00:00 PST 2012
now is Tue Mar 13 00:00:00 PDT 2012
birthdate is Sat Mar 10 00:00:00 PST 2012
--
View this message in context: http://drools.46999.n3.nabble.com/Problem-with-temporal-operations-spanni...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years
Avoid propagation of update in a then block.
by Patrik Dufresne
Hi,
I have some trouble to figure out how to stop / start the propagation of
updates within a Then block.
Here is a snippet to represent the problem I have.
rule "my-rule"
when
$objects : List()
from accumulate( $entity : Entity(closed==false),
collectList($entity) )
then
for(Object obj : $objects) {
((Entity) obj).setClosed(true);
update(obj);
}
end
When this rule's consequence is called first, the first enity in the list
is 'update', but then update if propagated to immediately causing the rule
to be evaluated with all the entities minus the updated one. So I'm
wondering if there is a transaction like operation allowing me to update
all the entities in the list and then fire the rules.
According to the documentation no-loop should have help me for this.
Here is the original rules
rule "close-shift"
salience -1
when
$shift : Shift( )
$assignments : List( size > 0 )
from accumulate (
$assignment : PlanifEventAssignment(
close == false,
shift == $shift ),
collectList($assignment) )
$availables : List( size >= $assignments.size )
from accumulate ( ( and
ShiftAssignment(
shift == $shift,
$employee : employee)
$available : EmployeeAvailable (
employee == $employee,
assignment.shift == $shift) ),
collectList($available) )
eval( Dfs.search($assignments, $availables) != null )
then
// Recalculate the result.
Map table = Dfs.search($assignments, $availables);
for(Object entry : table.entrySet()) {
PlanifEventAssignment assignment =
(PlanifEventAssignment)((Entry)entry).getKey();
EmployeeValue employee = (EmployeeValue)((Entry)entry).getValue();
assignment.setClose(true);
assignment.setEmployee(employee);
update(assignment);
}
end
Patrik Dufresne
14 years