Re: [rules-users] Using EntitySelector (EntityFilterClass)
by ge0ffrey
pppoole wrote
> I have a planning entity which has a "ResourceType" on it and I am
> attempting to schedule resources on the entity. The Resource is the
> Planning variable and the Resource instance has a "ResourceType" on it as
> well. I want to filter to make sure that a ResourceType matches between
> the PlanningEntity and the PlanningVariable prior to subjecting it to
> rules (since this is a hard constraint that can never be broken and want
> to save on performance). For example, if my PlanningEntity calls for a
> resource of type "janitor", then I shouldn't assign a Resource
> (PlanningVariable) of type "teacher" to the event. In order to filter
> these, I implemented a SelectionFilter class and validate that the
> entity's resource type matches the planning variable's resource type and
> return false if not. This is definitely returning the correct values (I
> debugged this to confirm), but yet my final solution is still getting the
> wrong resource types on it.
>
> My implementation for my filter:
>
> public boolean accept(ScoreDirector scoreDirector, PlanningEvent
> selection)
> {
> return selection.getRequiredResourceType().getType()
> .equals(selection.getResource().getResourceType().getType());
> }
>
> My configuration:
> <changeMoveSelector>
>
> <entitySelector>
>
> <entityFilterClass>
> com.lmco.mst.lss.autoscheduler.domain.move.RequiredTypeEntityFilter
> </entityFilterClass>
>
> </entitySelector>
> </changeMoveSelector>
> Please advise, I am kind of stuck.
>
> Thanks!
This thread continues here:
http://stackoverflow.com/questions/15394426/drools-planner-planner-not-pr...
--
View this message in context: http://drools.46999.n3.nabble.com/Using-EntitySelector-EntityFilterClass-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years
Strange exception
by goforcrazy
Hello,
I have been having my Drools project up and running but all of a sudden get
this new exception. Could anyone help me figure this out.
java.lang.IndexOutOfBoundsException: Index: 381, Size: 381
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at org.antlr.runtime.CommonTokenStream.LT(CommonTokenStream.java:103)
at org.drools.lang.ParserHelper.reportError(ParserHelper.java:391)
at org.drools.lang.DRLParser.compilationUnit(DRLParser.java:196)
at org.drools.lang.DRLParser.compilationUnit(DRLParser.java:157)
at org.drools.compiler.DrlParser.compile(DrlParser.java:240)
at org.drools.compiler.DrlParser.parse(DrlParser.java:157)
at org.drools.compiler.DrlParser.parse(DrlParser.java:139)
at
org.drools.compiler.PackageBuilder.drlToPackageDescr(PackageBuilder.java:478)
at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:467)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:673)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:45)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:34)
at cs441.eews.ServerApp.readKnowledgeBase(ServerApp.java:88)
at cs441.eews.ServerApp.main(ServerApp.java:36)
java.lang.RuntimeException: org.drools.compiler.DroolsParserException:
Unexpected exception raised while parsing. This is a bug. Please contact the
Development team :
Index: 381, Size: 381
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:705)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:45)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:34)
at cs441.eews.ServerApp.readKnowledgeBase(ServerApp.java:88)
at cs441.eews.ServerApp.main(ServerApp.java:36)
Caused by: org.drools.compiler.DroolsParserException: Unexpected exception
raised while parsing. This is a bug. Please contact the Development team :
Index: 381, Size: 381
at org.drools.compiler.DrlParser.compile(DrlParser.java:258)
at org.drools.compiler.DrlParser.parse(DrlParser.java:157)
at org.drools.compiler.DrlParser.parse(DrlParser.java:139)
at
org.drools.compiler.PackageBuilder.drlToPackageDescr(PackageBuilder.java:478)
at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:467)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:673)
... 4 more
Thanks,
Sam
--
View this message in context: http://drools.46999.n3.nabble.com/Strange-exception-tp4022814.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years
Implementing Refraction with Drools
by magaram
I believe we can inject in Refraction capabilities into Drools Rule Engine
using a simple Agenda Filter. I have tested this with test cases against
JRules and Drools and get similar results. Without the Refraction Agenda
Filter it loops infinitely as expected.
Please try it out and tell me what you think. I believe refraction is a much
needed feature of a forward chaining rule engine for commercial purposes.
Any feedback is deeply appreciated.
Here is what the code looks like
---------Agenda Filter---------------------------
package test;
import java.util.ArrayList;
import java.util.List;
import org.drools.runtime.rule.Activation;
import org.drools.runtime.rule.AgendaFilter;
/**
* This custom agenda filter injects refraction behavior into the rule engine
* @author Mukundan Agaram
*
*/
public class RefractionAgendaFilter implements AgendaFilter {
private List encounteredActivations = new ArrayList();
@Override
public boolean accept(Activation act)
{
//Check for a Refraction
if (encounteredActivations.contains(act))
{
//Remove from encountered activations for future firing
encounteredActivations.remove(act);
//return false so the rule is not selected as part of the refraction
return false;
}
//Otherwise add the rule to check for potential refractions in the future
encounteredActivations.add(act);
//select the rule to be part of the agenda
return true;
}
}
-----------------DRL------------------------
//created on: Jan 15, 2013
package test
dialect "mvel"
rule testFooBar1
salience 100
when
$foo : Foo()
$bar : Bar(y > 0)
then
$foo.setX(($foo.getX() + $bar.getY()));
System.out.println("Fired "+drools.getRule().getName())
update($foo);
end
rule testFooBar2
salience 150
when
$foo : Foo(x >= 6)
then
System.out.println("Fired "+drools.getRule().getName())
end
rule testFooBar3
salience 50
when
$foo : Foo(x >= 7)
then
System.out.println("Fired "+drools.getRule().getName())
end
----------------Runtime execution code--------------------------
package test;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
public class TestFooBarMain {
private static void test()
{
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( "TestFooBar.drl",
TestFooBarMain.class ),
ResourceType.DRL );
if ( kbuilder.hasErrors() ) {
System.out.println( kbuilder.getErrors().toString() );
}
else
{
System.out.println("DRL parsing - success!");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
Foo foo1 = new Foo();
foo1.setX(6);
Bar bar1 = new Bar();
bar1.setY(3);
ksession.insert(foo1);
ksession.insert(bar1);
ksession.fireAllRules(new RefractionAgendaFilter());
}
/**
* @param args
*/
public static void main(String[] args) {
test();
}
}
----------------Facts-------------------------
package test;
public class Foo {
private int x;
private int y;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
package test;
public class Bar {
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
private int x;
private int y;
}
Thanks,
Mukundan Agaram
--
View this message in context: http://drools.46999.n3.nabble.com/Implementing-Refraction-with-Drools-tp4...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years
Unable to parse ChangeSet in Linux Machine
by anniejoseph
Hi
I'm using change-set.xml, which pionts to a drl file.It *worked fine in
Windows* machine. But while running change-set.xml in *Linux machine I got
the following exception*.
java.lang.RuntimeException: *Unable to parse ChangeSet*
at
org.drools.agent.impl.KnowledgeAgentImpl.getChangeSet(KnowledgeAgentImpl.java:448)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:180)
at
xxx.xxxxxxx.xxxxx.xxxxxxxxxxxxx.xxxxxxxx.xxxxxxxx.<init>(xxxxxxx.java:79)
at
xxx.xxxxxxx.xxxxx.xxxxxxxxxxxxx.xxxxxxxx.xxxxxxxx.<clinit>(xxxxxxx.java:58)
at
org.apache.activemq.ActiveMQMessageConsumer.dispatch(ActiveMQMessageConsumer.java:1229)
at
org.apache.activemq.ActiveMQSessionExecutor.dispatch(ActiveMQSessionExecutor.java:134)
at
org.apache.activemq.ActiveMQSessionExecutor.iterate(ActiveMQSessionExecutor.java:205)
at
org.apache.activemq.thread.PooledTaskRunner.runTask(PooledTaskRunner.java:122)
at
org.apache.activemq.thread.PooledTaskRunner$1.run(PooledTaskRunner.java:43)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.net.ConnectException: Connection timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
at sun.net.NetworkClient.openServer(NetworkClient.java:118)
at sun.net.ftp.FtpClient.openServer(FtpClient.java:488)
at sun.net.ftp.FtpClient.openServer(FtpClient.java:475)
at
sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:270)
at
sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:352)
at org.drools.io.impl.UrlResource.grabStream(UrlResource.java:210)
at org.drools.io.impl.UrlResource.getInputStream(UrlResource.java:146)
at org.drools.io.impl.UrlResource.getReader(UrlResource.java:214)
at
org.drools.agent.impl.KnowledgeAgentImpl.getChangeSet(KnowledgeAgentImpl.java:446)
... 13 more
My code is:
kbase= KnowledgeBaseFactory.newKnowledgeBase();
ksession= kbase.newStatefulKnowledgeSession();
aconf = KnowledgeAgentFactory .newKnowledgeAgentConfiguration();
aconf.setProperty("drools.agent.newInstance", "false");
kagent = KnowledgeAgentFactory.newKnowledgeAgent( "Agent", aconf);
kagent.applyChangeSet( ResourceFactory.newFileResource(filePath));
kbase = kagent.getKnowledgeBase();
ksession= kbase.newStatefulKnowledgeSession();
sconf
=ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
sconf.setProperty( "drools.resource.scanner.interval",
AgentContainerContext.getRuleReloadInterval() );
ResourceFactory.getResourceChangeScannerService().configure( sconf );
ResourceFactory.getResourceChangeNotifierService().start();
ResourceFactory.getResourceChangeScannerService().start();
Can any one help me to solve my problem?
Thanks & Regards
Annie
--
View this message in context: http://drools.46999.n3.nabble.com/Unable-to-parse-ChangeSet-in-Linux-Mach...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years
Instant Drools Starter : Pack Publishing (Jeremy Ary)
by Mark Proctor
http://blog.athico.com/2013/03/instant-drools-starter-pack-publishing.html
We all start somewhere. My start with Drools came 5 years ago when I was tasked with maintaining some legacy rules and assisting with a new ground-up effort using the latest and greatest Drools release at the time. I dug through documentation, ordered every book I could find on the subject, and pestered Mark, Edson and others in the community willing to help way more than they probably cared for, but in the end, the community helped start me out with what I'd soon find to be my new obsession. Now, I feel like it's time for me to give something back.
If you're an architect, manager, or developer looking to evaluate or get started with Drools, you may find my new book, Drools Starter, to be a great way to get up and running quickly. I've done my best to compile all the basics needed to get a feel for working with the core engine into a brief, easy-to-digest guide. Here's some of what's covered inside:
Evaluate rules engines as a fit for your needs
Installing Drools and development tools
Authoring rule sets using the Drools Rule Language
Feeding information to your rules engine and evaluating rules
Understanding DRL syntax, operators, and functionality
Testing rules as a whole, individually, and for stability
Debugging the rule evaluation process visually and via logging
What modules make up the Drools system and the capabilities of each
Where to turn for more information and help
The book is currently available for pre-order (at a 20% discount!) over at Pack Publishing:
http://www.packtpub.com/getting-started-with-drools/book
I owe a large thanks to the community in helping me on my way through the last several years, especially to those in IRC and the mailing list who've aided with numerous predicaments and design choices along the way. Particular thanks to Mark, Edson and the rest of the development team for continued work on a great product and a great community, but especially to the two of you for spending too many hours in conversation online and at conferences helping myself and others like me find their way.
13 years