Constraint Programming Chapter Overview Chapter Details Chapter 1: Introduction Helmut Simonis Cork Constraint Computation Centre Computer Science Department University College Cork Ireland ECLiPSe ELearning Overview Helmut Simonis Introduction 1 Constraint Programming Chapter Overview Chapter Details 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. Helmut Simonis Introduction 2
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Constraint ProgrammingChapter Overview
Chapter Details
Chapter 1: Introduction
Helmut Simonis
Cork Constraint Computation CentreComputer Science Department
University College CorkIreland
ECLiPSe ELearning Overview
Helmut Simonis Introduction 1
Constraint ProgrammingChapter Overview
Chapter Details
Licence
This work is licensed under the Creative CommonsAttribution-Noncommercial-Share Alike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ orsend a letter to Creative Commons, 171 Second Street, Suite300, San Francisco, California, 94105, USA.
Constraint ProgrammingUsing ECLiPSe LanguageWith Saros Eclipse IDE
Helmut Simonis Introduction 4
Constraint ProgrammingChapter Overview
Chapter Details
Constraint Programming (CP)
Solve hard combinatorial problemsWith minimal programming effortExploit strategies and heuristicsUnderstand and control problem solving
Helmut Simonis Introduction 5
Constraint ProgrammingChapter Overview
Chapter Details
ECLiPSe Language
Open source constraint programming languageFlexible toolkit to develop/use constraintsContains different constraint solversHere: Use of finite domains/(mixed) integer programming
Helmut Simonis Introduction 6
Constraint ProgrammingChapter Overview
Chapter Details
Aims and Outcomes
Understand what constraint programming isHow constraint programs can be applied to a problemWhich application problems are good candidates for CPHow to write/run/analyze simple ECLiPSe programs
Helmut Simonis Introduction 7
Constraint ProgrammingChapter Overview
Chapter Details
You should already know about...
No hard requirementsBasic understanding of programming assumedUseful to have some background in one of:
Balanced Incomplete Block DesignsPlanning Experiments and Testing FeaturesProblems with highly symmetrical structureSymmetry Breaking with lex constraints
Video iPhone Slides Handout
Helmut Simonis Introduction 19
Constraint ProgrammingChapter Overview
Chapter Details
Choosing the Model - Sports Scheduling
Complex sports scheduling problemHow to decide which model to useImproving reasoning by channeling
Video iPhone Slides Handout
Helmut Simonis Introduction 20
Constraint ProgrammingChapter Overview
Chapter Details
Customizing Search - Progressive Party
Scheduling Meetings between TeamsTeams only meet onceCapacity LimitsBuild customized search routines tailored to problemProblem decomposition: decide which problem to solve
Video iPhone Slides Handout
Helmut Simonis Introduction 21
Constraint ProgrammingChapter Overview
Chapter Details
Limits of Propagation - Costas Array
Antenna/Sonar DesignHard Benchmark ProblemNaive Enumeration works bestWhen clever reasoning doesn’t pay offCautionary Tale
Video iPhone Slides Handout
Helmut Simonis Introduction 22
Constraint ProgrammingChapter Overview
Chapter Details
Systematic Development
Developing ProgramsTestingProfilingDocumentation
Video iPhone Slides Handout
Helmut Simonis Introduction 23
Constraint ProgrammingChapter Overview
Chapter Details
Visualization Techniques
How to visualize constraint programsVariable VisualizersUnderstanding Search TreesConstraint VisualizersComplex Visualizations
Video iPhone Slides Handout
Helmut Simonis Introduction 24
Constraint ProgrammingChapter Overview
Chapter Details
Finite Set and Continuous Variables - SONET DesignProblem
Finite set variablesContinuous domainsOptimization from belowAdvanced symmetry breakingSONET design problem without inter-ring traffic
Video iPhone Slides Handout
Helmut Simonis Introduction 25
Constraint ProgrammingChapter Overview
Chapter Details
Network Applications
Overview of Network ApplicationsTraffic PlacementCapacity ManagementNetwork DesignUsing Advanced Techniques
Video iPhone Slides Handout
Helmut Simonis Introduction 26
Constraint ProgrammingChapter Overview
Chapter Details
More Global Constraints - Car Sequencing
New global constraints: gcc and sequence
Choosing a better search strategy
Video iPhone Slides Handout
Helmut Simonis Introduction 27
Constraint ProgrammingChapter Overview
Chapter Details
Adding Material
How to add new chaptersCopying template filesConfiguring templatesAdding frames to bodyIntegrating with other chapters
Video iPhone Slides Handout
Helmut Simonis Introduction 28
Constraint ProgrammingChapter Overview
Chapter Details
To continue
Branch from here to all materialsChoose presentation form which suits you
Helmut Simonis Introduction 29
Chapter 2: First Steps
Helmut Simonis
Cork Constraint Computation CentreComputer Science Department
University College CorkIreland
ECLiPSe ELearning Overview
Helmut Simonis First Steps 1
Licence
This work is licensed under the Creative CommonsAttribution-Noncommercial-Share Alike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ orsend a letter to Creative Commons, 171 Second Street, Suite300, San Francisco, California, 94105, USA.
How to install ECLiPSeInstalling SarosWriting a first programRunning the programWhere to find information
Helmut Simonis First Steps 4
IntroductionSuccess Stories for Constraint Programming
Conclusions
Chapter 3: Application Overview
Helmut Simonis
Cork Constraint Computation CentreComputer Science Department
University College CorkIreland
ECLiPSe ELearning Overview
Helmut Simonis Application Overview 1
IntroductionSuccess Stories for Constraint Programming
Conclusions
Licence
This work is licensed under the Creative CommonsAttribution-Noncommercial-Share Alike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ orsend a letter to Creative Commons, 171 Second Street, Suite300, San Francisco, California, 94105, USA.
IntroductionSuccess Stories for Constraint Programming
Conclusions
Outline
1 Introduction
2 Success Stories for Constraint Programming
3 Conclusions
Helmut Simonis Application Overview 3
IntroductionSuccess Stories for Constraint Programming
Conclusions
What is the common element amongst
The production of Mirage 2000 fighter aircraftThe personnel planning for the guards in all French jailsThe production of Belgian chocolatesThe selection of the music programme of a pop musicradio stationThe design of advanced signal processing chipsThe print engine controller in Xerox copiers
They all use constraint programming!
Helmut Simonis Application Overview 4
IntroductionSuccess Stories for Constraint Programming
Conclusions
Constraint Programming - in a nutshell
Declarative description of problems withVariables which range over (finite) sets of valuesConstraints over subsets of variables which restrict possiblevalue combinationsA solution is a value assignment which satisfies allconstraints
Constraint propagation/reasoningRemoving inconsistent values for variablesDetect failure if constraint can not be satisfiedInteraction of constraints via shared variablesIncomplete
SearchUser controlled assignment of values to variablesEach step triggers constraint propagation
Different domains require/allow different methods
Helmut Simonis Application Overview 5
IntroductionSuccess Stories for Constraint Programming
Conclusions
Constraint Satisfaction Problems (CSP)
Different problems with common aspectsPlanningSchedulingResource allocationAssignmentPlacementLogisticsFinancial decision makingVLSI design
Helmut Simonis Application Overview 6
IntroductionSuccess Stories for Constraint Programming
Conclusions
Characteristics of these problems
There are no general methods or algorithmsNP-completenessDifferent strategies and heuristics have to be tested.
Requirements are quickly changing:Programs should be flexible enough to adapt to thesechanges rapidly.
Decision support requiredCo-operate with userFriendly interfaces
Helmut Simonis Application Overview 7
IntroductionSuccess Stories for Constraint Programming
Conclusions
Benefits of CLP approach
Short development timeFast prototypingRefining of modellingSame tool used for prototyping/production
Compact code sizeEase of understandingMaintenance
Simple modificationChanging requirementsNo need to understand all aspects of problem
Good performanceFast answerGood resultsOptimal solutions rarely required
Helmut Simonis Application Overview 8
IntroductionSuccess Stories for Constraint Programming
Traffic Engineering in MPLSFind routes for demands satisfying bandwidth limitsPath placement algorithm developed for Cisco by PTL andIC-Parc (2002-2004)Internal, competitive selection of approachesStrong emphasis on stabilityWritten in ECLiPSePTL bought by Cisco in 2004Part of team moved to Boston
Helmut Simonis Application Overview 16
IntroductionSuccess Stories for Constraint Programming
Animal feed productionFeed in different sizes/For different speciesHuman health risk
ContaminationBSE
Strict regulationsConstraints
Avoid contamination risksMachine setup timesMachine choice (quality/speed)Limited storage of finished productsVery short lead times (8-48 hours)Factory structure given as data
StatusOperational since Nov 96Installed in 5 millsHelmut Simonis Application Overview 21
IntroductionSuccess Stories for Constraint Programming
Based on the Retimer project for BAConsider fleet of aircraftShifting some flights by small amount may allow better useof fleetMany constraints of different types limit the changes thatare possible
Helmut Simonis Application Overview 23
IntroductionSuccess Stories for Constraint Programming
Large scale distribution problemDeliver fresh products to supermarketsDirect deliveries/warehousingCombining deliveriesCapacity constraintsTour planningWorkforce constraints
Helmut Simonis Application Overview 24
IntroductionSuccess Stories for Constraint Programming
IntroductionSuccess Stories for Constraint Programming
Conclusions
Good approach for specialized, complex problems
3D camera control in movie animationFinding instable control states for robotsOptimized register allocation in gcc
Helmut Simonis Application Overview 31
IntroductionSuccess Stories for Constraint Programming
Conclusions
Key advantages
Easy to prototype/developUsing modelling to understand problemExpressive powerAdd/remove constraints as problem evolvesCustomized search exploiting structure and knowledge
Cork Constraint Computation CentreComputer Science Department
University College CorkIreland
ECLiPSe ELearning Overview
Helmut Simonis Basic Constraint Reasoning 1
ProblemProgram
Constraint SetupSearch
Lessons Learned
Licence
This work is licensed under the Creative CommonsAttribution-Noncommercial-Share Alike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ orsend a letter to Creative Commons, 171 Second Street, Suite300, San Francisco, California, 94105, USA.
Finite Domain Solver in ECLiPSeModels and ProgramsConstraint Propagation and SearchBasic constraints: linear arithmetic, alldifferent, disequalityBuilt-in search: LabelingVisualizers for variables, constraints and search
Helmut Simonis Basic Constraint Reasoning 4
ProblemProgram
Constraint SetupSearch
Lessons Learned
Problem Definition
A Crypt-Arithmetic PuzzleWe begin with the definition of the SEND+MORE=MONEYpuzzle. It is often shown in the form of a hand-written addition:
S E N D+ M O R EM O N E Y
Helmut Simonis Basic Constraint Reasoning 5
ProblemProgram
Constraint SetupSearch
Lessons Learned
Rules
S E N D+ M O R EM O N E Y
Each character stands for a digit from 0 to 9.Numbers are built from digits in the usual, positionalnotation.Repeated occurrence of the same character denote thesame digit.Different characters denote different digits.Numbers do not start with a zero.The equation must hold.
Helmut Simonis Basic Constraint Reasoning 6
ProblemProgram
Constraint SetupSearch
Lessons Learned
Model
Each character is a variable, which ranges over the values0 to 9.An alldifferent constraint between all variables, whichstates that two different variables must have differentvalues. This is a very common constraint, which we willencounter in many other problems later on.Two disequality constraints (variable X must be differentfrom value V ) stating that the variables at the beginning ofa number can not take the value 0.An arithmetic equality constraint linking all variables withthe proper coefficients and stating that the equation musthold.
Built-in of ic libraryNo initial propagation possibleSuspends, waits until variables are changedWhen variable is fixed, remove value from domain of othervariablesForward checking
Try variable is order givenTry values starting from smallest value in domainWhen failing, backtrack to last open choiceChronological BacktrackingDepth First search
Finite Domain Solver in ECLiPSe, ic libraryModels and ProgramsConstraint Propagation and SearchBasic constraints: linear arithmetic, alldifferent,disequalityBuilt-in search: labelingVisualizers for variables, constraints and search
Helmut Simonis Basic Constraint Reasoning 53
ProblemProgram
Constraint SetupSearch
Lessons Learned
Lessons Learned
Constraint models are expressed by variables andconstraints.Problems can have many different models, which canbehave quite differently. Choosing the best model is an art.Constraints can take many different forms.Propagation deals with the interaction of variables andconstraints.It removes some values that are inconsistent with aconstraint from the domain of a variable.Constraints only communicate via shared variables.
Helmut Simonis Basic Constraint Reasoning 54
ProblemProgram
Constraint SetupSearch
Lessons Learned
Lessons Learned
Propagation usually is not sufficient, search may berequired to find a solution.Propagation is data driven, and can be quite complex evenfor small examples.The default search uses chronological depth-firstbacktracking, systematically exploring the complete searchspace.The search choices and propagation are interleaved, afterevery choice some more propagation may further reducethe problem.
Helmut Simonis Basic Constraint Reasoning 55
Alternative ModelsExercises
Model without DisequalityMultiple Equations
Alternative 1
Do we need the constraint “Numbers do not begin with azero”?This is not given explicitely in the problem statementRemove disequality constraints from programPrevious solution is still a solutionDoes it change propagation?Does it have more solutions?
Helmut Simonis Basic Constraint Reasoning 56
Alternative ModelsExercises
Model without DisequalityMultiple Equations
Program without Disequality
Listing 1: Alternative 1:−module ( a l t e r n a t i v e 1 ) .:−expor t ( sendmory / 1 ) .:− l i b ( i c ) .
sendmory ( L):−L = [S,E,N,D,M,O,R,Y ] ,L : : 0 . . 9 ,a l l d i f f e r e n t ( L ) ,1000*S + 100*E + 10*N + D +1000*M + 100*O + 10*R + E #=10000*M + 1000*O + 100*N + 10*E + Y,l a b e l i n g ( L ) .
Helmut Simonis Basic Constraint Reasoning 57
Alternative ModelsExercises
Model without DisequalityMultiple Equations
After Setup without Disequality
0 1 2 3 4 5 6 7 8 9SENDMORY
Helmut Simonis Basic Constraint Reasoning 58
Alternative ModelsExercises
Model without DisequalityMultiple Equations
Setup Comparison
original alternative 10 1 2 3 4 5 6 7 8 9
SENDMORY
0 1 2 3 4 5 6 7 8 9SENDMORY
Helmut Simonis Basic Constraint Reasoning 59
Alternative ModelsExercises
Model without DisequalityMultiple Equations
Search Tree: Many Solutions
11 2
2
3
4
5
6
7
83
4
5
1
6
5
6
7
86
4
5
1
7
2
8
9
2
3
4
5
6
7
87
4
1
9 3 4 8
5
6
7
84
3
1
7
2
6
3
4
5
6
7
87
4
1
2 3 4 6
5
6
7
86
3
1
7
9
8
5
24 6 8
2
3
4
5
6
7
88
4
1
2
5
6
7
87
4
1
9
5
6
3
4
5
6
7
86
5
4
1
7
8
3
2
3
49 5
5
6
7
87
5
6
1
3 8
5
6
7
85
9
6
1
7
2
3
4
5
6
7
87
5
6
1
9
3
3
4
5
6
7
87
5
6
1
2 9
5
6
7
82
9
6
1
5 7
3
8
4
2
3
4
5
6
7
87
9
8
1
4
2
5
3
4
5
6
7
85
2
8
1
7
9
3
4
5
6
7
84
9
8
1
2 9
5
6
7
87
9
8
1
4
5
6
7
8
2
8
1
7
5
3
3
42 9
5
6
7
87
9
8
1
5 3
5
6
7
83
2
8
1
7
4
6
29
3
4
5
6
7
86
2
7
1
9
5
3
4
5
6
7
84
2
7
1
9
5
3
4
5
6
7
86
2
7
1
9
3 4
8
2
3
4
5
6
7
89
8
1
2
6
4
3 4 6
7
Helmut Simonis Basic Constraint Reasoning 60
Alternative ModelsExercises
Model without DisequalityMultiple Equations
Note:
Not just a different model, solving a different problem!Often we can choose which problem we want to solve
Which constraints to includeWhat to ignore
In this case not acceptable
Choice of Model
Helmut Simonis Basic Constraint Reasoning 61
Alternative ModelsExercises
Model without DisequalityMultiple Equations
Alternative 2
S E N D+ M O R E
+C5 C4 C3 C2M O N E Y
Large equality difficult to understand by humansReplace with multiple, simpler equationsLinked by carry variables (0/1)Should produce same solutionsDoes it give same propagation?
Helmut Simonis Basic Constraint Reasoning 62
Alternative ModelsExercises
Model without DisequalityMultiple Equations
Carry Variables with Multiple Equations
S E N D+ M O R E
+C5 C4 C3 C2M O N E Y
:-module(alternative2),export(sendmory/1),lib(ic).sendmory(L):-é same as before
This is solving the original problemSearch tree slightly biggerCaused here by missing interaction of equationsAnd repeated variablesBut: Introducing auxiliary variables not always bad!
Choice of Model
Helmut Simonis Basic Constraint Reasoning 68
Alternative ModelsExercises
Exercises
1 Does the reasoning for the equality constraints that wehave presented remove all inconsistent values? Considerthe constraint Y=2*X.
2 Why is it important to remove multiple occurences of thesame variable from an equality constraint? Give anexample!
3 Solve the puzzle DONALD+GERALD=ROBERT. What isthe state of the variables before the search, after the initialconstraint propagation?
4 Solve the puzzle Y*WORRY = DOOOOD. What isdifferent?
5 (extra credit) How would you design a program that findsnew crypt-arithmetic puzzles? What makes a good puzzle?
A variable for each cell, ranging from 1 to 9A 9x9 matrix of variables describing the problemPreassigned integers for the given hintsalldifferent constraints for each row, column and 3x3 block
Argument: list of variablesMeaning: variables are pairwise differentReasoning: Forward Checking (FC)
When variable is assigned to value, remove the value fromall other variablesIf a variable has only one possible value, then it is assignedIf a variable has no possible values, then the constraint failsConstraint is checked whenever one of its variables isassignedEquivalent to decomposition into binary disequalityconstraints
The alldifferent constraint is missing propagationHow can we do more propagation?Do we know when we derive all possible information fromthe constraint?
Constraints only interact by changing domains of variables
Take each interval of possible values, say size NFind all K variables whose domain is completely containedin intervalIf K > N then the constraint is infeasibleIf K = N then no other variable can use that intervalRemove values from such variables if their bounds changeIf K < N do nothingRe-check whenever domain bounds change
DefinitionA constraint achieves bounds consistency, if for the lower andupper bound of every variable, it is possible to find values for allother variables between their lower and upper bounds whichsatisfy the constraint.
A Matching is subset of edges which do not coincide in anynodeNo matching can have more edges than number ofvariablesEvery solution corresponds to a maximal matching andvice versaIf a link does not belong to some maximal matching, then itcan be removed
Possible to compute all links which belong to somematching
Without enumerating all of them!
Enough to compute one maximal matchingRequires algorithm for strongly connected componentsExtra work required if more values than variablesAll links (values in domains) which are not supported canbe removedComplexity: O(n1.5d)
DefinitionA constraint achieves domain consistency, if for every variableand for every value in its domain, it is possible to find values inthe domains of all other variables which satisfy the constraint.
Also called generalized arc consistency (GAC)or hyper arc consistency
NO! This extracts all information from this one constraintWe could perhaps improve speed, but not propagationBut possible to use different modelOr model interaction of multiple constraints
ic_global library bounds consistent versionic_global_gac library domain consistent versionChoose which version to use by using module annotationChoice can be passed as parameter
This does not always happenSometimes, two methods produce same amount ofpropagationPossible to predict in certain special casesIn general, tradeoff between speed and propagationNot always fastest to remove inconsistent values earlyBut often required to find a solution at all
Search tree much smaller for bounds/domain consistencyDoes not always happen like thisSmaller tree = Less execution timeLess reasoning = Less execution timeProblem: Finding best balanceFor Sudoku: not good enough, should not require anysearch!
Complete Example: Domain Consistent AlldifferentGeneric Model
Exercises
No propagation in expanded exampleProblem shown as bipartite graphX
Y
Z
T
U
V
1
2
3
4
5
6
7Helmut Simonis Global Constraints
Complete Example: Domain Consistent AlldifferentGeneric Model
Exercises
No propagation in expanded exampleFind maximal matching (in blue)X
Y
Z
T
U
V
1
2
3
4
5
6
7Helmut Simonis Global Constraints
Complete Example: Domain Consistent AlldifferentGeneric Model
Exercises
No propagation in expanded exampleOrient graph (edges in matching fromvariables to values, all others fromvalues to variables), mark edges inmatching
X
Y
Z
T
U
V
1
2
3
4
5
6
7Helmut Simonis Global Constraints
Complete Example: Domain Consistent AlldifferentGeneric Model
Exercises
No propagation in expanded exampleFind strongly connected components(green and brown), mark their edges
X
Y
Z
T
U
V
1
2
3
4
5
6
7Helmut Simonis Global Constraints
Complete Example: Domain Consistent AlldifferentGeneric Model
Exercises
No propagation in expanded exampleFind unmatched value nodes (herenode 7, magenta)
X
Y
Z
T
U
V
1
2
3
4
5
6
7Helmut Simonis Global Constraints
Complete Example: Domain Consistent AlldifferentGeneric Model
Exercises
No propagation in expanded exampleFind alternating paths from suchnodes (in magenta), mark their edges
X
Y
Z
T
U
V
1
2
3
4
5
6
7Helmut Simonis Global Constraints
Complete Example: Domain Consistent AlldifferentGeneric Model
Exercises
No propagation in expanded exampleContinue with alternating pathsX
Y
Z
T
U
V
1
2
3
4
5
6
7Helmut Simonis Global Constraints
Complete Example: Domain Consistent AlldifferentGeneric Model
Exercises
No propagation in expanded exampleContinue with alternating paths, alledges marked, no propagation,constraint is domain consistent
X
Y
Z
T
U
V
1
2
3
4
5
6
7Helmut Simonis Global Constraints
Complete Example: Domain Consistent AlldifferentGeneric Model
Exercises
Observation
A lot of effort for no propagationProblem: Slows down search without any upsideConstraint is woken every time any domain is changedHow often does the constraint do actual pruning?
Helmut Simonis Global Constraints
Complete Example: Domain Consistent AlldifferentGeneric Model
Exercises
Generalize Program for different sizes
How to generalize program for different sizes(4,9,16,25,36...)Add parameter R (Order, number of blocks in arow/column)Size N is square of RRemove explicit integer bounds by expressionsUseful to do this change as rewriting of working program
Helmut Simonis Global Constraints
Complete Example: Domain Consistent AlldifferentGeneric Model
Exercises
Main Program
model(R,M,Matrix):-N is R*R,Matrix[1..N,1..N] :: 1..N,(for(I,1,N),param(N,M,Matrix) do
Complete Example: Domain Consistent AlldifferentGeneric Model
Exercises
Exercises
1
Helmut Simonis Global Constraints
ProblemProgram
Naive SearchImprovements
Chapter 6: Search Strategies (N-Queens)
Helmut Simonis
Cork Constraint Computation CentreComputer Science Department
University College CorkIreland
ECLiPSe ELearning Overview
Helmut Simonis Search Strategies 1
ProblemProgram
Naive SearchImprovements
Licence
This work is licensed under the Creative CommonsAttribution-Noncommercial-Share Alike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ orsend a letter to Creative Commons, 171 Second Street, Suite300, San Francisco, California, 94105, USA.
Importance of search strategy, constraints alone are notenoughDynamic variable ordering exploits information frompropagationVariable and value choiceHard to find strategy which works all the timesearch builtin, flexible search abstractionDifferent way of improving stability of search routine
Helmut Simonis Search Strategies 4
ProblemProgram
Naive SearchImprovements
Example Problem
N-Queens puzzleRather weak constraint propagationMany solutions, limited number of symmetriesEasy to scale problem size
Helmut Simonis Search Strategies 5
ProblemProgram
Naive SearchImprovements
Problem Definition
8-QueensPlace 8 queens on an 8× 8 chessboard so that no queenattacks another. A queen attacks all cells in horizontal, verticaland diagonal direction. Generalizes to boards of size N × N.
Solution for board size 8× 8
Helmut Simonis Search Strategies 6
ProblemProgram
Naive SearchImprovements
A Bit of History
This is a rather old puzzleDudeney (1917) cites Nauck (1850) as sourceCertain solutions for all sizes can be constructed, this isnot a hard problemLong history in AI and CP papersImportant: Haralick and Elliot (1980) describing the first-failprinciple
Cell based ModelA 0/1 variable for each cell to say if it is occupied or notConstraints on rows, columns and diagonals to enforceno-attackN2 variables, 6N − 2 constraints
Column (Row) based ModelA 1..N variable for each column, stating position of queen inthe columnBased on observation that each column must containexactly one queenN variables, N2/2 binary constraints
Even for small problem size, tree can become largeNot interested in all detailsIgnore all automatically fixed variablesFor more compact representation abstract failed sub-trees
Helmut Simonis Search Strategies 16
ProblemProgram
Naive SearchImprovements
Compact Representation
Number inside triangle: Number of choicesNumber under triangle: Number of failures1
2
1
2
1
3
45
2
3
6
7
3
4
6
4
4
4
6
3 5
6
7
8
Helmut Simonis Search Strategies 17
ProblemProgram
Naive SearchImprovements
Exploring other board sizes
How stable is the model?Try all sizes from 4 to 100Timeout of 100 seconds
Helmut Simonis Search Strategies 18
ProblemProgram
Naive SearchImprovements
Naive Stategy, Problem Sizes 4-100
0
5
10
15
20
25
0 5 10 15 20 25 30
Tim
e[s]
Problem Size
"naive/all.txt"
Helmut Simonis Search Strategies 19
ProblemProgram
Naive SearchImprovements
Observations
Time very reasonable up to size 20Sizes 20-30 times very variableNot just linked to problem sizeNo size greater than 30 solved within timeout
Helmut Simonis Search Strategies 20
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Possible Improvements
Better constraint reasoningRemodelling problem with 3 alldifferent constraintsGlobal reasoning as described beforeNot explored here
Better control of searchStatic vs. dynamic variable orderingBetter value choiceNot using complete depth-first chronological backtracking
Helmut Simonis Search Strategies 21
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Static vs. Dynamic Variable Ordering
Heuristic Static OrderingSort variables before search based on heuristicMost important decisionsSmallest initial domain
Dynamic variable orderingUse information from constraint propagationDifferent orders in different parts of search treeUse all information available
Helmut Simonis Search Strategies 22
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
First Fail strategy
Dynamic variable orderingAt each step, select variable with smallest domainIdea: If there is a solution, better chance of finding itIdea: If there is no solution, smaller number of alternativesNeeds tie-breaking method
Helmut Simonis Search Strategies 23
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Caveat
First fail in many constraint systems have slightly differenttie breakersHard to compare result across platformsBest to compare search trees, i.e. variable choices in allbranches of tree
Helmut Simonis Search Strategies 24
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
The search Predicate
Packaged search library in ic constraint solverProvides many different alternative search methodsJust select a combination of keywordsExtensible by user
Helmut Simonis Search Strategies 26
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
search Parameters
search(L,0,first_fail,indomain,complete,[])
1 List of variables (or terms, covered later)2 0 for list of variables3 Variable choice, e.g. first_fail, input_order4 Value choice, e.g. indomain5 Tree search method, e.g. complete6 Optional argument (or empty) list
Helmut Simonis Search Strategies 27
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Variable Choice
Determines the order in which variables are assignedinput_order assign variables in static order givenfirst_fail select variable with smallest domain firstmost_constrained like first_fail, tie break based onnumber of constraints in which variable occursOthers, including programmed selection
Helmut Simonis Search Strategies 28
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Value Choice
Determines the order in which values are tested forselected variablesindomain Start with smallest value, on backtracking trynext larger valueindomain_max Start with largest valueindomain_middle Start with value closest to middle ofdomainindomain_random Choose values in random order
Helmut Simonis Search Strategies 29
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Naive (Input Order) Strategy (Size 16)
1
2
3
4
5
123
456
1
177
844
2
169
837
3
198
464
45
455
84
44
172
474
46
6
7
2
7
1
7
18
7
6
13
46
8
4
8
1
91
1
4
2
11
112
128
47
7
49
46
41
3
4
6
9
4
Helmut Simonis Search Strategies 31
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
FirstFail Strategy (Size 16)
1
2
3
4
5
13
11
16
7
811 12
13
811 13
14
15
716
19
817 15
8
128
9
14
12
6
4
2
3
5
1
Helmut Simonis Search Strategies 32
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Comparing Solutions
Naive First Fail
Solutions are different!
Helmut Simonis Search Strategies 33
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
FirstFail, Problem Sizes 4-100
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
0 10 20 30 40 50 60 70 80 90
Tim
e[s]
Problem Size
"first_fail/all.txt"
Helmut Simonis Search Strategies 34
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Observations
This is much betterBut some sizes are much harderTimeout for sizes 88, 91, 93, 97, 98, 99
Helmut Simonis Search Strategies 35
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Can we do better?
Improved initial orderingQueens on edges of board are easier to assignDo hard assignment first, keep simple choices for laterBegin assignment in middle of board
Matching value choiceValues in the middle of board have higher impactAssign these early at top of search treeUse indomain_middle for this
Helmut Simonis Search Strategies 36
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Start from Middle (Size 16)
1
2
34
5
36
7
612
8
3513 4
15
354 1
5
11
37
94
335
32 5
16
13
35
335
13
1
11
17
6
3
7
8
19
Helmut Simonis Search Strategies 39
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Comparing Solutions
Naive First Fail Middle
Again, solutions are different!
Helmut Simonis Search Strategies 40
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Middle, Problem Sizes 4-100
0
5
10
15
20
25
30
35
0 10 20 30 40 50 60 70 80 90 100
Tim
e[s]
Problem Size
"middle/all.txt"
Helmut Simonis Search Strategies 41
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Observations
Not always better than first failFor size 16, trees are similar sizeTimeout only for size 94But still, one strategy does not work for all problem sizesThere are ways to resolve this!
Helmut Simonis Search Strategies 42
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Approach 1: Heuristic Portfolios
Try multiple strategies for the same problemWith multi-core CPUs, run them in parallelOnly one needs to be successful for each problem
Helmut Simonis Search Strategies 43
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Approach 2: Restart with Randomization
Only spend limited number of backtracks for a searchattemptWhen this limit is exceeded, restart at beginningRequires randomization to explore new search branchRandomize variable choice by random tie breakRandomize value choice by shuffling valuesNeeds strategy when to restart
Helmut Simonis Search Strategies 44
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Approach 3: Partial Search
Abandon depth-first, chronological backtrackingDon’t get locked into a failed sub-treeA wrong decision at a level is not detected, and we have toexplore the complete subtree below to undo that wrongchoiceExplore more of the search treeSpend time in promising parts of tree
Helmut Simonis Search Strategies 45
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Example: Credit Search
Explore top of tree completely, based on creditStart with fixed amount of creditEach node consumes one credit unitSplit remaining credit amongst childrenWhen credit runs out, start bounded backtrack searchEach branch can use only K backtracksIf this limit is exceeded, jump to unexplored top of tree
Helmut Simonis Search Strategies 46
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Credit, Search Tree Problem Size 94
12
13
45
11
46
67
47
64
82
92
84
98
68
94
87
99
83
89
95
96
65
91
39
3
33
31
57
8
52
32
37
81
2
53
85
28
25
54
34
55
21
51
59
58
9
7
6
35
26
78
76
97
4
6
38
5
36
8
88
1
24
2
71
56
5
29
23
22
31
2723 41
25
26
3
2721 41
1
2723 41
7
8
37 25
22
28
2222
31
2723 41
8
26
5 21
42
23
22
31 25
26
31 7
8 22
41
3
75
2242 46
23 47
1
75
2242 46
34 47
7
5
37
2242 46
25
21
29
3
23
75
2242 46
23
28
1
7
48
24
12
49
2
3
13
19
91
16
9
43
1
17
15
63
95
99
98
92
61
94
14
97
18
93
67
62
64
96
84
8
66
65
89
68
88
85
69
87
6
72
86
82
73
71
81
76
83
78
77
5
87
99
83
89
95
96
93
3
57
38
33
39
31
53
52
32
59
54
85
34
25
58
8
37
69
88
51
2
56
35
5
26
21
71
28
78
75
86
76
81
7
1
36
8
55
4
6
24
7
2
29
23
22
325 4
5
325 27
34 8
29
22
325 4
28
325 9
34
34 9
8
7
22
325 9
5
325 27
28 8
3
22
39 27
34
34 27
28
5
2
23
9
2229 28
27 4
7
228 5
29
23
6
24
47
1
44
46
19
94
41
15
95
99
1
14
97
17
66
9
92
12
61
98
91
18
64
63
62
93
96
89
84
68
8
67
65
85
69
73
88
6
86
71
72
87
82
81
76
83
78
5
77
75
94
87
99
6
35
3
26
33
29
28
2
37
21
44
89
39
65
88
17
83
57
8
36
34
56
61
31
32
58
55
7
5
4
2
9
97
38
25
1
86
6
24
51
3
5
8
85
23
81
22
52
59
54
27
727 41
7
75
7
78
76
71
53
66
49
93
95
41
4
48
42
69
19
15
18
16
1
63
149
62
43
9
96
911
8
34
7
9
38
39
3
23
2
26
25
6
3
44
27
2
28
21
45
4
35
48
22
12
5
41
4
47
11
29
42
49
15
24
9
46
16
43
13
99
94
1
98
17
18
14
61
96
19
97
67
63
91
95
8
66
62
92
88
93
65
68
69
64
81
89
84
86
6
85
87
73
83
71
78
82
72
76
5
75
77
54
59
7
79
58
74
56
55
57
52
53
51
Helmut Simonis Search Strategies 48
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Credit, Problem Sizes 4-100
0
0.05
0.1
0.15
0.2
0.25
0 20 40 60 80 100
Tim
e[s]
Problem Size
"credit/all.txt"
Helmut Simonis Search Strategies 49
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Credit, Problem Sizes 4-200
0
0.5
1
1.5
2
2.5
0 50 100 150 200
Tim
e[s]
Problem Size
"credit/all.txt"
Helmut Simonis Search Strategies 50
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Conclusions
Choice of search can have huge impact on performanceDynamic variable selection can lead to large reduction ofsearch spacesearch builtin provides useful abstraction of searchfunctionalityDepth-first chronologicial backtracking not always bestchoice
Helmut Simonis Search Strategies 51
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Outlook
Finite domain with good search reasonable for board sizesup to 1000Limitation is memory, not execution timeMemory requirement quadratic as domain changes mustbe trailedBetter results possible for repair based methodsN-Queens not a hard problem, so general conclusionshard to draw
Helmut Simonis Search Strategies 52
Exercises
Exercises
1 Write a program for the 0/1 model of the puzzle as described above. Explain theproblem with introducing a dynamic variable ordering for this model.
2 It is possible to express the problem with only three alldifferent constraints.Can you describe this model?
3 What is the impact of using a more powerful consistency method for thealldifferent constraint in our model? How do the search trees differ to oursolution? Does it pay off in execution time?
4 Describe precisely what the reorder predicate does. You may find it helpful torun the program with instantiated lists of varying length.
5 The credit search takes two parameters, the total amount of credit and the extranumber of backtracks allowed after the credit runs out. How does the programbehave if you change these parameters? Can you explain this behaviour?
Cork Constraint Computation CentreComputer Science Department
University College CorkIreland
ECLiPSe ELearning Overview
Helmut Simonis Optimization 1
ProblemProgram
Search
Licence
This work is licensed under the Creative CommonsAttribution-Noncommercial-Share Alike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ orsend a letter to Creative Commons, 171 Second Street, Suite300, San Francisco, California, 94105, USA.
OptimizationGraph algorithm libraryProblem decompositionRouting and Wavelength Assignment in Optical Networks
Helmut Simonis Optimization 4
ProblemProgram
Search
Problem 1: Find routingProblem 2: Assign Wavelengths
Problem Definition
Routing and Wavelength Assignment
In an optical network, traffic demands between nodes areassigned to a route through the network and a specificwavelength. The route (called lightpath) must be a simple pathfrom source to destination. Demands which are routed over thesame link must be allocated to different wavelengths, butwavelengths may be reused for demands which do not meet.The objective is to find a combined routing and wavelengthassignment which minimizes the number of wavelengths usedfor a given set of demands.
Helmut Simonis Optimization 5
ProblemProgram
Search
Problem 1: Find routingProblem 2: Assign Wavelengths
Example Network
A
B
C
D
E
F G
H J
Helmut Simonis Optimization 6
ProblemProgram
Search
Problem 1: Find routingProblem 2: Assign Wavelengths
Lightpath from A to C
A
B
C
D
E
F G
H J
Helmut Simonis Optimization 7
ProblemProgram
Search
Problem 1: Find routingProblem 2: Assign Wavelengths
Conflict between demands A to C and F to J: Usedifferent frequencies
A
B
C
D
E
F G
H J
Helmut Simonis Optimization 8
ProblemProgram
Search
Problem 1: Find routingProblem 2: Assign Wavelengths
Conflict between demands A to C and F to J: Usedifferent paths
A
B
C
D
E
F G
H J
Helmut Simonis Optimization 9
ProblemProgram
Search
Problem 1: Find routingProblem 2: Assign Wavelengths
Solution Approaches
Greedy heuristicOptimization algorithm for complete problemDecomposition into two problems
Find routingAssign wavelengths
Helmut Simonis Optimization 10
ProblemProgram
Search
Problem 1: Find routingProblem 2: Assign Wavelengths
Finding Routing
Find routing which does not assign too many demands onthe same linkLower bound for overall problemDo not use arbitrarily complex pathsStart with shortest paths
Helmut Simonis Optimization 11
ProblemProgram
Search
Problem 1: Find routingProblem 2: Assign Wavelengths
Proposed Solution
For each demand, use a shortest path between sourceand destinationShortest path = smallest number of links usedGood for overall network utilisationMay create bottlenecks on some links
Helmut Simonis Optimization 12
ProblemProgram
Search
Problem 1: Find routingProblem 2: Assign Wavelengths
How to Find Shortest Paths
Well studied, well understood problemMany different algorithms for particular cases
Positive/negative weightPath between pair of nodes/between node and all othernodes/between all nodesOne/all shortest paths or paths which are nearly shortestpaths
Don’t program this yourself!Library in ECLiPSe: lib(graph_algorithms)
Helmut Simonis Optimization 13
ProblemProgram
Search
Problem 1: Find routingProblem 2: Assign Wavelengths
Library graph_algorithms
Provides different algorithms about graphsBased on opaque Graph structure created from nodes andedgesmake_graph(NrNodes,Edges,Graph)
Edges are terms e(FromNode,ToNode,Weight)Directed graphs as default, undirected graphs representedby edges in both directions
Helmut Simonis Optimization 14
ProblemProgram
Search
Problem 1: Find routingProblem 2: Assign Wavelengths
Find path from node From to node To in graph Network
Second argument describes weight function-1: use number of hops
Result given length of path and edges as list
Helmut Simonis Optimization 15
ProblemProgram
Search
Problem 1: Find routingProblem 2: Assign Wavelengths
Problem 2: Assign Wavelength
Demands are routed on shortest pathsDemands routed over the same link must have differentfrequenciesMinimize maximal number of frequencies used
Helmut Simonis Optimization 16
ProblemProgram
Search
Problem 1: Find routingProblem 2: Assign Wavelengths
Model
Domain variable for every demandInitial domain large, e.g. number of demandsDisequality constraint between demands routed over samelinkAlternative: alldifferent constraints for all demandsover each linkFeasible solution: find assignment for variables
Helmut Simonis Optimization 17
ProblemProgram
Search
Problem 1: Find routingProblem 2: Assign Wavelengths
Optimization
We are not looking for only a feasible solutionWe want to optimize objectiveMinimize largest value used
Helmut Simonis Optimization 18
ProblemProgram
Search
Problem 1: Find routingProblem 2: Assign Wavelengths
problem(Name,NrDemands,Network,Demands):-network_topology(Name,NrNodes,Edges),make_graph(NrNodes,Edges,Directed),make_undirected_graph(Directed,Network),(for(I,1,NrDemands),fromto([],A,[demand(I,From,To)|A],Demands),param(NrNodes) do
repeat,From is 1+(random mod NrNodes),To is 1+(random mod NrNodes),From \= To,!
Optimal solution found with minimal backtrackingReaching lower bound avoids enumeration proof ofoptimalityNot guaranteed to be optimal for original problemGiven decomposition destroys flexibility in finding solution
Helmut Simonis Optimization 38
ProblemProgram
Search
Further Experiments
Vary number of demands to be handledMake 100 runs with randomized demands
These are not hard problem instancesIn general, graph coloring can be much more difficultFast, simple solution to RWA problemQuality gap to be determined
Cork Constraint Computation CentreComputer Science Department
University College CorkIreland
ECLiPSe ELearning Overview
Helmut Simonis Symmetry Breaking 1
ProblemProgram
Symmetry Breaking
Licence
This work is licensed under the Creative CommonsAttribution-Noncommercial-Share Alike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ orsend a letter to Creative Commons, 171 Second Street, Suite300, San Francisco, California, 94105, USA.
BIBD - Balanced Incomplete Block DesignsUsing lex constraints to remove symmetriesFinding all solutions to a problemUsing timeout to limit search
Helmut Simonis Symmetry Breaking 4
ProblemProgram
Symmetry Breaking
Problem Definition
BIBD (Balanced Incomplete Block Design)
A BIBD is defined as an arrangement of v distinct objects into bblocks such that each block contains exactly k distinct objects,each object occurs in exactly r different blocks, and every twodistinct objects occur together in exactly λ blocks. A BIBD istherefore specified by its parameters (v, b, r, k, λ).
Helmut Simonis Symmetry Breaking 5
ProblemProgram
Symmetry Breaking
Motivation: Test Planning
Consider a new release of some software with v new features.You want to regression test the software against combinationsof the new features. Testing each subset of features is tooexpensive, so you want to run b tests, each using k features.Each feature should be used r times in the tests. Each pair offeatures should be tested together exactly λ times. How do youarrange the tests?
Helmut Simonis Symmetry Breaking 6
ProblemProgram
Symmetry Breaking
Model
Another way of defining a BIBD is in terms of its incidencematrix, which is a binary matrix with v rows, b columns, r onesper row, k ones per column, and scalar product λ between anypair of distinct rows.
A (6,10,5,3,2) BIBD
Helmut Simonis Symmetry Breaking 7
ProblemProgram
Symmetry Breaking
Model
A binary v × b matrix. Entry Vij states if item i is in block j .Sum constraints over rows, each sum equal rSum constraints over columns, each sum equal kScalar product between any pair of rows, the product valueis λ.
).é Scalar product between all rowsHelmut Simonis Symmetry Breaking 10
ProblemProgram
Symmetry Breaking
scalar_product
scalar_product(XVector,YVector,V):-collection_to_list(XVector,XList),collection_to_list(YVector,YList),é Get lists(foreach(X,XList),é Iterate over listsforeach(Y,YList),é ...in parallelfromto(0,A,A1,Term) do é Build term
A1 = A+X*Yé Construct term),eval(Term) #= V.é State Constraint
Helmut Simonis Symmetry Breaking 11
ProblemProgram
Symmetry Breaking
Search Routine
Static variable orderFirst fail does not work for binary variablesEnumerate variables by rowUse utility predicate extract_array/3
Assign with indomain, try value 0, then value 1Use simple search call
Runs Goal for Limit secondsIf Limit is reached, Goal is stopped and TimeoutGoalis run insteadIf Limit is not reached, it has no impactMust load :-lib(timeout).
Helmut Simonis Symmetry Breaking 19
ProblemProgram
Symmetry Breaking
Search Tree 200 Nodes
1
2
3
4
5
11
12
13
12
13
0
14
8
9
0
15
5
6
0
16
17
18
21
22
12
13
0
23
24
6
7
0
25
5
6
0
26
32
330
34
350
360
37
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
1
0
360
37
43
450
490 1
1
0
45
490 1
0 1
1
0
43
450
490 1
1
0
45
490 1
0 1
1
1
1
1
1
0
33
34
350
360
39
42
440
470 1
1
0
44
470 1
0 1
1
0
42
440
470
1
0
1
1
1
0
0
1
0
1
1
0
1
0
0
0
0
1
1
1
0
0
0
0
0
0
0
Helmut Simonis Symmetry Breaking 20
ProblemProgram
Symmetry Breaking
Observation
Surprise! There are many solutions
Helmut Simonis Symmetry Breaking 21
ProblemProgram
Symmetry Breaking
Search Tree 300 Nodes
1
2
3
4
5
11
12
13
12
13
0
14
8
9
0
15
5
6
0
16
17
18
21
22
12
13
0
23
24
6
7
0
25
5
6
0
26
32
330
34
350
360
37
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
1
0
360
37
43
450
490 1
1
0
45
490 1
0 1
1
0
43
450
490 1
1
0
45
490 1
0 1
1
1
1
1
1
0
33
34
350
360
39
42
440
470 1
1
0
44
470 1
0 1
1
0
42
440
470 1
1
0
44
470 1
0 1
1
1
1
1
0
360
39
42
450
470 1
1
0
45
470 1
0 1
1
0
42
450
470 1
1
0
45
470 1
0 1
1
1
1
1
0
34
35
36
37
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
0
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
1
0
1
2
1
0 1
0 1
1
1
0
27
32
330
34
350
36
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
0
1
0
0
1
1
1
0
1
0
0
0
0
1
1
1
0
0
0
0
0
0
0
Helmut Simonis Symmetry Breaking 22
ProblemProgram
Symmetry Breaking
Search Tree 400 Nodes
1
2
3
4
5
11
12
13
12
13
0
14
8
9
0
15
5
6
0
16
17
18
21
22
12
13
0
23
24
6
7
0
25
5
6
0
26
32
330
34
350
360
37
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
1
0
360
37
43
450
490 1
1
0
45
490 1
0 1
1
0
43
450
490 1
1
0
45
490 1
0 1
1
1
1
1
1
0
33
34
350
360
39
42
440
470 1
1
0
44
470 1
0 1
1
0
42
440
470 1
1
0
44
470 1
0 1
1
1
1
1
0
360
39
42
450
470 1
1
0
45
470 1
0 1
1
0
42
450
470 1
1
0
45
470 1
0 1
1
1
1
1
0
34
35
36
37
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
0
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
1
0
1
2
1
0 1
0 1
1
1
0
27
32
330
34
350
36
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
0
36
43
450
490 1
1
0
45
490 1
0 1
1
0
43
450
490 1
1
0
45
490 1
0 1
1
1
1
1
0
33
34
350
370
39
42
440
460 1
1
0
44
460 1
0 1
1
0
42
440
460 1
1
0
44
460 1
0 1
1
1
1
1
0
370
39
42
450
460 1
1
0
45
460 1
0 1
1
0
42
450
460 1
1
0
45
460 1
0 1
1
1
1
1
0
34
35
36
37
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
0 1
0
37
390
0
1
0
0
1
1
0
1
1
1
0
1
0
0
0
0
1
1
1
0
0
0
0
0
0
0
Helmut Simonis Symmetry Breaking 23
ProblemProgram
Symmetry Breaking
Search Tree 500 Nodes
1
2
3
4
5
11
12
13
12
13
0
14
8
9
0
15
5
6
0
16
17
18
21
22
12
13
0
23
24
6
7
0
25
5
6
0
26
32
330
34
350
360
37
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
1
0
360
37
43
450
490 1
1
0
45
490 1
0 1
1
0
43
450
490 1
1
0
45
490 1
0 1
1
1
1
1
1
0
33
34
350
360
39
42
440
470 1
1
0
44
470 1
0 1
1
0
42
440
470 1
1
0
44
470 1
0 1
1
1
1
1
0
360
39
42
450
470 1
1
0
45
470 1
0 1
1
0
42
450
470 1
1
0
45
470 1
0 1
1
1
1
1
0
34
35
36
37
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
0
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
1
0
1
2
1
0 1
0 1
1
1
0
27
32
330
34
350
36
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
0
36
43
450
490 1
1
0
45
490 1
0 1
1
0
43
450
490 1
1
0
45
490 1
0 1
1
1
1
1
0
33
34
350
370
39
42
440
460 1
1
0
44
460 1
0 1
1
0
42
440
460 1
1
0
44
460 1
0 1
1
1
1
1
0
370
39
42
450
460 1
1
0
45
460 1
0 1
1
0
42
450
460 1
1
0
45
460 1
0 1
1
1
1
1
0
34
35
36
37
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
0 1
0
37
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
0 1
1
0 1
0 1
1
1
0
32
330
34
350
36
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
0
36
43
450
490 1
1
0
45
490 1
0 1
1
0
43
450
490 1
1
0
45
490 1
0 1
1
1
1
1
0
33
34
350
380
39
42
440
460 1
1
0
44
460 1
0 1
1
0
42
440
460 1
1
0
44
460 1
0 1
1
1
1
1
0
380 1
1
0
1
1
1
1
1
0
1
0
0
0
0
1
1
1
0
0
0
0
0
0
0
Helmut Simonis Symmetry Breaking 24
ProblemProgram
Symmetry Breaking
Search Tree 1000 Nodes
1
2
3
4
5
11
12
13
12
13
0
14
8
9
0
15
5
6
0
16
17
18
21
22
12
13
0
23
24
6
7
0
25
5
6
0
26
32
330
34
350
360
37
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
1
0
360
37
43
450
490 1
1
0
45
490 1
0 1
1
0
43
450
490 1
1
0
45
490 1
0 1
1
1
1
1
1
0
33
34
350
360
39
42
440
470 1
1
0
44
470 1
0 1
1
0
42
440
470 1
1
0
44
470 1
0 1
1
1
1
1
0
360
39
42
450
470 1
1
0
45
470 1
0 1
1
0
42
450
470 1
1
0
45
470 1
0 1
1
1
1
1
0
34
35
36
37
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
0
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
1
0
1
2
1
0 1
0 1
1
1
0
27
32
330
34
350
36
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
0
36
43
450
490 1
1
0
45
490 1
0 1
1
0
43
450
490 1
1
0
45
490 1
0 1
1
1
1
1
0
33
34
350
370
39
42
440
460 1
1
0
44
460 1
0 1
1
0
42
440
460 1
1
0
44
460 1
0 1
1
1
1
1
0
370
39
42
450
460 1
1
0
45
460 1
0 1
1
0
42
450
460 1
1
0
45
460 1
0 1
1
1
1
1
0
34
35
36
37
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
0 1
0
37
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
0 1
1
0 1
0 1
1
1
0
32
330
34
350
36
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
0
36
43
450
490 1
1
0
45
490 1
0 1
1
0
43
450
490 1
1
0
45
490 1
0 1
1
1
1
1
0
33
34
350
380
39
42
440
460 1
1
0
44
460 1
0 1
1
0
42
440
460 1
1
0
44
460 1
0 1
1
1
1
1
0
380
39
42
450
460 1
1
0
45
460 1
0 1
1
0
42
450
460 1
1
0
45
460 1
0 1
1
1
1
1
0
34
35
36
38
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
0 1
0
38
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
0 1
1
0 1
0 1
1
1
1
1
1
1
0
24
25
5
6
0
26
32
33
340
350
360
37
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
1
1
0
340
360
37
44
450
490 1
1
0
45
490 1
0 1
1
0
44
450
490 1
1
0
45
490 1
0 1
1
1
1
1
1
0
33
34
350
360
39
42
430
470 1
1
0
43
470 1
0 1
1
0
42
430
470 1
1
0
43
470 1
0 1
1
1
1
1
0
35
36
37
39
42
430 1
0
430 1
1
0
42
430 1
0
430 1
1
1
0
39
42
430 1
0
430 1
1
0
42
430 1
0
430 1
1
1
1
0
1
2
1
0 1
1
0
34
360
39
42
450
470 1
1
0
45
470 1
0 1
1
0
42
450
470 1
1
0
45
470 1
0 1
1
1
1
0 1
1
1
0
27
32
33
340
350
36
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
1
0
340
36
44
450
490 1
1
0
45
490 1
0 1
1
0
44
450
490 1
1
0
45
490 1
0 1
1
1
1
1
0
33
34
350
370
39
42
430
460 1
1
0
43
460 1
0 1
1
0
42
430
460 1
1
0
43
460 1
0 1
1
1
1
1
0
35
36
37
39
42
430 1
0
430 1
1
0
42
430 1
0
430 1
1
1
0 1
0
37
39
42
430 1
0
430 1
1
0
42
430 1
0
430 1
1
1
0 1
1
0 1
1
0
34
370
39
42
450
460 1
1
0
45
460 1
0 1
1
0
42
450
460 1
1
0
45
460 1
0 1
1
1
1
0 1
1
1
0
32
33
340
350
36
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
1
0
340
36
44
450
490 1
1
0
45
490 1
0 1
1
0
44
450
490 1
1
0
45
490 1
0 1
1
1
1
1
0
33
34
350
380
39
42
430
460 1
1
0
43
460 1
0 1
1
0
42
430
460 1
1
0
43
460 1
0 1
1
1
1
1
0
35
36
38
39
42
430 1
0
430 1
1
0
42
430 1
0
430 1
1
1
0 1
0
38
39
42
430 1
0
430 1
1
0
42
430 1
0
430 1
1
1
0 1
1
0 1
1
0
34
380
39
420
0
1
0
1
1
1
1
1
0
1
1
0
0
0
0
1
1
1
0
0
0
0
0
0
0
Helmut Simonis Symmetry Breaking 25
ProblemProgram
Symmetry Breaking
Search Tree 2000 Nodes
1
2
3
4
5
11
12
13
12
13
0
14
8
9
0
15
5
6
0
16
17
18
21
22
12
13
0
23
24
6
7
0
25
5
6
0
26
32
330
34
350
360
37
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
1
0
360
37
43
450
490 1
1
0
45
490 1
0 1
1
0
43
450
490 1
1
0
45
490 1
0 1
1
1
1
1
1
0
33
34
350
360
39
42
440
470 1
1
0
44
470 1
0 1
1
0
42
440
470 1
1
0
44
470 1
0 1
1
1
1
1
0
360
39
42
450
470 1
1
0
45
470 1
0 1
1
0
42
450
470 1
1
0
45
470 1
0 1
1
1
1
1
0
34
35
36
37
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
0
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
1
0
1
2
1
0 1
0 1
1
1
0
27
32
330
34
350
36
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
0
36
43
450
490 1
1
0
45
490 1
0 1
1
0
43
450
490 1
1
0
45
490 1
0 1
1
1
1
1
0
33
34
350
370
39
42
440
460 1
1
0
44
460 1
0 1
1
0
42
440
460 1
1
0
44
460 1
0 1
1
1
1
1
0
370
39
42
450
460 1
1
0
45
460 1
0 1
1
0
42
450
460 1
1
0
45
460 1
0 1
1
1
1
1
0
34
35
36
37
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
0 1
0
37
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
0 1
1
0 1
0 1
1
1
0
32
330
34
350
36
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
0
36
43
450
490 1
1
0
45
490 1
0 1
1
0
43
450
490 1
1
0
45
490 1
0 1
1
1
1
1
0
33
34
350
380
39
42
440
460 1
1
0
44
460 1
0 1
1
0
42
440
460 1
1
0
44
460 1
0 1
1
1
1
1
0
380
39
42
450
460 1
1
0
45
460 1
0 1
1
0
42
450
460 1
1
0
45
460 1
0 1
1
1
1
1
0
34
35
36
38
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
0 1
0
38
39
42
440 1
0
440 1
1
0
42
440 1
0
440 1
1
1
0 1
1
0 1
0 1
1
1
1
1
1
1
0
24
25
5
6
0
26
32
33
340
350
360
37
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
1
1
0
340
360
37
44
450
490 1
1
0
45
490 1
0 1
1
0
44
450
490 1
1
0
45
490 1
0 1
1
1
1
1
1
0
33
34
350
360
39
42
430
470 1
1
0
43
470 1
0 1
1
0
42
430
470 1
1
0
43
470 1
0 1
1
1
1
1
0
35
36
37
39
42
430 1
0
430 1
1
0
42
430 1
0
430 1
1
1
0
39
42
430 1
0
430 1
1
0
42
430 1
0
430 1
1
1
1
0
1
2
1
0 1
1
0
34
360
39
42
450
470 1
1
0
45
470 1
0 1
1
0
42
450
470 1
1
0
45
470 1
0 1
1
1
1
0 1
1
1
0
27
32
33
340
350
36
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
1
0
340
36
44
450
490 1
1
0
45
490 1
0 1
1
0
44
450
490 1
1
0
45
490 1
0 1
1
1
1
1
0
33
34
350
370
39
42
430
460 1
1
0
43
460 1
0 1
1
0
42
430
460 1
1
0
43
460 1
0 1
1
1
1
1
0
35
36
37
39
42
430 1
0
430 1
1
0
42
430 1
0
430 1
1
1
0 1
0
37
39
42
430 1
0
430 1
1
0
42
430 1
0
430 1
1
1
0 1
1
0 1
1
0
34
370
39
42
450
460 1
1
0
45
460 1
0 1
1
0
42
450
460 1
1
0
45
460 1
0 1
1
1
1
0 1
1
1
0
32
33
340
350
36
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
1
0
340
36
44
450
490 1
1
0
45
490 1
0 1
1
0
44
450
490 1
1
0
45
490 1
0 1
1
1
1
1
0
33
34
350
380
39
42
430
460 1
1
0
43
460 1
0 1
1
0
42
430
460 1
1
0
43
460 1
0 1
1
1
1
1
0
35
36
38
39
42
430 1
0
430 1
1
0
42
430 1
0
430 1
1
1
0 1
0
38
39
42
430 1
0
430 1
1
0
42
430 1
0
430 1
1
1
0 1
1
0 1
1
0
34
380
39
42
450
460 1
1
0
45
460 1
0 1
1
0
42
450
460 1
1
0
45
460 1
0 1
1
1
1
0 1
1
1
1
1
1
0
26
32
33
340
350
360
37
43
450
490 1
1
0
45
490 1
0 1
1
0
43
450
490 1
1
0
45
490 1
0 1
1
1
1
1
1
0
34
350
360
37
44
450
490 1
1
0
45
490 1
0 1
1
0
44
450
490 1
1
0
45
490 1
0 1
1
1
1
1
0 1
1
0
33
34
350
36
37
39
42
430 1
0
430 1
1
0
42
430 1
0
430 1
1
1
0
39
42
430 1
0
430 1
1
0
42
430 1
0
430 1
1
1
1
0
1
2
1
1
0
35
360
39
42
430
470 1
1
0
43
470 1
0 1
1
0
42
430
470 1
1
0
43
470 1
0 1
1
1
1
0 1
1
0
35
360
39
42
440
470 1
1
0
44
470 1
0 1
1
0
42
440
470 1
1
0
44
470 1
0 1
1
1
1
0 1
1
1
0
27
32
33
340
350
36
43
450
490 1
1
0
45
490 1
0 1
1
0
43
450
490 1
1
0
45
490 1
0 1
1
1
1
1
0
34
350
36
44
450
490 1
1
0
45
490 1
0 1
1
0
44
450
490 1
1
0
45
490 1
0 1
1
1
1
0 1
1
0
33
34
350
36
37
39
42
430 1
0
430 1
1
0
42
430 1
0
430 1
1
1
0 1
0
37
39
42
430 1
0
430 1
1
0
42
430 1
0
430 1
1
1
0 1
1
1
0
35
370
39
42
430
460 1
1
0
43
460 1
0 1
1
0
42
430
460 1
1
0
43
460 1
0 1
1
1
1
0 1
1
0
35
370
39
42
440
460 1
1
0
44
460 1
0 1
1
0
42
440
460 1
1
0
44
460 1
0 1
1
1
1
0 1
1
1
0
32
33
340
350
36
43
450
490 1
1
0
45
490 1
0 1
1
0
43
450
490 1
1
0
45
490 1
0 1
1
1
1
1
0
34
350
36
44
450
490 1
1
0
45
490 1
0 1
1
0
44
450
490 1
1
0
45
490 1
0 1
1
1
1
0 1
1
0
33
34
350
36
38
39
42
430 1
0
430 1
1
0
42
430 1
0
430 1
1
1
0 1
0
38
39
42
430 1
0
430 1
1
0
42
430 1
0
430 1
1
1
0 1
1
1
0
35
380
39
42
430
460 1
1
0
43
460 1
0 1
1
0
42
430
460 1
1
0
43
460 1
0 1
1
1
1
0 1
1
0
35
380
39
42
440
460 1
1
0
44
460 1
0 1
1
0
42
440
460 1
1
0
44
460 1
0 1
1
1
1
0 1
1
1
1
1
1
1
1
0
22
23
24
6
7
0
25
5
6
0
26
31
330
34
350
360
37
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
1
0
360
37
43
450
490 1
1
0
45
490 1
0 1
1
0
43
450
490 1
1
0
45
490 1
0 1
1
1
1
1
1
0
33
34
350
360
39
41
440
470 1
1
0
44
470 1
0 1
1
0
41
440
470 1
1
0
44
470 1
0 1
1
1
1
1
0
360
39
41
450
470 1
1
0
45
470 1
0 1
1
0
41
450
470 1
1
0
45
470 1
0 1
1
1
1
1
0
34
35
36
37
39
41
440 1
0
440 1
1
0
41
440 1
0
440 1
1
1
0
39
41
440 1
0
440 1
1
0
41
440 1
0
440 1
1
1
1
0
1
2
1
0 1
0 1
1
1
0
27
31
330
34
350
36
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
0
36
43
450
490 1
1
0
45
490 1
0 1
1
0
43
450
490 1
1
0
45
490 1
0 1
1
1
1
1
0
33
34
350
370
39
41
440
460 1
1
0
44
460 1
0 1
1
0
41
440
460 1
1
0
44
460 1
0 1
1
1
1
1
0
370
39
41
450
460 1
1
0
45
460 1
0 1
1
0
41
450
460 1
1
0
45
460 1
0 1
1
1
1
1
0
34
35
36
37
39
41
440 1
0
440 1
1
0
41
440 1
0
440 1
1
1
0 1
0
37
39
41
440 1
0
440 1
1
0
41
440 1
0
440 1
1
1
0 1
1
0 1
0 1
1
1
0
31
330
34
350
36
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
0
36
43
450
490 1
1
0
45
490 1
0 1
1
0
43
450
490 1
1
0
45
490 1
0 1
1
1
1
1
0
33
34
350
380
39
41
440
460 1
1
0
44
460 1
0 1
1
0
41
440
460 1
1
0
44
460 1
0 1
1
1
1
1
0
380
39
41
450
460 1
1
0
45
460 1
0 1
1
0
41
450
460 1
1
0
45
460 1
0 1
1
1
1
1
0
34
35
36
38
39
41
440 1
0
440 1
1
0
41
440 1
0
440 1
1
1
0 1
0
38
39
41
440 1
0
440 1
1
0
41
440 1
0
440 1
1
1
0 1
1
0 1
0 1
1
1
1
1
1
1
0
24
25
5
6
0
26
31
33
340
350
360
37
43
440
490 1
1
0
44
490 1
0 1
1
0
43
440
490 1
1
0
44
490 1
0 1
1
1
1
1
1
0
340
360
37
44
450
490 1
1
0 1
0
1
1
1
0
0
1
0
1
0
1
0
0
0
1
1
1
0
0
0
0
0
0
0
Helmut Simonis Symmetry Breaking 26
ProblemProgram
Symmetry Breaking
Problem
There are too many solutions to collect in a reasonabletimeMost of these solutions are very similarIf you take one solution and
exchange two rowsand/or exchange two columns
... you have another solutionCan we avoid exploring them all?
Helmut Simonis Symmetry Breaking 27
ProblemProgram
Symmetry BreakingExperiment with alternative value order
Symmetry Breaking Techniques
Remove all symmetriesReduce the search tree as much as possibleMay be hard to describe all symmetriesMay be expensive to remove symmetric parts of tree
Remove some symmetriesSearch is not reduced as muchMay be easier to find some symmetries to removeCost can be low
Helmut Simonis Symmetry Breaking 28
ProblemProgram
Symmetry BreakingExperiment with alternative value order
Symmetry Breaking Techniques
Symmetry removal by forcing partial, initial assignmentEasy to understandRather weak, does not affect search
Symmetry removal by stating constraintsRemoving all symmetries may require exponential numberof constraintsCan conflict with search strategies
Symmetry removal by controling searchAt each node, decide if it needs to be exploredCan be expensive to check
Helmut Simonis Symmetry Breaking 29
ProblemProgram
Symmetry BreakingExperiment with alternative value order
Solution used here: Double Lex
Partial symmetry removal by adding lexicographicalordering constraintsOur problem has full row and column symmetriesAny permutation of rows adn/or columns leads to anothersolutionIdea: Order rows lexicographicallyRows must be different from each other, strict order onrowsColumns might be identical, non strict order on columns
This can be improved in some cases
Constraints only between adjacent rows(columns)
Helmut Simonis Symmetry Breaking 30
ProblemProgram
Symmetry BreakingExperiment with alternative value order
Added Constraints
dim(Matrix,[V,B]),(for(I,1,V-1),param(Matrix,B) do
I1 is I+1,lex_less(Matrix[I1,1..B],Matrix[I,1..B])
),é Row lex constraints(for(J,1,B-1),param(Matrix,V) do
J1 is J+1,lex_leq(Matrix[1..V,J1],Matrix[1..V,J])
),é Column lex constraints
Helmut Simonis Symmetry Breaking 31
ProblemProgram
Symmetry BreakingExperiment with alternative value order
Two new global constraints
lex_leq(List1,List2)List1 is lexicographical smaller than or equal to List2Achieves domain consistency
lex_less(List1,List2)List1 is lexicographical smaller than List2Achieves domain consistency
Helmut Simonis Symmetry Breaking 32
ProblemProgram
Symmetry BreakingExperiment with alternative value order
Complete Search Tree with Double Lex
10
20
30
40
50
110
120
160
170
180
210
22
230
260
320
33
340
36
370
430
46
490 1
0 1
1
1
0 1
1
0
36
370 1
0 1
1
1
1
1
0 1
1
1
1
1
1
1
1
1
1
1
1
Helmut Simonis Symmetry Breaking 33
ProblemProgram
Symmetry BreakingExperiment with alternative value order
Observation
Enormous reduction in search spaceWe are solving a different problem!Not just good for finding all solutions, also for first solution!Value choice not optimal for finding first solutionThere is a lot of very shallow backtracking, can we avoidthat?
Helmut Simonis Symmetry Breaking 34
ProblemProgram
Symmetry BreakingExperiment with alternative value order
Effort for First Solution
Basic Model With double Lex
1
2
3
4
5
11
12
13
14
150
160
170 1
1
1
0
15
160
170 1
1
0
16
170
180 1
1
0
17
180 1
0 1
1
1
1
0
14
15
160
170 1
1
0
16
170
180 1
1
0
17
180 1
0 1
1
1
0
15
16
170
180 1
1
0
17
180 1
0 1
1
0
16
17
18
21
22
23
24
250
260
270 1
1
1
0
25
260
270 1
1
0 1
1
0
24
25
260
270 1
1
0 1
0 1
1
0
23
24
250
26
270
280 1
1
0
27
280 1
0 1
1
1
0
25
26
270
280 1
1
0
27
280 1
0 1
1
0
26
32
330
34
350
360
37
43
440
490
1
0
0
1
1
0
1
0
0
1
1
0
1
0
0
0
0
1
1
1
0
0
0
0
0
0
0
10
20
30
40
50
110
120
160
170
180
210
22
230
260
320
33
340
36
370
430
46
490 1
0
1
1
0
1
0
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
Helmut Simonis Symmetry Breaking 35
ProblemProgram
Symmetry BreakingExperiment with alternative value order
Symmetry BreakingExperiment with alternative value order
Assigning Value 1 First
1
2
3
4
5
11
12
16
17
18
21
221
23
26
32
33
361
371 0
0
1
34
361
37
43
461
491 0
0
1 0
1 0
0
1 0
0
1 0
1 0
1 0
0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
Helmut Simonis Symmetry Breaking 37
ProblemProgram
Symmetry BreakingExperiment with alternative value order
Observation
First solution is found more quicklySize of tree for all solutions unchangedValue order does not really affect search space whenexploring all choices!
Helmut Simonis Symmetry Breaking 38
ProblemProgram
Symmetry BreakingExperiment with alternative value order
Effort for All Solutions
Assign 0, then 1 Assign 1, then 010
20
30
40
50
110
120
160
170
180
210
22
230
260
320
33
340
36
370
430
46
490 1
0 1
1
1
0 1
1
0
36
370 1
0 1
1
1
1
1
0 1
1
1
1
1
1
1
1
1
1
1
1
1
2
3
4
5
11
12
16
17
18
21
221
23
26
32
33
361
371 0
0
1
34
361
37
43
461
491 0
0
1 0
1 0
0
1 0
0
1 0
1 0
1 0
0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
Helmut Simonis Symmetry Breaking 39
ProblemProgram
Symmetry BreakingExperiment with alternative value order
Conclusions
Symmetry breaking can have huge impact on modelMainly works for pure problemsPartial symmetry breaking with additional constraintsDouble lex for row/column symmetriesOnly one variant of many symmetry breaking techniques
Helmut Simonis Symmetry Breaking 40
Why assign by row?Alternative Models
Exercises
Variable Selection by Column
1
2
3
7
8
9
13
16
17
19
22
23
251 0
1
25
32
34
35
381 0
1
381 0
0
1
381 0
0
1 0
1 0
0
1 0
1 0
1 0
1 0
1 0
1
10
13
15
16
19
25
32
33
34
381 0
1
35
38
40
411
441 0
0
1 0
1 0
1 0
0
1
34
35
381 0
1 0
1 0
0
1 0
1 0
1 0
1
17
19
22
23
251 0
1
25
32
33
34
38
441 0
1 0
1
35
38
40
41
441 0
1
441 0
0
1
441 0
0
1 0
1
38
40
41
44
531 0
1 0
1
441 0
0
1
441 0
0
1 0
0
0
1
34
35
381 0
1
381 0
0
1
381 0
0
0
1 0
1 0
0
1
251 0
0
1 0
1 0
0
1
16
17
19
251 0
1 0
1 0
1
19
251 0
1 0
0
0
1 0
1 0
0
1
10
11
13
16
17
191 0
1
19
251 0
1 0
0
1 0
1 0
1 0
1 0
0
1 0
1 0
1 0
1 0
Helmut Simonis Symmetry Breaking 41
Why assign by row?Alternative Models
Exercises
Observation
Good, but not as good as row orderValue choice unimportant even for first solutionChanging the variable selection does affect size of searchspace, even for all solutions
Helmut Simonis Symmetry Breaking 42
Why assign by row?Alternative Models
Exercises
Effort for All Solutions
By Row By Column1
2
3
4
5
11
12
16
17
18
21
221
23
26
32
33
361
371 0
0
1
34
361
37
43
461
491 0
0
1 0
1 0
0
1 0
0
1 0
1 0
1 0
0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1
2
3
7
8
9
13
16
17
19
22
23
251 0
1
25
32
34
35
381 0
1
381 0
0
1
381 0
0
1 0
1 0
0
1 0
1 0
1 0
1 0
1 0
1
10
13
15
16
19
25
32
33
34
381 0
1
35
38
40
411
441 0
0
1 0
1 0
1 0
0
1
34
35
381 0
1 0
1 0
0
1 0
1 0
1 0
1
17
19
22
23
251 0
1
25
32
33
34
38
441 0
1 0
1
35
38
40
41
441 0
1
441 0
0
1
441 0
0
1 0
1
38
40
41
44
531 0
1 0
1
441 0
0
1
441 0
0
1 0
0
0
1
34
35
381 0
1
381 0
0
1
381 0
0
0
1 0
1 0
0
1
251 0
0
1 0
1 0
0
1
16
17
19
251 0
1 0
1 0
1
19
251 0
1 0
0
0
1 0
1 0
0
1
10
11
13
16
17
191 0
1
19
251 0
1 0
0
1 0
1 0
1 0
1 0
0
1 0
1 0
1 0
1 0
Helmut Simonis Symmetry Breaking 43
Why assign by row?Alternative Models
Exercises
Possible Explanations
There are fewer rows than columnsStrict lex constraints on rows, but not on columns
More impact of first row
Needs more testing
Helmut Simonis Symmetry Breaking 44
Why assign by row?Alternative Models
Exercises
Do we need binary variables?
Consider a model with finite domain variablesEach of b blocks consists of k variables ranging over vvaluesThe values in a block must be alldifferent (ordered)Each value can occur r timesScalar product more difficultEven better expressed with finite set variables
Helmut Simonis Symmetry Breaking 45
Why assign by row?Alternative Models
Exercises
Exercises
1
Helmut Simonis Symmetry Breaking 46
ProblemModel
ProgramSearch
Redundant Modelling
Chapter 9: Choosing the Model (SportsScheduling)
Helmut Simonis
Cork Constraint Computation CentreComputer Science Department
University College CorkIreland
ECLiPSe ELearning Overview
Helmut Simonis Choosing the Model 1
ProblemModel
ProgramSearch
Redundant Modelling
Licence
This work is licensed under the Creative CommonsAttribution-Noncommercial-Share Alike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ orsend a letter to Creative Commons, 171 Second Street, Suite300, San Francisco, California, 94105, USA.
How to come up with a model for a problemWhy choosing a good model is an artChannelingProjectionRedundant Constraints
Helmut Simonis Choosing the Model 4
ProblemModel
ProgramSearch
Redundant Modelling
Sports Scheduling
Tournament PlanningWe plan a tournament with 8 teams, where every team playsevery other team exactly once. The tournament is played on 7days, each team playing on each day. The games arescheduled in 7 venues, and each team should play in eachvenue exactly once.As part of the TV arrangements, some preassignments aredone: We may either fix the game between two particularteams to a fixed day and venue, or only state that some teammust play on a particular day at a given venue. The objective isto complete the schedule, so that all constraints are satisfied.
Helmut Simonis Choosing the Model 5
ProblemModel
ProgramSearch
Redundant Modelling
Example
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 8 7, 5Day 2 2 1, 5Day 3 7 8Day 4 2 5 1Day 5 8 1Day 6 5, 4Day 7 4 1, 3
Rooms Puzzle, (Thomas G. Room, 1955)Place numbers 1 to 8 in cells so that each row and eachcolumn has each number exactly once, each cell containseither no numbers or two numbers (which must be differentfrom each other), and each combination of two differentnumbers appears in exactly one cell.
Puzzle presented by R. Finkel
Helmut Simonis Choosing the Model 8
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
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
Helmut Simonis Choosing the Model 9
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Requirements
1 There are 8 teams, seven days and seven locations2 Each team plays each other team exactly once3 Each team plays 7 games (redundant)4 Each team plays in each location exactly once5 Each team plays on each day exactly once6 A game consists of two (different) teams7 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
Helmut Simonis Choosing the Model 10
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Idea 1
Matrix Day × Game (7× 4)Each cell contains two variables, denoting teamsEasy to say that team plays once on each day,alldifferent
Columns don’t have significanceModel does not mention location, how to add this?How to express that each team plays each other once?
Helmut Simonis Choosing the Model 11
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Idea 2, Change problem structure
Matrix of Day × Location (7× 7)Each cell contains two variables, each denoting a teamHow do we avoid symmetry inside cell?Need special value (0) to denote that there is no gameIn one cell, either both or none of the variables are 0Easy to say that each row and column contains each teamexactly onceExcept for value 0, can not use alldifferent
Link between two variables in cell to state that game needstwo different teamsHow to express that each (ordered) pair occurs exactlyonce?
Helmut Simonis Choosing the Model 12
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Idea 3, Add location variables
Model as in Idea 1, matrix Day × GameEach cell contains two variables for teams and one forlocationEasy to state that games on one day are in differentlocationsHow to express condition that each team plays in eachlocation once?Also, how to express that each team plays each otherexactly once?
Helmut Simonis Choosing the Model 13
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Idea 4, Use variables for pairs
Matrix Day × LocationEach cell contains one variable ranging over (sorted) pairsof teams, and special value 0 (no game)Each pair value occurs once, except for 0
Special constraint alldifferent0Or use gcc
How to state that each team plays once per day?How to state that each team plays in each location?
Helmut Simonis Choosing the Model 14
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Idea 5: If all else fails, use binary variables
Binary variable stating that team i plays in location j at daykThree dimensional matrixEach team plays once on each dayEach team plays once in each locationEach game has two (different) teams, needs auxiliaryvariableEach pair of team meets once, needs auxiliary variables
Helmut Simonis Choosing the Model 15
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Idea 6: An even bigger binary model
Use four dimensionsTeam i meets team j in location k on day l3136 = 8*8*7*7 variablesConstraints all linearWhy use finite domain constraints?
Helmut Simonis Choosing the Model 16
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Idea 7: A different mapping
Each team plays each other exactly once, one variable foreach combination (8*7/2=28 variables)Decide when and where this game is played, values rangeover combinations of days and locations (7*7=49 values)All variables must be different (no two games at same timeand location)Each team plays 7 games, by constructionHow to express that each team plays once per day?How to express that each team plays in each locationonce?
Helmut Simonis Choosing the Model 17
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Expand Idea 7 into Full Model
Helmut Simonis Choosing the Model 18
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Numbering Values
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 1 2 3 4 5 6 7Day 2 8 9 10 11 12 13 14Day 3 15 16 17 18 19 20 21Day 4 22 23 24 25 26 27 28Day 5 29 30 31 32 33 34 35Day 6 36 37 38 39 40 41 42Day 7 43 44 45 46 47 48 49
Helmut Simonis Choosing the Model 19
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Four games on each day
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 1 2 3 4 5 6 7Day 2 8 9 10 11 12 13 14Day 3 15 16 17 18 19 20 21Day 4 22 23 24 25 26 27 28Day 5 29 30 31 32 33 34 35Day 6 36 37 38 39 40 41 42Day 7 43 44 45 46 47 48 49
Day 1 corresponds to values 1..7Four variables can take these valuesDay 2 corresponds to values 8..14, etcOne constraint per dayExactly four of all variables take their value in the set ...Seven such constraints
Helmut Simonis Choosing the Model 20
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Four games at each location
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 1 2 3 4 5 6 7Day 2 8 9 10 11 12 13 14Day 3 15 16 17 18 19 20 21Day 4 22 23 24 25 26 27 28Day 5 29 30 31 32 33 34 35Day 6 36 37 38 39 40 41 42Day 7 43 44 45 46 47 48 49
City 1 corresponds to values1, 8, 15, 22, 29, 36, 43
Four variables can take these valuesCity 2 corresponds to values
2, 9, 16, 23, 30, 37, 44
One constraint per locationExactly four of all variables take their value in the set ...Seven such constraints over 28 variables each
Helmut Simonis Choosing the Model 21
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Teams plays once on a day (at a location)
Select those variables which correspond to Team iExactly one of those variables takes its value in the set 1..7Same for all other daysSame for all other teams56 Constraints over 7 variables eachSimilar for teams and locations, another 56 constraints
Helmut Simonis Choosing the Model 22
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Are we there yet?
28 variables with 49 possible values1 alldifferent7 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
Helmut Simonis Choosing the Model 23
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Do we satisfy the requirements?
1 There are 8 teams, seven days and seven locations2 Each team plays each other team exactly once3 Each team plays 7 games (redundant)4 Each team plays in each location exactly once5 Each team plays on each day exactly once6 A game consists of two (different) teams7 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
Helmut Simonis Choosing the Model 24
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
What about the exactly constraint?
ECLiPSe doesn’t provide this constraintOther system might do, could switch system
Implement itExtend gcc to allow multiple valuesShould be last resort
Emulate constraint with others
Helmut Simonis Choosing the Model 25
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Idea 8: Mapping games to days and locations
For each game to be played, we have two variablesOne ranges over the daysThe other over the locations
Easy to state that there are four games per day an locationEasy to state that each team plays once per day andlocationHow do we express that no two games are played at thesame location and the same time?
If we had an alldifferent over pairs of variables...Not in ECLiPSe
Helmut Simonis Choosing the Model 26
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
We have four games on each day
Each row value is taken four times amongst the variablesgcc([gcc(4,4,1),...,gcc(4,4,7)],Rows)
Similar for columns:gcc([gcc(4,4,1),...,gcc(4,4,7)],Cols)
Helmut Simonis Choosing the Model 27
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Each team plays once per day
For the seven variables which describe games of a teamEach row value is taken exactly once amongst thevariablesCould usegcc([gcc(1,1,1),...,gcc(1,1,7)],Vars)
But alldifferent(Vars) is more compactSimilar for columns
Helmut Simonis Choosing the Model 28
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
How do the models differ?
D DaysT TeamsL LocationsG Games
Idea Mapping1 D ×G × {f , s} → T2 D × L× {f , s} → T ∪ {0}
3D ×G × {f , s} → T
D ×G→ L4 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
8T M T → DT M T → L
Helmut Simonis Choosing the Model 29
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Requirements Capture
Idea Requirement1 2 3 4 5 6 7 8 9
1 N ? Y ? Y Y Y ? ?2 C ? Y Y Y Y Y Y Y3 C ? Y ? Y Y Y Y Y4 C Y Y Y Y Y Y Y Y5 C NL L L L NL L L NL6 C L L L L L L L L7 C C C E E C E E A8 C C C A A C G G ?
Helmut Simonis Choosing the Model 30
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Comments on models
Idea Main point1 missing locations, first second symmetry2 spare value, first second symmetry3 first second symmetry4 spare value5 0/1, non-linear constraints6 0/1, large matrix7 needs exactly constraint8 needs alldifferent on tuples
Helmut Simonis Choosing the Model 31
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Channeling
Instead of expressing all constraints over one set ofvariablesUse multiple sets of variablesDecide which constraint to express over which variablesAllows more freedom on how to express problemLink the different variables with channeling constraints
Helmut Simonis Choosing the Model 32
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
In Our Case
Combine ideas 7 and 8One set of variables ranging over pairsAnother using two variables per game for day and locationHow to combine variables?Minimize loss of information
Helmut Simonis Choosing the Model 33
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
ProjectionCity 1 City 2 City 3 City 4 City 5 City 6 City 7
Link pair variables to row and column variablesPair variable uses cell numbers 1-49 as valuesRow and column variables indicate on which day (row) andin which location (column) the game is playedPair value 23 = row 4, column 2element constraint to link the variablesTwo projections from D × L space onto D and L
Helmut Simonis Choosing the Model 34
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Mapping cells to rows and columnsCity 1 City 2 City 3 City 4 City 5 City 6 City 7
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),...
Helmut Simonis Choosing the Model 42
ProblemModel
ProgramSearch
Redundant Modelling
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
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]
)),occurrences(Pos,Required,1).
Helmut Simonis Choosing the Model 50
ProblemModel
ProgramSearch
Redundant Modelling
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).
Helmut Simonis Choosing the Model 51
ProblemModel
ProgramSearch
Redundant Modelling
Using input orderFirst Fail Strategy
Before Search
Helmut Simonis Choosing the Model 52
ProblemModel
ProgramSearch
Redundant Modelling
Using input orderFirst Fail Strategy
Solution
Helmut Simonis Choosing the Model 53
ProblemModel
ProgramSearch
Redundant Modelling
Using input orderFirst Fail Strategy
Search Tree with input order
121
1
23
2
1334 31 33 35
45
16
36 21
1431 33 35
4
2
36
7
89
27
15
26
2317
6
18
26
25
5
Helmut Simonis Choosing the Model 54
ProblemModel
ProgramSearch
Redundant Modelling
Using input orderFirst Fail Strategy
How to improve?
Try different search strategyUse first_fail dynamic variable selection
Helmut Simonis Choosing the Model 55
ProblemModel
ProgramSearch
Redundant Modelling
Using input orderFirst Fail Strategy
Search Tree with first fail
1212
12
34
13 11 14
32
53
671
13
143
8
11
5
5412 11 14 53
346 31 37
54
8
49
18
Helmut Simonis Choosing the Model 56
ProblemModel
ProgramSearch
Redundant Modelling
Using input orderFirst Fail Strategy
Observation
It does not workSearch tree is slightly larger than before!
Helmut Simonis Choosing the Model 57
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Missing Propagation
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 8 7, 5Day 2 2 1, 5Day 3 7 8Day 4 2 5 1Day 5 8 1Day 6 5, 4Day 7 4 1, 3
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 1 2 3 4 5 6 7Day 2 8 9 10 11 12 13 14Day 3 15 16 17 18 19 20 21Day 4 22 23 24 25 26 27 28Day 5 29 30 31 32 33 34 35Day 6 36 37 38 39 40 41 42Day 7 43 44 45 46 47 48 49
Helmut Simonis Choosing the Model 58
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Missing Propagation
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 8 7, 5Day 2 2 1, 5Day 3 7 8Day 4 2 5 1Day 5 8 1Day 6 5, 4Day 7 4 1, 3
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 1 2 3 4 5 6 7Day 2 8 9 10 11 12 13 14Day 3 15 16 17 18 19 20 21Day 4 22 23 24 25 26 27 28Day 5 29 30 31 32 33 34 35Day 6 36 37 38 39 40 41 42Day 7 43 44 45 46 47 48 49
Helmut Simonis Choosing the Model 59
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Missing Propagation
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 8 7, 5Day 2 2 1, 5Day 3 7 8Day 4 2 5 1Day 5 8 1Day 6 5, 4Day 7 4 1, 3
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 1 2 3 4 5 6 7Day 2 8 9 10 11 12 13 14Day 3 15 16 17 18 19 20 21Day 4 22 23 24 25 26 27 28Day 5 29 30 31 32 33 34 35Day 6 36 37 38 39 40 41 42Day 7 43 44 45 46 47 48 49
Helmut Simonis Choosing the Model 60
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Missing Propagation
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 8 7, 5Day 2 2 1, 5Day 3 7 8Day 4 2 5 1Day 5 8 1Day 6 5, 4Day 7 4 1, 3
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 1 2 3 4 5 6 7Day 2 8 9 10 11 12 13 14Day 3 15 16 17 18 19 20 21Day 4 22 23 24 25 26 27 28Day 5 29 30 31 32 33 34 35Day 6 36 37 38 39 40 41 42Day 7 43 44 45 46 47 48 49
Helmut Simonis Choosing the Model 61
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Missing Propagation
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 8 7, 5Day 2 2 1, 5Day 3 7 8Day 4 2 5 1Day 5 8 1Day 6 5, 4Day 7 4 1, 3
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 1 2 3 4 5 6 7Day 2 8 9 10 11 12 13 14Day 3 15 16 17 18 19 20 21Day 4 22 23 24 25 26 27 28Day 5 29 30 31 32 33 34 35Day 6 36 37 38 39 40 41 42Day 7 43 44 45 46 47 48 49
Helmut Simonis Choosing the Model 62
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Missing Propagation
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 8 7, 5Day 2 2 1, 5Day 3 7 8Day 4 2 5 1Day 5 8 1Day 6 5, 4Day 7 4 1, 3
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 1 2 3 4 5 6 7Day 2 8 9 10 11 12 13 14Day 3 15 16 17 18 19 20 21Day 4 22 23 24 25 26 27 28Day 5 29 30 31 32 33 34 35Day 6 36 37 38 39 40 41 42Day 7 43 44 45 46 47 48 49
Helmut Simonis Choosing the Model 63
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Missing Propagation
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 8 7, 5Day 2 2 1, 5Day 3 7 8Day 4 2 5 1Day 5 8 1Day 6 5, 4Day 7 4 1, 3
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 1 2 3 4 5 6 7Day 2 8 9 10 11 12 13 14Day 3 15 16 17 18 19 20 21Day 4 22 23 24 25 26 27 28Day 5 29 30 31 32 33 34 35Day 6 36 37 38 39 40 41 42Day 7 43 44 45 46 47 48 49
Helmut Simonis Choosing the Model 64
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Why is this?
Constraints involved:gcc constraint on row: four variables can use values fromthis rowfour occurrence constraints for hints: One of the variablesmust take this value
No interaction between constraints, only betweenconstraints and variablesWe do not detect that value 1 can not be usedEventual solution respects condition, model is correctWe are concerned about propagation, not correctness
Helmut Simonis Choosing the Model 65
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Adding redundant model
Add constraints which do more propagation, but do notaffect solutionsLead to smaller search tree, hopefully faster solutionIntroduction requires understanding of (lack of)propagationVisualization is key to detect missing propagation
Helmut Simonis Choosing the Model 66
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Adding 0/1 model
Day × Location matrix of 0/1 variablesIndicates if there is a game on this day at this locationRow/column sums: 4 games in each row/columnHint given for cell: Game variable is 1
Helmut Simonis Choosing the Model 67
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Channeling Constraint
Link pair variables Pi to 0/1 variables Yj as value-index(∃i s.t. Pi = v)⇔ Yv = 1Propagation:
Pi = v ⇒ Yv = 1Yv = 0⇒ ∀i : Pi 6= v(∀i : v /∈ d(Pi))⇒ Yv = 0Yv = 1⇒ occurrence(V , P1...Pn, N), N ≥ 1
Helmut Simonis Choosing the Model 68
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Added Program
value_set_channeling(L,Hints):-dim(Matrix,[7,7]),Matrix[1..7,1..7] :: 0..1,flatten_array(Matrix,ValueSet),value_set_channel(L,ValueSet,1),(for(I,1,7),param(Matrix) do
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 1 2 3 4 5 6 7Day 2 8 9 10 11 12 13 14Day 3 15 16 17 18 19 20 21Day 4 22 23 24 25 26 27 28Day 5 29 30 31 32 33 34 35Day 6 36 37 38 39 40 41 42Day 7 43 44 45 46 47 48 49
Game 12 can not be played on day 1 at locations 5 or 6
Helmut Simonis Choosing the Model 79
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Our model does not deal well with hints
Preset game is ok, leads to variable assignmentPreset team is weak, adds new constraintAs there is no interaction of this constraint with the otherconstraints, there is no initial domain restrictionModel is correct, but lazy
Helmut Simonis Choosing the Model 80
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Improving the handling of hints
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 8 7, 5Day 2 2 1, 5Day 3 7 8Day 4 2 5 1Day 5 8 1Day 6 5, 4Day 7 4 1, 3
This value can not be used by pairs not involving team 8One of the pairs involving team 8 must use this valueThese values can not be used by any pair involving team 8
Helmut Simonis Choosing the Model 81
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Added Program
improved_hint(Pos,[Value],L,Contains):-(foreach(X,L),foreach(A-B,Contains),fromto([],R,R1,Required),param(Pos,Value) do
Adding value index ChannelingImproving Handling of Hints
Added Program
excluded_locations(Pos,Excluded):-coor(Pos,X,Y),(for(I,1,7),fromto([],A,A1,E1),param(Y,Pos) do
coor(K,I,Y),(Pos = K ->
A1 = A;
A1 = [K|A])
),...
Helmut Simonis Choosing the Model 83
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Added Program
...(for(J,1,7),fromto(E1,A,A1,Excluded),param(X,Pos) do
coor(K,X,J),(Pos = K ->
A1 = A;
A1 = [K|A])
).
Helmut Simonis Choosing the Model 84
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Added Program
exclude_values(Vars,Values):-(foreach(X,Vars),param(Values) do
(foreach(Value,Values),param(X) do
X #\= Value)
).
Helmut Simonis Choosing the Model 85
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Before Search
Helmut Simonis Choosing the Model 86
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Impact of improved hint handling
With index set channeling Improved Hints
Helmut Simonis Choosing the Model 87
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Observation
We don’t need the value index channelingIt is subsumed by the improved hint treatmentAlways worthwhile to check if constraints are still requiredafter modifying model
Cork Constraint Computation CentreComputer Science Department
University College CorkIreland
ECLiPSe ELearning Overview
Helmut Simonis Customizing Search 1
ProblemProgram
Search
Licence
This work is licensed under the Creative CommonsAttribution-Noncommercial-Share Alike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ orsend a letter to Creative Commons, 171 Second Street, Suite300, San Francisco, California, 94105, USA.
Problem DecompositionDecide which problem to solveNot always required to solve complete problem in one go
Modelling with bin packingCustomized search routines can bring dramaticimprovementsUnderstanding what is happening important to findimprovements
Helmut Simonis Customizing Search 4
ProblemProgram
Search
Phase 1Phase 2
Problem Definition
Progressive Party
The problem is to timetable a party at a yacht club. Certainboats are to be designated hosts, and the crews of theremaining boats in turn visit the host boats for severalsuccessive half-hour periods. The crew of a host boat remainson board to act as hosts while the crew of a guest boat togethervisits several hosts. Every boat can only host a limited numberof guests at a time (its capacity) and crew sizes are different.The party lasts for 6 time periods. A guest boat cannot notrevisit a host and guest crews cannot meet more than once.The problem facing the rally organizer is that of minimizing thenumber of host boats.
Phase 2: Create plan to assign guest boats to hosts inmultiple periods
Done as a constraint program
Helmut Simonis Customizing Search 7
ProblemProgram
Search
Phase 1Phase 2
Idea
Decompose problem into multiple, simpler sub problemsSolve each sub problem in turnProvides solution of complete problemChallenge: How to decompose so that good solutions areobtained?How to show optimality of solution?
Helmut Simonis Customizing Search 8
ProblemProgram
Search
Phase 1Phase 2
Selecting Host boats
Some additional side constraintsSome boats must be hostsSome boats may not be hosts
Reason on total or spare capacityNo solution with 12 boats
Helmut Simonis Customizing Search 9
ProblemProgram
Search
Phase 1Phase 2
Solution to Phase 1
Select boats 1 to 12 and 14 as hostsMany possible problem variants by selecting other hostboats
Helmut Simonis Customizing Search 10
ProblemProgram
Search
Phase 1Phase 2
Phase 2 Sub-problem
Host boats and their capacity givenIgnore host teams, only consider free capacityAssign guest teams to host boats
Helmut Simonis Customizing Search 11
ProblemProgram
Search
Phase 1Phase 2
Model
Assign guest boats to hosts for each time periodMatrix of domain variables (size NrGuests × NrPeriods)Variables range over possible hosts 1..NrHosts
Helmut Simonis Customizing Search 12
ProblemProgram
Search
Phase 1Phase 2
Constraints
Each guest boat visits a host boat atmost onceTwo guest boats meet at most onceAll guest boats assigned to a host in a time period fit withinspare capacity of host boat
Helmut Simonis Customizing Search 13
ProblemProgram
Search
Phase 1Phase 2
Each guest visits a hosts atmost once
The variables for a guest and different time periods mustbe pairwise differentalldifferent constraint on rows of matrix
Helmut Simonis Customizing Search 14
ProblemProgram
Search
Phase 1Phase 2
Two guests meet at most once
The variables for two guests can have the same value foratmost one time periodConstraints on each pair of rows in matrix
Helmut Simonis Customizing Search 15
ProblemProgram
Search
Phase 1Phase 2
All guests assigned to a host in a time period fit withinspare capacity of host boat
Capacity constraint expressed as bin packing for each timeperiodEach host boat is a bin with capacity from 0 to its unusedcapacityEach guest is an item to be assigned to a binSize of item given by crew size of guest boat
Helmut Simonis Customizing Search 16
ProblemProgram
Search
Phase 1Phase 2
Bin Packing Constraint
Global constraintbin_packing(Assignment,Sizes,Capacity)
Items of different sizes are assigned to binsAssignment of item modelled with domain variable (firstargument)Size of items fixed: integer values (second argument)Each bin may have a different capacityCapacity of each bin given as a domain variable (thirdargument)
make_bins(HostCapacity,Bins):-(foreach(Cap,HostCapacity),foreach(B,Bins) do
B :: 0..Cap).
Helmut Simonis Customizing Search 25
ProblemProgram
Search
Each pair of guests meet atmost once
card_leq(Vector1,Vector2,Card):-collection_to_list(Vector1,List1),collection_to_list(Vector2,List2),(foreach(X,List1),foreach(Y,List2),fromto(0,A,A+B,Term) do
#=(X,Y,B)),eval(Term) #=< Card.
Helmut Simonis Customizing Search 26
ProblemProgram
Search
Naive Search
assign(List):-search(List,0,input_order,indomain,
complete,[]).
Helmut Simonis Customizing Search 27
ProblemProgram
Search
Naive SearchFirst Fail StrategyLayered SearchLayered with Credit SearchRandomized with Restart
Naive Search (Compact view)1
2
3
4
5
6
7
8
9
1
11
12
13
14
15
16
17
18
19
2
21
22
23
24
25
26
27
28
3
31
32
33
34
35
36
37
38
39
4
41
42
43
44
45
46
47
48
49
5
51
52
53
55
56
58
59
6
61
62
63
64
65
66
67
68
69
7
71
72
73
74
75
76
77
78
1
23
11
79
8
81
8212
8312
84
88
89
9
91
92
93
94
95
96
97
98
99
1
11
12
14
2
4
3
2
4
11
154
164
194 3 5
111
112
117
118
119
12
121
122
123
124
125
126
127
128
129
13
131
133
1
5
1
4
6
6
134
136
138
2
3
7
141
146
147
148
149
15
151
152
153
154
155
26347
86295
8
156
157
235
269
8 9
158
3
9
1
8
6
8
159
557
2857
1 9
168
164
165
24
384
1
166
167
168
169
174
8
1
9
8
1
3
19
18
11
8
5
1
9
12
5
3
7
4
6
5
5
6
1
7
5
18
11
12
1
9
8
1
9
8
3
6
4
3
4
19
18
11
18
9
3
12
5
6
7
7
8
6
1
1
4
8
9
11
18
19
5
11
5
18
7
9
7
7
12
3
6
5
6
4
3
8
4
8
1
1
9
11
11
12
18
12
18
11
5
12
6
5
8
7
5
3
7
4
3
4
1
9
6
9
1
8
18
18
18
11
11
11
12
12
12
5
5
4
1
5
7
7
3
3
6
6
9
8
4
9
8
1
Helmut Simonis Customizing Search 28
ProblemProgram
Search
Naive SearchFirst Fail StrategyLayered SearchLayered with Credit SearchRandomized with Restart
Observations
Not too many wrong choicesBut very deep backtracking required to discover failureMost effort wasted in “dead” parts of search tree
Helmut Simonis Customizing Search 29
ProblemProgram
Search
Naive SearchFirst Fail StrategyLayered SearchLayered with Credit SearchRandomized with Restart
First Fail strategy
assign(List):-search(List,0,first_fail,indomain,
complete,[]).
Helmut Simonis Customizing Search 30
ProblemProgram
Search
Naive SearchFirst Fail StrategyLayered SearchLayered with Credit SearchRandomized with Restart
Naive SearchFirst Fail StrategyLayered SearchLayered with Credit SearchRandomized with Restart
Observations
Assignment not done in row or column modeTree consists of straight parts without backtrackingand nearly fully explored parts
Helmut Simonis Customizing Search 32
ProblemProgram
Search
Naive SearchFirst Fail StrategyLayered SearchLayered with Credit SearchRandomized with Restart
Idea
Assign variables by time periodWithin one time period, use first_fail selectionSolves bin packing packing for each period completelyClearer impact of disequality constraints
Helmut Simonis Customizing Search 33
ProblemProgram
Search
Naive SearchFirst Fail StrategyLayered SearchLayered with Credit SearchRandomized with Restart
Layered Search
assign(Matrix,NrPeriods,NrGuests):-(for(J,1,NrPeriods),param(Matrix,NrGuests) do
Naive SearchFirst Fail StrategyLayered SearchLayered with Credit SearchRandomized with Restart
Layered Search1
2
3
4
5
6
7
8
9
1
11
12
13
14
15
16
17
18
19
2
21
22
23
24
25
26
27
28
3
32
31
33
34
37
38
39
4
41
42
43
35
36
44
45
46
47
48
49
5
51
52
53
55
56
58
59
62
61
6
63
64
72
66
67
69
68
7
65
71
74
76
77
78
8
79
82
831
811
73
84
88
89
9
94
91
92
98
99
1
19
113
11
114
115
18
116
17
14
111
12
11
93
95
96
117
119
12
118
13
121
122
123
125
129
124
126
128
127
132
131
135
136
143
1372 34
5
141
1372 34
5 2
36
7
143
137
1392
14
133
134
146
147
15
148
149
152
159
162
151
167
1638
165
15836 33 35
1668 2
169
154
15636
157
15336 35
5 35
33 35
3
164
1685 8 2
9 2
1714 8 2
33
5 36
155
1533 36 35
5 36 35
33
3 4 8
1
34
4 8
164
154
17
157
1728
168
1698 34
4 8 2
1 36
3
1584 36 35
153
168 2 35
5 4 36 35
34
33 35
1584 36 33 35
34
5
15836 33 35
1668 2
169
1688 2
3 8
1
34
4 8 2
3 36
157
1564 36 35
1584 36 35
34
3
17
155
15336 35
15636 35
34
3 36 35
4 8 2
5 35
1584 36 35
34
33
157
1564 36
1584 36 35
33 35
3
168 2 35
5
1584 36 35
33 35
34
5 2
154
1584 36 35
157
1614 36 35
3
17
15336
156
1698
1668 2
1
3 36 35
33 35
4 8 2
5
153
155
1564 36 35
3 4 36 35
5 4 36 35
33 35
34
3
1584 36 35
157
1534 36
1564 36 35
33 35
3
168 2 35
5
153
1564 36 35
3 4 36 35
33 35
34
5 36
1584 36 35
34
33
154
157
1614 36 35
3
17
15336
15836 35
33 35
4 8 2
5
1584 36 35
33 35
3
157
1534 36
1564 36 35
33 35
3
168 2 35
5
1584 36 35
33 35
5 36
157
1564 36 35
3
1584 36 35
5 35
33
34
9
154
157
1614 36 35
3
1534 36
1584 36 35
33 35
5
1584 36 35
33 35
3
157
1534 36
1564 36 35
33 35
3
168 2 35
5
1584 36 35
33 35
5 36
157
1564 36 35
3
1584 36 35
5 35
33
34
36
165
158
154
153
155
156
157
161
169
175 9
8
4
35
33
3
5
3
36
4
35
5
7
3
4
7
1
8
2
9
33
33
2
35
7
5
35
3
9
1
36
2
1
3
4
5
3
4
5
7
9
8
35
2
1
36
33
9
36
2
1
9
2
9
8
4
5
3
4
3
5
8
7
1
36
34
35
36
35
1
33
7
4
2
1
9
2
8
9
3
8
5
3
7
5
4
33
33
36
35
36
35
33
1
36
7
1
5
4
1
2
2
9
8
9
8
7
3
4
3
5
35
35
35
33
33
33
36
36
36
1
1
8
7
3
1
2
2
9
9
4
5
8
7
4
5
3
Helmut Simonis Customizing Search 35
ProblemProgram
Search
Naive SearchFirst Fail StrategyLayered SearchLayered with Credit SearchRandomized with Restart
Observations
Deep backtracking for last time periodNo backtracking to earlier time periods requiredSmall amount of backtracking at other time periods
Helmut Simonis Customizing Search 36
ProblemProgram
Search
Naive SearchFirst Fail StrategyLayered SearchLayered with Credit SearchRandomized with Restart
Idea
Use credit based searchBut not for complete search treeLoose too much useful workBacktrack independently for each time periodHope to correct wrong choices without deep backtracking
Helmut Simonis Customizing Search 37
ProblemProgram
Search
Naive SearchFirst Fail StrategyLayered SearchLayered with Credit SearchRandomized with Restart
Layered with Credit
assign(Matrix,NrPeriods,NrGuests):-(for(J,1,NrPeriods),param(Matrix,NrGuests) do
NSq is NrGuests*NrGuests,search(Matrix[1..NrGuests,J],0,
first_fail,indomain,credit(NSq,10),[])
).
Helmut Simonis Customizing Search 38
ProblemProgram
Search
Naive SearchFirst Fail StrategyLayered SearchLayered with Credit SearchRandomized with Restart
Layered with Credit Search1
2
3
4
5
6
7
8
9
1
11
12
13
14
15
16
17
18
19
2
21
22
23
24
25
26
27
28
3
32
31
33
34
37
38
39
4
41
42
43
35
36
44
45
46
47
48
49
5
51
52
53
55
56
58
59
62
61
6
63
64
72
66
67
69
68
7
65
71
74
76
77
78
8
79
82
831
811
73
84
88
89
9
94
91
92
98
99
1
19
113
11
114
115
18
116
17
14
111
12
11
93
95
96
117
119
12
118
13
121
122
123
125
129
124
126
128
127
132
131
135
136
143
1372 34
5
141
1372 34
5 2
36
7
143
137
1392
14
133
134
146
147
15
148
149
152
159
162
151
167
1638
165
15836 33 35
1668 2
169
154
15636
157
15336 35
5 35
33 35
3
164
1685 8 2
9 2
1714 8 2
33
5 36
155
1533 36 35
5 36 35
33
3 4 8
1
34
4 8
164
154
17
157
1728
168
1698 34
4 8 2
1 36
3
1584 36 35
153
168 2 35
5 4 36 35
34
33 35
1584 36 33 35
34
5
15836 33 35
1668 2
169
1688 2
3 8
1
34
4 8 2
3 36
157
1564 36 35
1584 36 35
34
3
17
155
15336 35
15636 35
34
3 36 35
4 8 2
5 35
1584 36 35
34
33
5
9
36
5
165
166
165
17
169
171
174
168
158
153
155
154
15635
3
5
33
36
9
4
5
3
5
2
8
5
4
7
3
4
7
1
8
2
9
33
33
2
35
7
5
35
3
9
1
36
2
1
3
4
5
3
4
5
7
9
8
35
2
1
36
33
9
36
2
1
9
2
9
8
4
5
3
4
3
5
8
7
1
36
34
35
36
35
1
33
7
4
2
1
9
2
8
9
3
8
5
3
7
5
4
33
33
36
35
36
35
33
1
36
7
1
5
4
1
2
2
9
8
9
8
7
3
4
3
5
35
35
35
33
33
33
36
36
36
1
1
8
7
3
1
2
2
9
9
4
5
8
7
4
5
3
Helmut Simonis Customizing Search 39
ProblemProgram
Search
Naive SearchFirst Fail StrategyLayered SearchLayered with Credit SearchRandomized with Restart
Observations
Improved searchNeed more sample problems to really understand impact
Helmut Simonis Customizing Search 40
ProblemProgram
Search
Naive SearchFirst Fail StrategyLayered SearchLayered with Credit SearchRandomized with Restart
Idea
Randomize value selctionRemove bias picking bins in same orderAllows to add restartWhen spending too much time without finding solutionRestart search from beginningRandomization will explore other initial assignmentsDo not get caught in “dead” part of search tree
Helmut Simonis Customizing Search 41
ProblemProgram
Search
Naive SearchFirst Fail StrategyLayered SearchLayered with Credit SearchRandomized with Restart
Randomized with Restart
assign(Matrix,NrPeriods,NrGuests):-repeat,(for(J,1,NrPeriods),param(Matrix,NrGuests) do
NSq is NrGuests*NrGuests,once(search(Matrix[1..NrGuests,J],0,
first_fail,indomain_random,credit(NSq,10),[]))
),!.
Helmut Simonis Customizing Search 42
ProblemProgram
Search
Naive SearchFirst Fail StrategyLayered SearchLayered with Credit SearchRandomized with Restart
Randomized Search1
2
3
4
5
6
7
8
9
1
11
12
13
14
15
16
17
18
19
2
21
22
23
24
25
26
27
28
3
31
32
33
34
35
36
37
4
41
42
43
38
39
44
45
5
53
58
47
48
55
57
46
49
51
54
59
61
62
63
6
66
68
74
64
71
67
69
7
72
65
75
78
79
8
81
83
82
85
84
87
761 2
34
761 34
2
35
87
762 1
35
7635 1
2
34
87
7635 1
34
761 34
35
2
34
84
77
87
76
88
89
9
91
95
96
11
97
94
13
92
93
1
98
99
111
12
18
114
112
16
19
15
116
113
14
11
117
118
119
12
123
121
124
125
126
13
128
129
122
127
13133 3
139
14
1334 1
6
132
143
136
1371 6
1 33
7
1334 1
6
35
133
141
13835
13435 7
3
4 7
6
141
1426 33
7
138
1347 35
3 35
6
4 1
1 33
3
33
14
141
133
142
1343 35
7
1383 35
33
33
1353
134
138
146
147
148
15
149
151
16
153
156
152
157
154
159
1618 35
6
161
167
168
169
1589
166
162
165
1638
7
4
6
7
7
9
35
8
4
6
34
35
33
4
31
3
3
2
1
33
3
7
1
4
33
6
8
34
2
9
3
2
35
31
9
7
8
6
4
1
3
4
2
9
2
8
1
33
6
1
7
9
4
7
8
2
3
34
33
3
1
6
31
35
1
34
2
34
1
9
3
2
1
2
8
2
1
7
3
6
7
3
6
9
4
4
8
35
33
31
9
9
31
33
1
33
33
2
9
7
35
1
8
1
31
8
3
34
35
4
2
7
3
6
2
9
2
4
7
7
4
3
9
31
35
6
7
8
1
31
8
2
34
9
4
1
6
35
33
3
Helmut Simonis Customizing Search 43
ProblemProgram
Search
Naive SearchFirst Fail StrategyLayered SearchLayered with Credit SearchRandomized with Restart
Observations
Avoids deep backtracking in last time periodsPerhaps by mixing values more evenlyImpose fewer disequality constraints for last periodsEasier to find solutionShould allow to find solutions with more time periods
Helmut Simonis Customizing Search 44
ProblemProgram
Search
Naive SearchFirst Fail StrategyLayered SearchLayered with Credit SearchRandomized with Restart
Naive SearchFirst Fail StrategyLayered SearchLayered with Credit SearchRandomized with Restart
Observations
Randomized method is strongest for this problemNot always fastest for smaller problem sizesRestart required for size 9 problemsSame model, very different results due to searchVery similar results for other problem instances
Helmut Simonis Customizing Search 46
ProblemProgram
SearchImprovements
Chapter 11: Limits of Propagation (CostasArray)
Helmut Simonis
Cork Constraint Computation CentreComputer Science Department
University College CorkIreland
ECLiPSe ELearning Overview
Helmut Simonis Limits of Propagation 1
ProblemProgram
SearchImprovements
Licence
This work is licensed under the Creative CommonsAttribution-Noncommercial-Share Alike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ orsend a letter to Creative Commons, 171 Second Street, Suite300, San Francisco, California, 94105, USA.
Improving propagation does not always payFor some problems, simple backtracking is bestCP may not always be the best methodCP should always be fastest way to model problemConsider time to target
Time required to run programTime required to write program
Costas Array (Wikipedia)A Costas array (named after John P. Costas) can be regardedgeometrically as a set of N points lying on the squares of a NxNcheckerboard, such that each row or column contains only onepoint, and that all of the N(N - 1)/2 vectors between each pair ofdots are distinct.
A variable for each column, ranging from 1 to NA list of N variables for the columnsA difference variable between each ordered pair ofvariablesalldifferent constraint between variablesalldifferent constraints for all differences
Problem becomes harder with increasing sizeFailures occur from level 3 downDeep backtracking required to undo wrong choicesValue selection not working, have to explore all choicesIncrease not uniform
Big improvement in backtracks and timeNot for all problem sizesQuestion: Do we need improvement of model for this towork?Experiment: Run changes search routine on basic model
Helmut Simonis Limits of Propagation 41
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Labeling Basic Model from Middle
Basic Model Basic Model, MiddleSize Backtrack Time Backtrack Time
Search strategy does not depend on modelVariable selection is the same!Basic model is about two times fasterAbout 50% more backtrack stepsAgain, sometimes reasoning does not pay!Better search strategy pays off dramatically
Helmut Simonis Limits of Propagation 45
0/1 Models
A Different Model
Model shown is not the only way to express problem
Helmut Simonis Limits of Propagation 46
0/1 Models
0/1 Models
SAT (Minisat)Pseudo Boolean (Minisat+)MIP (Coin-OR)
Helmut Simonis Limits of Propagation 47
0/1 Models
0/1 Models: Variables
Xiv : Variable i takes value vDijv : Difference between variables i and j is v
Helmut Simonis Limits of Propagation 48
0/1 Models
MIP Model: Constraints
alldifferent between variables∑i Xiv = 1∑v Xiv = 1
alldifferent between differences∑v Dijv = 1∑i−j=c Dijv ≤ 1
link between variables and differencesDijv =
∑v1=v2+v Xiv1Xjv2
Helmut Simonis Limits of Propagation 49
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Chapter 12: Systematic Development
Helmut Simonis
Cork Constraint Computation CentreComputer Science Department
University College CorkIreland
ECLiPSe ELearning Overview
Helmut Simonis Systematic Development 1
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Licence
This work is licensed under the Creative CommonsAttribution-Noncommercial-Share Alike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ orsend a letter to Creative Commons, 171 Second Street, Suite300, San Francisco, California, 94105, USA.
How to develop large applications in ECLiPSeSoftware development issues for PrologThis is essential for large applications
But it may show benefits already for small programs
This is not about problem solving, but the boring bits ofapplication development
Helmut Simonis Systematic Development 4
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Disclaimer
This is not holy writBut it works!
This is a team issuePeople working together must agreeCome up with a local style guide
Consistency is not optionalEvery shortcut must be paid for later on
This is an appetizer onlyThe real story is in the tutorial Developing Applications withECLiPSe (part of the ECLiPSe documentation)
Helmut Simonis Systematic Development 5
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Application Structure
Full Application Batch Application
Java Application User
ECLiPSe/Java Interface
ECLiPSe Application
Data Files
ECLiPSe Application
Helmut Simonis Systematic Development 6
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
LSCO Structure
prepare data
create variables
create constraints
find solution
output results
Helmut Simonis Systematic Development 7
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Top-Down Design
Design queriesUML static class diagram (structure definitions)API document/test casesTop-level structureData flow analysisAllocate functionality to modulesSyntactic test casesModule expansion
Using programming concepts where possibleIncremental changes
Helmut Simonis Systematic Development 8
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Modules
Grouping of predicates which are relatedTypically in a single fileDefined external interfaces
Which predicates are exportedMode declaration for argumentsIntended types for argumentsDocumentation
Helps avoid Spaghetti structure of program
Helmut Simonis Systematic Development 9
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Creating Documentation
Your program can be documented in the same way asECLiPSe library predicatesComment directives in source codeTools to extract comments and produce HTMLdocumentation with hyper-linksQuality depends on effort put into commentsEvery module interface should be documented
Helmut Simonis Systematic Development 10
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Example
:- comment(prepare_data/4,[summary:"creates the data structures
for the flow analysis",amode:prepare_data(+,+,+,-),args:[
"Dir":"directory for report output","Type":"the type of report to be generated","Summary":"a summary term","Nodes":"a nodes data structure"],
desc:html("This routine creates the datastructures for the flow analysis...."),
AlternativesIteration (list, terms, arrays)TransformationFilteringCombineMinimum/Best and restSumMergeGroupLookupCartesianOrdered pairs
Helmut Simonis Systematic Development 17
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Example: Cartesian
:-mode cartesian(+,+,-).cartesian(L,K,Res):-
(foreach(X,L),fromto([],In,Out,Res),param(K) do
(foreach(Y,K),fromto(In,In1,[pair(X,Y)|In1],Out),param(X) do
true)
).
Helmut Simonis Systematic Development 18
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Input/Output
Section on DCG useGrammars for parsing and generating text formats
XML parser in ECLiPSelib(xml)
EXDR format to avoid quoting/escaping problemsTip:
Generate hyper-linked HTML/SVG output to presentdata/results as development aid
Helmut Simonis Systematic Development 19
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
If it doesn’t work
Understand what happensWhich program point should be reached with whichinformation?Why do we not reach this point?Which data is wrong/missing?
Do not trace through program!Debugging is like solving puzzles
Pick up cluesDeduce what is going onDo not simulate program behaviour!
Helmut Simonis Systematic Development 20
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Correctness and Performance
TestingProfilingCode Reviews
Makes sure things are up to a certain standardDon’t expect reviewer to find bugs
Things to watch out forUnwanted choice pointsOpen streamsModified global stateDelayed goals
Helmut Simonis Systematic Development 21
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Did I mention testing?
Single most important/neglected activityRe-test directly after every change
Identifies faulty modificationAvoids lengthy debugging session after making 100s ofchanges
Independent verificationCheck results by hand (?)By other program (??)Use constraint solver as checker
Helmut Simonis Systematic Development 22
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Style Guide
Rules that should be satisfied by finished programThings may be relaxed during prototypingOften, choice among valid alternatives is made arbitrarily,so that a consistent way is definedIf you don’t like it, change it!
But: better a bad rule than no rule at all!
Helmut Simonis Systematic Development 23
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Style Guide Examples
There is one directory containing all code and itsdocumentation (using sub-directories).Filenames are of form [a-z][a-z_]+ with extension.ecl .One file per module, one module per file.Each module is documented with comment directives....Don’t use ’,’/2 to make tuples.Don’t use lists to make tuples.Avoid append/3 where possible, use accumulatorsinstead.
Helmut Simonis Systematic Development 24
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Layout rules
How to format ECLiPSe programsPretty-printer formatEases
Exchange of programsCode reviewsBug fixesAvoids extra reformatting work
Helmut Simonis Systematic Development 25
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Core Predicates List
Alphabetical predicate index lists 2940 entriesYou can’t possibly learn all of themDo you really want to know whatset_typed_pool_constraints/3 does?
List of Prolog predicates you need to know69 entries, more manageable
Ignores all solver librariesIf you don’t know what an entry does, find out about it
what does write_exdr/2 do?
If you use something not on the list, start to wonder...
Helmut Simonis Systematic Development 26
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Other Sources
Developing Applications with ECLiPSeH. Simonishttp://www.eclipse-clp.org
Constraint Logic Programming Using ECLiPSeK. Apt, M. WallaceCambridge University Press
The Craft of PrologR.O’Keefe, MIT Press
Helmut Simonis Systematic Development 27
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Conclusions
Large scale applications can be built with ECLiPSeSoftware engineering is not that different for PrologMany tasks are similar regardless of solver usedCorrectness of program is useful even for research work
Cork Constraint Computation CentreComputer Science Department
University College CorkIreland
ECLiPSe ELearning Overview
Helmut Simonis Visualization Techniques 1
Licence
This work is licensed under the Creative CommonsAttribution-Noncommercial-Share Alike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ orsend a letter to Creative Commons, 171 Second Street, Suite300, San Francisco, California, 94105, USA.
How to visualize constraint programsVariable visualizersUnderstanding search treesConstraint visualizersComplex visualizations
Helmut Simonis Visualization Techniques 4
ProblemProgram
SearchConclusions
Chapter 14: Finite Set and ContinuousVariables - SONET Design Problem
Helmut Simonis
Cork Constraint Computation CentreComputer Science Department
University College CorkIreland
ECLiPSe ELearning Overview
Helmut Simonis Finite Set and Continuous Variables 1
ProblemProgram
SearchConclusions
Licence
This work is licensed under the Creative CommonsAttribution-Noncommercial-Share Alike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ orsend a letter to Creative Commons, 171 Second Street, Suite300, San Francisco, California, 94105, USA.
Helmut Simonis Finite Set and Continuous Variables 2
Helmut Simonis Finite Set and Continuous Variables 3
ProblemProgram
SearchConclusions
What we want to introduce
Finite set variablesContinuous domainsOptimization from belowAdvanced symmetry breakingSONET design problem without inter-ring flows
Helmut Simonis Finite Set and Continuous Variables 4
ProblemProgram
SearchConclusions
Problem Definition
SONET Design Problem
We want to design a network with multiple SONET rings,minimizing ADM equipment. Traffic can only be transportedbetween nodes connected to the same ring, not between rings.Traffic demands between nodes are given. Decide which nodesto place on which ring(s), respecting a maximal number of ADMper ring, and capacity limits on ring traffic. If two nodes areconnected on more than one ring, the traffic between them canbe split arbitrarily between the rings. The objective is tominimize the overall number of ADM.
Helmut Simonis Finite Set and Continuous Variables 5
ProblemProgram
SearchConclusions
Example
N1
N2
N3
N4
R1 R2R3
3 rings, 4 nodes, 8 ADMEvery node connected to at least oneringOn every ring are at least two nodesN1 connected to R2and R3N4 and N2 can’t talk to each otherTraffic between N1and N2 must use R2Traffic between N2 and N3 can use eitherR1 or R2, or both
Helmut Simonis Finite Set and Continuous Variables 6
ProblemProgram
SearchConclusions
Data
Demands d ∈ D between nodes fd and td of size sd
Rings R, total of |R| = r ringsEach ring has capacity cNodes N
Helmut Simonis Finite Set and Continuous Variables 7
ProblemProgram
SearchConclusions
Model
Primary model integer 0/1 variables xikNode i has a connection to ring kA node can be connected to more than one ring
Continuous [0..1] variables fdkWhich fraction of total traffic of demand d is transported onring kA demand can use a ring only if both end-points areconnected to it
Helmut Simonis Finite Set and Continuous Variables 8
ProblemProgram
SearchConclusions
Constraints
min∑i∈N
∑k∈R
xik
s.t. ∑i∈N
xik ≤ r (1)∑k∈R
fdk = 1 (2)∑d∈D
sd ∗ fdk ≤ c (3)
fdk ≤ xfd k (4)fdk ≤ xtd k (5)
Helmut Simonis Finite Set and Continuous Variables 9
ProblemProgram
SearchConclusions
Dual Models
Introducing finite set variablesRange over sets of integers, not just integersMost useful when we don’t know the number of itemsinvolvedHere: for each node, the rings on which it is placedCould be one, could be two, or moreHard to express with finite domain variables alone
Helmut Simonis Finite Set and Continuous Variables 10
ProblemProgram
SearchConclusions
Dual Model 1
Finite set variables NiWhich rings node i is connected to
Cardinality finite domain variables ni|Ni | = ni
Helmut Simonis Finite Set and Continuous Variables 11
ProblemProgram
SearchConclusions
Dual Model 2
Finite set variables RkWhich nodes ring k is connected to
Cardinality finite domain variables rk|Rk | = rk
Helmut Simonis Finite Set and Continuous Variables 12
ProblemProgram
SearchConclusions
Channeling between models
Use the zero/one model as common groundxik = 1⇔ k ∈ Ni
xik = 1⇔ i ∈ Rk
Helmut Simonis Finite Set and Continuous Variables 13
ProblemProgram
SearchConclusions
Constraints in dual models
For every demand, source and sink must be on (at leastone) shared ring
∀d ∈ D : |Nfd ∩ Ntd | ≥ 1Every node must be on a ring
ni ≥ 1A ring can not have a single node connected to it
rk 6= 1
Helmut Simonis Finite Set and Continuous Variables 14
ProblemProgram
SearchConclusions
Assignment Strategy
Cost based decompositionAssign total cost firstThen assign ni variablesFinally, assign xik variablesIf required, fix flow fdk variablesMight leave flows as bound-consistent continuous domains
Helmut Simonis Finite Set and Continuous Variables 15
ProblemProgram
SearchConclusions
Optimization from below
Optimization handled by assigning cost firstEnumerate values increasing from lower boundFirst feasible solution is optimalDepends on proving infeasibility rapidlyDoes not provide sub-optimal initial solutions
Helmut Simonis Finite Set and Continuous Variables 16
ProblemProgram
SearchConclusions
Redundant Constraints
Deduce bounds in ni variablesHelps with finding ni assignment which can be extended
Symmetry Breaking
Helmut Simonis Finite Set and Continuous Variables 17
ProblemProgram
SearchConclusions
Symmetries
Typically no symmetries between demandsFull permutation symmetry on ringsGives r ! permutationsThese must be handled somehowFurther symmetries if capacity seen as discrete channels
Helmut Simonis Finite Set and Continuous Variables 18
ProblemProgram
SearchConclusions
Symmetry Breaking Choices
As part of assignment routineSBDS (symmetry breaking during search)Define all symmetries as parameterSearch routine eliminates symmetric sub-trees
By stating ordering constraintsAs shown in the BIBD exampleOrdering constraints not always compatible with searchheuristicParticular problem of dynamic variable ordering
Helmut Simonis Finite Set and Continuous Variables 19
ProblemProgram
SearchConclusions
Defining finite set variables
Library ic_setsDomain definition X :: Low..High
Low, High sets of integer values, e.g. [1,3,4]or intsets(L,N,Min,Max)
L is a list of N set variableseach containing all values between Min and Max
Helmut Simonis Finite Set and Continuous Variables 20
ProblemProgram
SearchConclusions
Using finite set variables
Set Expressions: A ∧ B, A ∨ B
Cardinality constraint: #(Set,Size)Size integer or finite domain variable
membership_booleans(Set,Booleans)Channeling between set and 0/1 integer variables
Helmut Simonis Finite Set and Continuous Variables 21
ProblemProgram
SearchConclusions
Using continuous variables
Library ic handles bothFinite domain variablesContinuous variables
Use floats as domain bounds, e.g. X :: 0.0 .. 1.0
Use $= etc for constraints instead of #=Bounds reasoning similar to finite caseBut must deal with safe roundingNot all constraints deal with continuous variables
Helmut Simonis Finite Set and Continuous Variables 22
ProblemProgram
SearchConclusions
Ambiguous Import
Multiple solvers define predicates like ::
If we load multiple solvers in the same module, we have totell ECLiPSe which one to useCompiler does not deduce this from context!So
ic:(X :: 1..3)ic_sets:(X :: [] .. [1,2,3])
Otherwise, we get loads of error messagesHappens whenever two modules export same predicate
Helmut Simonis Finite Set and Continuous Variables 23
Helmut Simonis Finite Set and Continuous Variables 39
ProblemProgram
SearchConclusions
Neighbors of a node
neighbors(N,List):-problem(_,_,Demands,_,_),(foreach(demand(I,J,_),Demands),fromto([],A,A1,List),param(N) do
(N = I ->A1 = [J|A]
; N = J ->A1 = [I|A]
;A1 = A
)).
Helmut Simonis Finite Set and Continuous Variables 40
ProblemProgram
SearchConclusions
Search at Cost 18-21
123
1
2
12
3
4
13
13
15
45
45
36
34
1
46
15
27
1
455
2
7
1
1
2
4 6
4
4
41
Helmut Simonis Finite Set and Continuous Variables 41
ProblemProgram
SearchConclusions
Search at Cost 22
123
45
112
134
1
46
553
567
1
455
51
52
1
8
1
2
471 2
3
2
2
22
Helmut Simonis Finite Set and Continuous Variables 42
ProblemProgram
SearchConclusions
Search at Cost 23
123
45
46
455
47
1123
1145
1
48
167
172
2
49
73
78
2
4
4
4
45
45
5
55
66
62
7
7
7
5
2
8
562
572
58
862 3
2
3
3
2
3
2
3
2
2
2
1
1
1
1
2
1
1
4
2
2
2
14
Helmut Simonis Finite Set and Continuous Variables 43
ProblemProgram
SearchConclusions
Conclusions
Introduced finite set and continuous domain solversFinite set variables useful when values are sets of integersUseful when number of items assigned are unknownCan be linked with finite domains (cardinality) and 0/1index variables
Helmut Simonis Finite Set and Continuous Variables 44
ProblemProgram
SearchConclusions
Continuous domain variables
Allow to reason about non-integral valuesBound propagation similar to bound propagation overintegersDifficult to enumerate valuesAssignment by domain splitting
Helmut Simonis Finite Set and Continuous Variables 45
ProblemProgram
SearchConclusions
SONET Problem
Example of optical network problemsCompetitive solution by combination of techniquesChanneling, redundant constraints, symmetry breakingDecomposition by branching on objective value
Helmut Simonis Finite Set and Continuous Variables 46
Traffic PlacementCapacity Management
Other Problems
Chapter 15: Network Applications
Helmut Simonis
Cork Constraint Computation CentreComputer Science Department
University College CorkIreland
ECLiPSe ELearning Overview
Helmut Simonis Network Applications 1
Traffic PlacementCapacity Management
Other Problems
Licence
This work is licensed under the Creative CommonsAttribution-Noncommercial-Share Alike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ orsend a letter to Creative Commons, 171 Second Street, Suite300, San Francisco, California, 94105, USA.
How can we get better performance out of a givennetwork?Make network transparent
Users should not need to know about detailsService maintained even if failures occur
Restricted by accepted techniques available in hardwareInteroperability between multi-vendor equipmentVery conversative deployment strategies
Helmut Simonis Network Applications 4
Traffic PlacementCapacity Management
Other Problems
Reminder: IP Networks
Packet forwardingConnection-lessDestination based routing
Distributed routing algorithm based on shortest pathalgorithmRouting metric determines preferred path
Best effortPackets are dropped when there is too much traffic oninterfaceGuaranteed delivery handled at other layers(TCP/applications)
Helmut Simonis Network Applications 5
Traffic PlacementCapacity Management
Other Problems
Disclaimer
Flexible border between CP and ORCP is ...
what CP people do.what is published in CP conferences.what uses CP languages.
Does not mean that other approaches are less valid!
Helmut Simonis Network Applications 6
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Example Network (Uniform metric 1, Capacity 100)
A
B
C
D
E
R1 R2
R3 R4
1
1
1
1
1
1
1
1 1
1
11
1
1
Helmut Simonis Network Applications 7
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Example Traffic Matrix
Only partially filled in for example
A B C D EA 0 0 10 20 20B 0 0 10 20 20C 0 0 0 0 0D 0 0 0 0 0E 0 0 0 0 0
Helmut Simonis Network Applications 8
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Using Routing
Demand AC 10
A
B
C
D
E
R1 R2
R3 R4
10
10 10
Helmut Simonis Network Applications 9
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Using Routing
Demand AD 20
A
B
C
D
E
R1 R2
R3 R4
20 20
20
Helmut Simonis Network Applications 10
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Using Routing
Demand BC 10A
B
C
D
E
R1 R2
R3 R4
5
5 5
5 5
5Helmut Simonis Network Applications 11
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Using Routing
Demand BD 20
A
B
C
D
E
R1 R2
R3 R4
10
10 10
10
10
10
Helmut Simonis Network Applications 12
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Using Routing
Demand AE 20
A
B
C
D
E
R1 R2
R3 R4
20
20
Helmut Simonis Network Applications 13
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Using Routing
Demand BE 20A
B
C
D
E
R1 R2
R3 R4
20
20
Helmut Simonis Network Applications 14
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Resulting Network Load
A
B
C
D
E
R1 R2
R3 R4
50
35
15 15
30
55 15
5
15
5
Helmut Simonis Network Applications 15
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Considering failure of R1-E
A
B
C
D
E
R1 R2
R3 R4
15
35
10
55
10
65
35
40 20
5
30
10
Helmut Simonis Network Applications 16
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Can we do better?
Choose single, explicit path for each demandRequires hardware support in routers (MPLS-TE)Baseline: CSPF, greedy heuristic
Helmut Simonis Network Applications 17
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Why not just use Multi-Commodity Flow ProblemSolution?
Can not use arbitrary, fractional flows in hardwareMILP does not scale too well
Helmut Simonis Network Applications 18
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Modelling Alternatives
Link based ModelPath based ModelNode based Model
Helmut Simonis Network Applications 19
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Variants
Demand AcceptanceChoose which demands to select fitting into availablecapacity
Traffic PlacementAll demands must be placed
Helmut Simonis Network Applications 20
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Intuition
Decide if demand d is run over link eSelect which demands run over link e (Knapsack)Demand d must run from source to sink (Path)Sum of delay on path should be limited (QoS)
Helmut Simonis Network Applications 21
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Link Based Model
min{Xde}
maxe∈E
1cap(e)
∑d∈D
bw(d)Xde or min{Xde}
∑e∈E,d∈D
bw(d)Xde
st.
∀d ∈ D,∀n ∈ N :∑
e∈OUT(n)
Xde −∑
e∈IN(n)
Xde =
−1 n = dest(d)
1 n = orig(d)
0 otherwise
∀e ∈ E :∑d∈D
bw(d)Xde ≤ cap(e)
∀d ∈ D :∑e∈E
del(e)Xde ≤ req(d)
Xde ∈ {0, 1}
Helmut Simonis Network Applications 22
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Lagrangian Relaxation - Path decomposition
[Ouaja&Richards2003]Dualize capacity constraintsStarting with CSPF initial solutionFinite domain solver for path constraintsAdded capacity constraints from st-cutsAt each step solve shortest path problems
Helmut Simonis Network Applications 24
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Lagrangian Relaxation - Knapsack decomposition
[Ouaja&Richards2005]Dualize path constraintsAt each step solve knapsack problemsReduced cost based filtering
Helmut Simonis Network Applications 25
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Probe Backtracking
[Liatsos et al 2003]Start with (infeasible) CSPF heuristicConsider capacity violation
Resolve by forcing one demand off/on linkFind new path respecting path and added constraints withILP
Repeat until no more violations, feasible solutionOptimality proof when exhausted search space
Search space often very small
Helmut Simonis Network Applications 26
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Intuition
Choose one of the possible paths for demand dThis paths competes with paths of other demands forbandwidthUsually too many paths to generate a priori, but most areuseless
Helmut Simonis Network Applications 27
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Path-Based Model
max{Zd ,Yid}
∑d∈D
val(d)Zd
st.
∀d ∈ D :∑
1≤i≤path(d)
Yid = Zd
∀e ∈ E :∑d∈D
bw(d)∑
1≤i≤path(d)
heidYid ≤ cap(e)
Zd ∈ {0, 1}Yid ∈ {0, 1}
Helmut Simonis Network Applications 28
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Blocking Islands
[Frei&Faltings1999]Feasible solution onlyCSP with variables ranging over paths for demandsNo explicit domain representationPossible to perform forward checking by updating blockingisland structure
Helmut Simonis Network Applications 30
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Local Search/FD Hybrid
[Lever2004]Start with (feasible) CSPF heuristicAdd more demands one by one
Use repair to solve capacity violationsUse FD model to check necessary conditions
Determine bottlenecks by st-cutsForce paths on/off links
Define neighborhood by rerouting demands currently overviolations
Helmut Simonis Network Applications 31
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Node Based Model: Intuition
For each demand, decide for each router where to go nextMany routers not used
Treat link capacity with cumulative/diffn constraintsPure FD model, no global cost view
Helmut Simonis Network Applications 32
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Cisco ISC-TEM
Path placement algorithm developed for Cisco by PTL andIC-Parc (2002-2004)Internal competitive selection of approachesStrong emphasis on stabilityWritten in ECLiPSePTL bought by Cisco in 2004Part of team moved to Boston
Helmut Simonis Network Applications 33
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Problem
What happens if element on selected path fails?Choose second path which is link (element) disjointState bandwidth constraints for each considered failurecaseProblem: Very large number of capacity constraints
Helmut Simonis Network Applications 34
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Example
Primary/Secondary path for demand AE
A
B
C
D
E
R1 R2
R3 R4
20
20
20 20
20
20
Helmut Simonis Network Applications 35
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Which bandwidth to count?
Failed Element No Failure A-R1 R1-E All OthersCapacity for Path Primary Secondary Secondary Primary
Helmut Simonis Network Applications 36
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Multiple Path Model
max{Zd ,Xde,Wde}
∑d∈D
val(d)Zd
∀d ∈ D, ∀n ∈ N :∑
e∈OUT(n)
Xde −∑
e∈IN(n)
Xde =
−Zd n = dest(d)
Zd n = orig(d)
0 otherwise
∀e ∈ E :∑d∈D
bw(d) ∗ Xde ≤ cap(e)
∀d ∈ D, ∀n ∈ N :∑
e∈OUT(n)
Wde −∑
e∈IN(n)
Wde =
−Zd n = dest(d)
Zd n = orig(d)
0 otherwise
∀e ∈ E, ∀e′ ∈ E \ e :∑d∈D
bw(d) ∗ (Xde − Xde′ ∗ Xde + Xde′ ∗Wde) ≤ cap(e)
∀d ∈ D, ∀e ∈ E : Xde + Wde ≤ 1
Zd ∈ {0, 1}, Xde ∈ {0, 1}, Wde ∈ {0, 1}
Helmut Simonis Network Applications 37
Traffic PlacementCapacity Management
Other Problems
Link Based ModelPath-Based ModelNode-Based ModelCommercial SolutionMultiple Paths
Solution Method
Benders Decomposition [Xia&Simonis2005]Use MILP for standard demand acceptance problemFind two link disjoint paths for each demandSub-problems consist of capacity constraints for failurecasesBenders cuts are just no-good cuts for secondary violations
Helmut Simonis Network Applications 38
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
The Problem
How to provide cost effective, high quality services runningan IP network?Easy to build high quality network by massiveover-provisioningEasy to build consumer grade network disregarding Qualityof Service (QoS)Very hard to right-size a network, providing just enoughcapacity
Helmut Simonis Network Applications 39
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
The Approach
Bandwidth on DemandCreate temporary bandwidth channels for high-value trafficAvoid disturbing existing traffic
Resilience AnalysisFind out how much capacity is required for current trafficProvide enough capacity to survive element failures withoutservice disruption
Helmut Simonis Network Applications 40
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Background
Failures of network should not affect services running onnetworkNot cost effective to protect connections in hardwareResponse time is critical
Interruption > 50ms not acceptable for telephonyReconvergence of IGP 1 sec (good setup)Secondary tunnels rely on signalling of failure (too slow)Live/Live connections too expensive
Helmut Simonis Network Applications 41
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Approach
Fast Re-routeIf element fails, use detour around failureLocal repair, not global reactionPre-compute possible reactions, allows offline optimization
Link protection rather easyNode protection quite difficult
Helmut Simonis Network Applications 42
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Example Problem
k l
c f
j e
ce,cf
20
ce,cfcf
ce
30
10
Helmut Simonis Network Applications 43
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Node j Failure
k l
c f
j e
20,30,40?
20
20,30,40?20,30?
10?
30
10
Helmut Simonis Network Applications 44
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Node j Failure (Result)
k l
c f
j e
20,30,40?
20
20,30,40?20,30?
10?
30
10
Helmut Simonis Network Applications 45
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Bandwidth Protection Model
min{Xfe}
∑f∈F
∑e∈E
Xfe
st .
∀f ∈ F :
∀n ∈ N \ {orig(f ),dest(f )} :∑
e∈IN(n)
Xfe =∑
e∈OUT(n)
Xfe
n = orig(f ) :∑
e∈OUT(n)
Xfe = 1
n = dest(f ) :∑
e∈IN(n)
Xfe = 1
∀e ∈ E : cap(e) ≥
max{Qfe}
∑f∈F
XfeQfe
st .
∀o ∈ orig(F) : ocap(o) ≥
∑f :orig(f )=o
Qfe
∀d ∈ dest(F) : dcap(o) ≥∑
f :dest(f )=d
Qfe
Xfe ∈ {0, 1}quan(f ) ≥ Qfe ≥ 0
Helmut Simonis Network Applications 46
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Solution Techniques
[Xia, Eremin & Wallace 2004]MILP
Use of Karusch-Kahn-Tucker conditionRemoval of nested optimizationLarge set of new variablesNot scalable
Problem DecompositionInteger Multi-Commodity Flow ProblemCapacity Optimization
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Cisco Tunnel Builder Pro
Algorithm/Implementation built by PTL/IC-Parc for CiscoNot based on published techniques aboveIn period 2000-2003Written in ECLiPSeEmbedded in Java GUINow subsumed by ISC-TEM
Helmut Simonis Network Applications 48
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Planning Ahead
Consider demands with fixed start and end timesDemands overlapping in time compete for bandwidthDemands arrive in batches, not always in temporalsequenceProblem called Bandwidth on Demand (BoD)
Helmut Simonis Network Applications 49
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Model: BoD
max{Zd ,Xde}
∑d∈D
val(d)Zd
st.
T = {start(d)|d ∈ D}
∀d ∈ D,∀n ∈ N :∑
e∈OUT(n)
Xde −∑
e∈IN(n)
Xde =
−Zd n = dest(d)
Zd n = orig(d)
0 otherwise
∀t ∈ T, ∀e ∈ E :∑d∈D
start(d)≤tt<end(d)
bw(d)Xde ≤ cap(e)
Zd ∈ {0, 1}Xde ∈ {0, 1}
Helmut Simonis Network Applications 50
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Solution Methods
France Telecom for ATM network [Lauvergne et al 2002,Loudni et al 2003]Schlumberger Dexa.net (PTL, IC-Parc)
Helmut Simonis Network Applications 51
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Schlumberger Dexa.net
Small, but global MPLS TE+diffserv networkOil field services(Very) High value traffic
Well loggingVideo conferencing
Bandwidth demand known well in advance, fixed periodLow latency, low jitter required
Helmut Simonis Network Applications 52
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Architecture
Provisioning Network
Demand Manager Resilience Analysis
Dexa.net Portal
Customer
Helmut Simonis Network Applications 53
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Workflow
Customer requests capacity for time slot via Web-interfaceDemand Manager determines if request can be satisfied
Based on free capacity predicted by Resilience AnalysisTaking other, accepted BoD requests into account
Email back to customerAt requested time, DM triggers provisioning tool to
Set up tunnelChange admission control
At end of period, DM pulls down tunnel
Helmut Simonis Network Applications 54
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
How much free capacity do we have in network?
Easy for normal network state (OSS tools)Challenge: How much is required for possible failurescenarios?Consider single link, switch, router, PoP failuresClassical solution
Get Traffic MatrixRun scenarios through simulator
Helmut Simonis Network Applications 55
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
How to get a Traffic Matrix?
Many algorithms assume given traffic matrixTraffic flow information is not collected in the routersOnly link traffic is readily availableDemand pattern changes over time, often quitedramaticallyMeasuring traffic flows with probes is very costly
From a network consultant:We have been working on extracting a TM for thisnetwork for 15 months, and we still don’t have a clue ifwe’ve got it right.
Helmut Simonis Network Applications 56
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Idea
Use the observed traffic to deduce traffic flowsNetwork Tomography [Vardi1996]
All flows routed over a link cause the observed trafficMust correct for observation errorsHighly dependent on accurate routing model
Gravity Model [Medina et al 2002]Ignore core of networkAssume that flows are proportional to product ofingress/egress size
Results are very hard to validate/falsify
Helmut Simonis Network Applications 57
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Model: Traffic Flow Analysis
∀i , j ∈ N : min{Fij}
/ max{Fij}
Fij
st.
∀e ∈ E :∑i,j∈N
reij Fij = traf(e)
∀i ∈ N :∑j∈N
Fij = extin(i)
∀j ∈ N :∑i∈N
Fij = extout(j)
Fij ≥ 0
Helmut Simonis Network Applications 58
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Start with Link Traffic
A
B
C
D
E
R1 R2
R3 R4
50
35
15 15
30
55 15
5
15
5
Helmut Simonis Network Applications 59
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Bandwidth ProtectionBandwidth on DemandResilience Analysis
What now?
Choose some particular solution?Which one? How to validate assumptions?Massively under-constrained problem
|N|2 variables|E |+ 2|N| constraints2|N|2 queries
Ill-conditioned even after error correctionAggregation helps
We are usually not interested in individual flowsWe want to use the TM to investigate something else
Helmut Simonis Network Applications 70
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Resilience Analysis
How much capacity is needed to survive all reasonablefailures?Use normal state as starting pointConsider routing in each failure caseAggregate flows in rerouted networkCalculate bounds on traffic in failure case
Helmut Simonis Network Applications 71
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Model: Resilience Analysis
∀e ∈ E : min{Fij}
/ max{Fij}
∑i,j∈N
r̄eij Fij
st.
∀e ∈ E :∑i,j∈N
reij Fij = traf(e)
∀i ∈ N :∑j∈N
Fij = extin(i)
∀j ∈ N :∑i∈N
Fij = extout (j)
Fij ≥ 0
Helmut Simonis Network Applications 72
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Perspectives
High polynomial complexityPossible to reduce number of queries
Small differences between failure casesMany queries are identical or dominated
Possible to reduce size of problem dramaticallyIntegrate multiple measurements in one modelWhich other problems can we solve without explicit TM?
Helmut Simonis Network Applications 77
Traffic PlacementCapacity Management
Other Problems
Network DesignIGP Metric Optimization
Problem
Which links should be used to build network structure?Link speed is related to costModel simple generalization of path findingAssumptions about routing in target network?
Helmut Simonis Network Applications 78
Traffic PlacementCapacity Management
Other Problems
Network DesignIGP Metric Optimization
Model
min{Xde,Wie}
∑e∈E
∑1≤i≤alt(e)
cost(i , e)Wie
∀d ∈ D,∀n ∈ N :∑
e∈OUT(n)
Xde −∑
e∈IN(n)
Xde =
−1 n = dest(d)
1 n = orig(d)
0 otherwise
∀e ∈ E :∑d∈D
bw(d)Xde ≤∑
1≤i≤alt(e)
cap(i , e)Wie
∀e ∈ E :∑
1≤i≤alt(e)
Wie = 1
Wie ∈ {0, 1}Xde ∈ {0, 1}
Helmut Simonis Network Applications 79
Traffic PlacementCapacity Management
Other Problems
Network DesignIGP Metric Optimization
Issues
Real-life problem not easily modelledPossible choices/costs not easily obtained (outside US)Choices often are inter-relatedPackage deals by providersSome regions don’t allow any flexibility at all
Helmut Simonis Network Applications 80
Traffic PlacementCapacity Management
Other Problems
Network DesignIGP Metric Optimization
Problem
How to set weights in IGP to avoid bottlenecks?Easy to beat default valuesSingle/equal cost paths required/allowed/forbidden?
Methods tested at IC-ParcBranch and priceTabu searchSet constraints
Very hard to compete with (guided) local search
Helmut Simonis Network Applications 83
Traffic PlacementCapacity Management
Other Problems
Network DesignIGP Metric Optimization
Further Reading
H. Simonis. Constraint Applications in Networks. Chaper 25 inF. Rossi, P van Beek and T. Walsh: Handbook of ConstraintProgramming. Elsevier, 2006.
Helmut Simonis Network Applications 84
Traffic PlacementCapacity Management
Other Problems
Network DesignIGP Metric Optimization
Summary
Network problems can be solved competitively byconstraint techniques.Hybrid methods required, simple FD models usually don’twork.Constraint based tools commercial reality.Open Problems
How to make this easier to develop?How to make this more stable to solve?
Helmut Simonis Network Applications 85
ProblemProgram
SearchImproved Search Strategy
Chapter 16: More Global Constraints (CarSequencing)
Helmut Simonis
Cork Constraint Computation CentreComputer Science Department
University College CorkIreland
ECLiPSe ELearning Overview
Helmut Simonis More Global Constraints 1
ProblemProgram
SearchImproved Search Strategy
Licence
This work is licensed under the Creative CommonsAttribution-Noncommercial-Share Alike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ orsend a letter to Creative Commons, 171 Second Street, Suite300, San Francisco, California, 94105, USA.
Car Sequencing Problemgcc Global cardinality constraintsequence constraintSearch based auxiliary variables
Helmut Simonis More Global Constraints 4
ProblemProgram
SearchImproved Search Strategy
Problem Definition
Car Sequencing
We have to schedule a number of cars for production on anassembly line. Each car is of a certain type, and we know howmany cars of each type we have to produce. Car types differ inthe options they require, i.e. sun-roof, air conditioning. For eachoption, we have capacity limits on the assembly line, expressedas k cars out of n consecutive cars on the line may have someoption. Find an assignment which produces the correct numberof cars of each type, while satisfying the capacity constraints.
Helmut Simonis More Global Constraints 5
ProblemProgram
SearchImproved Search Strategy
Example (DSV88)
100 cars18 types5 options
Option 1: 1 out of 2Option 2: 2 out of 3Option 3: 1 out of 3Option 4: 2 out of 5Option 5: 1 out of 5
Assign start time (sequence number) to each car100 variables, each with 100 valuesHandling of car types implicitSymmetry breaking for cars of same type (inequalities)?Capacity constraints?
Assign car type to each slot on assembly line100 variables, 18 valuesHow to control number of cars of each type?How to express capacity constraints?
Helmut Simonis More Global Constraints 9
ProblemProgram
SearchImproved Search Strategy
Model
100 Variables ranging over car typesgcc constraint to control number of items with same type5× 100 0/1 variables indicating use of option for each slotelement constraints to map car types to options usedsequence constraints to enforce limits on each option
Helmut Simonis More Global Constraints 10
ProblemProgram
SearchImproved Search Strategy
gcc(Pattern, Variables)
gcc Global Cardinality ConstraintPattern is list of terms gcc(Low, High, Value)
The overall number of variables taking value Value isbetween Low and High
Generalization of alldifferentDomain consistent version in ECLiPSe
Explained in optional material at endDomain Consistent gcc
Helmut Simonis More Global Constraints 17
ProblemProgram
SearchImproved Search Strategy
element(X,List,Y)
List is a list of integersThe X th element of List is YThe index starts from 1Typical Uses:
ProjectionCost
Helmut Simonis More Global Constraints 18
ProblemProgram
SearchImproved Search Strategy
Element Examples
Prime is 1 iff X ∈ 1..10 is a prime number
X :: 1..10,element(X,[1,1,1,0,1,0,1,0,0,0],Prime),
Cost is the cost corresponding to the assignment of Y
Y :: 1..10,element(Y,[5,3,34,0,3,1,12,12,1,3],Cost)
Helmut Simonis More Global Constraints 19
ProblemProgram
SearchImproved Search Strategy
sequence_total(Min,Max,Low,High,K,Vars)
Variables Vars have 0/1 domainBetween Min and Max variables have value 1For every sub-sequence of length K , between Low andHigh variables have value 1
This does not look goodTypical thrashing behaviourWe made a wrong choice at some point... but did not detect itMany additional choices are made before failure isdetectedWe have to explore the complete tree under the wrongchoiceThis is far too expensive
Helmut Simonis More Global Constraints 38
ProblemProgram
SearchImproved Search Strategy
Change of Search Strategy
Do not label car slot variablesDecide instead if slot should use an option or notThis restricts the car models which can be placed in thisslotStart with the most restricted optionWhen all options are assigned, the car type is fixedPotential problem: We now have 500 instead of 100decision variablesNaive searchspace 2500 = 3.2e150 instead of22100 = 1.7e134
Helmut Simonis More Global Constraints 39
ProblemProgram
SearchImproved Search Strategy
Second Modification
Instead of assigning values left to rightStart assigning in middle of boardAnd alternate around middle until you reach edgesIdea: Slots at edges are less constrained, i.e. easier toassignSave those slots until the endWe already encountered this idea for the N-Queensproblem
Helmut Simonis More Global Constraints 40
ProblemProgram
SearchImproved Search Strategy
Modified Search
12
13
11
14
15
62
63
61
64
65
42
43
41
44
45
72
73
71
74
75
52
53
51
54
55
12
18
16
91
62
98
66
31
42
38
46
1
72
8
76
21
521
28
5
11
541
9
12
91
14
6
35
64
39
4
5
44
9
7
25
29
12
97
19
14
99
68
92
63
37
66
31
65
3
5
43
6
46
3
45
8
73
24
76
23
75
5
53
1
95
97
19
11
96
14
93
68
62
98
35
63
34
36
64
39
33
48
32
42
38
43
1
9
2
61
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
Helmut Simonis More Global Constraints 41
ProblemProgram
SearchImproved Search Strategy
Assignment Step 2
Helmut Simonis More Global Constraints 42
ProblemProgram
SearchImproved Search Strategy
Assignment Step 28
Helmut Simonis More Global Constraints 43
ProblemProgram
SearchImproved Search Strategy
Assignment Step 119
Helmut Simonis More Global Constraints 44
ProblemProgram
SearchImproved Search Strategy
Observations
Important to start in middleMaking hard choices firstConcentrate on difficult to satisfy sub-problemNumber of choices is much smaller than number ofvariablesSome assignments lead to a lot of propagation
Helmut Simonis More Global Constraints 45
ProblemProgram
SearchImproved Search Strategy
Conclusions
Introduced two new global constraints, gcc and sequence
Used element for projectionSearch on auxiliary variables can work wellRaw search space measures are unreliableModelling idea
Decide what to make in a given time slot... and not when to schedule some given activity
Express constraint as max-flow problemAny flow solution corresponds to a valid assignmentOnly work with one flow solutionObtain all others by considering
residual graph andstrongly connected components
Classical method, faster methods existUse of max flow based propagators for many constraints