PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence,...

73
Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling, Tree Decomposition Sarah Gaggl Dresden, 13th May 2014

Transcript of PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence,...

Page 1: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Artificial Intelligence, Computational Logic

PROBLEM SOLVING AND SEARCHIN ARTIFICIAL INTELLIGENCE

Lecture 6 ASP Modelling, Tree Decomposition

Sarah Gaggl

Dresden, 13th May 2014

Page 2: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Agenda1 Introduction2 Uninformed Search versus Informed Search (Best First Search, A*

Search, Heuristics)3 Constraint Satisfaction4 Answer Set Programming (ASP)5 Structural Decomposition Techniques (Tree/Hypertree Decompositions)6 Local Search, Stochastic Hill Climbing, Simulated Annealing7 Tabu Search8 Evolutionary Algorithms/ Genetic Algorithms9 Adversial Search and Game Playing

TU Dresden, 13th May 2014 PSSAI slide 2 of 73

Page 3: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Modeling and Interpreting

Problem

Logic Program

Solution

Stable Models

?-

6

Modeling Interpreting

Solving

TU Dresden, 13th May 2014 PSSAI slide 3 of 73

Page 4: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Modeling• For solving a problem class C for a problem instance I,

encode1 the problem instance I as a set PI of facts and2 the problem class C as a set PC of rules

such that the solutions to C for I can be (polynomially) extractedfrom the stable models of PI ∪ PC

• PI is (still) called problem instance• PC is often called the problem encoding

• An encoding PC is uniform, if it can be used to solve all itsproblem instancesThat is, PC encodes the solutions to C for any set PI of facts

TU Dresden, 13th May 2014 PSSAI slide 4 of 73

Page 5: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Modeling• For solving a problem class C for a problem instance I,

encode1 the problem instance I as a set PI of facts and2 the problem class C as a set PC of rules

such that the solutions to C for I can be (polynomially) extractedfrom the stable models of PI ∪ PC

• PI is (still) called problem instance• PC is often called the problem encoding

• An encoding PC is uniform, if it can be used to solve all itsproblem instancesThat is, PC encodes the solutions to C for any set PI of facts

TU Dresden, 13th May 2014 PSSAI slide 5 of 73

Page 6: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Modeling• For solving a problem class C for a problem instance I,

encode1 the problem instance I as a set PI of facts and2 the problem class C as a set PC of rules

such that the solutions to C for I can be (polynomially) extractedfrom the stable models of PI ∪ PC

• PI is (still) called problem instance• PC is often called the problem encoding

• An encoding PC is uniform, if it can be used to solve all itsproblem instancesThat is, PC encodes the solutions to C for any set PI of facts

TU Dresden, 13th May 2014 PSSAI slide 6 of 73

Page 7: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

ASP solving process

Problem

LogicProgram Grounder Solver Stable

Models

Solution

- - -

?

6

Modeling Interpreting

Solving

TU Dresden, 13th May 2014 PSSAI slide 7 of 73

Page 8: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

ASP solving process

Problem

LogicProgram Grounder Solver Stable

Models

Solution

- - -

?

6

Modeling Interpreting

Solving

TU Dresden, 13th May 2014 PSSAI slide 8 of 73

Page 9: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

ASP solving process

Problem

LogicProgram Grounder Solver Stable

Models

Solution

- - -

?

6

Modeling Interpreting

Solving

TU Dresden, 13th May 2014 PSSAI slide 9 of 73

Page 10: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

ASP solving process

Problem

LogicProgram Grounder Solver Stable

Models

Solution

- - -

?

6

Modeling Interpreting

Solving

TU Dresden, 13th May 2014 PSSAI slide 10 of 73

Page 11: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

ASP solving process

Problem

LogicProgram Grounder Solver Stable

Models

Solution

- - -

?

6

Modeling Interpreting

Solving

TU Dresden, 13th May 2014 PSSAI slide 11 of 73

Page 12: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

ASP solving process

Problem

LogicProgram Grounder Solver Stable

Models

Solution

- - -

?

6

Modeling Interpreting

Solving

TU Dresden, 13th May 2014 PSSAI slide 12 of 73

Page 13: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

ASP solving process

Problem

LogicProgram Grounder Solver Stable

Models

Solution

- - -

?

6

Modeling Interpreting

Solving6

ElaboratingTU Dresden, 13th May 2014 PSSAI slide 13 of 73

Page 14: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Basic methodology

MethodologyGenerate and Test (or: Guess and Check)

Generator Generate potential stable model candidates(typically through non-deterministic constructs)

Tester Eliminate invalid candidates(typically through integrity constraints)

NutshellLogic program = Data + Generator + Tester ( + Optimizer)

TU Dresden, 13th May 2014 PSSAI slide 14 of 73

Page 15: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Basic methodology

MethodologyGenerate and Test (or: Guess and Check)

Generator Generate potential stable model candidates(typically through non-deterministic constructs)

Tester Eliminate invalid candidates(typically through integrity constraints)

NutshellLogic program = Data + Generator + Tester ( + Optimizer)

TU Dresden, 13th May 2014 PSSAI slide 15 of 73

Page 16: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Satisfiability testing

• Problem Instance: A propositional formula φ in CNF• Problem Class: Is there an assignment of propositional variables to true

and false such that a given formula φ is true

• Example: Consider formula

(a ∨ ¬b) ∧ (¬a ∨ b)

• Logic Program:

Generator Tester Stable models{ a, b } ← ← not a, b

← a, not bX1 = {a, b}X2 = {}

TU Dresden, 13th May 2014 PSSAI slide 16 of 73

Page 17: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Satisfiability testing

• Problem Instance: A propositional formula φ in CNF• Problem Class: Is there an assignment of propositional variables to true

and false such that a given formula φ is true

• Example: Consider formula

(a ∨ ¬b) ∧ (¬a ∨ b)

• Logic Program:

Generator Tester Stable models{ a, b } ← ← not a, b

← a, not bX1 = {a, b}X2 = {}

TU Dresden, 13th May 2014 PSSAI slide 17 of 73

Page 18: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Satisfiability testing

• Problem Instance: A propositional formula φ in CNF• Problem Class: Is there an assignment of propositional variables to true

and false such that a given formula φ is true

• Example: Consider formula

(a ∨ ¬b) ∧ (¬a ∨ b)

• Logic Program:

Generator Tester Stable models{ a, b } ← ← not a, b

← a, not bX1 = {a, b}X2 = {}

TU Dresden, 13th May 2014 PSSAI slide 18 of 73

Page 19: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Satisfiability testing

• Problem Instance: A propositional formula φ in CNF• Problem Class: Is there an assignment of propositional variables to true

and false such that a given formula φ is true

• Example: Consider formula

(a ∨ ¬b) ∧ (¬a ∨ b)

• Logic Program:

Generator Tester Stable models{ a, b } ← ← not a, b

← a, not bX1 = {a, b}X2 = {}

TU Dresden, 13th May 2014 PSSAI slide 19 of 73

Page 20: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Satisfiability testing

• Problem Instance: A propositional formula φ in CNF• Problem Class: Is there an assignment of propositional variables to true

and false such that a given formula φ is true

• Example: Consider formula

(a ∨ ¬b) ∧ (¬a ∨ b)

• Logic Program:

Generator Tester Stable models{ a, b } ← ← not a, b

← a, not bX1 = {a, b}X2 = {}

TU Dresden, 13th May 2014 PSSAI slide 20 of 73

Page 21: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

The n-Queens Problem

5 Z0Z0Z4 0Z0Z03 Z0Z0Z2 0Z0Z01 Z0Z0Z

1 2 3 4 5

• Place n queens on an n× nchess board

• Queens must not attack oneanother

Q Q Q

Q Q

TU Dresden, 13th May 2014 PSSAI slide 21 of 73

Page 22: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Defining the Field

queens.lp

row(1..n).col(1..n).

• Create file queens.lp

• Define the field– n rows– n columns

TU Dresden, 13th May 2014 PSSAI slide 22 of 73

Page 23: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Defining the Field

Running . . .

$ gringo queens.lp --const n=5 | claspAnswer: 1row(1) row(2) row(3) row(4) row(5) \col(1) col(2) col(3) col(4) col(5)SATISFIABLE

Models : 1Time : 0.000

Prepare : 0.000Prepro. : 0.000Solving : 0.000

TU Dresden, 13th May 2014 PSSAI slide 23 of 73

Page 24: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Placing some Queens

queens.lp

row(1..n).col(1..n).{ queen(I,J) : row(I) : col(J) }.

• Guess a solution candidate

by placing some queens on the board

TU Dresden, 13th May 2014 PSSAI slide 24 of 73

Page 25: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Placing some Queens

Running . . .

$ gringo queens.lp --const n=5 | clasp 3Answer: 1row(1) row(2) row(3) row(4) row(5) \col(1) col(2) col(3) col(4) col(5)Answer: 2row(1) row(2) row(3) row(4) row(5) \col(1) col(2) col(3) col(4) col(5) queen(1,1)Answer: 3row(1) row(2) row(3) row(4) row(5) \col(1) col(2) col(3) col(4) col(5) queen(2,1)SATISFIABLE

Models : 3+...

TU Dresden, 13th May 2014 PSSAI slide 25 of 73

Page 26: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Placing some Queens: Answer 1

Answer 1

5 Z0Z0Z4 0Z0Z03 Z0Z0Z2 0Z0Z01 Z0Z0Z

1 2 3 4 5

TU Dresden, 13th May 2014 PSSAI slide 26 of 73

Page 27: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Placing some Queens: Answer 2

Answer 2

5 Z0Z0Z4 0Z0Z03 Z0Z0Z2 0Z0Z01 L0Z0Z

1 2 3 4 5

TU Dresden, 13th May 2014 PSSAI slide 27 of 73

Page 28: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Placing some Queens: Answer 3

Answer 3

5 Z0Z0Z4 0Z0Z03 Z0Z0Z2 QZ0Z01 Z0Z0Z

1 2 3 4 5

TU Dresden, 13th May 2014 PSSAI slide 28 of 73

Page 29: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Placing n Queens

queens.lp

row(1..n).col(1..n).{ queen(I,J) : row(I) : col(J) }.:- not n { queen(I,J) } n.

• Place exactly n queens on the board

TU Dresden, 13th May 2014 PSSAI slide 29 of 73

Page 30: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Placing n Queens

Running . . .

$ gringo queens.lp --const n=5 | clasp 2Answer: 1row(1) row(2) row(3) row(4) row(5) \col(1) col(2) col(3) col(4) col(5) \queen(5,1) queen(4,1) queen(3,1) \queen(2,1) queen(1,1)Answer: 2row(1) row(2) row(3) row(4) row(5) \col(1) col(2) col(3) col(4) col(5) \queen(1,2) queen(4,1) queen(3,1) \queen(2,1) queen(1,1)...

TU Dresden, 13th May 2014 PSSAI slide 30 of 73

Page 31: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Placing n Queens: Answer 1

Answer 1

5 L0Z0Z4 QZ0Z03 L0Z0Z2 QZ0Z01 L0Z0Z

1 2 3 4 5

TU Dresden, 13th May 2014 PSSAI slide 31 of 73

Page 32: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Placing n Queens: Answer 2

Answer 2

5 Z0Z0Z4 QZ0Z03 L0Z0Z2 QZ0Z01 LQZ0Z

1 2 3 4 5

TU Dresden, 13th May 2014 PSSAI slide 32 of 73

Page 33: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Horizontal and vertical Attack

queens.lp

row(1..n).col(1..n).{ queen(I,J) : row(I) : col(J) }.:- not n { queen(I,J) } n.:- queen(I,J), queen(I,JJ), J != JJ.

:- queen(I,J), queen(II,J), I != II.

• Forbid horizontal attacks

• Forbid vertical attacks

TU Dresden, 13th May 2014 PSSAI slide 33 of 73

Page 34: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Horizontal and vertical Attack

queens.lp

row(1..n).col(1..n).{ queen(I,J) : row(I) : col(J) }.:- not n { queen(I,J) } n.:- queen(I,J), queen(I,JJ), J != JJ.:- queen(I,J), queen(II,J), I != II.

• Forbid horizontal attacks• Forbid vertical attacks

TU Dresden, 13th May 2014 PSSAI slide 34 of 73

Page 35: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Horizontal and vertical Attack

Running . . .

$ gringo queens.lp --const n=5 | claspAnswer: 1row(1) row(2) row(3) row(4) row(5) \col(1) col(2) col(3) col(4) col(5) \queen(5,5) queen(4,4) queen(3,3) \queen(2,2) queen(1,1)...

TU Dresden, 13th May 2014 PSSAI slide 35 of 73

Page 36: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Horizontal and vertical Attack: Answer 1

Answer 1

5 Z0Z0L4 0Z0L03 Z0L0Z2 0L0Z01 L0Z0Z

1 2 3 4 5

TU Dresden, 13th May 2014 PSSAI slide 36 of 73

Page 37: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Diagonal Attack

queens.lp

row(1..n).col(1..n).{ queen(I,J) : row(I) : col(J) }.:- not n { queen(I,J) } n.:- queen(I,J), queen(I,JJ), J != JJ.:- queen(I,J), queen(II,J), I != II.:- queen(I,J), queen(II,JJ), (I,J) != (II,JJ), I-J == II-JJ.:- queen(I,J), queen(II,JJ), (I,J) != (II,JJ), I+J == II+JJ.

• Forbid diagonal attacks

TU Dresden, 13th May 2014 PSSAI slide 37 of 73

Page 38: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Diagonal Attack

Running . . .

$ gringo queens.lp --const n=5 | claspAnswer: 1row(1) row(2) row(3) row(4) row(5) \col(1) col(2) col(3) col(4) col(5) \queen(4,5) queen(1,4) queen(3,3) \queen(5,2) queen(2,1)SATISFIABLE

Models : 1+Time : 0.000

Prepare : 0.000Prepro. : 0.000Solving : 0.000

TU Dresden, 13th May 2014 PSSAI slide 38 of 73

Page 39: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Diagonal Attack: Answer 1

Answer 1

5 ZQZ0Z4 0Z0ZQ3 Z0L0Z2 QZ0Z01 Z0ZQZ

1 2 3 4 5

TU Dresden, 13th May 2014 PSSAI slide 39 of 73

Page 40: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Optimizing

queens-opt.lp

1 { queen(I,1..n) } 1 :- I = 1..n.1 { queen(1..n,J) } 1 :- J = 1..n.:- 2 { queen(D-J,J) }, D = 2..2*n.:- 2 { queen(D+J,J) }, D = 1-n..n-1.

• Encoding can be optimized• Much faster to solve

TU Dresden, 13th May 2014 PSSAI slide 40 of 73

Page 41: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Traveling Salesperson

node(1..6).

edge(1,2;3;4). edge(2,4;5;6). edge(3,1;4;5).edge(4,1;2). edge(5,3;4;6). edge(6,2;3;5).

cost(1,2,2). cost(1,3,3). cost(1,4,1).cost(2,4,2). cost(2,5,2). cost(2,6,4).cost(3,1,3). cost(3,4,2). cost(3,5,2).cost(4,1,1). cost(4,2,2).cost(5,3,2). cost(5,4,2). cost(5,6,1).cost(6,2,4). cost(6,3,3). cost(6,5,1).

TU Dresden, 13th May 2014 PSSAI slide 41 of 73

Page 42: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Traveling Salesperson

node(1..6).

edge(1,2;3;4). edge(2,4;5;6). edge(3,1;4;5).edge(4,1;2). edge(5,3;4;6). edge(6,2;3;5).

cost(1,2,2). cost(1,3,3). cost(1,4,1).cost(2,4,2). cost(2,5,2). cost(2,6,4).cost(3,1,3). cost(3,4,2). cost(3,5,2).cost(4,1,1). cost(4,2,2).cost(5,3,2). cost(5,4,2). cost(5,6,1).cost(6,2,4). cost(6,3,3). cost(6,5,1).

TU Dresden, 13th May 2014 PSSAI slide 42 of 73

Page 43: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Traveling Salesperson

1 { cycle(X,Y) : edge(X,Y) } 1 :- node(X).1 { cycle(X,Y) : edge(X,Y) } 1 :- node(Y).

reached(Y) :- cycle(1,Y).reached(Y) :- cycle(X,Y), reached(X).

:- node(Y), not reached(Y).

#minimize [ cycle(X,Y) = C : cost(X,Y,C) ].

TU Dresden, 13th May 2014 PSSAI slide 43 of 73

Page 44: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Traveling Salesperson

1 { cycle(X,Y) : edge(X,Y) } 1 :- node(X).1 { cycle(X,Y) : edge(X,Y) } 1 :- node(Y).

reached(Y) :- cycle(1,Y).reached(Y) :- cycle(X,Y), reached(X).

:- node(Y), not reached(Y).

#minimize [ cycle(X,Y) = C : cost(X,Y,C) ].

TU Dresden, 13th May 2014 PSSAI slide 44 of 73

Page 45: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Traveling Salesperson

1 { cycle(X,Y) : edge(X,Y) } 1 :- node(X).1 { cycle(X,Y) : edge(X,Y) } 1 :- node(Y).

reached(Y) :- cycle(1,Y).reached(Y) :- cycle(X,Y), reached(X).

:- node(Y), not reached(Y).

#minimize [ cycle(X,Y) = C : cost(X,Y,C) ].

TU Dresden, 13th May 2014 PSSAI slide 45 of 73

Page 46: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Traveling Salesperson

1 { cycle(X,Y) : edge(X,Y) } 1 :- node(X).1 { cycle(X,Y) : edge(X,Y) } 1 :- node(Y).

reached(Y) :- cycle(1,Y).reached(Y) :- cycle(X,Y), reached(X).

:- node(Y), not reached(Y).

#minimize [ cycle(X,Y) = C : cost(X,Y,C) ].

TU Dresden, 13th May 2014 PSSAI slide 46 of 73

Page 47: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Agenda1 Introduction2 Uninformed Search versus Informed Search (Best First Search, A*

Search, Heuristics)3 Constraint Satisfaction4 Answer Set Programming (ASP)5 Structural Decomposition Techniques (Tree/Hypertree Decompositions)6 Local Search, Stochastic Hill Climbing, Simulated Annealing7 Tabu Search8 Evolutionary Algorithms/ Genetic Algorithms9 Adversial Search and Game Playing

TU Dresden, 13th May 2014 PSSAI slide 47 of 73

Page 48: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Fixed-Parameter Tractability (FPT) –Motivation

Some Observations• For intractable problems, computational costs often depend primarily on

some problem parameters rather than on the mere size of the instances.• Many hard problems become tractable if some problem parameter is fixed

or bounded by a fixed constant.• Typical parameters for graphs: treewidth and cliquewidth.

– Meta-theorems allow for rather easy proofs of FPT results w.r.t.these parameters

– Dedicated dynamic algorithms required for practical realization!

FPT is one branch in the area of Parameterized Complexity• Downey & Fellows: Parameterized Complexity. Springer, 1999• Flum & Grohe: Parameterized Complexity Theory. Springer, 2006• Niedermeier: Invitation to Fixed-Parameter Algorithms. OUP, 2006

TU Dresden, 13th May 2014 PSSAI slide 48 of 73

Page 49: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Introduction• Many instances of constraint satisfaction problems can be solved in

polynomial time if their treewidth (or hypertree width) is small.• Solving of problems with bounded width includes two phases:

– Generate a (hyper)tree decomposition with small width;– Solve a problem (based on generated decomposition) with a

particular algorithm such as for example dynamic programming.• The efficiency of solving of problem based on its (hyper)tree

decomposition depends from the width of (hyper)tree decomposition.• It is of high importance to generate (hyper)tree decompositions with small

width.

TU Dresden, 13th May 2014 PSSAI slide 49 of 73

Page 50: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

CSP: Map-Coloring

WesternAustralia

NorthernTerritory

SouthAustralia

Queensland

New South Wales

Victoria

Tasmania

Variables WA, NT, Q, NSW, V, SA, TDomains Di = {red, green, blue}

Constraints: adjacent regions must have different colors e.g., WA 6= NT, or(WA, NT) ∈ {(red, green), (red, blue), (green, red), (green, blue), . . .}

TU Dresden, 13th May 2014 PSSAI slide 50 of 73

Page 51: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Constraint Graph

Binary CSP: each constraint relates at most two variablesConstraint graph: nodes are variables, arcs show constraints

Victoria

WA

NT

SA

Q

NSW

V

T

General-purpose CSP algorithms use the graph structureto speed up search. E.g., Tasmania is an independent sub-problem!TU Dresden, 13th May 2014 PSSAI slide 51 of 73

Page 52: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Tree-structured CSPs

AB

CD

E

F

TheoremIf the constraint graph has no loops, the CSP can be solved in O(n d2) time.

• Compare to general CSPs, where worst-case time is O(dn)

• This property also applies to logical and probabilistic reasoning: animportant example of the relation between syntactic restrictions and thecomplexity of reasoning.

TU Dresden, 13th May 2014 PSSAI slide 52 of 73

Page 53: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

CSP: SAT Problem(x1 ∨ x2 ∨ ¬x3) ∧ (x1 ∨ ¬x4 ∨ x5 ∨ x6) ∧ · · · ∧ (x3 ∨ x4 ∨ x7 ∨ x8) . . .Possible CSP fomulation:

Variables x1, x2, x3, . . .Domains 0, 1

Constraints – C1: (x1 ∨ x2 ∨ ¬x3)→ true– C2: (x1 ∨ ¬x4 ∨ x5 ∨ x6)→ true– . . .

TU Dresden, 13th May 2014 PSSAI slide 53 of 73

Page 54: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

CSP and Hypergraph

(x1 ∨ x2 ∨ ¬x3) ∧ (x1 ∨ ¬x4 ∨ x5 ∨ x6) ∧ (x3 ∨ x4 ∨ x7 ∨ x8) . . .

In general worst case complexity: 2NumberOfVariables = 219

TU Dresden, 13th May 2014 PSSAI slide 54 of 73

Page 55: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Hypergraph and its Primal Graph

TU Dresden, 13th May 2014 PSSAI slide 55 of 73

Page 56: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

CSP and (Hyper)treewidth• In general exponential worst case complexity.• Can we solve this instance more efficiently (or in polynomial time)?• Yes, if it has a small (hyper) treewidth!!!

TU Dresden, 13th May 2014 PSSAI slide 56 of 73

Page 57: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Tree Decomposition

DefinitionTree Decomposition Let G = (V, E) be a graph. A tree decomposition of G is apair (T,χ), where T = (I, F) is a tree with node set I and edge set F, andχ = {χi : i ∈ I} is a family of subsets of V, one for each node of T, such that

1⋃

i∈I χi = V,

2 for every edge (v, w) ∈ E, there is an i ∈ I with v ∈ χi and w ∈ χi, and3 for all i, j, k ∈ I, if j is on the path from i to k in T, then χi ∩ χk ⊆ χj.

The width of a tree decompostion is maxi∈I |χi| − 1.The treewidth of a graph G, denoted by tw(G), is the minimum width over allpossible tree decompositions of G.

TU Dresden, 13th May 2014 PSSAI slide 57 of 73

Page 58: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Tree Decomposition - Example

All pairs of vertices that are connected appear in some node of the tree.Connectedness condition for vertices

TU Dresden, 13th May 2014 PSSAI slide 58 of 73

Page 59: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Elimination Ordering• For the given problem find the tree decomposition with minimal width ->

NP hard.• There exists a perfect elimination ordering which produces tree

decomposition with treewidth (smallest width).• Tree decomposition problem→ search for the best elimination ordering of

vertices!• Permutation Problem→ similar to TSP.

Possible elimination ordering for graph in previous slide:10, 9, 8, 7, 2, 3, 6, 1, 5, 4

TU Dresden, 13th May 2014 PSSAI slide 59 of 73

Page 60: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Perfect Elimination Ordering

Vertex 10 is eliminated from the graph. All neighbors of 10 are connected and atree node is created that contains vertex 10 and its neighbors.

Elimination ordering: 10, 9, 8, 7, 2, 3, 6, 1, 5, 4

TU Dresden, 13th May 2014 PSSAI slide 60 of 73

Page 61: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Perfect Elimination Ordering ctd.

The tree decomposition node withvertices [7,9,10] is connected with thetree decomposition node which iscreated when the next vertex whichappears in [7,9,10] is eliminated (in thiscase vertex 9)

Vertex 9 is eliminated from the graph. All neighbors of vertex 9 are connectedand a new tree node is created.

Elimination ordering: 10, 9, 8, 7, 2, 3, 6, 1, 5, 4

TU Dresden, 13th May 2014 PSSAI slide 61 of 73

Page 62: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Perfect Elimination Ordering ctd.

Elimination ordering: 10, 9, 8, 7, 2, 3, 6, 1, 5, 4

TU Dresden, 13th May 2014 PSSAI slide 62 of 73

Page 63: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Perfect Elimination Ordering ctd.

Elimination ordering: 10, 9, 8, 7, 2, 3, 6, 1, 5, 4

TU Dresden, 13th May 2014 PSSAI slide 63 of 73

Page 64: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Perfect Elimination Ordering ctd.

Elimination ordering: 10, 9, 8, 7, 2, 3, 6, 1, 5, 4

TU Dresden, 13th May 2014 PSSAI slide 64 of 73

Page 65: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Perfect Elimination Ordering ctd.

Elimination ordering: 10, 9, 8, 7, 2, 3, 6, 1, 5, 4

TU Dresden, 13th May 2014 PSSAI slide 65 of 73

Page 66: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Perfect Elimination Ordering ctd.

Elimination ordering: 10, 9, 8, 7, 2, 3, 6, 1, 5, 4

TU Dresden, 13th May 2014 PSSAI slide 66 of 73

Page 67: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Perfect Elimination Ordering ctd.

Elimination ordering: 10, 9, 8, 7, 2, 3, 6, 1, 5, 4

TU Dresden, 13th May 2014 PSSAI slide 67 of 73

Page 68: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Perfect Elimination Ordering ctd.

Elimination ordering: 10, 9, 8, 7, 2, 3, 6, 1, 5, 4

TU Dresden, 13th May 2014 PSSAI slide 68 of 73

Page 69: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Perfect Elimination Ordering ctd.

Elimination ordering: 10, 9, 8, 7, 2, 3, 6, 1, 5, 4

TU Dresden, 13th May 2014 PSSAI slide 69 of 73

Page 70: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Perfect Elimination Ordering ctd.

Elimination ordering: 10, 9, 8, 7, 2, 3, 6, 1, 5, 4

TU Dresden, 13th May 2014 PSSAI slide 70 of 73

Page 71: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Tree Decomposition of a Graph

Width: max(vertices in tree node)−1 = 3.

Treewidth: minimal width over all possible tree decompostions.

TU Dresden, 13th May 2014 PSSAI slide 71 of 73

Page 72: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

Bounded Treewidth for CSP

If a graph has treewidth k, and we are given the corresponding treedecomposition, then the problem can be solved in O(ndk+1) time.

n - number of variables,

d - maximum domain size of any variable in the CSP.

But, finding the decomposition with minimal treewidth is NP-hard.

→ Heuristic methods work well in practice!

TU Dresden, 13th May 2014 PSSAI slide 72 of 73

Page 73: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE€¦ · Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Lecture 6 ASP Modelling,

References

Martin Gebser, Benjamin Kaufmann Roland Kaminski, and TorstenSchaub.Answer Set Solving in Practice.Synthesis Lectures on Artificial Intelligence and Machine Learning.Morgan and Claypool Publishers, 2012.doi=10.2200/S00457ED1V01Y201211AIM019.

Michael Gelfond and Vladimir Lifschitz.Classical negation in logic programs and disjunctive databases.New Generation Comput., 9(3–4):365–386, 1991.

• See also: http://potassco.sourceforge.net

TU Dresden, 13th May 2014 PSSAI slide 73 of 73