[planner] Performance question
by Guilherme Kunigami
Consider I have a set of N activities with a given start and end times and I
want to assign them to a set of rooms.
One of the main rules is to avoid two activities that have time conflicts,
to be assigned to the same room. I devised three modelling options:
[1] Do it entirely in Java code, checking whether there will be a conflict
before allowing an "Assignment move". This way, all solutions that the
algorithm works with are feasible.
[2] Do it using drools rules, like the following:
rule "Avoid conflicting activities"
when
Assignment($room1: room, $act1: activity, $id : activity.id)
Assignment(room == $room1, room!= null, $act2 : activity, activity.id >
$id)
eval(Activity.conflict($act1, $act2))
then
insertLogical(new IntConstraintOccurrence("conflictingActivities",
ConstraintType.NEGATIVE_HARD,
10, null));
end
Here I'm using Assignment as the only planning entity. There's an assignment
for each activity and it may point to a room or to null in the case the
activity is not assigned. In the case above, I have a static function that
checks whether two activities conflicts. This way, solutions may be
infeasible but with high penalties the best solution found will eventually
be feasible.
I also thought of a third option, which is to insert a fact "Conflict" for
each pair of conflicting activities in a preprocessing phase. This way we
would end up with:
rule "Avoid conflicting activities"
when
Assignment($room1 : room, $act1: activity, $id : activity.id)
Assignment(room== $room1, room != null, $act2 : activity, activity.id > $id)
Conflict(act1 == $act1, act2 == $act2)
then
insertLogical(new IntConstraintOccurrence("conflictingActivities",
ConstraintType.NEGATIVE_HARD,
10, null));
end
The problem is that there may be up to O(N^2) such objects.
I do not know the rules engine algorithm in depth, so I'd like to know: Is
any of these approaches more efficient than the others?
Thanks!
13 years, 2 months
drools persistence contract
by Michal Bali
Hi all,
When persisting a session, process instance or workitem, Drools persists
some parts of the state as byte arrays.
I am trying to upgrade from 5.1 to 5.3 and I have some existing
sessions/processes persisted in the database. I am wondering if it is safe
to upgrade? Will the bytearrays created by 5.1 work fine with 5.3?
Is there any document describing persistence compatibility between versions?
I don’t see much in the “new and noteworthy” in relation to persistence.
Thanks.
Keep up the good work!
Best regards,
Michal
13 years, 2 months
KnowledgeBuilder.add(Resource, ResourceType) thread problem?
by chriscarr
I have a rules server that will handle executing different flows as requests
come in. For each thread, the following snippet is used:
final KnowledgeBuilder builder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
final Resource resource =
ResourceFactory.newClassPathResource(bpmnFile, Foo.class);
builder.add(resource, ResourceType.BPMN2);
if (builder.hasErrors())
System.out.println....
Unfortunately, it reports an error when there are simultaneous threads in
the "add" method of their respective builders.
This appears using Windows XP, Drools 5.1.1 and 5.2.0.Final, and either JDK
1.5 or 1.6. Attached is a small command-line project to reproduce the
problem.
-----------
Environment
-----------
OS: Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
DOWNLOAD: http://www.jboss.org/drools/downloads.html -->
droolsjbpm-tools-distribution-5.2.0.Final.zip
JAVA: java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode, sharing)
java version "1.5.0_19"
Java(TM) 2 Runtime Environment, Standard Edition (build
1.5.0_19-b02)
Java HotSpot(TM) Client VM (build 1.5.0_19-b02, mixed mode,
sharing)
------------------------------
Output from Drools 5.2.0.Final
------------------------------
This is the output that I was able to create on subsequent runs of the test
harness. The errors are different combinations of (but no limited to) the
messages below.
Message(s):
Process 'simple bpmn process #1' [simple.flow.id.one]: Process has no
start node. {where the "process" may vary}
Process 'simple bpmn process #2' [simple.flow.id.two]: Process has no
end node. {where the "process" may vary}
--
View this message in context: http://drools.46999.n3.nabble.com/KnowledgeBuilder-add-Resource-ResourceT...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 2 months
Help needed - how to get Number and intValue in Guvnor
by Praveen
Hello,
I am new to Drools and trying to write rules using Guvnor GUI.
I have uploaded POJO's that are required for my rules.
I am facing issue trying to get Number()(the one in Bold-Italics) and
intValue in the Guvnor GUI.
Below is the rule for reference, its taken from one of the examples provided
in Drools Planner.
// Accumulate hard constraints
rule "hardConstraintsBroken"
salience -1 // Do the other rules first (optional, for performance)
when
$hardTotal : */Number(/)* from accumulate(
IntConstraintOccurrence(constraintType ==
ConstraintType.NEGATIVE_HARD, $weight : weight),
sum($weight) // Vote for
http://jira.jboss.com/jira/browse/JBRULES-1075
)
then
scoreCalculator.setHardConstraintsBroken($hardTotal.intValue());
end
--
View this message in context: http://drools.46999.n3.nabble.com/Help-needed-how-to-get-Number-and-intVa...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 2 months
Rules from Multiple DRLs use the same namespace
by rajee.sakthi
Hi,
I am a newbie to DROOLs. I want to cross check with you for any potential
issues that you see about my DROOLs usage.
I have a requirement to create multiple DRLs that use the same namespace.
Hence, I am adding rules from DRL1, DRL2, DRL3 to a package named
"com.myproj.pkg".
And at some point I am removing rules of DRL1 from the knowledge package
leaving rest of the rules.
When all the rules from the package are removed, then I am removing the
knowledge package.
This is all done with StatefulSession.
So my rules removal code looks like this:
String pkgName = kpkg.getName();
Collection<Rule> rules = kpkg.getRules();
for(Rule rule : rules) {
knowledgeBase.removeRule(pkgName, rule.getName());
}
KnowledgePackage pkgAfterRemove =
knowledgeBase.getKnowledgePackage(pkgName);
Collection<Rule> rulesAfterCleanup = pkgAfterRemove.getRules()
if(rulesAfterCleanup == null || rulesAfterCleanup.isEmpty()) {
knowledgeBase.removeKnowledgePackage(pkgName);
}
I tested this logic and it works fine but does anyone see any side effects
of such logic?
I did a short search in the forum and couldnt find any similar posts.
Thanks a bunch,
Rajee
--
View this message in context: http://drools.46999.n3.nabble.com/Rules-from-Multiple-DRLs-use-the-same-n...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 2 months
compiled processes in PKG removed by knowledge agent after first change scan
by Jiang Zhu
hi,
I'm having trouble with scanning changed knowledge from Guvnor. I found out
that compiled processes from Guvnor are missing after resource change
scanner scan for changes first time (event there is no changes).
I wrote a simple test to reproduce this.
public class KnowledgeAgentTest {
@Test
public void should_load_processes() throws Exception {
ResourceChangeScannerConfiguration sconf =
ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
// Scan change every 2 seconds
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent("agent");
// Changeset points to a PKG contains 12 processes on Guvnor
kagent.applyChangeSet(ResourceFactory.newClassPathResource("test/drools-changeset.xml"));
// Everything is still ok now
System.out.println("Processes before scan: " +
kagent.getKnowledgeBase().getProcesses().size());
Assert.assertFalse(kagent.getKnowledgeBase().getProcesses().isEmpty());
// Scan change every 2 seconds
sconf.setProperty("drools.resource.scanner.interval", "2");
ResourceFactory.getResourceChangeScannerService().configure(sconf);
ResourceFactory.getResourceChangeScannerService().start();
ResourceFactory.getResourceChangeNotifierService().start();
// Wait long enough
Thread.sleep(5000);
// Processes are gone somehow
System.out.println("Processes after scan: " +
kagent.getKnowledgeBase().getProcesses().size());
Assert.assertFalse(kagent.getKnowledgeBase().getProcesses().isEmpty());
}
}
Here is what I'm getting when run the test.
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running test.KnowledgeAgentTest
Processes before scan: 12
Processes after scan: 0
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 5.802 sec
<<< FAILURE!
Results :
Failed tests: should_load_processes(test.KnowledgeAgentTest)
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
Thanks,
Jiang
--
View this message in context: http://drools.46999.n3.nabble.com/compiled-processes-in-PKG-removed-by-kn...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 2 months