[Drools Planner] Hard constraint appears to be ignored
by Reinis
Hello, it appears that hard constraint I have defined is being ignored
in some rare cases. Here's an example:
This is what my application logs after getting best solution after
solver has returned from solve():
2012-02-23 21:28:54,595 [main] INFO Project Project1 assignment
563:[2012-02-27T13:00:00.000/2012-02-27T17:00:00.000] was assigned to John
2012-02-23 21:28:54,597 [main] INFO Project Project2 assignment
508:[2012-02-27T13:00:00.000/2012-02-27T17:00:00.000] was assigned to John
(The log says that John was assigned twice in same time period to two
different assignments (assignment 563 and assignment 508)
Here short explanation of the relevant domain data
assignment.id = 563
assignment.interval = 2012-02-27T13:00:00.000/2012-02-27T17:00:00.000
assignment.project = Project1
assignment.resource = John
And this is rule that, to my opinion should've prohibited that two
assignments get assigned to the same resource:
rule "only one assignment within interval for the same resource"
when
$leftAssignment : Assignment($leftId : id, $interval :
interval, resource != null, $resource : resource)
$rightAssignment : Assignment(interval == $interval, resource
== $resource, id != $leftId)
then
insertLogical(new IntConstraintOccurrence("only one assignment
within interval for the same resource", ConstraintType.NEGATIVE_HARD, 1,
$leftAssignment, $rightAssignment));
end
The score looks like this:
2012-02-23 21:28:54,594 [main] DEBUG The hard score is: 0 and the soft
score is: -532
So no hard constraints are broken according to planner.
My question is not what is wrong with this particular example (unless it
is obvious for you), but if you can think of any anti-pattern that would
cause this behavior?
What I already checked is:
- this happens really sporadically (most of the time the result is
CORRECT but in 1 from 5 runs I get this kind of error);
- I checked, re-checked and re-re-checked all the hashCode, compareTo,
solutionHashCode, solutionCompare, clone, ... methods - they appear to
be correct;
- moves are simple and I tried to keep them consistent with the way
moves in drools-planner examples are constructed;
Would be great if you could give me a hint to what direction I should
look next.
br
Reinis
14 years
logicalInsert and construction of an inferred fact.
by devan.vanreenen@gmail.com
Hi there,
Kindly assist.
I am playing around with Inference and Truth maintenance
I have 2 questions.
1) When doing a logicalInsert() in the consequence of a rule - is this the
same as doing a insertLogical()? The reason I ask is that when creating rule
in Guvnor it doesnt recognize logicalInsert() but recognizes
insertLogical()?
2) Is there a way for Guvnor to create the inferred fact (dynamically) or
must I create the inferred fact seperately and place in a jar and upload the
the POJO model jar to Guvnor before the inferred fact can be logically
inserted?
Any help would be much appreciated.
Thanks
Devan
--
View this message in context: http://drools.46999.n3.nabble.com/logicalInsert-and-construction-of-an-in...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years
NPE in FireAllRulesCommand (bug?)
by Mike Melton
Drools 5.3.1.Final.
I have a use case where I am executing a BatchExecutionCommand against a
stateless session. One of the sub-commands is a FireAllRulesCommand, from
which I would like to retrieve the number of rules actually fired. Since
there is no factory or constructor method to configure both a maximum rules
to fire and an out identifier, I have to use code like this to set up
my FireAllRulesCommand:
FireAllRulesCommand farc = (FireAllRulesCommand)
CommandFactory.newFireAllRules(maxRulesToFire);
farc.setOutIdentifier("num-rules-fired");
commands.add(farc); // commands is List<Command<?>> which I later use to
construct a BatchExecutionCommand
At runtime, when I execute the BatchExecutionCommand, I get an NPE
at FireAllRulesCommand:110. After some investigating, I determined that the
value returned from (ExecutionResultImpl) ((KnowledgeCommandContext)
context).getExecutionResults() is null, which causes the NPE.
As far as I can tell, the cause of this breaks down like so:
- StatelessKnowledgeSession.execute() fires with the batch command as input.
- It constructs a KnowledgeCommandContext, setting the ExecutionResults
parameter of the constructor to null (line 254).
- KnowledgeCommandContext.executionResults is a private member with no
setter so there is no way to give it a value after it's been instantiated.
- The FireAllRulesCommand fires as part of the batch, and when it tries to
access the execution results from the context, the NPE is thrown.
StatelessKnowledgeSession.execute() later gets the execution results from
the session itself, via the ExecutionResultsImpl instance which is
constructed and passed to the startBatchExecution() method on line 262. I
haven't had time to try this myself, but if we constructed
the ExecutionResultsImpl earlier and passed it to both
the KnowledgeCommandContext constructor and the startBatchExecution()
method, would the problem be alleviated?
In other words, something like this
(StatelessKnowledgeSessionImpl.java:251):
public <T> T execute(Command<T> command) {
StatefulKnowledgeSession ksession = newWorkingMemory();
ExecutionResults results = new ExecutionResultImpl();
KnowledgeCommandContext context = new KnowledgeCommandContext( new
ContextImpl( "ksession",
null ),
null,
null,
ksession,
results
);
try {
((StatefulKnowledgeSessionImpl)
ksession).session.startBatchExecution( results );
If this is indeed a bug and not something silly I'm missing, I'll be happy
to submit a JIRA and even a pull request with the fix.
Thanks
Mike
14 years
Class test fails (!= same as ==)
by Wolfgang Laun
Using 5.3.0.Final, arbitrary facts and the rule shown below:
import org.drools.reteoo.InitialFactImpl
rule "Clear" when
$f: Object() #######
then
if( ! ($f instanceof InitialFactImpl) ){
System.out.println( "retract a " + $f.getClass() );
retract( $f );
}
end
This retracts my Foo, Bar and Counter facts. Good.
$f: Object( class == Foo.class ) ####### changed
This retracts all of my Foo facts. Excellent.
$f: Object( class != Foo.class ) ####### changed again
This retracts only Foo facts. Bad.
-W
14 years
MVEL and nested properties takes longer time to build working memory
by Anto Paul
Hi,
I have rules that uses nested properties. There are more than thousands
of such rules. Before using any nested properties, time to build working
memory(from decision tables) was pretty fast. After using nested
properties, rule compilation time increased by many folds and it is worse
in environments where NAS is used instead of SCSI disks.
Worst thing is I am not able to profile app using VisualVM as it gives
error that 64k limit of instrumented methods exceeded. So took some thread
dump using jstack and see that most often thread is doing class loading.
This is performed by MVEL classes.
On seeing this I used custom class loader in KnowledgeBuilder and
printed all loaded classes. I do not see that MVEL is using custom class
loader and is directly reading class using some other class loader.This
class loading is taking pretty long time when using network disks.
Is there any way to speed up rule compilation time when using nested
properties.Is there anything like a hint to tell MVEL to load fields of an
object directly from that class instead of searching it in entire
classpath? I see something like "m:" in
MVELDialectRuntimeData.getParserConfiguration().
Using Drools 5.30 Final and Decision tables.
Thanks,
Anto
14 years
matches operator
by shawn
Hey there.
I get stuck on using matches operator. The Documentation doesn't say the
operator in details.
I just need to find whether String2 contains String1 (Ignore Case).
Now I have a key(String variable) and a value(String variable).
If I write key matches value, I know it definitely wrong. So is there anyone
knows how to write it?
Cheers.
Shawn
--
View this message in context: http://drools.46999.n3.nabble.com/matches-operator-tp3816492p3816492.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years