Drools Puzzle #1: Ages of the sons
by Ellen Zhao
Hallo all!
I talked about running a periodic puzzle solving contest in the user
mailing list to some people in the drools team. They have never done
it before so did not know how this contest will come out. However, I
was allowed to make the first try. If no body is interested, there
won't be any Drools Puzzle #2. Sorry for the spam if you do not like
this at all. In the end of this email you can see how I came up with
this idea.
So, here is the puzzle for round No. 1:
------------------------------------------------------------------------------------------------------------------------------------
Difficulty level: settler
An old man asked a mathematician to guess the ages of his three sons.
Old man said: "The product of their ages is 36."
Mathematician said: "I need more information."
Old man said:"Over there you can see a building. The sum of their ages
equals the number of the windows in that building."
After a short while the mathematician said: "I need more information."
Old man said: "The oldest son has blue eyes."
Mathematician said: "I got it."
------------------------------------------------------------------------------------------------------------------------------------
This is a simple puzzle, you may not need any computer to solve it.
But here are the rules:
1. Solution (the core algorithm) must be written in drools. Any
dialect is allowed. Any DSL is allowed.
2. Any kind of user interface is allowed.
3. Make your program as easy to test as possible. Please attach a
simple and short readme file about how to build/test/deploy it.
4. The drools team will measure the performance of all submissions on
a same computer.
3. The winner will be allowed to post the next puzzle.
4. Any participator, no matter finally win or not, will get points for
each participation. Drools team will run a global ranking system and
build a hall of fame for all participators. At the end of the year,
the one who has most points will be awarded with ( Drools team please
fill here, something like a T-shirt or ?). Top ten people in the hall
of fame will be awarded with (Drools team please fill here).
5. If there are many, many participators, the Drools team might
consider things like "shortest run-time award", "least memory-usage
award", "best UI award", "shortest code award", etc. for each puzzle.
6. Currently the puzzle will come once half month. Submission deadline
of this round is August 15th, 2007.
7. Please do not post your solution to the user mailing list, since
everybody can see your program before the deadline. Drools team please
specify an email account to which participators can post solutions.
8. Best/inspiring solutions will be disclosed when next round is on.
9. If any Drools bug is caught during your solving of the puzzle, the
Drools team will award you with (Drools team please fill here).
-----------------------------------------------------------------------------------------------------------------------------------
Any constructive advice and suggestion about the rules of Drools
Puzzle is welcome.
Here is guideline for posting puzzles:
1. You do not want to scare people away with too difficult puzzles or
bore people with questions like 1+1=?, so please consider a proper
difficulty level for the puzzle.
2. NP-complete or NP-hard is okay. For some NP-hard problems,
sub-optimal solutions can be achieved efficiently. But do please tag
the difficulty level as something like "veteran", "guru", etc.
3. Complexity aside, there is still scope and testability
consideration. Puzzles like "How to integrate my 15 different kind of
services objects and my entity home with Drools?" might be
algorithmically not difficult, but the application-building can really
take a lot of time and energy, and it is not straightforward to test
the solution.
4. The purposes of this contest are:
4.1 To learn from each other, enhance our programming skill and
learn good algorithms, good implementations.
4.2 To encourage people to explore features of Drools.
4.3 For fun.
So your puzzle should not take too much work to solve. It should not
mentally or physically torture participators.
---------------------------------------------------------------------------------------------------------------------------------
This idea was inspired by a "Weekly Challenge" running on dpreview.com
user forum and GOTM from http://gotm.civfanatics.net/
On dpreview.com, a subject is posted by the winner of the prior week,
people can post their photos to compete. On civfanatics.net, an
initial configuration file is posted each month, and gamers submit
their end results for ranking. Both of these two non-official contests
are running very well, I hope Drools Puzzle will turn out a fun thing
too.
Regards and nice weekend,
Ellen
18 years, 5 months
Simple Example / Tutorial
by Robert Burdick
Hello All:
I'm still finding the samples that I've come across far too obtuse to easily
illustrate how JBoss Rules works. I really need the worlds simplest working
example (no missing code files as in many of the examples) with a tutorial /
description that really explains what's going on. You've all been through
this: can anyone share how they got going?
18 years, 5 months
Re: [rules-users] nested accessors with Sets
by mark.mcnally@comcast.net
Edson,
I opened ticket # 1058 for this - http://jira.jboss.com/jira/browse/JBRULES-1058
Thank you,
Mark
-------------- Original message ----------------------
From: "Edson Tirelli" <tirelli(a)post.com>
> Mark,
>
> Hmmm, something is going on with mvel integration... bellow must work.
> There are work arounds (like using plain java code, or using multiple
> patterns), but I think we need to fix that. Can you please include this info
> in the ticket.
>
> Thanks,
>
> []s
> Edson
>
> 2007/8/2, mark.mcnally(a)comcast.net <mark.mcnally(a)comcast.net>:
> >
> > Edson,
> >
> > Thank you for the response. I tried writing the in-line eval as suggested
> > but get this Exception:
> >
> > org.drools.rule.InvalidRulePackage: Unable to determine the used
> > declarations : [Rule name=State, agendaGroup=MAIN, salience=0,
> > no-loop=false]
> > at org.drools.rule.Package.checkValidity(Package.java:408)
> > at org.drools.common.AbstractRuleBase.addPackage(
> > AbstractRuleBase.java:288)
> > at [...]
> >
> > This is my rule:
> >
> > rule State
> > dialect "mvel"
> > when
> > $ca:CandidateAssociation( eval ( !
> > nurseDetails.stateLicensures.contains( patientDetails.state ) ) )
> > then
> > retract( $ca );
> > end
> >
> > I haven't yet but, plan to open an issue in JIRA as requested
> >
> > Thanks for your help.
> > Mark
> >
> >
18 years, 5 months
correlating two collects
by Yuri de Wit
I am finally having some time to use collects. What I basically need
to do is to collect items from a list using a specific criteria, then
collect items from a diff list using another criteria, and finally
compare the groups collected using a 3rd criteria
Here is what I am thinking:
i : Item(type==A)
ig : ItemGroup(size>1)
collect Item(a==i.a, b==i.b, ... n==i.n)
i2: Item(type==B)
ig2 : ItemGroup( size>1,
ga==ig.ga, gb==i.gb, .... )
collect Item(a==i.a, b==i.b, ... n==i.n)
1) It is quite nice that any implementation of java.util.Collection
can be the resut of collect. ItemGroup here not only keeps hold of all
Items returned but has some aggregate properties (afaik, I cannot use
the aggregate functions with accumulate since I have multiple column
aggregation).
2) Am I on the right track? Or is there a better way?
3) Is the collect recomputed from scratch or incrementally every time
a new fact is asserted or updated?
thanks
18 years, 5 months
Need Design Inputs
by shanmu
Hi,
We are currenlty working on a new assignment
where we have a requirement where some mapping
details are available such as
A-->B-->C-->D
The relationship goes like this A has multiple
values of B.Combination of A and B has multiple
values for C and finally combination of A,B,C has
multiple values of D.
User on selecting A the system needs to display
the list of B and selecting a value of B from the
list system displays the lsit of C and so on.
All the request needs to contacts a web service
for retreiving the values.
Based on the anlaysis we have close to around 30K
combination of A,B,C,D.
People adviced me to use Drools for this by
maintainning the combination in rules (DRL) files
is it ideal for using Drools for this kinda
scenario.
I could well achieve the same requirement with a
dynamic query built and fetch the values from
database for each combination.
I feel using Drools would increase the
development time a lot.Also from a maintenance
perspective it might consume lots of effort.
Can anyone advice me what to use? also please let
me know the PRO's and Cons if any?
Thanks
Best Regards
shanmu
"Smile , it improves your face value "
____________________________________________________________________________________
Got a little couch potato?
Check out fun summer activities for kids.
http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities+for+kid...
18 years, 5 months
Re: [rules-users] nested accessors with Sets
by mark.mcnally@comcast.net
My rule now appears to be working after switching from the "excludes" operator to the newer "not contains".
This works:
$ca:CandidateAssociation(nurseDetails.stateLicensures not contains patientDetails.state )
This does not:
$ca:CandidateAssociation(nurseDetails.stateLicensures excludes patientDetails.state )
Mark
-------------- Original message ----------------------
From: mark.mcnally(a)comcast.net
> Hello,
>
> Please excuse me if I have double posted - my first did not seem to appear.
>
> I am wondering if the following is valid rule syntax. I am getting a stacktrace
> when the rules fire that points to a ClassCastException on a HashSet
>
> I am using v4.0 GA.
>
> Thank you, Mark
>
>
> rule StateMatch
> when
> $ca:CandidateAssociation(nurseDetails.stateLicensures excludes
> patientDetails.state )
> then
> retract( $ca );
> end
>
>
> public class CandidateAssociation {
> private PatientDetails patientDetails;
> private NurseDetails nurseDetails;
> private int overlapHours;
>
> public CandidateAssociation( PatientDetails patientDetails, NurseDetails
> nurseDetails) {
> super();
> this.patientDetails = patientDetails;
> this.nurseDetails = nurseDetails;
> overlapHours =
> participantDetails.getNumberOverlapHourCnt(nurseDetails);
> }
> [...]
> }
>
> public class NurseDetails {
> private Set stateLicensures = new HashSet();
> [...]
> }
> public class PatientDetails {
> private String state;
> [...]
> }
>
> ------------------------------------------------------
> Firing Rules
> **********
> org.drools.RuntimeDroolsException: Exception executing predicate
> org.drools.base.mvel.MVELPredicateExpression@27d6bfb
> at
> org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:197)
> at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:121)
> at
> org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObje
> ctSinkAdapter.java:317)
> at
> org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:159)
> at org.drools.reteoo.Rete.assertObject(Rete.java:175)
> at
> org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:190)
> at
> org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:70)
> at
> org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:772)
> at
> org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:64)
> at
> org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:58)
> at
> org.drools.examples.Rule_InitializeCandidateForEachNurse_0.consequence(Rule_Init
> ializeCandidateForEachNurse_0.java:13)
> at
> org.drools.examples.Rule_InitializeCandidateForEachNurse_0ConsequenceInvoker.eva
> luate(Rule_InitializeCandidateForEachNurse_0ConsequenceInvoker.java:25)
> at
> org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:503)
> at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:467)
> at
> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:
> 403)
> at
> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:
> 384)
> at
> primarynursePOC.PrimaryNursePOC.selectPrimaryNurse(PrimaryNursePOC.java:136)
> at primarynursePOC.PrimaryNursePOC.main(PrimaryNursePOC.java:91)
> Caused by: java.lang.ClassCastException: java.util.HashSet
> at
> org.drools.base.mvel.MVELPredicateExpression.evaluate(MVELPredicateExpression.ja
> va:35)
> at
> org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:191)
> ... 17 more
> org.drools.RuntimeDroolsException: Exception executing predicate
> org.drools.base.mvel.MVELPredicateExpression@27d6bfb
> at
> org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:197)
> at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:121)
> at
> org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObje
> ctSinkAdapter.java:317)
> at
> org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:159)
> at org.drools.reteoo.Rete.assertObject(Rete.java:175)
> at
> org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:190)
> at
> org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:70)
> at
> org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:772)
> at
> org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:64)
> at
> org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:58)
> at
> org.drools.examples.Rule_InitializeCandidateForEachNurse_0.consequence(Rule_Init
> ializeCandidateForEachNurse_0.java:13)
> at
> org.drools.examples.Rule_InitializeCandidateForEachNurse_0ConsequenceInvoker.eva
> luate(Rule_InitializeCandidateForEachNurse_0ConsequenceInvoker.java:25)
> at
> org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:503)
> at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:467)
> at
> org.drools.common.AbstractWorkingMemory.doOtherwise(AbstractWorkingMemory.java:4
> 30)
> at
> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:
> 412)
> at
> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:
> 384)
> at
> primarynursePOC.PrimaryNursePOC.selectPrimaryNurse(PrimaryNursePOC.java:136)
> at primarynursePOC.PrimaryNursePOC.main(PrimaryNursePOC.java:91)
> Caused by: java.lang.ClassCastException: java.util.HashSet
> at
> org.drools.base.mvel.MVELPredicateExpression.evaluate(MVELPredicateExpression.ja
> va:35)
> at
> org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:191)
> ... 18 more
> Exception in thread "main" org.drools.spi.ConsequenceException:
> org.drools.RuntimeDroolsException: Exception executing predicate
> org.drools.base.mvel.MVELPredicateExpression@27d6bfb
> at
> org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:507)
> at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:467)
> at
> org.drools.common.AbstractWorkingMemory.doOtherwise(AbstractWorkingMemory.java:4
> 30)
> at
> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:
> 412)
> at
> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:
> 384)
> at
> primarynursePOC.PrimaryNursePOC.selectPrimaryNurse(PrimaryNursePOC.java:136)
> at primarynursePOC.PrimaryNursePOC.main(PrimaryNursePOC.java:91)
> Caused by: org.drools.RuntimeDroolsException: Exception executing predicate
> org.drools.base.mvel.MVELPredicateExpression@27d6bfb
> at
> org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:197)
> at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:121)
> at
> org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObje
> ctSinkAdapter.java:317)
> at
> org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:159)
> at org.drools.reteoo.Rete.assertObject(Rete.java:175)
> at
> org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:190)
> at
> org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:70)
> at
> org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:772)
> at
> org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:64)
> at
> org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:58)
> at
> org.drools.examples.Rule_InitializeCandidateForEachNurse_0.consequence(Rule_Init
> ializeCandidateForEachNurse_0.java:13)
> at
> org.drools.examples.Rule_InitializeCandidateForEachNurse_0ConsequenceInvoker.eva
> luate(Rule_InitializeCandidateForEachNurse_0ConsequenceInvoker.java:25)
> at
> org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:503)
> ... 6 more
> Caused by: java.lang.ClassCastException: java.util.HashSet
> at
> org.drools.base.mvel.MVELPredicateExpression.evaluate(MVELPredicateExpression.ja
> va:35)
> at
> org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:191)
> ... 18 more
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
18 years, 5 months
drools-example-brms
by David Nogueras
Hi, I´m trying to run the brms sample and i get the next output:
RuleAgent(insuranceconfig) INFO (Thu Jul 19 14:27:44 CEST 2007): Configuring
with newInstance=true, secondsToRefresh=30
RuleAgent(insuranceconfig) INFO (Thu Jul 19 14:27:44 CEST 2007): Configuring
package provider : URLScanner monitoring URLs:
http://localhost:8080/drools-jbrms/org.drools.brms.JBRMS/package/org.acme...
local cache dir of D:\workspace2\drools-example-brms\cache
RuleAgent(insuranceconfig) WARNING (Thu Jul 19 14:27:44 CEST 2007): Falling
back to local cache.
java.lang.NullPointerException
at org.drools.agent.FileScanner.readPackage(FileScanner.java:101)
at org.drools.agent.FileScanner.getChangeSet(FileScanner.java:79)
at org.drools.agent.FileScanner.loadPackageChanges(FileScanner.java:57)
at org.drools.agent.URLScanner.loadPackageChanges(URLScanner.java:93)
at org.drools.agent.RuleAgent.checkForChanges(RuleAgent.java:291)
at org.drools.agent.RuleAgent.refreshRuleBase(RuleAgent.java:259)
at org.drools.agent.RuleAgent.configure(RuleAgent.java:228)
at org.drools.agent.RuleAgent.init(RuleAgent.java:160)
at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:169)
at org.acme.insurance.launcher.InsuranceBusiness.loadRuleBase(
InsuranceBusiness.java:26)
at org.acme.insurance.launcher.InsuranceBusiness.executeExample(
InsuranceBusiness.java:14)
at org.acme.insurance.launcher.MainClass.main(MainClass.java:13)
could someone help me?
18 years, 5 months
SAP Netweaver
by Heyns, Juan
Hi,
I have posed the question on IRC before:
Has anybody used JBoss Rules with SAP Netweaver application server? I am
curious whether anybody has managed to integrate the eclipse plugins
into the the SAP NetWeaver Developer Studio (which is Eclipse 2.1.2
based btw).
If anyone has any experiences to share, please let me know. Otherwise I
will give some feedback after my attempt.
Regards
Juan
"Employees of Lonmin Platinum ("Lonplats") are not authorised to conclude
electronic transactions or to enter into electronic agreements on behalf
of Lonplats. Any electronic signature (other than an advanced electronic
signature as defined in the Electronic Communications and Transactions
Act of 2003) added to a data message (such as an email or an attachment
to an (email) ostensibly on behalf of Lonplats by a Lonplats employee shall
not be legally binding on Lonplats and Lonplats shall incur no liability of
any nature whatsoever, directly or indirectly, arising from such act on the
part of it's employee. It is further recorded that nothing (other than an
advanced electronic signature) inserted into any data message
emanating from Lonplats shall be construed as constituting an electronic
signature"
18 years, 5 months