Runing Rules in Two Phases ( using AgendaFilters ) with inference
by viraj
Hi all,
I have a system which i'm running to learn drools. In this system I have two
sets of rules. First one is eligible rules and other set is selection rules
which depend on eligible rules. So the system first evaluate eligible rules
and then add those results to facts in-order to use in selection rules.
System is working fine in this way. Now I want to run this with two phases.
i.e without using fireAllRules() , I need to run eligible rules ( which are
in rule package "rule.eligible" ) using AgendaFilter and then later run the
selection rules which are in "rule.selection" package. The problem is even
though eligible rules activate selection rules , in second phase selection
rules won't run. I checked rule execution with KnowledgeRuntimeLogger. This
shows eligible rules correctly activate selection rules but later when i run
selection rules only , those activated rules do not get executed. I really
want to rule this in two phases since in some scenarios, I only need
eligible objects. Is there a another way to achieve this kind of work ?
Ex : Eligible Rule
package rule.eligible
rule "Eligible Rule 1 - 4 "
no-loop true
when
$evaluationResults : EvaluationResults( valids not contains "4" );
UserProfile( userState == UserState.TEST , status == 1 )
then
modify( $evaluationResults ) { addIntoEvaluated( 4 + "" ) } ;
end
Ex : Selection Rule
package rule.selection
rule "Selection Rule - 3"
no-loop true
when
$evaluationResults : EvaluationResults( validMap not contains "3" ,
valids contains "4" )
then
modify( $evaluationResults ){ addIntoEvaluatedMap("3", "21","23")}
end;
I'm executing rules in following way.
To run eligible rules.
statefulKnowledgeSession.fireAllRules(DroolsHelper.getActivatedRulesFromRuleStartWith("Eligible
Rule"));
To run selection rules.
statefulKnowledgeSession.fireAllRules(DroolsHelper.getActivatedRulesFromRuleStartWith("Selection
Rule"));
Method DroolsHelper.getActivatedRulesFromRuleStartWith
public static AgendaFilter getActivatedRulesFromRuleStartWith(final
String startWith) {
AgendaFilter filter = new AgendaFilter() {
public boolean accept(Activation activation) {
if (activation.getRule().getName().startsWith(startWith)) {
return true;
}
return false;
}
};
return filter;
}
Thanks in advance
--
View this message in context: http://drools.46999.n3.nabble.com/Runing-Rules-in-Two-Phases-using-Agenda...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 3 months
Long pattern for Nurse Rostering
by john poole
I'm trying to create a rule for a 15 day pattern. When the patterns uses the
same shift for all 15 days, I do this:
rule "unWanted15DayPattern"
when
$pattern : U15DayPattern(
$numberOfDays : numberOfDays,
$shiftType : shiftType
)
ShiftAssignment(
shiftType == $shiftType,
$employee : employee,
$firstDayIndex : shiftDateDayIndex
)
ShiftDate( $firstDayIndex == dayIndex, dayIndex % 15 == 0)
//Check for different employee working that shift in the next N days
$shiftAssignment : ShiftAssignment(
shiftType == $shiftType,
employee != $employee,
shiftDateDayIndex > $firstDayIndex,
shiftDateDayIndex < $firstDayIndex + 15
)
then
insertLogical(new IntConstraintOccurrence("unWanted15DayPattern",
ConstraintType.NEGATIVE_SOFT,
$pattern.getWeight(),
$firstDayIndex));
end
But I'm having a hard time figuring out how to do it with different
shiftTypes for each day, because it means having to use a loop.
Not sure if that makes sense, but it anyone has used a long pattern that
stores items in a list/array I'd love to hear how they did it.
--
View this message in context: http://drools.46999.n3.nabble.com/Long-pattern-for-Nurse-Rostering-tp4025...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 3 months
Re: [rules-users] Is my use case suuported in Drools?
by Elran Dvir
I neglected to mention I am checking different types of CEP engines to embed inside our java application.
So my question is about Drools Fusion syntax and features.
Thanks.
From: Elran Dvir
Sent: Sunday, August 11, 2013 10:57 AM
To: rules-users(a)lists.jboss.org
Subject: Is my use case suuported in Drools?
Hi all,
I am new to drools and I'm trying to understand whether the following use case is supported - any help on the following will be greatly appreciated:
I would like to create a new event based on multiple events (all of the same type meeting a set of conditions) occurring over a given period of time T1.
For each combination of values for fieldA and fieldB, a new group of event candidates should be opened (fieldA and fieldB are group by fields. Each combination of values of these fields, should be treated separately).
The event should be created when at least X events occurred over the period. Count the events based on unique values of fieldC and fieldD (for a given combination of fieldA and fieldB, if you notice an event with already existing values of the combination of fieldC and fieldD, it should not be counted).
If all conditions described above are met, create the desired new event. The new event will stay open for duration of T2, and update will be sent for it every T3.
Aside from the above, I need an aggregation function (besides count) of "collect" : in the new event the value of fieldE will be the collection of (preferably distinct) values of fieldE in originating events.
Example:
Port scan event - the basic event is connection. For each combination of source_ip and destination_ip (group by fields), detect a port scan event if over a minute (T1) there more than 20 (X) events with different ports (unique field).
The event will stay open for 10 minutes (T2) and an update will be sent every 1 minute (T3). Every update will contain the count of events, source_ip, destination_ip and collection of services.
Thanks a lot.
11 years, 3 months
calling kbuilder API from jsp and servlet
by ashish6276
Hi,
we are trying to call drools api from servlet by using
KnowledgeBuilderFactory and proving drl path and creating knowledge base and
session but when i am gonna fireRule it is giving me compile time error.
I am pasting the log below.
Aug 9, 2013 10:17:11 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet dispatcher threw exception
java.lang.NoClassDefFoundError: org/drools/builder/KnowledgeBuilderFactory
at
com.maxmechanics.controller.MMController.fireRulesAndGetResponse(MMController.java:467)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:439)
at
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:427)
at
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
at
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
this error is coming while initializing knowledgefactory.
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
--
View this message in context: http://drools.46999.n3.nabble.com/calling-kbuilder-API-from-jsp-and-servl...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 3 months
Guvnor in Reselliency environment : Assets stored in DB not visible in Secondary server
by Zahid Ahmed
I am working in Drools-Guvnor-5.5.0.Final version and have configured repository.xml to save all assets + indexes in Oracle 11 database.
I am deploying Guvnor in a resilient environment which has two servers. Guvnor deployed in both the servers is pointing to the same database.
Step 1
For this I generated the repository.xml from the administration panel of Guvnor and replaced in both primary and secondary Guvnor instance. And when I started the server and imported assets into primary guvnor, I was able to see the following tables in database,
1. FS_FSENTRY;
2. FS_WS_DEFAULT_FSENTRY;
3. PM_WS_DEFAULT_FSENTRY;
4. PM_WS_DEFAULT_BINVAL;
5. PM_WS_DEFAULT_BUNDLE;
6. PM_WS_DEFAULT_REFS;
7. PM_WS_DEFAULT_NAMES;
8. REPOSITORY_FS_FSENTRY;
9. VERSIONING_FS_FSENTRY;
10. VERSIONING_PM_BINVAL;
11. VERSIONING_PM_BUNDLE;
12. VERSIONING_PM_NAMES;
13. VERSIONING_PM_REFS;
I also configured workspace.xml files in
1. jboss-eap-6.0/bin/repository/workspaces/default
2. jboss-eap-6.0/bin/repository/workspaces/security
Step 2
Now started secondary guvnor, configured similar to primary Guvnor. But secondary server did not displayed the packages and assets from DB. Instead asked me to install sample packages.
Step 3
I configured DataStore in repository.xml. Restarted primary Guvnor server and found one more table is created in database with the assets init.
Table name : DS_DATASTORE
Step 4
Configured secondary Guvnor with DataStore and restarted it. Now I could see the packages of primary Guvnor, But the assets in packages were not available.
I am attaching the repository.xml file from both the servers.
Thanks and Best Regards,
Zahid Ahmed
Senior Software Engineer | Emirates Group IT
P.O. Box 686 | Dubai, United Arab Emirates
T +971 4 245 2551| M +971 55 124 9171
11 years, 3 months
WorkingMemoryListener & Declared Types
by droolster
Hello,
Please can the community help me.
I am attaching a WorkingMemoryListener to a session. In my DRL file, I have
a number of declared types for which I want to "watch" when the process is
running. How can I implement a "toString()" method in the DRL file for a
declared type? I have detailed the structure of my code below to make it
clear what I am trying to do:
DRL FILE
--------
declare Foo
low : double
high : double
score : int
end
Java Code
----------
ksession.addEventListener(new WorkingMemoryEventListener()
{
@Override
public void objectInserted(ObjectInsertedEvent event) {
System.out.println(*"Inserted: " + event.toString()*);
/*// Here I would like to print out the data in the
type Foo in a specific format.*/
}
@Override
public void objectUpdated(ObjectUpdatedEvent event) {
System.out.println("Updated");
}
@Override
public void objectRetracted(ObjectRetractedEvent event) {
System.out.println("Retracted");
}
});
Thanks in advance for your help.
--
View this message in context: http://drools.46999.n3.nabble.com/WorkingMemoryListener-Declared-Types-tp...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 3 months