Constraint Programming. Global Constraints. Amira Zaki Prof. Dr. Thom Frühwirth. University of Ulm WS 2012/2013

Similar documents
AMS /672: Graph Theory Homework Problems - Week V. Problems to be handed in on Wednesday, March 2: 6, 8, 9, 11, 12.

3 No-Wait Job Shops with Variable Processing Times

Graph Theory: Matchings and Factors

Notes for Lecture 20

Mathematical and Algorithmic Foundations Linear Programming and Matchings

Matchings and Covers in bipartite graphs

1. Lecture notes on bipartite matching

MC302 GRAPH THEORY Thursday, 10/24/13

Number Theory and Graph Theory

1. Lecture notes on bipartite matching February 4th,

Matching and Covering

Matching Algorithms. Proof. If a bipartite graph has a perfect matching, then it is easy to see that the right hand side is a necessary condition.

MATH 682 Notes Combinatorics and Graph Theory II

Theorem 3.1 (Berge) A matching M in G is maximum if and only if there is no M- augmenting path.

The Dynamic Hungarian Algorithm for the Assignment Problem with Changing Costs

The vertex set is a finite nonempty set. The edge set may be empty, but otherwise its elements are two-element subsets of the vertex set.

Graphs and Network Flows IE411. Lecture 21. Dr. Ted Ralphs

Constraint (Logic) Programming

Discrete mathematics , Fall Instructor: prof. János Pach

Treewidth and graph minors

Copyright 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin Introduction to the Design & Analysis of Algorithms, 2 nd ed., Ch.

PERFECT MATCHING THE CENTRALIZED DEPLOYMENT MOBILE SENSORS THE PROBLEM SECOND PART: WIRELESS NETWORKS 2.B. SENSOR NETWORKS OF MOBILE SENSORS

Graph Theory S 1 I 2 I 1 S 2 I 1 I 2

Assignment and Matching

5 Matchings in Bipartite Graphs and Their Applications

11.4 Bipartite Multigraphs

Lecture 11: Maximum flow and minimum cut

15-451/651: Design & Analysis of Algorithms October 11, 2018 Lecture #13: Linear Programming I last changed: October 9, 2018

1 Linear programming relaxation

Graph theory - solutions to problem set 1

by conservation of flow, hence the cancelation. Similarly, we have

Part II. Graph Theory. Year

1 Matchings in Graphs

Studying Graph Connectivity

CS 473: Algorithms. Ruta Mehta. Spring University of Illinois, Urbana-Champaign. Ruta (UIUC) CS473 1 Spring / 36

Advanced Algorithms Class Notes for Monday, October 23, 2012 Min Ye, Mingfu Shao, and Bernard Moret

CS473-Algorithms I. Lecture 13-A. Graphs. Cevdet Aykanat - Bilkent University Computer Engineering Department

2. Lecture notes on non-bipartite matching

Introduction to Graph Theory

6. Lecture notes on matroid intersection

Module 7. Independent sets, coverings. and matchings. Contents

A graph is finite if its vertex set and edge set are finite. We call a graph with just one vertex trivial and all other graphs nontrivial.

Graph Theory. ICT Theory Excerpt from various sources by Robert Pergl

PART II: Local Consistency & Constraint Propagation

Graph Algorithms Matching

Lecture 6: Graph Properties

Matching Theory. Figure 1: Is this graph bipartite?

Graphs and Network Flows IE411. Lecture 13. Dr. Ted Ralphs

Figure 2.1: A bipartite graph.

Math 776 Graph Theory Lecture Note 1 Basic concepts

Paths. Path is a sequence of edges that begins at a vertex of a graph and travels from vertex to vertex along edges of the graph.

Assignment 4 Solutions of graph problems

Graphs: Introduction. Ali Shokoufandeh, Department of Computer Science, Drexel University

5. Lecture notes on matroid intersection

1 Digraphs. Definition 1

Integer Programming Theory

Math 170- Graph Theory Notes

Matching and Planarity

CS6702 GRAPH THEORY AND APPLICATIONS 2 MARKS QUESTIONS AND ANSWERS

Graph Coloring Facets from a Constraint Programming Formulation

The Structure of Bull-Free Perfect Graphs

W[1]-hardness. Dániel Marx. Recent Advances in Parameterized Complexity Tel Aviv, Israel, December 3, 2017

Approximation Algorithms: The Primal-Dual Method. My T. Thai

ACO Comprehensive Exam October 12 and 13, Computability, Complexity and Algorithms

Definition For vertices u, v V (G), the distance from u to v, denoted d(u, v), in G is the length of a shortest u, v-path. 1

Graph Theory II. Po-Shen Loh. June edges each. Solution: Spread the n vertices around a circle. Take parallel classes.

Parallelizing SAT Solver With specific application on solving Sudoku Puzzles

Byzantine Consensus in Directed Graphs

{ 1} Definitions. 10. Extremal graph theory. Problem definition Paths and cycles Complete subgraphs

Varying Applications (examples)

Combining Tree Partitioning, Precedence, and Incomparability Constraints

Introduction to Mathematical Programming IE406. Lecture 16. Dr. Ted Ralphs

Logic, Programming and Prolog (Supplement)

Induction Review. Graphs. EECS 310: Discrete Math Lecture 5 Graph Theory, Matching. Common Graphs. a set of edges or collection of two-elt subsets

Coloring. Radhika Gupta. Problem 1. What is the chromatic number of the arc graph of a polygonal disc of N sides?

On Covering a Graph Optimally with Induced Subgraphs

Introduction III. Graphs. Motivations I. Introduction IV

Ma/CS 6b Class 4: Matchings in General Graphs

4. (a) Draw the Petersen graph. (b) Use Kuratowski s teorem to prove that the Petersen graph is non-planar.

11.1. Definitions. 11. Domination in Graphs

Characterizing Graphs (3) Characterizing Graphs (1) Characterizing Graphs (2) Characterizing Graphs (4)

Rigidity, connectivity and graph decompositions

GRAPH THEORY and APPLICATIONS. Factorization Domination Indepence Clique

Introduction to Graph Theory

Sources for this lecture. 3. Matching in bipartite and general graphs. Symmetric difference

Math 778S Spectral Graph Theory Handout #2: Basic graph theory

CS 441 Discrete Mathematics for CS Lecture 26. Graphs. CS 441 Discrete mathematics for CS. Final exam

Domination, Independence and Other Numbers Associated With the Intersection Graph of a Set of Half-planes

Lecture 6: Faces, Facets

Network flows and Menger s theorem

Bipartite Perfect Matching in O(n log n) Randomized Time. Nikhil Bhargava and Elliot Marx

CS599: Convex and Combinatorial Optimization Fall 2013 Lecture 14: Combinatorial Problems as Linear Programs I. Instructor: Shaddin Dughmi

Space vs Time, Cache vs Main Memory

Finding Strongly Connected Components

PERFECT MATCHING THE CENTRALIZED DEPLOYMENT MOBILE SENSORS THE PROBLEM SECOND PART: WIRELESS NETWORKS 2.B. SENSOR NETWORKS OF MOBILE SENSORS

Chapter 3. Advanced Techniques. The advanced techniques presented in this chapter are meant to solve difficult grids.

Notes for Lecture 24

Lecture 4: Primal Dual Matching Algorithm and Non-Bipartite Matching. 1 Primal/Dual Algorithm for weighted matchings in Bipartite Graphs

IMO Training 2008: Graph Theory

Theorem 2.9: nearest addition algorithm

Transcription:

Global Constraints Amira Zaki Prof. Dr. Thom Frühwirth University of Ulm WS 2012/2013 Amira Zaki & Thom Frühwirth University of Ulm Page 1 WS 2012/2013

Overview Classes of Constraints Global Constraints Case Study 1: all different Global Constraint as Graph Problem Case Study 2: cumulative Amira Zaki & Thom Frühwirth University of Ulm Page 2 WS 2012/2013

Combinatorial Problem Representation Many possible models for a given problem Represent the entities of the problem Variables and domains Constraints that apply to these variables Test the model and try to improve its solving efficiency, try: Global constraints Redundant constraints Dual models Amira Zaki & Thom Frühwirth University of Ulm Page 3 WS 2012/2013

Expressing the Constraints Different ways can lead to different algorithm behavior Example of two programs having the same solutions but consistency propagators produce different results P1: X in 1..5, Y in 0..7, Z in 1..9, X = Y, X + Y = Z P2: X in 1..5, Y in 0..7, Z in 1..9, X = Y, 2*X = Z = X,Y in 1..5, Z in 2..9 = X,Y in 1..4, Z in 2..8 Amira Zaki & Thom Frühwirth University of Ulm Page 4 WS 2012/2013

Expressing the Constraints Bring different viewpoints of the problem A good viewpoint Problem is easily expressed Few constraints with efficient propagators The inequality constraint is rarely a good choice Knowing the different types of constraints offered by the solver Global constraints tend to be more effective Capture more semantics of the problem structure Implied or redundant constraints Amira Zaki & Thom Frühwirth University of Ulm Page 5 WS 2012/2013

Classes of Constraints 1. Basic constraints For which the solver is complete Stored in the constraint store x D, x = v 2. Primitive constraints Cannot be meaningfully decomposed Implemented as propagators x < y, x = y, x + y = z,... 3. Global Constraints Amira Zaki & Thom Frühwirth University of Ulm Page 6 WS 2012/2013

Global Constraints Global Constraints is one of the main trends in todays CP-research and practice Algorithms that can be implemented as incremental filtering mechanisms integrate well in to the general CP framework Many such algorithms from matching theory, flow optimization and graph algorithms have proved to be most effective as specialized modeling components in such frameworks Amira Zaki & Thom Frühwirth University of Ulm Page 7 WS 2012/2013

Global Constraints Captures a relation between a non-fixed number of variables Subsumes a set of basic and or primitive constraints, thus less constraints needed Encode complex or high level modeling concepts May give (significantly) stronger propagation than corresponding set of primitive constraints Case studies all_different cumulative Amira Zaki & Thom Frühwirth University of Ulm Page 8 WS 2012/2013

Global Constraint: all different all_different(+variables) where Variables is a list of domain variables with bounded domains or integers. Each variable is constrained to take a value that is unique among the variables, hence the variables are pairwise distinct Or formally, all different([x 1,..., x n ]) = {[d 1,..., d n ] i d i D(x i ), i=j d i d j }. Amira Zaki & Thom Frühwirth University of Ulm Page 9 WS 2012/2013

all different It is a filtering constraint; all values that do not belong to any solution of the constraint are filtered from its domain Example all different([x, Y, Z]), X in [1, 2], Y in [1, 2], Z in [1, 2, 3] The two variables X and Y take the values 1 and 2, while z cannot take these values. Thus by filtering, Z = 3 Amira Zaki & Thom Frühwirth University of Ulm Page 10 WS 2012/2013

Sudoku Fill a 9 9 grid with digits from 1 to 9 so that each column, each row, and each of the nine 3 3 sub-grids that compose the grid contains each digit exactly once Sample Sudoku puzzle (Wikipedia) Amira Zaki & Thom Frühwirth University of Ulm Page 11 WS 2012/2013

Modeling of Sudoku Variables One for each cell A 9 9 matrix of variables for the Sudoku grid Domains Each variable has a domain from 1 to 9 Constraints Pairwise inequality constraints among cells of the same row, column and 3 3 block Too many! Amira Zaki & Thom Frühwirth University of Ulm Page 12 WS 2012/2013

Better Modeling of Sudoku One global constraint for each row, column and 3 3 block all different(rows), all different(columns), all different(blocks) Seek sets of values that must be matched to some variables; they can not be assigned to other variables Reformulate the constraints using a bipartite graph Amira Zaki & Thom Frühwirth University of Ulm Page 13 WS 2012/2013

Bipartite Graph Definition A graph G consists of a finite non-empty set of elements V called nodes and a set of unordered pairs of nodes E called edges. If the node set V can be partitioned into two disjoint non-empty sets X and Y such that all edges in E join a node from X to a node in Y, we call G bipartite with bipartition (X, Y ) For Global Constraints, X = Variables Y = Values G = (X, Y, E) Amira Zaki & Thom Frühwirth University of Ulm Page 14 WS 2012/2013

all different as Graph Problem X Y 1 2 graph :- X in 1..2, Y in 1..2, Z in 1..3, all_different([x,y,z]). Z 3 Amira Zaki & Thom Frühwirth University of Ulm Page 15 WS 2012/2013

Matching Definitions Matching: a subset of edges in a graph G where no two edges have a node in common Maximum matching: a matching of maximum cardinality i.e. has largest set of edges in a graph that form a matching Every solution to the all different corresponds to a maximal matching If a link does not belong to a maximum matching, it can be removed (domain reduction) Amira Zaki & Thom Frühwirth University of Ulm Page 16 WS 2012/2013

Example X in [1, 2], Y in [1, 2], Z in [1, 2, 3] X 1 X 1 X 1 Y 2 Y 2 Y 2 Z 3 Z 3 Z 3 Bipartite Graph Matching Maximum Matching Amira Zaki & Thom Frühwirth University of Ulm Page 17 WS 2012/2013

Hall s Theorem Hall s marriage Theorem (Hall, 1935) If a group of men and women marry only if they have been introduced to each other previously, then a complete set of marriages is possible if and only if every subset of men has collectively been introduced to at least as many women, and vice versa Meaning: all different([x 1,..., x n ]) has a solution if and only if: K D(K) for all K {x 1,..., x n } Amira Zaki & Thom Frühwirth University of Ulm Page 18 WS 2012/2013

Step 1: Maximum Matching Computation Largest number of edges such that no two edges share an endpoint Take a bipartite graph produce maximum cardinality matching Increase the size of partial matching by finding alternating paths that starts from and ends on free (unmatched) nodes X Y Z 1 2 3 Amira Zaki & Thom Frühwirth University of Ulm Page 19 WS 2012/2013

Step 1: Maximum Matching Computation Largest number of edges such that no two edges share an endpoint Take a bipartite graph produce maximum cardinality matching X 1 X 1 Increase the size of partial matching by finding alternating paths that starts from and ends on free (unmatched) nodes Y Z 2 3 Y Z 2 3 Amira Zaki & Thom Frühwirth University of Ulm Page 20 WS 2012/2013

Step 2: Strongly Connected Components 1. Orient the edges (Matching edges from variables to values, other from values to variables) X Y 1 2 Z 3 Amira Zaki & Thom Frühwirth University of Ulm Page 21 WS 2012/2013

Step 2: Strongly Connected Components 1. Orient the edges (Matching edges from variables to values, other from values to variables) X 1 X 1 2. Compute maximal subgraph of a directed graph in which every vertex is reachable from every other vertex: aka strongly connected components Y Z 2 3 Y Z 2 3 Amira Zaki & Thom Frühwirth University of Ulm Page 22 WS 2012/2013

Step 3: Mark More Edges 1. Find unmatched value nodes (here none) 2. Mark alternative paths for these nodes, regardless if these edges belonged or not to matching X Y Z 1 2 3 4 Amira Zaki & Thom Frühwirth University of Ulm Page 23 WS 2012/2013

Step 4: Pruning Remove all unmarked edges (i.e. dotted) X 1 X 1 Y 2 Y 2 Z 3 Z 3 Corresponds to pruning stronger than binary constraints: X in [1, 2], Y in [1, 2], Z = 3 Amira Zaki & Thom Frühwirth University of Ulm Page 24 WS 2012/2013

Resource Scheduling Planning of temporal order of tasks (jobs) in presence of limited resources task, e.g., production step or lecture resource e.g., a machine, electrical energy, or lecture room tasks compete for limited resources dependencies between tasks find a schedule with an optimal value for a given objective function (measuring time or use of other resources) job shop scheduling problem tasks have fixed duration and cannot be interrupted resources are machines for at most one task at a time objective is to minimize the overall production time that is needed to accomplish all the tasks Amira Zaki & Thom Frühwirth University of Ulm Page 25 WS 2012/2013

Global Constraint: cumulative cumulative(+tasks,?limit) Tasks is a list of tasks, each of form task(s i, D i, E i, R i, T i ). S i denotes start time, D i positive duration, E i end time, R i non-negative resource consumption, T i task identifier Each of these arguments must be a finite domain variable with bounded domain or an integer The constraint holds if at any time during the start and end of each task, the total resource consumption of all tasks running at that time does not exceed the global resource limit stated Amira Zaki & Thom Frühwirth University of Ulm Page 26 WS 2012/2013

Global Constraint: cumulative Given positive Durations, Resources and Limit, let: a = min(s 1,..., S n ) b = max(s 1 + D 1,..., S n + D n ) and R ij = { R j if S j i < S j + D j 0 otherwise The constraint is True iff: ( ) n ( a i < b) R ij Limit j=1 Amira Zaki & Thom Frühwirth University of Ulm Page 27 WS 2012/2013

Moving Furniture Example We would like to move the following items: Item Movers Time/minutes Piano 3 30 Bed 3 15 Chair 1 10 Table 2 15 We want to finish moving in one hour Only 4 people are available to move Amira Zaki & Thom Frühwirth University of Ulm Page 28 WS 2012/2013

Moving Furniture Example Solution requires one cumulative constraint: Starts: [SP,SB,SC,ST] Ends: [EP,EB,EC,ET] Durations: [30,15,10,15] Resources: [3,3,1,2] TaskIds: [p,b,c,t] Limit: 4 Amira Zaki & Thom Frühwirth University of Ulm Page 29 WS 2012/2013

:- use_module(library(clpfd)). % with SWI-Prolog 6.3.8 move(tasks):- Tasks = [task(sp,dp,ep,rp,tp), task(sb,db,eb,rb,tb), task(sc,dc,ec,rc,tc), task(st,dt,et,rt,tt)], Starts = [SP,SB,SC,ST], Ends = [EP,EB,EC,ET], Durations = [DP,DB,DC,DT], Durations = [30,15,10,15], Resources = [RP,RB,RC,RT], Resources = [3,3,1,2], TaskIds = [TP,TB,TC,TT], TaskIds = [p,b,c,t], Limit = 4, Starts ins 0..60, Ends ins 0..60, cumulative(tasks, [limit(limit)]), label([sp,sb,sc,st]). % a solution: [task(0,30,30,3,p), task(30,15,45,3,b), task(0,10,10,1,c), task(45,15,60,2,t)] Amira Zaki & Thom Frühwirth University of Ulm Page 30 WS 2012/2013