drools planner - 2012-10-23 intellifest 2012
TRANSCRIPT
drools
Geoffrey De Smet
Business resource optimization
with
Drools Planner
DemoTravelling Salesman ProblemVehicle Routing
Every organization has planning problems.
What is a planning problem?
Complete goals
With limited resources
Under constraints
Hospital employee rostering
Assign eachShift
ToEmployee
ConstraintsEmployment contract
Free time preferences
Skills
http://www.flickr.com/photos/glenpooh/709704564/
DemoEmployee rostering
Other planning problems
http://www.flickr.com/photos/phelyan/2281095105/
http://www.flickr.com/photos/markhillary/2227726759/
Hospital bed planning
Course scheduling
Many more: port planning, airline routing, train
composition,
task assignment, assembly line planning,
satellite bandwidth planning, stock cutting, ...
Bin packing in the cloud
Assign eachProcess
ToServer
ConstraintsHardware requirements
Minimize server cost
http://www.flickr.com/photos/torkildr/3462607995/
Bin packing in the cloud
Assign eachProcess
ToServer
ConstraintsHardware requirements
Minimize server cost
http://www.flickr.com/photos/torkildr/3462607995/
Which processes do we assign to this server?
How did we find that solution?
First fit by decreasing size
First fit by decreasing size
First fit by decreasing size
First fit by decreasing size
Another case
Try FFD again
Try FFD again
Try FFD again
Try FFD again
FFD failure
NP complete
NP complete
No silver bullet knownHoly grail of computer scienceP == NP
Probably does not existP != NP
Root problem of
all planning problems
http://www.flickr.com/photos/annguyenphotography/3267723713/
Multiple servers...
Multiple servers...
Multiple servers...
Multiple servers...
Multiple constraints...
Multiple constraints...
Multiple constraints...
Multiple constraints...
Organizations rarely optimize
planning problems.
Given 2 solutions, which one is better?
Each Solution has 1 Score
Each Solution has 1 Score
Better score => better solution
Better score => better solution
Best score => best solution
Best score => best solution
Reuse optimization algorithms?
Open source (ASL 2.0)
Regular releases
Reference manual
Examples
DemoCloudBalance example
Domain model
Server
Server
public class Server {
private int cpuPower; private int memory; private int networkBandwidth;
private int cost;
// getters}
Process
Process
Process is a planning entity
@PlanningEntitypublic class Process {
private int requiredCpuPower; private int requiredMemory; private int requiredNetworkBandwidth; private Server server;
@PlanningVariable @ValueRange(... = "serverList") public Server getServer() {...}
// getters, setters, clone, equals, hashcode}
CloudBalance
Solution class CloudBalance
public class CloudBalance implements Solution {
private List serverList; private List processList; private HardAndSoftScore score;
@PlanningEntityCollectionProperty public List getProcessList() {...}
// getters, setters, clone, getProblemFacts()
}
Score constraints
Score calculation
Simple Java
Incremental Java
Drools
Simple Java score calculation
Easy to implement
Bridge to an existing scoring system
Slow
public class ... implements SimpleScoreCalculator {
public Score calculateScore(CloudBalance cb) { ... }
}
Incremental Java
score calculation
FastSolution changes => only score delta is recalculated
Hard to implementMuch boilerplate code
Drools score calculation
Also incremental => fastbut no boilerplate code
Integration opportunitiesGuvnor repository
DSL: natural language constraints
Decision tables
DRL soft constraint:
server cost
rule "serverCost" when // there is a server $s : Server($c : cost) // there is a processes on that server exists Process(server == $s) then // lower soft score by $cend
DRL hard constraint:
CPU power
rule "requiredCpuPowerTotal" when // there is a server $s : Server($cpu : cpuPower) // with too little CPU for its processes $total : Number(intValue > $cpu) from accumulate( Process(server == $s, $requiredCpu : requiredCpuPower), sum($requiredCpu) ) then // lower hard score by ($total - $cpu)end
Solving it
Solver configuration by XML
...CloudBalance ...Process
HARD_AND_SOFT ...ScoreRules.drl
Solving
XmlSolverFactory factory = new XmlSolverFactory( "...SolverConfig.xml");Solver solver = factory.buildSolver();
solver.setPlanningProblem(cloudBalance);solver.solve();cloudBalance = (CloudBalance) solver.getBestSolution();
Optimization algorithms
Brute Force
Brute Force config
...
Brute force scalability
12 processes = 17 minutes
6 processes = 15 ms
9 processes = 1.5 seconds
* 100
* 680
Plan 1200 processes
with brute force?
First Fit
First Fit config
...
FIRST_FIT
First Fit Decreasing
First Fit Decreasing config
...
FIRST_FIT_DECREASING
@PlanningEntity(difficultyComparatorClass = ProcessDifficultyComparator.class)public class Process { ...}
First Fit scalability
Local Search comes after
Construction Heuristics
Local Search comes after
Construction Heuristics
...
FIRST_FIT_DECREASING ...
Local Search
Local Search Algorithms
(Hill climbing)
Tabu Search
Simulated Annealing
Late Acceptance
Details explained Friday 4:15 PM
Local Search results
Cost ($) reduction
Compared to First FitFirst Fit Decreasing49 480 $ = 4 %
Tabu Search160 860 $ = 14 %
Simulated annealing128 950 $ = 11 %
Few constraints=> low ROI
Benchmarker toolkit
Organizations rarely optimize
planning problems.
http://www.flickr.com/photos/techbirmingham/345897594/
Organizations waste resources.
Summary
Summary
Drools Planner optimizes business resources
Adding constraints is easy and scalable
Switching/combining algorithms is easy
Try an example!
Q&A
Drools 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
Twitter: @geoffreydesmet
Google+: Geoffrey De Smet
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