• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
2012 02-04fosdem2012-droolsplanner-120207031949-phpapp01
 

2012 02-04fosdem2012-droolsplanner-120207031949-phpapp01

on

  • 179 views

 

Statistics

Views

Total Views
179
Views on SlideShare
179
Embed Views
0

Actions

Likes
0
Downloads
2
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    2012 02-04fosdem2012-droolsplanner-120207031949-phpapp01 2012 02-04fosdem2012-droolsplanner-120207031949-phpapp01 Presentation Transcript

    • Drools Planner:Planning optimization by example Geoffrey De Smet
    • DemoDrools PlannerTSP 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  Constraintshttp://www.flickr.com/photos/markhillary/2227726759/ ● Length of stay ● Room requirements ● Room preferences 5
    • Hospital nurse rostering  Assign each ● Shift  To ● Nurse  Constraintshttp://www.flickr.com/photos/glenpooh/709704564/ ● Employment contract ● Free time preferences ● Skills 6
    • School timetabling  Assign each ● Course  To ● Room ● Timeslothttp://www.flickr.com/photos/phelyan/2281095105/  Constraints ● No simultaneous courses ● Per room ● Per teacher ● Per student 7
    • Airline routing  Assign each ● Flight  To ● Airplane ● Crewhttp://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 ● Hardwarehttp://www.flickr.com/photos/torkildr/3462607995/ requirements ● Minimize server cost 9
    • Bin packing in the cloud  Assign each ● Process  To ● Server  Constraints ● Hardwarehttp://www.flickr.com/photos/torkildr/3462607995/ requirements ● Minimize server cost 10
    • Which processes do we assignto 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 ofhttp://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 PlannerCloudBalance example 43
    • Domain model
    • Server 45
    • Serverpublic 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@PlanningEntitypublic class Process { private int requiredCpuPower; private int requiredMemory; private int requiredNetworkBandwidth; ... // getters, clone, equals, hashcode} 49
    • Process has a planning variable@PlanningEntitypublic 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 factspublic class CloudBalance implements Solution<HardAndSoftScore> { private List<Server> serverList; public List<Server> getServerList() { return serverList; } ...} 52
    • Solution CloudBalance: planning entitiespublic class CloudBalance implements Solution<HardAndSoftScore> { ... private List<Process> processList; @PlanningEntityCollectionProperty public List<Process> getProcessList() { return processList; } ...} 53
    • Solution CloudBalance: getProblemFactspublic 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: scorepublic 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 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 $c insertLogical(new IntConstraintOccurrence( "serverCost", ConstraintType.NEGATIVE_SOFT, $c, $s));end 58
    • 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.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
    • SolvingXmlSolverFactory 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 processeswith brute force? 68
    • First Fit 69
    • First Fit config<solver> ... <constructionHeuristic> <constructionHeuristicType>FIRST_FIT</> </constructionHeuristic></solver> 70
    • First Fit scalability 71
    • First Fit resultsCPU: OKRAM: OKNetwork: OKCost active servers: shown 72
    • First Fit Decreasing 73
    • First Fit Decreasing config<solver> ... <constructionHeuristic> <constructionHeuristicType>FIRST_FIT_DECREASING</> </constructionHeuristic></solver> 74
    • DifficultyComparatorpublic 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 planningCloudBalance example 94
    • DemoReal-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