Theory and Practice of Constraint Programming September 24-28, 2012
Total Page:16
File Type:pdf, Size:1020Kb
Association for Constraint Programming ACP Summer School 2012 Theory and Practice of Constraint Programming September 24-28, 2012 Institute of Computer Science University of Wrocław Poland Association for Constraint Programming ACP Summer School 2012 Theory and Practice of Constraint Programming September 24-28, 2012 Institute of Computer Science University of Wrocław Poland Table of contents Introduction to constraint programming Willem-Jan van Hoeve Operations Research Techniques in Constraint Programming Willem-Jan van Hoewe Constraint Programming and Biology Agostino Dovier Constraints and Complexity Peter Jeavons Set Constraints Witold Charatonik Constraints: Counting and Approximation Andrei Bulatov Introduction to Constraint Programming Willem-Jan van Hoeve Tepper School of Business, Carnegie Mellon University ACP Summer School on Theory and Practice of Constraint Programming September 24-28, 2012, Wrocław, Poland Outline Constraint Programming Overview General introduction • Successful applications Artificial Operations Computer Intelligence Research Science • Modeling • Solving • CP software optimization search algorithms data structures Basic concepts logical inference formal languages • Search Constraint • Constraint propagation Programming • Complexity Evolution events of CP Successful applications 1970s: Image processing applications in AI; Search+qualitative inference 1980s: Logic Programming (Prolog); Search + logical inference 1989: CHIP System; Constraint Logic Programming 1990s: Constraint Programming; Industrial Solvers (ILOG, Eclipse,…) 1994: Advanced inference for alldifferent and resource scheduling 2000s: Global constraints; integrated methods; modeling languages 2006: CISCO Systems acquires Eclipse CLP solver 2009: IBM acquires ILOG CP Solver & Cplex Sport Scheduling Hong Kong Airport • Gate allocation at the Hong Kong International Airport Week 1 Week 2 Week 3 Week 4 Week 5 Week 6 Week 7 • System was implemented in only four months, and includes Period 1 0 vs 1 0 vs 2 4 vs 7 3 vs 6 3 vs 7 1 vs 5 2 vs 4 constraint programming technology (ILOG) Period 2 2 vs 3 1 vs 7 0 vs 3 5 vs 7 1 vs 4 0 vs 6 5 vs 6 • Schedules ~900 flights a day (53 million passengers in 2011) Period 3 4 vs 5 3 vs 5 1 vs 6 0 vs 4 2 vs 6 2 vs 7 0 vs 7 Period 4 6 vs 7 4 vs 6 2 vs 5 1 vs 2 0 vs 5 3 vs 4 1 vs 3 Schedule of 1997/1998 ACC basketball league (9 teams) • various complicated side constraints • all 179 solutions were found in 24h using enumeration and integer linear programming [Nemhauser & Trick, 1998] • all 179 solutions were found in less than a minute using constraint programming [Henz, 1999, 2001] Port of Singapore Railroad Optimization • Netherlands Railways has among the densest rail networks in • One of the world’s largest container transshipment hubs the world, with 5,500 trains per day • Links shippers to a network of 200 shipping lines with connections to 600 ports in 123 countries • Constraint programming is one of the components in their railway planning software, which was used to design a new • Problem: Assign yard locations and loading plans under various operational and safety requirements timetable from scratch (2009) • Solution: Yard planning system, based on constraint programming • Much more robust and effective schedule, and $75M additional (ILOG) annual profit • INFORMS Edelman Award winner (2009) 8 CP Modeling and Solving CP Variables • CP allows a very flexible modeling language • CP variable types include the classical: binary, integer, continuous • Virtually any expression over the variables is allowed • In addition, variables may take a value from any e.g., x3(y2 – z) ≥ 25 + x2∙max(x,y,z) finite set e.g., x in {a,b,c,d,e} the set of possible values is called the domain of a variable • CP models can be much more intuitive than, e.g., MIP or SAT models • Lastly, there exist special `structured’ variable types close to natural language set variables (take a set of elements as value) activities or interval variables (for scheduling applications) 10 11 CP Constraints – Examples CP vs MIP Modeling: Task Sequencing • Algebraic expressions: • We need to sequence a set of tasks on a machine x3(y2 – z) ≥ 25 + x2∙max(x,y,z) Each task i has a specific fixed processing time pi • Extensional constraints (‘table’ constraints): Each task can be started after its release date ri, and must be (x,y,z) in MyTupleSet completed before its deadline di • Variables as subscripts (‘element’ constraints): Tasks cannot overlap in time y = cost[x] (here y and x are variables, ‘cost’ is an array of parameters) • Reasoning with meta-constraints: Time is represented as a discrete set of time points, say ∑i (xi > Ti) ≤ 5 • Logical relations in which (meta-)constraints can be mixed: {1, 2,…, H} (H stands for horizon) ((x < y) OR (y < z)) (c = min(x,y)) • Global constraints: Alldifferent(x1,x2, ...,xn) DisjunctiveResource( [start1,..., startn], [dur1,...,durn], [end1,...,endn] ) 13 MIP model MIP model (cont’d) • Variables • Tasks cannot overlap Binary variable xij represents whether task i starts at time variant 1 period j ∑i xij ≤ 1 for all time points j • Constraints we also need to take processing times into account; this Each task starts on exactly one time point becomes messy variant 2 ∑j xij = 1 for all tasks i Respect release date and deadline introduce binary variable bik representing whether task i comes before task k j*xij = 0 for all tasks i and (j < ri) or (j > di -pi) must be linked to xij; this becomes messy 14 15 CP model CP model • Variables • Tasks cannot overlap: Let starti represent the starting time of task i for all tasks i and j takes a value from domain {1,2,…, H} (start + p < start ) OR (start + p < start ) This immediately ensures that each task starts at exactly one i i j j j i time point • Constraints That’s it! Respect release date and deadline ri ≤ starti ≤ di -pi (See also Lombardi’s lectures on scheduling for more advanced models) 16 17 Benefits of CP model Variables as subscripts: the TSP • The number of CP variables is equal to the number of • The traveling salesperson problem asks to find a tasks, while the number of MIP variables depends also closed tour on a given set of n locations, with on the time granularity (for a horizon H, and n tasks, minimum total length we have H*n binary variables x ) ij • Input: set of locations and distance dij between two • The sequencing constraints are quite messy in MIP, locations i and j but straightforward and intuitive in CP 18 19 TSP: MIP model TSP: MIP model (cont’d) • Classical model based on ‘assignment problem’ 1 • Need to make sure that we leave and enter • Binary variable x represents whether the tour goes each location exactly once ij 5 from i to j 5 ∑j xij = 1 for all i 4 • Objective 2 4 ∑i xij = 1 for all j 2 3 min ∑ij dij xij • Constraints to remove all possible 3 subtours: 1 1 there are exponentially many 6 6 1 Alternative MIP models exist, for example the time-indexed MIP methodology therefore applies formulation uses yijt = 1 if we traverse (i,j) at step t specialized solving methods for the TSP 20 21 TSP: CP model MIP and CP model compared • Variable xi represents the i-th location that the tour • The CP model needs only n variables, while the MIP visits (variable domain is {1,2,…,n} ) model needs n2 variables (n is #locations) • Objective • The MIP model is of exponential size, while the CP model only needs one single constraint (and element n−1 contraints) min variables can be dx x + dx x • The CP model is perhaps more intuitive, as it is based n , 1 i , i+1 used as subscripts! i=1 directly on the problem structure: the ordering of the locations in the tour • Constraint alldifferent(x1, x2, …, xn) ‘global’ constraint Note: The specialized MIP solving methods outperform CP on pure TSP. In presence of side constraints (e.g., time windows), CP is often much faster than MIP. 22 23 CP Solving Basics of CP solving In general • CP solving is based on intelligently enumerating all • CP variables can be possible variable-value combinations discrete (i.e., integer valued) backtracking search • CP constraints can be • At each search state, CP applies specific constraint non-linear propagation algorithms non-differentiable • These propagation algorithms are applied to individual discontinuous constraints, and their role is to limit the size of the search tree Hence, no traditional exact Operations Research technique (LP, NLP, MIP, etc) can solve these models 24 25 Example: Graph coloring Smaller (8 variable) instance Assign a color to each country x3 x2 Adjacent countries x1 must have different x colors x4 6 x5 Can we do this with x8 at most four colors? x7 26 27 CP Model CP Solving rgbp x x 3 rgbp 3 rgbp x2 x2 x1 x1 rgbp x4 x6 x4 rgbp x6 rgbp x5 x5 x8 x8 x7 rgbp x7 rgbp Variables and domains: xi in {r,g,b,p} for all i Constraint propagation: can we remove Constraints: xi ≠ xj for all edges (i,j) inconsistent domain values? 28 29 Search Propagate rgbp rgbp x x rgbp 3 r 3 rgbp rgbp x2 x2 x1 x1 rgbp rgbp x4 rgbp x6 x4 rgbp x6 rgbp rgbp x5 x5 x8 x8 rgbp x7 rgbp x7 rgbp rgbp Search: guess a value for a variable Constraint propagation (but be prepared to backtrack): x2 = r 30 31 Search Propagate gbp gbp x x r 3 r 3 gbp gbp x2 x2 x1 x1 gbp gbp x4 gbp x6 x4 g x6 gbp gbp x5 x5 x8 x8 rgbp x7 rgbp x7 rgbp rgbp Search: guess a value for a variable Constraint propagation (but be prepared to backtrack): x5 = g 32 33 Search Continuing search & propagate gbp gbp x x r 3 r 3 gbp gp x2 x2 x1 x1 bp b x4 g x6 x4 g x6 bp bp x5 x5 x8 x8 rbp x7