Advertisement
Advertisement

More Related Content

Advertisement
Advertisement

2012 02-04 fosdem 2012 - drools planner

  1. Geoffrey De Smet Drools Planner: Planning optimization by example
  2. Demo Drools Planner TSP example
  3. Every organization has planning problems.
  4. With limited resources
  5. Under constraints
  6. Room requirements
  7. Room preferences http://www.flickr.com/photos/markhillary/2227726759/
  8. Free time preferences
  9. Skills http://www.flickr.com/photos/glenpooh/709704564/
  10. Per teacher
  11. Per student http://www.flickr.com/photos/phelyan/2281095105/
  12. Minimize mileage http://www.flickr.com/photos/yorickr/3674349657/
  13. Minimize server cost http://www.flickr.com/photos/torkildr/3462607995/
  14. Minimize server cost http://www.flickr.com/photos/torkildr/3462607995/
  15. Which processes do we assign to this server?
  16. How did we find that solution?
  17. First fit by decreasing size
  18. First fit by decreasing size
  19. First fit by decreasing size
  20. First fit by decreasing size
  21. Another case
  22. Try FFD again
  23. Try FFD again
  24. Try FFD again
  25. Try FFD again
  26. FFD failure
  27. NP complete
  28. Multiple servers...
  29. Multiple servers...
  30. Multiple servers...
  31. Multiple servers...
  32. Multiple constraints...
  33. Multiple constraints...
  34. Multiple constraints...
  35. Multiple constraints...
  36. Organizations rarely optimize planning problems.
  37. Reuse optimization algorithms?
  38. Regular releases
  39. Reference manual
  40. Examples
  41. Given 2 solutions, which one is better?
  42. Each Solution has 1 Score
  43. Each Solution has 1 Score
  44. Better score => better solution
  45. Better score => better solution
  46. Best score => best solution
  47. Best score => best solution
  48. Demo Drools Planner CloudBalance example
  49. Domain model
  50. Server
  51. Server public class Server { private int cpuPower ; private int memory ; private int networkBandwidth ; private int cost ; // getters }
  52. Process
  53. Process
  54. Process is a planning entity @PlanningEntity public class Process { private int requiredCpuPower ; private int requiredMemory ; private int requiredNetworkBandwidth ; ... // getters, clone, equals, hashcode }
  55. Process has a planning variable @PlanningEntity public class Process { ... private Server server ; @PlanningVariable @ValueRange(type = FROM_SOLUTION_PROPERTY, solutionProperty = "serverList" ) public Server getServer() { return server ; } public void setServer(Server server) { ... } ... }
  56. CloudBalance
  57. Solution CloudBalance: problem facts public class CloudBalance implements Solution<HardAndSoftScore> { private List<Server> serverList ; public List<Server> getServerList() { return serverList ; } ... }
  58. Solution CloudBalance: planning entities public class CloudBalance implements Solution<HardAndSoftScore> { ... private List<Process> processList ; @PlanningEntityCollectionProperty public List<Process> getProcessList() { return processList ; } ... }
  59. Solution CloudBalance: getProblemFacts public class CloudBalance implements Solution<HardAndSoftScore> { ... // Used in score constraints public Collection<Object> getProblemFacts() { List<Object> facts = new ArrayList<Object>(); facts.addAll( serverList ); return facts; } ... }
  60. Solution CloudBalance: score public class CloudBalance implements Solution<HardAndSoftScore> { ... private HardAndSoftScore score ; public HardAndSoftScore getScore() { ... } public void setScore(HardAndSoftScore score) { ... } ... }
  61. Score constraints
  62. Soft constraint: server cost rule &quot;serverCost&quot; 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 $c insertLogical( new IntConstraintOccurrence( &quot;serverCost&quot; , ConstraintType. NEGATIVE_SOFT , $c , $s )); end
  63. Hard constraint: CPU power rule &quot;requiredCpuPowerTotal&quot; 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.intValue() - $cpu) end
  64. Solving it
  65. Solver configuration by XML < solver > < solutionClass > ... CloudBalance</ solutionClass > < planningEntityClass > ... Process</> < scoreDrl > ... ScoreRules.drl</ scoreDrl > < scoreDefinition > < scoreDefinitionType >HARD_AND_SOFT</> </ scoreDefinition > <!-- optimization algorithms --> </ solver >
  66. Solving XmlSolverFactory factory = new XmlSolverFactory( &quot; ... SolverConfig.xml&quot; ); Solver solver = factory .buildSolver(); solver.setPlanningProblem( cloudBalance ); solver.solve(); cloudBalance = ( CloudBalance) solver.getBestSolution();
  67. Optimization algorithms
  68. Brute Force
  69. Brute Force config < solver > ... < bruteForce /> </ solver >
  70. Brute force scalability 6 processes = 15 ms 9 processes = 1.5 seconds * 100
  71. Brute force scalability 12 processes = 17 minutes 6 processes = 15 ms 9 processes = 1.5 seconds * 100 * 680
  72. Plan 1200 processes with brute force?
  73. First Fit
  74. First Fit config < solver > ... < constructionHeuristic > < constructionHeuristicType >FIRST_FIT</> </ constructionHeuristic > </ solver >
  75. First Fit scalability
  76. First Fit results CPU: OK RAM: OK Network: OK Cost active servers: shown
  77. First Fit Decreasing
  78. First Fit Decreasing config < solver > ... < constructionHeuristic > < constructionHeuristicType >FIRST_FIT_DECREASING</> </ constructionHeuristic > </ solver >
  79. DifficultyComparator public class ProcessDifficultyComparator implements Comparator<Process> { public int compare(Process a, Process b) { // Compare on requiredCpuPower * requiredMemory // * requiredNetworkBandwidth } } @PlanningEntity (difficultyComparatorClass = ProcessDifficultyComparator. class ) public class Process { ... }
  80. First Fit Decreasing scalability
  81. First Fit Decreasing results
  82. Local Search
  83. Local Search comes after Construction Heuristics < solver > ... < constructionHeuristic > < constructionHeuristicType >FIRST_FIT_DECREASING</> </ constructionHeuristic > < localSearch > ... < localSearch > </ solver >
  84. Local Search needs to be terminated < solver > ... < termination > < maximumMinutesSpend >20</ maximumMinutesSpend > </ termination > ... </ solver >
  85. Selecting moves < localSearch > < selector > < selector > < moveFactoryClass >GenericChangeMoveFactory</> </ selector > < selector > < moveFactoryClass >GenericSwapMoveFactory</> </ selector > </ selector > ... tabu search, simulated annealing or ... </ localSearch >
  86. Hill climbing < localSearch > < selector > ... </ selector > < forager > <!-- Untweaked standard value --> < minimalAcceptedSelection >1000</> </ forager > </ localSearch >
  87. Tabu Search < localSearch > < selector > ... </ selector > < acceptor > <!-- Untweaked standard value --> < propertyTabuSize >7</ propertyTabuSize > </ acceptor > < forager > <!-- Untweaked standard value --> < minimalAcceptedSelection >1000</> </ forager > </ localSearch >
  88. Simulated Annealing < localSearch > < selector > ... </ selector > < acceptor > <!-- Tweaked value --> < simulatedAnnealingStartingTemperature > 0hard/400soft</> </ acceptor > < forager > <!-- Untweaked standard value --> < minimalAcceptedSelection >4</> </ forager > </ localSearch >
  89. Local Search results
  90. Organizations rarely optimize planning problems.
  91. http://www.flickr.com/photos/techbirmingham/345897594/ Organizations waste resources.
  92. Real-time planning
  93. Time allowed: 100ms after last change
  94. Demo Real-time planning CloudBalance example
  95. Demo Real-time planning TSP example
  96. Summary
  97. Adding constraints is easy and scalable
  98. Switching/combining algorithms is easy
  99. Try an example!
  100. Google+: Geoffrey De Smet
Advertisement