SlideShare une entreprise Scribd logo
1  sur  99
Drools Planner:
Planning optimization
     by example

    Geoffrey De Smet
Demo
Drools Planner
TSP example




                 2
Every organization has planning problems.




                                            3
What is a planning problem?

             Complete goals
             With limited resources
             Under constraints




                                       4
Hospital bed scheduling

                                                          Assign each
                                                                ●   Patient
                                                          To
                                                                ●   Bed
                                                          Constraints
http://www.flickr.com/photos/markhillary/2227726759/
                                                                ●   Length of stay
                                                                ●   Room requirements
                                                                ●   Room preferences



                                                                                        5
Hospital nurse rostering

                                                      Assign each
                                                            ●   Shift
                                                      To
                                                            ●   Nurse
                                                      Constraints
http://www.flickr.com/photos/glenpooh/709704564/
                                                            ●   Employment
                                                                  contract
                                                            ●   Free time
                                                                  preferences
                                                            ●   Skills

                                                                                6
School timetabling

                                                      Assign each
                                                            ●   Course
                                                      To
                                                            ●   Room
                                                            ●   Timeslot

http://www.flickr.com/photos/phelyan/2281095105/
                                                      Constraints
                                                            ●   No simultaneous
                                                                 courses
                                                                   ● Per room
                                                                   ● Per teacher

                                                                   ● Per student
                                                                                   7
Airline routing

                                                      Assign each
                                                            ●   Flight
                                                      To
                                                            ●   Airplane
                                                            ●   Crew

http://www.flickr.com/photos/yorickr/3674349657/
                                                      Constraints
                                                            ●   Airplane/crew
                                                                 depart from where
                                                                 they arrive
                                                            ●   Minimize mileage

                                                                                 8
Bin packing in the cloud

                                                       Assign each
                                                             ●   Process
                                                       To
                                                             ●   Server
                                                       Constraints
                                                             ●   Hardware
http://www.flickr.com/photos/torkildr/3462607995/
                                                                  requirements
                                                             ●   Minimize server cost



                                                                                    9
Bin packing in the cloud

                                                       Assign each
                                                             ●   Process
                                                       To
                                                             ●   Server
                                                       Constraints
                                                             ●   Hardware
http://www.flickr.com/photos/torkildr/3462607995/
                                                                  requirements
                                                             ●   Minimize server cost



                                                                                    10
Which processes do we assign
to this server?




                           11
How did we find that solution?




                             12
First fit by decreasing size




                               13
First fit by decreasing size




                               14
First fit by decreasing size




                               15
First fit by decreasing size




                               16
Another case




               17
Try FFD again




                18
Try FFD again




                19
Try FFD again




                20
Try FFD again




                21
FFD failure




              22
NP complete




              23
NP complete

                                                                  No silver bullet known
                                                                      ●   Holy grail of
                                                                           computer science
                                                                              ●   P == NP
                                                                      ●   Probably does not
                                                                            exist
                                                                              ●   P != NP
                                                                  Root problem of
http://www.flickr.com/photos/annguyenphotography/3267723713/
                                                                    all planning
                                                                    problems

                                                                                              24
Multiple servers...




                      25
Multiple servers...




                      26
Multiple servers...




                      27
Multiple servers...




                      28
Multiple constraints...




                          29
Multiple constraints...




                          30
Multiple constraints...




                          31
Multiple constraints...




                          32
Organizations rarely optimize
    planning problems.




                                33
Reuse optimization algorithms?




                                 34
   Open source (ASL 2.0)
   Regular releases
   Reference manual
   Examples



                            35
Given 2 solutions, which one is better?




                                          36
Each Solution has 1 Score




                            37
Each Solution has 1 Score




                            38
Better score => better solution




                              39
Better score => better solution




                              40
Best score => best solution




                              41
Best score => best solution




                              42
Demo
    Drools Planner
CloudBalance example




                       43
Domain model
Server




         45
Server

public class Server {


    private int cpuPower;
    private int memory;
    private int networkBandwidth;


    private int cost;


    // getters
}




                                    46
Process




          47
Process




          48
Process is a planning entity

@PlanningEntity
public class Process {


    private int requiredCpuPower;
    private int requiredMemory;
    private int requiredNetworkBandwidth;


    ...


    // getters, clone, equals, hashcode
}



                                            49
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) {...}
    ...
}
                                                 50
CloudBalance




               51
Solution CloudBalance:
              problem facts
public class CloudBalance
        implements Solution<HardAndSoftScore> {


    private List<Server> serverList;


    public List<Server> getServerList() {
        return serverList;
    }


    ...
}



                                                  52
Solution CloudBalance:
              planning entities
public class CloudBalance
        implements Solution<HardAndSoftScore> {
    ...


    private List<Process> processList;


    @PlanningEntityCollectionProperty
    public List<Process> getProcessList() {
        return processList;
    }


    ...
}
                                                  53
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;
    }


    ...
}
                                                        54
Solution CloudBalance:
            score
public class CloudBalance
     implements Solution<HardAndSoftScore> {
    ...


    private HardAndSoftScore score;


    public HardAndSoftScore getScore() {...}
    public void setScore(HardAndSoftScore score) {...}


    ...
}



                                                         55
Score constraints
Score calculation
                   with Drools rule engine
   DRL
       ●   Declarative
       ●   Like SQL, regular expressions
   Performance + scalability
       ●   Indexing, ReteOO, ...
       ●   Incremental (delta based) score calculation
               ●   Solution changes => only recalculate part of
                    score




                                                                  57
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 $c
      insertLogical(new IntConstraintOccurrence(
          "serverCost", ConstraintType.NEGATIVE_SOFT,
          $c,
          $s));
end

                                                        58
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.intValue() - $cpu)
end

                                                          59
Solving it
Solver configuration by XML

<solver>
  <solutionClass>...CloudBalance</solutionClass>
  <planningEntityClass>...Process</>


  <scoreDrl>...ScoreRules.drl</scoreDrl>
  <scoreDefinition>
   <scoreDefinitionType>HARD_AND_SOFT</>
  </scoreDefinition>


  <!-- optimization algorithms -->
</solver>



                                                   61
Solving

XmlSolverFactory factory = new XmlSolverFactory(
   "...SolverConfig.xml");
Solver solver = factory.buildSolver();


solver.setPlanningProblem(cloudBalance);
solver.solve();
cloudBalance = (CloudBalance)
  solver.getBestSolution();




                                                   62
Optimization algorithms
Brute Force




              64
Brute Force config

<solver>
  ...


  <bruteForce />
</solver>




                                 65
Brute force scalability

                     9 processes = 1.5 seconds




                             * 100




       6 processes = 15 ms


                                                 66
Brute force scalability

                         12 processes = 17 minutes




                                       * 680




           9 processes = 1.5 seconds


  6 processes = 15 ms     * 100

                                                     67
Plan 1200 processes
with brute force?




                      68
First Fit




            69
First Fit config

<solver>
  ...


  <constructionHeuristic>
   <constructionHeuristicType>FIRST_FIT</>
  </constructionHeuristic>
</solver>




                                             70
First Fit scalability




                        71
First Fit results




CPU: OK
RAM: OK
Network: OK
Cost active servers: shown

                             72
First Fit Decreasing




                       73
First Fit Decreasing config

<solver>
  ...


  <constructionHeuristic>
   <constructionHeuristicType>FIRST_FIT_DECREASING</>
  </constructionHeuristic>
</solver>




                                                    74
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     {
    ...
}

                                                          75
First Fit Decreasing scalability




                               76
First Fit Decreasing results




                               77
Local Search




               78
Local Search comes after
            Construction Heuristics
<solver>
  ...


  <constructionHeuristic>
   <constructionHeuristicType>FIRST_FIT_DECREASING</>
  </constructionHeuristic>
  <localSearch>
   ...
  <localSearch>
</solver>




                                                    79
Local Search needs to be
            terminated
<solver>
  ...


  <termination>
   <maximumMinutesSpend>20</maximumMinutesSpend>
  </termination>
  ...
</solver>




                                                   80
Selecting moves

<localSearch>
  <selector>
   <selector>
     <moveFactoryClass>GenericChangeMoveFactory</>
   </selector>
   <selector>
     <moveFactoryClass>GenericSwapMoveFactory</>
   </selector>
  </selector>
  ... tabu search, simulated annealing or ...
</localSearch>



                                                     81
Hill climbing

   Select the best improving move
   Gets stuck in local optima
       ●   Not good




                                     82
Hill climbing

<localSearch>
  <selector>...</selector>
  <forager>
   <!-- Untweaked standard value -->
   <minimalAcceptedSelection>1000</>
  </forager>
</localSearch>




                                       83
Tabu search

   Hill climbing ++
   Select the best move
       ●   Recently selected moves are taboo
       ●   Even if the best move is not improving
   Does not get stuck in local optima




                                                    84
Tabu Search

<localSearch>
  <selector>...</selector>
  <acceptor>
   <!-- Untweaked standard value -->
   <propertyTabuSize>7</propertyTabuSize>
  </acceptor>
  <forager>
   <!-- Untweaked standard value -->
   <minimalAcceptedSelection>1000</>
  </forager>
</localSearch>



                                            85
Simulated annealing

   Randomly select moves
       ●   Prefer improving moves
               ●   Especially as time goes by
   Does not get stuck in local optima




                                                86
Simulated Annealing

<localSearch>
  <selector>...</selector>
  <acceptor>
   <!-- Tweaked value -->
   <simulatedAnnealingStartingTemperature>
       0hard/400soft</>
  </acceptor>
  <forager>
   <!-- Untweaked standard value -->
   <minimalAcceptedSelection>4</>
  </forager>
</localSearch>


                                             87
Local Search results




                       88
Cost ($) reduction

              Compared to First Fit
                  ●   First Fit Decreasing
                          ●   49 480 $ = 4 %
                  ●   Tabu Search
                          ●   160 860 $ = 14
                               %
                  ●   Simulated annealing
                          ●   128 950 $ = 11
                               %
              Few constraints here
                  ●   => low ROI
                                               89
Organizations rarely optimize
    planning problems.




                                90
http://www.flickr.com/photos/techbirmingham/345897594/




Organizations waste resources.

                                                                 91
Real-time planning
Real-time paradox

   First Fit Decreasing 1200 processes = 8 seconds
   Time allowed: 100ms after last change




                                                      93
Demo
  Real-time planning
CloudBalance example




                       94
Demo
Real-time planning
  TSP example




                     95
Summary
Summary

   Drools Planner optimizes planning
   Adding constraints is easy and scalable
   Switching/combining algorithms is easy




                                              97
Try an example!




                  98
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
                                                         99

Contenu connexe

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

2012 02-04fosdem2012-droolsplanner-120207031949-phpapp01

  • 1. Drools Planner: Planning optimization by example Geoffrey De Smet
  • 3. Every organization has planning problems. 3
  • 4. What is a planning problem?  Complete goals  With limited resources  Under constraints 4
  • 5. Hospital bed scheduling  Assign each ● Patient  To ● Bed  Constraints http://www.flickr.com/photos/markhillary/2227726759/ ● Length of stay ● Room requirements ● Room preferences 5
  • 6. Hospital nurse rostering  Assign each ● Shift  To ● Nurse  Constraints http://www.flickr.com/photos/glenpooh/709704564/ ● Employment contract ● Free time preferences ● Skills 6
  • 7. School timetabling  Assign each ● Course  To ● Room ● Timeslot http://www.flickr.com/photos/phelyan/2281095105/  Constraints ● No simultaneous courses ● Per room ● Per teacher ● Per student 7
  • 8. Airline routing  Assign each ● Flight  To ● Airplane ● Crew http://www.flickr.com/photos/yorickr/3674349657/  Constraints ● Airplane/crew depart from where they arrive ● Minimize mileage 8
  • 9. Bin packing in the cloud  Assign each ● Process  To ● Server  Constraints ● Hardware http://www.flickr.com/photos/torkildr/3462607995/ requirements ● Minimize server cost 9
  • 10. Bin packing in the cloud  Assign each ● Process  To ● Server  Constraints ● Hardware http://www.flickr.com/photos/torkildr/3462607995/ requirements ● Minimize server cost 10
  • 11. Which processes do we assign to this server? 11
  • 12. How did we find that solution? 12
  • 13. First fit by decreasing size 13
  • 14. First fit by decreasing size 14
  • 15. First fit by decreasing size 15
  • 16. First fit by decreasing size 16
  • 24. NP complete  No silver bullet known ● Holy grail of computer science ● P == NP ● Probably does not exist ● P != NP  Root problem of http://www.flickr.com/photos/annguyenphotography/3267723713/ all planning problems 24
  • 33. Organizations rarely optimize planning problems. 33
  • 35. Open source (ASL 2.0)  Regular releases  Reference manual  Examples 35
  • 36. Given 2 solutions, which one is better? 36
  • 37. Each Solution has 1 Score 37
  • 38. Each Solution has 1 Score 38
  • 39. Better score => better solution 39
  • 40. Better score => better solution 40
  • 41. Best score => best solution 41
  • 42. Best score => best solution 42
  • 43. Demo Drools Planner CloudBalance example 43
  • 45. Server 45
  • 46. Server public class Server { private int cpuPower; private int memory; private int networkBandwidth; private int cost; // getters } 46
  • 47. Process 47
  • 48. Process 48
  • 49. Process is a planning entity @PlanningEntity public class Process { private int requiredCpuPower; private int requiredMemory; private int requiredNetworkBandwidth; ... // getters, clone, equals, hashcode } 49
  • 50. 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) {...} ... } 50
  • 52. Solution CloudBalance: problem facts public class CloudBalance implements Solution<HardAndSoftScore> { private List<Server> serverList; public List<Server> getServerList() { return serverList; } ... } 52
  • 53. Solution CloudBalance: planning entities public class CloudBalance implements Solution<HardAndSoftScore> { ... private List<Process> processList; @PlanningEntityCollectionProperty public List<Process> getProcessList() { return processList; } ... } 53
  • 54. 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; } ... } 54
  • 55. Solution CloudBalance: score public class CloudBalance implements Solution<HardAndSoftScore> { ... private HardAndSoftScore score; public HardAndSoftScore getScore() {...} public void setScore(HardAndSoftScore score) {...} ... } 55
  • 57. Score calculation with Drools rule engine  DRL ● Declarative ● Like SQL, regular expressions  Performance + scalability ● Indexing, ReteOO, ... ● Incremental (delta based) score calculation ● Solution changes => only recalculate part of score 57
  • 58. 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 $c insertLogical(new IntConstraintOccurrence( "serverCost", ConstraintType.NEGATIVE_SOFT, $c, $s)); end 58
  • 59. 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.intValue() - $cpu) end 59
  • 61. Solver configuration by XML <solver> <solutionClass>...CloudBalance</solutionClass> <planningEntityClass>...Process</> <scoreDrl>...ScoreRules.drl</scoreDrl> <scoreDefinition> <scoreDefinitionType>HARD_AND_SOFT</> </scoreDefinition> <!-- optimization algorithms --> </solver> 61
  • 62. Solving XmlSolverFactory factory = new XmlSolverFactory( "...SolverConfig.xml"); Solver solver = factory.buildSolver(); solver.setPlanningProblem(cloudBalance); solver.solve(); cloudBalance = (CloudBalance) solver.getBestSolution(); 62
  • 65. Brute Force config <solver> ... <bruteForce /> </solver> 65
  • 66. Brute force scalability 9 processes = 1.5 seconds * 100 6 processes = 15 ms 66
  • 67. Brute force scalability 12 processes = 17 minutes * 680 9 processes = 1.5 seconds 6 processes = 15 ms * 100 67
  • 68. Plan 1200 processes with brute force? 68
  • 69. First Fit 69
  • 70. First Fit config <solver> ... <constructionHeuristic> <constructionHeuristicType>FIRST_FIT</> </constructionHeuristic> </solver> 70
  • 72. First Fit results CPU: OK RAM: OK Network: OK Cost active servers: shown 72
  • 74. First Fit Decreasing config <solver> ... <constructionHeuristic> <constructionHeuristicType>FIRST_FIT_DECREASING</> </constructionHeuristic> </solver> 74
  • 75. 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 { ... } 75
  • 76. First Fit Decreasing scalability 76
  • 77. First Fit Decreasing results 77
  • 79. Local Search comes after Construction Heuristics <solver> ... <constructionHeuristic> <constructionHeuristicType>FIRST_FIT_DECREASING</> </constructionHeuristic> <localSearch> ... <localSearch> </solver> 79
  • 80. Local Search needs to be terminated <solver> ... <termination> <maximumMinutesSpend>20</maximumMinutesSpend> </termination> ... </solver> 80
  • 81. Selecting moves <localSearch> <selector> <selector> <moveFactoryClass>GenericChangeMoveFactory</> </selector> <selector> <moveFactoryClass>GenericSwapMoveFactory</> </selector> </selector> ... tabu search, simulated annealing or ... </localSearch> 81
  • 82. Hill climbing  Select the best improving move  Gets stuck in local optima ● Not good 82
  • 83. Hill climbing <localSearch> <selector>...</selector> <forager> <!-- Untweaked standard value --> <minimalAcceptedSelection>1000</> </forager> </localSearch> 83
  • 84. Tabu search  Hill climbing ++  Select the best move ● Recently selected moves are taboo ● Even if the best move is not improving  Does not get stuck in local optima 84
  • 85. Tabu Search <localSearch> <selector>...</selector> <acceptor> <!-- Untweaked standard value --> <propertyTabuSize>7</propertyTabuSize> </acceptor> <forager> <!-- Untweaked standard value --> <minimalAcceptedSelection>1000</> </forager> </localSearch> 85
  • 86. Simulated annealing  Randomly select moves ● Prefer improving moves ● Especially as time goes by  Does not get stuck in local optima 86
  • 87. Simulated Annealing <localSearch> <selector>...</selector> <acceptor> <!-- Tweaked value --> <simulatedAnnealingStartingTemperature> 0hard/400soft</> </acceptor> <forager> <!-- Untweaked standard value --> <minimalAcceptedSelection>4</> </forager> </localSearch> 87
  • 89. Cost ($) reduction  Compared to First Fit ● First Fit Decreasing ● 49 480 $ = 4 % ● Tabu Search ● 160 860 $ = 14 % ● Simulated annealing ● 128 950 $ = 11 %  Few constraints here ● => low ROI 89
  • 90. Organizations rarely optimize planning problems. 90
  • 93. Real-time paradox  First Fit Decreasing 1200 processes = 8 seconds  Time allowed: 100ms after last change 93
  • 94. Demo Real-time planning CloudBalance example 94
  • 95. Demo Real-time planning TSP example 95
  • 97. Summary  Drools Planner optimizes planning  Adding constraints is easy and scalable  Switching/combining algorithms is easy 97
  • 99. 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 99