Drools Planner: Solving a job schedule problem
by mr_moe
Hey,
I want to solve the following problem using drools planner:There are several
jobs which should be worked through by a machine on one day. Each job has a
length and a constraint that it only can be worked of between a fixed start
and end date.
For example there are three tasks
Job first possible start date last possible start date length
A 7:00 am 8:30 am 60 min
B 7:30 am 10:00 am 30 min
C 10:30 am 12:00 pm 60 min
The jobs should be organized in the following way, that there is as less
time between tasks as possible. If it is due to restrictions not possible to
order the tasks without a break and also the break is longer than, say, 20
minutes, the tasks should be organized with a long break as possible.Tasks
cannot overlap.
A good solution would be:
Job Start date End date
A 7:00 am 8:00 am
B 8:00 am 8:30 am
C 12:00 am 1:00 pm
First, the planning variable (ValueRangeType.FROM_PLANNING_ENTITY_PROPERTY)
of each task is its start date, which can takes a value which is between the
first possible start date and the last possible start date. E.g. possible
start dates for job A are between 7:00 am and 8:30 am. To make sure, that
tasks aren’t scheduled at the same time, I’ve written a hard constraint
rule, which checks if one task overlaps with another one. And running the
planner with hard constraints only, it works fine.
But now I’m getting problems, writing the soft constraints. At the moment,
every job (planning entity) has variables, called “nextJob” und “prevJob”,
which points to the jobs which are scheduled before and after that job. In
my example, it would look like this:
Job prevJob nextJob
A null Job B
B Job A Job C
C Job B null
My intention of these variables is that I can check with a soft constraint
rule, if the current chosen job and the job with which it gets compared are
consecutive jobs, and if so, how much time between these jobs is left.
In the soft constraint rule, I check if the “nextJob” Variable points to the
job, with which I’m currently comparing the job. If this is the case, then
there is no other job scheduled between those jobs and I can check how much
time between these jobs is left.
Every time drools planner reschedules a job, I have to check if nextJob and
prevJob of each job are still pointing to their right predecessor and
successor.
For example, if Job A gets moved to 8:00 the sequence could look like this:
Job Start date End date
A 8:00 am 9:00 am
B 7:30 am 8:00 am
C 12:00 am 1:00 pm
Therefore the variables preJob and nextJob have to be adjusted for each job:
Job prevJob nextJob
Job A Job B Job C
Job B null Job A
Job C Job A null
To achieve that, I use a list in which I save the current order of the
jobs.Furthermore I’ve written my own mover that, besides assigning the
current job to its new start date, updates the list and each job if a job
gets rescheduled.
You’ve probably got the punch line by now: It’s not working. And besides
from getting a scoreCurroption exception, I truly doubt that this is the
perfect solution for solving this planning problem.Have any of you an idea,
what a better way for solving this problem could be?
I’ve tried to find a similar problem in the examples, but none of them has
similar restrictions as mine. The curriculumcourse example has only fixed
time slots instead of a variable length and in the nurserostering, nurses
(jobs) get assigned to fixed shifts (time periods) and not the other way
around.
Thanks!
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Planner-Solving-a-job-schedule-p...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years
XML rule: Wrongly interpreted Numeric String to Number
by Christina Lau
Dear all,
System is generating XML rule file with literal-restriction like that:
...
<field-constraint field-name="myStringTypeField">
<literal-restriction evaluator="=="
value="0020" />
</field-constraint>
...
I am expecting the constraint is in form of
myStringTypeField == "0020"
However, the outcome is
myStringTypeField == 0020 (the double quote is missed)
causing my rule fails all the time.
Does anyone know if it it the problem of XML parsing? If yes, can I do
something to override the default parser behaviour?
Thank you very much.
Christina
--
View this message in context: http://drools.46999.n3.nabble.com/XML-rule-Wrongly-interpreted-Numeric-St...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years
passing empty string to a method with varargs failed on the second execution
by brachi
ContainsCODE.drl
<http://drools.46999.n3.nabble.com/file/n4021195/ContainsCODE.drl>
See attached DRL. input is: condContainsCODE=Lists.newArrayList("1", "2",
"4")
I Executed this DRL with the above input twice times. I got indexOutOfBound
Exception.
If I execute it *only one time* I didn't get this exception.
In addition, I found that if I change the rule to be *without the empty
string element*, then I didn't get this exception even if I run it twice
times.
This rule failed on the second time:
when condContainsCODE(Operators.contains(value,"1","2",*" "*))
this succeeded even in the second time:
when condContainsCODE(Operators.contains(value,"1","2"))
also this:
when condContainsCODE(*eval*(Operators.contains(value,"1","2",*" "*)))
That is the *Operators.contains* method:
public static boolean contains(Collection<?> c1, Object.. obj) {
return c1.containsAll(Lists.newArrayList(obj));
}
I read that are problems with varargs, but I don't understand why only
*space *causes problems, and why only in the *second time*?
looks like optimizer bug...
--
View this message in context: http://drools.46999.n3.nabble.com/passing-empty-string-to-a-method-with-v...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years
Is Drools suitable for preprocessing my Resource Allocation Problem
by Raphael Jolivet
Hello,
Here is a copy of a question I just sent on Stackoverflow :
http://stackoverflow.com/questions/13753983/is-drools-suitable-for-prepro...
I have a quite big resource allocation problem to compute.
I have just discovered Drools and I would like to know if it is a good
candidate to work as a preprocessor and generate a list of forbidden
allocations, based on some user rules.
The ProblemI have an optimisation engine that can allocate some activities
to some resources, while optimizing some KPIs (Key Performance Indicator).
The optimizer takes as input (among others) a list of forbiden allocations
that should be generated based on some user-provided rules.
Each forbid rule is an "AND" composition of two rules:
One for the activity
One for the resource
Each sub rule is itself a list of "AND" tests on some attributes.
Here is the structure of one rule, in Pseudo-Code
Rule1:
* ActivityRule
* activity.prop1 == "foo" AND
* activity.prop2 == "bar" AND
* ...
* ResourceRule
* resource.prop3 == "foobar" AND
* resource.prop4 == "NULL" AND
* ...
Rule2:
...
As soon as a pair of [Activity,Resource] matches one rule, it should be
sent as output, and not tested again against other rules.
Also, this is important to note that some rules will match very often,
while overs will match very rarely (very specific cases).
Performance constraints
Here are some rough hints about the volumetry of the problem :
* 1000 activities
* 200 resources
* 50 rules
I need the forbidden allocations to be generated in under a minute.
The challengeAs far, as I understand, Drools can surely generate those
forbidden allocations. the question is : "How smart is he" ?
If I had to write an engine myself for this particular problem, I would
make some improvements :
For example, I would not generate all possible allocations (200.000) and
then try to apply each rule on it (50 rules x 200.000).
Instead, I would try to match the resources and the activities separately
on each rule (each side of the rule), and then assemble the couples that
match at least one common rule.
Also, I would add some counter on each rule that would auto increment upon
each match, in order to apply first the rules that match often.
QuestionsIs the engine of Drools smart enought for that ? Or is he even
smarter ?
Do you have an example of Drools being used in a similar problem with
success ?
Do you have some hints on how to modelise this problem in Drools ?
Thanks in advance for your advice.
12 years
drools memory explosion for quite simple pattern
by michal.antolik
Hello All,
I have a temporal pattern and I'm wondering what's the best way to find
something like:
*stream of messages of type A and B
search for B and give me 5 immediate occurrences of A or B which happened
before B.*
example:
A,A,A,B,B,A,B,A,B,A,A,A,A,A,B,A
should give me:
A,A,A|B
A,A,A,B|B
A,A,B,B,A|B
B,B,A,B,A|B
A,A,A,A,A|B
So I made a pattern like:
$e1 : Event( type== A || type == B) from entry-point "Stream"
$e2 : Event( type== A || type == B, this after[1ms,1m] $e1) from
entry-point "Stream"
$e3 : Event( e type== A || type == B, this after[1ms,1m] $e2) from
entry-point "Stream"
$e4 : Event( type== A || type == B, this after[1ms,1m] $e3) from
entry-point "Stream"
$e5 : Event( type== A || type == B, this after[1ms,1m] $e4) from
entry-point "Stream"
$e : Event( type== B, this after[1ms,1m] $e5 ) from entry-point "Stream"
not( Event( type== A || type == B, this after $e1, this before $e2) from
entry-point "Stream" )
not( Event( type== A || type == B, this after $e2, this before $e3) from
entry-point "Stream" )
not( Event( type== A || type == B, this after $e3, this before $e4)
from entry-point "Stream" )
not( Event( type== A || type == B, this after $e4, this before $e5)
from entry-point "Stream" )
not( Event( type== A || type == B, this after $e5, this before $e)
from entry-point "Stream" )
I also put the time constraint for more constraint search, but the search is
quite slow plus the memory is exploding very fast - several GB in few
seconds.
I also tried to accumulate last 5 events using a floating window, which
helped a lot with performance, but if I would be interested to have only A
preceding B, then it wouldn't help.
Can you pls help me understand what is the best practice to define a drool
pattern for the one I described above?
Thanks a lot!
Michal
--
View this message in context: http://drools.46999.n3.nabble.com/drools-memory-explosion-for-quite-simpl...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years
Rule Match deduplication
by michal.antolik
Hello,
I have a temporal pattern like
*A after B*
and a stream as
*A1,B1,B2,B3,B4,B5,A2,B6*
and if I define a pattern simply as
$a: Event()
$b: Event(this after $a)
I'll get matches like (A1,B1),(A1,B2),(A1,B3),(A1,B4),...
However I care about first match only and then I want to reset the pattern
so the next one would be (A2,B6).
Can you please advice how to achieve that? I don't want to do the
deduplication by myself and most importantly I could achieve much better
performance if I could expire partial matches (I cannot expire event since
it might be used by other patterns)
Thanks a lot for help.
--
View this message in context: http://drools.46999.n3.nabble.com/Rule-Match-deduplication-tp4020717.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years
How to implement the MoveIteratorFactory interface for ?
by 软件0907黄泓
Hi,
I have to implement this interface to meet requirement on performance and to use Random and JUST_IN_TIME configuration in xml. However, all examples provided implement MoveListFactory instead of this interface,and I don't quite understand how to implement the MoveIteratorFactory interface. The reference mannual told me not to create a collection of moves when creating the Iterator<Move>. I don't understand what this means,and how to use the arguments ScoreDirector and Random for each method. How can you get an iterator of moves if you do not make a collection of moves?And I don't quite understand what the reference mannual means by saying "this interface gives you the ability to create a move just in time in the iterator's method next()".Does this mean I only have to provide a collection with only one move that was randomly chosen?Could you provide me an example on how to implement this interface on the curriculumcourse example?
with kind regards
12 years