traits - don more than 3 pojos, got IllegalArgumentException
by Michal Bali
Hi all,
I came across this issue when trying out 'traits' with POJOs (not declared
types). An IllegalArgumentException is being thrown when I apply the third
'don'. Here is how to reproduce:
as the POJO I am using the Message class that comes with the project
created by the Eclipse plugin.
now the rule file:
declare Message
@Traitable
end
declare NiceMessage
@format(trait)
end
rule load
when
then
Message message = new Message();
message.setMessage("Hello World");
insert(message);
don(message, NiceMessage.class);
Message unreadMessage = new Message();
unreadMessage.setMessage("unread");
insert(unreadMessage);
don(unreadMessage, NiceMessage.class);
Message oldMessage = new Message();
oldMessage.setMessage("old");
insert(oldMessage);
System.out.println("don " + oldMessage);
don(oldMessage, NiceMessage.class); //*<--- exception happens here*
System.out.println("wont reach this point");
end
When I run this and rule 'load' fires the third 'don' will throw the
following exception:
Exception executing consequence for rule "load" in com.mycompany.app:
java.lang.IllegalArgumentException: argument type mismatch
at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1101)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1029)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1251)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:709)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:673)
at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:221)
at com.mycompany.app.DroolsTest.main(DroolsTest.java:44)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at
org.drools.factmodel.traits.TraitFactory.getProxy(TraitFactory.java:92)
at
org.drools.base.DefaultKnowledgeHelper.don(DefaultKnowledgeHelper.java:502)
at
org.drools.base.DefaultKnowledgeHelper.don(DefaultKnowledgeHelper.java:522)
at
com.mycompany.app.Rule_load_86ecf966a4c14d8486844cfae2e1e0d8.defaultConsequence(Rule_load_86ecf966a4c14d8486844cfae2e1e0d8.java:21)
at
com.mycompany.app.Rule_load_86ecf966a4c14d8486844cfae2e1e0d8DefaultConsequenceInvokerGenerated.evaluate(Unknown
Source)
at
com.mycompany.app.Rule_load_86ecf966a4c14d8486844cfae2e1e0d8DefaultConsequenceInvoker.evaluate(Unknown
Source)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1091)
... 6 more
Am I doing something wrong or is this a bug. I am running with 5.4.0.Beta2.
BTW traits are a great piece of functionality. Thank you!
Best regards,
Michal
13 years, 8 months
planner score calculation error...
by Ricardo
Hi when i use the following drl file for score calculation ....It assign a
bigger table into the smaller room. help will be appreciated....
console output is as follows..
*Solved Organizer with 2 rooms and 3 tables:
Table 1 -> Room 1
Table 2 -> Room 2
Table 3 -> Room 2*
test data:
Room room1 = new Room(10, 10);
room1.setId((long) 1);
Room room2 = new Room(10, 10);
room2.setId((long) 2);
----
Table table1 = new Table(10, 10);
table1.setId((long) 1);
Table table2 = new Table(9, 9);
table2.setId((long) 2);
Table table3 = new Table(9, 9);
table3.setId((long) 3);
drl file for score calculation...
//created on: Jun 18, 2012
package org.drools.planner.organizer;
dialect "java"
//list any import classes here.
import
org.drools.planner.core.score.buildin.hardandsoft.HardAndSoftScoreHolder;
import org.drools.planner.core.score.constraint.IntConstraintOccurrence;
import org.drools.planner.core.score.constraint.ConstraintType;
import org.drools.planner.organizer.domain.Room;
import org.drools.planner.organizer.domain.Table;
//declare any global variables here
global HardAndSoftScoreHolder scoreHolder;
//
############################################################################
// Hard constraints
//
############################################################################
rule "requiredLengthTotal"
when
$room : Room($length : length)
$requiredSpaceTotal : Number(intValue > $length) from accumulate(
Table(
room == $room,
$tablelength : length),
sum($tablelength)
)
then
insertLogical(new IntConstraintOccurrence("requiredLengthTotal",
ConstraintType.NEGATIVE_HARD,
$requiredSpaceTotal.intValue() - $length,
$room));
end
rule "requiredWidthTotal"
when
$room : Room($width : width)
$requiredSpaceTotal : Number(intValue > $width) from accumulate(
Table(
room == $room,
$tablewidth : width),
sum($tablewidth)
)
then
insertLogical(new IntConstraintOccurrence("requiredWidthTotal",
ConstraintType.NEGATIVE_HARD,
$requiredSpaceTotal.intValue() - $width,
$room));
end
//
############################################################################
// Soft constraints
//
############################################################################
rule "roomLengthCapacity"
when
$room : Room($length : length)
$table : Table(room == $room, length > $length, $tablelength :
length)
then
insertLogical(new IntConstraintOccurrence("roomLengthCapacity",
ConstraintType.NEGATIVE_SOFT,
($tablelength - $length),
$room, $table));
end
rule "roomWidthCapacity"
when
$room : Room($width : width)
$table : Table(room == $room, width > $width, $tablewidth : width)
then
insertLogical(new IntConstraintOccurrence("roomWidthCapacity",
ConstraintType.NEGATIVE_SOFT,
($tablewidth - $width),
$room, $table));
end
//
############################################################################
// Calculate score
//
############################################################################
// Accumulate hard constraints
rule "hardConstraintsBroken"
salience -1 // Do the other rules first (optional, for performance)
when
$hardTotal : Number() from accumulate(
IntConstraintOccurrence(constraintType ==
ConstraintType.NEGATIVE_HARD, $weight : weight),
sum($weight)
)
then
scoreHolder.setHardConstraintsBroken($hardTotal.intValue());
end
// Accumulate soft constraints
rule "softConstraintsBroken"
salience -1 // Do the other rules first (optional, for performance)
when
$softTotal : Number() from accumulate(
IntConstraintOccurrence(constraintType ==
ConstraintType.NEGATIVE_SOFT, $weight : weight),
sum($weight)
)
then
scoreHolder.setSoftConstraintsBroken($softTotal.intValue());
end
-----
with kind regards,
--
View this message in context: http://drools.46999.n3.nabble.com/planner-score-calculation-error-tp40181...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 8 months
Does Guvnor Support Traits?
by BenjaminWolfe
I'm pretty new to developer forums. If my question is best asked in a
different venue, feel free to point me there. And if it's vague (see the
full version below), please ask clarifying questions. Thank you!
I was just reading in the 5.4 docs about traits, donning the isA keyword...
pretty exciting stuff. It allows me a lot of flexibility as a rule-writer.
But my company's upcoming implementation of Drools is going to feature
Guvnor pretty prominently. (We're in the process of rolling it out.) Does
Guvnor support traits?
I should mention that I'm an analyst, and our developers are new to Drools
and Guvnor as well. Traits are coming up in one of our early projects, as
we consider whether to squish two similar things into the same fact type (so
that we can easily use the same rules on both) or separate them out into
two.
--
View this message in context: http://drools.46999.n3.nabble.com/Does-Guvnor-Support-Traits-tp4018176.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 8 months
drools planner ConstraintOccurrence
by Ricardo
Hi,
I am learning drools planner, please explain to me about the
ConstraintOccurrence (Int, Double,Long and Umweighted) object used in the
then part of the drools planner drl file. My doubt is when to use this each
type of this class and how it makes changes in the score calculations.
note: Already search the mailing list, src code and read the user guide but
no details available
best regards,
-----
with kind regards,
--
View this message in context: http://drools.46999.n3.nabble.com/drools-planner-ConstraintOccurrence-tp4...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 8 months
Trouble wrapping my head around window.length(1)
by Ladd
I'm new to Drools and have what I think should be a simple use case. But I'm
getting some puzzling results from my tests.
I have a simple class with just a key and value. What I want to detect is
when the last occurrence with key "X" has a value of "ALARM" and the last
occurrence with key "Y" has a value of "ALARM".
Could someone please either educate me or point me to the documentation that
explains how this would be done? Many thanks in advance!!
Here's my test code and results:
*The event class:*
public class MyEvent {
String key;
String value;
public MyEvent( String key, String value ) {
this.key = key;
this.value = value;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
*The test runner:*
@Test
public void testWindowLen1() {
StringBuilder sb = new StringBuilder();
sb.append( "import drools.tests.MyEvent \n" );
sb.append( " \n" );
sb.append( "declare MyEvent @role(event) end \n" );
sb.append( " \n" );
sb.append( "rule \"Any event detected\" \n" );
sb.append( " \n" );
sb.append( "salience 10 \n" );
sb.append( "when \n" );
sb.append( " f : MyEvent() \n" );
sb.append( "then \n" );
sb.append( " System.out.println( \"************ fault seen with key \" +
f.getKey() + \" value \" + f.getValue() ); \n" );
sb.append( "end \n" );
sb.append( " \n" );
sb.append( "rule \"Faults coincide\" \n" );
sb.append( " \n" );
sb.append( "when \n" );
sb.append( " f1 : MyEvent( key == \"faultType1\", value == \"ALARM\" )
over window:length( 1 ) \n" );
sb.append( " f2 : MyEvent( key == \"faultType2\", value == \"ALARM\" )
over window:length( 1 ) \n" );
sb.append( "then \n" );
sb.append( " System.out.println( \"************ both faults are active!
f1.key = \" + f1.getKey() + \" f2.key = \" + f2.getKey() ); \n" );
sb.append( "end \n" );
sb.append( " \n" );
sb.append( "rule \"Faults don't coincide\" \n" );
sb.append( " \n" );
sb.append( "when \n" );
sb.append( " f1 : MyEvent( key == \"faultType1\", value != \"ALARM\" )
over window:length( 1 ) \n" );
sb.append( " or \n" );
sb.append( " f2 : MyEvent( key == \"faultType2\", value != \"ALARM\" )
over window:length( 1 ) \n" );
sb.append( "then \n" );
sb.append( " System.out.println( \"************ at least one fault isn't
active!\" ); \n" );
sb.append( "end \n" );
StatefulKnowledgeSession ksession = null;
KnowledgeBase kbase = null;
KnowledgeBaseConfiguration config =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
config.setOption( EventProcessingOption.STREAM );
kbase = KnowledgeBaseFactory.newKnowledgeBase( config );
ksession = kbase.newStatefulKnowledgeSession();
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newByteArrayResource(
sb.toString().getBytes() ), ResourceType.DRL );
if( kbuilder.hasErrors() ) {
System.err.println( kbuilder.getErrors().toString() );
} else {
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
}
// Inject the first fault = ALARM
MyEvent faultType1Alarm = new MyEvent( "faultType1", "ALARM" );
System.out.println( "Firing fault1 = ALARM" );
ksession.insert( faultType1Alarm );
ksession.fireAllRules();
// Inject the second fault = ALARM
// Want this to trigger the "Faults concide" rule
MyEvent faultType2Alarm = new MyEvent( "faultType2", "ALARM" );
System.out.println( "Firing fault2 = ALARM" );
ksession.insert( faultType2Alarm );
ksession.fireAllRules();
// Inject the first fault = OK
// Want this to trigger the "Faults don't concide" rule
MyEvent faultType1OK = new MyEvent( "faultType1", "OK" );
System.out.println( "Firing fault1 = OK" );
ksession.insert( faultType1OK );
ksession.fireAllRules();
ksession.dispose();
System.out.println( "Done!" );
assert( true );
}
*And the results that have me scratching my head:*
Firing fault1 = ALARM
************ fault seen with key faultType1 value ALARM
************ at least one fault isn't active!
************ at least one fault isn't active!
************ both faults are active! f1.key = faultType1 f2.key = faultType1
Firing fault2 = ALARM
************ fault seen with key faultType2 value ALARM
************ at least one fault isn't active!
************ at least one fault isn't active!
************ both faults are active! f1.key = faultType2 f2.key = faultType2
************ both faults are active! f1.key = faultType2 f2.key = faultType1
Firing fault1 = OK
************ fault seen with key faultType1 value OK
************ at least one fault isn't active!
************ at least one fault isn't active!
************ both faults are active! f1.key = faultType1 f2.key = faultType1
************ both faults are active! f1.key = faultType1 f2.key = faultType2
Done!
--
View this message in context: http://drools.46999.n3.nabble.com/Trouble-wrapping-my-head-around-window-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 8 months
Error deploying drools-spring (5.4.0.Final) on ServiceMix 4.4.1
by Nicholas Hemley
Hello,
I have deployed drools-spring on ServiceMix 4.4.1 and suffer the following error:
java.lang.NullPointerException
at org.apache.felix.framework.resolver.ResolverImpl.toStringBlame(ResolverImpl.java:1521)[org.apache.felix.framework-3.0.9-fuse-07-03.jar:]
at org.apache.felix.framework.resolver.ResolverImpl.checkPackageSpaceConsistency(ResolverImpl.java:943)[org.apache.felix.framework-3.0.9-fuse-07-03.jar:]
at org.apache.felix.framework.resolver.ResolverImpl.resolve(ResolverImpl.java:130)[org.apache.felix.framework-3.0.9-fuse-07-03.jar:]
at org.apache.felix.framework.Felix$StatefulResolver.resolve(Felix.java:4129)[org.apache.felix.framework-3.0.9-fuse-07-03.jar:]
at org.apache.felix.framework.Felix.resolveBundle(Felix.java:3459)[org.apache.felix.framework-3.0.9-fuse-07-03.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:1739)[org.apache.felix.framework-3.0.9-fuse-07-03.jar:]
Nothing further in the log, so I am a bit stumped as to what the actual problem is.
Has anyone successfully deployed drools 5.4.0.Final to ServiceMix 4.4.x, please?
Cheerio,
Nic
Nicholas Hemley
Direct: +44 (0) 117 231 0003
Scott Logic | 10 Victoria Street, Bristol, BS1 6BN
Reception: +44 (0) 117 231 0000
13 years, 8 months
Drools verifier
by FrankVhh
Hi all,
Triggered by a post on this forum, I decided to try a testcase
implementation of Drool Verifiier.
I manage to write some code that does not produce any errors at runtime,
which is good. Unfortunately, it doesn't produce any errors/warnings/notes
on my rulefile either, which isn't good.
The drl file consists of some duplicate rules, and since the file is only
part of a ruleset, there might be some gaps as well.
I pasted the java-code below. Does anyone see where I am going wrong?
Thanks in advance!
Regards,
Frank
VerifierBuilder vBuilder =
VerifierBuilderFactory.newVerifierBuilder();
Verifier verifier = vBuilder.newVerifier();
String ruleText =
"C:\\Users\\Frank\\Documents\\DroolsWorkSpaces\\EmpiricalExperiments\\Financial
Rules\\src\\main\\rules\\clearancerules.drl";
verifier.addResourcesToVerify( ResourceFactory.newReaderResource(
new StringReader( ruleText ) ), ResourceType.DRL );
verifier.fireAnalysis();
VerifierReport result = verifier.getResult();
for(VerifierMessageBase base: result.getBySeverity(
Severity.ERROR ) ){
System.out.println( base );
}
for(VerifierMessageBase base: result.getBySeverity(
Severity.WARNING ) ){
System.out.println( base );
}
for(VerifierMessageBase base: result.getBySeverity( Severity.NOTE )
){
System.out.println( base );
}
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Drools-verifier-tp268...
Sent from the Drools - User mailing list archive at Nabble.com.
13 years, 8 months
simple subtraction in drools 5.3 fires rules
by oranoh
I have a simple class
public class Dummy {
private int x1, x2, y1, y2;
public Dummy(int x1, int y1, int x2, int y2) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
public int getX1() {
return x1;
}
public int getX2() {
return x2;
}
public int getX2M150() {
return x2-150;
}
public int getY1() {
return y1;
}
public int getY2() {
return y2;
}
}
And a the following Rule:
rule "DummyRule"
ruleflow-group "DummyTest"
when
d1 : Dummy()
d2 : Dummy(y2 == d1.y1, (x1 == (d1.x2 -150) || x2 == (d1.x2 -150)))
then
System.out.println("Rule DummyTest fired");
end
Executing the rule with the following Data - The Rule fires !!! - WRONG
Dummy d1 = new Dummy(-1050, -900, -750, -600);
Dummy d2 = new Dummy(-1050, -1200, -750, -900);
When I modify the Rule the follow way
rule "DummyRule"
ruleflow-group "DummyTest"
when
d1 : Dummy()
d2 : Dummy(y2 == d1.y1, (x1 == d1.x2M150 || x2 == d1.x2M150))
then
System.out.println("Rule DummyTest fired");
end
with the same Data - The Rule fires not !!!! - What is CORRECT
This problem comes up, when I move from drools 5.01 to 5.3
Can anybody help ?
--
View this message in context: http://drools.46999.n3.nabble.com/simple-subtraction-in-drools-5-3-fires-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 8 months
Re: [rules-users] Planner and domain modeling
by ge0ffrey
Garf wrote
>
> Ah, I see.
> It would be handy to update the docs to clarify such (is there a community
> wiki around?)
>
Not sure. Normally, I'd like to document as much as possible, but I 'd
rather leave this one undefined for now and see how people solve, instead of
pushing people into a certain direction which I haven't tried out decently
in any of the examples yet (or any of the alternative directions).
Try it out, let me know what works best for you. Also, a pull request for
the docs is welcome, if you've verified the changes :)
--
View this message in context: http://drools.46999.n3.nabble.com/Planner-and-domain-modeling-tp4018117p4...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 8 months