Title: The Repair Library
1The Repair Library
2Overview
- Context and Motivation
- Tentative Values, and Conflicts
- Tree Search and Local Search for an Example
Problem - Combining Local Search and Tree Search
- Conclusion
3Constraint Logic Programming
X,Y0..1, X Y gt 1, X Y, label(X,Y).
Define Decision Variables Constrain Decision
Variables Search for a Solution
4Algorithms using Inconsistent States
- One Basic Technique
- Start with good inconsistent solution
- Increase consistency incrementally
- Applications
- Repair Problems
- good inconsistent solution the previous
solution - Repair-Based Constraint Satisfaction
- good inconsistent solution the partially
consistent soln. found by heuristics - Repair-Based Constraint Optimization
- good inconsistent solution a good soln.
with respect to optimization function - Hybridization
- good inconsistent solution a good soln.
produced by a partial solver -
5Overview
- Context and Motivation
- Tentative Values, and Conflicts
- Tree Search and Local Search for an Example
Problem - Combining Local Search and Tree Search
- Conclusion
6Tentative Assignments
Logical Assignment
Tentative Assignment
Define Decision Variables Constrain Decision
Variables Search for a Solution
X1..10 X4
X tent_set 8 X tent_set 4
Xgt5
Fail Record Conflict
7Problem Modelling and Solving
Tree Search
Local Search
VarsDomain
Vars tent_set Vals
Initialise Decision Variables Constrain Decision
Variables Search for a Solution
ic ltConsgt
ltConsgt r_conflict Store
ic labeling(Vars)
repair(Store)
8Tentative Invariants
X,Y tent_set 1,2
Initialise Decision Variables Constrain Decision
Variables During Search
Either Y X1
r_conflict a
Or Y tent_is X1
X tent_set 3
Record Conflict
Y4
9Overview
- Context and Motivation
- Tentative Values, and Conflicts
- Tree Search and Local Search for an Example
Problem - Combining Local Search and Tree Search
- Conclusion
10Knapsack Problem
knapsack(N, Profits, Weights,Capacity, Opt)
- N
- - the number of items (integer)
- Profits
- - a list of N integers (profit per item)
- Sizes
- - a list of N integers (size per item)
- Capacity
- - the capacity of the knapsack (integer)
- Opt
- - the optimal result (output)
10
20
15
6
12
8
11Knapsack Problem
knapsack(N, Profits, Weights, Capacity, Opt) -
length(Vars, N),
N boolean variables
Capacity gt
WeightsVars
constraint Opt
ProfitsVars, the
objective
search
12Knapsack Problem
- Solved with ic-constraints and bb
- - lib(ic).
- - lib(branch_and_bound).
- knapsack(N, Profits, Weights, Capacity, Profit)
- - length(Vars, N), N boolean
variables - Vars 0..1, 1 iff
item in knapsack - Capacity gt WeightsVars, the
single constraint - Profit ProfitsVars, the
objective -
- minimize(labeling(Vars), -Profit).
branch-and-bound search
0/1?
Capacity100
Weight12 Profit7
Weight9 Profit4
Weight7 Profit5
13Model for local searches
- Using ic and repair library
- - lib(ic).
- - lib(repair).
- knapsack(N, Profits, Weights, Capacity, Opt) -
- length(Vars, N),
- Vars 0..1,
- Capacity gt WeightsVars r_conflict cap,
- Profit tent_is ProfitsVars,
- local_search(ltextra parametersgt, Vars, Profit,
Opt).
constraint
objective
14Local Search - algorithm template
- local_search
- set starting state
- while global_condition
- while local_condition
- select a move
- if acceptable
- do the move
- if new optimum
- remember it
- endwhile
- set restart state
- endwhile
15Local Search instances
- Algorithm parameters
- starting (and restarting) state
- global and local condition
- possible moves and how to select one
- when is a move accepted
- Different parameters yield different algorithms
- random walk
- hill climbing
- simulated annealing
- tabu search
- ... and many variants
16Hill climbing
- hill_climb(MaxTries, MaxIter, VarArr, Profit,
Opt) - - init_tent_values(VarArr, 0),
starting solution - ( for(I,1,MaxTries),
global condition - fromto(0, Opt1, Opt4, Opt),
- param(MaxIter,Profit,VarArr)
- do
- ( for(J,1,MaxIter),
local condition - fromto(Opt1, Opt2, Opt3,
Opt4), - param(I,VarArr,Profit)
- do
- Profit tent_get PrevProfit,
- ( flip_random(VarArr),
try a move - Profit tent_get
CurrentProfit, - CurrentProfit gt
PrevProfit, is it uphill? - conflict_constraints(cap
,) is it a solution? - -gt
- ( CurrentProfit gt Opt2
-gt is it new optimum? - printf("Found
profit wn", CurrentProfit), - Opt3CurrentProfit
accept and remember
17Hill climbing
hill_climb(MaxTries, MaxIter, VarArr) -
init_tent_values(VarArr, 0), starting
solution ( for(I,1,MaxTries),
global condition
do (
for(J,1,MaxIter), local condition
do
once(move(VarArr,Profit))
) init_tent_values(VarArr, 0)
restart ).
18Hill climbing
move(VarArr,Profit) - Profit tent_get
PrevProfit, flip_random(VarArr),
try a move Profit tent_get
CurrentProfit, CurrentProfit gt
PrevProfit, is
it uphill? conflict_constraints(cap,).
is it a solution?
19Techniques used here
- Move operation and acceptance test
- If the acceptance test fails (no solution or
objective not improved) the move is automatically
undone by backtracking! - Detecting solutions
- Constraint satisfaction is checked by checking
whether the conflict constraint set is empty - Monitoring cost/profit
- Retrieve tentative value of Profit-variable
before and after the move to check whether it is
uphill - Since the move changes the tentative values of
some variable(s), tent_is/2 will automatically
update the Profit variable!
20Auxiliaries used
- Starting state
- init_tent_values(VarArr, N) -
- ( foreacharg(X,VarArr),param(N) do X tent_set N
). - Move operator (the most stupid one...)
- flip_random(VarArr) -
- functor(VarArr, _, N),
- X is VarArrrandom mod N 1,
- X tent_get Old,
- New is xor(Old,1),
- X tent_set New.
21Sample run
- Found solution with profit 90
- Found solution with profit 102
- Found solution with profit 104
- restart
- restart
- Found solution with profit 111
- restart
- restart
- restart
- restart
- Found solution with profit 114
- restart
- restart
- restart
- restart
22Slightly more clever moves
- random_walk(MaxIter, VarArr, Profit, Opt) -
- init_tent_values(VarArr, random),
starting point - ( for(_,1,MaxIter),
do MaxIter steps - fromto(0, Best, NewBest, Opt),
track the optimum - param(Profit,VarArr)
- do
- ( conflict_constraints(cap,)
-gt it's a solution! - Profit tent_get
CurrentProfit, what is its profit? - (
- CurrentProfit gt Best
new optimum? - -gt
- printf("Found solution
with profit wn", CurrentProfit), - NewBestCurrentProfit
yes, remember it -
- NewBestBest
no, ignore - ),
- change_random(VarArr, 0, 1)
add another item -
- NewBestBest,
23Summary
- We have looked at pure local search
- possible with repair-library facilities
- Problems with these methods
- too many parameters to try
- how to make good but quick moves
- not good for very constrained problems
- solution quality unknown, no optimality proof
- Challenge
- how to combine with constructive methods
- repair methods
24Overview
- Context and Motivation
- Tentative Values, and Conflicts
- Tree Search and Local Search for an Example
Problem - Combining Local Search and Tree Search
- Conclusion
25A Tentative Assignment
Remaining Variables
Conflict Region of Violated Constraints
Changed Variables
26Tree Search Employing Tentative Assignments
a
b
c
c
27 Search with Tentative Assignments
Initialise Decision Variables Constrain Decision
Variables Search for a Solution
Vars tent_set Vals
ltConsgt r_conflict a
search(a) - ( find_conflict( a, Var) -gt
search(a)
true ).
28Tutorial Example Bridge Scheduling
- Schedule tasks to build a bridge
- Schedule consists of different tasks that share
several resources - (eg. excavator, pile-driver)
- Some tasks depend on others
- Temporal Constraints
- e.g time for concrete to set
- Disjunctive resource constraints
- pile-driver can only be used in one task at a
time
29The Bridge Scheduling Problem
T2
T1
T3
T4
T5
M1
M6
M5
M4
M3
M2
B6 S6
B1 S1
A1
A6
B4 S4
B5 S5
B2 S2
B3 S3
A5
A3
A4
A2
P1
P2
30Bridge Scheduling Problem
No. Name Description
Duration Resource 1 PA
Beginning of project
0 - 2 A1
Excavation (abutment 1) 4
excavator 3 A2 Excavation
(pillar 1) 2
excavator 8 P1 Foundation
Piles 1 20
pile-driver 9 P2 Foundation
Piles 2 13
pile-driver 10 U1 Erection of
temporary housing 10
- 11 S1 Formwork (abutment 1)
8 carpentry 17
B1 Concrete Foundation (abut. 1)
1 concrete-mixer 23 AB1
Concrete Setting Time (abut 1) 1
- 29 M1 Masonry work
(abutment 1) 16
bricklaying 35 L Delivery of
preformed Bearers 2
crane 36 T1 Positioning (preformed
bearer 1) 12 crane 42
V1 Filling 1
15 caterpillar 46
PE End of Project
0 -
31Temporal constraints on the Schedule
- Precedence
- before(Start1,Duration1,Start2)
- Maximal delay
- before(Start2,-Delay,Start1)
before(Start1,Duration1,Start2) - ic(Start1
Duration1 lt Start2)
32Resource Constraints
Machine
End
Start
D1
D2
D3
D4
D5
Tasks
noclash(S1,D1,S2,D2) - S1gtS2D2. noclash(S1,D1,S
2,D2) - S2gtS1D1.
33Disjunctive Resource Constraints
this clause is tried 1st
noclash1(Si,Di,Sj,_Dj) - incval(nodes), ic
(Sj gt SiDi). noclash1(Si,_Di,Sj,Dj)
- incval(nodes), ic (Si gt SjDj).
this clause is tried 2nd
just adds another temporal constraint
34Non-repair Search Labeling
min_max(( mylabeling(Starts), writeq(Starts),
nl, print_nodes ), End_date),
mylabeling(Starts) - ( foreach(S,Starts) do
mindomain(S,S) ).
35Repair Search Probe Backtracking
- Post temporal constraints
- Post resource constraints
- Probe Tentative Values are Earliest Possible
Start times - Probe satisfies temporal constraints
- Probe violates resource constraints
before(Start1,Duration1,Start2)
noclash(S0,D0,S1,D1) r_conflict
cs-noclash1(S0,D0,S1,D1)
tent_set_to_min(Vars) - ( foreach(Var,Vars),
foreach(Min,Mins) do mindomain(Var,Min) ),
Vars tent_set Mins.
36A disjunctive constraint is in conflict
- Probe can cause violation (overlap)
repair_label - conflict_vars(CVs), tent_set_to_
min(CVs), conflict_constraints(cs,CCs), ( CCs
-gt true CCs Constraint_, call(
Constraint), Fix the constraint
create choice point affect probe
repair_label ).
37Repair Search Top level
- Fix to tentative values after all conflicts
resolved
minimize(( repair_label, Starts tent_get
Starts, writeq(Starts), nl, print_nodes
), End_date),
38A repair heuristic
- Pick a constraint according to a heuristic
disjunctive(S0,D0,S1,D1) r_conflict cs -
tasks(Task0,Task1) select_constraint(TaskPairs,Se
lectedPair) - (
foreach(TaskPair,TaskPairs),
foreach(Key-TaskPair,KeyedCCs) do
TaskPair tasks( task with durationD0
, task with durationD1), Key is
min(D0,D1) ), sort(1,gt,KeyedCCs,_
- SelectedPair_).
39Exercise Files
- Slides
- /vol/members/Eclipse/Tutorial/Slides/2001/repair.p
pt - Files
- bridge_gen_test.pl standard strategy
- bridge_repair.pl repair no heuristic
- bridge_rep_heuristic.pl repair with heuristic
40Repair library - Quick Reference
- Tentative Values
- Vars tent_set Vals
- Vars tent_get Vals
- Conflict Sets
- conflict_constraints(Cset,CCs)
- Constraint Annotations
- Constraint r_conflict Cset
- Var tent_is Expression
41Exercise Propositional Satisfiability
A clause X or Y or neg Z
An encoding - lib(ic), lib(repair).
cons_clause(Clause,Bool) - Clause 1
r_conflict cs, Bool tent_is Clause.
Example ?- X,Y,Z tent_set 1,0,1,
cons_clause(X or Y or neg Z ,Bool).
yes Bool1
42Exercise Propositional Satisfiability
prop_sat(Vars,Clauses) - init_tent_values(Var
s), ( foreach(Cl,Clauses),
foreach(B,Bools) do
cons_clause(Cl,B) ), Bsum tent_is
sum(Bools), min_conflicts(Vars,Bsum).
You code min_conflicts! See Tutorial p.145
43Specification of min_conflicts(Vars, Count)
- If conflict set cs is empty, instantiate Vars to
their tentative values - Otherwise find a variable, V, in a conflict
constraint - Instantiate V to the value (0 or 1) that
maximises the tentative value of Count - On backtracking instantiate V the other way.
- See Tutorial p.134