Is Drools suitable for preprocessing my Resource Allocation Problem
by Raphael Jolivet
Hello,
Here is a copy of a question I just sent on Stackoverflow :
http://stackoverflow.com/questions/13753983/is-drools-suitable-for-prepro...
I have a quite big resource allocation problem to compute.
I have just discovered Drools and I would like to know if it is a good
candidate to work as a preprocessor and generate a list of forbidden
allocations, based on some user rules.
The ProblemI have an optimisation engine that can allocate some activities
to some resources, while optimizing some KPIs (Key Performance Indicator).
The optimizer takes as input (among others) a list of forbiden allocations
that should be generated based on some user-provided rules.
Each forbid rule is an "AND" composition of two rules:
One for the activity
One for the resource
Each sub rule is itself a list of "AND" tests on some attributes.
Here is the structure of one rule, in Pseudo-Code
Rule1:
* ActivityRule
* activity.prop1 == "foo" AND
* activity.prop2 == "bar" AND
* ...
* ResourceRule
* resource.prop3 == "foobar" AND
* resource.prop4 == "NULL" AND
* ...
Rule2:
...
As soon as a pair of [Activity,Resource] matches one rule, it should be
sent as output, and not tested again against other rules.
Also, this is important to note that some rules will match very often,
while overs will match very rarely (very specific cases).
Performance constraints
Here are some rough hints about the volumetry of the problem :
* 1000 activities
* 200 resources
* 50 rules
I need the forbidden allocations to be generated in under a minute.
The challengeAs far, as I understand, Drools can surely generate those
forbidden allocations. the question is : "How smart is he" ?
If I had to write an engine myself for this particular problem, I would
make some improvements :
For example, I would not generate all possible allocations (200.000) and
then try to apply each rule on it (50 rules x 200.000).
Instead, I would try to match the resources and the activities separately
on each rule (each side of the rule), and then assemble the couples that
match at least one common rule.
Also, I would add some counter on each rule that would auto increment upon
each match, in order to apply first the rules that match often.
QuestionsIs the engine of Drools smart enought for that ? Or is he even
smarter ?
Do you have an example of Drools being used in a similar problem with
success ?
Do you have some hints on how to modelise this problem in Drools ?
Thanks in advance for your advice.
13 years, 4 months
drools memory explosion for quite simple pattern
by michal.antolik
Hello All,
I have a temporal pattern and I'm wondering what's the best way to find
something like:
*stream of messages of type A and B
search for B and give me 5 immediate occurrences of A or B which happened
before B.*
example:
A,A,A,B,B,A,B,A,B,A,A,A,A,A,B,A
should give me:
A,A,A|B
A,A,A,B|B
A,A,B,B,A|B
B,B,A,B,A|B
A,A,A,A,A|B
So I made a pattern like:
$e1 : Event( type== A || type == B) from entry-point "Stream"
$e2 : Event( type== A || type == B, this after[1ms,1m] $e1) from
entry-point "Stream"
$e3 : Event( e type== A || type == B, this after[1ms,1m] $e2) from
entry-point "Stream"
$e4 : Event( type== A || type == B, this after[1ms,1m] $e3) from
entry-point "Stream"
$e5 : Event( type== A || type == B, this after[1ms,1m] $e4) from
entry-point "Stream"
$e : Event( type== B, this after[1ms,1m] $e5 ) from entry-point "Stream"
not( Event( type== A || type == B, this after $e1, this before $e2) from
entry-point "Stream" )
not( Event( type== A || type == B, this after $e2, this before $e3) from
entry-point "Stream" )
not( Event( type== A || type == B, this after $e3, this before $e4)
from entry-point "Stream" )
not( Event( type== A || type == B, this after $e4, this before $e5)
from entry-point "Stream" )
not( Event( type== A || type == B, this after $e5, this before $e)
from entry-point "Stream" )
I also put the time constraint for more constraint search, but the search is
quite slow plus the memory is exploding very fast - several GB in few
seconds.
I also tried to accumulate last 5 events using a floating window, which
helped a lot with performance, but if I would be interested to have only A
preceding B, then it wouldn't help.
Can you pls help me understand what is the best practice to define a drool
pattern for the one I described above?
Thanks a lot!
Michal
--
View this message in context: http://drools.46999.n3.nabble.com/drools-memory-explosion-for-quite-simpl...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 4 months
Rule Match deduplication
by michal.antolik
Hello,
I have a temporal pattern like
*A after B*
and a stream as
*A1,B1,B2,B3,B4,B5,A2,B6*
and if I define a pattern simply as
$a: Event()
$b: Event(this after $a)
I'll get matches like (A1,B1),(A1,B2),(A1,B3),(A1,B4),...
However I care about first match only and then I want to reset the pattern
so the next one would be (A2,B6).
Can you please advice how to achieve that? I don't want to do the
deduplication by myself and most importantly I could achieve much better
performance if I could expire partial matches (I cannot expire event since
it might be used by other patterns)
Thanks a lot for help.
--
View this message in context: http://drools.46999.n3.nabble.com/Rule-Match-deduplication-tp4020717.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 4 months
How to implement the MoveIteratorFactory interface for ?
by 软件0907黄泓
Hi,
I have to implement this interface to meet requirement on performance and to use Random and JUST_IN_TIME configuration in xml. However, all examples provided implement MoveListFactory instead of this interface,and I don't quite understand how to implement the MoveIteratorFactory interface. The reference mannual told me not to create a collection of moves when creating the Iterator<Move>. I don't understand what this means,and how to use the arguments ScoreDirector and Random for each method. How can you get an iterator of moves if you do not make a collection of moves?And I don't quite understand what the reference mannual means by saying "this interface gives you the ability to create a move just in time in the iterator's method next()".Does this mean I only have to provide a collection with only one move that was randomly chosen?Could you provide me an example on how to implement this interface on the curriculumcourse example?
with kind regards
13 years, 4 months
Multi-threading inefficiency caused by static class synchronization?
by ping
hi,
I'm new to Drools and I'm doing some performance benchmark to see if I can
scale up a StatelessSession engine. I did the benchmark on a 8 core machine
but the results shows the engine can only take advantage of 1.5 cores at any
time.
here is my tests:
1. create a KnowledgeBase
2. started multiple threads (I tried 4/8/16 threads) running same loop:
create a stateless session from KnowledgeBase and create a new fact, then
insert the fact into the session.
After running the test for multiple times I found that it can only utilize
at most 1.5 cores at the same time.
I also found that most of time threads were blocked by static class locks
like:
public static synchronized ProcessRuntimeFactoryService
getProcessRuntimeFactoryService()
Anyone has experience scaling up a stateless drools engine?
Thanks a lot.
-Ping
--
View this message in context: http://drools.46999.n3.nabble.com/Multi-threading-inefficiency-caused-by-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 4 months
Drools hangs on parsing a Query
by spotlight2001
*Drools 5.4.0.Final*
Im running a *query* against Drools
It is running for many hours and doesnt seem to return.
This happens in 5% on production. Probably some race problem?
...
query "distributeForMove" (long pSpmaId)
$spma: SubPlanningMatrixOpt ( ..., spmaId == pSpmaId, ...)
...
On suspending the thread
I see that Drools tries to resolve "pSpmaId" as a class
Thread is in status "RUNNABLE"
"jmsWaitingMessageListenerContainer-1" prio=10 tid=0x00002aaed49ad000
nid=0x1719 runnable [0x00000000440e1000]
java.lang.Thread.State: RUNNABLE
at java.util.HashMap.getEntry(Unknown Source)
at java.util.HashMap.containsKey(Unknown Source)
at
org.drools.util.CompositeClassLoader$CachingLoader.load(CompositeClassLoader.java:244)
at
org.drools.util.CompositeClassLoader$CachingLoader.load(CompositeClassLoader.java:237)
at
org.drools.util.CompositeClassLoader.loadClass(CompositeClassLoader.java:88)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at
org.mvel2.ParserConfiguration.checkForDynamicImport(ParserConfiguration.java:159)
at org.mvel2.ParserConfiguration.hasImport(ParserConfiguration.java:187)
at org.mvel2.ParserContext.hasImport(ParserContext.java:352)
at
org.mvel2.compiler.AbstractParser.createPropertyToken(AbstractParser.java:1331)
at org.mvel2.compiler.AbstractParser.nextToken(AbstractParser.java:836)
at
org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:128)
at
org.mvel2.compiler.ExpressionCompiler.compile(ExpressionCompiler.java:62)
at org.mvel2.MVEL.compileExpression(MVEL.java:810)
at
org.drools.rule.constraint.MvelConditionEvaluator.<init>(MvelConditionEvaluator.java:34)
at
org.drools.rule.constraint.MvelConstraint.createMvelConditionEvaluator(MvelConstraint.java:179)
at
org.drools.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:157)
at
org.drools.rule.constraint.MvelConstraint.isAllowedCachedLeft(MvelConstraint.java:136)
at
org.drools.common.SingleNonIndexSkipBetaConstraints.isAllowedCachedLeft(SingleNonIndexSkipBetaConstraints.java:125)
at org.drools.reteoo.JoinNode.assertLeftTuple(JoinNode.java:96)
at
org.drools.reteoo.CompositeLeftTupleSinkAdapter.doPropagateAssertLeftTuple(CompositeLeftTupleSinkAdapter.java:232)
at
org.drools.reteoo.CompositeLeftTupleSinkAdapter.propagateAssertLeftTuple(CompositeLeftTupleSinkAdapter.java:89)
at org.drools.reteoo.JoinNode.assertLeftTuple(JoinNode.java:98)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:196)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.createAndPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:145)
at
org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:154)
at
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:59)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:364)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:235)
at org.drools.reteoo.EntryPointNode.assertQuery(EntryPointNode.java:146)
at
org.drools.reteoo.ReteooWorkingMemory.getQueryResults(ReteooWorkingMemory.java:189)
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-hangs-on-parsing-a-Query-tp40211...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 4 months
Rules not properly re-evaluating in 5.5
by CyBurr
If am using a Stateful knowledge session with a rule flow group. I am
inserting into working memory one instance of each class/type listed below.
All of the rules fire except for rule 14. Rule 14 and 15 are very similar
but for some reason only rule 15 fires. If I swap the physical order of 14
and 15 in the DRL file then rule 14 fires and 15 does NOT. If I change the
order of the LHS conditions for rules 14 and 15 then both rules fire. I am
assuming the order of the LHS conditions or physical order of the rules is
irrelevant. Is that the case? If so, then can someone tell me what I’m
doing wrong?
//*******************Classes/Types***********************************
DRuleContext.java (annotated with @PropertyReactive):
boolean elig;
Date date;
Person.java
String typeID;
String status;
DDE (declared type in Drools. Annotated with @propertyReactive)
drvYear : Integer;
drvStartYear: Integer;
drvEndYear : Integer;
//**********************RULES*****************************************
rule "2"
ruleflow-group "MyGroup"
date-effective "01-Jan-2008"
when
$aPerson : Person( typeID == "AE", status == "S")
$aResponse : DRuleContext()
then
modify ($aResponse) { setElig(true) };
end
rule "12"
ruleflow-group "MyGroup"
date-effective "01-Jan-2008"
when
$aResponse : DRuleContext()
eval(getMonthOfTheDate($aResponse.getDate()) > 6)
$dde : DDE()
then
modify($dde){setDrvYear( getYearOfTheDate($aResponse.getDate()))};
modify($dde){setDrvEndYear ( $dde.getDrvYear() + 1)};
modify($dde){setDrvBeginYear( getYearOfTheDate($aResponse.getDate()))};
end
rule "14"
ruleflow-group "MyGroup"
date-effective "01-Jan-2008"
when
$aResponse : DRuleContext( elig==true)
$dde : DDE( drvBeginYear!=null )
then
modify ($aResponse)
{setFsaStartDate(createDate(07,01,$dde.getDrvBeginPlanYear())) };
end
rule "15"
ruleflow-group "MyGroup"
date-effective "01-Jan-2008"
when
$aResponse : DRuleContext( elig==true)
$dde : DDE( drvEndYear!=null )
then
modify ($aResponse)
{setFsaEndDate(createDate(06,30,$dde.getDrvEndPlanYear())) };
end
--
View this message in context: http://drools.46999.n3.nabble.com/Rules-not-properly-re-evaluating-in-5-5...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 4 months
Problem with KnowledgeBase updates in Guvnor and the Fusion temporal rules with time intervals
by Adrián Paredes
Hi all:
I have a Guvnor Repository with same rules.
Then, I have a web application with a KnowledgeAgent. The agent has the
"drools.agent.newInstance" property in "false", to update the
KnowledgeStatefulSession with every change in the KnowledgeBase, and the
scanning interval setted in 10 seconds.
In my rules, I use temporal operator of Fusion with "befores" and "afters",
and time intervals.
In my web application I have a long running KnowledgeStatefulSession and I
use an AgendaEventListener to fire rules in every activationCreated() event.
My problem is that in each KnowledgeBase update, the session cancels all
the activations created and then creates all activations cancelled again. I
see this because I have a logger in each method of the AgendaEventListener
instance.
If I had a rule of this style in progress:
rule "Basic Rule"
dialect 'mvel'
when
$eventA: EventA($aId: id) from entry-point "time stream"
not EventB($aId == id, this after [0s,5m] $eventA) from entry-point
"time stream"
then
System.out.println("Event A " + $aId + " at " + $eventA.timestamp);
end
And this rule had been activated 2 minutes ago... When the KnowledgeAgent
updates the KnowledgeSession, after a KnowledgeBase update from Guvnor, the
time intervals resets to zero. I guess it must be because the agent cancels
the activations and creates them again.
The result is that the System.out fires 7 minutes after the event was
inserted... 2 minutes later.
I hope you have understood me, despite my english.
Thanks!!
Adrian
--
*Epidata Consulting | Deploying Ideas
Ing. Adrián M. Paredes | Arquitecto Desarrollador
adrianp(a)epidataconsulting.com | Cel: (54911) 3297 1713
----------------------------------------------------------------------------------------------------------------------------
Argentina: Maipú 521 Piso 1 Of. A | Buenos Aires | Of: (5411) 5031 0060
Chile: Apoquindo 3600 Piso 7 y 9 | Las Condes - Santiago | Of: (+56) 2 495
8450
---------------------------------------------------------------------------------------------------------------------------
www.epidataconsulting.com
Linkedin <http://bit.ly/epidatalinkedin> |
Facebook<http://www.facebook.com/epidata.consulting>
| Twitter <http://twitter.com/epidata>
*
13 years, 4 months