1 / 36

The Repair Library

Learn how to solve constraint satisfaction problems using techniques like tree search, local search, and repair-based approaches. Explore hybrid methods for finding "good" inconsistent solutions.

cumbie
Download Presentation

The Repair Library

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Repair Library

  2. Overview • Context and Motivation • Tentative Values, and Conflicts • Tree Search and Local Search for an Example Problem • Combining Local Search and Tree Search • Conclusion

  3. X=0 X=1 Y=0 Y=1 Y=0 Y=1 Constraint Logic Programming [X,Y]::0..1, X + Y >= 1, X = Y, label([X,Y]). Define Decision Variables Constrain Decision Variables Search for a Solution

  4. Algorithms 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

  5. Overview • Context and Motivation • Tentative Values, and Conflicts • Tree Search and Local Search for an Example Problem • Combining Local Search and Tree Search • Conclusion

  6. Tentative Assignments Tentative Assignment Logical Assignment Define Decision Variables Constrain Decision Variables Search for a Solution X::1..10 X=4 X tent_set 8 X tent_set 4 “X>=5” Fail Record Conflict

  7. Problem Modelling and Solving Tree Search Local Search Vars::Domain Vars tent_set Vals Initialise Decision Variables Constrain Decision Variables Search for a Solution ic: <Cons> <Cons> r_conflict Store ic: labeling(Vars) repair(Store)

  8. Tentative Invariants [X,Y] tent_set [1,2] Initialise Decision Variables Constrain Decision Variables During Search … Either: Y =:= X+1 r_conflict a Or: Y tent_is X+1 X tent_set 3 Record Conflict Y{4}

  9. Overview • Context and Motivation • Tentative Values, and Conflicts • Tree Search and Local Search for an Example Problem • Combining Local Search and Tree Search • Conclusion

  10. Knapsack 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) 20 10 15 6 12 8

  11. :- lib(repair). :- lib(ic), lib(branch_and_bound). Vars :: 0..1, r_conflict cap, ic: tent_is ic: local_search_opt(cap, Vars, Opt). =:= minimize(labeling(Vars), -Opt). Local Search Tree Search Knapsack Problem knapsack(N, Profits, Weights, Capacity, Opt) :- length(Vars, N), % N boolean variables Capacity >= Weights*Vars % constraint OptProfits*Vars, % the objective % search =

  12. Model 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 #>= Weights*Vars r_conflict cap, • Profit tent_is Profits*Vars, • local_search(<extra parameters>, Vars, Profit, Opt). constraint objective

  13. Local 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

  14. Local 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

  15. Hill 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 ).

  16. Hill climbing move(VarArr,Profit) :- Profit tent_get PrevProfit, flip_random(VarArr), % try a move Profit tent_get CurrentProfit, CurrentProfit > PrevProfit, % is it uphill? conflict_constraints(cap,[]). % is it a solution?

  17. Techniques 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!

  18. Auxiliaries 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 VarArr[random mod N + 1], • X tent_get Old, • New is xor(Old,1), • X tent_set New.

  19. Sample 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

  20. Overview • Context and Motivation • Tentative Values, and Conflicts • Tree Search and Local Search for an Example Problem • Combining Local Search and Tree Search • Conclusion

  21. A Tentative Assignment • The Conflict Region Remaining Variables Conflict Region of Violated Constraints Changed Variables

  22. c a b c c a Tree Search Employing Tentative Assignments a b c c

  23. Local Tree And with Finite Domains Vars::Domain, ic: <Cons> change_tent_val(Var), ic:indomain(Var), Search with Tentative Assignments Initialise Decision Variables Constrain Decision Variables Search for a Solution Vars tent_set Vals <Cons> r_conflict a search(a) :- ( find_conflict( a, Var) -> search(a) ; true ).

  24. Tutorial 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

  25. The Bridge Scheduling Problem T1 T2 T3 T5 T4 M6 M1 M5 M4 M3 M2 B6 S6 B1 S1 A1 A6 B4 S4 B5 S5 B2 S2 B3 S3 A5 A3 A4 A2 P1 P2

  26. Bridge 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 -

  27. Temporal constraints on the Schedule • Precedence • before(Start1,Duration1,Start2) • Maximal delay • before(Start2,-Delay,Start1) • before(Start1,Duration1,Start2) :- ic:(Start1 + Duration1 =< Start2)

  28. Resource Constraints Machine End Start D1 D2 D3 D4 D5 Tasks noclash(S1,D1,S2,D2) :- S1>=S2+D2. noclash(S1,D1,S2,D2) :- S2>=S1+D1.

  29. Disjunctive Resource Constraints this clause is tried 1st noclash1(Si,Di,Sj,_Dj) :- incval(nodes), ic: (Sj >= Si+Di). noclash1(Si,_Di,Sj,Dj) :- incval(nodes), ic: (Si >= Sj+Dj). this clause is tried 2nd just adds another temporal constraint

  30. Repair Search: Probe Backtracking before(Start1,Duration1,Start2) … • Post temporal constraints • Post resource constraints • Probe: Tentative Values are Earliest Possible Start times • Probe satisfies temporal constraints • Probe violates resource constraints 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.

  31. A 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 == [] -> true ; CCs = [Constraint|_], call(Constraint), %% Fix the constraint %% create choice point %% affect probe repair_label ).

  32. Repair 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),

  33. 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 Repair library - Quick Reference

  34. Exercise – 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 Bool{1}

  35. Exercise: Propositional Satisfiability prop_sat(Vars,Clauses) :- init_tent_values(Vars), ( 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

  36. Specification 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

More Related