Using global variable in DRL file
by zeeshan
Hi All !
I am trying use global variable in DRL file but when I am using it, gives
Exception. Please have a look at the DRL file -----
package com.drools.rules
import com.drools.facts.*;
*global CSVBeanAgent csvAgent;* [here I have declared the Global variable]
rule "Calculating Agent APE"
salience 35
no-loop true
when
$csvPolicy : CSVBeanPolicy()
//$csvAgent : CSVBeanAgent()
then
System.out.println("For agent --->zzzzz in rule setting premium form
rate>>>>"+$csvPolicy.getPremiumMode());
double policyAPE=$csvPolicy.getPolicyAPE();
System.out.println("policyAPE>>>>>"+policyAPE);
*System.out.println("Agent
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz>>>>>"+csvAgent);*
double agentAPE=0.0;
if(csvAgent.getAgentNo()==$csvPolicy.getAgentNo()){
System.out.println("inside if");
agentAPE=agentAPE+policyAPE;
}
csvAgent.setAgentAPE(agentAPE);
System.out.println("AgentAPE>>>>>>>>>>>>>>>"+csvAgent.getAgentAPE());
update($csvPolicy);
end
Above is my rule....the Bold one is I am trying to the value of *csvAgent*,
it gives *null* value. Please help me in finding the solution i.e. How to
declare the global variable and how to use it in DRL file.
Thanks !
--
View this message in context: http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp401...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 8 months
Collections versus Relational Approach in Fact Model
by BenjaminWolfe
I'm learning Java and Drools at the same time; please be gentle if my
question is misdirected.
I'm working on creating my first nontrivial fact model. A policy can have
multiple vehicles; a vehicle can have multiple coverages. My data will come
into the rules engine via an XML file, and be output to XML after all rules
are fired. I'm looking for best practices.
I've seen it suggested to use a relational approach to my object graph. A
policy will have policyID 12345; its vehicles will have a policyID field,
and each will have a different vehicleNumber (e.g. 1, 2 and 3). A coverage
will have policyID (12345) and vehicleNumber(1), and a coverage identifier
of its own.
That seems simple, sleek and elegant. I hope to use it to write rules. But
I wonder if it will be resource-intensive when I get to outputting the XML.
I'm imagining having to write the policy node, then search all vehicles for
the 3 that are related to this policy, then search through all coverages for
the ones corresponding to each vehicle, etc.
Is it better to include some sort of collection? (Policy 12345 might
include a collection of vehicles, each of which would include a collection
of coverages.) If so, what kind of collection: an implementation of set?
list? map? More specifically, are there drawbacks or advantages to one
approach or another?
I'm very thankful for any guidance you'd like to offer.
Best regards,
Benjamin
--
View this message in context: http://drools.46999.n3.nabble.com/Collections-versus-Relational-Approach-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 8 months
Counting events / fact condition not evalauted with accumulate
by jpullmann
Dear contributors,
this simple rule should trigger only when a critical amount of particular
events was detected,
though it seems to accept any event of this type, disregarding the fact
condition (e.g. there
is no single event that matches "target == Long.MAX_VALUE"). The current
behaviour results in
an unconstrained type match: LocalizationEvent():
// annotation for external event class
declare LocalizationEvent
@role( event )
@duration( dur )
@timestamp( time )
end
// triggers on *any* LocalizationEvent, regardless of fact condition
rule "Detect crictial number of events"
when
accumulate(
// there is no matching event
$ev: LocalizationEvent(type == TYPE.LEFT, target == Long.MAX_VALUE, area
== Long.MAX_VALUE)
over window:time(30s) from entry-point "events/localization";
$n : count( $ev );
$n > 5 )
then
System.out.println($n+" events detected" );
end
The KB is configured for stream processing, the events are inserted in a
chronological order
and the session pseudo clock is advanced accordingly. Drools version in
use is 5.4.0.
Any suggestions are appreciated!
Many thanks
Jaro
--
View this message in context: http://drools.46999.n3.nabble.com/Counting-events-fact-condition-not-eval...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 8 months
Re: [rules-users] Rule Templates
by FrankVhh
>The information that would help me is (using Eclipse or JBDS) can one edit,
It depends if you mean edit the templates or edit the data that you use to
populate it.
You can create a rule template in any text editor you like and, AFAIK, it
can have any extension you prefer. Convert it to an inputstream and use it
in the code as is documented.
Regarding the data source, you have multiple options to collect the data.
Editing this data depends a bit on the type you are using. I typically
convert xml objects to java objects and use (and, sometimes, abuse) them to
fill the template and "generate" rules.
>compile to drl
Compile to drl is done using the code as documented.
String drl = converter.compile( objs, templateStream );
You can do with the String whatever you like. use it to feed a
knowledgebuilder directly, or write it to a file.
>and test the rule templates
Again. This depends on what you mean. If test the rule templates means:
"check whether it generates a correct drl", than there are 2 things you can
do.
1) Manually check that the rules are as you expect them to be.
2) Verify that the drl compiles in a knowledgebuilder.
If "test" means, check whether my generated rules can construct a correct
decision, then you wikk have to set up a service/a method/ a unit test in
which you use the rules to create a knowledge base and which takes input
data to generate a certain output.
If you want, you can use guvnor to create test scenarios or implement a
testing tool by your own.
Regards,
Frank
mclovis wrote
>
> Frank,
> Thank you for your quick reply. I had previously read your suggested
> documentation and understand the basics of rule templates. The information
> that would help me is (using Eclipse or JBDS) can one edit, compile to drl
> and test the rule templates. The information in the article does not
> reflect these things and furthermore has a lists of file types for Drools
> that is not in current versions of IDEs (example: rules resource). If you
> have knowledge of the mechanics of these things (using even Ant or Maven
> to compile), it would be much appreciated.
>
> Thanks in advance,
>
> Mike
>
--
View this message in context: http://drools.46999.n3.nabble.com/Rule-Templates-tp2820139p4018956.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 8 months
[Planner][DRL] Changable problem facts?
by mSkiba
Hello!
I am working on task scheduling system. My system works fine, but I want to
make it faster. For my current problem we can assume that my domain consists
of:
* Worker (int id, List<TimePeriod> workingHours)
* TaskAssignment (int id, List<TimePeriod> possibleExecutionTime, Duration
leadTime, Worker worker)
I am trying to assing each Task Assignment to 1 worker. It's obvious. All I
need to do is to make my rules computing faster. For example I have a rule:
rule "ASSIGN_OUT_OF_WORKING_TIME"
when
$w : Worker($id : id != 0, $wh : workingHours)
$ta : TaskAssignment(worker != null, worker.id == $id)
not TimePeriod( isBetweenInclusive($ta.getTimeSlot()),
isBetweenInclusive($ta.getEndTimeSlot()) ) from $wh
then
insertLogical(new IntConstraintOccurrence("ASSIGN_OUT_OF_WORKING_TIME",
ConstraintType.NEGATIVE_HARD,
100, $w ));
end
This rule checks if every TaskAssignment assigned to a Worker lies in the
worker's working hours. The problem is that score calculator is trying to
pair given Worker with every TaskAssignment. So I have to make set of
TaskAssignment as small as possible. I can acquire that by storing in a
Worker any kind of Set including all assigned TaskAssignments. After this my
domain should looks like this:
* Worker (int id, List<TimePeriod> workingHours, Set<TaskAssignment>
cashedTaskAssignments)
* TaskAssignment (int id, List<TimePeriod> possibleExecutionTime, Duration
leadTime, Worker worker)
and my rule:
rule "ASSIGN_OUT_OF_WORKING_TIME"
when
$w : Worker($id : id != 0, $wh : workingHours, *$cta :
cachedTaskAssignments*)
$ta : TaskAssignment() *from $cta*
not TimePeriod( isBetweenInclusive($ta.getTimeSlot()),
isBetweenInclusive($ta.getEndTimeSlot()) ) from $wh
then
insertLogical(new IntConstraintOccurrence("ASSIGN_OUT_OF_WORKING_TIME",
ConstraintType.NEGATIVE_HARD,
ASSIGN_OUT_OF_WORKING_TIME, $w ));
end
My cloneSolution() method is cloning everything right (deep clone of every
TaskAssignment and Worker). I've checked it via many tests. Anyways I'm
getting:
*Score corruption: the workingScore (-1800hard/0soft) is not the
uncorruptedScore (-1904hard/0soft):*
or similar error.
To sum up:
* my system works fine without any changes in Worker class
* I want to make it faster by caching assigned TaskAssignments in a Worker
objects
* I'm getting 'Score corruption' error
Is my idea possible to play out?
--
View this message in context: http://drools.46999.n3.nabble.com/Planner-DRL-Changable-problem-facts-tp4...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 8 months