• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
CP Optimizer Walkthrough
 

CP Optimizer Walkthrough

on

  • 1,309 views

A brief overview of CP Optimizer, the Constraint Programming engine of IBM CPLEX Optimization Studio

A brief overview of CP Optimizer, the Constraint Programming engine of IBM CPLEX Optimization Studio

Statistics

Views

Total Views
1,309
Views on SlideShare
1,125
Embed Views
184

Actions

Likes
2
Downloads
0
Comments
0

3 Embeds 184

https://twitter.com 180
http://www.plurk.com 3
https://duckduckgo.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

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

    CP Optimizer Walkthrough CP Optimizer Walkthrough Presentation Transcript

    • © 2013 IBM CorporationCP Optimizer:CPLEX Studios Constraint Programming EnginePaul Shaw, IBM Software Group
    • © 2013 IBM Corporation These are my own words and dont necessarily reflect the opinions of IBM This presentation is for informational purposes only and does not imply a promise orguarantee on product features or behaviourAbout this Presentation
    • © 2013 IBM Corporation Constraint Programming (CP) is an optimization technology which iscomplementary to Math Programming taking a different approach tooptimization, but having similarities to MP Major strength is in scheduling and highly combinatorial problems CP has concepts such as variables, constraints, and an objective function Variables: unknowns to be decided–are typically finite domain–can have enumerated domains, for example {2, 3, 5, 7, 11, 13, 17, 19} Constraints can capture structure and can have rich semantics. e.g.––– Also, the objective function can be a general expression. e.g.–What is Constraint Programming?all−different (x1... xn)y=count( x1... xn ,v)( y2≤z)∨(w( y+z)≥10)minimize∑i=1nci∣xi−di∣
    • © 2013 IBM Corporation Scheduling–Project scheduling• aircraft assembly–Rostering (often in conjunction with CPLEX)• hospital staffing–Maintenance scheduling• aircraft or train maintenance–Scheduling of transport zones• seaport scheduling–Manufacturing• production line scheduling Configuration–configuration of new cars Timetabling–sports timetable creationSome Applications of Constraint Programming
    • © 2013 IBM Corporation CP is a constructive approach Values are assigned to variablesone at a time to extend a partialsolution to a complete solution At a point, it may be useless tofurther extend a partial solution asat least one constraint is alreadyviolated by the partial solution–The solver backtracks and triesa different value for a previouslyassigned variable–All possible assignments ofvalues to variables can beexamined in this wayHow Constraint Programming Works
    • © 2013 IBM Corporation In CP, the basic search behaviouris tree search Including search space reductionvia domain filtering Domain filtering–Before each value-variableassignment, domain filteringoccurs–Each value of a variable whichcannot be used in a solution(given the current partialassignment) can be removed–Each constraint type has aspecialized algorithm whichfilters domainsHow Constraint Programming Works
    • © 2013 IBM CorporationAll DifferentDomain filtering1234513134141245A B C D E
    • © 2013 IBM CorporationAll DifferentDomain filtering1234513134141245A B C D EUses matching theory
    • © 2013 IBM CorporationAll DifferentDomain filtering Other examples in CP Optimizer–Cardinality (occurrence count)• Flow theory–Packing• Subset sum and packingtheory–Table (assignments)• Support structures–Scheduling constraints• Energetic reasoning• Timetables• Edge finding1234513134141245A B C D EUses matching theory
    • © 2013 IBM CorporationCP OptimizerCP Optimizer, together with CPLEX Optimizer and OPL, formCPLEX Optimization StudioCPLEX Optimization StudioOPL Modeling Language & IDELP MIPQP ...CPLEX OptimizerCSP COPSchedulingCP Optimizer
    • © 2013 IBM CorporationCP OptimizerCP Optimizer, together with CPLEX Optimizer and OPL, formCPLEX Optimization StudioCPLEX Optimization StudioOPL Modeling Language & IDELP MIPQP ...CPLEX OptimizerCSP COPSchedulingCP OptimizerDedicated modellingconstructs & APIsDedicated modellingconstructs & APIs
    • © 2013 IBM CorporationLayered ArchitectureCP Solving Engine (C++)OPLC++ Java .NETModeling and SolvingAPIsAdvanced SolvingAPI (C++ only)Modelling Languageand IDEUserAccessPoints
    • © 2013 IBM CorporationCPLEX Optimization Studio – IDE with CP Optimizer modelEditorProgressSolution browserProjects anddata sets
    • © 2013 IBM CorporationCPLEX Optimization Studio – IDE with CP Optimizer modelResourceprofilesProgressSolution browserProjects anddata sets
    • © 2013 IBM CorporationCPLEX Optimization Studio – IDE with CP Optimizer modelGantt viewProgressSolution browserProjects anddata sets
    • © 2013 IBM Corporation CP Optimizer modelling can be roughly split into two subgroups–Integer modelling–Modelling of scheduling problems These can be freely mixedModelling in CP Optimizer
    • © 2013 IBM CorporationInteger modelling in CP OptimizerVariables Expressions ConstraintsVariables are discreteintegerDomains can bespecified as a range[1..50] or as a set ofvalues {1, 3, 5, 7, 9}dvar int x in 1..50Expressions can be integeror floating-point, forexample 0.37 * y is allowedBasic arithmetic and morecomplex operators (min,max, log, pow etc.) aresupportedRelational expressions canbe treated as 0-1expressions.e.g. z = (y < t)Special expressions:y == a[x]t == count(b, 3)t == cond ? x : yRich set of constraintsStandard relational constraints(==, !=, <, >, <=, >=)Logical combinators (&&, ||, !, =>)Specialized (global) constraintsallDifferent(b)allowedAssignments(b, tuples)forbiddenAssignments(b, tuples)pack(load, container, size)lexicographic(b, c)inverse(b, c)
    • © 2013 IBM CorporationInteger modelling in CP Optimizer: Pythagorean triplesusing CP;int hmax = 100;dvar int o in 1..hmax;dvar int a in 1..hmax;dvar int h in 1..hmax;maximize (0.5 * a * o) / pow(h + a + o, 2.0);subject to {  h * h == a * a + o * o;  o < a;}execute {  writeln(h + "t" + o + "t" + a);}
    • © 2013 IBM CorporationInteger modelling in CP Optimizer: CP Optimizer log ! ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ ! Maximization problem ­ 3 variables, 2 constraints ! Initial process time : 0.00s (0.00s extraction + 0.00s propagation) !  . Log search space  : 19.8 (before), 19.8 (after) !  . Memory usage      : 746.2 kB (before), 746.2 kB (after) ! Using parallel search with 2 workers. ! ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ !          Best Branches  Non­fixed    W       Branch decision                    1,001          2    1         7 != o * 0.04166666667        5 0.06s         1            ­   0.04166666667    1,001          2    2        62 != a   0.04166666667    2,001          2    1        54 != a   0.04166666667    2,001          2    2         4 != o * 0.04285714286    2,784 0.19s         1            ­ ! ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ ! Search terminated normally, 2 solutions found. ! Best objective         : 0.0428571 (optimal ­ effective tol. is 4.285714e­06) ! Number of branches     : 5,988 ! Number of fails        : 3,048 ! Total memory usage     : 2.3 MB (2.0 MB CP Optimizer + 0.3 MB Concert) ! Time spent in solve    : 0.19s (0.19s engine + 0.00s extraction) ! Search speed (br. / s) : 31,515.8 ! ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­<<< solveOBJECTIVE: 0.0428571458      40      42
    • © 2013 IBM Corporation Scheduling problems are based on reasoning about resources over intervalsof time–In CP Optimizer, time is discrete Basic modelling entity is an intervalModelling for Scheduling in CP Optimizer: IntervalsEarliest Start Start End Latest EndTimeLength
    • © 2013 IBM Corporation We can have general precedences between intervalsModelling for Scheduling in CP Optimizer: PrecedencesabcendBeforeStart(a, b)startBeforeStart(a, b)startBeforeEnd(a, b)endBeforeEnd(a, b)startAtStart(a, b)startAtEnd(a, b)endAtStart(a, b)endAtEnd(a, b)
    • © 2013 IBM Corporation Precedence constraints can have min/max delaysModelling for Scheduling in CP Optimizer: PrecedencesabcendBeforeStart(a, b, z)startBeforeStart(a, b, z)startBeforeEnd(a, b, z)endBeforeEnd(a, b, z)startAtStart(a, b, z)startAtEnd(a, b, z)endAtStart(a, b, z)endAtEnd(a, b, z)zendBeforeStart(a, b, z) means end(a) + z <= start(b)
    • © 2013 IBM Corporation Precedence constraints can have min/max delaysModelling for Scheduling in CP Optimizer: PrecedencesabcendBeforeStart(a, b, z)startBeforeStart(a, b, z)startBeforeEnd(a, b, z)endBeforeEnd(a, b, z)startAtStart(a, b, z)startAtEnd(a, b, z)endAtStart(a, b, z)endAtEnd(a, b, z)zendBeforeStart(a, b, 10) – b starts no earlier than 10 units after a ends
    • © 2013 IBM Corporation Resources are modelled by constructing the load profile of a resource–Cumul functions are built from atomic functions–e.g. cumulFunction f = pulse(itv1, 3) + pulse(itv2, 2) + pulse(itv3, 4)Modelling for Scheduling in CP Optimizer: Resourcesintervaldemand pulseInterval 3Interval 1Interval 2sum(pulse)capacity CintervalpulseintervalstepAtStartintervalstepAtEndResource limits can be written as f <= C
    • © 2013 IBM CorporationModel (data definition)using CP;int NbTasks = ...;int NbRsrcs = ...;range RsrcIds = 0..NbRsrcs­1;int Capacity[r in RsrcIds] = ...;tuple Task {  key int id;  int     pt;  int     dmds[RsrcIds];  {int}   succs; }{Task} Tasks = ...;Example: Resource Constrained Project SchedulingDataNbTasks = 20;NbRsrcs = 4;Capacity = [ 15, 15, 16, 15 ];Tasks = {  < 1, 0, [ 0, 0, 0, 0 ], { 2, 3, 4 } >,  < 2, 10, [ 0, 3, 0, 0 ], { 5, 13 } >,  < 3, 4, [ 0, 3, 0, 0 ], { 17 } >,  < 4, 5, [ 0, 0, 0, 9 ], { 12, 15 } >,  < 5, 2, [ 0, 7, 0, 0 ], { 6, 8 } >,  < 6, 10, [ 0, 0, 0, 1 ], { 7, 9, 16 } >,  < 7, 5, [ 0, 7, 0, 0 ], { 15 } >,  < 8, 7, [ 0, 10, 0, 0 ], { 12, 20 } >,  < 9, 10, [ 0, 1, 0, 0 ], { 10, 11, 17 } >
    • © 2013 IBM CorporationModel (variables and constraints)dvar interval itvs[t in Tasks] size t.pt;cumulFunction rsrcUsage[r in RsrcIds] =    sum (t in Tasks: t.dmds[r] > 0)        pulse(itvs[t], t.dmds[r]);minimize max(t in Tasks) endOf(itvs[t]);subject to {  forall (r in RsrcIds)    rsrcUsage[r] <= Capacity[r];  forall (t1 in Tasks, t2id in t1.succs)    endBeforeStart(itvs[t1], itvs[<t2id>]);}Example: Resource Constrained Project SchedulingPost processingexecute {    for (var t in Tasks) {        writeln("Task " + t.id +                    " starts at " + itvs[t].start);    }}
    • © 2013 IBM Corporation Hierarchy–Naturally model work breakdown into tasks and sub-tasks Optionality–Intervals can be optional – solver decides if present or absent–Logical constraints between pairs of intervals Alternatives–A master interval can behave as one of a set of slave intervals–Each slave interval can have different requirements (e.g. resources) Setup times and costs–When a task of type B follows a task of type A, this may introduce adelay between them, or contribute to the objective function Complex cost functions–General cost functions can be modelled–e.g. task non-execution, resource assignment cost, tardiness costsSome Additional Features (backup slides contain more information)
    • © 2013 IBM Corporation CP Optimizer leads the way in CP for robust automatic search methods Historically, and even today, CP solvers offer only quite limited built-inmethods for exploring the search space–Instead they invariably have APIs to control the solution search process–Users use domain knowledge to write a dedicated solution searchprocess–The goal of this process is to generate variable fixings which are likely tolead the solver to a good solution quickly–This has disadvantages CP Optimizer has three levels of search control available–Fully automatic search–Give hints to the engine (use parameters or search phases)–Traditional full search control as above (rarely needed in practice) We advocate the use of automatic search or search with phasesSolving in CP Optimizer
    • © 2013 IBM CorporationCP Optimizer Layered ArchitectureCP Solving Engine (C++)OPLC++ Java .NETModeling and SolvingAPIsAdvanced SolvingAPI (C++ only)Modelling LanguageAutomatic search APIsAutomatic search APIsFull search control APIsFull search control APIs
    • © 2013 IBM Corporation Automatic search uses a set of techniques working together–These typically use domain filtering and tree search with pruning as abuilding block, but are not limited to this Examples of techniques used–Restarting techniques–No-good tracking–Impact-based branching–Opportunistic probing–Large Neighborhood Search–Evolutionary algorithms–Constraint aggregation–Dominance rules–Machine learning–LP-assisted heuristicsAutomatic Search in CP Optimizer
    • © 2013 IBM CorporationPerformance of Automatic Search on Scheduling Benchmarks
    • © 2013 IBM CorporationTraditionally, early/tardy problems are challenging for CP-based scheduling tools as they dont have a good global viewof the cost functioncostxcostxcostxcostxcostxLP-assisted heuristics
    • © 2013 IBM Corporationpiecewise {-3->5, 0->8, -10->8, 0->10, -2->12, 0->14, 2->16, 0.5->19; 0} (14,0);Traditionally, early/tardy problems are challenging for CP-based scheduling tools as they dont have a good global viewof the cost functioncostxcostxcostxcostxcostxLP-assisted heuristicsmax(0, slope * (endOf(op) - dueDate))penalty * (endOf(op) > dueDate)
    • © 2013 IBM CorporationTraditionally, early/tardy problems are challenging for CP-based scheduling tools as they dont have a good global viewof the cost functionApproach–Automatically use CPLEXs LP solver to provide a solution toa relaxed version of the scheduling problem–Use the LP solution to guide heuristics. Start an operation asclose as possible to the time proposed by CPLEXcostxcostxcostxcostxcostxLP-assisted heuristics
    • © 2013 IBM CorporationExample of benefit of LP assistance on early / tardy models
    • © 2013 IBM Corporation CP Optimizer is the only Constraint Programming engine offering– A high level of support for complex scheduling– A fully automatic solution search procedure– Full “CP-toolkit” flexibility of the search should you wish it CP Optimizer lies in an ecosystem– Fully usable in conjunction with CPLEX Optimizer• Column generation, for example– CPLEX Enterprise Server can be used to solve CP Optimizer models– Can be used from IBM ILOG ODME CP Optimizer offers other useful features– Deterministic multi-core parallelism– Conflict detection and refinement for models with no solution– Warm start procedure to start search from some known solution– Presolve capability to simplify and strengthen models before solving– Lexicographic multi-objective functionalityCP Optimizer: Main Features
    • © 2013 IBM CorporationBackup slides
    • © 2013 IBM Corporation Task hierarchies and abstraction are modelled using spanning intervalsModelling for Scheduling in CP Optimizer: Task hierarchiesModel work breakdown structure
    • © 2013 IBM Corporation Task hierarchies and abstraction are modelled using spanning intervalsModelling for Scheduling in CP Optimizer: Task hierarchiessa bc edspan(s, [a, b, c, d, e])Model work breakdown structure
    • © 2013 IBM Corporation A basic property of an intervals isthat they can be made optional We say an interval is present orabsent in any solution–The solver decides the status Example uses of optionality:–Do some work in-house,outsource (at a cost)–Optional work can be useful ifperformed (e.g. extra finishing) Each constraint reacts “gracefully”when an interval is absent Arbitrary logical relations can bespecified between the presence ofdifferent intervalsModelling for Scheduling in CP Optimizer: Optionalityba cimplies impliesacb Precedencenot activePrecedence active
    • © 2013 IBM CorporationbModelling for Scheduling in CP Optimizer: Alternatives Alternatives1 ofabcdalternative(t, [a, b, c, d])t Often there is more than one wayof carrying out a task. We modelthis using alternatives Each alternative may use differentresources and have differentdurations An “alternative” constraint uses amaster task and slave tasks. Eachslave task is optional, only one canbe present in the final solution The master starts and ends at thesame time of the selected slave
    • © 2013 IBM CorporationModelling for Scheduling in CP Optimizer: Alternatives Alternatives1 ofabcdalternative(t, [a, b, c, d])t Often there is more than one wayof carrying out a task. We modelthis using alternatives Each alternative may use differentresources and have differentdurations An “alternative” constraint uses amaster task and slave tasks. Eachslave task is optional, only one canbe present in the final solution The master starts and ends at thesame time of the selected slave
    • © 2013 IBM Corporation A recipe is a scheduling sub-system that can involveprecedences, resources etc. Alternative recipes can bemodelled using a combination ofalternative and span constraints For each recipe, all intervals arecoupled together via constraints All intervals have the samepresence status: either all presentor all absentModelling for Scheduling in CP Optimizer: Recipes Alternatives (recipes)tt1 of
    • © 2013 IBM Corporation A recipe is a scheduling sub-system that can involveprecedences, resources etc. Alternative recipes can bemodelled using a combination ofalternative and span constraints For each recipe, all intervals arecoupled together via constraints All intervals have the samepresence status: either all presentor all absentModelling for Scheduling in CP Optimizer: Recipes Alternatives (recipes)1 oft