770 likes | 963 Views
MBD and CSP. Meir Kalech. Partially based on slides of Jia You and Brian Williams. Outline. Last lecture: Autonomous systems Model-based programming Livingstone Today’s lecture: Constraints satisfaction problems (CSP) Optimal CSP Conflict-directed A* Expand best child.
E N D
MBD and CSP Meir Kalech Partially based on slides of Jia You and Brian Williams
Outline • Last lecture: • Autonomous systems • Model-based programming • Livingstone • Today’s lecture: • Constraints satisfaction problems (CSP) • Optimal CSP • Conflict-directed A* • Expand best child
Intro Example: 8-Queens Generate-and-test, 88 combinations
Constraint Satisfaction Problem • Set of variables {X1, X2, …, Xn} • Each variable Xi has a domain Di of possible values • Usually Di is discrete and finite • Set of constraints {C1, C2, …, Cp} • Each constraint Ck involves a subset of variables and specifies the allowable combinations of values of these variables • Goal: Assign a value to every variable such that all constraints are satisfied
Example: 8-Queens Problem • 8 variables Xi, i = 1 to 8 • Domain for each variable {1,2,…,8} • Constraints are of the forms: • Xi = k Xj k for all j = 1 to 8, ji
NT Q WA SA NT NSW Q V WA SA T NSW V T Example: Map Coloring • 7 variables {WA,NT,SA,Q,NSW,V,T} • Each variable has the same domain {red, green, blue} • No two adjacent variables have the same value: • WANT, WASA, NTSA, NTQ, SAQ, SANSW, SAV,QNSW, NSWV
T1 T2 T4 T3 Example: Task Scheduling T1 must be done during T3 T2 must be achieved before T1 starts T2 must overlap with T3 T4 must start after T1 is complete
Binary constraints NT T1 Q WA T2 NSW T4 SA V T3 T Constraint Graph Two variables are adjacent or neighbors if they are connected by an edge or an arc
CSP as a Search Problem • Initial state: empty assignment • Successor function: a value is assigned to any unassigned variable, which does not conflict with the currently assigned variables • Goal test: the assignment is complete • Path cost: irrelevant
Backtracking Algorithm CSP-BACKTRACKING(PartialAssignment a) • If a is complete then return a • X select an unassigned variable • D select an ordering for the domain of X • For each value v in D do • If v is consistent with a then • Add (X= v) to a • result CSP-BACKTRACKING(a) • If resultfailure then return result • Remove (X= v) from a • Return failure Start with CSP-BACKTRACKING({})
Improving backtracking efficiency • Which variable should be assigned next? • In what order should its values be tried? • Can we detect obvious failure early?
Outline • Last lecture: • Autonomous systems • Model-based programming • Livingstone • Today’s lecture: • Constraints satisfaction problems (CSP) • Optimal CSP • Conflict-directed A* • Expand best child
What is an Optimal CSP(OCSP)? • Set of decision variables y, • A utility function gon y, • A set of constraints C that y must satisfy. • The solution is an assignment to y, maximizing g and satisfyingC.
What is an OCSP formally? • OCSP is: • Where CSP = • x – set of variables • Dx – Domain over variables • Cx – set of constraints over variables • - set of decision variables • Cost function – • We call the elements of Dy decision states. • A solution y* to an OCSP is a minimum cost decision state that is consistent with the CSP.
Methods for solving OCSP • Traditional method: A* • Good at finding optimal solutions. • Visits every state that whose estimated cost is less than the true optimum*.Computationally unacceptable for model-based executives. * A* heuristic is admissible, that is, it never overestimates cost. • Solution: CONFLICT-DIRECTED A* • Also searches in best-first order • Eliminates subspaces around inconsistent states
Outline • Last lecture: • Autonomous systems • Model-based programming • Livingstone • Today’s lecture: • Constraints satisfaction problems (CSP) • Optimal CSP • Conflict-directed A* • Expand best child
CONFLICT-DIRECTED A*Williams&Rango 03 Step 1: Best candidate S generated Step 2: S is tested for consistency Step 3: If S is inconsistent, the inconsistency is generalized to conflicts, removing a subspace of the solution space Step 4: The program jumps to the next-best candidate, resolving all conflicts.
Enumerating Probable Candidates Generate Candidate Leading Candidate Based on Priors Test Candidate Yes No Consistent? Keep Extract Conflict Compute Posterior p Yes Below Threshold? No Done
A* - must visit all states with cost lower than optimum Increasing Cost inconsistent consistent
Conflict-directed A* - found inconsistent state eliminates all states entail the same symptom Increasing Cost inconsistent consistent
Conflict-directed A* Increasing Cost Conflict 1 inconsistent consistent
Conflict-directed A* Increasing Cost Conflict 1 inconsistent consistent
Conflict-directed A* Increasing Cost Conflict 1 inconsistent Conflict 2 consistent
Conflict-directed A* Increasing Cost Conflict 1 inconsistent Conflict 2 consistent
Conflict-directed A* Increasing Cost Conflict 1 inconsistent Conflict 2 consistent Conflict 3
Conflict-directed A* Increasing Cost Conflict 1 inconsistent Conflict 2 consistent • Feasible regions described by the implicates of known conflicts (Kernel Assignments) • Want kernel assignment containing the best cost candidate Conflict 3
Conflict-directed A* Function Conflict-directed-A*(OCSP) returns the leading minimal cost solutions. Conflicts[OCSP] {} OCSP Initialize-Best-Kernels(OCSP) Solutions[OCSP] {} loop do decision-state Next-Best-State-Resolving-Conflicts(OCSP) if no decision-state returned or Terminate?(OCSP) then return Solutions[OCSP] if Consistent?(CSP[OCSP ], decision-state) then add decision-state to Solutions[OCSP] else new-conflicts Extract-Conflicts(CSP[OCSP], decision-state) Conflicts[OCSP] Eliminate-Redundant-Conflicts(Conflicts[OCSP] new-conflicts) end
Conflict-directed A* Function Conflict-directed-A*(OCSP) returns the leading minimal cost solutions. Conflicts[OCSP] {} OCSP Initialize-Best-Kernels(OCSP) Solutions[OCSP] {} loop do decision-state Next-Best-State-Resolving-Conflicts(OCSP) if no decision-state returned or Terminate?(OCSP) then return Solutions[OCSP] if Consistent?(CSP[OCSP ], decision-state) then add decision-state to Solutions[OCSP] else new-conflicts Extract-Conflicts(CSP[OCSP], decision-state) Conflicts[OCSP] Eliminate-Redundant-Conflicts(Conflicts[OCSP] new-conflicts) end
A M1 X F B A1 3 C 10 M2 Y 2 D G A2 2 12 M3 E Z 3 3 Example: Diagnosis as an OCSP Assume Independent failures: • PG(mi) >> PU(mi) //G-good, U-unknown • Psingle >> Pdouble • PU(M2) > PU(M1) > PU(M3) > PU(A1) > PU(A2)
A M1 X F B A1 3 C 10 M2 Y 2 D G A2 2 12 M3 E Z 3 3 Example: Diagnosis • OBS = observation. • COMPONENTS = variable set y. • System Description = constraints - Cy. • M1=G X=A+B • Candidate = a mode assignments to y. • Diagnosis = a candidate that is consistent with Cy and OBS. • Utility = candidate probability P(y). • Cost = 1/P(y).
A M1 X F B A1 3 C 10 M2 Y 2 D G A2 2 12 M3 E Z 3 3 First Iteration • Conflicts / Constituent Diagnoses • none • Best Kernel: • {} • Best Candidate: • ?
M1=? M2=? M3=? A1=? A2=? M1=G M2=G M3=G A1=G A2=G { } • Select most likely value for unassigned modes
Test: M1=G M2=G M3=G A1=G A2=G A 3 M1 X F 10 B A1 2 C M2 2 Y 12 D G A2 3 M3 E Z 3
Test: M1=G M2=G M3=G A1=G A2=G A 6 3 M1 X F 10 B A1 2 C M2 2 Y 12 D G A2 3 M3 E Z 3
Test: M1=G M2=G M3=G A1=G A2=G A 6 3 M1 X F 10 B A1 2 6 C M2 2 Y 12 D G A2 3 M3 E Z 3
Test: M1=G M2=G M3=G A1=G A2=G A 6 3 M1 X F 10 B A1 2 6 C M2 2 Y 12 D G A2 3 6 M3 E Z 3
Test: M1=G M2=G M3=G A1=G A2=G A 6 12 3 M1 X F 10 B A1 2 6 C M2 2 Y 12 D G A2 3 6 M3 E Z 3
Test: M1=G M2=G M3=G A1=G A2=G A 6 12 3 M1 X F 10 B A1 2 6 C M2 2 Y 12 D G A2 3 6 M3 E Z 3 • Extract Conflict and Constituent Diagnoses:
Test: M1=G M2=G M3=G A1=G A2=G A 6 12 3 M1 X F 10 B A1 2 6 C M2 2 Y 12 D G A2 3 6 M3 E Z 3 • Extract Conflict and Constituent Diagnoses:
A 6 12 3 M1 X F 10 B A1 2 6 C M2 2 Y 12 D G A2 3 6 M3 E Z 3 • Test: M1=G M2=G M3=G A1=G A2=G • Extract Conflict and Constituent Diagnoses:¬ [M1=G M2=G A1=G]
A 6 12 3 M1 X F 10 B A1 2 6 C M2 2 Y 12 D G A2 3 6 M3 E Z 3 • Test: M1=G M2=G M3=G A1=G A2=G • Extract Conflict and Constituent Diagnoses:¬ [M1=G M2=G A1=G] M1=U M2=U A1=U This process has been done through propositional satisfiability algorithm DPLL algorithm*
A 6 12 3 M1 X F 10 B A1 2 6 C M2 2 Y 12 D G A2 3 6 M3 E Z 3 Second Iteration • Conflicts / Constituent Diagnoses • M1=U M2=U A1=U • Best Kernel: • M2=U • Best Candidate: • M1=G M2=U M3=G A1=G A2=G Later we will describe how to determine the best Kernel
Test: M1=G M2=U M3=G A1=G A2=G A 3 M1 X F 10 B A1 2 C 2 Y 12 D G A2 3 M3 E Z 3
Test: M1=G M2=U M3=G A1=G A2=G A 6 3 M1 X F 10 B A1 2 C 2 Y 12 D G A2 3 M3 E Z 3
Test: M1=G M2=U M3=G A1=G A2=G A 6 3 M1 X F 10 B A1 2 C 2 Y 12 D G A2 3 6 M3 E Z 3