About for and inheritance
by Chris Woodrow
Hi,
I recently find out a few issues using for, and I wanted to share it with
you. I made a simple exemple to illustrate my purpose.
My classes are (I did not represent accessors & constructors):
public class Cheese {
protected String name;
}
public class FrenchCheese extends Cheese{
private String smell;
}
public class Person {
private Cheese likes;
}
Here is my rule set :
package rules
rule "likes cheese"
when
$person : Person ()
Cheese( ) from $person.getLikes()
then
System.out.println("likes cheese");
end
rule "likes french cheese"
when
$person : Person ()
FrenchCheese( ) from $person.getLikes()
then
System.out.println("likes french cheese");
end
First test :
Cheese cheese = new FrenchCheese("good", "camembert");
Person person = new Person();
person.setLikes(cheese);
Output :
likes french cheese
likes cheese
Wich is expected...
Second test :
Cheese cheese = new Cheese();
Person person = new Person();
person.setLikes(cheese);
Output :
likes french cheese
likes cheese
That's the first strange thing. As far as I am concerned, rule "likes french
cheese" should not match (since a Cheese is not a FrenchCheese).
I made a change to the second rule :
rule "likes french cheese"
when
$person : Person ()
FrenchCheese( smell == "good" ) from $person.getLikes()
then
System.out.println("likes french cheese");
end
Third test :
Cheese cheese = new Cheese();
Person person = new Person();
person.setLikes(cheese);
output :
It throwed an exception : Exception in thread "main"
java.lang.ClassCastException: rules.Cheese
I am not saying the ClassCastException is not to expect in such a case but I
think I would simply expect it not to match (as far as a Cheese is not a
FrenchCheese).
Chris
13 years, 10 months
Drools Planner, when/how is a cloned solution used?
by aliquip
I’ve known about drools planner for quite some time and always wanted to play
with it, but now that I finally found something to solve with it, I’m afraid
that I don’t fully understand drools planner, or I’m simply using it wrong.
The problem I try to solve/optimize is optimizing a sequence of events,
where each event can be influence by the previous events.
Background info (not essential for my main question):
-----------------------------------------------------------------------
More specifically I try to optimize a series of “attacks” for the webgame
utopia, so that they do most damage, each attack changes the targets. To put
it simply:
We have the following attackers and targets
1. Attacker A: [offense :55, nw:100, attacks_made: 0]
2. Attacker B: [offense :75, nw:150, attacks_made: 0]
3. Attacker C: [offense :40, nw:80, attacks_made: 0]
1. Target A: [defense :30, nw:50, land:500]
2. Target B: [defense :21, nw:50, land: 500]
3. Target C: [defense :60, nw:80, land: 800]
Particularities: each attacker can, at max make 4 attacks, but each attack
uses offense. Each attack destroys defense, nw and land. Attacks take 10% of
land or less (less when nw attacker is largetly different from that of the
target).
So for example the following sequence is possible
• Attacker B: [offense :80, nw:150, attacks_made: 0] attacks Target C:
[defense :60, nw:80, land: 800]
• -> new status Attacker B: [offense :20, nw:150, attacks_made: 1]
• -> new status Target C: [defense :54, nw:70, land: 720]
• Attacker A: [offense :55, nw:100, attacks_made: 0] attacks Target C:
[defense :54, nw:70, land: 720]
• -> new status Attacker A: [offense 1, nw:100, attacks_made: 1]
• -> new status Target C: [defense :49, nw:65, land: 620]
• Attacker C: [offense :40, nw:80, attacks_made: 0] attacks Target B:
[defense :21, nw:50, land: 500]
• new status Attacker C xxxx
• new status Target B: [defense :19, nw:45, land: 450] >Now Attacker B can
attack this target<
• Attacker B: [offense :20, nw:150, attacks_made: 1] attacks Target B:
[defense :19, nw:45, land: 450
• etc
• etc
In my implementation, the solver has a sequence of attack. The possible
moves are attacks and undo attacks. Undo attacks are nasty, because when
there are, for example 20 attacks, and the 15th is undo, attacks 16 is
invalid if it’s on the same target as attack 15, or is by the same attacker,
attack 17 is invalid if it’s by the same attacker or on the same target as
15 OR attacks 16 was invalid and 17 has same attacker or target, etc. This
is taken care of by removing all invalidated attacks.
This has 1 large problem: removing an attack that invalidates multiple
attacks has an enormous impact on
the score.
-----------------------------------------------------------------------
Anyway, my problem is that I don’t fully understand what is going on, or I
have a bug in my logic, I suppose the last.
What I expected the solver to do:
• clone the solution to clone[1]
• clone clone[1] to clone[1.1], do some semi random moves on clone[1.1]
• clone clone[1] to clone[1.2], do some semi random moves on clone[1.2]
• clone clone[1] to clone[1.3], do some semi random moves on clone[1.3]
• get the solution with the best score, for example clone[1.3]
• clone clone[1.3] to clone[1.3.1], do some semi random moves on
clone[1.3.1]
• clone clone[1.3] to clone[1.3.2], do some semi random moves on
clone[1.3.2]
• etc
• get the solution with the best score, for example clone[1.3.1]
• clone clone[1.3.1] to clone[1.3.1.1], do some semi random moves on
clone[1.3.1.1]
• etc
• etc
But what appears to happen is:
• clone the solution to clone[1]
• do move on clone[1], if result is better than previous result, clone
clone[1] to clone[1.1]
• do move on clone[1], if result is better than previous result, clone
clone[1] to clone[1.2]
• do move on clone[1], if result is better than previous result, clone
clone[1] to clone[1.3]
• etc
• etc
Thus effectively for every move the same, initial, solution is used. And all
the clones are used for is to remember the best solution.
This is important for my problem because a solution has a sequence of
events, a move either adds an event, or removes one or multiple events. It
turns out that, even though the solution is cloned, my moves always affect
the sequence in the original solution. This seems strange to me.
Any insights that could help me understand whether or t what I’m doing makes
sense?
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Drools-Planner-when-h...
Sent from the Drools - User mailing list archive at Nabble.com.
13 years, 10 months
No activations created for condition with two checks for collection size
by Tina Vießmann
Hi,
I'm trying to check the following condition:
when
$currentLowLimit : LimitViolationEvent ( limitTypes.size == 1
&& limitTypes contains LimitTypes.ACTIVE_LOWER_LIMIT
&& parameterNames.size == 1 )
limitType and parameterNames are both Sets. I know events exists which
satisfy the condition. But why are there no activation created at all?
Thank you,
Tina
13 years, 10 months
Knowledge Base and Guvnor
by Dean Whisnant
Hi all, thank you for all the help in the past.
I'm to a point in my project of implementing Guvnor built packages into my java code that calls drools.
In the past I used the simple solution of building the knowledge agent on a .drl file as follows:
//Setup the knowledge session for drools
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("Standard837P.drl"),
ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;
}
A little background before the question. My project includes one set of rules that are standard business logic, we'll call that STANDARD for now and one set of rules that any one of my 45 customers could have created, we'll call CUSTOMER, on our common guvnor server. My java code knows which customer is running the app, so determining which two packages I want to fire is simple. The part that is not as straight forward for me is how I then I migrate using the guvnor urls in my above code.
I thought it would be as easy as to replace "Standard837P.drl" above with the STANDARD url and create a second add that would use the CUSTOMER url.
I also want all of my STANDARD rules applied before my CUSTOMER rules are applied. This got me thinking that I need to have two independent knowledge bases running so that I fire all in the first and then fire all in the second.
Backing up a bit again, my application looks through an incoming file inserting facts into the knowledge base for one medical claim line item, fires rules, writes out results to a database, and then moves on to the next claim line item in the file.
1) What would the syntax need to be to implement the STANDARD and CUSTOMER urls?
2) Would I need to create two independent knowledge bases?
3) DO you see any performance issues in this arrangement?
Thank you!
Dean
13 years, 10 months
Drools 5.1: What happens when an incremental KA rebuild fails?
by ljnelson
Seeing some strange things on a production system.
I have Drools set up to use a KnowledgeAgent.
I have the KnowledgeAgent set up to scan resources and directories.
The agent is pointed at--let's say--C:\LEAD\rules, where "LEAD" is the name
of the project in question and "rules" is a directory underneath which I
would like to have several .drl files.
I begin by placing one well-known, valid .drl file under there. That
obviously loads up fine and the rules go into effect.
If I deliberately introduce a syntax error, I hear about it in the
logs--that's fine too.
But if I then remove the syntax error, it's as though scanning stops. The
KnowledgeAgent appears as though it is never rebuilt again, so it appears
simply to be broken.
I will obviously supply more details as needed, but thought I'd fire this
quick flare to see if anyone knows of any simple cause here.
Best,
Laird
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Drools-5-1-What-happe...
Sent from the Drools - User mailing list archive at Nabble.com.
13 years, 10 months
How to say that two events have to happen during the same time interval
by Tina Vießmann
Hi,
I'm trying to find a easy way to express that two events A and B have to
happen during the same time interval. The events have each a duration >
0.
A example condition could be: The event A and B have to happen during the
same 60 seconds.
For me it includes several possibilites:
* A can start before B and
~ end before B starts
~ end during B
~ end after B ends
* The same can be possible for B
* A and B start/end/both at the same time
In any case the maximum duration from the first start time to the last end
time is e.g. 60s.
Is there a easy way to express that. I can only think of specifying the
several possibilities as conditions.
Thank you! :)
Tina
13 years, 10 months