Re: [rules-users] insertLogical and modifyRetract (drools-solver)
by tim tim
thanks, you are right, that is kind of a solution. but not really what i am
looking for.
i am using drools-solver, and the "CreatedFact" is an
IntConstraintOccurrence, which i do not want to change.
maybe i should make the example more specific for my problem.
i have a rule, used for the solver:
rule "fact1 should be smaller then 1"
when
$f : UserFact(fact1 >= 1);
then
// use the value of fact1 to determine the error
insertLogical(new IntConstraintOccurence("fact1 should be smaller
then 1", $f.getFact1(), $f ));
end
i have a Move that decrements fact1, so that after the move the error should
be 1 smaller.
but the move is almost never triggered, because the old constraintOccurence
is not retracted from memory and the new one added anyway,
hence the error is nearly double after the move, as now two
constraintOccurences represent the same error.
what i could think of is something like this:
one rule for the first test:
rule "fact1 should be smaller then 1"
when
$f : UserFact(fact1 >= 1)
not IntConstraintOccurence(
ruleId == "fact1 should be smaller then 1",
constraintType ==
ConstraintType.NEGATIVE_SOFT,
causes contains $f)
then
// use the value of fact1 to determine the error
insertLogical(new IntConstraintOccurence("fact1 should be smaller
then 1", $f.getFact1(), $f ));
end
and a second rule, when the first rule has already fired before:
rule "fact1 should be smaller then 1, old constraint exists"
when
$f : UserFact(fact1 >= 1);
// see if there is already a fact in the
$oldConstraint : IntConstraintOccurence(
ruleId == "fact1 should be smaller then 1",
constraintType ==
ConstraintType.NEGATIVE_SOFT,
causes contains $f)
then
retract($oldConstraint); // manually retract the obsolete fact
// use the value of fact1 to determine the error
insertLogical(new IntConstraintOccurence("fact1 should be smaller
then 1",ConstraintType.NEGATIVE_SOFT, $f.getFact1(), $f ));
end
this solution seems very verbose for such a common task. and again, i do not
understand, why an obsolete fact is not
retracted automatically?
best, tim
On Tue, Oct 7, 2008 at 5:57 PM, Gras, Patrick <Patrick.Gras(a)generali.ch>wrote:
> Hello,
>
> If you can change the code for CreatedFact and let it have a reference to
> UserFact and change the rule to:
>
> rule "fact = 1"
> when
> $f : UserFact(fact1 == 1);
> then
> insertLogical(new CreatedFact($f));
> end
> you will also have to overide equals and hashcode for CreatedFact so that
> several CreatedFacts referencing the same UserFact are considered equal...
>
> But with this solution CreatedFact will always be up to date with the value
> of UserFact even without firing the rules and maybe it's not what you
> want...
>
> -Patrick
>
> -----Message d'origine-----
> *De :* rules-users-bounces(a)lists.jboss.org [mailto:
> rules-users-bounces(a)lists.jboss.org]*De la part de* tim tim
> *Envoyé :* mardi, 7. octobre 2008 16:53
> *À :* rules-users(a)lists.jboss.org
> *Objet :* [rules-users] insertLogical and modifyRetract
>
> Hello,
>
> I am a bit confused about how insertLogical() supposed to work in drools 5.
>
> when i have a rule such as:
>
> rule "fact = 1"
> when
> $f : UserFact(fact1 == 1);
> then
> insertLogical(new CreatedFact($f.getFact2()));
> end
>
> now i change $f in such a way, that the rule will fire again.
> via
>
> // build first version
> UserFact f = new UserFact();
> f.setFact1(1);
> f.setFact2(1);
>
> memory.insert(f);
> memory.fireAllRules(); // <- Rule fires once
>
> // now i change the memory and fire the rules again
>
> memory.modifyRetract(f) ;
> f.setFact2(100); // <- changing $f, but leaving fact1 as it is.
> memory.modifyInsert(f);
>
> memory.fireAllRules(); // <- Rule fires again
>
> now the rule should fire again, which it does.
> but i end up with two CreatedFact instances in the workingMemory..
> one with the old OtherFact value 1, and one with the new value, 100
>
> but i want only the second instance. the one created first is not valid any
> more.
> i could write an extra rule for retracting the first CreatedFact-fact, but
> then i would have
> a very tight coupling of the two rules.
>
> is there a better way?
> it seems odd to me, that a consequence of a rule stays in memory, when
> there is
> a more current version of the rule evocation with the _same_ facts in the
> precondition
> and a different consequence.
>
> thanks in advance, tim
>
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
17 years, 8 months
insertLogical and modifyRetract
by tim tim
Hello,
I am a bit confused about how insertLogical() supposed to work in drools 5.
when i have a rule such as:
rule "fact = 1"
when
$f : UserFact(fact1 == 1);
then
insertLogical(new CreatedFact($f.getFact2()));
end
now i change $f in such a way, that the rule will fire again.
via
// build first version
UserFact f = new UserFact();
f.setFact1(1);
f.setFact2(1);
memory.insert(f);
memory.fireAllRules(); // <- Rule fires once
// now i change the memory and fire the rules again
memory.modifyRetract(f) ;
f.setFact2(100); // <- changing $f, but leaving fact1 as it is.
memory.modifyInsert(f);
memory.fireAllRules(); // <- Rule fires again
now the rule should fire again, which it does.
but i end up with two CreatedFact instances in the workingMemory..
one with the old OtherFact value 1, and one with the new value, 100
but i want only the second instance. the one created first is not valid any
more.
i could write an extra rule for retracting the first CreatedFact-fact, but
then i would have
a very tight coupling of the two rules.
is there a better way?
it seems odd to me, that a consequence of a rule stays in memory, when there
is
a more current version of the rule evocation with the _same_ facts in the
precondition
and a different consequence.
thanks in advance, tim
17 years, 8 months
possible bug with event declarations
by Michal Bali
Hi,
Should it be possible to declare an event role to an existing type that is
outside of the current rule package?
Example:
In the following file:
http://fisheye.jboss.org/browse/JBossRules/trunk/drools-compiler/src/test...
change the first line to:
package org.droolsssssss; //this makes sure that StockTick is in different
package
now, the test org.drools.integrationtests.StreamsTest.testEventAssertion()
throws following exception:
org.drools.RuntimeDroolsException: unable to resolve Type Declaration class
'StockTick'
at
org.drools.common.AbstractRuleBase.addPackage(AbstractRuleBase.java:484)
at org.drools.reteoo.ReteooRuleBase.addPackage(ReteooRuleBase.java:381)
at
org.drools.integrationtests.StreamsTest.loadRuleBase(StreamsTest.java:93)
at
org.drools.integrationtests.StreamsTest.testEventAssertion(StreamsTest.java:101)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Best Regards,
Michal
17 years, 8 months
Parallell rules execution?
by Magnus Heino
I remember reading something somewhere a while ago about Drools 5 and
parallel rules execution...?
Is there any info available on this? Is it available in 5M2? When will it be
available? What are the features? Are the any docs now? etc...
Thanks!
/Magnus Heino
17 years, 8 months
not exists / forall(not) logically equivalent, behave differently
by tim tim
hello there,
i have a rule, that should fire, when a required part of a whole is missing.
lets say the whole is a dog, and the required part the tail.
then the rule should fire, when there is a dog without a tail.
i stated the rule in two logically equivalent ways.
1) when we have a dog, and all existing tails belong to other peoples dogs,
the rule should fire:
rule "no dog without a tail; forall"
when
$dog :Dog()
forall($t : Tail()
Tail(dog != $dog))
then
// fire rule
end
2) when we have a dog and no tail exists that belongs to this dog the rule
should fire:
rule "no dog without a tail; not exists"
when
$dog :Dog()
not( exists( Tail(dog == $dog)))
then
// fire rule
end
and they really do behave similar, but not the same..
workingMemory.insert(dog);
workingMemory.insert(dog.getTail());
workingMemory.fireAllRules();
// here both did not fire, but when i go on:
workingMemory.modifyRetract(dogHandle)
workingMemory.modifyInsert(dogHandle, dog)
workingMemory.fireAllRules();
// now the not(exists(..)) version did fire, whereas the forall(..) version
did not.
of course both rules should not have fired, nothing changed for the dogs
relationship
with its tail.
i am using the 5.0.0.snapshot version of drools but i can not imagine that
this is an
unknown bug, as this is rather basic predicate logic.
what am i missing?
best, tim
17 years, 8 months
modify/update Object query
by Sangrish
Hi
I have a number of rules(in an agenda) which make many little changes
to the same object(s). Every time I update an object
the rules get activated again. Is there a way that I make the small changes
to the objects as the rules are executed but update/modify them with respect
to (w.r.t.) WorkingMemory only in the last rule to fire (decided by
salience).
You can visualize it as some kind of "Refresh" operation on an object w.r.t.
WorkingMemory
Thanks
Siddharth
--
View this message in context: http://www.nabble.com/modify-update-Object-query-tp19843075p19843075.html
Sent from the drools - user mailing list archive at Nabble.com.
17 years, 8 months
BRMS rule info logging
by techluver
I'm new to drools world. Kindly clarify following things
My requirement is to log each data in the DB(that meets any of the business
rule) along with rule info.
if I use BRMS ( i think it maintains the rules separately in its own db
table)
How I can associate each log with the rule info?
Approach 1. Can I access BRMS's rules directly and associate it in my
logging?
Approach 2. I can't do Approach 1, then I'm thinking to have RULES table in
my app db.Then whenever any rule is added using BRMS, Then add an entry into
RULES table and use this table for my logging
Please advise me on the right approach.
Thanks in advance.
--
View this message in context: http://www.nabble.com/BRMS-rule-info-logging-tp19766982p19766982.html
Sent from the drools - user mailing list archive at Nabble.com.
17 years, 8 months
Upload Rules to BRMS at runtime
by Asif Akram
Hi,
I was wondering if it is possible to create and upload rules at
runtime to BRMS to be accessed by other users. I have only seen the
examples where existing packages/rules are loaded from the BRMS. Any
help and suggestion will be appreciated.
Cheers
Asif
--
This message has been scanned for viruses and
dangerous content by WATEEN TELECOM, and is
believed to be clean.
17 years, 8 months