Iterating facts
by Phani Saripalli
Hi.
1) I could list all the facts via knowledge session.facthandle.iterator.
2) I could iterate over the objects contained in a fact. For example:
List<FactField> fFields =
ksession.getKnowledgeBase().getFactType(pckg, "Project").getFields();
3) I could get the name of the object and retrieve the contained value as a
string if it is a primitive datatype - int, real, boolean.
4) The problem for me is I am not able to retrieve the values of the inner
fields of an object.
For example, fFields.get(0).get(projIns) - yields me C( a=1, bool=false,
cc=0 ), I could retrieve this particular objects' name and also the inner
fields' names, but not the contained values for a, bool and cc.
I have tried java reflection, but no positive result so far.
I am using declared types, with no metadata. Any other nice way to tackle
this problem.
Thank you.
--
View this message in context: http://drools.46999.n3.nabble.com/Iterating-facts-tp4020214.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
Re: [rules-users] Loading a large number of rules is too slow.
by Davide Sottara
There seem to be two issues here..
- one is that loading is "too slow" for a "large number" of rules --> could
you provide some figures? :)
There may also be ways to reduce the number of rules, but we'd need to know
more about your usecase.
Please also consider that Drools is optimized for execution, so the tradeoff
is a heavier startup phase,
where many optimizations are pre-calculated
- the other is that you don't want to restart the application server when
you change the rule --> please read the manual at the "KnowledgeAgent"
section and see if that helps
Best
Davide
--
View this message in context: http://drools.46999.n3.nabble.com/Loading-a-large-number-of-rules-is-too-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
Re: [rules-users] Drools Planner for purchasing optimization - good fit for problem?
by Schneider, Bill
Geoffrey,
Thanks for the quick response.
As I'm learning more about my scenario, it feels more like a mixed-integer problem than a combinatorial problem. The objective function is linear in the decision variables. I would model the decision variables as the quantities of each item from each vendor. The conditional offers I could model as a separate vendor/bid, with a binary decision variable for "condition met?" and inequalities to constrain the quantities that depend on the binary variable. Some of the global constraints can be modeled in the same way, like "at most two vendors."
It sounds like there are some advantages to using Drools Planner in terms of readability and maintainability of the relationships and constraints - you have the full expressive power of DRL (or Java), and are not limited to inequalities. That could make it easier to program for new types of rules or constraints later.
Are there any advantages to using Drools Planner from a computational-complexity standpoint as well? Would it *hurt* to use in terms of CPU/memory, or even learning curve, for a problem that is possibly not combinatorial, and might be solvable with other means?
Also - are you aware of any case studies or examples of Drools Planner being used in the purchasing domain like this?
Thanks again!
--Bill
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Geoffrey De Smet
Sent: Thursday, October 11, 2012 10:35 AM
To: Rules Users List
Subject: Re: [rules-users] Drools Planner for purchasing optimization - good fit for problem?
[...]
- If you want to upscale, go Metaheuristics (for example with Planner). If you want to downscale, linear programming might be a better fit. (Compo's like ROADEF 2012 assert this statement).
- LP will require you to write your constraints as mathematical equitations based on arrays and primitives, for example "x < y * 1.21". Planner uses a declarative OO approach using drools rules (or even just plain Java), for example "Invoice ($x < yWithVAT)".
- If you have different conditional price types, you might want to look into using a drools decision table to easily declare that conditional logic - and use that as in Planner. Especially if those rules change often.
Thanks for any help you can give.
--Bill
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org<mailto:rules-users@lists.jboss.org>
https://lists.jboss.org/mailman/listinfo/rules-users
12 years, 2 months
Drools Planner for purchasing optimization - good fit for problem?
by Schneider, Bill
I'm trying to understand whether Drools Planner is a good fit for a purchasing optimization problem.
The problem is something like this: there are X different items, each of which can be purchased from Y different vendors at different prices. The objective variable/function to minimize is the total amount purchased (sum(qty_i * price_i)).
Some vendor prices are conditional - only valid if you purchase more than some minimum threshold, or if you purchase more than some total quantity from that vendor. There are some additional constraints like dual-sourcing
- for some item x_i, exactly two vendors must be selected.
I feel like you *could* probably solve this problem in Drools Planner, but I'm not sure if it's the best way, or if a more traditional solver approach would be better. It feels more like a linear programming problem at its core, and I'm having a hard time figuring out where the boundary is - what kind of constraint would make the problem "non-convex" or "non-smooth" to the point where a local search (tabu, evolutionary etc.) is required?
Thanks for any help you can give.
--Bill
12 years, 2 months
2 problems with the keyword contains in HashMaps
by raffi
Hy.
I have problems, filtering data with the help of /contains/. I have a
HashMap with /long/-values as keys. In my rules I filter data in the
following way:
FilterCriteria(categories_slot1 contains $cid)
HashMap categories_slot1 is initialized with HashMap<Long, Double>. $cid is
set as long value in the corresponding class, too. Does this work in
general?
Second problem is that there is another HashMap with Strings as key values.
FilterCriteria(brands contains $brand)
The problem is, that /brands/-key value strings are not identical to $brand.
But $brand can contain the key value string. But contains only checks if
they are identical right?
Thanks
--
View this message in context: http://drools.46999.n3.nabble.com/2-problems-with-the-keyword-contains-in...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
Unable to find implementation for BusinessRuleProvider
by John Peterson
Hi,
I've been experimenting with the Guided Rule Editor plug-in in Eclipse.
I've built a Drools Project using the default Hello World sample
application. I've created a new "Guided Rule" in my project called
"GuidedRule.brl" and get the associated "drools.package" with it. The
rule is simple:
WHEN
THEN
System.out.println("Rule has fired");
I build the knowledge base as follows:
private static KnowledgeBase readKnowledgeBase() throws
Exception {
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("SampleGuided.drl"),
ResourceType.BRL);
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;
}
The only line changed is adding the resource of type BRL.
When I try to run, I get the following error:
java.lang.RuntimeException: org.drools.compiler.DroolsParserException:
org.drools.CheckedDroolsException: Unable to find implementation for
BusinessRuleProvider
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.j
ava:544)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.ja
va:28)
at com.sample.DroolsTest.readKnowledgeBase(DroolsTest.java:41)
at com.sample.DroolsTest.main(DroolsTest.java:23)
Caused by: org.drools.compiler.DroolsParserException:
org.drools.CheckedDroolsException: Unable to find implementation for
BusinessRuleProvider
at
org.drools.compiler.PackageBuilder.addPackageFromBrl(PackageBuilder.java
:386)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.j
ava:470)
... 3 more
Caused by: org.drools.CheckedDroolsException: Unable to find
implementation for BusinessRuleProvider
at
org.drools.compiler.BusinessRuleProviderFactory.throwNoImplementationFou
nd(BusinessRuleProviderFactory.java:66)
at
org.drools.compiler.BusinessRuleProviderFactory.loadProvider(BusinessRul
eProviderFactory.java:42)
at
org.drools.compiler.BusinessRuleProviderFactory.getProvider(BusinessRule
ProviderFactory.java:25)
at
org.drools.compiler.PackageBuilder.addPackageFromBrl(PackageBuilder.java
:366)
... 4 more
I've tried variations to add the drools.package as a PKG type, I've had
the rules (and package) in both "com.sample" and /src/main/rules, but I
can't seem to resolve the problem. "drools.package" has been updated to
include the package name (package com.sample;) and I import the message
class as well (even though it isn't being used currently).
I suspect the issue is simple, but I haven't been able to figure it out.
Any help would be appreciated.
12 years, 2 months
Protobuf Marshaller Question (ScheduledActivation Persistence)
by Philipp Herzig
Dear developers,
I believe this is a question for Edson.
I wonder if ScheduledActivations are added to the Agenda when
unmarshalling an existing session and fired as well, e.g., non-expired
timers.
I guess that this worked with the DefaultMarshaller implementation (at
least I can see LOCs in the InputMarshaller where normal or scheduled
activations are added to the newly created agenda). I cannot find
similar code in the ProtobufMarshaller or, more precisely, the
ProtobufInputMarshaller.
I also tried to override MarshallerProvider in order to use the
DefaultMarshaller but that is obviously not-consistent
(ClassCastException) with the current codebase anymore.
Hopefully, I am doing/understanding sth. completely wrong here.
Thanks for any help regarding this issue,
Philipp
12 years, 2 months
Query regarding guvnor and drools remote execution using categories of guvnor
by Krishnendra Nandi
Hi All
I am a newbie
I have a question
In guvnor we have categories
Using REST API we can access assets through categories like
/rest/categories/{}/assets ...something like this
I have a JSON object which gets populated which has references to binary
for all the assets
1) How do we construct the KnowledgeBase out of it and execute rules based
on those subset of rules ? is it advisable to do that ?
2) How do we get all the declarative facts residing inside guvnor remotely
from a Java client ?
--
Thanks and Regards
Krishnendra Nandi
Phone :+91-93727-08782
Skype :krish_nandi_78
Gtalk :krishnendra@gmail.com
12 years, 2 months