• Aucun résultat trouvé

ECLiPSeELearning HelmutSimonis Chapter9:ChoosingtheModel(SportsScheduling)

N/A
N/A
Protected

Academic year: 2021

Partager "ECLiPSeELearning HelmutSimonis Chapter9:ChoosingtheModel(SportsScheduling)"

Copied!
394
0
0

Texte intégral

(1)

Chapter 9: Choosing the Model (Sports Scheduling)

Helmut Simonis

Cork Constraint Computation Centre Computer Science Department

University College Cork Ireland

ECLiPSe ELearning

Overview

(2)

Licence

This work is licensed under the Creative Commons

Attribution-Noncommercial-Share Alike 3.0 Unported License.

To view a copy of this license, visit http:

//creativecommons.org/licenses/by-nc-sa/3.0/ or

send a letter to Creative Commons, 171 Second Street, Suite

300, San Francisco, California, 94105, USA.

(3)

Outline

1 Problem

2 Model

3 Program

4 Search

5 Redundant Modelling

(4)

What we want to introduce

How to come up with a model for a problem Why choosing a good model is an art Channeling

Projection

Redundant Constraints

(5)

Outline

1 Problem

2 Model

3 Program

4 Search

5 Redundant Modelling

(6)

Sports Scheduling

Tournament Planning

We plan a tournament with 8 teams, where every team plays every other team exactly once. The tournament is played on 7 days, each team playing on each day. The games are

scheduled in 7 venues, and each team should play in each venue exactly once.

As part of the TV arrangements, some preassignments are

done: We may either fix the game between two particular

teams to a fixed day and venue, or only state that some team

must play on a particular day at a given venue. The objective is

to complete the schedule, so that all constraints are satisfied.

(7)

Example

City 1 City 2 City 3 City 4 City 5 City 6 City 7

Day 1 8 7, 5

Day 2 2 1, 5

Day 3 7 8

Day 4 2 5 1

Day 5 8 1

Day 6 5, 4

Day 7 4 1, 3

(8)

Solution

City 1 City 2 City 3 City 4 City 5 City 6 City 7

Day 1 6, 8 1, 2 5, 7 3, 4

Day 2 2, 3 1, 5 4, 8 6, 7

Day 3 1, 7 2, 4 3, 8 5, 6

Day 4 4, 7 2, 6 3, 5 1, 8

Day 5 5, 8 3, 6 1, 4 2, 7

Day 6 3, 7 1, 6 4, 5 2, 8

Day 7 4, 6 2, 5 7, 8 1, 3

(9)

Problem Model Program Search Redundant Modelling

A More Abstract Formulation

Rooms Puzzle, (Thomas G. Room, 1955)

Place numbers 1 to 8 in cells so that each row and each

column has each number exactly once, each cell contains

either no numbers or two numbers (which must be different

from each other), and each combination of two different

numbers appears in exactly one cell.

(10)

A More Abstract Formulation

Rooms Puzzle, (Thomas G. Room, 1955)

Place numbers 1 to 8 in cells so that each row and each column has each number exactly once, each cell contains either no numbers or two numbers (which must be different from each other), and each combination of two different numbers appears in exactly one cell.

Puzzle presented by R. Finkel

(11)

Outline

1 Problem

2 Model

Exploring Ideas Expanding Idea 7 Comparing Ideas Channeling Selected Model

3 Program

4 Search

(12)

How to come up with a model

What are the variables/what are their values?

How can we express the constraints?

Do we have these constraints in our system?

Does this do good propagation?

Backtrack to earlier step as required

(13)

Requirements

1

There are 8 teams, seven days and seven locations

2

Each team plays each other team exactly once

3

Each team plays 7 games (redundant)

4

Each team plays in each location exactly once

5

Each team plays on each day exactly once

6

A game consists of two (different) teams

7

There are four games on each day (redundant)

8

There are four games at each location (redundant)

9

In any location there is atmost one game at a time

(14)

Idea 1

Matrix Day × Game (7 × 4)

Each cell contains two variables, denoting teams Easy to say that team plays once on each day, alldifferent

Columns don’t have significance

Model does not mention location, how to add this?

How to express that each team plays each other once?

(15)

Idea 2, Change problem structure

Matrix of Day × Location (7 × 7)

Each cell contains two variables, each denoting a team How do we avoid symmetry inside cell?

Need special value (0) to denote that there is no game In one cell, either both or none of the variables are 0 Easy to say that each row and column contains each team exactly once

Except for value 0, can not use alldifferent

Link between two variables in cell to state that game needs two different teams

How to express that each (ordered) pair occurs exactly

(16)

Idea 3, Add location variables

Model as in Idea 1, matrix Day × Game

Each cell contains two variables for teams and one for location

Easy to state that games on one day are in different locations

How to express condition that each team plays in each location once?

Also, how to express that each team plays each other

exactly once?

(17)

Idea 4, Use variables for pairs

Matrix Day × Location

Each cell contains one variable ranging over (sorted) pairs of teams, and special value 0 (no game)

Each pair value occurs once, except for 0 Special constraint alldifferent0 Or use gcc

How to state that each team plays once per day?

How to state that each team plays in each location?

(18)

Idea 5: If all else fails, use binary variables

Binary variable stating that team i plays in location j at day k

Three dimensional matrix

Each team plays once on each day Each team plays once in each location

Each game has two (different) teams, needs auxiliary variable

Each pair of team meets once, needs auxiliary variables

(19)

Idea 6: An even bigger binary model

Use four dimensions

Team i meets team j in location k on day l 3136 = 8*8*7*7 variables

Constraints all linear

Why use finite domain constraints?

(20)

Idea 7: A different mapping

Each team plays each other exactly once, one variable for each combination (8*7/2=28 variables)

Decide when and where this game is played, values range over combinations of days and locations (7*7=49 values) All variables must be different (no two games at same time and location)

Each team plays 7 games, by construction

How to express that each team plays once per day?

How to express that each team plays in each location

once?

(21)

Expand Idea 7 into Full Model

(22)

Numbering Values

City 1 City 2 City 3 City 4 City 5 City 6 City 7

Day 1 1 2 3 4 5 6 7

Day 2 8 9 10 11 12 13 14

Day 3 15 16 17 18 19 20 21

Day 4 22 23 24 25 26 27 28

Day 5 29 30 31 32 33 34 35

Day 6 36 37 38 39 40 41 42

Day 7 43 44 45 46 47 48 49

(23)

Four games on each day

City 1 City 2 City 3 City 4 City 5 City 6 City 7

Day 1 1 2 3 4 5 6 7

Day 2 8 9 10 11 12 13 14

Day 3 15 16 17 18 19 20 21

Day 4 22 23 24 25 26 27 28

Day 5 29 30 31 32 33 34 35

Day 6 36 37 38 39 40 41 42

Day 7 43 44 45 46 47 48 49

Day 1 corresponds to values 1..7 Four variables can take these values Day 2 corresponds to values 8..14, etc One constraint per day

Exactly four of all variables take their value in the set ...

Seven such constraints

(24)

Four games at each location

City 1 City 2 City 3 City 4 City 5 City 6 City 7

Day 1 1 2 3 4 5 6 7

Day 2 8 9 10 11 12 13 14

Day 3 15 16 17 18 19 20 21

Day 4 22 23 24 25 26 27 28

Day 5 29 30 31 32 33 34 35

Day 6 36 37 38 39 40 41 42

Day 7 43 44 45 46 47 48 49

City 1 corresponds to values 1, 8, 15, 22, 29, 36, 43

Four variables can take these values City 2 corresponds to values

2, 9, 16, 23, 30, 37, 44 One constraint per location

Exactly four of all variables take their value in the set ...

Seven such constraints over 28 variables each

(25)

Teams plays once on a day (at a location)

Select those variables which correspond to Team i

Exactly one of those variables takes its value in the set 1..7 Same for all other days

Same for all other teams

56 Constraints over 7 variables each

Similar for teams and locations, another 56 constraints

(26)

Are we there yet?

28 variables with 49 possible values 1 alldifferent

7 exactly constraints over all variables (Days) 7 exactly constraints over all variables (Locations) 56 exactly constraints over 7 variables each (Days) 56 exactly constraints over 7 variables each (Locations) Forgotten anything?

Check the requirements

(27)

Are we there yet?

28 variables with 49 possible values 1 alldifferent

7 exactly constraints over all variables (Days) 7 exactly constraints over all variables (Locations) 56 exactly constraints over 7 variables each (Days) 56 exactly constraints over 7 variables each (Locations) Forgotten anything?

Check the requirements

(28)

Are we there yet?

28 variables with 49 possible values 1 alldifferent

7 exactly constraints over all variables (Days) 7 exactly constraints over all variables (Locations) 56 exactly constraints over 7 variables each (Days) 56 exactly constraints over 7 variables each (Locations) Forgotten anything?

Check the requirements

(29)

Do we satisfy the requirements?

By construction

1

There are 8 teams, seven days and seven locations

2

Each team plays each other team exactly once

3

Each team plays 7 games (redundant)

4

Each team plays in each location exactly once

5

Each team plays on each day exactly once

6

A game consists of two (different) teams

7

There are four games on each day (redundant)

8

There are four games at each location (redundant)

9

In any location there is atmost one game at a time

(30)

Do we satisfy the requirements?

By construction

1

There are 8 teams, seven days and seven locations

2

Each team plays each other team exactly once

3

Each team plays 7 games (redundant)

4

Each team plays in each location exactly once

5

Each team plays on each day exactly once

6

A game consists of two (different) teams

7

There are four games on each day (redundant)

8

There are four games at each location (redundant)

9

In any location there is atmost one game at a time

(31)

Do we satisfy the requirements?

By construction

1

There are 8 teams, seven days and seven locations

2

Each team plays each other team exactly once

3

Each team plays 7 games (redundant)

4

Each team plays in each location exactly once

5

Each team plays on each day exactly once

6

A game consists of two (different) teams

7

There are four games on each day (redundant)

8

There are four games at each location (redundant)

9

In any location there is atmost one game at a time

(32)

Do we satisfy the requirements?

56 exactly constraints on 7 variables

1

There are 8 teams, seven days and seven locations

2

Each team plays each other team exactly once

3

Each team plays 7 games (redundant)

4

Each team plays in each location exactly once

5

Each team plays on each day exactly once

6

A game consists of two (different) teams

7

There are four games on each day (redundant)

8

There are four games at each location (redundant)

9

In any location there is atmost one game at a time

(33)

Do we satisfy the requirements?

56 exactly constraints on 7 variables

1

There are 8 teams, seven days and seven locations

2

Each team plays each other team exactly once

3

Each team plays 7 games (redundant)

4

Each team plays in each location exactly once

5

Each team plays on each day exactly once

6

A game consists of two (different) teams

7

There are four games on each day (redundant)

8

There are four games at each location (redundant)

9

In any location there is atmost one game at a time

(34)

Do we satisfy the requirements?

By construction

1

There are 8 teams, seven days and seven locations

2

Each team plays each other team exactly once

3

Each team plays 7 games (redundant)

4

Each team plays in each location exactly once

5

Each team plays on each day exactly once

6

A game consists of two (different) teams

7

There are four games on each day (redundant)

8

There are four games at each location (redundant)

9

In any location there is atmost one game at a time

(35)

Do we satisfy the requirements?

7 exactly constraints on 28 variables

1

There are 8 teams, seven days and seven locations

2

Each team plays each other team exactly once

3

Each team plays 7 games (redundant)

4

Each team plays in each location exactly once

5

Each team plays on each day exactly once

6

A game consists of two (different) teams

7

There are four games on each day (redundant)

8

There are four games at each location (redundant)

9

In any location there is atmost one game at a time

(36)

Do we satisfy the requirements?

7 exactly constraints on 28 variables

1

There are 8 teams, seven days and seven locations

2

Each team plays each other team exactly once

3

Each team plays 7 games (redundant)

4

Each team plays in each location exactly once

5

Each team plays on each day exactly once

6

A game consists of two (different) teams

7

There are four games on each day (redundant)

8

There are four games at each location (redundant)

9

In any location there is atmost one game at a time

(37)

Do we satisfy the requirements?

alldifferent

1

There are 8 teams, seven days and seven locations

2

Each team plays each other team exactly once

3

Each team plays 7 games (redundant)

4

Each team plays in each location exactly once

5

Each team plays on each day exactly once

6

A game consists of two (different) teams

7

There are four games on each day (redundant)

8

There are four games at each location (redundant)

9

In any location there is atmost one game at a time

(38)

What about the exactly constraint?

ECLiPSe doesn’t provide this constraint Other system might do, could switch system Implement it

Extend gcc to allow multiple values Should be last resort

Emulate constraint with others

(39)

Idea 8: Mapping games to days and locations

For each game to be played, we have two variables One ranges over the days

The other over the locations

Easy to state that there are four games per day an location Easy to state that each team plays once per day and location

How do we express that no two games are played at the same location and the same time?

If we had an alldifferent over pairs of variables...

Not in ECLiPSe

(40)

We have four games on each day

Each row value is taken four times amongst the variables gcc([gcc(4,4,1),...,gcc(4,4,7)],Rows) Similar for columns:

gcc([gcc(4,4,1),...,gcc(4,4,7)],Cols)

(41)

Each team plays once per day

For the seven variables which describe games of a team Each row value is taken exactly once amongst the variables

Could use

gcc([gcc(1,1,1),...,gcc(1,1,7)],Vars)

But alldifferent(Vars) is more compact

Similar for columns

(42)

How do the models differ?

D Days

T Teams

L Locations

G Games

Idea Mapping

1 D × G × {f , s} → T 2 D × L × {f , s} → T ∪ {0}

3 D × G × {f , s} → T D × G → L 4 D × L → T M T ∪ {0}

5 T × D × L → {0, 1}

6 T × T × D × L → {0, 1}

7 T M T → D × L

8 T M T → D

T M T → L

(43)

Requirements Capture

Y yes

N no

? unknown

C by construction

L linear

NL non-linear

E exactly

G gcc

A alldifferent

Idea Requirement

1 2 3 4 5 6 7 8 9

1 N ? Y ? Y Y Y ? ?

2 C ? Y Y Y Y Y Y Y

3 C ? Y ? Y Y Y Y Y

4 C Y Y Y Y Y Y Y Y

5 C NL L L L NL L L NL

6 C L L L L L L L L

7 C C C E E C E E A

8 C C C A A C G G ?

(44)

Requirements Capture

Req 1: There are 8 teams, seven days and seven locations

Y yes

N no

? unknown

C by construction

L linear

NL non-linear

E exactly

G gcc

A alldifferent

Idea Requirement

1 2 3 4 5 6 7 8 9

1 N ? Y ? Y Y Y ? ?

2 C ? Y Y Y Y Y Y Y

3 C ? Y ? Y Y Y Y Y

4 C Y Y Y Y Y Y Y Y

5 C NL L L L NL L L NL

6 C L L L L L L L L

7 C C C E E C E E A

8 C C C A A C G G ?

(45)

Requirements Capture

Req 2: Each team plays each other team exactly once

Y yes

N no

? unknown

C by construction

L linear

NL non-linear

E exactly

G gcc

A alldifferent

Idea Requirement

1 2 3 4 5 6 7 8 9

1 N ? Y ? Y Y Y ? ?

2 C ? Y Y Y Y Y Y Y

3 C ? Y ? Y Y Y Y Y

4 C Y Y Y Y Y Y Y Y

5 C NL L L L NL L L NL

6 C L L L L L L L L

7 C C C E E C E E A

8 C C C A A C G G ?

(46)

Requirements Capture

Req 3: Each team plays 7 games

Y yes

N no

? unknown

C by construction

L linear

NL non-linear

E exactly

G gcc

A alldifferent

Idea Requirement

1 2 3 4 5 6 7 8 9

1 N ? Y ? Y Y Y ? ?

2 C ? Y Y Y Y Y Y Y

3 C ? Y ? Y Y Y Y Y

4 C Y Y Y Y Y Y Y Y

5 C NL L L L NL L L NL

6 C L L L L L L L L

7 C C C E E C E E A

8 C C C A A C G G ?

(47)

Requirements Capture

Req 4: Each team plays in each location exactly once

Y yes

N no

? unknown

C by construction

L linear

NL non-linear

E exactly

G gcc

A alldifferent

Idea Requirement

1 2 3 4 5 6 7 8 9

1 N ? Y ? Y Y Y ? ?

2 C ? Y Y Y Y Y Y Y

3 C ? Y ? Y Y Y Y Y

4 C Y Y Y Y Y Y Y Y

5 C NL L L L NL L L NL

6 C L L L L L L L L

7 C C C E E C E E A

8 C C C A A C G G ?

(48)

Requirements Capture

Req 5: Each team plays on each day exactly once

Y yes

N no

? unknown

C by construction

L linear

NL non-linear

E exactly

G gcc

A alldifferent

Idea Requirement

1 2 3 4 5 6 7 8 9

1 N ? Y ? Y Y Y ? ?

2 C ? Y Y Y Y Y Y Y

3 C ? Y ? Y Y Y Y Y

4 C Y Y Y Y Y Y Y Y

5 C NL L L L NL L L NL

6 C L L L L L L L L

7 C C C E E C E E A

8 C C C A A C G G ?

(49)

Requirements Capture

Req 6: A game consists of two (different) teams

Y yes

N no

? unknown

C by construction

L linear

NL non-linear

E exactly

G gcc

A alldifferent

Idea Requirement

1 2 3 4 5 6 7 8 9

1 N ? Y ? Y Y Y ? ?

2 C ? Y Y Y Y Y Y Y

3 C ? Y ? Y Y Y Y Y

4 C Y Y Y Y Y Y Y Y

5 C NL L L L NL L L NL

6 C L L L L L L L L

7 C C C E E C E E A

8 C C C A A C G G ?

(50)

Requirements Capture

Req 7: There are four games on each day

Y yes

N no

? unknown

C by construction

L linear

NL non-linear

E exactly

G gcc

A alldifferent

Idea Requirement

1 2 3 4 5 6 7 8 9

1 N ? Y ? Y Y Y ? ?

2 C ? Y Y Y Y Y Y Y

3 C ? Y ? Y Y Y Y Y

4 C Y Y Y Y Y Y Y Y

5 C NL L L L NL L L NL

6 C L L L L L L L L

7 C C C E E C E E A

8 C C C A A C G G ?

(51)

Requirements Capture

Req 8: There are four games at each location

Y yes

N no

? unknown

C by construction

L linear

NL non-linear

E exactly

G gcc

A alldifferent

Idea Requirement

1 2 3 4 5 6 7 8 9

1 N ? Y ? Y Y Y ? ?

2 C ? Y Y Y Y Y Y Y

3 C ? Y ? Y Y Y Y Y

4 C Y Y Y Y Y Y Y Y

5 C NL L L L NL L L NL

6 C L L L L L L L L

7 C C C E E C E E A

8 C C C A A C G G ?

(52)

Requirements Capture

Req 9: In any location there is atmost one game at a time

Y yes

N no

? unknown

C by construction

L linear

NL non-linear

E exactly

G gcc

A alldifferent

Idea Requirement

1 2 3 4 5 6 7 8 9

1 N ? Y ? Y Y Y ? ?

2 C ? Y Y Y Y Y Y Y

3 C ? Y ? Y Y Y Y Y

4 C Y Y Y Y Y Y Y Y

5 C NL L L L NL L L NL

6 C L L L L L L L L

7 C C C E E C E E A

8 C C C A A C G G ?

(53)

Comments on models

Idea Main point

1 missing locations, first second symmetry 2 spare value, first second symmetry 3 first second symmetry

4 spare value

5 0/1, non-linear constraints

6 0/1, large matrix

7 needs exactly constraint

8 needs alldifferent on tuples

(54)

Channeling

Instead of expressing all constraints over one set of variables

Use multiple sets of variables

Decide which constraint to express over which variables Allows more freedom on how to express problem

Link the different variables with channeling constraints

(55)

In Our Case

Combine ideas 7 and 8

One set of variables ranging over pairs

Another using two variables per game for day and location How to combine variables?

Minimize loss of information

(56)

Projection

City 1 City 2 City 3 City 4 City 5 City 6 City 7

Day 1 1 2 3 4 5 6 7

Day 2 8 9 10 11 12 13 14

Day 3 15 16 17 18 19 20 21

Day 4 22 23 24 25 26 27 28

Day 5 29 30 31 32 33 34 35

Day 6 36 37 38 39 40 41 42

Day 7 43 44 45 46 47 48 49

Link pair variables to row and column variables Pair variable uses cell numbers 1-49 as values

Row and column variables indicate on which day (row) and in which location (column) the game is played

Pair value 23 = row 4, column 2

element constraint to link the variables

Two projections from D × L space onto D and L

(57)

Mapping cells to rows and columns

City 1 City 2 City 3 City 4 City 5 City 6 City 7

Day 1 1 2 3 4 5 6 7

Day 2 8 9 10 11 12 13 14

Day 3 15 16 17 18 19 20 21

Day 4 22 23 24 25 26 27 28

Day 5 29 30 31 32 33 34 35

Day 6 36 37 38 39 40 41 42

Day 7 43 44 45 46 47 48 49

element(Cell,[1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3, 4,4,4,4,4,4,4,5,5,5,5,5,5,5,6,6,6,6,6,6,6, 7,7,7,7,7,7,7],Row),

element(Cell,[1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,

1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,

1,2,3,4,5,6,7],Col),

(58)

Mapping cells to rows and columns

City 1 City 2 City 3 City 4 City 5 City 6 City 7

Day 1 1 2 3 4 5 6 7

Day 2 8 9 10 11 12 13 14

Day 3 15 16 17 18 19 20 21

Day 4 22 23 24 25 26 27 28

Day 5 29 30 31 32 33 34 35

Day 6 36 37 38 39 40 41 42

Day 7 43 44 45 46 47 48 49

element(23 ,[1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3, 4,4,4,4,4,4,4,5,5,5,5,5,5,5,6,6,6,6,6,6,6, 7,7,7,7,7,7,7],4 ),

element(23 ,[1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,

1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,

1,2,3,4,5,6,7],2 ),

(59)

Channeling Constraints

This is one common type, a projection Another common type is the inverse

Link a variable A → B to another B → A Typically used for bijective mappings Built-in inverse/2

Also used: Boolean channeling

Link variables A → B and A × B → {0, 1}

Built-in bool_channeling/3

(60)

Selected Model

Two sets of variables (Req 1, 2, 3, 6, by construction) Pair variables (T M T → D × L)

alldifferent (Req 9)

Day and Location variables (T M T → D), (T M T → L) gcc (Req 4, 5)

alldifferent (Req 7, 8) Channeling Constraints

element projection from pairs onto rows and columns

Search only on pair variables

(61)

Selected Model

Req 1: There are 8 teams, seven days and seven locations Two sets of variables (Req 1, 2, 3, 6, by construction) Pair variables (T M T → D × L)

alldifferent (Req 9)

Day and Location variables (T M T → D), (T M T → L) gcc (Req 4, 5)

alldifferent (Req 7, 8) Channeling Constraints

element projection from pairs onto rows and columns

Search only on pair variables

(62)

Selected Model

Req 2: Each team plays each other team exactly once Two sets of variables (Req 1, 2, 3, 6, by construction) Pair variables (T M T → D × L)

alldifferent (Req 9)

Day and Location variables (T M T → D), (T M T → L) gcc (Req 4, 5)

alldifferent (Req 7, 8) Channeling Constraints

element projection from pairs onto rows and columns

Search only on pair variables

(63)

Selected Model

Req 3: Each team plays 7 games

Two sets of variables (Req 1, 2, 3, 6, by construction) Pair variables (T M T → D × L)

alldifferent (Req 9)

Day and Location variables (T M T → D), (T M T → L) gcc (Req 4, 5)

alldifferent (Req 7, 8) Channeling Constraints

element projection from pairs onto rows and columns

Search only on pair variables

(64)

Selected Model

Req 4: Each team plays in each location exactly once Two sets of variables (Req 1, 2, 3, 6, by construction) Pair variables (T M T → D × L)

alldifferent (Req 9)

Day and Location variables (T M T → D), (T M T → L) gcc (Req 4, 5)

alldifferent (Req 7, 8) Channeling Constraints

element projection from pairs onto rows and columns

Search only on pair variables

(65)

Selected Model

Req 5: Each team plays on each day exactly once

Two sets of variables (Req 1, 2, 3, 6, by construction) Pair variables (T M T → D × L)

alldifferent (Req 9)

Day and Location variables (T M T → D), (T M T → L) gcc (Req 4, 5)

alldifferent (Req 7, 8) Channeling Constraints

element projection from pairs onto rows and columns

Search only on pair variables

(66)

Selected Model

Req 6: A game consists of two (different) teams

Two sets of variables (Req 1, 2, 3, 6, by construction) Pair variables (T M T → D × L)

alldifferent (Req 9)

Day and Location variables (T M T → D), (T M T → L) gcc (Req 4, 5)

alldifferent (Req 7, 8) Channeling Constraints

element projection from pairs onto rows and columns

Search only on pair variables

(67)

Selected Model

Req 7: There are four games on each day

Two sets of variables (Req 1, 2, 3, 6, by construction) Pair variables (T M T → D × L)

alldifferent (Req 9)

Day and Location variables (T M T → D), (T M T → L) gcc (Req 4, 5)

alldifferent (Req 7, 8) Channeling Constraints

element projection from pairs onto rows and columns

Search only on pair variables

(68)

Selected Model

Req 8: There are four games at each location

Two sets of variables (Req 1, 2, 3, 6, by construction) Pair variables (T M T → D × L)

alldifferent (Req 9)

Day and Location variables (T M T → D), (T M T → L) gcc (Req 4, 5)

alldifferent (Req 7, 8) Channeling Constraints

element projection from pairs onto rows and columns

Search only on pair variables

(69)

Selected Model

Req 9: In any location there is atmost one game at a time Two sets of variables (Req 1, 2, 3, 6, by construction) Pair variables (T M T → D × L)

alldifferent (Req 9)

Day and Location variables (T M T → D), (T M T → L) gcc (Req 4, 5)

alldifferent (Req 7, 8) Channeling Constraints

element projection from pairs onto rows and columns

Search only on pair variables

(70)

Handling of hints (I)

City 1 City 2 City 3 City 4 City 5 City 6 City 7

Day 1 8 7, 5

Day 2 2 1, 5

Day 3 7 8

Day 4 2 5 1

Day 5 8 1

Day 6 5, 4

Day 7 4 1, 3

This value (17) can not be used by pairs not involving team 8

One of the pairs involving team 8 must use this value (17)

(71)

Handling of hints (I)

City 1 City 2 City 3 City 4 City 5 City 6 City 7

Day 1 8 7, 5

Day 2 2 1, 5

Day 3 7 8

Day 4 2 5 1

Day 5 8 1

Day 6 5, 4

Day 7 4 1, 3

This value (17) can not be used by pairs not involving team 8

One of the pairs involving team 8 must use this value (17)

(72)

Handling of hints (I)

City 1 City 2 City 3 City 4 City 5 City 6 City 7

Day 1 8 7, 5

Day 2 2 1, 5

Day 3 7 8

Day 4 2 5 1

Day 5 8 1

Day 6 5, 4

Day 7 4 1, 3

This value (17) can not be used by pairs not involving team 8

One of the pairs involving team 8 must use this value (17)

(73)

Handling of hints (II)

City 1 City 2 City 3 City 4 City 5 City 6 City 7

Day 1 8 7, 5

Day 2 2 1, 5

Day 3 7 8

Day 4 2 5 1

Day 5 8 1

Day 6 5, 4

Day 7 4 1, 3

The pair involving teams 5 and 7 must take value 5, fixes

variable

(74)

Handling of hints (II)

City 1 City 2 City 3 City 4 City 5 City 6 City 7

Day 1 8 7, 5

Day 2 2 1, 5

Day 3 7 8

Day 4 2 5 1

Day 5 8 1

Day 6 5, 4

Day 7 4 1, 3

The pair involving teams 5 and 7 must take value 5, fixes

variable

(75)

Outline

1 Problem

2 Model

3 Program

4 Search

5 Redundant Modelling

(76)

Problem Data

hint(1,8,[2-[8],5-[5,7],8-[2],9-[1,5],15-[7],

17-[8],26-[2],27-[5],28-[1],29-[8],

34-[1],39-[4,5],43-[4],47-[1,3]]).

(77)

Main Program

top(Problem,L):-

hint(Problem,N,Hints), N1 is N-1,

N2 is N//2,

NrVars is N*N1//2, SizeDomain is N1*N1, length(L,NrVars), L :: 1..SizeDomain,

create_pairs(N,Contains,Names),

ic_global_gac:alldifferent(L),

process_hints(L,Contains,Hints),

...

(78)

Main Program (continued)

project_row_cols(L,N1,Rows,Cols), limit(Rows,N2,N1),

limit(Cols,N2,N1),

separate(Contains,Rows,N,SplitRows), separate(Contains,Cols,N,SplitCols), (foreach(K,SplitRows) do

ic_global_gac:alldifferent(K) ),

(foreach(K,SplitCols) do

ic_global_gac:alldifferent(K) ),

search(L,0,input_order,indomain,

(79)

Create Pairs and Names

create_pairs(N,Contains,Names):- (for(I,1,N-1),

fromto(Names,A1,A,[]), fromto(Contains,B1,B,[]), param(N) do

(for(J,I+1,N),

fromto(A1,[Name|AA],AA,A), fromto(B1,[I-J|BB],BB,B), param(I) do

concat_string([I,J],Name)

)

(80)

Projecting Rows and Columns

project_row_cols(L,N,Rows,Cols):-

generate_tables(N,RowTable,ColTable), (foreach(X,L),

foreach(R,Rows), foreach(C,Cols),

param(RowTable,ColTable) do

element(X,RowTable,R),

element(X,ColTable,C)

).

(81)

Generating Projection Tables

generate_tables(N,RowTable,ColTable):- (for(I,1,N),

fromto(RowTable,A1,A,[]), fromto(ColTable,B1,B,[]), param(N) do

(for(J,1,N),

fromto(A1,[I|AA],AA,A), fromto(B1,[J|BB],BB,B), param(I) do

true

)

(82)

Extract row variables

separate(Contains,Rows,Values,SplitRows):- (for(Value,1,Values),

foreach(SplitRow,SplitRows), param(Contains,Rows) do

(foreach(A-B,Contains),foreach(V,Rows), fromto([],R,R1,SplitRow),param(Value) do

(memberchk(Value,[A,B]) ->

R1 = [V|R]

;

R1 = R )

)

(83)

Set up gcc constraint

limit(L,Bound,Values):- (for(I,1,Values),

foreach(gcc(Bound,Bound,I),Pattern), param(Bound) do

true ),

gcc(Pattern,L).

(84)

Setting up hints

process_hints(L,Contains,Hints):- (foreach(Pos-Values,Hints),

param(L,Contains) do

process_hint(Pos,Values,L,Contains) ).

process_hint(Pos,[A,B],L,Contains):- % clause 1

!,

match_hint(A-B,Contains,L,X),

X #= Pos.

(85)

Setting up hints

process_hint(Pos,[Value],L,Contains):- % clause 2 (foreach(X,L),

foreach(A-B,Contains), fromto([],R,R1,Required), param(Pos,Value) do

(not_mentioned(A,B,Value) ->

X #\= Pos, R1 = R

;

R1 = [X|R]

)

),

(86)

Setting up hints

not_mentioned(A,B,V):- A \= V,

B \= V.

match_hint(H,[H|_],[X|_],X):-

!.

match_hint(H,[_|T],[_|R],X):-

match_hint(H,T,R,X).

(87)

Outline

1 Problem

2 Model

3 Program

4 Search

Using input order

First Fail Strategy

(88)

Before Search

(89)

Input Order

(90)

Input Order

12

1

(91)

Input Order

12

1 3

(92)

Input Order

12

1

14

20

3

(93)

Input Order

12

1

14

20 21

3

(94)

Input Order

12

1

14

20 21 22

3

(95)

Input Order

12

1

14

20 21 22 28

3

(96)

Input Order

12

1

14

20 21 22

16

18

28

3

(97)

Input Order

12

1

14

20 21 22

16 17

34

18

28

3

(98)

Input Order

12

1

14

20 21 22

16 17

34 36

18

28

3

(99)

Input Order

12

1

14

20 21 22

16 17

34 36 41

18

28

3

(100)

Input Order

12

1

14

20 21 22

16

1 3

18 20

28

3

(101)

Input Order

12

1

14

20 21 22

16

1 3

18 20 32 28

3

(102)

Input Order

12

1

14

20 21 22

16

1 3

18 20 32 34 28

3

(103)

Input Order

12

1

14

20 21 22

16

1 3

18 20 32

17

15 34 28

3

(104)

Input Order

12

1

14

20 21 22

16

1 3

18 20 32

17

15 18 34 28

3

(105)

Input Order

12

1

14

20 21 22

16

1 3

18 20 32

17

15 18 36 34 28

3

(106)

Input Order

12

1

14

20 21 22

16

1 3

18 20 32

1 3

34 36 28

3

(107)

Input Order

12

1

14

20 21 22

16

1 3

18 20 32

1 3

34

17

18 36 28

3

(108)

Input Order

12

1

14

20 21 22

16

1 3

18 20 32

1 3

34

17

18 20 36 28

3

(109)

Input Order

12

1

14

20 21 22

16

1 3

18 20 32

1 3

34

17

18 20 32 36 28

3

(110)

Input Order

12

1

14

20 21 22

16

1 3

18 20 32

1 3

34

17

18 20 32 34 36

28 3

(111)

Input Order

12

1

14

20 21 22

16

1 3

18 20 32

1 3

34

1 4

36 41 28

3

(112)

Input Order

12

1

14

20 21 22

4 13

28 34

3

(113)

Input Order

12

1

14

20 21 22

4 13

28

16

18

34

3

(114)

Input Order

12

1

14

20 21 22

4 13

28

16 17

22

18

34

3

(115)

Input Order

12

1

14

20 21 22

4 13

28

16 17

22 28

18

34

3

(116)

Input Order

12

1

14

20 21 22

4 13

28

16 17

22 28 36 18 34 3

(117)

Input Order

12

1

14

20 21 22

4 13

28

16 17

22 28 36 42 18 34 3

(118)

Input Order

12

1

14

20 21 22

4 13

28

16

1 4

18 21

34

3

(119)

Input Order

12

1

14

20 21 22

4 13

28

16

1 4

18 21 22 34

3

(120)

Input Order

12

1

14

20 21 22

4 13

28

16

1 4

18 21 22 25 34

3

(121)

Input Order

12

1

14

20 21 22

4 13

28

16

1 4

18 21 22 25 28 34

3

(122)

Input Order

12

1

14

20 21 22

4 13

28

16

1 4

18 21 22 25

17

15 28 34

3

(123)

Input Order

12

1

14

20 21 22

4 13

28

16

1 4

18 21 22 25

17

15 18 28 34

3

(124)

Input Order

12

1

14

20 21 22

4 13

28

16

1 4

18 21 22 25

17

15 18 36 28 34

3

(125)

Input Order

12

1

14

20 21 22

4 13

28

16

1 4

18 21 22 25

1 3

28 36 34

3

(126)

Input Order

12

1

14

20 21 22

4 13

28

16

1 4

18 21 22 25

1 3

28

17

18 36 34

3

(127)

Input Order

12

1

14

20 21 22

4 13

28

16

1 4

18 21 22 25

1 3

28

17

18 21 36 34

3

(128)

Input Order

12 1

14 20 21 22

4 13

28 16

1 4

18 21 22 25

1 3

28 17 18 21 25 36 34

3

(129)

Input Order

12

1

14

20 21 22

4 13 28

16

1 4

18 21 22 25

1 3 28

17

18 21 25 28 36

34 3

(130)

Input Order

12

1

14

20 21 22

4 13

28

16

1 4

18 21 22 25

1 3

28

1 4

36 42 34

3

(131)

Input Order

12

1

14

20 21 22

4 13

28

4 15

34 35 3

(132)

Input Order

12

1

9 32

3 4

(133)

Input Order

12

1

9 32

3

14

20

4

(134)

Input Order

12

1

9 32

3

14

20 21

4

(135)

Input Order

12

1

9 32

3

14

20 21 22

4

(136)

Input Order

12

1

9 32

3

14

20 21 22 24

4

(137)

Input Order

12

1

9 32

3

14

20 21 22 24 28

4

(138)

Input Order

12

1

9 32

3

14

20 21 22 24

16

20

28

4

(139)

Input Order

12

1

9 32

3

14

20 21 22 24

16

20 31

28

4

(140)

Input Order

12

1

9 32

3

14

20 21 22 24

16

20 31 34 28

4

(141)

Input Order

12

1

9 32

3

14

20 21 22 24

16

20 31

17

15 34 28

4

(142)

Input Order

12

1

9 32

3

14

20 21 22 24

16

20 31

17

15 36 34 28

4

(143)

Input Order

12

1

9 32

3

14

20 21 22 24

16

20 31

17

15 36 38 34 28 4

(144)

Input Order

12

1

9 32

3

14

20 21 22 24

16

20 31

1 3

34 36 28

4

(145)

Input Order

12

1

9 32

3

14

20 21 22 24

16

20 31

1 3

34

17

20 36 28

4

(146)

Input Order

12

1

9 32

3

14

20 21 22 24

16

20 31

1 3

34

17

20 31 36 28

4

(147)

Input Order

12

1

9 32

3

14

20 21 22 24

16

20 31

1 3

34

17

20 31 34 36 28

4

(148)

Input Order

12

1

9 32

3

14

20 21 22 24

16

20 31

1 3

34

17

20 31

23

8 34 36 28

4

(149)

Input Order

12

1

9 32

3

14

20 21 22 24

16

20 31

1 3

34

17

20 31

23

8 10 34 36 28 4

(150)

Input Order

12 1

9 32

3 14 20 21 22 24

16 20 31

1 3

34 17 20 31

23 8 10 13 34 36 28 4

(151)

Input Order

12

1

9 32

3

14

20 21 22 24

16

20 31

1 3

34

17

20 31

23

8 10 13 14 34 36 28 4

(152)

Input Order

12 1

9 32

3 14 20 21 22 24

16 20 31

1 3

34 17 20 31

23 8 10 13 14 16

34 36 28 4

(153)

Input Order

12

1

9 32

3

14

20 21 22 24

16

20 31

1 3

34

17

20 31

23

8 10 13 14 16 20 34 36 28 4

(154)

Input Order

12 1

9 32

3 14 20 21 22 24

16 20 31

1 3

34 17 20 31

23 8 10 13 14 16 20 21

34 36 28 4

(155)

Input Order

12 1

9 32

3 14 20 21 22 24

16 20 31

1 3

34 17 20 31

23 8 10 13 14 16 20 21 22

34 36 28 4

(156)

Input Order

12 1

9 32

3 14 20 21 22 24

16 20 31

1 3

34 17 20 31

23 8 10 13 14 16 20 21 22 23

34 36 28 4

(157)

Input Order

12 1

9 32

3 14 20 21 22 24

16 20 31

1 3

34 17 20 31

23 8 10 13 14 16 20 21 22 23 24

34 36 28 4

(158)

Input Order

12 1

9 32

3 14 20 21 22 24

16 20 31

1 3

34 17 20 31

23

8 10 13 14 16 20 21 22 23 24 30 34

36 28 4

(159)

Input Order

12 1

9 32

3 14 20 21 22 24

16 20 31

1 3

34 17 20 31

23 8 10 13 14 16 20 21 22 23 24

24 8 30 34

36 28 4

(160)

Input Order

12 1

9 32

3 14 20 21 22 24

16 20 31

1 3

34 17 20 31

23 8 10 13 14 16 20 21 22 23 24

24 8 10 30 34

36 28 4

(161)

Input Order

12 1

9 32

3 14 20 21 22 24

16 20 31 1 3

34 17 20 31

23 8 10 13 14 16 20 21 22 23 24

24 8 10 12 30

34 36 28 4

(162)

Input Order

12 1

9 32

3 14 20 21 22 24

16 20 31 1 3

34 17 20 31

23 8 10 13 14 16 20 21 22 23 24

24 8 10 12 13 30

34 36 28 4

(163)

Input Order

12 1

9 32

3 14 20 21 22 24

16 20 31 1 3

34 17 20 31

23 8 10 13 14 16 20 21 22 23 24

24 8 10 12 13 19 30

34 36 28 4

(164)

Input Order

12 1

9 32

3 14 20 21 22 24

16 20 31

1 3

34 17 20 31

23 8 10 13 14 16 20 21 22 23 24

24 8 10 12 13 19 20 30

34 36 28 4

Références

Documents relatifs

Stand allocation Air traffic control Frequency allocation Network configuration Product design Production step planning.. Introduction Success Stories for Constraint

Problem: Slows down search without any upside Constraint is woken every time any domain is changed How often does the constraint do actual pruning?.. Generalize Program for

Hard to find strategy which works all the time search builtin, flexible search abstraction. Different way of improving stability of

The objective is to find a combined routing and wavelength assignment which minimizes the number of wavelengths used for a given set of demands....

All guest boats assigned to a host in a time period fit within spare capacity of host boat.. Problem

A Costas array (named after John P. Costas) can be regarded geometrically as a set of N points lying on the squares of a NxN checkerboard, such that each row or column contains only

Large scale applications can be built with ECLiPSe Software engineering is not that different for Prolog Many tasks are similar regardless of solver used. Correctness of program

//creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. Helmut Simonis