drools planner webinar (2011-06-15): drools planner optimizes automated planning
TRANSCRIPT
drools
Geoffrey De Smet
Drools Planner optimizes automated planning
Agenda
Drools and jBPM Platform overview
Use casesBin packingWhat is NP complete?
Employee shift rosteringHard and soft constraints
Patient admission scheduleHow many possible solutions?
Algorithms
Results
Future
Drools and jBPM Platform
Overview
Business Logic Integration
BusinessLogicIntegrationPlatform
Rule
engine
Workflow
Complex event
processing
(CEP)
Business Rule
Management System(BRMS)
Automated
planning
Use cases
What are planning problems?
Hard constraint implementation
// a nurse can only work one shift per dayrule "oneShiftPerDay" when $left : EmployeeAssignment( $employee : employee, $shiftDate : shiftDate, $leftId : id ) $right : EmployeeAssignment( employee == $employee, shiftDate == $shiftDate, id > $leftId ) then // Lower the hard score with a weight ...end
Soft constraint implementation
rule "dayOffRequest" when $dayOffRequest : DayOffRequest( $employee : employee, $shiftDate : shiftDate, $weight : weight ) $employeeAssignment : EmployeeAssignment( employee == $employee, shiftDate == $shiftDate ) then // Lower the soft score with the weight $weight ...end
Object orientated
Readable
by domain experts
Fast and scalable:
Indexes, ReteOO, ...
Java methods usable
Isolated
Hospital bed planning
Hospital bed planning constraints
Hard constraintsNo 2 patients in same bed in same nightRoom gender limitationDepartment minimum or maximum agePatient requires specific room equipment(s)Soft constraintsPatient prefers maximum room sizeDepartment specializationRoom specializationPatient prefers specific room equipment(s)
Needle in a haystack
How many possible solutions?310 bedsin 105 roomsin 4 departments84 nights2750 patients (admissions)Numbers from a real dataset
Needle in a haystack
How many possible solutions?310 bedsin 105 roomsin 4 departments84 nights2750 patients (admissions)> humans?7000000000 humans
Source: NASA (wikipedia)
Needle in a haystack
How many possible solutions?310 bedsin 105 roomsin 4 departments84 nights2750 patients (admissions)> minimum atoms in the observable universe?10^80
Source: NASA and ESA (wikipedia)
Needle in a haystack
How many possible solutions?310 bedsin 105 roomsin 4
departments84 nights2750 patients (admissions)> atoms in the
universe
if every atom is a universe
of atoms?(10^80)^80 = 10^6400
Source: NASA and ESA (wikipedia)
Needle in a haystack
How many possible solutions?310 bedsin 105 roomsin 4 departments84 nights2750 patients (admissions)A little over 10^6851
Do the math
1 patient310 beds310 ways to schedule 1 patient2 patients310 * 310 = 961003 patients310 * 310 * 310 = 297910002750 patients310 * 310 * ... * 310310^2750= a little over 10^6851
A little over 10^6851
17565400009613647714189309909847019528176031676612802408947467896773536824694320253771058944295328388965847321421820520338269384218763243353186553203291774156243401969717704429199723195574019731357439221586010900901318775661618988149185744289903563474940721372704649669447515706252843900344472960295273324597346780837674886972275338744554737771986776337765496773882810395955542351928331414378439283405132892358744224215499792287586474426914111457027335258269167103194692790665217766902628732489519488236496931246157419949856522543510386164584826962224171420152255658502323853504643497053252922727924406406179159327025274968691052425818270121710670552641837503435108794481961062422002729288737980404185875233912428178009558605680683578864680145557998942327371019832139824665975180911386722774004539981342785523851686636374432671601485496423110930175953308580416767966832068095365964656939583089443708945844323888227816296382464122209980716936990539499472027590738400791514217875461942733015467480308665074008529461146577114465977072581447925882122906827160570007228017056499674188148507908716786164922536467490587163626945689452927061532150637454615233641645612791027410608416476380642469085143980464067453971429400369608313929289399595696359958354101721624055729520838609453039985592726289376243856941429063767903919977138724432513602703448146045970566585076809576476984036923221553270878279574239866657156729051295085970100212856025787345034666683590797377984104207041334053480226788236770435009014979334517769826461063281178894554527012859966520606253098788699367180806367012372895824963357992764969799123361044456461687410981522493093316910464937089299655880447014074876397812210684054337706530175130912335567383560436635091489083375525519539844805718811296858076507685112192499405286337668107046095023999871224655107877174220679360212410573001491104381221662138764756898834588381340410892158544837200229008533930816794663631470201197595487045022087615873490295940409113638894083753062801416644858
A little over 10^6851
70757942487218045035508810158461046502812782292385633846174494690914238485407798379765738528402484632449685642401410897637632172694954465509230907381501728706686840208173164426348468614134650930610728341876292346711310677332648553951422991989751468506508069513397904821612697383659788320905691994864296149528670873271380180066507702490525594196383327289726362280241278856579591895744202499646581373849829964867870738964842426372580420928473929652466453066089306581572745139056256181505240205578741292314133858985615181677968313683876880079649763914095651402272047776108451445066888366968448972791816669030945790810396895725248399188822034667566483522327685006195080178525107491255245054238976705620547582329759857450557583834141364747838395082871684183199560673441708538602779816347949276957201268066627372831370768073558934679410276824283049183299518869516908654179971718550810202675628457097617280232889096038128616543128200089047813223519902714196694639844273986565523012106816309974964021700560537928432528631741787455155275823033005847637107210747721372066369346754152090839849611389908167353907349234368276522287410730637555342957452428266968002573227849933691449063418286501311036314048960528249465982665132492491072491788618403253474529440348798670244615185355092357283764936387607076234181916670755269421546530337284689838773122323053171794271444358533638806848969871884168582847613016398013006633016140503743175611255484273419291435502775849577615159921009571496639402549077872124227731739936370100132762333353473908080215719004335487157010620020523763648856692728699459471603410776592535816520745995861336577877431293776796124264697049418795186010546056975226424227455446011031581123438684685838655333776830823720356749120051129394691394743488410658613543537795455760655157849602214428915084056181314465895075924498263846040474495622654552157933867572542745838370889391243702358459244386561081479905545570084491443709439642235090455604548030317754849613813010298858282615659336373785985294
A little over 10^6851
58667337266411706925088329158776619790296442059252886388879455197093987039774900087293989610103172000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
A little over 10^6851
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
The search space is big!Compare with WWW size 22020000000 pagesEach possible solution2750 patients scheduled into 310 bedsStill need to calculate the score! => Drools Expert
Brute force?
Throw hardware at it?
Calculate 10^9 scores per msImpossible today!Actually more like 1-10 scores per ms per CPU
31579200000 ms in 1 year< 10^11 ms in 1 year
10^9 * 10^11 scores per year= 10^20 scores per year
How many years? 10^6851 / 10^20= 10^6831 years
CPU 1000 times fasterIt becomes 10^6828 years
Algorithms
Operations research is fun.
N Queens: use case
Place n queens on a n-sized chess board
No 2 queens can attack each otherScore -1 for every 2 queens that can attack each other
Score = -2
Score = 0
Brute force algorithm
Useless with
a real world n
A huge performance gain
because of Drools Expert
Critical for ALL of your constraints!
No extra code thanks to Drools Expert
Branch and bound algorithm
Useless with
a real world n
Useful algorithms
Construction heuristicsFirst fit (decreasing), Best fit (decreasing), ...
Easy to implementDrools Planner score supportOut-of-the-box support for Drools Planner 5.3
Short and stable time (for example 8 seconds)
MetaheuristicsMove things aroundStart from result of construction heuristics
Tabu search, Simulated annealing, ...
More time = better score
Greedy algorithm
First fit
Greedy algorithm
First fit decreasing
Human planner are worse
than this algorithmand take more time. (*)
(*) with a real world n
Metaheuristics:
Move things around
Move = from solution A to solution BChange the row of 1
queen
Give 2 queens each others rows
...
Score = -6
Score = -4
Local search 1/2
Local search
2/2
Search pathNot a tree
Local optima
1) Construction heuristic StartingSolutionInitializer
2) Simple local search
3) Stuck in local optimum!
Source: Wikipedia
Score function
Local search++
Don't get stuck in local optima
Tabu SearchSolution tabu (high tabu size)Been there, no need to go there again
Move tabu (low tabu size)Done that recently, no need to do that again
Property tabu (low tabu size)Changed that recently,
no need to change that again
Simulated annealing
Great deluge, late acceptance,
Hyper heuristics
Termination
Synchronous (configurable)Max timeMillis/seconds/minutes/hours spend
Score attained
Max step count
Max unimproved step count
Asynchronous (from another thread)planner.terminateEarly();
Get the resultplanner.getBestSolution();
Results
Measure, don't guess.
Results: input
Competition use cases and datasetsReal world data
Real world constraints
Not only the datasets that perform well (no cheating)
Greedy: First Fit Decreasing (FFD)Performs better than humansEspecially when the dataset or constraints scale out
Metaheuristics: Tabu search or SAStarting from Greedy First Fit Decreasing
10 minutes total time (greedy included)Normal PC: Xeon 3.07 Ghz (using 1 of 4 CPU's)
Results: Greedy vs Metaheuristics
Hospital bed planning (PAS)Dataset testdata01-13
Tabu search is on average 26% better than FFDFrom 9% to 53% better
=> Better healthcare, more single rooms sold, ...
Nurse rostering (INRC2010)Dataset medium01-05, medium_hint01-03
SA is on average 164% better than FFDFrom 24% to 543% better
=> Better healthcare, less overtime, happier nurses, ...
Tabu search is slightly worse than SA
Results: Greedy vs Metaheuristics
Examination (ITC2007 track 3)Dataset exam_comp_set1-5,8Broken hard constraints make fair calculations difficultExcluded exam_comp_set6: infinity% better-51hard/-5338soft to 0hard/-5037soft
Excluded exam_comp_set7: 0% better-6hard/-9802soft to -6hard/-9116soft
Not even counting soft where there's hard improvement
Tabu search is on average 85% better than FFDFrom 1% to 195%
=> Happier students
Don't believe me?Download the examples!
Benchmarker class
Real output from
the Benchmarker class
CPU power VS algorithms
more CPU power
better
algorithm
Real output from
the Benchmarker class
Future
Simpler, faster and more powerful
Repeated planning
Better Guvnor integration
Planning domain experts create the score rulesNurse rostering: head nurse
Truck routing: logistics expert
Job shop scheduling: supply chain expert
Using Guvnor's web interface
Summary
Summary
Drools Planner solves planning problems
Adding constraints is easy and scalable
Switching/combining algorithms is easy
Try an example!
Q & A
Questions?
Useful linksDrools Planner homepage:http://www.jboss.org/drools/drools-planner
Reference manual:http://www.jboss.org/drools/documentation
Download this presentation:http://www.jboss.org/drools/presentations
Mailing list (use forum) for further questions: http://www.jboss.org/drools/lists.html
Team blog: http://blog.athico.com/
Twitter: @geoffreydesmet
This is the title
Second line of the title
Click to edit the outline text formatSecond Outline LevelThird Outline LevelFourth Outline LevelFifth Outline LevelSixth Outline LevelSeventh Outline LevelEighth Outline LevelNinth Outline Level
This is the chapter title
This is the subtitle