Post on 25-Mar-2022
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.
Helmut Simonis Introduction 2
Constraint ProgrammingChapter Overview
Chapter Details
Outline
1 Constraint Programming
2 Chapter Overview
3 Chapter Details
Helmut Simonis Introduction 3
Constraint ProgrammingChapter Overview
Chapter Details
What we want to introduce
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:
Network ManagementInteger ProgrammingCombinatorial Optimization
Helmut Simonis Introduction 8
Constraint ProgrammingChapter Overview
Chapter Details
Choices of materials
Slides PDF files for computer viewingContains animations of visualizationLarge file sizes
Handout PDF files for printing2 slides per pageDoes not contain all animations
Transcript Text of presentation as articlesVideo Video presentation with audio (640x480 pixels)
iPhone Video presentation tuned for iPhone display(480x320 pixels)
Helmut Simonis Introduction 9
Constraint ProgrammingChapter Overview
Chapter Details
Chapters
Introduction (You are here) Video iPhone Slides Handout
First Steps - Hello World Video iPhone Slides Handout
Application Overview Video iPhone Slides Handout
Basic Constraint Reasoning Video iPhone Slides Handout
Global Constraints Video iPhone Slides Handout
Search Strategies Video iPhone Slides Handout
Optimization Video iPhone Slides Handout
Symmetry Breaking Video iPhone Slides Handout
Choosing the Model Video iPhone Slides Handout
Customizing Search Video iPhone Slides Handout
Limits of Propagation Video iPhone Slides Handout
Systematic Development Video iPhone Slides Handout
Visualization Techniques Video iPhone Slides Handout
Finite Set and Continuous Variables Video iPhone Slides Handout
Network Applications Video iPhone Slides Handout
More Global Constraints Video iPhone Slides Handout
Adding Material Video iPhone Slides Handout
Helmut Simonis Introduction 10
Constraint ProgrammingChapter Overview
Chapter Details
Applications
Application Overview Video iPhone Slides Handout
SEND+MORE=MONEY Video iPhone Slides Handout
Sudoku Video iPhone Slides Handout
N-Queens Video iPhone Slides Handout
Routing and Wavelenght Assignment Video iPhone Slides Handout
Balanced Incomplete Block Designs Video iPhone Slides Handout
Sports Scheduling Video iPhone Slides Handout
Progressive Party Video iPhone Slides Handout
Costas Array Video iPhone Slides Handout
SONET/SDH Ring Design Video iPhone Slides Handout
Network Applications Video iPhone Slides Handout
Car Sequencing Video iPhone Slides Handout
Helmut Simonis Introduction 11
Constraint ProgrammingChapter Overview
Chapter Details
Introduction
Aims and OutcomesOverview of chaptersHyperlinks to all materials
Video iPhone Slides Handout
Helmut Simonis Introduction 12
Constraint ProgrammingChapter Overview
Chapter Details
First Steps - Hello World
How to install ECLiPSe and SarosWriting a first programRunning the programWhere to find information
Video iPhone Slides Handout
Helmut Simonis Introduction 13
Constraint ProgrammingChapter Overview
Chapter Details
Application Overview
Why constraint programming is interestingSolving industrial problems with CPMain application areas
AssignmentSchedulingNetwork problemsTransportationPersonnel Assignment
Video iPhone Slides Handout
Helmut Simonis Introduction 14
Constraint ProgrammingChapter Overview
Chapter Details
Basic Constraint Reasoning - SEND+MORE =MONEY
Finite Domain variablesCP: Variables + Constraints + SearchBounds reasoning on arithmetic constraintsSimple visualizers
Video iPhone Slides Handout
Helmut Simonis Introduction 15
Constraint ProgrammingChapter Overview
Chapter Details
Global Constraints - Sudoku
Modellimg the Sudoku puzzleOne model, different behavioursGlobal constraint: alldifferentBounds and domain consistencyA domain consistent alldifferent
Video iPhone Slides Handout
Helmut Simonis Introduction 16
Constraint ProgrammingChapter Overview
Chapter Details
Search Strategies - N Queens
How to search for a solutionVariable and value choiceHow to avoid deep backtrackingPartial search strategies
Video iPhone Slides Handout
Helmut Simonis Introduction 17
Constraint ProgrammingChapter Overview
Chapter Details
Optimization - Routing and Wavelength Assignment
OptimizationGraph algorithms libraryInteger Programming with eplex
Problem decompositionRouting and Wavelength Assignment in Optical Networks
Video iPhone Slides Handout
Helmut Simonis Introduction 18
Constraint ProgrammingChapter Overview
Chapter Details
Symmetry Breaking - Balanced Incomplete BlockDesigns
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.
Helmut Simonis First Steps 2
Outline
Helmut Simonis First Steps 3
What we want to introduce
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.
Helmut Simonis Application Overview 2
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
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
Overview
ProductionsequencingProductionschedulingSatellite taskingMaintenanceplanningProduct blendingTime tablingCrew rotationAircraft rotation
TransportPersonnelassignmentPersonnelrequirementplanningHardware designCompilationFinancial problemsPlacementCutting problems
Stand allocationAir traffic controlFrequencyallocationNetworkconfigurationProduct designProduction stepplanning
Helmut Simonis Application Overview 9
IntroductionSuccess Stories for Constraint Programming
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
Tools Used (Prolog Based Constraint Languages)
CHIP1986-1990 ECRC, Munich, Germany1990-today COSYTEC, Orsay, France
ECLiPSe1984-1996 ECRC1996-2004 IC-Parc, PTL, London2004-today Cisco Systemsa.k.a. Sepia (ECRC)a.k.a. DecisionPower (ICL)
Helmut Simonis Application Overview 10
IntroductionSuccess Stories for Constraint Programming
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
Five central topics
AssignmentParking assignmentPlatform allocation
Network ConfigurationScheduling
Production schedulingProject planning
TransportLorry, train, airlines
Personnel assignmentTimetabling, RosteringTrain, airlines
Helmut Simonis Application Overview 11
IntroductionSuccess Stories for Constraint Programming
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
Stand allocation
HIT (ICL)Assign ships to berths in container harborDeveloped with ECRC’s version of CHIP
Then using DecisionPower (ICL)Early version of ECLiPSe
First operational constraint application (1989-90)APACHE (COSYTEC)
Stand allocation for airportRefinery berth allocation (ISAB/COSYTEC)
Where to load/unload ships in refinery
Helmut Simonis Application Overview 12
IntroductionSuccess Stories for Constraint Programming
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
APACHE - AIR FRANCE (COSYTEC)
Stand allocation systemFor Air Inter/Air FranceRoissy, CDG2Packaged for large airports
Complex constraint problemTechnical constraintsOperational constraintsIncremental re-scheduler
Cost modelMax. nb passengers in contactMin. towing, bus usage
Benefits and statusQuasi real-time re-schedulingKAL, Turkish Airlines
Helmut Simonis Application Overview 13
IntroductionSuccess Stories for Constraint Programming
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
Network configuration
BoD (PTL)Locarim (France Telecom, COSYTEC)
Cabling of buildingPlanets (UCB, Enher)
Electrical power network reconfigurationLoad Balancing in Banking networks (ICON)
Distributed applicationsControl network traffic
Water Networks (UCB, ClocWise)
Helmut Simonis Application Overview 14
IntroductionSuccess Stories for Constraint Programming
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
BoD - Schlumberger (IC-Parc/PTL)
Bandwidth on DemandProvide guaranteed QoSFor temporary connectionsVideo conferencesOil well logging
World-wide, sparse networkBandwidth limitedDo not affect existing trafficUses route generator module for MPLS-TE
Model extended with temporal component
First version delivered February, 2003
Helmut Simonis Application Overview 15
IntroductionSuccess Stories for Constraint Programming
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
ISC-TEM - Cisco Systems
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
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
LOCARIM - France Telecom
Intelligent cabling systemFor large buildingsDeveloped by
COSYTECTelesystemes
ApplicationInput scanned drawingSpecify requirements
OptimizationMinimize cabling, drillingReduce switchesShortest path
StatusOperational in 5 Telecom sitesGenerates quotations
Helmut Simonis Application Overview 17
IntroductionSuccess Stories for Constraint Programming
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
Production Scheduling
Amylum (OM Partners)Glucose production
Cerestar (OM Partners)Glucose production
Saveplan (Sligos)Production scheduling
Trefi Metaux (Sligos)Heavy industry production scheduling
MichelinRubber blending, rework optimization
Helmut Simonis Application Overview 18
IntroductionSuccess Stories for Constraint Programming
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
PLANE - Dassault Aviation
Assembly line schedulingMirage 2000 FighterFalcon business jet
Two user systemProduction planning 3-5 yearsCommercial what-if sales aid
OptimisationBalanced scheduleMinimise changes in production rateMinimise storage costs
Benefits and statusReplaces 2 week manual planningOperational since Apr 94Used in US for business jets
Helmut Simonis Application Overview 19
IntroductionSuccess Stories for Constraint Programming
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
FORWARD - Fina
Oil refinery schedulingDeveloped by
TECHNIPCOSYTEC
Uses simulation toolForward by Elf
Schedules daily productionCrude arrival→Processing→ DeliveryDesign, optimize and simulate
Product BlendingExplanation facilitiesHandling of over-constrained problems
StatusOperational since June 94Operational at FINA, ISAB, BP
Helmut Simonis Application Overview 20
IntroductionSuccess Stories for Constraint Programming
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
MOSES - Dalgety
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
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
Transport
By AirAirPlanner (PT)Daysy (Lufthansa)Pilot (SAS)
By RoadWincanton (IC-Parc)TACT (SunValley)EVA (EDF)
By RailCREW (Servair)COBRA (NWT)
Helmut Simonis Application Overview 22
IntroductionSuccess Stories for Constraint Programming
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
AirPlanner (IC-Parc)
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
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
Wincanton (IC-Parc)
Large scale distribution problemDeliver fresh products to supermarketsDirect deliveries/warehousingCombining deliveriesCapacity constraintsTour planningWorkforce constraints
Helmut Simonis Application Overview 24
IntroductionSuccess Stories for Constraint Programming
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
CREW - Servair
Crew rostering systemAssign service staff to TGVBar/Restaurant serviceJoint design COSYTEC/GSI
Problem solverGenerates tours/cyclesAssigns skilled personnel
ConstraintsUnion, physical, calendar
StatusOperational since Mar 1995Cost reduction by 5%
Helmut Simonis Application Overview 25
IntroductionSuccess Stories for Constraint Programming
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
Personnel Planning
RAC (IC-Parc)OPTISERVICE (RFO)Shifter (ERG Petroli)Gymnaste (UCF)MOSAR (Ministère de la JUSTICE)
Helmut Simonis Application Overview 26
IntroductionSuccess Stories for Constraint Programming
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
RAC
Personnel dispatchingOn-line problem
Change plan as new requests are phoned inTypical constraints for workforce
Duty timeRest periodsMax driving timeResponse time
Operational/Strategic use
Helmut Simonis Application Overview 27
IntroductionSuccess Stories for Constraint Programming
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
OPTI SERVICE - RFO
Assignment of technical staffOverseas radio/TV networkRadio France Outre-merJoint development:
GIST and COSYTEC250 journalists and technicans
FeaturesSchedule manually,Check, Run automaticRule builder to specify cost formulasMinimize overtime, temporary staffCompute cost of schedule
StatusOperational since 1997Installed worldwide in 8 sitesDeveloped into generic tool
Helmut Simonis Application Overview 28
IntroductionSuccess Stories for Constraint Programming
Conclusions
AssignmentNetwork ManagementSchedulingTransportPersonnel Planning
Nurse Scheduling
GYMNASTETime tablingPersonnel assignmentProvisional and reactive planning (1-6 weeks)Developed by COSYTEC with partners
PRAXIM/Université Joseph Fourier de Grenoble
Pilot site GrenobleAlso used at hôpital de BLIGNY (Paris)Advantages :
Plan generation in 5 minutesUser/personnel preferencesDecrease in days lost
Helmut Simonis Application Overview 29
IntroductionSuccess Stories for Constraint Programming
Conclusions
Conclusions
Constraint Programming useful for many domainsLarge scale industrial use in
AssignmentNetwork ManagementProduction SchedulingTransportPersonnel Planning
Helmut Simonis Application Overview 30
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
Helmut Simonis Application Overview 32
ProblemProgram
Constraint SetupSearch
Lessons Learned
Chapter 4: Basic Constraint Reasoning(SEND+MORE=MONEY)
Helmut Simonis
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.
Helmut Simonis Basic Constraint Reasoning 2
ProblemProgram
Constraint SetupSearch
Lessons Learned
Outline
1 Problem
2 Program
3 Constraint Setup
4 Search
5 Lessons Learned
Helmut Simonis Basic Constraint Reasoning 3
ProblemProgram
Constraint SetupSearch
Lessons Learned
What we want to introduce
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.
Helmut Simonis Basic Constraint Reasoning 7
ProblemProgram
Constraint SetupSearch
Lessons Learned
General Program Structure
:- module(sendmory).:- export(sendmory/1).:- lib(ic).sendmory(L):-
L = [S,E,N,D,M,O,R,Y],é VariablesL :: 0..9,alldifferent(L),é ConstraintsS #\= 0, M #\= 0,1000*S + 100*E + 10*N + D +1000*M + 100*O + 10*R + E #=10000*M + 1000*O + 100*N + 10*E + Y,labeling(L).é Search
Helmut Simonis Basic Constraint Reasoning 8
ProblemProgram
Constraint SetupSearch
Lessons Learned
Choice of Model
This is one model, not the model of the problemMany possible alternativesChoice often depends on your constraint system
Constraints availableReasoning attached to constraints
Not always clear which is the best modelOften: Not clear what is the problem
Alternative 1 Alternative 2
Helmut Simonis Basic Constraint Reasoning 9
ProblemProgram
Constraint SetupSearch
Lessons Learned
Running the program
To run the program, we have to enter the querysendmory:sendmory(L).
ResultL = [9, 5, 6, 7, 1, 0, 8, 2]yes (0.00s cpu, solution 1, maybe more)
Helmut Simonis Basic Constraint Reasoning 10
ProblemProgram
Constraint SetupSearch
Lessons Learned
Question
But how did the program come up with this solution?
Helmut Simonis Basic Constraint Reasoning 11
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Domain Definition
L = [S,E,N,D,M,O,R,Y],L :: 0..9,
[S, E , N, D, M, O, R, Y ] ∈ {0..9}
Helmut Simonis Basic Constraint Reasoning 12
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Domain Visualization
Rows =Variables
Columns = Values
Cells= State
0 1 2 3 4 5 6 7 8 9SENDMORY
Helmut Simonis Basic Constraint Reasoning 13
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Alldifferent Constraint
alldifferent(L),
Built-in of ic libraryNo initial propagation possibleSuspends, waits until variables are changedWhen variable is fixed, remove value from domain of othervariablesForward checking
Helmut Simonis Basic Constraint Reasoning 14
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Alldifferent Visualization
Uses the same representation as the domain visualizer
0 1 2 3 4 5 6 7 8 9SENDMORY
Helmut Simonis Basic Constraint Reasoning 15
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Disequality Constraints
S #\= 0, M#\= 0,
Remove value from domain
S ∈ {1..9}, M ∈ {1..9}
Constraints solved, can be removed
Helmut Simonis Basic Constraint Reasoning 16
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Domains after Disequality
0 1 2 3 4 5 6 7 8 9SENDMORY
Helmut Simonis Basic Constraint Reasoning 17
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Equality Constraint
Normalization of linear termsSingle occurence of variablePositive coefficients
Propagation
Helmut Simonis Basic Constraint Reasoning 18
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Normalization
1000*S+ 100*E+ 10*N+ D+1000*M+ 100*O+ 10*R+ E
10000*M+ 1000*O+ 100*N+ 10*E+ Yis transformed into
1000*S+ 91*E+ D+ 10*R
9000*M+ 900*O+ 90*N+ Y
Helmut Simonis Basic Constraint Reasoning 19
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Simplified Equation
1000∗S +91∗E +10∗R +D = 9000∗M +900∗O +90∗N +Y
Helmut Simonis Basic Constraint Reasoning 20
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Propagation
1000 ∗ S1..9 + 91 ∗ E0..9 + 10 ∗ R0..9 + D0..9︸ ︷︷ ︸1000..9918
=
9000 ∗M1..9 + 900 ∗O0..9 + 90 ∗ N0..9 + Y 0..9︸ ︷︷ ︸9000..89919
Deduction:M = 1, S = 9, O ∈ {0..1}
Why? Skip
Helmut Simonis Basic Constraint Reasoning 21
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Consider lower bound for S
1000 ∗ S1..9 + 91 ∗ E0..9 + 10 ∗ R0..9 + D0..9︸ ︷︷ ︸9000..9918
= 9000 ∗M1..9 + 900 ∗O0..9 + 90 ∗ N0..9 + Y 0..9︸ ︷︷ ︸9000..9918
Lower bound of equation is 9000Rest of lhs (left hand side) (91 ∗E0..9 + 10 ∗R0..9 + D0..9) isatmost 918S must be greater or equal to 9000−918
1000 = 8.082otherwise lower bound of equation not reached by lhs
S is integer, therefore S ≥ d9000−9181000 e = 9
S has upper bound of 9, so S = 9
Helmut Simonis Basic Constraint Reasoning 22
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Consider upper bound of M
1000 ∗ S1..9 + 91 ∗ E0..9 + 10 ∗ R0..9 + D0..9︸ ︷︷ ︸9000..9918
= 9000 ∗M1..9 + 900 ∗O0..9 + 90 ∗ N0..9 + Y 0..9︸ ︷︷ ︸9000..9918
Upper bound of equation is 9918Rest of rhs (right hand side) 900 ∗O0..9 + 90 ∗ N0..9 + Y 0..9
is at least 0M must be smaller or equal to 9918−0
9000 = 1.102
M must be integer, therefore M ≤ b9918−09000 c = 1
M has lower bound of 1, so M = 1
Helmut Simonis Basic Constraint Reasoning 23
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Consider upper bound of O
1000 ∗ S1..9 + 91 ∗ E0..9 + 10 ∗ R0..9 + D0..9︸ ︷︷ ︸9000..9918
= 9000 ∗M1..9 + 900 ∗O0..9 + 90 ∗ N0..9 + Y 0..9︸ ︷︷ ︸9000..9918
Upper bound of equation is 9918Rest of rhs (right hand side) 9000 ∗ 1 + 90 ∗ N0..9 + Y 0..9 isat least 9000O must be smaller or equal to 9918−9000
900 = 1.02
O must be integer, therefore O ≤ b9918−9000900 c = 1
O has lower bound of 0, so O ∈ {0..1}
Helmut Simonis Basic Constraint Reasoning 24
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Propagation of equality: Result
0 1 2 3 4 5 6 7 8 9S - - - - - - - - Y
ENDM Y - - - - - - - -O 6 6 6 6 6 6 6 6
RY
Helmut Simonis Basic Constraint Reasoning 25
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Propagation of alldifferent
0 1 2 3 4 5 6 7 8 9SENDMORY
O = 0, [E , R, D, N, Y ] ∈ {2..8}
Helmut Simonis Basic Constraint Reasoning 26
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Waking the equality constraint
Triggered by assignment of variablesor update of lower or upper bound
Helmut Simonis Basic Constraint Reasoning 27
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Removal of constants
1000 ∗ 9 + 91 ∗ E2..8 + 10 ∗ R2..8 + D2..8 =
9000 ∗ 1 + 900 ∗ 0 + 90 ∗ N2..8 + Y 2..8
1000 ∗ 9 + 91 ∗ E2..8 + 10 ∗ R2..8 + D2..8 =
9000 ∗ 1 + 900 ∗ 0 + 90 ∗ N2..8 + Y 2..8
91 ∗ E2..8 + 10 ∗ R2..8 + D2..8 = 90 ∗ N2..8 + Y 2..8
Helmut Simonis Basic Constraint Reasoning 28
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Propagation of equality (Iteration 1)
91 ∗ E2..8 + 10 ∗ R2..8 + D2..8︸ ︷︷ ︸204..816
= 90 ∗ N2..8 + Y 2..8︸ ︷︷ ︸182..728
91 ∗ E2..8 + 10 ∗ R2..8 + D2..8 = 90 ∗ N2..8 + Y 2..8︸ ︷︷ ︸204..728
N ≥ 3 = d204− 890
e, E ≤ 7 = b728− 2291
c
Helmut Simonis Basic Constraint Reasoning 29
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Propagation of equality (Iteration 2)
91 ∗ E2..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N3..8 + Y 2..8
91 ∗ E2..7 + 10 ∗ R2..8 + D2..8︸ ︷︷ ︸204..725
= 90 ∗ N3..8 + Y 2..8︸ ︷︷ ︸272..728
91 ∗ E2..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N3..8 + Y 2..8︸ ︷︷ ︸272..725
E ≥ 3 = d272− 8891
e
Helmut Simonis Basic Constraint Reasoning 30
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Propagation of equality (Iteration 3)
91 ∗ E3..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N3..8 + Y 2..8
91 ∗ E3..7 + 10 ∗ R2..8 + D2..8︸ ︷︷ ︸295..725
= 90 ∗ N3..8 + Y 2..8︸ ︷︷ ︸272..728
91 ∗ E3..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N3..8 + Y 2..8︸ ︷︷ ︸295..725
N ≥ 4 = d295− 890
e
Helmut Simonis Basic Constraint Reasoning 31
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Propagation of equality (Iteration 4)
91 ∗ E3..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N4..8 + Y 2..8
91 ∗ E3..7 + 10 ∗ R2..8 + D2..8︸ ︷︷ ︸295..725
= 90 ∗ N4..8 + Y 2..8︸ ︷︷ ︸362..728
91 ∗ E3..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N4..8 + Y 2..8︸ ︷︷ ︸362..725
E ≥ 4 = d362− 8891
e
Helmut Simonis Basic Constraint Reasoning 32
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Propagation of equality (Iteration 5)
91 ∗ E4..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N4..8 + Y 2..8
91 ∗ E4..7 + 10 ∗ R2..8 + D2..8︸ ︷︷ ︸386..725
= 90 ∗ N4..8 + Y 2..8︸ ︷︷ ︸362..728
91 ∗ E4..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N4..8 + Y 2..8︸ ︷︷ ︸386..725
N ≥ 5 = d386− 890
e
Helmut Simonis Basic Constraint Reasoning 33
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Propagation of equality (Iteration 6)
91 ∗ E4..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N5..8 + Y 2..8
91 ∗ E4..7 + 10 ∗ R2..8 + D2..8︸ ︷︷ ︸386..725
= 90 ∗ N5..8 + Y 2..8︸ ︷︷ ︸452..728
91 ∗ E4..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N5..8 + Y 2..8︸ ︷︷ ︸452..725
N ≥ 5 = d452− 890
e, E ≥ 4 = d452− 8891
e
No further propagation at this point
Helmut Simonis Basic Constraint Reasoning 34
ProblemProgram
Constraint SetupSearch
Lessons Learned
Domain DefinitionAlldifferent ConstraintDisequality ConstraintsEquality Constraint
Domains after setup
0 1 2 3 4 5 6 7 8 9SENDMORY
Helmut Simonis Basic Constraint Reasoning 35
ProblemProgram
Constraint SetupSearch
Lessons Learned
Step 1Step 2Further StepsSolution
labeling built-in
labeling([S,E,N,D,M,O,R,Y])
Try variable is order givenTry values starting from smallest value in domainWhen failing, backtrack to last open choiceChronological BacktrackingDepth First search
Helmut Simonis Basic Constraint Reasoning 36
ProblemProgram
Constraint SetupSearch
Lessons Learned
Step 1Step 2Further StepsSolution
Search Tree Step 1
Variable S already fixed
1
21
Helmut Simonis Basic Constraint Reasoning 37
ProblemProgram
Constraint SetupSearch
Lessons Learned
Step 1Step 2Further StepsSolution
Step 2, Alternative E = 4
Variable E ∈ {4..7}, first value tested is 4
1
21
2
Helmut Simonis Basic Constraint Reasoning 38
ProblemProgram
Constraint SetupSearch
Lessons Learned
Step 1Step 2Further StepsSolution
Assignment E = 4
0 1 2 3 4 5 6 7 8 9SE Y - - -NDMORY
Helmut Simonis Basic Constraint Reasoning 39
ProblemProgram
Constraint SetupSearch
Lessons Learned
Step 1Step 2Further StepsSolution
Propagation of E = 4, equality constraint
91 ∗ 4 + 10 ∗ R2..8 + D2..8 = 90 ∗ N5..8 + Y 2..8
91 ∗ 4 + 10 ∗ R2..8 + D2..8︸ ︷︷ ︸386..452
= 90 ∗ N5..8 + Y 2..8︸ ︷︷ ︸452..728
91 ∗ 4 + 10 ∗ R2..8 + D2..8 = 90 ∗ N5..8 + Y 2..8︸ ︷︷ ︸452
N = 5, Y = 2, R = 8, D = 8
Helmut Simonis Basic Constraint Reasoning 40
ProblemProgram
Constraint SetupSearch
Lessons Learned
Step 1Step 2Further StepsSolution
Result of equality propagation
0 1 2 3 4 5 6 7 8 9SEN Y - - -D - - - - - - Y
MOR - - - - - - Y
Y Y - - - - - -
Helmut Simonis Basic Constraint Reasoning 41
ProblemProgram
Constraint SetupSearch
Lessons Learned
Step 1Step 2Further StepsSolution
Propagation of alldifferent
0 1 2 3 4 5 6 7 8 9S |E |N Y - - |D - - - - - - Y
M |O |R - - - - - - Y
Y Y - - - - - |
Alldifferent fails!
Helmut Simonis Basic Constraint Reasoning 42
ProblemProgram
Constraint SetupSearch
Lessons Learned
Step 1Step 2Further StepsSolution
Step 2, Alternative E = 5
Return to last open choice, E , and test next value
1
21
32
3
Helmut Simonis Basic Constraint Reasoning 43
ProblemProgram
Constraint SetupSearch
Lessons Learned
Step 1Step 2Further StepsSolution
Assignment E = 5
0 1 2 3 4 5 6 7 8 9SE - Y - -NDMORY
Helmut Simonis Basic Constraint Reasoning 44
ProblemProgram
Constraint SetupSearch
Lessons Learned
Step 1Step 2Further StepsSolution
Propagation of alldifferent
0 1 2 3 4 5 6 7 8 9SENDMORY
N 6= 5, N ≥ 6
Helmut Simonis Basic Constraint Reasoning 45
ProblemProgram
Constraint SetupSearch
Lessons Learned
Step 1Step 2Further StepsSolution
Propagation of equality
91 ∗ 5 + 10 ∗ R2..8 + D2..8 = 90 ∗ N6..8 + Y 2..8
91 ∗ 5 + 10 ∗ R2..8 + D2..8︸ ︷︷ ︸477..543
= 90 ∗ N6..8 + Y 2..8︸ ︷︷ ︸542..728
91 ∗ 5 + 10 ∗ R2..8 + D2..8 = 90 ∗ N6..8 + Y 2..8︸ ︷︷ ︸542..543
N = 6, Y ∈ {2, 3}, R = 8, D ∈ {7..8}
Helmut Simonis Basic Constraint Reasoning 46
ProblemProgram
Constraint SetupSearch
Lessons Learned
Step 1Step 2Further StepsSolution
Result of equality propagation
0 1 2 3 4 5 6 7 8 9SEN Y - -D 6 6 6 6
MOR - - - - - Y
Y 6 6 6 6
Helmut Simonis Basic Constraint Reasoning 47
ProblemProgram
Constraint SetupSearch
Lessons Learned
Step 1Step 2Further StepsSolution
Propagation of alldifferent
0 1 2 3 4 5 6 7 8 9SENDMORY
D = 7
Helmut Simonis Basic Constraint Reasoning 48
ProblemProgram
Constraint SetupSearch
Lessons Learned
Step 1Step 2Further StepsSolution
Propagation of equality
91 ∗ 5 + 10 ∗ 8 + 7 = 90 ∗ 6 + Y 2..3
91 ∗ 5 + 10 ∗ 8 + 7︸ ︷︷ ︸542
= 90 ∗ 6 + Y 2..3︸ ︷︷ ︸542..543
91 ∗ 5 + 10 ∗ 8 + 7 = 90 ∗ 6 + Y 2..3︸ ︷︷ ︸542
Y = 2
Helmut Simonis Basic Constraint Reasoning 49
ProblemProgram
Constraint SetupSearch
Lessons Learned
Step 1Step 2Further StepsSolution
Last propagation step
0 1 2 3 4 5 6 7 8 9SENDMORY Y -
Helmut Simonis Basic Constraint Reasoning 50
ProblemProgram
Constraint SetupSearch
Lessons Learned
Step 1Step 2Further StepsSolution
Complete Search Tree
1
21
3
4
5
6
7
82
3
4
5
6
7
8 7 6
9
Helmut Simonis Basic Constraint Reasoning 51
ProblemProgram
Constraint SetupSearch
Lessons Learned
Step 1Step 2Further StepsSolution
Solution
9 5 6 7+ 1 0 8 51 0 6 5 2
Helmut Simonis Basic Constraint Reasoning 52
ProblemProgram
Constraint SetupSearch
Lessons Learned
Topics introduced
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
L=[S,E,N,D,M,O,R,Y],L :: 0..9,[C2,C3,C4,C5] :: 0..1, é newalldifferent(L),S #\= 0,M #\= 0,M #= C5,S+M+C4 #= 10*C5+O,E+O+C3 #= 10*C4+N,N+R+C2 #= 10*C3+E,D+E #= 10*C2+Y,labeling(L).
Helmut Simonis Basic Constraint Reasoning 63
Alternative ModelsExercises
Model without DisequalityMultiple Equations
With Carry Variables: After Setup
0 1 2 3 4 5 6 7 8 9SENDMORY
Helmut Simonis Basic Constraint Reasoning 64
Alternative ModelsExercises
Model without DisequalityMultiple Equations
Setup Comparison
original alternative20 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 65
Alternative ModelsExercises
Model without DisequalityMultiple Equations
Search Tree: First Solution
1
21 2 3
3
4
5
6
7
81
4
5
6
7
8
9
Helmut Simonis Basic Constraint Reasoning 66
Alternative ModelsExercises
Model without DisequalityMultiple Equations
Comparison
Single Equation Multiple Equations
1
21
3
4
5
6
7
82
3
4
5
6
7
8 7 6
9
1
21 2 3
3
4
5
6
7
81
4
5
6
7
8
9 8 7 4
Helmut Simonis Basic Constraint Reasoning 67
Alternative ModelsExercises
Model without DisequalityMultiple Equations
Observations
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?
Helmut Simonis Basic Constraint Reasoning 69
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Chapter 5: Global Constraints(Sudoku)
Helmut Simonis
Cork Constraint Computation CentreComputer Science Department
University College CorkIreland
ECLiPSe ELearning Overview
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Outline
1 Problem
2 Program
3 Initial Propagation (Forward Checking)
4 Improved Reasoning
5 Search
6 Lessons Learned
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
What we want to introduce
Global ConstraintsPowerful modelling abstractionsNon-trivial propagation
Consistency LevelsTradeoff between speed and propagationCharacterisation of reasoning power
Example: Alldifferent3 variants shown
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Methodology
Evaluation on Sudoku puzzleComparing
Initial setupSearchPerformance
Explaining reasoning inside constraintLink to general classification of global constraints
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Problem Definition
SudokuFill in numbers from 1 to 9 so that each row, column and blockcontain each number exactly once
11 2 34 5 67 8 9 2
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 3 4
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 2
1 2 34 5 67 8 9
1 2 34 5 67 8 9 5 6
1 2 34 5 67 8 9
1 2 34 5 67 8 9 7
1 2 34 5 67 8 9
1 2 34 5 67 8 9 2 6 8
1 2 34 5 67 8 9
1 2 34 5 67 8 9 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 2
1 2 34 5 67 8 9
1 2 34 5 67 8 9 5 4 7
1 2 34 5 67 8 9
1 2 34 5 67 8 9 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
6 41 2 34 5 67 8 9
1 2 34 5 67 8 9 8
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 3 1
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 7
1 2 34 5 67 8 9 1
1 2 3 4 5 6 7 8 96 4 9 7 8 2 1 5 38 5 7 1 3 9 4 6 27 1 5 6 9 3 2 4 84 9 2 8 1 7 6 3 53 6 8 5 2 4 9 1 72 8 1 9 4 5 3 7 65 3 6 2 7 1 8 9 49 7 4 3 6 8 5 2 1
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Model
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
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Reminder: alldifferent
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
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Declarations
:-module(sudoku).:-export(top/0).:-lib(ic).
top:-problem(Matrix),model(Matrix),writeln(Matrix).
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Data
problem([]([](4, _, 8, _, _, _, _, _, _),[](_, _, _, 1, 7, _, _, _, _),[](_, _, _, _, 8, _, _, 3, 2),[](_, _, 6, _, _, 8, 2, 5, _),[](_, 9, _, _, _, _, _, 8, _),[](_, 3, 7, 6, _, _, 9, _, _),[](2, 7, _, _, 5, _, _, _, _),[](_, _, _, _, 1, 4, _, _, _),[](_, _, _, _, _, _, 6, _, 4))).
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Main Program
model(Matrix):-Matrix[1..9,1..9] :: 1..9,(for(I,1,9),param(Matrix) do
alldifferent(Matrix[I,1..9]),alldifferent(Matrix[1..9,I])
),(multifor([I,J],[1,1],[7,7],[3,3]),param(Matrix) do
alldifferent(flatten(Matrix[I..I+2,J..J+2]))),flatten_array(Matrix,List),labeling(List).
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Domain Visualizer
11 2 34 5 67 8 9 2
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 3 4
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 2
1 2 34 5 67 8 9
1 2 34 5 67 8 9 5 6
1 2 34 5 67 8 9
1 2 34 5 67 8 9 7
1 2 34 5 67 8 9
1 2 34 5 67 8 9 2 6 8
1 2 34 5 67 8 9
1 2 34 5 67 8 9 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 2
1 2 34 5 67 8 9
1 2 34 5 67 8 9 5 4 7
1 2 34 5 67 8 9
1 2 34 5 67 8 9 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
6 41 2 34 5 67 8 9
1 2 34 5 67 8 9 8
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 3 1
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 7
1 2 34 5 67 8 9 1
Problem shown as matrixEach cell corresponds to a variableInstantiated: Shows integer value (large)Uninstantiated: Shows values in domain
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Constraint Visualizer
11 23 4 2
2 536
2 546
2 53 46
13
7
14
7 6
13 4
7 6546
23 4
536 3 4
2 53 468 39
8 46
3 49 6
47 6
13 4
1368 3
6 2 3 46
18 37 5 6
3 1 75
7 6
5
6 2 6 85
7 6
8 9 65
87
58
1 5
7
1 587 2
1 54
7
2 5 4 7 6 8 9 1 36 4
1 58
6
589 6 8
1 546
1 589
18 4
6
1 54
9 654
7 6
23 49
536
2 53
7 9 6 3 15
37 9
24
7 6
53 4
7 9 65
7 6
1 239
1 536
2 53
7 9 6
2 5
6
1 2 53
7 6 71 2
7 6 1
Problem shown as matrixCurrently active constraint highlightedValues removed at this step shown in blueValues assigned at this step shown in red
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Initial State (Forward Checking)
11 2 34 5 67 8 9 2
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 3 4
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 2
1 2 34 5 67 8 9
1 2 34 5 67 8 9 5 6
1 2 34 5 67 8 9
1 2 34 5 67 8 9 7
1 2 34 5 67 8 9
1 2 34 5 67 8 9 2 6 8
1 2 34 5 67 8 9
1 2 34 5 67 8 9 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 2
1 2 34 5 67 8 9
1 2 34 5 67 8 9 5 4 7
1 2 34 5 67 8 9
1 2 34 5 67 8 9 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
6 41 2 34 5 67 8 9
1 2 34 5 67 8 9 8
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 3 1
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 7
1 2 34 5 67 8 9 1
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Propagation Steps (Forward Checking)
11 23 4 2
2 536
2 546
2 53 46
13
7
14
7 6
13 4
7 6546
23 4
536 3 4
2 53 468 39
8 46
3 49 6
47 6
13 4
1368 3
6 2 3 46
18 37 5 6
3 1 75
7 6
5
6 2 6 85
7 6
8 9 65
87
58 4
1 54
7
1 587 2
1 54
7
2 5 4 72
81 23 9
1 28
13
6 41 58
6
589 6 8
1 546
1 589
18 4
6
1 54
9 654
7 6
23 49
536
2 53
7 9 6 3 15
37 9
24
7 6
53 4
7 9 65
7 6
1 239
1 536
2 53
7 9 6
2 5
6
1 2 53
7 6 71 2
7 6 1
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
After Setup (Forward Checking)
11 23 4 2
2 536
546
2 546
13
7
14
7 63 4
7 6546
23 4
536 3 4
2 5468 39
46
3 49 6
47 6
13 4
1368 3
6 2 46
18 37 5 6
3 1 75
7 6
5
6 2 6 85
7
8 9 65
87
58
1 5
7
5
7 254
7
2 5 4 7 6 8 9 1 36 4
1 58
6
5
9 6 8546
1 5
9
1
6
5
9 6546
3 49
536
2 5
7 9 6 3 15
37 9
2
7 6
53
7 9 65
6
139
1 536
2 5
7 9 6
5
6
2 5
7 6 71 2
7 6 1
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Can we do better?
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
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
A Simpler Example
:-lib(ic).
top:-X :: 1..2,Y :: 1..2,Z :: 1..3,alldifferent([X,Y,Z]),writeln([X,Y,Z]).
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Using Forward Checking
No variable is assignedNo reduction of domainsBut, values 1 and 2 can be removed from ZThis means that Z is assigned to 3
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Visualization of alldifferent as Graph
X
Y
Z
1
2
3Show problem as graph with two types of nodes
Variables on the leftValues on the right
If value is in domain of variable, show link between themThis is called a bipartite graph
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
A Simpler Example
Value Graph for
X :: 1..2,
Y :: 1..2,
Z :: 1..3
X
Y
Z
1
2
3
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
A Simpler Example
Check interval [1,2]X
Y
Z
1
2
3
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
A Simpler Example
Find variables completelycontained in intervalThere are two: X and YThis uses up the capacity of theinterval
X
Y
Z
1
2
3
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
A Simpler Example
No other variable can use thatinterval
X
Y
Z
1
2
3
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
A Simpler Example
Only one value left in domain of Z,this can be assigned
X
Y
Z
1
2
3
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Idea (Hall Intervals)
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
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Implementation
Problem: Too many intervals (O(n2)) to considerSolution:
Check only those intervals which update boundsEnumerate intervals incrementallyStarting from lowest(highest) valueUsing sorted list of variables
Complexity: O(n log(n)) in standard implementationsImportant: Only looks at min/max bounds of variables
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Bounds Consistency
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.
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Can we do better?
Bounds consistency only considers min/max boundsIgnores “holes” in domainSometimes we can improve propagation looking at thoseholes
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Another Simple Example
:-lib(ic).
top:-X :: [1,3],Y :: [1,3],Z :: 1..3,alldifferent([X,Y,Z]),writeln([X,Y,Z]).
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Another Simple Example
Value Graph for
X :: [1,3],
Y :: [1,3],
Z :: 1..3
X
Y
Z
1
2
3
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Another Simple Example
Check interval [1,2]No domain of a variablecompletely contained in intervalNo propagation
X
Y
Z
1
2
3
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Another Simple Example
Check interval [2,3]No domain of a variablecompletely contained in intervalNo propagation
X
Y
Z
1
2
3
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Another Simple Example
But, more propagation is possible,there are only two solutions
X
Y
Z
1
2
3
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Another Simple Example
Solution 1: assignment in blueX
Y
Z
1
2
3
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Another Simple Example
Solution 2: assignment in greenX
Y
Z
1
2
3
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Another Simple Example
Solution 1 Solution 2 CombinedX
Y
Z
1
2
3
X
Y
Z
1
2
3
X
Y
Z
1
2
3
Combining solutions shows that Z=1 andZ=3 are not possible. Can we deduce thiswithout enumerating solutions?
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Solutions and maximal matchings
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
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Implementation
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)
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Domain Consistency
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
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Can we still do better?
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
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Should all constraints achieve domain consistency?
Domain consistency is usually more expensive thanbounds consistency
Overkill for simple problemsNice to have choices
For some constraints achieving domain consistency isNP-hard
We have to live with more restricted propagation
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Improved Propagation in ECLiPSe
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
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Declarations
:-module(sudoku).:-export(top/0).:-lib(ic).:-lib(ic_global).:-lib(ic_global_gac).
top:-problem(Matrix),model(ic_global,Matrix),writeln(Matrix).
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Main Program
model(Method,Matrix):-Matrix[1..9,1..9] :: 1..9,(for(I,1,9),param(Method,Matrix) do
Method:alldifferent(Matrix[I,1..9]),Method:alldifferent(Matrix[1..9,I])
),(multifor([I,J],[1,1],[7,7],[3,3]),param(Method,Matrix) do
Method:alldifferent(flatten(Matrix[I..I+2,J..J+2]))
),flatten_array(Matrix,List),labeling(List).
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Initial State (Bounds Consistency)
11 2 34 5 67 8 9 2
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 3 4
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 2
1 2 34 5 67 8 9
1 2 34 5 67 8 9 5 6
1 2 34 5 67 8 9
1 2 34 5 67 8 9 7
1 2 34 5 67 8 9
1 2 34 5 67 8 9 2 6 8
1 2 34 5 67 8 9
1 2 34 5 67 8 9 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 2
1 2 34 5 67 8 9
1 2 34 5 67 8 9 5 4 7
1 2 34 5 67 8 9
1 2 34 5 67 8 9 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
6 41 2 34 5 67 8 9
1 2 34 5 67 8 9 8
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 3 1
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 7
1 2 34 5 67 8 9 1
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Propagation Steps (Bounds Consistency)
11 23 4 2 3 4
2 53 46
13
7
14
7 6
13 4
7 6546
23 4
536 5 6
2 53 468 39
8 46
3 49 6
6 4136 1 2 7
18 3 8 9
5 1 45
7 6
5
6 2 9 35
7 6
3 7 95
87
58 4 5
1 587 2 4
2 8 6 4 9 3 7 1 59 6 1
589 6 3 4
1 589
18 4
6
1 54
9 6
423 49
536
2 53
7 9 6 5 15
37 9
24
7 6
53 4
7 9 65
6
1 239
1 536
2 53
7 9 6
2 5
6 6 41 2
7 6 1
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
After Setup (Bounds Consistency)
11 2
2 3 42 3 1
4
1
4 5 4 53
5
26
3
5 5 62 3
7 68
95
68 5
6 416 1 2 7
16 8 9
5 1 43
4 5
3
5 2 9 33
4
3 7 93
4
37 5
3
4 2 42 8 6 4 9 3 7 1 59 6 1
3
8 5 3 41 3
8
1
5
3
8 5
4 68
3
5
2 3
8 5 5 13
64 8
2
4 5
36
4 8 53
5
168
16
2
8
3
5 6 41 2
1
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Initial State (Domain Consistency)
11 2 34 5 67 8 9 2
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 3 4
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 2
1 2 34 5 67 8 9
1 2 34 5 67 8 9 5 6
1 2 34 5 67 8 9
1 2 34 5 67 8 9 7
1 2 34 5 67 8 9
1 2 34 5 67 8 9 2 6 8
1 2 34 5 67 8 9
1 2 34 5 67 8 9 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 2
1 2 34 5 67 8 9
1 2 34 5 67 8 9 5 4 7
1 2 34 5 67 8 9
1 2 34 5 67 8 9 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
6 41 2 34 5 67 8 9
1 2 34 5 67 8 9 8
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 3 1
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9
1 2 34 5 67 8 9 7
1 2 34 5 67 8 9 1
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Propagation Steps (Domain Consistency)
1 2 3 4 5 6 71
23 4
15 2
3 4624 4
654 7 8 2 1 5 3
8 5 7 1 3 9 4 6 27 1 5
6
3 4
6
4 3 2 46
3 4
4 9 26
3 1 71 673 3 5
3 6 8 5 2 4 9 1 72 8 1
6
8 4 4 5 3 71 6
28 4
5 36
54 2 7 1
65
3 8
92
3 4 46
4 7 4 39 6
4 8 5 2 1
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
After Setup (Domain Consistency)
1 2 3 4 5 6 7 1 2 1 23
2 43
2 7 8 2 1 5 38 5 7 1 3 9 4 6 27 1 5
3
1 2
3
2 3 2 43
1
4 9 23
1 1 73
1 3 53 6 8 5 2 4 9 1 72 8 1
3
2 4 5 3 73
2
5 33
2 2 7 13
1 1 2 43
2 7 4 33
2 8 5 2 1
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Comparison
Forward Checking Bounds Consistency Domain Consistency1
1 23 4 2
2 536
546
2 546
13
7
14
7 63 4
7 6546
23 4
536 3 4
2 5468 39
46
3 49 6
47 6
13 4
1368 3
6 2 46
18 37 5 6
3 1 75
7 6
5
6 2 6 85
7
8 9 65
87
58
1 5
7
5
7 254
7
2 5 4 7 6 8 9 1 36 4
1 58
6
5
9 6 8546
1 5
9
1
6
5
9 6546
3 49
536
2 5
7 9 6 3 15
37 9
2
7 6
53
7 9 65
6
139
1 536
2 5
7 9 6
5
6
2 5
7 6 71 2
7 6 1
11 2
2 3 42 3 1
4
1
4 5 4 53
5
26
3
5 5 62 3
7 68
95
68 5
6 416 1 2 7
16 8 9
5 1 43
4 5
3
5 2 9 33
4
3 7 93
4
37 5
3
4 2 42 8 6 4 9 3 7 1 59 6 1
3
8 5 3 41 3
8
1
5
3
8 5
4 68
3
5
2 3
8 5 5 13
64 8
2
4 5
36
4 8 53
5
168
16
2
8
3
5 6 41 2
1
1 2 3 4 5 6 7 1 2 1 23
2 43
2 7 8 2 1 5 38 5 7 1 3 9 4 6 27 1 5
3
1 2
3
2 3 2 43
1
4 9 23
1 1 73
1 3 53 6 8 5 2 4 9 1 72 8 1
3
2 4 5 3 73
2
5 33
2 2 7 13
1 1 2 43
2 7 4 33
2 8 5 2 1
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Bounds ConsistencyDomain ConsistencyComparison
Typical?
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
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Solution
Simple search routine
Enumerate variables in given orderTry values starting from smallest one in domainComplete, chronological backtracking
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Solution
Search Tree (Forward Checking)
1
2
31 2 3
4
32 3
1 5 3
6
2
32 3
1
31
4
57
6
2
5
4
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Solution
Search Tree (Bounds Consistency)
11
22
3
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Solution
Search Tree (Domain Consistency)
11
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Solution
Observations
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!
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Solution
Solution
1 2 3 4 5 6 7 8 96 4 9 7 8 2 1 5 38 5 7 1 3 9 4 6 27 1 5 6 9 3 2 4 84 9 2 8 1 7 6 3 53 6 8 5 2 4 9 1 72 8 1 9 4 5 3 7 65 3 6 2 7 1 8 9 49 7 4 3 6 8 5 2 1
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Global Constraints
Powerful modelling abstractionsEfficient reasoning
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Consistency Levels
Defined levels of propagationTradeoff speed/reasoningCharacterisation of power of constraint
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
Alldifferent Variants
Forward CheckingOnly reacts when variables are assignedEquivalent to decomposition into binary constraints
Bounds ConsistencyTypical best compomise speed/reasoningWorks well if no holes in domain
Domain ConsistencyExtracts all information from single constraintCost only justified for very hard problems
Helmut Simonis Global Constraints
ProblemProgram
Initial Propagation (Forward Checking)Improved Reasoning
SearchLessons Learned
End of Chapter 5
Thank you!Some optional material follows
Helmut Simonis Global Constraints
Complete Example: Domain Consistent AlldifferentGeneric Model
Exercises
Bigger Example
:-lib(ic).:-lib(ic_global_gac).
top:-[X,Y] :: 1..2,Z :: 2..5,[T,U] :: 3..5,V :: [2,4,6,7],ic_global_gac:alldifferent([X,Y,Z,T,U,V]).
Helmut Simonis Global Constraints
Complete Example: Domain Consistent AlldifferentGeneric Model
Exercises
Making constraint domain consistentProblem 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
Making constraint domain consistentFind 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
Making constraint domain consistentOrient 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
Making constraint domain consistentFind 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
Making constraint domain consistentFind 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
Making constraint domain consistentFind 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
Making constraint domain consistentAll unmarked edges can be removedX
Y
Z
T
U
V
1
2
3
4
5
6
7Helmut Simonis Global Constraints
Complete Example: Domain Consistent AlldifferentGeneric Model
Exercises
Making constraint domain consistentResulting graph, constraint is domainconsistent
X
Y
Z
T
U
V
1
2
3
4
5
6
7Helmut Simonis Global Constraints
Complete Example: Domain Consistent AlldifferentGeneric Model
Exercises
Extended Example
:-lib(ic).:-lib(ic_global_gac).
top:-X :: 1..2,Y :: [1,2,7],Z :: 2..5,[T,U] :: 3..5,V :: [2,4,6,7],ic_global_gac:alldifferent([X,Y,Z,T,U,V]).
Helmut Simonis Global Constraints
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
M:alldifferent(Matrix[I,1..N]),M:alldifferent(Matrix[1..N,I])
),(multifor([I,J],[1,1],[N-R+1,N-R+1],[R,R]),param(R,M,Matrix) do
M:alldifferent(flatten(Matrix[I..I+R-1,J..J+R-1]))
),flatten_array(Matrix,List),labeling(List).
Helmut Simonis Global Constraints
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.
Helmut Simonis Search Strategies 2
ProblemProgram
Naive SearchImprovements
Outline
1 Problem
2 Program
3 Naive Search
4 Improvements
Helmut Simonis Search Strategies 3
ProblemProgram
Naive SearchImprovements
What we want to introduce
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
Helmut Simonis Search Strategies 7
ProblemProgram
Naive SearchImprovements
ModelProgram (Array version)Program (List Version)
Basic Model
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
Helmut Simonis Search Strategies 8
ProblemProgram
Naive SearchImprovements
ModelProgram (Array version)Program (List Version)
Model
assign [X1, X2, ...XN ]
s.t.
∀1 ≤ i ≤ N : Xi ∈ 1..N∀1 ≤ i < j ≤ N : Xi 6= Xj
∀1 ≤ i < j ≤ N : Xi 6= Xj + i − j∀1 ≤ i < j ≤ N : Xi 6= Xj + j − i
Helmut Simonis Search Strategies 9
ProblemProgram
Naive SearchImprovements
ModelProgram (Array version)Program (List Version)
Main Program (Array Version)
:-module(array).:-export(top/0).:-lib(ic).
top:-nqueen(8,Array), writeln(Array).
nqueen(N,Array):-dim(Array,[N]),Array[1..N] :: 1..N,alldifferent(Array[1..N]),noattack(Array,N),labeling(Array[1..N]).
Helmut Simonis Search Strategies 10
ProblemProgram
Naive SearchImprovements
ModelProgram (Array version)Program (List Version)
Generating binary constraints
noattack(Array,N):-(for(I,1,N-1),param(Array,N) do
(for(J,I+1,N),param(Array,I) do
subscript(Array,[I],Xi),subscript(Array,[J],Xj),D is I-J,Xi #\= Xj+D,Xj #\= Xi+D
)).
Helmut Simonis Search Strategies 11
ProblemProgram
Naive SearchImprovements
ModelProgram (Array version)Program (List Version)
Main Program (List Version)
:-module(nqueen).:-export(top/0).:-lib(ic).
top:-nqueen(8,L), writeln(L).
nqueen(N,L):-length(L,N),L :: 1..N,alldifferent(L),noattack(L),labeling(L).
Helmut Simonis Search Strategies 12
ProblemProgram
Naive SearchImprovements
ModelProgram (Array version)Program (List Version)
Generating binary constraints
noattack([]).noattack([H|T]):-
noattack1(H,T,1),noattack(T).
noattack1(_,[],_).noattack1(X,[Y|R],N):-
X #\= Y+N,Y #\= X+N,N1 is N+1,noattack1(X,R,N1).
Helmut Simonis Search Strategies 13
ProblemProgram
Naive SearchImprovements
Default Strategy
1
2
31
42 3
4
4
55 3
2
6
42 4
3
7
3
41 6 3
2
47 3
4
4
54 3
7 1
6
47 1
3
5
3
44
57 4
3
2
4
55 4
2
6
4
55 6
2
5
6
7
85
2
6
7
4
3
1
8
Helmut Simonis Search Strategies 14
ProblemProgram
Naive SearchImprovements
First Solution
1
2
31
42 3
4
4
55 3
2
6
42 4
3
7
3
41 6 3
2
47 3
4
4
54 3
7 1
6
47 1
3
5
3
44
57 4
3
2
4
55 4
2
6
4
55 6
2
5
6
7
85
2
6
7
4
3
1
8
Helmut Simonis Search Strategies 15
ProblemProgram
Naive SearchImprovements
Observations
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
Modification of Program
:-module(nqueen).:-export(top/0).:-lib(ic).
top:-nqueen(8,L), writeln(L).
nqueen(N,L):-length(L,N),L :: 1..N,alldifferent(L),noattack(L),search(L,0,first_fail,indomain,complete,[]).
Helmut Simonis Search Strategies 25
ProblemProgram
Naive SearchImprovements
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
Comparison
Board size 16x16Naive (Input Order) StrategyFirst Fail variable selection
Helmut Simonis Search Strategies 30
ProblemProgram
Naive SearchImprovements
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
Modified Program
:-module(nqueen).:-export(top/0).:-lib(ic).top:-
nqueen(16,L),writeln(L).
nqueen(N,L):-length(L,N),L :: 1..N,alldifferent(L),noattack(L),reorder(L,R),
search(R,0,first_fail,indomain_middle,complete,[]).
Helmut Simonis Search Strategies 37
ProblemProgram
Naive SearchImprovements
Dynamic Variable ChoiceImproved HeuristicsMaking Search More Stable
Reordering Variable List
reorder(L,L1):-halve(L,L,[],Front,Tail),combine(Front,Tail,L1).
halve([],Tail,Front,Front,Tail).halve([_],Tail,Front,Front,Tail).halve([_,_|R],[F|T],Front,Fend,Tail):-
halve(R,T,[F|Front],Fend,Tail).
combine(C,[],C):-!.combine([],C,C).combine([A|A1],[B|B1],[B,A|C1]):-
combine(A1,B1,C1).
Helmut Simonis Search Strategies 38
ProblemProgram
Naive SearchImprovements
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
Credit based search
:-module(nqueen).:-export(top/0).:-lib(ic).top:-
nqueen(8,L),writeln(L).
nqueen(N,L):-length(L,N),L :: 1..N,alldifferent(L),noattack(L),reorder(L,R),search(R,0,first_fail,indomain_middle, credit(N,5),[]).
Helmut Simonis Search Strategies 47
ProblemProgram
Naive SearchImprovements
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?
Helmut Simonis Search Strategies 53
ProblemProgram
Search
Chapter 7: Optimization (Routing andWavelength Assignment)
Helmut Simonis
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.
Helmut Simonis Optimization 2
ProblemProgram
Search
Outline
1 Problem
2 Program
3 Search
Helmut Simonis Optimization 3
ProblemProgram
Search
What We Want to Introduce
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
Basic Shortest Path Method
single_pair_shortest_path(Network,-1,From,To,Result)
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
Library branch_and_bound
bb_min(Goal,Cost,bb_options{})
Goal search goalLike search/6 or labeling/1 call
Cost objective (domain variable)bb_options optional parameters
timeout:Time timeout limit in secondsfrom:LowerBound known lower boundto:UpperBound known upper bound
Helmut Simonis Optimization 19
ProblemProgram
Search
Problem 1: Find routingProblem 2: Assign Wavelengths
Example
...List :: 1..20,...ic:max(List,Max),bb_min(labeling(List),Max,
bb_options{timeout:100,from:10}),...
Helmut Simonis Optimization 20
ProblemProgram
Search
Problem 1: Find routingProblem 2: Assign Wavelengths
ic Constraint max(List,Var)
Var is the largest value occuring in List
Similar min(List,Var)Do not confuse with max in core language
Helmut Simonis Optimization 21
ProblemProgram
Search
Main Program
:-module(pure).:-export(top/5).:-lib(ic).:-lib(ic_global).:-lib(graph_algorithms).:-lib(branch_and_bound).
top(Name,NrDemands,LowerBound,Assignment,Max):-problem(Name,NrDemands,Network,Demands),route(Network,Demands,Routes),wave(NrDemands,Routes,
LowerBound,Assignment,Max).
Helmut Simonis Optimization 22
ProblemProgram
Search
Routing
route(Network,Demands,Routes):-(foreach(demand(I,From,To),Demands),foreach(route(I,Path),Routes),param(Network) do
single_pair_shortest_path(Network,-1,From,To,_-Path)
).
Helmut Simonis Optimization 23
ProblemProgram
Search
Wavelength Assignment
wave(NrDemands,Routes,LowerBound,Var,Max):-dim(Var,[NrDemands]),Var[1..NrDemands] :: 1..NrDemands,ic:max(Var,Max),setup_alldifferent(Routes,Var,LowerBound),bb_min(assign(Var),Max,
bb_options{from:LowerBound,timeout:100}).
Helmut Simonis Optimization 24
ProblemProgram
Search
Assignment Routine
assign(Var):-search(Var,0,most_constrained,indomain,
complete,[]).
Helmut Simonis Optimization 25
ProblemProgram
Search
Variable Selection Method most_constrained
Similar to first_fail
Select vairable with smallest domain firstFor tie break, select variable in largest number ofconstraints
Helmut Simonis Optimization 26
ProblemProgram
Search
Creating alldifferent Constraints
setup_alldifferent(Routes,Var,LowerBound):-(foreach(route(I,Path),Routes),fromto([],A,A1,Pairs) do
(foreach(Edge,Path),fromto(A,AA,[l(Edge,I)|AA],A1),param(I) do
true)
),group(Pairs,1,Groups),...
Helmut Simonis Optimization 27
ProblemProgram
Search
Creating alldifferent Constraints (II)
...(foreach(_-Group,Groups),fromto(0,A,A1,LowerBound),param(Var) do
length(Group,N),A1 is eclipse_language:max(N,A),(foreach(l(_,I),Group),foreach(X,AlldifferentVars),param(Var) do
subscript(Var,[I],X)),ic_global:alldifferent(AlldifferentVars)
).
Helmut Simonis Optimization 28
ProblemProgram
Search
Generating Data
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,!
).
Helmut Simonis Optimization 29
ProblemProgram
Search
Example Network: MCI
1
2
3
4
5
12
6
7
1811
17
9
19
115
16 13
14
Helmut Simonis Optimization 30
ProblemProgram
Search
MCI Topology Data
network_topology(mci,19,[e(1,2,1),e(1,5,1),e(1,6,1),e(2,3,1),e(2,5,1),e(2,12,1),e(3,4,1),e(4,5,1),e(4,8,1),e(4,10,1),e(5,6,1),e(6,11,1),e(6,12,1),e(6,18,1),e(7,8,1),e(7,9,1),e(8,10,1),e(8,11,1),e(8,12,1),e(9,10,1),e(10,17,1),e(10,19,1),e(11,12,1),e(12,13,1),e(12,18,1),e(13,14,1),e(14,18,1),e(15,18,1),e(16,17,1),e(16,18,1),e(17,18,1),e(17,19,1)]).
Helmut Simonis Optimization 31
ProblemProgram
Search
Searchtree
1
23
44
51
53
26
78
16
15
63
95
7
4
62
3
7
35
6
7
61
65
71
1
39
5
68
3
92
17
18
43
46
76
31
91
99
75
6
14
58
5
69
47
3
73
79
8
64
21
98
38
32
33
66
57
13
4
67
94
59
27
2
45
6
1
37
11
22
93
41
9
96
52
34
9
9
36
97
24
55
19
54
56
77
42
25
29
2
74
288
4
72
49
48
5
28
2
121
1
2
1
1
3
2
2
4
5
6
3
3
7
2
3
2
2
1
1
4
5
6
7
1
3
1
6
3
7
6
2
5
6
1
8
9
7
9
4
5
6
1
7
9
4
5
6
7
3
1
7
2
5
6
3
1
3
2
692
47
3
73
79
8
64
21
98
32
33
66
38
13
4
67
94
59
27
2
1
6
11
22
93
41
9
96
52
34
9
9
36
97
24
55
77
25
42
29
2
74
288
19
54
56
4
72
49
48
5
28
2
121
1
2
1
1
3
1
2
3
2
2
4
5
6
3
2
3
7
2
1
4
5
6
7
1
1
1
6
3
7
6
2
5
1
7
2
4
5
6
1
7
7
4
5
6
3
1
7
2
5
6
3
1
6
3
9
4
5
6
2
3
1
6
2
7
3
1
4
7
2
1
9
4
5
6
7
2
3
1
9
4
6
3
7
2
6
1
5
3
7
2
6
3
7
2
1
Helmut Simonis Optimization 32
ProblemProgram
Search
Initial State
Helmut Simonis Optimization 33
ProblemProgram
Search
Update Cost
Helmut Simonis Optimization 34
ProblemProgram
Search
First Solution
Helmut Simonis Optimization 35
ProblemProgram
Search
Continue Search
Helmut Simonis Optimization 36
ProblemProgram
Search
Optimal Solution
Helmut Simonis Optimization 37
ProblemProgram
Search
Observations
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
Helmut Simonis Optimization 39
ProblemProgram
Search
Multiple Runs (100 experiments)
Network Nr Demands Avg LB Avg Sol Σ Sol Avg Gapmci 20 3.71 3.71 0.711 0.00mci 40 5.85 5.85 0.931 0.00mci 60 7.69 7.69 1.324 0.00mci 80 9.48 9.48 1.353 0.00mci 100 11.34 11.34 1.687 0.00mci 120 12.89 12.89 1.928 0.00mci 140 14.59 14.59 2.298 0.00mci 160 16.28 16.28 2.421 0.00mci 180 17.89 17.89 2.656 0.00mci 200 19.52 19.52 2.456 0.00
Helmut Simonis Optimization 40
ProblemProgram
Search
Conclusions
These are not hard problem instancesIn general, graph coloring can be much more difficultFast, simple solution to RWA problemQuality gap to be determined
Helmut Simonis Optimization 41
ProblemProgram
Symmetry Breaking
Chapter 8: Symmetry Breaking (BalancedIncomplete Block Designs)
Helmut Simonis
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.
Helmut Simonis Symmetry Breaking 2
ProblemProgram
Symmetry Breaking
Outline
1 Problem
2 Program
3 Symmetry Breaking
Helmut Simonis Symmetry Breaking 3
ProblemProgram
Symmetry Breaking
What we want to introduce
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 λ.
Helmut Simonis Symmetry Breaking 8
ProblemProgram
Symmetry Breaking
Top Level Program
:-module(bibd).:-export(top/0).:-lib(ic).:-lib(ic_global).
top:-bibd(6,10,5,3,2,Matrix),writeln(Matrix).
bibd(V,B,R,K,L,Matrix):-model(V,B,R,K,L,Matrix),é Set up modelextract_array(row,Matrix,List),é Get listsearch(L,0,input_order,indomain,
complete,[]).é Search
Helmut Simonis Symmetry Breaking 9
ProblemProgram
Symmetry Breaking
Constraint Model
model(V,B,R,K,L,Matrix,Method):-dim(Matrix,[V,B]),é Define Binary MatrixMatrix[1..V,1..B] :: 0..1,(for(I,1,V), param(Matrix,B,R) do
sumlist(Matrix[I,1..B],R)),é Row Sum = R(for(J,1,B), param(Matrix,V,K) do
sumlist(Matrix[1..V,J],K)),é Column Sum = K(for(I,1,V-1), param(Matrix,V,B,L) do
(for(I1,I+1,V), param(Matrix,I,B,L) doscalar_product(Matrix[I,1..B],
Matrix[I1,1..B],L))
).é 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
Helmut Simonis Symmetry Breaking 12
ProblemProgram
Symmetry Breaking
Basic Model - First Solution
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
Helmut Simonis Symmetry Breaking 13
ProblemProgram
Symmetry Breaking
Finding all solutions - Hack!
:-module(bibd).:-export(top/0).:-lib(ic).:-lib(ic_global).
top:-bibd(6,10,5,3,2,Matrix),writeln(Matrix),fail.é Force Backtracking
bibd(V,B,R,K,L,Matrix):-model(V,B,R,K,L,Matrix),extract_array(row,Matrix,List),search(L,0,input_order,indomain,
complete,[]).
Helmut Simonis Symmetry Breaking 14
ProblemProgram
Symmetry Breaking
Finding all solutions - Proper
:-module(bibd).:-export(top/0).:-lib(ic).:-lib(ic_global).
top:-findall(Matrix,bibd(6,10,5,3,2,Matrix),Sols),writeln(Sols).
bibd(V,B,R,K,L,Matrix):-model(V,B,R,K,L,Matrix),extract_array(row,Matrix,List),search(L,0,input_order,indomain,
complete,[]).
Helmut Simonis Symmetry Breaking 15
ProblemProgram
Symmetry Breaking
findall predicate
findall(Template,Goal,Collection)
Finds all solutions to Goal and collects them into a listCollection
Template is used to extract arguments from Goal tostore as solutionBacktracks through all choices in Goal
Solutions are returned in order in which they are found
Helmut Simonis Symmetry Breaking 16
ProblemProgram
Symmetry Breaking
Problem
Program now only stops when it has found all solutionsThis takes too long!How can we limit the amount of time to wait?Use of the timeout library
Helmut Simonis Symmetry Breaking 17
ProblemProgram
Symmetry Breaking
Finding all solutions - Proper
:-module(bibd).:-export(top/0).:-lib(ic).:-lib(ic_global).:-lib(timeout).é Load library
top:-findall(Matrix,timeout(bibd(6,10,5,3,2,Matrix),
10,é secondsfail),Sols),
writeln(Sols).
Helmut Simonis Symmetry Breaking 18
ProblemProgram
Symmetry Breaking
timeout library
timeout(Goal,Limit,TimeoutGoal)
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
Alternative Value Order
:-module(bibd).:-export(top/0).:-lib(ic).:-lib(ic_global).
top:-bibd(6,10,5,3,2,Matrix),writeln(Matrix).
bibd(V,B,R,K,L,Matrix):-model(V,B,R,K,L,Matrix),extract_array(row,Matrix,List),search(L,0,input_order,
indomain_max,é Start with 1complete,[]).
Helmut Simonis Symmetry Breaking 36
ProblemProgram
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.
Helmut Simonis Choosing the Model 2
ProblemModel
ProgramSearch
Redundant Modelling
Outline
1 Problem
2 Model
3 Program
4 Search
5 Redundant Modelling
Helmut Simonis Choosing the Model 3
ProblemModel
ProgramSearch
Redundant Modelling
What we want to introduce
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
Helmut Simonis Choosing the Model 6
ProblemModel
ProgramSearch
Redundant Modelling
Solution
City 1 City 2 City 3 City 4 City 5 City 6 City 7Day 1 6, 8 1, 2 5, 7 3, 4Day 2 2, 3 1, 5 4, 8 6, 7Day 3 1, 7 2, 4 3, 8 5, 6Day 4 4, 7 2, 6 3, 5 1, 8Day 5 5, 8 3, 6 1, 4 2, 7Day 6 3, 7 1, 6 4, 5 2, 8Day 7 4, 6 2, 5 7, 8 1, 3
Helmut Simonis Choosing the Model 7
ProblemModel
ProgramSearch
Redundant Modelling
A More Abstract Formulation
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
Day 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
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
Day 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
element(Cell,[1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,5,5,5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7],Row),
element(Cell,[1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7],Col),
Helmut Simonis Choosing the Model 35
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
Day 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
element(23 ,[1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,5,5,5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7],4 ),
element(23 ,[1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7],2 ),
Helmut Simonis Choosing the Model 36
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Channeling Constraints
This is one common type, a projectionAnother common type is the inverse
Link a variable A→ B to another B → ATypically used for bijective mappingsBuilt-in inverse/2
Also used: Boolean channelingLink variables A→ B and A× B → {0, 1}Built-in bool_channeling/3
Helmut Simonis Choosing the Model 37
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Selected Model
Two sets of variables (Req 1, 2, 3, 6, by construction)Pair variables (T M T → D × L)
alldifferent (Req 9)Day and Location variables (T M T → D), (T M T → L)
gcc (Req 4, 5)alldifferent (Req 7, 8)
Channeling Constraintselement projection from pairs onto rows and columns
Search only on pair variables
Helmut Simonis Choosing the Model 38
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Handling of hints (I)
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 (17) can not be used by pairs not involving team8One of the pairs involving team 8 must use this value (17)
Helmut Simonis Choosing the Model 39
ProblemModel
ProgramSearch
Redundant Modelling
Exploring IdeasExpanding Idea 7Comparing IdeasChannelingSelected Model
Handling of hints (II)
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
The pair involving teams 5 and 7 must take value 5, fixesvariable
Helmut Simonis Choosing the Model 40
ProblemModel
ProgramSearch
Redundant Modelling
Problem Data
hint(1,8,[2-[8],5-[5,7],8-[2],9-[1,5],15-[7],17-[8],26-[2],27-[5],28-[1],29-[8],34-[1],39-[4,5],43-[4],47-[1,3]]).
Helmut Simonis Choosing the Model 41
ProblemModel
ProgramSearch
Redundant Modelling
Main Program
top(Problem,L):-hint(Problem,N,Hints),N1 is N-1,N2 is N//2,NrVars is N*N1//2,SizeDomain is N1*N1,length(L,NrVars),L :: 1..SizeDomain,create_pairs(N,Contains,Names),ic_global_gac:alldifferent(L),process_hints(L,Contains,Hints),...
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
ic_global_gac:alldifferent(K)),search(L,0,input_order,indomain,
complete,[]).
Helmut Simonis Choosing the Model 43
ProblemModel
ProgramSearch
Redundant Modelling
Create Pairs and Names
create_pairs(N,Contains,Names):-(for(I,1,N-1),fromto(Names,A1,A,[]),fromto(Contains,B1,B,[]),param(N) do
(for(J,I+1,N),fromto(A1,[Name|AA],AA,A),fromto(B1,[I-J|BB],BB,B),param(I) do
concat_string([I,J],Name))
).
Helmut Simonis Choosing the Model 44
ProblemModel
ProgramSearch
Redundant Modelling
Projecting Rows and Columns
project_row_cols(L,N,Rows,Cols):-generate_tables(N,RowTable,ColTable),(foreach(X,L),foreach(R,Rows),foreach(C,Cols),param(RowTable,ColTable) do
element(X,RowTable,R),element(X,ColTable,C)
).
Helmut Simonis Choosing the Model 45
ProblemModel
ProgramSearch
Redundant Modelling
Generating Projection Tables
generate_tables(N,RowTable,ColTable):-(for(I,1,N),fromto(RowTable,A1,A,[]),fromto(ColTable,B1,B,[]),param(N) do
(for(J,1,N),fromto(A1,[I|AA],AA,A),fromto(B1,[J|BB],BB,B),param(I) do
true)
).
Helmut Simonis Choosing the Model 46
ProblemModel
ProgramSearch
Redundant Modelling
Extract row variables
separate(Contains,Rows,Values,SplitRows):-(for(Value,1,Values),foreach(SplitRow,SplitRows),param(Contains,Rows) do
(foreach(A-B,Contains),foreach(V,Rows),fromto([],R,R1,SplitRow),param(Value) do
(memberchk(Value,[A,B]) ->R1 = [V|R]
;R1 = R
))
).
Helmut Simonis Choosing the Model 47
ProblemModel
ProgramSearch
Redundant Modelling
Set up gcc constraint
limit(L,Bound,Values):-(for(I,1,Values),foreach(gcc(Bound,Bound,I),Pattern),param(Bound) do
true),gcc(Pattern,L).
Helmut Simonis Choosing the Model 48
ProblemModel
ProgramSearch
Redundant Modelling
Setting up hints
process_hints(L,Contains,Hints):-(foreach(Pos-Values,Hints),param(L,Contains) do
process_hint(Pos,Values,L,Contains)).
process_hint(Pos,[A,B],L,Contains):- % clause 1!,match_hint(A-B,Contains,L,X),X #= Pos.
Helmut Simonis Choosing the Model 49
ProblemModel
ProgramSearch
Redundant Modelling
Setting up hints
process_hint(Pos,[Value],L,Contains):- % clause 2(foreach(X,L),foreach(A-B,Contains),fromto([],R,R1,Required),param(Pos,Value) do
(not_mentioned(A,B,Value) ->X #\= Pos,R1 = R
;R1 = [X|R]
)),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
sumlist(Matrix[I,1..7],4),sumlist(Matrix[1..7,I],4)
),(foreach(K-_,Hints),param(Matrix) do
coor(K,I,J),subscript(Matrix,[I,J],1)
).
Helmut Simonis Choosing the Model 69
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Before Search
Helmut Simonis Choosing the Model 70
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Impact of Redundant Constraints
Without With value index channeling
Helmut Simonis Choosing the Model 71
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Solution
Helmut Simonis Choosing the Model 72
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Search Tree
12
1312
1413 12 41
54 53
5
1314 12 56
1414 12
2367
52
54
4
Helmut Simonis Choosing the Model 73
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Still Missing PropagationCity 1 City 2 City 3 City 4 City 5 City 6 City 7
Day 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
Game 12 can not be played on day 1 at locations 5 or 6
Helmut Simonis Choosing the Model 74
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Still Missing PropagationCity 1 City 2 City 3 City 4 City 5 City 6 City 7
Day 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
Game 12 can not be played on day 1 at locations 5 or 6
Helmut Simonis Choosing the Model 75
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Still Missing PropagationCity 1 City 2 City 3 City 4 City 5 City 6 City 7
Day 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
Game 12 can not be played on day 1 at locations 5 or 6
Helmut Simonis Choosing the Model 76
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Still Missing PropagationCity 1 City 2 City 3 City 4 City 5 City 6 City 7
Day 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
Game 12 can not be played on day 1 at locations 5 or 6
Helmut Simonis Choosing the Model 77
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Still Missing PropagationCity 1 City 2 City 3 City 4 City 5 City 6 City 7
Day 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
Game 12 can not be played on day 1 at locations 5 or 6
Helmut Simonis Choosing the Model 78
ProblemModel
ProgramSearch
Redundant Modelling
Adding value index ChannelingImproving Handling of Hints
Still Missing PropagationCity 1 City 2 City 3 City 4 City 5 City 6 City 7
Day 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
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
(not_mentioned(A,B,Value) ->X #\= Pos,R1 = R
;R1 = [X|R]
)),occurrences(Pos,Required,1),excluded_locations(Pos,Excluded),exclude_values(Required,Excluded).
Helmut Simonis Choosing the Model 82
ProblemModel
ProgramSearch
Redundant Modelling
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
Helmut Simonis Choosing the Model 88
ProblemProgram
Search
Chapter 10: Customizing Search (ProgressiveParty Problem)
Helmut Simonis
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.
Helmut Simonis Customizing Search 2
ProblemProgram
Search
Outline
1 Problem
2 Program
3 Search
Helmut Simonis Customizing Search 3
ProblemProgram
Search
What we want to introduce
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.
Helmut Simonis Customizing Search 5
ProblemProgram
Search
Phase 1Phase 2
Data
Boat 1 2 3 4 5 6 7 8 9 10 11 12 13 14Capacity 6 8 12 12 12 12 12 10 10 10 10 10 8 8
Crew 2 2 2 2 4 4 4 1 2 2 2 3 4 2Boat 15 16 17 18 19 20 21 22 23 24 25 26 27 28
Capacity 8 12 8 8 8 8 8 8 7 7 7 7 7 7Crew 3 6 2 2 4 2 4 5 4 4 2 2 4 5Boat 29 30 31 32 33 34 35 36 37 38 39 40 41 42
Capacity 6 6 6 6 6 6 6 6 6 6 9 0 0 0Crew 2 4 2 2 2 2 2 2 4 5 7 2 3 4
Helmut Simonis Customizing Search 6
ProblemProgram
Search
Phase 1Phase 2
Problem Decomposition
Phase 1: Select minimal set of host boatsManually
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)
Helmut Simonis Customizing Search 17
ProblemProgram
Search
Main Program
top:-top(10,6).
top(Problem,Size):-problem(Problem,Hosts,Guests),model(Hosts,Guests,Size,Matrix),writeln(Matrix).
Helmut Simonis Customizing Search 18
ProblemProgram
Search
Data
problem(10,[10,10,9,8,8,8,8,8,8,7,6,6,4],[7,6,5,5,5,4,4,4,4,4,4,4,4,4,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2]).
Helmut Simonis Customizing Search 19
ProblemProgram
Search
Creating Variables
model(Hosts,Guests,NrPeriods,Matrix):-length(Hosts,NrHosts),length(Guests,NrGuests),dim(Matrix,[NrGuests,NrPeriods]),Matrix[1..NrGuests,1..NrPeriods] :: 1..NrHosts,...
Helmut Simonis Customizing Search 20
ProblemProgram
Search
Setting up alldifferent constraints
...(for(I,1,NrGuests),param(Matrix,NrPeriods) do
ic:alldifferent(Matrix[I,1..NrPeriods])),...
Helmut Simonis Customizing Search 21
ProblemProgram
Search
Setting up bin_packing constraints
...(for(J,1,NrPeriods),param(Matrix,NrGuests,Guests,Hosts) do
make_bins(Hosts,Bins),bin_packing(Matrix[1..NrGuests,J],
Guests,Bins)),...
Helmut Simonis Customizing Search 22
ProblemProgram
Search
Each pair of guests meet atmost once
...(for(I,1,NrGuests-1),param(Matrix,NrGuests,NrPeriods) do
(for(I1,I+1,NrGuests),param(Matrix,NrPeriods,I) do
card_leq(Matrix[I,1..NrPeriods],Matrix[I1,1..NrPeriods],1)
)),...
Helmut Simonis Customizing Search 23
ProblemProgram
Search
Call search
...extract_array(col,Matrix,List),assign(List).
Helmut Simonis Customizing Search 24
ProblemProgram
Search
Make Bin variables
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
First Fail Search
1 2 3 4 5 62 5 1 6 3 43 1 6 2 4 54 6 2 5 1 35 3 2 1 6 72 8 4 3 7 13 4 5 1 7 26 7 1 9 8 16 8 1 7 9 37 4 9 2 8 127 1 5 8 9 118 3 4 7 1 28 7 11 3 2 99 1 7 8 2 131 9 12 5 4 74 2 121 3 55 6 8 12 2 119 11 3 6 1129 12 6 111 21121311 6 11 5 7 1211 9111 9 1312 81112 8 131 91113 7 9 12 111 9 11213 81213 9 111 412113 9 11 81211 8 113 113 9 8 11121
1
23
45
66
117
189
2
8
4
9
7
6
5
13
11
1
12
18
14
19
17
16
15
3
1
2
8
4
9
7
6
2
53
115
186
91
93
9
92
116
187
21
65
5
11
13
185
143
22
28
51
29
58
14
12
94
52
141
1
24
98
16
15
123
18
14
19
17
12
121
122
129
127
126
125
183
18
182
128
124
147
81
55
73
133
146
57
56
1321
59
54
131
134
139
118
136
112
111
25
83
27
26
8
82
89
87
1
22
2
86
3
22
2
24
25
3
84
43
411
41
4245
95
99
97
71
96
7
79
77
64
4
6
6
75
636
766
617
148
142
149
144
72
81
4
145
444
656
4
193
191
225
275
4
19
45
49
4
8
1
8
28
42
45
192
22
27
4
8
1
2
8
2
6
198
7
1
4
199
2
4
4 6
194
1978 6
4
1
2
42
44
3
7
49
42
44
45
9
6
49
1
7
49
9
7
1
44
45
4
3
49
42
44
3
2
42
44
45
7
6
7
4
8
1
44
42
1
45
6
1
7
45
6
2
1
9
8
7
9
2
44
45
44
45
42
45
42
44
2
8
9
1
6
1
6
2
2
4
8
6
7
4
9
3
7
2
4
8
3
9
7
9
4
4
3
8
9
2
2
4
3
8
2
4
42
42
42
44
44
44
45
45
45
1
1
3
8
4
1
6
6
7
7
9
2
3
8
9
2
3
8
9
2
4
Helmut Simonis Customizing Search 31
ProblemProgram
Search
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
search(Matrix[1..NrGuests,J],0,first_fail,indomain,complete,[])
).
Helmut Simonis Customizing Search 34
ProblemProgram
Search
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
Changing time periods
Problem Size Naive FF Layered Credit Random10 5 0.812 1.453 1.515 0.828 1.92210 6 14.813 2.047 2.093 1.219 2.46910 7 79.109 3.688 50.250 3.234 3.67210 8 - - 141.609 55.156 6.32810 9 - - - - 10.281
Helmut Simonis Customizing Search 45
ProblemProgram
Search
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.
Helmut Simonis Limits of Propagation 2
ProblemProgram
SearchImprovements
Outline
1 Problem
2 Program
3 Search
4 Improvements
Helmut Simonis Limits of Propagation 3
ProblemProgram
SearchImprovements
What we want to introduce
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
Problem: Costas Array (Antenna design, sonar systems)
Helmut Simonis Limits of Propagation 4
ProblemProgram
SearchImprovements
Problem Definition
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.
Helmut Simonis Limits of Propagation 5
ProblemProgram
SearchImprovements
Example (Size 6)
1233333333143333333315333333331633333333173333333318
2
4
5
6
7
8
Helmut Simonis Limits of Propagation 6
ProblemProgram
SearchImprovements
Model
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
Helmut Simonis Limits of Propagation 7
ProblemProgram
SearchImprovements
Model
X1
X2
X3
X4
X5
X6
D56
D45
D34
D23
D12
D46
D35
D24
D13
D36
D25
D14
D26
D15
D16
Helmut Simonis Limits of Propagation 8
ProblemProgram
SearchImprovements
Example
1233333333143333333315333333331633333333173333333318
2
4
5
6
7
8
1
2
5
4
6
3-3
2
-1
3
1
-1
1
2
4
-2
4
3
1
5
2
Helmut Simonis Limits of Propagation 9
ProblemProgram
SearchImprovements
Declarations
:-module(costas).
:-export(top/0).
:-lib(ic).
Helmut Simonis Limits of Propagation 10
ProblemProgram
SearchImprovements
Main Program
top:-(for(N,3,20) do
costas(N,_)).
costas(N,L):-length(L,N),L :: 1..N,alldifferent(L),L = [_|L1],diffs(L,L1),search(L,0,first_fail,indomain,
complete,[]).
Helmut Simonis Limits of Propagation 11
ProblemProgram
SearchImprovements
Differences
diffs(_,[]).diffs(L,[H|T]):-
diff_pairs(L,[H|T],Diffs),alldifferent(Diffs),diffs(L,T).
diff_pairs(_,[],[]).diff_pairs([X|X1],[Y|Y1],[D|D1]):-
X #= Y+D,diff_pairs(X1,Y1,D1).
Helmut Simonis Limits of Propagation 12
ProblemProgram
SearchImprovements
Basic Model
1
2
3
4
12
23
1 2 3
45
626
4
5
6
74 5 67
85
66
3
1
8
9
6
Helmut Simonis Limits of Propagation 13
ProblemProgram
SearchImprovements
Other Problem Sizes
Basic ModelSize Backtrack Time
10 4 0.0011 118 0.0812 50 0.0513 335 0.3614 5008 6.2315 47332 68.9216 157773 271.2217 1641685 3278.1918 115745 283.97
Helmut Simonis Limits of Propagation 14
ProblemProgram
SearchImprovements
Search tree (Size 12)
1
2
3
4
12
23
1 2 3
45
626
4
5
6
74 5 67
85
66
3
1
8
9
6
Helmut Simonis Limits of Propagation 15
ProblemProgram
SearchImprovements
Search tree (Size 13)
1
2
3
4
11
213
1 2 3
245
567
4
216
538
5
5
72
89
1
2
8
2
23
59
3 4
79
54
5 67 66
18
254
68
6
6
73
1
4
75
2
72
2
3
4
2
8
5
2
7
67
81
2
7
2 4
66
3
61
9
8
6
Helmut Simonis Limits of Propagation 16
ProblemProgram
SearchImprovements
Search tree (Size 14)
1
2
3
1232
24255
1
4
316
2783
2
392
2267
1 3
5
73
222
2
79
45
1
9
54
3 4 5 67
56
253
66
6
979
68
275
767
62
6
99
67
2
28
9
1
25
79
3
9
59
4
78
11
5
21
3
67
97
69
66
7
6
27
2
6
26
1
5
2
3
9
4
99
5
5
2
67
8
2
9
2
9
3
1 3
92
9
7
1
12 1
3
4
66
68
61
9
8
6
Helmut Simonis Limits of Propagation 17
ProblemProgram
SearchImprovements
Search tree (Size 15)
1
2
3
12234
22561
1
53277
44823
2
4
3179
5637
3
378
9638
1
3655
8912
2 4
1579
6974
5
1153
6342
6 78
5154
4259
77
831
3318
79
571
325
73
5
58
782
3
878
3558
1
818
3383
2
597
353
4
698
3487
5
6
7
2
1
2 4
5
2
5
6
34
78 77 79
33
11
73
8
19
1
8
4
3
5
5
79 73
78
2
72
3
6
71
9
7
Helmut Simonis Limits of Propagation 18
ProblemProgram
SearchImprovements
Search tree (Size 16)
1
2
3
112311
445661
1
172318
431946
2
4
2859
12515
3
153
71155
1
5561
13138
2 4
3833
18813
5
8759
73536
6 78
5
37
168
3
691
7227
1
6
2
159
3
25
17
1
31
13
4
33
799
5 6 78
33
799
79
7
72
3
79
39
1
79
56
4
2
15
5 6
1
23
78
11
42
79
76
86
71
8
3
12
3 1 4
1979
123 4 6
71
5
72
73
2
77
9
7
Helmut Simonis Limits of Propagation 19
ProblemProgram
SearchImprovements
Observation
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
Helmut Simonis Limits of Propagation 20
ProblemProgram
SearchImprovements
Missing Propagation
The model isdoing this
Helmut Simonis Limits of Propagation 21
ProblemProgram
SearchImprovements
Missing Propagation
It could be doingthat!
Helmut Simonis Limits of Propagation 22
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Changed Differences
diffs(_,[]).diffs(L,[H|T]):-
diff_pairs(L,[H|T],Diffs,Triples),impose_triples(Triples,[]),alldifferent(Diffs),diffs(L,T).
diff_pairs(_,[],[],[]).diff_pairs([X|X1],[Y|Y1],[D|D1],[t(X,Y,D)|T]):-
X #= Y+D,diff_pairs(X1,Y1,D1,T).
Helmut Simonis Limits of Propagation 23
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Changed Differences
impose_triples([],_).impose_triples([t(X,Y,D)|R],Others):-
suspend(impose_triple(D,R),4,D->inst),suspend(impose_triple(D,Others),4,D->inst),impose_triples(R,[t(X,Y,D)|Others]).
Helmut Simonis Limits of Propagation 24
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Changed Differences
impose_triple(_D,[]).impose_triple(D,[t(X,Y,_)|R]):-
(var(X) ->suspend(impose_one_triple12(D,X,Y),
4,X->inst);
impose_one_triple12(D,X,Y)),
% ...impose_triple(D,R).
impose_one_triple12(D,X,Y):-V is X-D,Y #\= V.
Helmut Simonis Limits of Propagation 25
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Further Model Improvements
DC consistent alldifferent between variables(DC consistent alldifferent between differences)DC difference constraint
Helmut Simonis Limits of Propagation 26
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Improved Model
1
2
3
4
12
34
1
32
56
2
5
6
72 33
4
1
5
6
7
3
Helmut Simonis Limits of Propagation 27
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Comparison (Solutions)
Initial Model Improved Model
Helmut Simonis Limits of Propagation 28
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Comparison (Search Trees)
Initial Model Improved Model
1
2
3
4
12
23
1 2 3
45
626
4
5
6
74 5 67
85
66
3
1
8
9
61
2
3
4
12
34
1
32
56
2
5
6
72 33
4
1
5
6
7
3
Helmut Simonis Limits of Propagation 29
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Search tree (Size 12)
1
2
3
4
12
34
1
32
56
2
5
6
72 33
4
1
5
6
7
3
Helmut Simonis Limits of Propagation 30
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Search tree (Size 13)
1
2
3
4
12
343
1
56
374
2
88
385
3
5
31
98
1
8
35
4
8
38
5
36
96
3
77
67
6
7
36
1
7
39
4
7
3
1
3
4
82 3 68 66
67
5
61
9
7
6
Helmut Simonis Limits of Propagation 31
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Search tree (Size 14)
1
2
3
1234
5121
1
4
672
868
2
692
46
1
5
62
88
2
66
12
1
92
17
3
46
2
44
42
1
45
29
979
42
6
92
2
93
97
1
94
68
3
7
9
6
2
9
6
1
1
8
3
82
9
6
1
9
1
46
92
9
6
1 3
44
45
7
41
8
9
5
4
Helmut Simonis Limits of Propagation 32
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Search tree (Size 15)
1
2
3
12134
54413
1
16274
78916
2
4
479
1258
3
46
113
1
331
19
2
42
139
4
1575
5227
5
195
7512
66
5185
2173
67
5835
2179
63
5
12
747
3
565
683
1
517
284
2
14
723
8
569
688
4
6
7
6
18
2
7
9
4
2
4
69
4
12
63
18
1
2
2
5
2
8
7
6
4
966 67 63
69
62
3
5
61
7
6
Helmut Simonis Limits of Propagation 33
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Search tree (Size 16)
1
2
3
11234
526436
1
65312
554678
2
4
3934
156
3
837
6871
1
342
1936
2
866
9216
4
7255
9439
5
5
815
669
3
898
939
1
6
82
11
3
38
89
1
37
78
6
78
3
4
81
66
78
7
51
3
8
9
5
3
3
8
7
71
178 71
72
1
4
73
2
77
9
8
7
Helmut Simonis Limits of Propagation 34
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Comparison (Search Tree, size 16)
Initial Model Improved Model
1
2
3
112311
445661
1
172318
431946
2
4
2859
12515
3
153
71155
1
5561
13138
2 4
3833
18813
5
8759
73536
6 78
5
37
168
3
691
7227
1
6
2
159
3
25
17
1
31
13
4
33
799
5 6 78
33
799
79
7
72
3
79
39
1
79
56
4
2
15
5 6
1
23
78
11
42
79
76
86
71
8
3
12
3 1 4
1979
123 4 6
71
5
72
73
2
77
9
7
1
2
3
11234
526436
1
65312
554678
2
4
3934
156
3
837
6871
1
342
1936
2
866
9216
4
7255
9439
5
5
815
669
3
898
939
1
6
82
11
3
38
89
1
37
78
6
78
3
4
81
66
78
7
51
3
8
9
5
3
3
8
7
71
178 71
72
1
4
73
2
77
9
8
7
Helmut Simonis Limits of Propagation 35
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Other Problem Sizes
Basic Model Improved ModelSize Backtrack Time Backtrack Time
10 4 0.00 4 0.1611 118 0.08 77 1.4412 50 0.05 31 0.9413 335 0.36 216 6.2214 5008 6.23 2875 95.9415 47332 68.92 25820 1046.7516 157773 271.22 84161 4099.5217 1641685 3278.19 825590 49371.0218 115745 283.97 55102 4530.83
Helmut Simonis Limits of Propagation 36
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Observation
Changes reduce backtracks by 50%But, run times explodeBeing clever does not always payOr, perhaps, we did not make the right improvements?
Helmut Simonis Limits of Propagation 37
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Change of Search Strategy
Idea: Make more difficult choices firstReorder variables to start from middleAssign values starting in middle
Helmut Simonis Limits of Propagation 38
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Labeling From Middle
1
2
3
4
12
34
1
35
22
2
14
25
3
5
6
77
1
2
77
2
6
77
3
6
77
44
77
74
4
67
7
3
3
1
8
5
83 44
6
45
47
8
9
Helmut Simonis Limits of Propagation 39
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Other Problem Sizes
Improved Model Improved Model, MiddleSize Backtrack Time Backtrack Time
10 4 0.16 1 0.0111 77 1.44 13 0.0312 31 0.94 72 0.2613 216 6.22 513 1.8114 2875 95.94 589 2.3715 25820 1046.75 7840 34.3016 84161 4099.52 13158 63.9117 825590 49371.02 56390 298.1618 55102 4530.83 19750 115.64
Helmut Simonis Limits of Propagation 40
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Observation
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
10 4 0.00 1 0.0011 118 0.08 17 0.0112 50 0.05 97 0.0913 335 0.36 644 0.7414 5008 6.23 746 1.0315 47332 68.92 10041 16.0316 157773 271.22 17005 31.1217 1641685 3278.19 73080 152.7218 115745 283.97 28837 60.97
Helmut Simonis Limits of Propagation 42
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Comparison: Model Impact
Basic Model,Middle Improved Model, MiddleSize Backtrack Time Backtrack Time
10 1 0.00 1 0.0111 17 0.01 13 0.0312 97 0.09 72 0.2613 644 0.74 513 1.8114 746 1.03 589 2.3715 10041 16.03 7840 34.3016 17005 31.12 13158 63.9117 73080 152.72 56390 298.1618 28837 60.97 19750 115.6419 1187618 3174.72 1044751 4474.56
Helmut Simonis Limits of Propagation 43
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Comparison (Search Tree, size 18)
Initial Model Improved Model
12
3
11
4
11123
34254
1
15
4546
7677
2
4687
7319
1
7515
411
3
7321
1823
45
172
87
5
6
727
144
1
78
47
6
19
397
3
19
666
7
17
32
51
1
62
97
6
8
6
9
1
42
45
2
19
1
4
7
47
92 8
4
1
7
5
46
43
48
44
49
12
3
11
4
12342
51642
1
15
3232
1537
2
3566
1148
1
1312
6545
3
3889
6143
45
1689
6844
5
6
346
173
1
16
624
6
61
582
3
615
252
7
17
67
93
1
2
7
6
8
9
8
1
4
36
2
19
147
92 8
4
1
7
5
46
43
48
44
49
Helmut Simonis Limits of Propagation 44
ProblemProgram
SearchImprovements
Adding ConstraintsChange of Search Strategy
Observation
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.
Helmut Simonis Systematic Development 2
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Outline
1 Introduction
2 Application Structure
3 Documentation
4 Data Representation
5 Programming Concepts
6 Style Guide
Helmut Simonis Systematic Development 3
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Overview
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...."),
see_also:[hop/3]]).
Helmut Simonis Systematic Development 11
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
External Data Representation
Property Argument DataFile
TermFile Facts EXDR
Multiple runs ++ + + - +Debugging - + + ++ -
Test generationeffort - + + + -
Java I/O Effort - + - - +ECLiPSeI/O Effort ++ + ++ ++ ++
Memory ++ - - – -Develoment
Effort + - + + -
Helmut Simonis Systematic Development 12
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Internal Data Representation
Named structuresDefine & document properly
ListsDo not use for fixed number of elements
Hash tables, e.g. lib(hash)EfficientExtensibleMultiple keys possible
Vectors & arraysRequires that keys are integers (tuples)
Multi-representationDepending on key use one of multiple representations
Helmut Simonis Systematic Development 13
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Internal Representation Comparison
NamedStructures Lists Hash
TablesVectorsArrays
Multi-representation
holddisparate
data++ – – – –
accessspecific
info+ – + + +
add newentries – + ++ – –
doloops + ++ - ++ ++
sortentries – ++ - - ++
indexcalculations - – – ++ +
Helmut Simonis Systematic Development 14
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Getting it to work
Early testing lib(test_util)Define what a piece of code should do by exampleMay help to define behaviour
StubsLine coverage lib(coverage)
Check that tests cover code baseHeeding warnings of compiler, lib(lint)
Eliminate all causes of warningsSingleton warnings typically hide more serious problems
Small, incremental changesMatter of styleWorks for most people
Helmut Simonis Systematic Development 15
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
Programming Concepts
Many programming tasks are similarFinding the right informationPutting things together in the right sequence
We don’t need the fastest program, but the easiest tomaintain
Squeezing the last 10% improvement normally does notpay
Avoid unnecessary inefficiencylib(profile), lib(port_profiler)
Helmut Simonis Systematic Development 16
IntroductionApplication Structure
DocumentationData Representation
Programming ConceptsStyle Guide
List of concepts
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
Helmut Simonis Systematic Development 28
Chapter 13: Visualization Techniques
Helmut Simonis
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.
Helmut Simonis Visualization Techniques 2
Outline
Helmut Simonis Visualization Techniques 3
What we want to introduce
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
ProblemProgram
SearchConclusions
Outline
1 Problem
2 Program
3 Search
4 Conclusions
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
ProblemProgram
SearchConclusions
Top-level predicate
:-module(sonet).:-export(top/0).:-lib(ic),lib(ic_global),lib(ic_sets).
top:-problem(NrNodes,NrRings,Demands,
MaxRingSize,ChannelSize),length(Demands,NrDemands),...
Helmut Simonis Finite Set and Continuous Variables 24
ProblemProgram
SearchConclusions
Matrix of xik integer variables
...dim(Matrix,[NrNodes,NrRings]),ic:(Matrix[1..NrNodes,1..NrRings] :: 0..1),...
Helmut Simonis Finite Set and Continuous Variables 25
ProblemProgram
SearchConclusions
Node and ring set variables
...dim(Nodes,[NrNodes]),intsets(Nodes[1..NrNodes],NrNodes,1,NrRings),dim(NodeSizes,[NrNodes]),ic:(NodeSizes[1..NrNodes] :: 1..NrRings),dim(Rings,[NrRings]),intsets(Rings[1..NrRings],NrRings,1,NrNodes),dim(RingSizes,[NrRings]),ic:(RingSizes[1..NrRings] :: 0..MaxRingSize),...
Helmut Simonis Finite Set and Continuous Variables 26
ProblemProgram
SearchConclusions
Channeling node set variables
...(for(I,1,NrNodes),param(Matrix,Nodes,NodeSizes,NrRings) do
subscript(Nodes,[I],Node),subscript(NodeSizes,[I],NodeSize),#(Node,NodeSize),membership_booleans(Node,
Matrix[I,1..NrRings])),...
Helmut Simonis Finite Set and Continuous Variables 27
ProblemProgram
SearchConclusions
Channeling ring set variables
...(for(J,1,NrRings),param(Matrix,Rings,RingSizes,NrNodes) do
subscript(Rings,[J],Ring),subscript(RingSizes,[J],RingSize),RingSize #\= 1,#(Ring,RingSize),membership_booleans(Ring,
Matrix[1..NrNodes,J])),...
Helmut Simonis Finite Set and Continuous Variables 28
ProblemProgram
SearchConclusions
Demand ends must be (on atleast one) same ring
...(foreach(demand(I,J,_Size),Demands),param(Nodes,NrRings) do
subscript(Nodes,[I],NI),subscript(Nodes,[J],NJ),ic:(NonZero :: 1..NrRings),#(NI /\ NJ,NonZero)
),...
Helmut Simonis Finite Set and Continuous Variables 29
ProblemProgram
SearchConclusions
Flow Variables
...dim(Flow,[NrDemands,NrRings]),ic:(Flow[1..NrDemands,1..NrRings]::0.0 .. 1.0),(for(I,1,NrDemands),param(Flow,NrRings) do
(for(J,1,NrRings),fromto(0.0,A,A+F,Term),param(Flow,I) dosubscript(Flow,[I,J],F)),eval(Term) $= 1.0
),...
Helmut Simonis Finite Set and Continuous Variables 30
ProblemProgram
SearchConclusions
Ring Capacity Constraints
...(for(I,1,NrRings),param(Flow,Demands,ChannelSize) do
(foreach(demand(_,_,Size),Demands),count(J,1,_),fromto(0.0,A,A+Size*F,Term),param(Flow,I) dosubscript(Flow,[J,I],F)),eval(Term) $=< ChannelSize
),...
Helmut Simonis Finite Set and Continuous Variables 31
ProblemProgram
SearchConclusions
Linking xik and fdk variables
...(foreach(demand(From,To,_),Demands),count(I,1,_),param(Flow,Matrix,NrRings) do
(for(K,1,NrRings),param(I,From,To,Flow,Matrix) dosubscript(Flow,[I,K],F),subscript(Matrix,[From,K],X1),subscript(Matrix,[To,K],X2),F $=< X1,F $=< X2)
),...
Helmut Simonis Finite Set and Continuous Variables 32
ProblemProgram
SearchConclusions
Setting up degrees
...dim(Degrees,[NrNodes]),(for(I,1,NrNodes),param(Degrees) do
subscript(Degrees,[I],Degree),neighbors(I,Neighbors),length(Neighbors,Degree)
),...
Helmut Simonis Finite Set and Continuous Variables 33
ProblemProgram
SearchConclusions
Defining cost and assigning values
...sumlist(NodeSizesList,Cost),assign(Cost,Handle,NrNodes,Degrees,
NodeSizes,Matrix).
Helmut Simonis Finite Set and Continuous Variables 34
ProblemProgram
SearchConclusions
Assignment Routines
assign(Cost,Handle,NrNodes,Degrees,NodeSizes,Matrix):-
indomain(Cost),order_sizes(NrNodes,Degrees,NodeSizes,
OrderedSizes),search(OrderedSizes,1,input_order,indomain,
complete,[]),order_vars(Degrees,NodeSizes,Matrix,
VarAssign),search(VarAssign,0,input_order,indomain_max,
complete,[]).
Helmut Simonis Finite Set and Continuous Variables 35
ProblemProgram
SearchConclusions
Order ring size variables by increasing degree
order_sizes(NrNodes,Degrees,NodeSizes,OrderedSizes):-
(for(I,1,NrNodes),foreach(t(X,D),Terms),param(Degrees,NodeSizes) do
subscript(Degrees,[I],D),subscript(NodeSizes,[I],X)
),sort(2,=<,Terms,OrderedSizes).
Helmut Simonis Finite Set and Continuous Variables 36
ProblemProgram
SearchConclusions
Ordering decision variables
order_vars(Degrees,NodeSizes,Matrix,VarAssign):-dim(Matrix,[NrNodes,NrRings]),(for(I,1,NrNodes),foreach(t(Size,Y,I),Terms),param(Degrees,NodeSizes) do
subscript(NodeSizes,[I],Size),subscript(Degrees,[I],Degree),Y is -Degree
),sort(0,=<,Terms,Sorted),...
Helmut Simonis Finite Set and Continuous Variables 37
ProblemProgram
SearchConclusions
Ordering decision variables
...(foreach(t(_,_,I),Sorted),fromto(VarAssign,A1,A,[]),param(NrRings,Matrix) do
(for(J,1,NrRings),fromto(A1,[X|AA],AA,A),param(I,Matrix) do
subscript(Matrix,[I,J],X))
).
Helmut Simonis Finite Set and Continuous Variables 38
ProblemProgram
SearchConclusions
Data (13 nodes, 7 rings, 24 demands)
problem(13,7,[demand(1,9,8),demand(1,11,2),demand(2,3,25),demand(2,5,5),demand(2,9,2),demand(2,10,3),demand(2,13,4),demand(3,10,2),demand(4,5,4),demand(4,8,1),demand(4,11,5),demand(4,12,2),demand(5,6,5),demand(5,7,4),demand(7,9,5),demand(7,10,2),demand(7,12,6),demand(8,10,1),demand(8,12,4),demand(8,13,1),demand(9,12,5),demand(10,13,9),demand(11,13,3),demand(12,13,2)],5,40).
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.
Helmut Simonis Network Applications 2
Traffic PlacementCapacity Management
Other Problems
Outline
1 Traffic Placement
2 Capacity Management
3 Other Problems
Helmut Simonis Network Applications 3
Traffic PlacementCapacity Management
Other Problems
Common Theme
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
Solution Methods
Lagrangian RelaxationPath decompositionKnapsack decomposition
Probe Backtracking
Helmut Simonis Network Applications 23
Traffic PlacementCapacity Management
Other Problems
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
Solution Methods
Blocking IslandsLocal Search/ FD Hybrid(Column Generation)
Helmut Simonis Network Applications 29
Traffic PlacementCapacity Management
Other Problems
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
Improved MILP out-performs decomposition [Xia 2005]
Helmut Simonis Network Applications 47
Traffic PlacementCapacity Management
Other Problems
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
Setup Model to Find Flows
[AC,AD,BC,BD,AE,BE] :: 0.0 .. 1.0Inf,AC + AD + AE $= 50, % A R10.5*BC + 0.5*BD + BE $= 35, % B R10.5*BC + 0.5*BD $= 15, % B R3AD + 0.5*BD $= 30, % R1 R2AC + 0.5*BC + AE +BE $= 55, % R1 EAD + 0.5*BD $= 30, % R2 D0.5*BC + 0.5*BD $= 15, % R3 R4AC + 0.5*BC $= 15, % E C0.5*BC $= 5, % R4 C0.5*BD $= 10, % R4 D
Helmut Simonis Network Applications 60
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Solve for Different Flows
min(AC,MinAC),max(AC,MaxAC),min(AD,MinAD),max(AD,MaxAD),min(BC,MinBC),max(BC,MaxBC),min(BD,MinBD),max(BD,MaxBD),min(AE,MinAE),max(AE,MaxAE),min(BE,MinBE),max(BE,MaxBE),...
Helmut Simonis Network Applications 61
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Results of Analysis
C D EA 10 20 20B 10 20 20
Problem solved, no?
Helmut Simonis Network Applications 62
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Benchmark Problems
Network Routers PoPs Lines Lines/routerdexa 51 24 59 1.15as1221 108 57 153 1.41as1239 315 44 972 3.08as1755 87 23 161 1.85as3257 161 49 328 2.03as3967 79 22 147 1.86as6461 141 22 374 2.65
Helmut Simonis Network Applications 63
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
TFA Result for Benchmarks
Network LowSimul (%) High
Simul (%) Obj Time (sec)dexa 0 2310.65 1190 11as1221 0.09 8398.64 11556 1318as1239 n/a n/a n/a n/aas1755 0.15 6255.31 7482 699as3257 0.04 12260.03 25760 12389as3967 0.1 5387.10 6162 500as6461 0.28 8688.39 19740 8676
Helmut Simonis Network Applications 64
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Reduce Problem Size
Pop Level AnalysisOnly consider flows between PoPs, not routersLocal area connections typically not bottlenecksModelling routing can be tricky
Helmut Simonis Network Applications 65
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
PoP Level Results
Network LowSimul (%) High
Simul (%) Obj Time (sec)dexa 0 1068.37 557 5as1221 0.24 2964.93 3205 424as1239 0.63 1401.72 1931 101359as1755 0.66 1263.28 526 103as3257 0.30 2028.73 2378 2052as3967 0.1 1209.37 483 90as6461 1.47 951.41 481 768
Helmut Simonis Network Applications 66
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Increase Accuracy
LSP CountersIn MPLS networks only, provide improved resolutionImplementation buggy, not all counters can be used
NetflowCollect end-to-end flow information in routerImpact on router (memory)Impact on network (data aggregation)
Helmut Simonis Network Applications 67
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
TFA with LSP Counters
Network LowSimul (%) High
Simul (%) Obj Time (sec)dexa 30.35 249.71 1190 7as1221 9.94 685.37 11556 885as1239 10.74 1151.03 98910 72461as1755 25.29 269.30 7482 397as3257 23.77 425.67 25760 5121as3967 24.47 300.17 6162 275as6461 19.43 477.44 19740 2683
Helmut Simonis Network Applications 68
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
PoP TFA with LSP Counters
Network LowSimul (%) High
Simul (%) Obj Time (sec)dexa 60.62 145.85 557 3as1221 28.49 499.16 3205 271as1239 33.36 211.84 1931 2569as1755 50.33 169.37 526 46as3257 36.82 249.16 2378 640as3967 40.72 182.97 483 36as6461 34.05 210.93 481 136
Helmut Simonis Network Applications 69
Traffic PlacementCapacity Management
Other Problems
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
Resilience Analysis
Network LowSimul (%) High
Simul (%) Obj Time (sec) Casesdexa 68.91 108.25 3503 57 59as1221 85.75 102.60 14191 2869 153as1239 92.53 102.64 4499 44205 10as1755 92.82 105.39 8409 1815 161as3257 93.69 103.15 31093 39934 328as3967 91.60 108.79 9090 1635 141as6461 96.51 103.44 24808 20840 374
Helmut Simonis Network Applications 73
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Results over 100 runs
Network lower bound/simul upper bound/ simulaverage stdev average stdev
dexa 91.50 0.14 108.28 0.16as1755 88.65 0.11 106.08 0.056as3967 94.08 0.073 106.88 0.091as1221 87.34 0.10 102.05 0.025
Helmut Simonis Network Applications 74
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Results with LSP counters
Network LowSimul (%) High
Simul (%) Obj Time Casesdexa 97.76 101.33 3503 36 59as1221 98.15 100.69 14191 1840 153as1239 99.37 100.38 4499 3974 10as1755 99.28 100.66 8409 964 161as3257 99.41 100.44 31093 13381 328as3967 98.88 101.00 9090 819 147as6461 99.44 100.52 24808 8006 374
Helmut Simonis Network Applications 75
Traffic PlacementCapacity Management
Other Problems
Bandwidth ProtectionBandwidth on DemandResilience Analysis
Results over 100 runs (with LSP Counters)
Network lower bound/simul upper bound/ simulaverage stdev average stdev
dexa 99.60 0.029 100.33 0.025as1755 99.31 0.016 100.63 0.015as3967 99.41 0.014 100.61 0.014as1221 98.10 0.025 100.57 0.010
Helmut Simonis Network Applications 76
Traffic PlacementCapacity Management
Other Problems
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?
Helmut Simonis Network Applications 81
Traffic PlacementCapacity Management
Other Problems
Network DesignIGP Metric Optimization
Model
min{Yid ,We}
maxe∈E
1cap(e)
∑d∈D
bw(d)∑
1≤i≤path(d)
heid Yid
st.
∀d ∈ D :∑
1≤i≤path(d)
Yid = 1
∀d ∈ D, 1 ≤ i ≤ path(d) : Pid =∑e∈E
heid We
∀d ∈ D, 1 ≤ i, j ≤ path(d) : Pid = Pjd =⇒ Yid = Yjd = 0
∀d ∈ D, 1 ≤ i, j ≤ path(d) : Pid < Pjd =⇒ Yjd = 0
Yid ∈ {0, 1}integer We ≥ 1
Pid ≥ 0
Helmut Simonis Network Applications 82
Traffic PlacementCapacity Management
Other Problems
Network DesignIGP Metric Optimization
Solution Methods
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.
Helmut Simonis More Global Constraints 2
ProblemProgram
SearchImproved Search Strategy
Outline
1 Problem
2 Program
3 Search
4 Improved Search Strategy
Helmut Simonis More Global Constraints 3
ProblemProgram
SearchImproved Search Strategy
What we want to introduce
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
Helmut Simonis More Global Constraints 6
ProblemProgram
SearchImproved Search Strategy
Car TypesCars Option
Type Required 1 2 3 4 51 5 1 1 0 0 12 3 1 1 0 1 03 7 1 1 1 0 04 1 0 1 1 1 05 10 1 1 0 0 06 2 1 0 0 0 17 11 1 0 0 1 08 5 1 0 1 0 09 4 0 1 0 0 1
10 6 0 1 0 1 011 12 0 1 1 0 012 1 0 0 1 0 113 1 0 0 1 1 014 5 1 0 0 0 015 9 0 1 0 0 016 5 0 0 0 0 117 12 0 0 0 1 018 1 0 0 1 0 0
Helmut Simonis More Global Constraints 7
ProblemProgram
SearchImproved Search Strategy
Solution
Helmut Simonis More Global Constraints 8
ProblemProgram
SearchImproved Search Strategy
Modelling Alternatives
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
Helmut Simonis More Global Constraints 11
ProblemProgram
SearchImproved Search Strategy
gcc Example
X1 :: [2,4], X2 :: [1,3,4], X3 :: [1,2,3,4],X4 :: [3,4,5], X5 :: [3,4,5],gcc([gcc(1,1,1),gcc(2,3,2),gcc(1,3,3),
gcc(0,4,4),gcc(1,3,5)],[X1,X2,X3,X4,X5]),
X1 = ?, X2 = ?, X3 = ?, X4 = ?, X5 = ?
Helmut Simonis More Global Constraints 12
ProblemProgram
SearchImproved Search Strategy
gcc Reasoning
X1 :: [2,4], X2 :: [1,3,4], X3 :: [1,2,3,4],X4 :: [3,4,5], X5 :: [3,4,5],gcc([gcc(1,1,1),gcc(2,3,2),gcc(1,3,3),
gcc(0,4,4),gcc(1,3,5)],[X1,X2,X3,X4,X5]),
X1 = ?2, X2 = ?, X3 = ?2, X4 = ?, X5 = ?
Helmut Simonis More Global Constraints 13
ProblemProgram
SearchImproved Search Strategy
gcc Next Step
X1 :: [2,4], X2 :: [1,3,4], X3 :: [1,2,3,4],X4 :: [3,4,5], X5 :: [3,4,5],gcc([gcc(1,1,1),gcc(2,3,2),gcc(1,3,3),
gcc(0,4,4),gcc(1,3,5)],[X1,X2,X3,X4,X5]),
X1 = 2, X2 = ?1, X3 = 2, X4 = ?, X5 = ?
Helmut Simonis More Global Constraints 14
ProblemProgram
SearchImproved Search Strategy
gcc Continued
X1 :: [2,4], X2 :: [1,3,4], X3 :: [1,2,3,4],X4 :: [3,44,5], X5 :: [3,44,5],gcc([gcc(1,1,1),gcc(2,3,2),gcc(1,3,3),
gcc(0,4,4),gcc(1,3,5)],[X1,X2,X3,X4,X5]),
X1 = 2, X2 = 1, X3 = 2, X4 = ?, X5 = ?
Helmut Simonis More Global Constraints 15
ProblemProgram
SearchImproved Search Strategy
gcc Made Domain Consistent
X1 :: [2,4], X2 :: [1,3,4], X3 :: [1,2,3,4],X4 :: [3,4,5], X5 :: [3,4,5],gcc([gcc(1,1,1),gcc(2,3,2),gcc(1,3,3),
gcc(0,4,4),gcc(1,3,5)],[X1,X2,X3,X4,X5]),
X1 = 2, X2 = 1, X3 = 2, X4 ∈ {3, 5}, X5 ∈ {3, 5}
Helmut Simonis More Global Constraints 16
ProblemProgram
SearchImproved Search Strategy
How does the constraint solver do that?
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
Helmut Simonis More Global Constraints 20
ProblemProgram
SearchImproved Search Strategy
sequence_total Example
[X1,X2,X3,X4,X5,X6,X7,X8,X9,X10] :: 0..1,sequence_total(2,3,1,2,3,
[X1,X2,X3,X4,X5,X6,X7,X8,X9,X10]),
X1 = 0, X4 = 0, X7 = 0, X10 = 0
Helmut Simonis More Global Constraints 21
ProblemProgram
SearchImproved Search Strategy
Example, cont’d
x1, x2, x3, x4, x5, x6, x7, x8, x9, x10
x1,
1..2︷ ︸︸ ︷x2, x3, x4,
1..2︷ ︸︸ ︷x5, x6, x7,
1..2︷ ︸︸ ︷x8, x9, x10
x1,
3..6︷ ︸︸ ︷1..2︷ ︸︸ ︷
x2, x3, x4,
1..2︷ ︸︸ ︷x5, x6, x7,
1..2︷ ︸︸ ︷x8, x9, x10
x1,
3..6︷ ︸︸ ︷1..2︷ ︸︸ ︷
x2, x3, x4,
1..2︷ ︸︸ ︷x5, x6, x7,
1..2︷ ︸︸ ︷x8, x9, x10︸ ︷︷ ︸
2..3
x10,
3..6︷ ︸︸ ︷1..2︷ ︸︸ ︷
x2, x3, x4,
1..2︷ ︸︸ ︷x5, x6, x7,
1..2︷ ︸︸ ︷x8, x9, x10︸ ︷︷ ︸
2..3
Helmut Simonis More Global Constraints 22
ProblemProgram
SearchImproved Search Strategy
Mathematical Equivalent
Vars = [x1, x2, ...xN ]
Min ≤∑
1≤i≤N
xi ≤ Max
1 ≤ s ≤ N − k + 1 : Low ≤∑
s≤j≤s+k−1
xj ≤ High
Helmut Simonis More Global Constraints 23
ProblemProgram
SearchImproved Search Strategy
Mathematical Equivalent
Pruning very different when using finite domain inequalitiesCurrently no domain consistent implementation ofsequence_total
Weaker version sequence (no global counters) domainconsistentCurrently using decomposition:
sequence_total = sequence + gcc + more
Helmut Simonis More Global Constraints 24
ProblemProgram
SearchImproved Search Strategy
Main Program
:-module(car).:-export(top/0).:-lib(ic).:-lib(ic_global_gac).
top:-problem(Problem),model(Problem,L),writeln(L).
Helmut Simonis More Global Constraints 25
ProblemProgram
SearchImproved Search Strategy
Structure Definitions
:-local struct(problem(cars,models,required,using_options,value_order)).
:-local struct(option(k,n,index_set,total_use)).
Helmut Simonis More Global Constraints 26
ProblemProgram
SearchImproved Search Strategy
Model (Part 1)
model(problem{cars:NrCars,models:NrModels,required:Required,using_options:List,value_order:Ordered},L):-
length(L,NrCars),L :: 1..NrModels,(foreach(Cnt,Required),count(J,1,_),foreach(gcc(Cnt,Cnt,J),Card) do
true),gcc(Card,L),...
Helmut Simonis More Global Constraints 27
ProblemProgram
SearchImproved Search Strategy
Model (Part 2)
...(foreach(option{k:K,
n:N,index_set:IndexSet,total_use:Total},List),
param(L,NrCars) do(foreach(X,L),foreach(B,Binary),param(IndexSet) do
element(X,IndexSet,B)),sequence_total(Total,Total,0,K,N,Binary)
),search(L,0,input_order,ordered(Ordered),
complete,[]).Helmut Simonis More Global Constraints 28
ProblemProgram
SearchImproved Search Strategy
Data
problem(100,18,[5,3,7,1,10,2,11,5,4,6,12,1,1,5,9,5,12,1],[option(1,2,[1,2,3,5,6,7,8,14],
[1,1,1,0,1,1,1,1,0,0,0,0,0,1,0,0,0,0],48),option(2,3,[1,2,3,4,5,9,10,11,15],
[1,1,1,1,1,0,0,0,1,1,1,0,0,0,1,0,0,0],57),option(1,3,[3,4,8,11,12,13,18],
[0,0,1,1,0,0,0,1,0,0,1,1,1,0,0,0,0,1],28),option(2,5,[2,4,7,10,13,17],
[0,1,0,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0],34),option(1,5,[1,6,9,12,16],
[1,0,0,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0],17)],[1,3,2,4,6,8,7,12,13,5,9,11,10,14,16,18,17,15]).
Helmut Simonis More Global Constraints 29
ProblemProgram
SearchImproved Search Strategy
Data Generation
Data not really stored as factsGenerated from text data files in different formatBenchmark set from CSPLIB(http://www.csplib.org)
Helmut Simonis More Global Constraints 30
ProblemProgram
SearchImproved Search Strategy
DSV88 ExampleMore Difficult Example
1
2
3
4
5
6
7
11
12
13
14
18
16
17
21
22
29
24
28
25
26
27
31
32
33
39
34
35
36
37
9
911
93
99
94
98
951
97
4
41
42
431 2
49
44
45
46
47
8
81
83
84
88
85
87
51
52
53
59
54
55
56
57
61
62
63
69
64
68
65
66
67
7
71
72
73
79
74
7813
14
13
14
11
5
13
14
11
5
13
6
7
5
13
6
5
7
6
3
11
1
13
6
3
5
18
6
1
3
11
3
7
2
5
11
9
18
3
11
5
2
18
3
11
5
2
18
3
11
5
2
18
3
16
1
3
11
3
19
2
18
11
1
11
7
2
11
9
5
12
2
3
4
1
Helmut Simonis More Global Constraints 31
ProblemProgram
SearchImproved Search Strategy
DSV88 ExampleMore Difficult Example
Assignment Step 4
Helmut Simonis More Global Constraints 32
ProblemProgram
SearchImproved Search Strategy
DSV88 ExampleMore Difficult Example
Assignment Step 40
Helmut Simonis More Global Constraints 33
ProblemProgram
SearchImproved Search Strategy
DSV88 ExampleMore Difficult Example
Assignment Step 83
Helmut Simonis More Global Constraints 34
ProblemProgram
SearchImproved Search Strategy
DSV88 ExampleMore Difficult Example
Another Example (PR97)
100 cars22 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
Helmut Simonis More Global Constraints 35
ProblemProgram
SearchImproved Search Strategy
DSV88 ExampleMore Difficult Example
Second Example: Car Types
Cars OptionType Required 1 2 3 4 5
1 6 1 0 0 1 02 10 1 1 1 0 03 2 1 1 0 0 14 2 0 1 1 0 05 8 0 0 0 1 06 15 0 1 0 0 07 1 0 1 1 1 08 5 0 0 1 1 09 2 1 0 1 1 0
10 3 0 0 1 0 011 2 1 0 1 0 012 1 1 1 1 0 113 8 0 1 0 1 014 3 1 0 0 1 115 10 1 0 0 0 016 4 0 1 0 0 117 4 0 0 0 0 118 2 1 0 0 0 119 4 1 1 0 0 020 6 1 1 0 1 021 1 1 0 1 0 122 1 1 1 1 1 1
Helmut Simonis More Global Constraints 36
ProblemProgram
SearchImproved Search Strategy
DSV88 ExampleMore Difficult Example
Search (Stopped After 1000 Nodes)
1
2
3
4
5
6
7
18
11
19
14
15
16
17
1
21
22
29
24
25
26
27
2
91
92
99
93
94
95
96
97
9
38
31
32
39
33
34
35
36
37
3
4112
49
43
46
4
511
59
54
561
53
68
61
69
64
65
661 45 6
46
66
6
78
7146
72
79
74
761 46 45 6
4 47 5
1
73
74
761 46 45 6
4 47 5
8 47 5
45 6
46
79
74
761 45 6
49
75
761 45 6
46
761 46 45 6
6
4 47 5
1 46
73
74
761 45 6
49
75
761 45 6
46
761 46 45 6
6
4 47 5
8 47 5
45 6
6
45 6
8 47
71
72
73
74
761 46 45 6
4 47 5
8 47 5
46
73
74
761 45 6
49
75
761 45 6
46
761 46 45 6
6
4 47 5
8 47 5
6
1 46 45 6
5
4 5
1 45 6
43
66
6
78
71
79
74
761 45 6
49
75
761 45 6
46
761 46 45 6
6
4 47 5
1 46
73
74
761 45 6
49
75
761 45 6
46
761 46 45 6
6
4 47 5
8 47 5
45 6
45 6
8 47
71
73
74
761 45 6
49
75
761 45 6
46
761 46 45 6
6
4 47 5
8 47 5
1 45 6
5
4 47 5
1 46 45 43 6
6
4 47
6646 43
7849
7146 43 6
4
6
5
1
63
64
65
661 45 6
46
66
6
78
7146
72
79
74
761 46 45 6
4 47
1
46
45
8
4
1
43
4
8
45
48
3
4
45
49
1
45
49
1
46
12
1
48
5
1
47
45
42
4
46
12
42
45
47
14
47
4
42
12
43
12
44
47
7
8
4
43
12
44
47
7
8
4
12
9
47
41
5
4
9
47
11
Helmut Simonis More Global Constraints 37
ProblemProgram
SearchImproved Search Strategy
DSV88 ExampleMore Difficult Example
Observation
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
Helmut Simonis More Global Constraints 46
Making gcc Domain Consistent
Making gcc Domain Consistent
X1 :: [2,4], X2 :: [1,3,4], X3 :: [1,2,3,4],X4 :: [3,4,5], X5 :: [3,4,5],gcc([gcc(1,1,1),gcc(2,3,2),gcc(1,3,3),
gcc(0,4,4),gcc(1,3,5)],[X1,X2,X3,X4,X5]),
Helmut Simonis More Global Constraints 47
Making gcc Domain Consistent
Method: Max Flow Model
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
Helmut Simonis More Global Constraints 48
Making gcc Domain Consistent
Start with Value Graph
X1
X2
X3
X4
X5
1
2
3
4
5
Helmut Simonis More Global Constraints 49
Making gcc Domain Consistent
Convert to Flow Problem
s t
X1
X2
X3
X4
X5
1
2
3
4
5
11111
1-12-3
1-3
0-4
1-3
5
Helmut Simonis More Global Constraints 50
Making gcc Domain Consistent
Find Maximal Flow
s t
X1
X2
X3
X4
X5
1
2
3
4
5
11111
121
1
5
Helmut Simonis More Global Constraints 51
Making gcc Domain Consistent
Mark Value Edges in Flow
s t
X1
X2
X3
X4
X5
1
2
3
4
5
11111
121
1
5
Helmut Simonis More Global Constraints 52
Making gcc Domain Consistent
Residual Graph
s t
X1
X2
X3
X4
X5
1
2
3
4
5
Helmut Simonis More Global Constraints 53
Making gcc Domain Consistent
Find Strongly Connected Components
s t
X1
X2
X3
X4
X5
1
2
3
4
5
Helmut Simonis More Global Constraints 54
Making gcc Domain Consistent
Mark Edges
s t
X1
X2
X3
X4
X5
1
2
3
4
5
Helmut Simonis More Global Constraints 55
Making gcc Domain Consistent
Remove Unmarked Edges
s t
X1
X2
X3
X4
X5
1
2
3
4
5
Helmut Simonis More Global Constraints 56