Optaplan6.0.0Beta1:chaining-simpleScore OK, DRL Score corruption
by Paul T
Requirement:Equip to tasks scheduling.Earlier tasks may not exceed a waittime
to latest endtime for each job.
2 JOBs to plan each with 2 identical TASKs with only 1 EQUIPMENT anchor:
J1 comprises T1,T2 and J2 comprises T1,T2.
problem Fact: EQUIPMENT E1
planning Entity: TASK T1|duration=3|waittime=2 and
T2|duration=5|waittime=3
OptaPlan Schedule attempt
-------------------------
anchor(E1:T1J1,T1J2,T2J1,T2J2) - so T1J1 is pos1,T1J2 is pos2 etc :
timings are 3+3+5+5 and respective waittimes are 2,2,3,3
Rule: get latest ending task by JOB and punish if waittime is exceeded
between the tasks for that specific JOB.
J1 latestendtime=11 which is T2J1
J2 latestendtime=16 which is T2J2
Punish if any task endtime for JOB exceeds waittime (so for J1:
T2J1-T1J1=(11-6-2)*-1 = -3 (SOFT)
- I believe that the score function remembers J1,T2J1 in position 3 and
T1J1 in position 1 with SOFT score -3
OptaPlan Schedule attempt
-------------------------
anchor(E1:T1J1,T2J2,T2J1,T1J2) - so T1J1 is pos1,T2J2 is pos2 etc :
timings are 3+5+5+3 and respective waittimes are 2,3,3,2
Rule: get latest ending task by JOB and punish if waittime is exceeded
between JOBs
J1 latestendtime=13 which is T2J1
J2 latestendtime=16 which is T1J2
Punish if any task endtime for JOB exceeds waittime (so for J1:
T2J1-T1J1=(13-6-2)*-1 = -5 (SOFT)
- I believe that the score function remembers J1,T2J1 in position 3 and
T1J1 in position 1 with SOFT score -5
Score corruption seems to occur as the DRL scoring function has 2 identical
set of entities/values but with different score results!
J1,T2J1 in position 3 and T1J1 in position 1 with SOFT score -3
J1,T2J1 in position 3 and T1J1 in position 1 with SOFT score -5
What has happened is that J2 has swapped its tasks around which are not(?)
taken into account for a chaining DRL score function and
hence does not see them as different.
Q?: Am I correct in my assumption that the DRL score function has
insufficient data to compare for my requirement?
Q?: If so any ideas to resolve?
--
View this message in context: http://drools.46999.n3.nabble.com/Optaplan6-0-0Beta1-chaining-simpleScore...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 11 months
How to write Hibernate query lang(HQL) in .DRL file
by zeeshan
Hi !
According to my requirement I need to fetch and Insert data from database
using Hibernate Query from .DRL file.
I have idea how to execute HQL in Plain Java class but according to my
requirement,I need to fire query to database from .DRL file which I tried
but unable to get output instead I was getting errors.
Can anyone suggest me process to execute Hibernate Query from DRL file
or please provide me some sample code or any link.
Thanks !!
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-write-Hibernate-query-lang-HQL-i...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 12 months
[Planner]
by Mats Norén
Hi,
I've got a really simple problem that I can't seem to fix. :-)
I'm trying to use a simplified model for a room planning problem.
The planning entity is a Topic and the planning variables are Room and
TimeSlot.
A Person is tied to a Topic as a moderator.
Each Person can have multiple Topics as an interest.
The hard constraints are that a Person cannot be moderator in two Topics at
the same TimeSlot and that there cannot be multiple Topics in the same Room
at the same TimeSlot.
rule "conflictingModeratorInSameTimeslot"
when
$leftTopic : Topic($leftId : id, $leftTimeslot : timeSlot, timeSlot
!= null, $leftModerator: moderator)
$rightTopic : Topic(timeSlot == $leftTimeslot, moderator ==
$leftModerator, id > $leftId)
then
scoreHolder.addHardConstraintMatch(kcontext, -1);
end
rule "multipleTopicsInSameRoomAndTimeslot"
when
$leftTopic : Topic($leftId : id, $leftTimeslot : timeSlot, timeSlot
!= null, $leftRoom: room)
$rightTopic : Topic(timeSlot == $leftTimeslot, room == $leftRoom,
id > $leftId)
then
scoreHolder.addHardConstraintMatch(kcontext, -1);
end
The soft constraint that I have a problem with is that a Person has
multiple Topics as interests and I would like to penalize the Solution with
the number of Topics in the Persons interests collection with the number of
Topics that are allocated at the same TimeSlot.
Any ideas on how to go about this?
Regards,
Mats
13 years
KnowledgeAgent to update knowledge base built with Guvnor pkg
by riri
Hello everyone,
I am trying to take advantage of the automatic uploading that the
KnowledgeAgent provides and am using the 5.5.Final Drools version. The
Drools Expert documentation states that one can use an existing knowledge
base to create an agent, and the agent will subscribe to the resources that
it finds (Example 3.26. Using an existing KnowledgeBase).
I am at first creating the knowledge base using a set of .drl files defined
in a change-set file and also a Guvnor url :
http://127.0.0.1:8080/guvnor/org.drools.guvnor.Guvnor/package/<package-name>/LATEST.
I then create the knowledge agent as shown in Example 3.26 of the
documentation. The problem is that if I modify the Guvnor package (add or
remove a rule) and then rerun a stateful knowledge session, the knowledge
base is not updated. I thought that I needed to build the package in Guvnor
every time I modify it but doing so does not solve the problem. Modifying
the rules in the change-set files seems to update the knowledge base.
I start the ResourceChangeScanner and ResourceChangeNotifier and if I call
isMonitorChangeSetEvents() and isScanResources() they return true. And also,
whenever I create a session, I use the getKnowledgeBase() method and am not
caching it somewhere in my program. Should I not be creating the agent with
an existing knowledge base and instead use the applyChangeSet() method? If
so, how would I be able to configure the knowledge base to use
AssertBehaviorOption.EQUALITY?
Thany you very much for any help or tips to point me in the right direction.
Best regards
--
View this message in context: http://drools.46999.n3.nabble.com/KnowledgeAgent-to-update-knowledge-base...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years
Error deploying Guvnor 6.0.0.Beta1 on Tomcat 7
by maunakea
I was excited to try out Guvnor 6. Downloaded the Beta1 and tried deploying
on Tomcat 7.0.32. It deployed fine, but when I access the URL, I get the
trace below. Anybody able to deploy on Tomcat 7?
org.jboss.errai.bus.client.api.base.MessageDeliveryFailure: error invoking
endpoint
at
org.jboss.errai.bus.server.io.ConversationalEndpointCallback.callback(ConversationalEndpointCallback.java:132)
at
org.jboss.errai.bus.server.io.RemoteServiceCallback.callback(RemoteServiceCallback.java:54)
at
org.jboss.errai.cdi.server.CDIExtensionPoints$3.callback(CDIExtensionPoints.java:512)
at
org.jboss.errai.bus.client.framework.DeliveryPlan.deliver(DeliveryPlan.java:43)
...
Caused by: java.lang.NullPointerException
at
org.uberfire.backend.server.UserServicesImpl.buildPath(UserServicesImpl.java:71)
at
org.uberfire.backend.server.UserServicesImpl$Proxy$_$$_WeldClientProxy.buildPath(UserServicesImpl$Proxy$_$$_We
at
org.uberfire.backend.server.WorkbenchServicesImpl.getPathToDefaultEditors(WorkbenchServicesImpl.java:105)
at
org.uberfire.backend.server.WorkbenchServicesImpl.loadDefaultEditorsMap(WorkbenchServicesImpl.java:76)
at
org.uberfire.backend.server.WorkbenchServicesImpl$Proxy$_$$_WeldClientProxy.loadDefaultEditorsMap(WorkbenchSer
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.jboss.errai.bus.server.io.ConversationalEndpointCallback.callback(ConversationalEndpointCallback.java:114)
... 29 more
*** Message delivery failure ***
Bus: org.jboss.errai.bus.server.ServerMessageBusImpl@134137c
Message: CommandType=loadDefaultEditorsMap:,
ErrorTo=org.uberfire.client.workbench.services.WorkbenchServices:RPC.loadDef
errorMessage: Error calling remote service:
org.uberfire.client.workbench.services.WorkbenchServices:RPC
exception: org.jboss.errai.bus.client.api.base.MessageDeliveryFailure: error
invoking endpoint
disconnect: false
org.jboss.errai.bus.client.api.base.MessageDeliveryFailure: error invoking
endpoint
at
org.jboss.errai.bus.server.io.ConversationalEndpointCallback.callback(ConversationalEndpointCallback.java:132)
at
org.jboss.errai.bus.server.io.RemoteServiceCallback.callback(RemoteServiceCallback.java:54)
at
org.jboss.errai.cdi.server.CDIExtensionPoints$3.callback(CDIExtensionPoints.java:512)
at
org.jboss.errai.bus.client.framework.DeliveryPlan.deliver(DeliveryPlan.java:43)
--
View this message in context: http://drools.46999.n3.nabble.com/Error-deploying-Guvnor-6-0-0-Beta1-on-T...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years
window:length with variables as constraints not working correctly
by Andreas
Hello,
I'm having a problem using sliding windows length
I would like to get the average oft he last 5 Events of the AccountNumber
"123"
(rule: FiveLastEventsWhichBelongsToTheAccount).
If there are no Events with other AccountNumbers and if the AccountNumber is
directly added as String as a rule constraint, both cases will work
correctly as I understand the rule behaviour
But
If there are Events available for different AccountNumbers and the
AccountNumber is extracted from the $account : Account() to use it as a
constraint to check if the Event belongs to the AccountNumber the condition
is not working like first filter then window; it seems to work like first
window then filter)
I don’t know if it should work like this or if it is maybe a bug.
If I’m wrong, how is it possible to solve my problem, so that I don’t need
to write a rule for every possible account number.
Thanks in advanced
Andreas
I’m using drools version 5.3.5 because of the NPE (
https://issues.jboss.org/browse/DROOLS-78?page=com.atlassian.jira.plugin....),
which don’t occurs in this test case but in other rules I’ve implemented. So
it would be nice to have a solution for version 5.3.5.
For Testing you can use the following classes and drl File:
public class Account {
private String number = "";
public Account() {
super();
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
}
public class Event implements Serializable {
private static final long serialVersionUID = 1L;
private String accountNumber = "";
private double amount = 0.00;
public Event(String accountNumber, double amount) {
this.accountNumber = accountNumber;
this.amount = amount;
}
public String getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(String accountNumber) {
this.accountNumber = accountNumber;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
}
Rule file
declare Event
@role( event )
end
rule "FiveLastEventsWhichBelongsToTheAccount"
when
$account : Account()
$averageOfAmount : Number( doubleValue > 0 )
from accumulate(
Event(
//accountNumber == “123“, //works
accountNumber == $account.number, //not working if
more than one
//AccountNumbers available during all events
$amount : amount
)
over window:length( 5 ) from
entry-point EventStream,
average($amount)
)
then
System.out.println("Average of aveOfLastClaims: " + $averageOfAmount);
End
TesterClass:
public class Tester {
private static final String DRL_FILENAME = "account.drl";
private static final String ENTRY_POINT = "EventStream";
private static KnowledgeBase knowledgeBase = null;
private static StatefulKnowledgeSession session = null;
private static Account account123 = null;
private static String accountNumber123 = "123";
private static Account account456 = null;
private static String accountNumber456 = "456";
private static void setUp() {
prepareKnowledgeBase();
prepareStatefulKnowledgeSession();
prepareAccounts();
}
private static void prepareAccounts() {
account123 = new Account();
account123.setNumber(accountNumber123);
account456 = new Account();
account456.setNumber(accountNumber456);
}
private static void prepareStatefulKnowledgeSession() {
KnowledgeSessionConfiguration sessConfig =
KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
sessConfig.setOption(ClockTypeOption.get("pseudo"));
session = knowledgeBase.newStatefulKnowledgeSession(sessConfig, null);
}
private static void prepareKnowledgeBase() {
try {
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
builder.add(ResourceFactory.newClassPathResource(DRL_FILENAME),
ResourceType.DRL);
KnowledgeBuilderErrors errors = builder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowledgeBase.addKnowledgePackages(builder.getKnowledgePackages());
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
setUp();
try {
SessionPseudoClock clock = session.getSessionClock();
WorkingMemoryEntryPoint eventStream =
session.getWorkingMemoryEntryPoint(ENTRY_POINT);
eventStream.insert(new Event(accountNumber123, 50.00));
eventStream.insert(new Event(accountNumber456, 500.00));
clock.advanceTime(5, TimeUnit.DAYS);
eventStream.insert(new Event(accountNumber123, 40.00));
eventStream.insert(new Event(accountNumber456, 400.00));
clock.advanceTime(10, TimeUnit.DAYS);
eventStream.insert(new Event(accountNumber123, 30.00));
eventStream.insert(new Event(accountNumber456, 300.00));
clock.advanceTime(15, TimeUnit.DAYS);
eventStream.insert(new Event(accountNumber123, 20.00));
eventStream.insert(new Event(accountNumber456, 200.00));
clock.advanceTime(20, TimeUnit.DAYS);
eventStream.insert(new Event(accountNumber123, 10.00));
eventStream.insert(new Event(accountNumber456, 100.00));
session.insert(account123);
session.fireAllRules();
} catch (Throwable t) {
t.printStackTrace();
}
}
}
--
View this message in context: http://drools.46999.n3.nabble.com/window-length-with-variables-as-constra...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years