Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no...

187
Introduction to Artificial Intelligence with Python

Transcript of Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no...

Page 1: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Introduction to Artificial Intelligence

with Python

Page 2: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Optimization

Page 3: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

optimization

choosing the best option from a set of options

Page 4: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

local search

search algorithms that maintain a single node and searches by moving to a neighboring node

Page 5: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

B

A

Page 6: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

B

Page 7: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 8: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Cost: 17

Page 9: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

state-space landscape

Page 10: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

global maximumobjective function

Page 11: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

global minimumcost function

Page 12: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

current state

Page 13: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

neighbors

Page 14: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Hill Climbing

Page 15: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 16: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 17: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 18: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 19: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 20: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 21: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 22: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 23: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 24: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 25: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 26: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Hill Climbing

function HILL-CLIMB(problem): current = initial state of problem repeat: neighbor = highest valued neighbor of current if neighbor not better than current: return current current = neighbor

Page 27: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Cost: 17

Page 28: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Cost: 17

Page 29: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Cost: 17

Page 30: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Cost: 15

Page 31: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Cost: 13

Page 32: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Cost: 11

Page 33: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Cost: 9

Page 34: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 35: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

global maximum

Page 36: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

local maxima

Page 37: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

global minimum

Page 38: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

local minima

Page 39: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 40: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 41: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 42: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 43: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 44: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

flat local maximum

Page 45: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

shoulder

Page 46: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Variant Definition

steepest-ascent choose the highest-valued neighbor

stochasticchoose randomly from higher-valued

neighbors

first-choice choose the first higher-valued neighbor

random-restart conduct hill climbing multiple times

local beam search chooses the k highest-valued neighbors

Hill Climbing Variants

Page 47: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Simulated Annealing

Page 48: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 49: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 50: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 51: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 52: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 53: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 54: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 55: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 56: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Simulated Annealing

• Early on, higher "temperature": more likely to accept neighbors that are worse than current state

• Later on, lower "temperature": less likely to accept neighbors that are worse than current state

Page 57: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Simulated Annealingfunction SIMULATED-ANNEALING(problem, max): current = initial state of problem for t = 1 to max: T = TEMPERATURE(t) neighbor = random neighbor of current ΔE = how much better neighbor is than current if ΔE > 0: current = neighbor with probability eΔE/T set current = neighbor return current

Page 58: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Traveling Salesman Problem

Page 59: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 60: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 61: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 62: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 63: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 64: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 65: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:
Page 66: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Linear Programming

Page 67: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Linear Programming

• Minimize a cost function c1x1 + c2x2 + ... + cnxn

• With constraints of form a1x1 + a2x2 + ... + anxn ≤ b or of form a1x1 + a2x2 + ... + anxn = b

• With bounds for each variable li ≤ xi ≤ ui

Page 68: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Linear Programming Example

• Two machines X1 and X2. X1 costs $50/hour to run, X2 costs $80/hour to run. Goal is to minimize cost.

• X1 requires 5 units of labor per hour. X2 requires 2 units of labor per hour. Total of 20 units of labor to spend.

• X1 produces 10 units of output per hour. X2 produces 12 units of output per hour. Company needs 90 units of output.

Page 69: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Linear Programming Example

• Two machines X1 and X2. X1 costs $50/hour to run, X2 costs $80/hour to run.

• X1 requires 5 units of labor per hour. X2 requires 2 units of labor per hour. Total of 20 units of labor to spend.

• X1 produces 10 units of output per hour. X2 produces 12 units of output per hour. Company needs 90 units of output.

50x1 + 80x2Cost Function:

Page 70: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Linear Programming Example

• Two machines X1 and X2. X1 costs $50/hour to run, X2 costs $80/hour to run.

• X1 requires 5 units of labor per hour. X2 requires 2 units of labor per hour. Total of 20 units of labor to spend.

• X1 produces 10 units of output per hour. X2 produces 12 units of output per hour. Company needs 90 units of output.

50x1 + 80x2Cost Function:

5x1 + 2x2 ≤ 20Constraint:

Page 71: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Linear Programming Example

• Two machines X1 and X2. X1 costs $50/hour to run, X2 costs $80/hour to run.

• X1 requires 5 units of labor per hour. X2 requires 2 units of labor per hour. Total of 20 units of labor to spend.

• X1 produces 10 units of output per hour. X2 produces 12 units of output per hour. Company needs 90 units of output.

50x1 + 80x2Cost Function:

5x1 + 2x2 ≤ 20Constraint:

10x1 + 12x2 ≥ 90Constraint:

Page 72: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Linear Programming Example

• Two machines X1 and X2. X1 costs $50/hour to run, X2 costs $80/hour to run.

• X1 requires 5 units of labor per hour. X2 requires 2 units of labor per hour. Total of 20 units of labor to spend.

• X1 produces 10 units of output per hour. X2 produces 12 units of output per hour. Company needs 90 units of output.

50x1 + 80x2Cost Function:

5x1 + 2x2 ≤ 20Constraint:

(−10x1) + (−12x2) ≤ − 90Constraint:

Page 73: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Linear Programming Algorithms

• Simplex

• Interior-Point

Page 74: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Constraint Satisfaction

Page 75: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

1

2

3

4

Student:

Page 76: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

1

2

3

4

Student: Taking classes:

A B C

B D E

C E F

E F G

Page 77: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

1

2

3

4

Student: Taking classes:

A B C

B D E

C E F

E F G

Exam slots:

Monday

Tuesday

Wednesday

Page 78: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

1

2

3

4

A B C

B D E

C E F

E F G

A

B C

D

E

F

G

Page 79: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

1

2

3

4

A B C

B D E

C E F

E F G

A

B C

D

E

F

G

Page 80: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

1

2

3

4

A B C

B D E

C E F

E F G

A

B C

D

E

F

G

Page 81: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

1

2

3

4

A B C

B D E

C E F

E F G

A

B C

D

E

F

G

Page 82: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

1

2

3

4

A B C

B D E

C E F

E F G

A

B C

D

E

F

G

Page 83: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

1

2

3

4

A B C

B D E

C E F

E F G

A

B C

D

E

F

G

Page 84: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

1

2

3

4

A B C

B D E

C E F

E F G

A

B C

D

E

F

G

Page 85: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

1

2

3

4

A B C

B D E

C E F

E F G

A

B C

D

E

F

G

Page 86: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

1

2

3

4

A B C

B D E

C E F

E F G

A

B C

D

E

F

G

Page 87: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Page 88: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Constraint Satisfaction Problem

• Set of variables {X1, X2, ..., Xn}

• Set of domains for each variable {D1, D2, ..., Dn}

• Set of constraints C

Page 89: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Variables

{(0, 2), (1, 1), (1, 2), (2, 0), ...}

Domains

{1, 2, 3, 4, 5, 6, 7, 8, 9}for each variable

Constraints

{(0, 2) ≠ (1, 1) ≠ (1, 2) ≠ (2, 0), ...}

5 3 7

6 1 9 5

9 8 6

8 6 3

4 8 3 1

7 2 6

6 2 8

4 1 9 5

8 7 9

Page 90: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Variables

{A, B, C, D, E, F, G}

Domains

{Monday, Tuesday, Wednesday}for each variable

Constraints{A≠B, A≠C, B≠C, B≠D, B≠E, C≠E,

C≠F, D≠E, E≠F, E≠G, F≠G}

Page 91: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

hard constraints

constraints that must be satisfied in a correct solution

Page 92: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

soft constraints

constraints that express some notion of which solutions are preferred over others

Page 93: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Page 94: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

unary constraint

constraint involving only one variable

Page 95: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

unary constraint

{A ≠ Monday}

Page 96: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

binary constraint

constraint involving two variables

Page 97: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

binary constraint

{A ≠ B}

Page 98: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

node consistency

when all the values in a variable's domain satisfy the variable's unary constraints

Page 99: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A B

{Mon, Tue, Wed} {Mon, Tue, Wed}

{A ≠ Mon, B ≠ Tue, B ≠ Mon, A ≠ B}

Page 100: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A B

{Mon, Tue, Wed} {Mon, Tue, Wed}

{A ≠ Mon, B ≠ Tue, B ≠ Mon, A ≠ B}

Page 101: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A B

{Tue, Wed} {Mon, Tue, Wed}

{A ≠ Mon, B ≠ Tue, B ≠ Mon, A ≠ B}

Page 102: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A B

{Tue, Wed}

{A ≠ Mon, B ≠ Tue, B ≠ Mon, A ≠ B}

{Mon, Tue, Wed}

Page 103: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A B

{Tue, Wed} {Mon, Wed}

{A ≠ Mon, B ≠ Tue, B ≠ Mon, A ≠ B}

Page 104: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A B

{Tue, Wed} {Mon, Wed}

{A ≠ Mon, B ≠ Tue, B ≠ Mon, A ≠ B}

Page 105: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A B

{Tue, Wed} {Wed}

{A ≠ Mon, B ≠ Tue, B ≠ Mon, A ≠ B}

Page 106: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A B

{Tue, Wed} {Wed}

{A ≠ Mon, B ≠ Tue, B ≠ Mon, A ≠ B}

Page 107: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

arc consistency

when all the values in a variable's domain satisfy the variable's binary constraints

Page 108: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

arc consistency

To make X arc-consistent with respect to Y, remove elements from X's domain until every choice for X has a possible choice for Y

Page 109: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A B

{Tue, Wed} {Wed}

{A ≠ Mon, B ≠ Tue, B ≠ Mon, A ≠ B}

Page 110: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A B

{Tue, Wed} {Wed}

{A ≠ Mon, B ≠ Tue, B ≠ Mon, A ≠ B}

Page 111: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A B

{Tue} {Wed}

{A ≠ Mon, B ≠ Tue, B ≠ Mon, A ≠ B}

Page 112: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A B

{Tue} {Wed}

{A ≠ Mon, B ≠ Tue, B ≠ Mon, A ≠ B}

Page 113: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Arc Consistency

function REVISE(csp, X, Y): revised = false for x in X.domain: if no y in Y.domain satisfies constraint for (X, Y): delete x from X.domain revised = true return revised

Page 114: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Arc Consistencyfunction AC-3(csp): queue = all arcs in csp while queue non-empty: (X, Y) = DEQUEUE(queue) if REVISE(csp, X, Y): if size of X.domain == 0: return false for each Z in X.neighbors - {Y}: ENQUEUE(queue, (Z, X)) return true

Page 115: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Page 116: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

{Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 117: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Search Problems

• initial state

• actions

• transition model

• goal test

• path cost function

Page 118: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

CSPs as Search Problems

• initial state: empty assignment (no variables)

• actions: add a {variable = value} to assignment

• transition model: shows how adding an assignment changes the assignment

• goal test: check if all variables assigned and constraints all satisfied

• path cost function: all paths have same cost

Page 119: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Backtracking Search

Page 120: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Backtracking Searchfunction BACKTRACK(assignment, csp): if assignment complete: return assignment var = SELECT-UNASSIGNED-VAR(assignment, csp) for value in DOMAIN-VALUES(var, assignment, csp): if value consistent with assignment: add {var = value} to assignment result = BACKTRACK(assignment, csp) if result ≠ failure: return result remove {var = value} from assignment return failure

Page 121: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

{Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 122: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

{Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 123: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Mon

{Mon, Tue, Wed}

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 124: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Mon

{Mon, Tue, Wed}

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 125: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

{Mon, Tue, Wed}

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 126: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Mon

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 127: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Mon

Mon {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 128: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Mon

Mon {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 129: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Mon

Tue {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 130: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Mon

Tue {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 131: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Mon

Wed {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 132: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Mon

Wed {Mon, Tue, Wed}

{Mon, Tue, Wed}

Mon

Page 133: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Mon

Wed {Mon, Tue, Wed}

{Mon, Tue, Wed}

Mon

Page 134: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Mon

Wed {Mon, Tue, Wed}

{Mon, Tue, Wed}

Tue

Page 135: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Mon

Wed {Mon, Tue, Wed}

{Mon, Tue, Wed}

Tue

Page 136: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Mon

Wed {Mon, Tue, Wed}

{Mon, Tue, Wed}

Wed

Page 137: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Mon

Wed {Mon, Tue, Wed}

{Mon, Tue, Wed}

Wed

Page 138: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Mon

Wed {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 139: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Mon

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 140: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

{Mon, Tue, Wed}

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 141: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Tue

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 142: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Tue

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 143: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Wed

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 144: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Wed

Mon {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 145: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Wed

Mon {Mon, Tue, Wed}

{Mon, Tue, Wed}

Mon

Page 146: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Wed

Mon {Mon, Tue, Wed}

{Mon, Tue, Wed}

Mon

Page 147: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Wed

Mon {Mon, Tue, Wed}

{Mon, Tue, Wed}

Tue

Page 148: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Wed

Mon {Mon, Tue, Wed}

{Mon, Tue, Wed}

Tue

Page 149: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Wed

Mon {Mon, Tue, Wed}

{Mon, Tue, Wed}

Wed

Page 150: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Wed

Mon {Mon, Tue, Wed}

Mon

Wed

Page 151: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Wed

Mon {Mon, Tue, Wed}

Mon

Wed

Page 152: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Wed

Mon {Mon, Tue, Wed}

Tue

Wed

Page 153: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Wed

Mon Mon

Tue

Wed

Page 154: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Wed

Mon Mon

Tue

Wed

Page 155: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Wed

Mon Tue

Tue

Wed

Page 156: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Wed

Mon Tue

Tue

Wed

Page 157: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Wed

Mon Wed

Tue

Wed

Page 158: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Inference

Page 159: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

{Mon, Tue, Wed}

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 160: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Mon

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 161: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Mon

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 162: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

{Mon, Tue, Wed}

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 163: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

{Mon, Tue, Wed}

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Wed}

Page 164: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

{Mon, Tue, Wed}

{Mon} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Wed}

Page 165: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

{Wed}

{Mon} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Wed}

Page 166: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

{Wed}

{Mon} {Mon, Tue, Wed}

{Tue}

{Wed}

Page 167: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

{Wed}

{Mon} {Wed}

{Tue}

{Wed}

Page 168: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Wed

Mon Wed

Tue

Wed

Page 169: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

maintaining arc-consistency

algorithm for enforcing arc-consistency every time we make a new assignment

Page 170: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

maintaining arc-consistency

When we make a new assignment to X, calls AC-3, starting with a queue of all arcs (Y, X) where Y is a neighbor of X

Page 171: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

function BACKTRACK(assignment, csp): if assignment complete: return assignment var = SELECT-UNASSIGNED-VAR(assignment, csp) for value in DOMAIN-VALUES(var, assignment, csp): if value consistent with assignment: add {var = value} to assignment inferences = INFERENCE(assignment, csp) if inferences ≠ failure: add inferences to assignment result = BACKTRACK(assignment, csp) if result ≠ failure: return result remove {var = value} and inferences from assignment return failure

Page 172: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

function BACKTRACK(assignment, csp): if assignment complete: return assignment var = SELECT-UNASSIGNED-VAR(assignment, csp) for value in DOMAIN-VALUES(var, assignment, csp): if value consistent with assignment: add {var = value} to assignment inferences = INFERENCE(assignment, csp) if inferences ≠ failure: add inferences to assignment result = BACKTRACK(assignment, csp) if result ≠ failure: return result remove {var = value} and inferences from assignment return failure

Page 173: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

function BACKTRACK(assignment, csp): if assignment complete: return assignment var = SELECT-UNASSIGNED-VAR(assignment, csp) for value in DOMAIN-VALUES(var, assignment, csp): if value consistent with assignment: add {var = value} to assignment inferences = INFERENCE(assignment, csp) if inferences ≠ failure: add inferences to assignment result = BACKTRACK(assignment, csp) if result ≠ failure: return result remove {var = value} and inferences from assignment return failure

Page 174: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

SELECT-UNASSIGNED-VAR

• minimum remaining values (MRV) heuristic: select the variable that has the smallest domain

• degree heuristic: select the variable that has the highest degree

Page 175: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

{Mon, Wed}

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Wed}

Page 176: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

{Mon, Wed}

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Wed}

Page 177: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

{Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 178: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

{Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed} {Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed}

Page 179: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

function BACKTRACK(assignment, csp): if assignment complete: return assignment var = SELECT-UNASSIGNED-VAR(assignment, csp) for value in DOMAIN-VALUES(var, assignment, csp): if value consistent with assignment: add {var = value} to assignment inferences = INFERENCE(assignment, csp) if inferences ≠ failure: add inferences to assignment result = BACKTRACK(assignment, csp) if result ≠ failure: return result remove {var = value} and inferences from assignment return failure

Page 180: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

function BACKTRACK(assignment, csp): if assignment complete: return assignment var = SELECT-UNASSIGNED-VAR(assignment, csp) for value in DOMAIN-VALUES(var, assignment, csp): if value consistent with assignment: add {var = value} to assignment inferences = INFERENCE(assignment, csp) if inferences ≠ failure: add inferences to assignment result = BACKTRACK(assignment, csp) if result ≠ failure: return result remove {var = value} and inferences from assignment return failure

Page 181: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

DOMAIN-VALUES

• least-constraining values heuristic: return variables in order by number of choices that are ruled out for neighboring variables

• try least-constraining values first

Page 182: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

{Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed} Wed

{Mon, Tue}

{Tue, Wed}

Page 183: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

{Mon, Tue, Wed}

{Mon, Tue, Wed}

{Mon, Tue, Wed} Wed

{Mon, Tue}

Wed

Page 184: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

A

B C

D

E

F

G

Mon

Tue

Wed

Mon Wed

Tue

Wed

Page 185: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Problem Formulation

Local Search

50x1 + 80x2

5x1 + 2x2 ≤ 20(−10x1) + (−12x2) ≤ − 90

Linear Programming

Constraint Satisfaction

A

B C

D

E

F

G

Page 186: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Optimization

Page 187: Introduction to Artificial Intelligence · 2020-03-09 · •initial state: empty assignment (no variables) •actions: add a {variable = value} to assignment •transition model:

Introduction to Artificial Intelligence

with Python