Business resource optimization             with       Drools Planner         Geoffrey De Smet
DemoTravelling Salesman Problem       Vehicle Routing                              2
Every organization has planning problems.                                            3
What is a planning problem?             Complete goals             With limited resources             Under constraints...
Hospital employee rostering                                                      Assign each                             ...
DemoEmployee rostering                     6
Other planning problemsCourse scheduling                                     Hospital bed planning                        ...
Bin packing in the cloud                                                       Assign each                               ...
Bin packing in the cloud                                                       Assign each                               ...
Which processes do we assignto this server?                               10
How did we find that solution?                                 11
First fit by decreasing size                               12
First fit by decreasing size                               13
First fit by decreasing size                               14
First fit by decreasing size                               15
Another case               16
Try FFD again                17
Try FFD again                18
Try FFD again                19
Try FFD again                20
FFD failure              21
NP complete              22
NP complete                                                                  No silver bullet known                      ...
Multiple servers...                      24
Multiple servers...                      25
Multiple servers...                      26
Multiple servers...                      27
Multiple constraints...                          28
Multiple constraints...                          29
Multiple constraints...                          30
Multiple constraints...                          31
Organizations rarely optimize    planning problems.                                32
Given 2 solutions, which one is better?                                          33
Each Solution has 1 Score                            34
Each Solution has 1 Score                            35
Better score => better solution                                  36
Better score => better solution                                  37
Best score => best solution                              38
Best score => best solution                              39
Reuse optimization algorithms?                                 40
   Open source (ASL 2.0)   Regular releases   Reference manual   Examples                            41
DemoCloudBalance example                       42
Domain model
Server         44
Serverpublic class Server {    private int cpuPower;    private int memory;    private int networkBandwidth;    private in...
Process          46
Process          47
Process is a planning entity@PlanningEntitypublic class Process {    private int requiredCpuPower;    private int required...
CloudBalance               49
Solution class CloudBalancepublic class CloudBalance      implements Solution<HardAndSoftScore> {    private List<Server> ...
Score constraints
Score calculation   Simple Java   Incremental Java   Drools                                 52
Simple Java score calculation   Easy to implement   Bridge to an existing scoring system   Slowpublic class ...        ...
Incremental Java                score calculation   Fast    ●   Solution changes => only score delta is recalculated   H...
Drools score calculation   Also incremental => fast    ●   but no boilerplate code   Integration opportunities    ●   Gu...
DRL soft constraint:              server costrule "serverCost"  when      // there is a server      $s : Server($c : cost)...
DRL hard constraint:                CPU powerrule "requiredCpuPowerTotal"  when      // there is a server      $s : Server...
Solving it
Solver configuration by XML<solver>  <solutionClass>...CloudBalance</solutionClass>  <planningEntityClass>...Process</>  <...
SolvingXmlSolverFactory factory = new XmlSolverFactory(    "...SolverConfig.xml");Solver solver = factory.buildSolver();so...
Optimization algorithms
Brute Force              62
Brute Force config<solver>  ...  <bruteForce /></solver>                                 63
Brute force scalability                         12 processes = 17 minutes                                       * 680     ...
Plan 1200 processeswith brute force?                      65
First Fit            66
First Fit config<solver>  ...  <constructionHeuristic>    <constructionHeuristicType>FIRST_FIT</>  </constructionHeuristic...
First Fit Decreasing                       68
First Fit Decreasing config<solver>    ...    <constructionHeuristic>      <constructionHeuristicType>FIRST_FIT_DECREASING...
First Fit scalability                        70
Local Search comes afterConstruction Heuristics                           71
Local Search comes after            Construction Heuristics<solver>  ...  <constructionHeuristic>    <constructionHeuristi...
Local Search               73
Local Search Algorithms   (Hill climbing)   Tabu Search   Simulated Annealing   Late Acceptance    Details explained F...
Local Search results                       75
Cost ($) reduction              Compared to First Fit               ●   First Fit Decreasing                    ●   49 48...
Benchmarker toolkit                      77
Organizations rarely optimize    planning problems.                                78
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 a...
Try an example!                  82
Q&A   Drools Planner homepage:    ●  http://www.jboss.org/drools/drools-planner   Reference manual:     ● http://www.jbo...
Upcoming SlideShare
Loading in …5
×

Drools planner - 2012-10-23 IntelliFest 2012

1,276 views
1,130 views

Published on

Business resource optimization with Drools Planner

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,276
On SlideShare
0
From Embeds
0
Number of Embeds
35
Actions
Shares
0
Downloads
28
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Drools planner - 2012-10-23 IntelliFest 2012

  1. 1. Business resource optimization with Drools Planner Geoffrey De Smet
  2. 2. DemoTravelling Salesman Problem Vehicle Routing 2
  3. 3. Every organization has planning problems. 3
  4. 4. What is a planning problem?  Complete goals  With limited resources  Under constraints 4
  5. 5. Hospital employee rostering  Assign each ● Shift  To ● Employee  Constraints ● Employment contracthttp://www.flickr.com/photos/glenpooh/709704564/ ● Free time preferences ● Skills 5
  6. 6. DemoEmployee rostering 6
  7. 7. Other planning problemsCourse scheduling Hospital bed planning http://www.flickr.com/photos/markhillary/2227726759/ http://www.flickr.com/photos/phelyan/2281095105/ Many more: port planning, airline routing, train composition, task assignment, assembly line planning, satellite bandwidth planning, stock cutting, ... 7
  8. 8. Bin packing in the cloud  Assign each ● Process  To ● Server  Constraints ● Hardware requirements ● Minimize server costhttp://www.flickr.com/photos/torkildr/3462607995/ 8
  9. 9. Bin packing in the cloud  Assign each ● Process  To ● Server  Constraints ● Hardware requirements ● Minimize server costhttp://www.flickr.com/photos/torkildr/3462607995/ 9
  10. 10. Which processes do we assignto this server? 10
  11. 11. How did we find that solution? 11
  12. 12. First fit by decreasing size 12
  13. 13. First fit by decreasing size 13
  14. 14. First fit by decreasing size 14
  15. 15. First fit by decreasing size 15
  16. 16. Another case 16
  17. 17. Try FFD again 17
  18. 18. Try FFD again 18
  19. 19. Try FFD again 19
  20. 20. Try FFD again 20
  21. 21. FFD failure 21
  22. 22. NP complete 22
  23. 23. NP complete  No silver bullet known ● Holy grail of computer science ● P == NP ● Probably does not exist ● P != NP  Root problem of all planning problemshttp://www.flickr.com/photos/annguyenphotography/3267723713/ 23
  24. 24. Multiple servers... 24
  25. 25. Multiple servers... 25
  26. 26. Multiple servers... 26
  27. 27. Multiple servers... 27
  28. 28. Multiple constraints... 28
  29. 29. Multiple constraints... 29
  30. 30. Multiple constraints... 30
  31. 31. Multiple constraints... 31
  32. 32. Organizations rarely optimize planning problems. 32
  33. 33. Given 2 solutions, which one is better? 33
  34. 34. Each Solution has 1 Score 34
  35. 35. Each Solution has 1 Score 35
  36. 36. Better score => better solution 36
  37. 37. Better score => better solution 37
  38. 38. Best score => best solution 38
  39. 39. Best score => best solution 39
  40. 40. Reuse optimization algorithms? 40
  41. 41.  Open source (ASL 2.0) Regular releases Reference manual Examples 41
  42. 42. DemoCloudBalance example 42
  43. 43. Domain model
  44. 44. Server 44
  45. 45. Serverpublic class Server { private int cpuPower; private int memory; private int networkBandwidth; private int cost; // getters} 45
  46. 46. Process 46
  47. 47. Process 47
  48. 48. 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} 48
  49. 49. CloudBalance 49
  50. 50. Solution class CloudBalancepublic class CloudBalance implements Solution<HardAndSoftScore> { private List<Server> serverList; private List<Process> processList; private HardAndSoftScore score; @PlanningEntityCollectionProperty public List<Process> getProcessList() {...} // getters, setters, clone, getProblemFacts()} 50
  51. 51. Score constraints
  52. 52. Score calculation Simple Java Incremental Java Drools 52
  53. 53. Simple Java score calculation Easy to implement Bridge to an existing scoring system Slowpublic class ... implements SimpleScoreCalculator<CloudBalance> { public Score calculateScore(CloudBalance cb) { ... }} 53
  54. 54. Incremental Java score calculation Fast ● Solution changes => only score delta is recalculated Hard to implement ● Much boilerplate code 54
  55. 55. Drools score calculation Also incremental => fast ● but no boilerplate code Integration opportunities ● Guvnor repository ● DSL: natural language constraints ● Decision tables 55
  56. 56. DRL soft constraint: server costrule "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 56
  57. 57. DRL hard constraint: CPU powerrule "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 57
  58. 58. Solving it
  59. 59. Solver configuration by XML<solver> <solutionClass>...CloudBalance</solutionClass> <planningEntityClass>...Process</> <scoreDirectorFactory> <scoreDefinitionType>HARD_AND_SOFT</> <scoreDrl>...ScoreRules.drl</scoreDrl> </scoreDirectorFactory> <!-- optimization algorithms --></solver> 59
  60. 60. SolvingXmlSolverFactory factory = new XmlSolverFactory( "...SolverConfig.xml");Solver solver = factory.buildSolver();solver.setPlanningProblem(cloudBalance);solver.solve();cloudBalance = (CloudBalance) solver.getBestSolution(); 60
  61. 61. Optimization algorithms
  62. 62. Brute Force 62
  63. 63. Brute Force config<solver> ... <bruteForce /></solver> 63
  64. 64. Brute force scalability 12 processes = 17 minutes * 680 9 processes = 1.5 seconds 6 processes = 15 ms * 100 64
  65. 65. Plan 1200 processeswith brute force? 65
  66. 66. First Fit 66
  67. 67. First Fit config<solver> ... <constructionHeuristic> <constructionHeuristicType>FIRST_FIT</> </constructionHeuristic></solver> 67
  68. 68. First Fit Decreasing 68
  69. 69. First Fit Decreasing config<solver> ... <constructionHeuristic> <constructionHeuristicType>FIRST_FIT_DECREASING</> </constructionHeuristic></solver>@PlanningEntity(difficultyComparatorClass = ProcessDifficultyComparator.class)public class Process { ...} 69
  70. 70. First Fit scalability 70
  71. 71. Local Search comes afterConstruction Heuristics 71
  72. 72. Local Search comes after Construction Heuristics<solver> ... <constructionHeuristic> <constructionHeuristicType>FIRST_FIT_DECREASING</> </constructionHeuristic> <localSearch> ... <localSearch></solver> 72
  73. 73. Local Search 73
  74. 74. Local Search Algorithms (Hill climbing) Tabu Search Simulated Annealing Late Acceptance Details explained Friday 4:15 PM 74
  75. 75. Local Search results 75
  76. 76. Cost ($) reduction  Compared to First Fit ● First Fit Decreasing ● 49 480 $ = 4 % ● Tabu Search ● 160 860 $ = 14 % ● Simulated annealing ● 128 950 $ = 11 %  Few constraints ● => low ROI 76
  77. 77. Benchmarker toolkit 77
  78. 78. Organizations rarely optimize planning problems. 78
  79. 79. http://www.flickr.com/photos/techbirmingham/345897594/Organizations waste resources. 79
  80. 80. Summary
  81. 81. Summary Drools Planner optimizes business resources Adding constraints is easy and scalable Switching/combining algorithms is easy 81
  82. 82. Try an example! 82
  83. 83. 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 83

×