the rules of modelling automatic generation of constraint programs through refinement

52
Alan M. Frisch Ian Miguel Joint work with Matt Grum, Chris Jefferson & Bernadette Martinez Hernandez The Rules of Modelling Automatic Generation of Constraint Programs through Refinement Artificial Intelligence Group Dept of Computer Science University of York School of Computer Science University of St Andrews

Upload: mercer

Post on 15-Jan-2016

30 views

Category:

Documents


0 download

DESCRIPTION

The Rules of Modelling Automatic Generation of Constraint Programs through Refinement. Artificial Intelligence Group Dept of Computer Science University of York. School of Computer Science University of St Andrews. Alan M. Frisch Ian Miguel - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Alan M. Frisch Ian Miguel

Joint work with Matt Grum, Chris Jefferson & Bernadette Martinez Hernandez

The Rules of ModellingAutomatic Generation of Constraint

Programs through Refinement

Artificial Intelligence Group

Dept of Computer Science

University of York

School of Computer Science

University of St Andrews

Page 2: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Allocating a Divisible Resource:An Application to Grid Computing

Alan Frisch

Artificial Intelligence Group

Dept. Computer Science

University of York

4pm, CS103

Page 3: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Modelling Bottleneck

• Useful for solving a wide range of important, complex problems including scheduling, allocation, layout, configuration,…

• Modelling a problem as a constraint program requires moderate/great expertise.

• Major barrier to widespread use of CP.

Page 4: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

What are CP researchers doing?

• Model Generation:– Done in private.

• Model Selection:– Case studies– Some generalisations from analysis

& experiments

Page 5: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Reducing the Modelling Bottleneck:

Automated Modelling• 2 to 3 years: We have been generating

models more and more systematically.• Embed systematic viewpoint in

automated system (CONJURE).– Takes specification in high-level language

(ESSENCE).– Reformulates specification into a set of

correct constraint programs.

• Ongoing: add heuristics for model selection.

Page 6: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Outline

• Reduced constraint programming.• ESSENCE.• CONJURE.• The big picture.

Page 7: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Part IReduced Constraint

Programming

Page 8: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

What is Constraint Programming?

• Broad view: programming in which constraints play a central role.

• Narrow view: solve combinatorial (optimisation) problem by • mapping it to a constraint satisfaction

problem• solving the constraint satisfaction

problem• mapping solution back to original

problem

Page 9: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

What is the (finite domain) CSP?

An instance comprises:• Finite set of variables• Each associated with a finite domain• Finite set of constraints on the

values taken by the variables• (Objective function)Solution is assignment of values to

variables that satisfies the constraints (and optimises objective function)

Page 10: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Modelling: Just Do It!

Find 3 distinct non-zero digits that sum to 9.

Page 11: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Just Do It!

Find 3 distinct non-zero digits that sum to 9.

• Variables: X, Y, Z

Page 12: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Just Do It!

Find 3 distinct non-zero digits that sum to 9.

• Variables/Domains: X, Y, Z::{1,..9}

Page 13: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Just Do It!

Find 3 distinct non-zero digits that sum to 9.

• Variables/Domains: X, Y, Z::{1,..9}• Constraints: X Y, Y Z, X Z, X+Y+Z=9

Page 14: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Just Do It!

Find 3 distinct non-zero digits that sum to 9.

• Variables/Domains: X, Y, Z :: {1..9}• Constraints: X Y, Y Z, X Z, X+Y+Z=9

X Y Z

Page 15: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Just Do It!

Find 3 non-zero digits that sum to 9.• Variables/Domains: X, Y, Z :: {1..9}• Constraints: X Y, Y Z, X Z, X+Y+Z=9

X Y Z X < Y < Z

Page 16: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Just Do It for a Problem

Given n and s, find n distinct non-zero digits that sum to s.

Page 17: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Model: Explicit Representation

Given n and s, find n distinct non-zero digits that sum to s.

givenfindsuch that

n:nat, s:natX: matrix (indexed by 1.. n) of 1..9?

1 nX

2 31..9 1..9 1..9…

1..9

AllDiff(X)

i1..n X[i] = s

Page 18: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Model: Occurrence Representation

givenfindsuch that

n:nat, s:natD: matrix (indexed by 1..9) of 0..1?

Given n and s, find n distinct non-zero digits that sum to s.

10/1 …

9D 0/1 0/1

2 30/1

D[1] + 2D[2] + … + 9D[9] = sD[1] + D[2] + … + D[9] = n

Page 19: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

The SONET Problem

• Given nrings rings, nnodes nodes, a set of pairs of nodes (communication demand) and an integer capacity (of each ring). Install nodes on rings satisfying demand and capacity constraints. Minimise installations.

• nrings=2, nnodes=5, capacity = 4

• demand: n1 & n3, n1 & n4, n2 & n3, n2 & n4, n3 & n5

Specification

Instance

Solution

n2 n1

n3n4 n5

n3

Page 20: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

A Model of SONET Problem

0..1 0..1 0..1 0..1

0..1 0..1 0..1 0..1

0..1 0..1 0..1 0..1

0..1 0..1 0..1 0..1

0..1 0..1 0..1 0..1

0..1 0..1 0..1 0..1

Nodes

Ringsrings-nodes

rings-nodes[r,n] = 1iff

node n is installed on ring r.

Page 21: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

A Model of SONET Problem

0..1 0..1 0..1 0..1

0..1 0..1 0..1 0..1

0..1 0..1 0..1 0..1

0..1 0..1 0..1 0..1

0..1 0..1 0..1 0..1

0..1 0..1 0..1 0..1

Nodes

Ringsrings-nodes

c

ScalarProduct > 0

c…

Minimise:

rings-nodes[r,n]r Rings n Nodes

Page 22: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Part II

Abstract Problem Specifications

The ESSENCE Language

Page 23: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

ESSENCE

• The language enables problems to be specified at a level of abstraction above that at which modelling decisions are made.

• This requires features not found in current constraint programming languages.

Page 24: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

SONET Specification

given

letting

given find

minimising

such that

nrings:nat, nnodes:nat, capacity:nat

Nodes be 1..nnodes

demand: set of set (size 2) of Nodes

rings: mset (size nrings) of set (maxsize capacity) of Nodes

r rings .|r|

pair demand . r rings . pair r

Page 25: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

ESSENCE Provides Abstract Types

Sets, Multisets, Partitions, Range Types, Unnamed TypesFunctions, Relations, Enumerated Types, Sequences…

given

letting

given find

minimising

such that

nrings:nat, nnodes:nat, capacity:nat

Nodes be 1..nnodes

demand: set of set (size 2) of Nodes

rings: mset (size nrings) of set (maxsize capacity) of Nodes

r rings .|r|

pair demand . r rings . pair r

Abstract types

Page 26: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

ESSENCE SupportsArbitrarily-Nested Types

given

letting

given find

minimising

such that

nrings:nat, nnodes:nat, capacity:nat

Nodes be 1..nnodes

demand: set of set (size 2) of Nodes

rings: mset (size nrings) of set (maxsize capacity) of Nodes

r rings .|r|

pair demand . r rings . pair r

Arbitrary nesting of types

Page 27: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

ESSENCE Supports Quantification over Decision

Variables

given

letting

given find

minimising

such that

nrings:nat, nnodes:nat, capacity:nat

Nodes be 1..nnodes

demand: set of set (size 2) of Nodes

rings: mset (size nrings) of set (maxsize capacity) of Nodes

r rings .|r|

pair demand . r rings . pair r

QuantifyingOver Decision

Variables

Page 28: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

How Usable is ESSENCE?

• Specifications of ~50 problems found in the CSP literature written by an undergraduate with no background in constraint programming.

• URL: http://www.cs.york.ac.uk/aig/constraints/

Page 29: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

ESSENCE’

• ESSENCE’ has a similar level of abstraction to existing constraint languages.

ESSENCE’ = ESSENCE -

Abstract types

Arbitrary nesting of types

QuantifyingOver Decision

Variables

Page 30: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Model Generation: Informal

Given n and s, find n distinct non-zero digits that sum to s.

givenfindsuch that

n:nat, s:natX: matrix (indexed by 1.. n) of 1..9AllDiff(X)i1..n X[i] = s

givenfindsuch that

n:nat, s:natD: matrix (indexed by 1..9) of 0..1D[1] + 2D[2] + … + 9D[9] = sD[1] + D[2] + … + D[9] = n

ESSENCE’

ESSENCE’

Page 31: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

givenfind

n:nat, s:intX: set (size n) of 1..9x = sx X

such that

Formalisation of Model Generation

givenfindsuch that

n:nat, s:natX: matrix (indexed by 1.. n) of 1..9AllDiff(X)i1..n X[i] = s

givenfindsuch that

n:nat, s:natD: matrix (indexed by 1..9) of 0..1D[1] + 2D[2] + … + 9D[9] = sD[1] + D[2] + … + D[9] = n

ESSENCE’

ESSENCE’

Page 32: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Part III

Generating Models:The CONJURE System

Page 33: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

A Theory of Model Generation Must Account

for

• Representing complex decision variables.• SONET involves finding a multiset of sets.

• Exploiting channelling.• Generate, maintain multiple representations.

• Identifying and breaking symmetries.• X+Y+Z = c X <= Y <= Z

• Performing transformations to improve efficiency.• X<=Y<=Z, AllDiff(X,Y,Z) X < Y < Z

Page 34: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

CONJURE

• CONJURE automatically generates a set of alternative ESSENCE’ models from ESSENCE specifications.

• Core: set of refinement rules.• Refine an ESSENCE expression into a set of

ESSENCE’ expressions.• Produce a set because often many

alternative refinements of an ESSENCE expression.

Page 35: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Rules Must be Compositional

• Compositional refinement: • Refinement of an expression is composed

of the refinements of its sub-expressions.

• Necessary to handle:• Unbounded nesting of constraints (usual)

• |A (B C) | < X

• Unbounded nesting of types (unique)• set, set of sets, set of set of sets, …

Page 36: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Challenge: Compositionality is Difficult

• Complex variables: can have multiple refinements. Not all support all operations.

• Nested variables: refinement of outer type must be determined without looking arbitrarily deep into the nesting.

• Operators: refinement depends on refinement of operands.

• Operators: recursion needed to handle arbitrary nesting of operands, e.g.

Page 37: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Refinement via Operator

• Function mapping ESSENCE expression to a set of ESSENCE’ expressions.

• Defined by set of equalities.• One per syntactic construct.

• For easy presentation, each equation broken into clauses:• RuleName1 (e) e1’

• RuleName2 (e) e2’

• …

• RuleNamen (e) en’

Page 38: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Refining a Specification

• Refine constraints & objective function in turn.• Compose results to form final model.

• Multiple refinements composed = multiple models.

givenlettingfindsuch that

nnodes:nat, capacity:natNodes be 1..nnodes

4 ring

MicroSonet:

4 ring : set (maxsize capacity) of Nodes

ring : set (size capacity) of Nodes

Page 39: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Refining MicroSonet

• Refinement begins with (4 ring):• Relevant clause of Element rule refines

both sides, composes the results.

givenlettingfindsuch that

nnodes:nat, capacity:natNodes be 1..nnodesring : set (size capacity) of Nodes

4 ring

(ring)(4) = {4}

Compositionality

at work

Page 40: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

FixedSizeSet1: Occurrence Rep

FixedSizeSet1 (S: set (size n) of lb..ub )

= n

such that sum(S’ )= n

{

|}

• Generates a 1-d matrix, S’

Indexed by lb..ub0/1 0/1 0/1 0/1 0/1 …

S’ = genSym(S, matrix (indxd by lb..ub) of bool)

S’

true

• Associate an axiom schema with this rule:• i . i S S’ [i]

Page 41: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

ESSENCE’ Occ Model: MicroSonet

givenlettingfindsuch that

nnodes:nat, capacity:natNodes be 1..nnodes

ring’ : matrix (indexed by Nodes) of boolsum(ring’ ) = capacityring’ [4]=1

0/1 0/1 0/1 0/1…ring’1 2 3 nnodes

givenlettingfindsuch that

nnodes:nat, capacity:natNodes be 1..nnodesring :set (size capacity) of Nodes

4 ring

ESSENCE’

ESSENCE

Page 42: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

FixedSizeSet2: Explicit RepFixedSizeSet2 (S: set (size n) of )

{

}

|

• S’ refined to give fully refined matrix S’’

S’’

S’’ (S’ )

S’’ : matrix (indexed by 1..n) of _

such that

(AllDiff(S’ ))

• All-different constraint refined, added to local model.

AllDiff(S’ )

S’ = genSym(S, matrix (indexed by 1..n) of )

• Generates intermediate 1-d matrix, S’ :

1 nS’

2 3

• Axiom schema: i . i S j 1..n (S’ [j]=i )

NB could be arbitrarily complex

Page 43: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

ESSENCE’ Explicit Model: MicroSonet

nnodes:nat, capacity:natNodes be 1..nnodes

ring’:matrix (indexed by 1..capacity) of NodesAllDifferent(ring’ )ring’ [1] = 4 OR ring’ [2] = 4 OR…

1Nodes

capacity2ring’ Nodes Nodes…

givenlettingfindsuch that

nnodes:nat, capacity:natNodes be 1..nnodesring :set (size capacity) of Nodes

4 ring

ESSENCE

givenlettingfind

such that

ESSENCE’

Page 44: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Channelling Models

• Good constraint models often contain multiple representations of same abstract variable.

• Different constraints can often be stated most effectively on different representations.

• We use channelling constraints to maintain consistency between the representations.

• CONJURE can generate these constraints automatically.

Page 45: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Automatically GeneratingChannelling Models

S:set (size n) of

S1’ :matrix (indxd by ) of bool S2’ :matrix (indxd by 1..n) of

(1) i (i S S1’ [i])(2) i (i S j 1..n (S2’ [j]=i ))

(1) (2)

(3) i (S1’ [i] j 1..n (S2’ [j]=i ))

(3)

FixedSizeSet1 FixedSizeSet2

Page 46: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

(Some) Symmetry Detection is Free!

• Some refinements, whether manual or automatic, introduce symmetry.

• Some rule clauses introduce symmetry every time they are used.

• The clause can annotate the refined expression with a description of the symmetry.

• E.g. explicit representation of a set of 3 integers drawn from 1..n.

1..n1 2 3

• Have named the indices, where the set did not.

• Introduced index symmetry.

1..n 1..n

Page 47: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Part IV

Conclusion: The Big Picture

Page 48: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

What we Hope to Achieve

• Much of modelling can be formalised as refining ESSENCE to ESSENCE’• Reduce modelling bottleneck with CONJURE.

• Ongoing work:• Develop heuristics to select among

competing models.

Page 49: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

E

Why Might we Fail to Build a Competent Automatic

Modeller?• Can’t get compositionality to work.• Some/much of modelling is involved in

writing ESSENCE specs.

M4M3

E2

M2M1

E1

Page 50: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Why Might we Fail to Build a Competent Automatic

Modeller?• Can’t get compositionality to work.• Some/much of modelling is involved in

writing ESSENCE specs.• Failure to reach closure:

– Endless list of new modelling steps to encapsulate in rules.

• General mathematical reasoning needed to perform transformations:– Adding implied constraints.– Obtaining rule applicability.– Obtaining more effective models.

Page 51: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

Benefits other than Automation

• A more systematic approach to modelling.– We’ve noticed missing combinations.– Reveal gaps in understanding.

• Generalisation/Patterns.– See a technique used in generating one model

and recognise its general usefulness.• Pedagogical purposes.

– Modelling almost absent from existing textbooks.

• ESSENCE could prove useful.• We look at modelling differently.

– Eventually, so will others.

Page 52: The Rules of Modelling Automatic Generation of Constraint Programs through Refinement

• ESSENCE specifications and CONJURE paper:– http://www.cs.york.ac.uk/aig/constraints/