problem solving and search in artificial intelligence · problem solving and search in artificial...

147
Artificial Intelligence, Computational Logic PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE Answer-Set Programming Motivation and Introduction * slides adapted from Torsten Schaub [Gebser et al.(2012)] Sarah Gaggl Dresden, 6th May 2014

Upload: dohanh

Post on 20-Feb-2019

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Artificial Intelligence, Computational Logic

PROBLEM SOLVING AND SEARCHIN ARTIFICIAL INTELLIGENCE

Answer-Set Programming Motivation and Introduction∗

slides adapted from Torsten Schaub [Gebser et al.(2012)]

Sarah Gaggl

Dresden, 6th May 2014

Page 2: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

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, 6th May 2014 PSSAI slide 2 of 147

Page 3: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Outline1 Motivation

– Declarative Problem Solving– ASP in a Nutshell– ASP Paradigm

2 Introduction– Syntax– Semantics– Examples– Language Constructs– Modeling

TU Dresden, 6th May 2014 PSSAI slide 3 of 147

Page 4: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Informatics

“What is the problem?” versus “How to solve the problem?”

Problem

Computer

Solution

Output?

-

6

TU Dresden, 6th May 2014 PSSAI slide 4 of 147

Page 5: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Informatics

“What is the problem?” versus “How to solve the problem?”

Problem

Computer

Solution

Output?

-

6

TU Dresden, 6th May 2014 PSSAI slide 5 of 147

Page 6: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Traditional programming

“What is the problem?” versus “How to solve the problem?”

Problem

Computer

Solution

Output?

-

6

TU Dresden, 6th May 2014 PSSAI slide 6 of 147

Page 7: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Traditional programming

“What is the problem?” versus “How to solve the problem?”

Problem

Program

Solution

Output?

-

6

Programming Interpreting

Executing

TU Dresden, 6th May 2014 PSSAI slide 7 of 147

Page 8: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Declarative problem solving

“What is the problem?” versus “How to solve the problem?”

Problem

Computer

Solution

Output?

-

6

Interpreting

TU Dresden, 6th May 2014 PSSAI slide 8 of 147

Page 9: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Declarative problem solving

“What is the problem?” versus “How to solve the problem?”

Problem

Representation

Solution

Output?

-

6

Modeling Interpreting

Solving

TU Dresden, 6th May 2014 PSSAI slide 9 of 147

Page 10: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Declarative problem solving

“What is the problem?” versus “How to solve the problem?”

Problem

Representation

Solution

Output?

-

6

Modeling Interpreting

Solving

TU Dresden, 6th May 2014 PSSAI slide 10 of 147

Page 11: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Answer Set Programmingin a Nutshell

• ASP is an approach to declarative problem solving, combining– a rich yet simple modeling language– with high-performance solving capacities

• ASP has its roots in– (deductive) databases– logic programming (with negation)– (logic-based) knowledge representation and (nonmonotonic)

reasoning– constraint solving (in particular, SATisfiability testing)

• ASP allows for solving all search problems in NP (and NPNP)in a uniform way

• ASP is versatile as reflected by the ASP solver clasp, winningfirst places at ASP, CASC, MISC, PB, and SAT competitions

• ASP embraces many emerging application areas

TU Dresden, 6th May 2014 PSSAI slide 11 of 147

Page 12: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Answer Set Programmingin a Nutshell

• ASP is an approach to declarative problem solving, combining– a rich yet simple modeling language– with high-performance solving capacities

• ASP has its roots in– (deductive) databases– logic programming (with negation)– (logic-based) knowledge representation and (nonmonotonic)

reasoning– constraint solving (in particular, SATisfiability testing)

• ASP allows for solving all search problems in NP (and NPNP)in a uniform way

• ASP is versatile as reflected by the ASP solver clasp, winningfirst places at ASP, CASC, MISC, PB, and SAT competitions

• ASP embraces many emerging application areas

TU Dresden, 6th May 2014 PSSAI slide 12 of 147

Page 13: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Answer Set Programmingin a Nutshell

• ASP is an approach to declarative problem solving, combining– a rich yet simple modeling language– with high-performance solving capacities

• ASP has its roots in– (deductive) databases– logic programming (with negation)– (logic-based) knowledge representation and (nonmonotonic)

reasoning– constraint solving (in particular, SATisfiability testing)

• ASP allows for solving all search problems in NP (and NPNP)in a uniform way

• ASP is versatile as reflected by the ASP solver clasp, winningfirst places at ASP, CASC, MISC, PB, and SAT competitions

• ASP embraces many emerging application areas

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

Page 14: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Answer Set Programmingin a Nutshell

• ASP is an approach to declarative problem solving, combining– a rich yet simple modeling language– with high-performance solving capacities

• ASP has its roots in– (deductive) databases– logic programming (with negation)– (logic-based) knowledge representation and (nonmonotonic)

reasoning– constraint solving (in particular, SATisfiability testing)

• ASP allows for solving all search problems in NP (and NPNP)in a uniform way

• ASP is versatile as reflected by the ASP solver clasp, winningfirst places at ASP, CASC, MISC, PB, and SAT competitions

• ASP embraces many emerging application areas

TU Dresden, 6th May 2014 PSSAI slide 14 of 147

Page 15: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Answer Set Programmingin a Nutshell

• ASP is an approach to declarative problem solving, combining– a rich yet simple modeling language– with high-performance solving capacities

• ASP has its roots in– (deductive) databases– logic programming (with negation)– (logic-based) knowledge representation and (nonmonotonic)

reasoning– constraint solving (in particular, SATisfiability testing)

• ASP allows for solving all search problems in NP (and NPNP)in a uniform way

• ASP is versatile as reflected by the ASP solver clasp, winningfirst places at ASP, CASC, MISC, PB, and SAT competitions

• ASP embraces many emerging application areas

TU Dresden, 6th May 2014 PSSAI slide 15 of 147

Page 16: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Answer Set Programmingin a Nutshell

• ASP is an approach to declarative problem solving, combining– a rich yet simple modeling language– with high-performance solving capacities

• ASP has its roots in– (deductive) databases– logic programming (with negation)– (logic-based) knowledge representation and (nonmonotonic)

reasoning– constraint solving (in particular, SATisfiability testing)

• ASP allows for solving all search problems in NP (and NPNP)in a uniform way

• ASP is versatile as reflected by the ASP solver clasp, winningfirst places at ASP, CASC, MISC, PB, and SAT competitions

• ASP embraces many emerging application areas

TU Dresden, 6th May 2014 PSSAI slide 16 of 147

Page 17: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Answer Set Programmingin a Hazelnutshell

• ASP is an approach to declarative problem solving, combining– a rich yet simple modeling language– with high-performance solving capacities

tailored to Knowledge Representation and Reasoning

TU Dresden, 6th May 2014 PSSAI slide 17 of 147

Page 18: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Answer Set Programmingin a Hazelnutshell

• ASP is an approach to declarative problem solving, combining– a rich yet simple modeling language– with high-performance solving capacities

tailored to Knowledge Representation and Reasoning

ASP = DB+LP+KR+SAT

TU Dresden, 6th May 2014 PSSAI slide 18 of 147

Page 19: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

KR’s shift of paradigm

Theorem Proving based approach (eg. Prolog)1 Provide a representation of the problem2 A solution is given by a derivation of a query

Model Generation based approach (eg. SATisfiability testing)1 Provide a representation of the problem2 A solution is given by a model of the representation

TU Dresden, 6th May 2014 PSSAI slide 19 of 147

Page 20: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

KR’s shift of paradigm

Theorem Proving based approach (eg. Prolog)1 Provide a representation of the problem2 A solution is given by a derivation of a query

Model Generation based approach (eg. SATisfiability testing)1 Provide a representation of the problem2 A solution is given by a model of the representation

TU Dresden, 6th May 2014 PSSAI slide 20 of 147

Page 21: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

KR’s shift of paradigm

Theorem Proving based approach (eg. Prolog)1 Provide a representation of the problem2 A solution is given by a derivation of a query

Model Generation based approach (eg. SATisfiability testing)1 Provide a representation of the problem2 A solution is given by a model of the representation

TU Dresden, 6th May 2014 PSSAI slide 21 of 147

Page 22: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Model Generation based Problem Solving

Representation Solutionconstraint satisfaction problem assignmentpropositional horn theories smallest modelpropositional theories models

SAT

propositional theories minimal modelspropositional theories stable modelspropositional programs minimal modelspropositional programs supported modelspropositional programs stable modelsfirst-order theories modelsfirst-order theories minimal modelsfirst-order theories stable modelsfirst-order theories Herbrand modelsauto-epistemic theories expansionsdefault theories extensions

......

TU Dresden, 6th May 2014 PSSAI slide 22 of 147

Page 23: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Model Generation based Problem Solving

Representation Solutionconstraint satisfaction problem assignmentpropositional horn theories smallest modelpropositional theories models

SAT

propositional theories minimal modelspropositional theories stable modelspropositional programs minimal modelspropositional programs supported modelspropositional programs stable modelsfirst-order theories modelsfirst-order theories minimal modelsfirst-order theories stable modelsfirst-order theories Herbrand modelsauto-epistemic theories expansionsdefault theories extensions

......

TU Dresden, 6th May 2014 PSSAI slide 23 of 147

Page 24: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Model Generation based Problem Solving

Representation Solutionconstraint satisfaction problem assignmentpropositional horn theories smallest modelpropositional theories models SATpropositional theories minimal modelspropositional theories stable modelspropositional programs minimal modelspropositional programs supported modelspropositional programs stable modelsfirst-order theories modelsfirst-order theories minimal modelsfirst-order theories stable modelsfirst-order theories Herbrand modelsauto-epistemic theories expansionsdefault theories extensions

......

TU Dresden, 6th May 2014 PSSAI slide 24 of 147

Page 25: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

LP-style playing with blocks

Prolog programon(a,b).on(b,c).

above(X,Y) :- on(X,Y).above(X,Y) :- on(X,Z), above(Z,Y).

Prolog queries?- above(a,c).true.

?- above(c,a).no.

TU Dresden, 6th May 2014 PSSAI slide 25 of 147

Page 26: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

LP-style playing with blocks

Prolog programon(a,b).on(b,c).

above(X,Y) :- on(X,Y).above(X,Y) :- on(X,Z), above(Z,Y).

Prolog queries?- above(a,c).true.

?- above(c,a).no.

TU Dresden, 6th May 2014 PSSAI slide 26 of 147

Page 27: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

LP-style playing with blocks

Prolog programon(a,b).on(b,c).

above(X,Y) :- on(X,Y).above(X,Y) :- on(X,Z), above(Z,Y).

Prolog queries?- above(a,c).true.

?- above(c,a).no.

TU Dresden, 6th May 2014 PSSAI slide 27 of 147

Page 28: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

LP-style playing with blocks

Prolog programon(a,b).on(b,c).

above(X,Y) :- on(X,Y).above(X,Y) :- on(X,Z), above(Z,Y).

Prolog queries (testing entailment)?- above(a,c).true.

?- above(c,a).no.

TU Dresden, 6th May 2014 PSSAI slide 28 of 147

Page 29: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

LP-style playing with blocks

Shuffled Prolog programon(a,b).on(b,c).

above(X,Y) :- above(X,Z), on(Z,Y).above(X,Y) :- on(X,Y).

Prolog queries?- above(a,c).

Fatal Error: local stack overflow.

TU Dresden, 6th May 2014 PSSAI slide 29 of 147

Page 30: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

LP-style playing with blocks

Shuffled Prolog programon(a,b).on(b,c).

above(X,Y) :- above(X,Z), on(Z,Y).above(X,Y) :- on(X,Y).

Prolog queries?- above(a,c).

Fatal Error: local stack overflow.

TU Dresden, 6th May 2014 PSSAI slide 30 of 147

Page 31: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

LP-style playing with blocks

Shuffled Prolog programon(a,b).on(b,c).

above(X,Y) :- above(X,Z), on(Z,Y).above(X,Y) :- on(X,Y).

Prolog queries (answered via fixed execution)?- above(a,c).

Fatal Error: local stack overflow.

TU Dresden, 6th May 2014 PSSAI slide 31 of 147

Page 32: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

SAT-style playing with blocks

Formula

on(a, b)∧ on(b, c)∧ (on(X, Y)→ above(X, Y))∧ (on(X, Z) ∧ above(Z, Y)→ above(X, Y))

Herbrand model{

on(a, b), on(b, c), on(a, c), on(b, b),above(a, b), above(b, c), above(a, c), above(b, b), above(c, b)

}

TU Dresden, 6th May 2014 PSSAI slide 32 of 147

Page 33: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

SAT-style playing with blocks

Formula

on(a, b)∧ on(b, c)∧ (on(X, Y)→ above(X, Y))∧ (on(X, Z) ∧ above(Z, Y)→ above(X, Y))

Herbrand model{

on(a, b), on(b, c), on(a, c), on(b, b),above(a, b), above(b, c), above(a, c), above(b, b), above(c, b)

}

TU Dresden, 6th May 2014 PSSAI slide 33 of 147

Page 34: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

SAT-style playing with blocks

Formula

on(a, b)∧ on(b, c)∧ (on(X, Y)→ above(X, Y))∧ (on(X, Z) ∧ above(Z, Y)→ above(X, Y))

Herbrand model (among 426!){

on(a, b), on(b, c), on(a, c), on(b, b),above(a, b), above(b, c), above(a, c), above(b, b), above(c, b)

}

TU Dresden, 6th May 2014 PSSAI slide 34 of 147

Page 35: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

SAT-style playing with blocks

Formula

on(a, b)∧ on(b, c)∧ (on(X, Y)→ above(X, Y))∧ (on(X, Z) ∧ above(Z, Y)→ above(X, Y))

Herbrand model (among 426!){

on(a, b), on(b, c), on(a, c), on(b, b),above(a, b), above(b, c), above(a, c), above(b, b), above(c, b)

}

TU Dresden, 6th May 2014 PSSAI slide 35 of 147

Page 36: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

SAT-style playing with blocks

Formula

on(a, b)∧ on(b, c)∧ (on(X, Y)→ above(X, Y))∧ (on(X, Z) ∧ above(Z, Y)→ above(X, Y))

Herbrand model (among 426!){

on(a, b), on(b, c), on(a, c), on(b, b),above(a, b), above(b, c), above(a, c), above(b, b), above(c, b)

}

TU Dresden, 6th May 2014 PSSAI slide 36 of 147

Page 37: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

KR’s shift of paradigm

Theorem Proving based approach (eg. Prolog)1 Provide a representation of the problem2 A solution is given by a derivation of a query

Model Generation based approach (eg. SATisfiability testing)1 Provide a representation of the problem2 A solution is given by a model of the representation

TU Dresden, 6th May 2014 PSSAI slide 37 of 147

Page 38: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

KR’s shift of paradigm

Theorem Proving based approach (eg. Prolog)1 Provide a representation of the problem2 A solution is given by a derivation of a query

Model Generation based approach (eg. SATisfiability testing)1 Provide a representation of the problem2 A solution is given by a model of the representation

å Answer Set Programming (ASP)

TU Dresden, 6th May 2014 PSSAI slide 38 of 147

Page 39: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Model Generation based Problem Solving

Representation Solutionconstraint satisfaction problem assignmentpropositional horn theories smallest modelpropositional theories modelspropositional theories minimal modelspropositional theories stable modelspropositional programs minimal modelspropositional programs supported modelspropositional programs stable modelsfirst-order theories modelsfirst-order theories minimal modelsfirst-order theories stable modelsfirst-order theories Herbrand modelsauto-epistemic theories expansionsdefault theories extensions

......

TU Dresden, 6th May 2014 PSSAI slide 39 of 147

Page 40: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Answer Set Programming at large

Representation Solution

constraint satisfaction problem assignment

propositional horn theories smallest modelpropositional theories modelspropositional theories minimal modelspropositional theories stable modelspropositional programs minimal modelspropositional programs supported modelspropositional programs stable modelsfirst-order theories modelsfirst-order theories minimal modelsfirst-order theories stable modelsfirst-order theories Herbrand modelsauto-epistemic theories expansionsdefault theories extensions

......

TU Dresden, 6th May 2014 PSSAI slide 40 of 147

Page 41: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Answer Set Programming commonly

Representation Solution

constraint satisfaction problem assignmentpropositional horn theories smallest modelpropositional theories modelspropositional theories minimal models

propositional theories stable models

propositional programs minimal modelspropositional programs supported models

propositional programs stable models

first-order theories modelsfirst-order theories minimal models

first-order theories stable models

first-order theories Herbrand modelsauto-epistemic theories expansionsdefault theories extensions

......

TU Dresden, 6th May 2014 PSSAI slide 41 of 147

Page 42: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Answer Set Programming in practice

Representation Solution

constraint satisfaction problem assignmentpropositional horn theories smallest modelpropositional theories modelspropositional theories minimal modelspropositional theories stable modelspropositional programs minimal modelspropositional programs supported models

propositional programs stable models

first-order theories modelsfirst-order theories minimal modelsfirst-order theories stable modelsfirst-order theories Herbrand modelsauto-epistemic theories expansionsdefault theories extensions

......

TU Dresden, 6th May 2014 PSSAI slide 42 of 147

Page 43: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Answer Set Programming in practice

Representation Solution

constraint satisfaction problem assignmentpropositional horn theories smallest modelpropositional theories modelspropositional theories minimal modelspropositional theories stable modelspropositional programs minimal modelspropositional programs supported models

propositional programs stable models

first-order theories modelsfirst-order theories minimal modelsfirst-order theories stable modelsfirst-order theories Herbrand modelsauto-epistemic theories expansionsdefault theories extensions

first-order programs stable Herbrand models

TU Dresden, 6th May 2014 PSSAI slide 43 of 147

Page 44: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

ASP-style playing with blocks

Logic programon(a,b).on(b,c).

above(X,Y) :- on(X,Y).above(X,Y) :- on(X,Z), above(Z,Y).

Stable Herbrand model

{ on(a,b), on(b,c), above(b,c), above(a,b), above(a,c) }

TU Dresden, 6th May 2014 PSSAI slide 44 of 147

Page 45: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

ASP-style playing with blocks

Logic programon(a,b).on(b,c).

above(X,Y) :- on(X,Y).above(X,Y) :- on(X,Z), above(Z,Y).

Stable Herbrand model

{ on(a,b), on(b,c), above(b,c), above(a,b), above(a,c) }

TU Dresden, 6th May 2014 PSSAI slide 45 of 147

Page 46: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

ASP-style playing with blocks

Logic programon(a,b).on(b,c).

above(X,Y) :- on(X,Y).above(X,Y) :- on(X,Z), above(Z,Y).

Stable Herbrand model (and no others)

{ on(a,b), on(b,c), above(b,c), above(a,b), above(a,c) }

TU Dresden, 6th May 2014 PSSAI slide 46 of 147

Page 47: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

ASP-style playing with blocks

Logic programon(a,b).on(b,c).

above(X,Y) :- above(Z,Y), on(X,Z).above(X,Y) :- on(X,Y).

Stable Herbrand model (and no others)

{ on(a,b), on(b,c), above(b,c), above(a,b), above(a,c) }

TU Dresden, 6th May 2014 PSSAI slide 47 of 147

Page 48: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

ASP versus LP

ASP Prolog

Model generation Query orientationBottom-up Top-downModeling language Programming language

Rule-based formatInstantiation UnificationFlat terms Nested terms

(Turing +) NP(NP) Turing

TU Dresden, 6th May 2014 PSSAI slide 48 of 147

Page 49: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

ASP versus SAT

ASP SAT

Model generationBottom-up

Constructive Logic Classical LogicClosed (and open) Open world reasoning

world reasoningModeling language —Complex reasoning modes Satisfiability testing

Satisfiability SatisfiabilityEnumeration/Projection —Optimization —Intersection/Union —

(Turing +) NP(NP) NP

TU Dresden, 6th May 2014 PSSAI slide 49 of 147

Page 50: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

ASP solving

Problem

LogicProgram Grounder Solver Stable

Models

Solution

- - -

?

6

Modeling Interpreting

Solving

TU Dresden, 6th May 2014 PSSAI slide 50 of 147

Page 51: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

SAT solving

Problem

Formula(CNF) Solver Classical

Models

Solution

- -

?

6

Programming Interpreting

Solving

TU Dresden, 6th May 2014 PSSAI slide 51 of 147

Page 52: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Rooting ASP solving

Problem

LogicProgram Grounder Solver Stable

Models

Solution

- - -

?

6

Modeling Interpreting

Solving

TU Dresden, 6th May 2014 PSSAI slide 52 of 147

Page 53: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Rooting ASP solving

Problem

LogicProgram

LP

Grounder

DB

Solver

SAT

StableModels

DB+KR+LP

Solution

- - -

?

6

Modeling KR Interpreting

Solving

TU Dresden, 6th May 2014 PSSAI slide 53 of 147

Page 54: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Two sides of a coin

• ASP as High-level Language– Express problem instance(s) as sets of facts– Encode problem (class) as a set of rules– Read off solutions from stable models of facts and rules

• ASP as Low-level Language– Compile a problem into a logic program– Solve the original problem by solving its compilation

TU Dresden, 6th May 2014 PSSAI slide 54 of 147

Page 55: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

What is ASP good for?• Combinatorial search problems in the realm of P, NP, and NPNP

(some with substantial amount of data), like

– Automated Planning– Code Optimization– Composition of Renaissance Music– Database Integration– Decision Support for NASA shuttle controllers– Model Checking– Product Configuration– Robotics– System Biology– System Synthesis– (industrial) Team-building– and many many more

TU Dresden, 6th May 2014 PSSAI slide 55 of 147

Page 56: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

What is ASP good for?• Combinatorial search problems in the realm of P, NP, and NPNP

(some with substantial amount of data), like– Automated Planning– Code Optimization– Composition of Renaissance Music– Database Integration– Decision Support for NASA shuttle controllers– Model Checking– Product Configuration– Robotics– System Biology– System Synthesis– (industrial) Team-building– and many many more

TU Dresden, 6th May 2014 PSSAI slide 56 of 147

Page 57: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

What does ASP offer?

• Integration of DB, KR, and SAT techniques

• Succinct, elaboration-tolerant problem representations– Rapid application development tool

• Easy handling of dynamic, knowledge intensive applications– including: data, frame axioms, exceptions, defaults, closures, etc

ASP = DB+LP+KR+SAT

TU Dresden, 6th May 2014 PSSAI slide 57 of 147

Page 58: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

What does ASP offer?

• Integration of DB, KR, and SAT techniques

• Succinct, elaboration-tolerant problem representations– Rapid application development tool

• Easy handling of dynamic, knowledge intensive applications– including: data, frame axioms, exceptions, defaults, closures, etc

ASP = DB+LP+KR+SAT

TU Dresden, 6th May 2014 PSSAI slide 58 of 147

Page 59: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Agenda1 Motivation

– Declarative Problem Solving– ASP in a Nutshell– ASP Paradigm

2 Introduction– Syntax– Semantics– Examples– Language Constructs– Modeling

TU Dresden, 6th May 2014 PSSAI slide 59 of 147

Page 60: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Problem solving in ASP: Syntax

Problem

Logic Program

Solution

Stable Models

?-

6

Modeling Interpreting

Solving

TU Dresden, 6th May 2014 PSSAI slide 60 of 147

Page 61: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Normal logic programs• A (normal) logic program over a set A of atoms is a finite set of rules• A (normal) rule, r, is of the form

a0 ← a1, . . . , am, not am+1, . . . , not an

where 0 ≤ m ≤ n and each ai ∈ A is an atom for 0 ≤ i ≤ n

• Notation

head(r) = a0

body(r) = {a1, . . . , am, not am+1, . . . , not an}body(r)+ = {a1, . . . , am}body(r)− = {am+1, . . . , an}

• A program is called positive if body(r)− = ∅ for all its rules

TU Dresden, 6th May 2014 PSSAI slide 61 of 147

Page 62: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Normal logic programs• A (normal) logic program over a set A of atoms is a finite set of rules• A (normal) rule, r, is of the form

a0 ← a1, . . . , am, not am+1, . . . , not an

where 0 ≤ m ≤ n and each ai ∈ A is an atom for 0 ≤ i ≤ n

• Notation

head(r) = a0

body(r) = {a1, . . . , am, not am+1, . . . , not an}body(r)+ = {a1, . . . , am}body(r)− = {am+1, . . . , an}

• A program is called positive if body(r)− = ∅ for all its rules

TU Dresden, 6th May 2014 PSSAI slide 62 of 147

Page 63: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Normal logic programs• A (normal) logic program over a set A of atoms is a finite set of rules• A (normal) rule, r, is of the form

a0 ← a1, . . . , am, not am+1, . . . , not an

where 0 ≤ m ≤ n and each ai ∈ A is an atom for 0 ≤ i ≤ n

• Notation

head(r) = a0

body(r) = {a1, . . . , am, not am+1, . . . , not an}body(r)+ = {a1, . . . , am}body(r)− = {am+1, . . . , an}

• A program is called positive if body(r)− = ∅ for all its rules

TU Dresden, 6th May 2014 PSSAI slide 63 of 147

Page 64: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Rough notational convention

We sometimes use the following notation interchangeablyin order to stress the respective view:

default classicaltrue, false if and or iff negation negation

source code :- , | not -logic program ← , ; not ¬formula ⊥,> → ∧ ∨ ↔ ∼ ¬

TU Dresden, 6th May 2014 PSSAI slide 64 of 147

Page 65: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Problem solving in ASP: Semantics

Problem

Logic Program

Solution

Stable Models

?-

6

Modeling Interpreting

Solving

TU Dresden, 6th May 2014 PSSAI slide 65 of 147

Page 66: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Formal DefinitionStable models of positive programs

• A set of atoms X is closed under a positive program P ifffor any r ∈ P, head(r) ∈ X whenever body(r)+ ⊆ X

– X corresponds to a model of P (seen as a formula)

• The smallest set of atoms which is closed under a positive program P isdenoted by Cn(P)

– Cn(P) corresponds to the ⊆-smallest model of P (ditto)

• The set Cn(P) of atoms is the stable model of a positive program P

TU Dresden, 6th May 2014 PSSAI slide 66 of 147

Page 67: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Formal DefinitionStable models of positive programs

• A set of atoms X is closed under a positive program P ifffor any r ∈ P, head(r) ∈ X whenever body(r)+ ⊆ X

– X corresponds to a model of P (seen as a formula)

• The smallest set of atoms which is closed under a positive program P isdenoted by Cn(P)

– Cn(P) corresponds to the ⊆-smallest model of P (ditto)

• The set Cn(P) of atoms is the stable model of a positive program P

TU Dresden, 6th May 2014 PSSAI slide 67 of 147

Page 68: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Formal DefinitionStable models of positive programs

• A set of atoms X is closed under a positive program P ifffor any r ∈ P, head(r) ∈ X whenever body(r)+ ⊆ X

– X corresponds to a model of P (seen as a formula)

• The smallest set of atoms which is closed under a positive program P isdenoted by Cn(P)

– Cn(P) corresponds to the ⊆-smallest model of P (ditto)

• The set Cn(P) of atoms is the stable model of a positive program P

TU Dresden, 6th May 2014 PSSAI slide 68 of 147

Page 69: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Formal DefinitionStable models of positive programs

• A set of atoms X is closed under a positive program P ifffor any r ∈ P, head(r) ∈ X whenever body(r)+ ⊆ X

– X corresponds to a model of P (seen as a formula)

• The smallest set of atoms which is closed under a positive program P isdenoted by Cn(P)

– Cn(P) corresponds to the ⊆-smallest model of P (ditto)

• The set Cn(P) of atoms is the stable model of a positive program P

TU Dresden, 6th May 2014 PSSAI slide 69 of 147

Page 70: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Some “logical” remarks• Positive rules are also referred to as definite clauses

– Definite clauses are disjunctions with exactly one positive atom:

a0 ∨ ¬a1 ∨ · · · ∨ ¬am

– A set of definite clauses has a (unique) smallest model

• Horn clauses are clauses with at most one positive atom– Every definite clause is a Horn clause but not vice versa– Non-definite Horn clauses can be regarded as integrity constraints

– A set of Horn clauses has a smallest model or none

• This smallest model is the intended semantics of such sets of clauses– Given a positive program P, Cn(P) corresponds to the smallest

model of the set of definite clauses corresponding to P

TU Dresden, 6th May 2014 PSSAI slide 70 of 147

Page 71: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Some “logical” remarks• Positive rules are also referred to as definite clauses

– Definite clauses are disjunctions with exactly one positive atom:

a0 ∨ ¬a1 ∨ · · · ∨ ¬am

– A set of definite clauses has a (unique) smallest model

• Horn clauses are clauses with at most one positive atom– Every definite clause is a Horn clause but not vice versa– Non-definite Horn clauses can be regarded as integrity constraints

– A set of Horn clauses has a smallest model or none

• This smallest model is the intended semantics of such sets of clauses– Given a positive program P, Cn(P) corresponds to the smallest

model of the set of definite clauses corresponding to P

TU Dresden, 6th May 2014 PSSAI slide 71 of 147

Page 72: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Some “logical” remarks• Positive rules are also referred to as definite clauses

– Definite clauses are disjunctions with exactly one positive atom:

a0 ∨ ¬a1 ∨ · · · ∨ ¬am

– A set of definite clauses has a (unique) smallest model

• Horn clauses are clauses with at most one positive atom– Every definite clause is a Horn clause but not vice versa– Non-definite Horn clauses can be regarded as integrity constraints

– A set of Horn clauses has a smallest model or none

• This smallest model is the intended semantics of such sets of clauses– Given a positive program P, Cn(P) corresponds to the smallest

model of the set of definite clauses corresponding to P

TU Dresden, 6th May 2014 PSSAI slide 72 of 147

Page 73: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Basic idea

Consider the logical formula Φ and its three(classical) models:

HHHHH

HHjp 7→ 1q 7→ 1r 7→ 0

{p, q}, {q, r}, and {p, q, r}

Φ q ∧ (q ∧ ¬r→ p)

Formula Φ has one stable model,often called answer set:

{p, q}

PΦ q ←p ← q, not r

Informally, a set X of atoms is a stable model of a logic program P

• if X is a (classical) model of P and• if all atoms in X are justified by some rule in P

(rooted in intuitionistic logics HT (Heyting, 1930) andG3 (Gödel, 1932))

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

Page 74: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Basic ideaConsider the logical formula Φ and its three(classical) models:

HHHHH

HHjp 7→ 1q 7→ 1r 7→ 0

{p, q}, {q, r}, and {p, q, r}

Φ q ∧ (q ∧ ¬r→ p)

Formula Φ has one stable model,often called answer set:

{p, q}

PΦ q ←p ← q, not r

Informally, a set X of atoms is a stable model of a logic program P

• if X is a (classical) model of P and• if all atoms in X are justified by some rule in P

(rooted in intuitionistic logics HT (Heyting, 1930) andG3 (Gödel, 1932))

TU Dresden, 6th May 2014 PSSAI slide 74 of 147

Page 75: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Basic ideaConsider the logical formula Φ and its three(classical) models:

HHHHH

HHjp 7→ 1q 7→ 1r 7→ 0

{p, q}, {q, r}, and {p, q, r}

Φ q ∧ (q ∧ ¬r→ p)

Formula Φ has one stable model,often called answer set:

{p, q}

PΦ q ←p ← q, not r

Informally, a set X of atoms is a stable model of a logic program P

• if X is a (classical) model of P and• if all atoms in X are justified by some rule in P

(rooted in intuitionistic logics HT (Heyting, 1930) andG3 (Gödel, 1932))

TU Dresden, 6th May 2014 PSSAI slide 75 of 147

Page 76: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Basic ideaConsider the logical formula Φ and its three(classical) models:

HHHHH

HHjp 7→ 1q 7→ 1r 7→ 0

{p, q}, {q, r}, and {p, q, r}

Φ q ∧ (q ∧ ¬r→ p)

Formula Φ has one stable model,often called answer set:

{p, q}

PΦ q ←p ← q, not r

Informally, a set X of atoms is a stable model of a logic program P

• if X is a (classical) model of P and• if all atoms in X are justified by some rule in P

(rooted in intuitionistic logics HT (Heyting, 1930) andG3 (Gödel, 1932))

TU Dresden, 6th May 2014 PSSAI slide 76 of 147

Page 77: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Basic ideaConsider the logical formula Φ and its three(classical) models:

HHHHH

HHjp 7→ 1q 7→ 1r 7→ 0

{p, q}, {q, r}, and {p, q, r}

Φ q ∧ (q ∧ ¬r→ p)

Formula Φ has one stable model,often called answer set:

{p, q}

PΦ q ←p ← q, not r

Informally, a set X of atoms is a stable model of a logic program P

• if X is a (classical) model of P and• if all atoms in X are justified by some rule in P

(rooted in intuitionistic logics HT (Heyting, 1930) andG3 (Gödel, 1932))

TU Dresden, 6th May 2014 PSSAI slide 77 of 147

Page 78: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Basic ideaConsider the logical formula Φ and its three(classical) models:

HHHHH

HHjp 7→ 1q 7→ 1r 7→ 0

{p, q}, {q, r}, and {p, q, r}

Φ q ∧ (q ∧ ¬r→ p)

Formula Φ has one stable model,often called answer set:

{p, q}

PΦ q ←p ← q, not r

Informally, a set X of atoms is a stable model of a logic program P

• if X is a (classical) model of P and• if all atoms in X are justified by some rule in P

(rooted in intuitionistic logics HT (Heyting, 1930) andG3 (Gödel, 1932))

TU Dresden, 6th May 2014 PSSAI slide 78 of 147

Page 79: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Basic ideaConsider the logical formula Φ and its three(classical) models:

HHHHH

HHjp 7→ 1q 7→ 1r 7→ 0

{p, q}, {q, r}, and {p, q, r}

Φ q ∧ (q ∧ ¬r→ p)

Formula Φ has one stable model,often called answer set:

{p, q}

PΦ q ←p ← q, not r

Informally, a set X of atoms is a stable model of a logic program P

• if X is a (classical) model of P and• if all atoms in X are justified by some rule in P

(rooted in intuitionistic logics HT (Heyting, 1930) andG3 (Gödel, 1932))

TU Dresden, 6th May 2014 PSSAI slide 79 of 147

Page 80: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Basic idea

Consider the logical formula Φ and its three(classical) models:

HHHHH

HHjp 7→ 1q 7→ 1r 7→ 0

{p, q}, {q, r}, and {p, q, r}

Φ q ∧ (q ∧ ¬r→ p)

Formula Φ has one stable model,often called answer set:

{p, q}

PΦ q ←p ← q, not r

Informally, a set X of atoms is a stable model of a logic program P

• if X is a (classical) model of P and• if all atoms in X are justified by some rule in P

(rooted in intuitionistic logics HT (Heyting, 1930) andG3 (Gödel, 1932))

TU Dresden, 6th May 2014 PSSAI slide 80 of 147

Page 81: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Formal DefinitionStable model of normal programs

• The Gelfond-Lifschitz Reduct[Gelfond and Lifschitz(1991)], PX , of aprogram P relative to a set X of atoms is defined by

PX = {head(r)← body(r)+ | r ∈ P and body(r)− ∩ X = ∅}

• A set X of atoms is a stable model of a program P, if Cn(PX) = X

• Note: Cn(PX) is the ⊆–smallest (classical) model of PX

• Note: Every atom in X is justified by an “applying rule from P”

TU Dresden, 6th May 2014 PSSAI slide 81 of 147

Page 82: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Formal DefinitionStable model of normal programs

• The Gelfond-Lifschitz Reduct[Gelfond and Lifschitz(1991)], PX , of aprogram P relative to a set X of atoms is defined by

PX = {head(r)← body(r)+ | r ∈ P and body(r)− ∩ X = ∅}

• A set X of atoms is a stable model of a program P, if Cn(PX) = X

• Note: Cn(PX) is the ⊆–smallest (classical) model of PX

• Note: Every atom in X is justified by an “applying rule from P”

TU Dresden, 6th May 2014 PSSAI slide 82 of 147

Page 83: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Formal DefinitionStable model of normal programs

• The Gelfond-Lifschitz Reduct[Gelfond and Lifschitz(1991)], PX , of aprogram P relative to a set X of atoms is defined by

PX = {head(r)← body(r)+ | r ∈ P and body(r)− ∩ X = ∅}

• A set X of atoms is a stable model of a program P, if Cn(PX) = X

• Note: Cn(PX) is the ⊆–smallest (classical) model of PX

• Note: Every atom in X is justified by an “applying rule from P”

TU Dresden, 6th May 2014 PSSAI slide 83 of 147

Page 84: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

A closer look at PX

• In other words, given a set X of atoms from P,

PX is obtained from P by deleting1 each rule having not a in its body with a ∈ X

and then2 all negative atoms of the form not a

in the bodies of the remaining rules

• Note: Only negative body literals are evaluated w.r.t. X

TU Dresden, 6th May 2014 PSSAI slide 84 of 147

Page 85: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

A closer look at PX

• In other words, given a set X of atoms from P,

PX is obtained from P by deleting1 each rule having not a in its body with a ∈ X

and then2 all negative atoms of the form not a

in the bodies of the remaining rules

• Note: Only negative body literals are evaluated w.r.t. X

TU Dresden, 6th May 2014 PSSAI slide 85 of 147

Page 86: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

A first example

P = {p← p, q← not p}

X

PX

Cn(PX)∅

p ← pq ←

{q} 8

{p}

p ← p ∅ 8

{q}

p ← pq ←

{q} 4

{p, q}

p ← p ∅ 8

TU Dresden, 6th May 2014 PSSAI slide 86 of 147

Page 87: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

A first example

P = {p← p, q← not p}

X

PX

Cn(PX)∅

p ← pq ←

{q} 8

{p}

p ← p ∅ 8

{q}

p ← pq ←

{q} 4

{p, q}

p ← p ∅ 8

TU Dresden, 6th May 2014 PSSAI slide 87 of 147

Page 88: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

A first example

P = {p← p, q← not p}

X PX Cn(PX)∅ p ← p

q ←{q}

8

{p} p ← p ∅

8

{q} p ← pq ←

{q}

4

{p, q} p ← p ∅

8

TU Dresden, 6th May 2014 PSSAI slide 88 of 147

Page 89: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

A first example

P = {p← p, q← not p}

X PX Cn(PX)∅ p ← p

q ←{q} 8

{p} p ← p ∅

8

{q} p ← pq ←

{q}

4

{p, q} p ← p ∅

8

TU Dresden, 6th May 2014 PSSAI slide 89 of 147

Page 90: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

A first example

P = {p← p, q← not p}

X PX Cn(PX)∅ p ← p

q ←{q} 8

{p} p ← p ∅ 8

{q} p ← pq ←

{q}

4

{p, q} p ← p ∅

8

TU Dresden, 6th May 2014 PSSAI slide 90 of 147

Page 91: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

A first example

P = {p← p, q← not p}

X PX Cn(PX)∅ p ← p

q ←{q} 8

{p} p ← p ∅ 8

{q} p ← pq ←

{q} 4

{p, q} p ← p ∅

8

TU Dresden, 6th May 2014 PSSAI slide 91 of 147

Page 92: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

A first example

P = {p← p, q← not p}

X PX Cn(PX)∅ p ← p

q ←{q} 8

{p} p ← p ∅ 8

{q} p ← pq ←

{q} 4

{p, q} p ← p ∅ 8

TU Dresden, 6th May 2014 PSSAI slide 92 of 147

Page 93: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

A second example

P = {p← not q, q← not p}

X PX Cn(PX)∅ p ←

q ←{p, q}

8

{p} p ← {p}

4

{q}q ←

{q}

4

{p, q} ∅

8

TU Dresden, 6th May 2014 PSSAI slide 93 of 147

Page 94: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

A second example

P = {p← not q, q← not p}

X PX Cn(PX)∅ p ←

q ←{p, q}

8

{p} p ← {p}

4

{q}q ←

{q}

4

{p, q} ∅

8

TU Dresden, 6th May 2014 PSSAI slide 94 of 147

Page 95: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

A second example

P = {p← not q, q← not p}

X PX Cn(PX)∅ p ←

q ←{p, q} 8

{p} p ← {p}

4

{q}q ←

{q}

4

{p, q} ∅

8

TU Dresden, 6th May 2014 PSSAI slide 95 of 147

Page 96: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

A second example

P = {p← not q, q← not p}

X PX Cn(PX)∅ p ←

q ←{p, q} 8

{p} p ← {p} 4

{q}q ←

{q}

4

{p, q} ∅

8

TU Dresden, 6th May 2014 PSSAI slide 96 of 147

Page 97: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

A second example

P = {p← not q, q← not p}

X PX Cn(PX)∅ p ←

q ←{p, q} 8

{p} p ← {p} 4

{q}q ←

{q} 4

{p, q} ∅

8

TU Dresden, 6th May 2014 PSSAI slide 97 of 147

Page 98: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

A second example

P = {p← not q, q← not p}

X PX Cn(PX)∅ p ←

q ←{p, q} 8

{p} p ← {p} 4

{q}q ←

{q} 4

{p, q} ∅ 8

TU Dresden, 6th May 2014 PSSAI slide 98 of 147

Page 99: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

A third example

P = {p← not p}

X PX Cn(PX)∅ p ← {p}

8

{p} ∅

8

TU Dresden, 6th May 2014 PSSAI slide 99 of 147

Page 100: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

A third example

P = {p← not p}

X PX Cn(PX)∅ p ← {p}

8

{p} ∅

8

TU Dresden, 6th May 2014 PSSAI slide 100 of 147

Page 101: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

A third example

P = {p← not p}

X PX Cn(PX)∅ p ← {p} 8

{p} ∅

8

TU Dresden, 6th May 2014 PSSAI slide 101 of 147

Page 102: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

A third example

P = {p← not p}

X PX Cn(PX)∅ p ← {p} 8

{p} ∅ 8

TU Dresden, 6th May 2014 PSSAI slide 102 of 147

Page 103: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Some properties

• A logic program may have zero, one, or multiple stable models!

• If X is an stable model of a logic program P,then X is a model of P (seen as a formula)

• If X and Y are stable models of a normal program P,then X 6⊂ Y

TU Dresden, 6th May 2014 PSSAI slide 103 of 147

Page 104: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Some properties

• A logic program may have zero, one, or multiple stable models!• If X is an stable model of a logic program P,

then X is a model of P (seen as a formula)• If X and Y are stable models of a normal program P,

then X 6⊂ Y

TU Dresden, 6th May 2014 PSSAI slide 104 of 147

Page 105: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Programs with Variables

Let P be a logic program• Let T be a set of (variable-free) terms

(also called Herbrand universe)

• Let A be a set of (variable-free) atoms constructable from T

(also called alphabet or Herbrand base)• Ground Instances of r ∈ P: Set of variable-free rules obtained by

replacing all variables in r by elements from T :

ground(r) = {rθ | θ : var(r)→ T , var(rθ) = ∅}

where var(r) stands for the set of all variables occurring in r;θ is a (ground) substitution

• Ground Instantiation of P: ground(P) =⋃

r∈Pground(r)

TU Dresden, 6th May 2014 PSSAI slide 105 of 147

Page 106: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Programs with Variables

Let P be a logic program• Let T be a set of

(

variable-free

)

terms (also called Herbrand universe)• Let A be a set of (variable-free) atoms constructable from T

(also called alphabet or Herbrand base)

• Ground Instances of r ∈ P: Set of variable-free rules obtained byreplacing all variables in r by elements from T :

ground(r) = {rθ | θ : var(r)→ T , var(rθ) = ∅}

where var(r) stands for the set of all variables occurring in r;θ is a (ground) substitution

• Ground Instantiation of P: ground(P) =⋃

r∈Pground(r)

TU Dresden, 6th May 2014 PSSAI slide 106 of 147

Page 107: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Programs with Variables

Let P be a logic program• Let T be a set of (variable-free) terms

(also called Herbrand universe)

• Let A be a set of (variable-free) atoms constructable from T

(also called alphabet or Herbrand base)

• Ground Instances of r ∈ P: Set of variable-free rules obtained byreplacing all variables in r by elements from T :

ground(r) = {rθ | θ : var(r)→ T , var(rθ) = ∅}

where var(r) stands for the set of all variables occurring in r;θ is a (ground) substitution

• Ground Instantiation of P: ground(P) =⋃

r∈Pground(r)

TU Dresden, 6th May 2014 PSSAI slide 107 of 147

Page 108: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Programs with Variables

Let P be a logic program• Let T be a set of (variable-free) terms

(also called Herbrand universe)

• Let A be a set of (variable-free) atoms constructable from T

(also called alphabet or Herbrand base)

• Ground Instances of r ∈ P: Set of variable-free rules obtained byreplacing all variables in r by elements from T :

ground(r) = {rθ | θ : var(r)→ T , var(rθ) = ∅}

where var(r) stands for the set of all variables occurring in r;θ is a (ground) substitution

• Ground Instantiation of P: ground(P) =⋃

r∈Pground(r)

TU Dresden, 6th May 2014 PSSAI slide 108 of 147

Page 109: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

An example

P= { r(a, b)←, r(b, c)←, t(X, Y)← r(X, Y) }

T = {a, b, c}

A=

{r(a, a), r(a, b), r(a, c), r(b, a), r(b, b), r(b, c), r(c, a), r(c, b), r(c, c),t(a, a), t(a, b), t(a, c), t(b, a), t(b, b), t(b, c), t(c, a), t(c, b), t(c, c)

}

ground(P) =

r(a, b) ← ,r(b, c) ← ,t(a, a) ← r(a, a), t(b, a) ← r(b, a), t(c, a) ← r(c, a),t(a, b) ← r(a, b), t(b, b) ← r(b, b), t(c, b) ← r(c, b),t(a, c) ← r(a, c), t(b, c) ← r(b, c), t(c, c) ← r(c, c)

• Intelligent Grounding aims at reducing the groundinstantiation

TU Dresden, 6th May 2014 PSSAI slide 109 of 147

Page 110: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

An example

P= { r(a, b)←, r(b, c)←, t(X, Y)← r(X, Y) }

T = {a, b, c}

A=

{r(a, a), r(a, b), r(a, c), r(b, a), r(b, b), r(b, c), r(c, a), r(c, b), r(c, c),t(a, a), t(a, b), t(a, c), t(b, a), t(b, b), t(b, c), t(c, a), t(c, b), t(c, c)

}

ground(P) =

r(a, b) ← ,r(b, c) ← ,t(a, a) ← r(a, a), t(b, a) ← r(b, a), t(c, a) ← r(c, a),t(a, b) ← r(a, b), t(b, b) ← r(b, b), t(c, b) ← r(c, b),t(a, c) ← r(a, c), t(b, c) ← r(b, c), t(c, c) ← r(c, c)

• Intelligent Grounding aims at reducing the groundinstantiation

TU Dresden, 6th May 2014 PSSAI slide 110 of 147

Page 111: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

An example

P= { r(a, b)←, r(b, c)←, t(X, Y)← r(X, Y) }

T = {a, b, c}

A=

{r(a, a), r(a, b), r(a, c), r(b, a), r(b, b), r(b, c), r(c, a), r(c, b), r(c, c),t(a, a), t(a, b), t(a, c), t(b, a), t(b, b), t(b, c), t(c, a), t(c, b), t(c, c)

}

ground(P) =

r(a, b) ← ,r(b, c) ← ,

t(a, a) ← r(a, a), t(b, a) ← r(b, a), t(c, a) ← r(c, a),

t(a, b) ←

r(a, b)

,

t(b, b) ← r(b, b), t(c, b) ← r(c, b),t(a, c) ← r(a, c),

t(b, c) ←

r(b, c), t(c, c) ← r(c, c)

• Intelligent Grounding aims at reducing the ground

instantiationTU Dresden, 6th May 2014 PSSAI slide 111 of 147

Page 112: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Stable models of programs with Variables

Let P be a normal logic program with variables

• A set X of (ground) atoms is a stable model of P,

if Cn(ground(P)X) = X

TU Dresden, 6th May 2014 PSSAI slide 112 of 147

Page 113: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Stable models of programs with Variables

Let P be a normal logic program with variables

• A set X of (ground) atoms is a stable model of P,

if Cn(ground(P)X) = X

TU Dresden, 6th May 2014 PSSAI slide 113 of 147

Page 114: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

———————————————————————-

TU Dresden, 6th May 2014 PSSAI slide 114 of 147

Page 115: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Problem solving in ASP: Extended Syntax

Problem

Logic Program

Solution

Stable Models

?-

6

Modeling Interpreting

Solving

TU Dresden, 6th May 2014 PSSAI slide 115 of 147

Page 116: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Language Constructs

• Variables (over the Herbrand Universe)– p(X) :- q(X) over constants {a,b,c} stands for

p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)

• Conditional Literals– p :- q(X) : r(X) given r(a), r(b), r(c) stands for

p :- q(a), q(b), q(c)

• Disjunction– p(X) | q(X) :- r(X)

• Integrity Constraints– :- q(X), p(X)

• Choice– 2 { p(X,Y) : q(X) } 7 :- r(Y)

• Aggregates– s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7– also: #sum, #avg, #min, #max, #even, #odd

TU Dresden, 6th May 2014 PSSAI slide 116 of 147

Page 117: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Language Constructs• Variables (over the Herbrand Universe)

– p(X) :- q(X) over constants {a,b,c} stands forp(a) :- q(a), p(b) :- q(b), p(c) :- q(c)

• Conditional Literals– p :- q(X) : r(X) given r(a), r(b), r(c) stands for

p :- q(a), q(b), q(c)

• Disjunction– p(X) | q(X) :- r(X)

• Integrity Constraints– :- q(X), p(X)

• Choice– 2 { p(X,Y) : q(X) } 7 :- r(Y)

• Aggregates– s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7– also: #sum, #avg, #min, #max, #even, #odd

TU Dresden, 6th May 2014 PSSAI slide 117 of 147

Page 118: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Language Constructs

• Variables (over the Herbrand Universe)– p(X) :- q(X) over constants {a,b,c} stands for

p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)

• Conditional Literals– p :- q(X) : r(X) given r(a), r(b), r(c) stands for

p :- q(a), q(b), q(c)

• Disjunction– p(X) | q(X) :- r(X)

• Integrity Constraints– :- q(X), p(X)

• Choice– 2 { p(X,Y) : q(X) } 7 :- r(Y)

• Aggregates– s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7– also: #sum, #avg, #min, #max, #even, #odd

TU Dresden, 6th May 2014 PSSAI slide 118 of 147

Page 119: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Language Constructs

• Variables (over the Herbrand Universe)– p(X) :- q(X) over constants {a,b,c} stands for

p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)

• Conditional Literals– p :- q(X) : r(X) given r(a), r(b), r(c) stands for

p :- q(a), q(b), q(c)

• Disjunction– p(X) | q(X) :- r(X)

• Integrity Constraints– :- q(X), p(X)

• Choice– 2 { p(X,Y) : q(X) } 7 :- r(Y)

• Aggregates– s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7– also: #sum, #avg, #min, #max, #even, #odd

TU Dresden, 6th May 2014 PSSAI slide 119 of 147

Page 120: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Language Constructs

• Variables (over the Herbrand Universe)– p(X) :- q(X) over constants {a,b,c} stands for

p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)

• Conditional Literals– p :- q(X) : r(X) given r(a), r(b), r(c) stands for

p :- q(a), q(b), q(c)

• Disjunction– p(X) | q(X) :- r(X)

• Integrity Constraints– :- q(X), p(X)

• Choice– 2 { p(X,Y) : q(X) } 7 :- r(Y)

• Aggregates– s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7– also: #sum, #avg, #min, #max, #even, #odd

TU Dresden, 6th May 2014 PSSAI slide 120 of 147

Page 121: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Language Constructs

• Variables (over the Herbrand Universe)– p(X) :- q(X) over constants {a,b,c} stands for

p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)

• Conditional Literals– p :- q(X) : r(X) given r(a), r(b), r(c) stands for

p :- q(a), q(b), q(c)

• Disjunction– p(X) | q(X) :- r(X)

• Integrity Constraints– :- q(X), p(X)

• Choice– 2 { p(X,Y) : q(X) } 7 :- r(Y)

• Aggregates– s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7– also: #sum, #avg, #min, #max, #even, #odd

TU Dresden, 6th May 2014 PSSAI slide 121 of 147

Page 122: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Language Constructs

• Variables (over the Herbrand Universe)– p(X) :- q(X) over constants {a,b,c} stands for

p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)

• Conditional Literals– p :- q(X) : r(X) given r(a), r(b), r(c) stands for

p :- q(a), q(b), q(c)

• Disjunction– p(X) | q(X) :- r(X)

• Integrity Constraints– :- q(X), p(X)

• Choice– 2 { p(X,Y) : q(X) } 7 :- r(Y)

• Aggregates– s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7– also: #sum, #avg, #min, #max, #even, #odd

TU Dresden, 6th May 2014 PSSAI slide 122 of 147

Page 123: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Language Constructs• Variables (over the Herbrand Universe)

– p(X) :- q(X) over constants {a,b,c} stands forp(a) :- q(a), p(b) :- q(b), p(c) :- q(c)

• Conditional Literals– p :- q(X) : r(X) given r(a), r(b), r(c) stands for

p :- q(a), q(b), q(c)

• Disjunction– p(X) | q(X) :- r(X)

• Integrity Constraints– :- q(X), p(X)

• Choice– 2 { p(X,Y) : q(X) } 7 :- r(Y)

• Aggregates– s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7– also: #sum, #avg, #min, #max, #even, #odd

TU Dresden, 6th May 2014 PSSAI slide 123 of 147

Page 124: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

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, 6th May 2014 PSSAI slide 124 of 147

Page 125: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

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, 6th May 2014 PSSAI slide 125 of 147

Page 126: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

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, 6th May 2014 PSSAI slide 126 of 147

Page 127: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Example 3-Colorability

• Vertices are represented with predicates vertex(X);• Edges are represented with predicates edge(X, Y).

Question: Is there a valid assignment of three colors for an input graph G suchthat no two adjacent vertices have the same color?

TU Dresden, 6th May 2014 PSSAI slide 127 of 147

Page 128: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Graph coloring

node(1..6).

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

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 6th May 2014 PSSAI slide 128 of 147

Page 129: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Graph coloring

node(1..6).

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

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 6th May 2014 PSSAI slide 129 of 147

Page 130: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Graph coloring

node(1..6).

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

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 6th May 2014 PSSAI slide 130 of 147

Page 131: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Graph coloring

node(1..6).

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

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 6th May 2014 PSSAI slide 131 of 147

Page 132: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Graph coloring

node(1..6).

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

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 6th May 2014 PSSAI slide 132 of 147

Page 133: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Graph coloring

node(1..6).

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

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 6th May 2014 PSSAI slide 133 of 147

Page 134: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Graph coloring

node(1..6).

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

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 6th May 2014 PSSAI slide 134 of 147

Page 135: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Graph coloring

node(1..6).

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

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 6th May 2014 PSSAI slide 135 of 147

Page 136: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Graph coloring

node(1..6).

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

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 6th May 2014 PSSAI slide 136 of 147

Page 137: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

color.lp

node(1..6).

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

col(r). col(b). col(g).

Probleminstance

1 { color(X,C) : col(C) } 1 :- node(X).

:- edge(X,Y), color(X,C), color(Y,C).

}Problemencoding

TU Dresden, 6th May 2014 PSSAI slide 137 of 147

Page 138: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

ASP solving process

Problem

LogicProgram Grounder Solver Stable

Models

Solution

- - -

?

6

Modeling Interpreting

Solving

TU Dresden, 6th May 2014 PSSAI slide 138 of 147

Page 139: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Graph coloring: Grounding

$ gringo --text color.lp

node(1). node(2). node(3). node(4). node(5). node(6).

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

col(r). col(b). col(g).

1 {color(1,r), color(1,b), color(1,g)} 1.1 {color(2,r), color(2,b), color(2,g)} 1.1 {color(3,r), color(3,b), color(3,g)} 1.1 {color(4,r), color(4,b), color(4,g)} 1.1 {color(5,r), color(5,b), color(5,g)} 1.1 {color(6,r), color(6,b), color(6,g)} 1.

:- color(1,r), color(2,r). :- color(2,g), color(5,g). ... :- color(6,r), color(2,r).:- color(1,b), color(2,b). :- color(2,r), color(6,r). :- color(6,b), color(2,b).:- color(1,g), color(2,g). :- color(2,b), color(6,b). :- color(6,g), color(2,g).:- color(1,r), color(3,r). :- color(2,g), color(6,g). :- color(6,r), color(3,r).:- color(1,b), color(3,b). :- color(3,r), color(1,r). :- color(6,b), color(3,b).:- color(1,g), color(3,g). :- color(3,b), color(1,b). :- color(6,g), color(3,g).:- color(1,r), color(4,r). :- color(3,g), color(1,g). :- color(6,r), color(5,r).:- color(1,b), color(4,b). :- color(3,r), color(4,r). :- color(6,b), color(5,b).:- color(1,g), color(4,g). :- color(3,b), color(4,b). :- color(6,g), color(5,g).:- color(2,r), color(4,r). :- color(3,g), color(4,g).:- color(2,b), color(4,b). :- color(3,r), color(5,r).:- color(2,g), color(4,g). :- color(3,b), color(5,b).:- color(2,r), color(5,r). :- color(3,g), color(5,g).:- color(2,b), color(5,b). :- color(4,r), color(1,r).

TU Dresden, 6th May 2014 PSSAI slide 139 of 147

Page 140: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Graph coloring: Grounding

$ gringo --text color.lp

node(1). node(2). node(3). node(4). node(5). node(6).

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

col(r). col(b). col(g).

1 {color(1,r), color(1,b), color(1,g)} 1.1 {color(2,r), color(2,b), color(2,g)} 1.1 {color(3,r), color(3,b), color(3,g)} 1.1 {color(4,r), color(4,b), color(4,g)} 1.1 {color(5,r), color(5,b), color(5,g)} 1.1 {color(6,r), color(6,b), color(6,g)} 1.

:- color(1,r), color(2,r). :- color(2,g), color(5,g). ... :- color(6,r), color(2,r).:- color(1,b), color(2,b). :- color(2,r), color(6,r). :- color(6,b), color(2,b).:- color(1,g), color(2,g). :- color(2,b), color(6,b). :- color(6,g), color(2,g).:- color(1,r), color(3,r). :- color(2,g), color(6,g). :- color(6,r), color(3,r).:- color(1,b), color(3,b). :- color(3,r), color(1,r). :- color(6,b), color(3,b).:- color(1,g), color(3,g). :- color(3,b), color(1,b). :- color(6,g), color(3,g).:- color(1,r), color(4,r). :- color(3,g), color(1,g). :- color(6,r), color(5,r).:- color(1,b), color(4,b). :- color(3,r), color(4,r). :- color(6,b), color(5,b).:- color(1,g), color(4,g). :- color(3,b), color(4,b). :- color(6,g), color(5,g).:- color(2,r), color(4,r). :- color(3,g), color(4,g).:- color(2,b), color(4,b). :- color(3,r), color(5,r).:- color(2,g), color(4,g). :- color(3,b), color(5,b).:- color(2,r), color(5,r). :- color(3,g), color(5,g).:- color(2,b), color(5,b). :- color(4,r), color(1,r).

TU Dresden, 6th May 2014 PSSAI slide 140 of 147

Page 141: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

ASP solving process

Problem

LogicProgram Grounder Solver Stable

Models

Solution

- - -

?

6

Modeling Interpreting

Solving

TU Dresden, 6th May 2014 PSSAI slide 141 of 147

Page 142: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Graph coloring: Solving

$ gringo color.lp | clasp 0

clasp version 2.1.0Reading from stdinSolving...Answer: 1edge(1,2) ... col(r) ... node(1) ... color(6,b) color(5,g) color(4,b) color(3,r) color(2,r) color(1,g)Answer: 2edge(1,2) ... col(r) ... node(1) ... color(6,r) color(5,g) color(4,r) color(3,b) color(2,b) color(1,g)Answer: 3edge(1,2) ... col(r) ... node(1) ... color(6,g) color(5,b) color(4,g) color(3,r) color(2,r) color(1,b)Answer: 4edge(1,2) ... col(r) ... node(1) ... color(6,r) color(5,b) color(4,r) color(3,g) color(2,g) color(1,b)Answer: 5edge(1,2) ... col(r) ... node(1) ... color(6,g) color(5,r) color(4,g) color(3,b) color(2,b) color(1,r)Answer: 6edge(1,2) ... col(r) ... node(1) ... color(6,b) color(5,r) color(4,b) color(3,g) color(2,g) color(1,r)SATISFIABLE

Models : 6Time : 0.002s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s)CPU Time : 0.000s

TU Dresden, 6th May 2014 PSSAI slide 142 of 147

Page 143: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Graph coloring: Solving

$ gringo color.lp | clasp 0

clasp version 2.1.0Reading from stdinSolving...Answer: 1edge(1,2) ... col(r) ... node(1) ... color(6,b) color(5,g) color(4,b) color(3,r) color(2,r) color(1,g)Answer: 2edge(1,2) ... col(r) ... node(1) ... color(6,r) color(5,g) color(4,r) color(3,b) color(2,b) color(1,g)Answer: 3edge(1,2) ... col(r) ... node(1) ... color(6,g) color(5,b) color(4,g) color(3,r) color(2,r) color(1,b)Answer: 4edge(1,2) ... col(r) ... node(1) ... color(6,r) color(5,b) color(4,r) color(3,g) color(2,g) color(1,b)Answer: 5edge(1,2) ... col(r) ... node(1) ... color(6,g) color(5,r) color(4,g) color(3,b) color(2,b) color(1,r)Answer: 6edge(1,2) ... col(r) ... node(1) ... color(6,b) color(5,r) color(4,b) color(3,g) color(2,g) color(1,r)SATISFIABLE

Models : 6Time : 0.002s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s)CPU Time : 0.000s

TU Dresden, 6th May 2014 PSSAI slide 143 of 147

Page 144: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Guess & Check Methodology1 Guess all possible assignments of colors;2 Check whether adjacent vertices have indeed different colors.

πcol = πguess ∪ πcheck

πguess = { red(X)← vertex(X), not green(X), not blue(X);

green(X)← vertex(X), not red(X), not blue(X);

blue(X)← vertex(X), not red(X), not green(X) }πcheck = { fail← red(X), red(Y), edge(X, Y);

fail← green(X), green(Y), edge(X, Y);

fail← blue(X), blue(Y), edge(X, Y);

← fail }

TU Dresden, 6th May 2014 PSSAI slide 144 of 147

Page 145: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Problem solving in ASP: Reasoning Modes

Problem

Logic Program

Solution

Stable Models

?-

6

Modeling Interpreting

Solving

TU Dresden, 6th May 2014 PSSAI slide 145 of 147

Page 146: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

Reasoning Modes

• Satisfiability• Enumeration†

• Projection†

• Intersection‡

• Union‡

• Optimization

• and combinations of them

† without solution recording‡ without solution enumeration

TU Dresden, 6th May 2014 PSSAI slide 146 of 147

Page 147: PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE · PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE ... Solving TU Dresden, 6th May 2014 PSSAI slide 9 of 147. ... TU Dresden,

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, 6th May 2014 PSSAI slide 147 of 147