Download Understanding Constraint Modelling & Abstract Models with AI and more Study notes Computer Numerical Control in PDF only on Docsity!
Alan M. Frisch Artificial Intelligence Group Department of Computer Science University of York
Modelling with Constraints
Formulating Abstract Models
Constraint Programming Last updated: 16 Nov 2010 Ian Miguel School of Computing University of St Andrews
2
Solving a Problem with Constraint Programming
Concrete FD-constraint Model of Problem using typical constructs or a particular language: OPL, ESSENCE ´ , MiniZinc , ... CSP instance in solver language, e.g., FlatZinc Original Problem Statement usually many instances may need to make well-formed from Ill-formed Instance Data Solution Solve Compile or “flatten” Model MiniZinc System Abstract FD-constraint Model of Problem in non-formal language or ESSENCE Modelling Concrete modelling Abstract modelling
4 Our Approach to Constraint Modelling Well-defined problem statement Abstract FD-constraint model (using arbitrary constructs) Concrete FD-constraint model using typical constructs Constraint model using solver- specific constructs Ill-defined problem statement 1 2 3 4
- Get from 2 to 3 in two steps.
- Our research has developed two formal languages: ESSENCE for A, ESSENCE ’ for 3.
- We’ve automated some of translation from A to 3. A
5 Teaching Constraint Modelling Well-defined problem statement Abstract FD-constraint model (using arbitrary constructs) Concrete FD-constraint model using typical constructs Constraint model using solver- specific constructs Ill-defined problem statement 1 2 3 4
- Given 2, construct A (in an informal language). Today, by example and reflection.
- Given A, construct 3 (in an informal language). Later lectures, by informal rules based on our formal rules. A
7 Writing Abstract FD-Constraint Models
- Writing a what?
- A finite-domain CSP specification in which
- Each domain is a finite set of finite objects, all of the same type, The type could be: - Atomic type: integers, Booleans, … - Compound type: array, sequence, permutation, set, multiset, function, relation, partition, graph,…
- Constraints and objective function use usual operators on these types of objects: set union, membership of a set or relation, function application,...
8 Writing Abstract FD-Constraint Models
- Each of the compound types is actually a type constructor , e.g.: - Set of . Examples: set of integer, set of Boolean - Function from to Example: function from integer to Boolean
- Every object in a domain must be finite.
- So, set of integer means finite set of integer
- { {1,2,3},{}} is a domain of type set of integer.
- { {x | x is odd}, {2,4,6} } is not a domain.
- Nesting of type constructors is allowed, e.g.:
- set of set of integer, set of function from integer to Boolean
10 Reflection
- The domain of Magic is finite: size is (n 2 ) (n 2 )
- But only if we fix size of matrix and restrict values of Magic to come from a fixed, finite set. Given a positive integer n Find Magic , an n-by-n matrix containing values between 1 and n 2 Such that Every row, column and main diagonal of Magic has the same sum No two cells of Magic contain the same value
11 Reflection Given a positive integer n Find Magic , an n-by-n matrix containing values between 1 and n 2 Such that Every row, column and main diagonal of Magic has the same sum No two cells of Magic contain the same value
- This specifies a problem class, not a single problem instance.
- Given specifies the parameters. Each assignment of appropriate values to the parameters is an instance.
- Find specifies the decision variables and their domains, usually in terms of the parameters.
- Such that specifies the constraints, usually in terms of the parameters and decision variables.
Formulating Abstract Constraint Models: Sometimes it is Trivial
14 Obvious Questions
- How hard is it to take a naturally-arising, well- formed problem statement and formulate it as an abstract constraint model?
- Is it natural to formulate a problem as an abstract constraint model? We are talking about formulating combinatorial problems not arbitrary problems.
16 Knapsack Problem from Garey and Johnson Notice: INSTANCE gives the parameters: U, s, v, B, K QUESTION gives the decision variable: U’ gives its domain: power set of U gives two constraints
16 Knapsack Problem from Garey and Johnson INSTANCE : Finite set U, for each u in U: a size s(u)∈Z
, a value v(u)∈Z
, and positive integers B and K. QUESTION : Is there a subset U'⊆ U such that ∑ u (^) ∈ U' s(u) ≤ B and ∑ u (^) ∈ U' v(u) ≥ K Notice: INSTANCE gives the parameters: U, s, v, B, K QUESTION gives the decision variable: U’ gives its domain: power set of U gives two constraints
18 Reflection
- It appears that people – well, at least computer scientists – often think of combinatorial problems as abstract constraint models. - problem is to find a combinatorial object(s) of a certain type. - so use a decision variable of this type.
19 Reflection
- Types we have seen so far:
- matrix of integer: magic square, Sudoku
- set: knapsack
- function from elements of a given set to integer: knapsack
- sequence: magic sequence
- unordered triple (set of size 3): Steiner triple systems