unit 2 -- asp extensions › asptut › slides › unit2.pdf · 2008-01-30 · intro weak...

137

Upload: others

Post on 03-Jul-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

Answer Set Programming for the Semantic Web

Tutorial

Thomas Eiter, Roman Schindlauer (TU Wien)Giovambattista Ianni (TU Wien, Univ. della Calabria)

Axel Polleres (Univ. Rey Juan Carlos, Madrid)

Supported by IST REWERSE, FWF Project P17212-N04, CICyT project TIC-2003-9001-C02.

G. Ianni Unit 2 � ASP Extensions

Page 2: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

Unit 2 � ASP Extensions

G. Ianni

Dipartimento di Matematica - Università della Calabria

European Semantic Web Conference 2006

G. Ianni Unit 2 � ASP Extensions

Page 3: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

Unit Outline

1 Introduction

2 Weak constraints

3 Aggregate Atoms

4 Frame Logic Syntax

5 Template Predicates

6 References

G. Ianni Unit 2 � ASP Extensions

Page 4: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

Logic Programming Extensions

• Besides disjunction and strong negation, many extensions ofnormal logic programs have been proposed

• Some of these extensions are motivated by applications

• Some of these extensions are syntactic sugar, other strictly addexpressiveness

• Comprehensive survey of extensions:

See http://www.tcs.hut.fi/Research/Logic/wasp/wp3/

• Here, we consider some DLV speci�c extensions.

G. Ianni Unit 2 � ASP Extensions

Page 5: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

Logic Programming Extensions

• Besides disjunction and strong negation, many extensions ofnormal logic programs have been proposed

• Some of these extensions are motivated by applications

• Some of these extensions are syntactic sugar, other strictly addexpressiveness

• Comprehensive survey of extensions:

See http://www.tcs.hut.fi/Research/Logic/wasp/wp3/

• Here, we consider some DLV speci�c extensions.

G. Ianni Unit 2 � ASP Extensions

Page 6: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

Logic Programming Extensions

• Besides disjunction and strong negation, many extensions ofnormal logic programs have been proposed

• Some of these extensions are motivated by applications

• Some of these extensions are syntactic sugar, other strictly addexpressiveness

• Comprehensive survey of extensions:

See http://www.tcs.hut.fi/Research/Logic/wasp/wp3/

• Here, we consider some DLV speci�c extensions.

G. Ianni Unit 2 � ASP Extensions

Page 7: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

Logic Programming Extensions

• Besides disjunction and strong negation, many extensions ofnormal logic programs have been proposed

• Some of these extensions are motivated by applications

• Some of these extensions are syntactic sugar, other strictly addexpressiveness

• Comprehensive survey of extensions:

See http://www.tcs.hut.fi/Research/Logic/wasp/wp3/

• Here, we consider some DLV speci�c extensions.

G. Ianni Unit 2 � ASP Extensions

Page 8: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

Logic Programming Extensions

• Besides disjunction and strong negation, many extensions ofnormal logic programs have been proposed

• Some of these extensions are motivated by applications

• Some of these extensions are syntactic sugar, other strictly addexpressiveness

• Comprehensive survey of extensions:

See http://www.tcs.hut.fi/Research/Logic/wasp/wp3/

• Here, we consider some DLV speci�c extensions.

G. Ianni Unit 2 � ASP Extensions

Page 9: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Weak Constraints

• Allow the formalization of optimization problems in an easyand natural way.

• Constraints vs. weak constraints:• Constraints �kill� unwanted models;• Weak constraints express desiderata which should be satis�ed,

if possible.

• The answer sets of a program P with a set W of weakconstraints are those answer sets of P which minimize thenumber of violated constraints.

• Such answer sets are called optimal or best models of (P,W ).

• Other solvers feature similar constructs.

G. Ianni Unit 2 � ASP Extensions

Page 10: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Weak Constraints

• Allow the formalization of optimization problems in an easyand natural way.

• Constraints vs. weak constraints:• Constraints �kill� unwanted models;• Weak constraints express desiderata which should be satis�ed,

if possible.

• The answer sets of a program P with a set W of weakconstraints are those answer sets of P which minimize thenumber of violated constraints.

• Such answer sets are called optimal or best models of (P,W ).

• Other solvers feature similar constructs.

G. Ianni Unit 2 � ASP Extensions

Page 11: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Weak Constraints

• Allow the formalization of optimization problems in an easyand natural way.

• Constraints vs. weak constraints:• Constraints �kill� unwanted models;• Weak constraints express desiderata which should be satis�ed,

if possible.

• The answer sets of a program P with a set W of weakconstraints are those answer sets of P which minimize thenumber of violated constraints.

• Such answer sets are called optimal or best models of (P,W ).

• Other solvers feature similar constructs.

G. Ianni Unit 2 � ASP Extensions

Page 12: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Weak Constraints

• Allow the formalization of optimization problems in an easyand natural way.

• Constraints vs. weak constraints:• Constraints �kill� unwanted models;• Weak constraints express desiderata which should be satis�ed,

if possible.

• The answer sets of a program P with a set W of weakconstraints are those answer sets of P which minimize thenumber of violated constraints.

• Such answer sets are called optimal or best models of (P,W ).

• Other solvers feature similar constructs.

G. Ianni Unit 2 � ASP Extensions

Page 13: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Weak Constraints

• Allow the formalization of optimization problems in an easyand natural way.

• Constraints vs. weak constraints:• Constraints �kill� unwanted models;• Weak constraints express desiderata which should be satis�ed,

if possible.

• The answer sets of a program P with a set W of weakconstraints are those answer sets of P which minimize thenumber of violated constraints.

• Such answer sets are called optimal or best models of (P,W ).

• Other solvers feature similar constructs.

G. Ianni Unit 2 � ASP Extensions

Page 14: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Weak Constraints

• Allow the formalization of optimization problems in an easyand natural way.

• Constraints vs. weak constraints:• Constraints �kill� unwanted models;• Weak constraints express desiderata which should be satis�ed,

if possible.

• The answer sets of a program P with a set W of weakconstraints are those answer sets of P which minimize thenumber of violated constraints.

• Such answer sets are called optimal or best models of (P,W ).

• Other solvers feature similar constructs.

G. Ianni Unit 2 � ASP Extensions

Page 15: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Weak Constraints

• Allow the formalization of optimization problems in an easyand natural way.

• Constraints vs. weak constraints:• Constraints �kill� unwanted models;• Weak constraints express desiderata which should be satis�ed,

if possible.

• The answer sets of a program P with a set W of weakconstraints are those answer sets of P which minimize thenumber of violated constraints.

• Such answer sets are called optimal or best models of (P,W ).

• Other solvers feature similar constructs.

G. Ianni Unit 2 � ASP Extensions

Page 16: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Syntax and Semantics

• Syntax:

: ~ b1, · · · , bk, not bk+1, · · · , not bm. [Weight : Level]

• In the presence of weights, best models minimize the sum ofthe weights of violated constraints.

• Semantics: minimizes the violation of constraints with highestpriority level �rst; then with the lower priority levels indescending order.

• Level part is syntactic sugar, can be compiled into weights.

G. Ianni Unit 2 � ASP Extensions

Page 17: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Syntax and Semantics

• Syntax:

: ~ b1, · · · , bk, not bk+1, · · · , not bm. [Weight : Level]

• In the presence of weights, best models minimize the sum ofthe weights of violated constraints.

• Semantics: minimizes the violation of constraints with highestpriority level �rst; then with the lower priority levels indescending order.

• Level part is syntactic sugar, can be compiled into weights.

G. Ianni Unit 2 � ASP Extensions

Page 18: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Syntax and Semantics

• Syntax:

: ~ b1, · · · , bk, not bk+1, · · · , not bm. [Weight : Level]

• In the presence of weights, best models minimize the sum ofthe weights of violated constraints.

• Semantics: minimizes the violation of constraints with highestpriority level �rst; then with the lower priority levels indescending order.

• Level part is syntactic sugar, can be compiled into weights.

G. Ianni Unit 2 � ASP Extensions

Page 19: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Syntax and Semantics

• Syntax:

: ~ b1, · · · , bk, not bk+1, · · · , not bm. [Weight : Level]

• In the presence of weights, best models minimize the sum ofthe weights of violated constraints.

• Semantics: minimizes the violation of constraints with highestpriority level �rst; then with the lower priority levels indescending order.

• Level part is syntactic sugar, can be compiled into weights.

G. Ianni Unit 2 � ASP Extensions

Page 20: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Weak Constraints: Examples

a v b.

c :- b.

:~ a.

:~ b.

:~ c.

Best model: a Cost ([Weight:Level]): <[1:1]> Answer set {b, c}is discarded because it violates two weak constraints!

G. Ianni Unit 2 � ASP Extensions

Page 21: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Weak Constraints: Examples

a v b.

c :- b.

:~ a.

:~ b.

:~ c.

Best model: a Cost ([Weight:Level]): <[1:1]> Answer set {b, c}is discarded because it violates two weak constraints!

G. Ianni Unit 2 � ASP Extensions

Page 22: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Weak Constraints: Examples

a v b.

c :- b.

:~ a.

:~ b.

:~ c.

Best model: a Cost ([Weight:Level]): <[1:1]> Answer set {b, c}is discarded because it violates two weak constraints!

G. Ianni Unit 2 � ASP Extensions

Page 23: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Weak Constraints: Examples /2

a v b.

:~ a. [1:] :~ a. [1:] :~ b. [2:]

Best model: b Cost ([Weight:Level]): <[2:1]>Best model: a Cost ([Weight:Level]): <[2:1]>

a v b1 v b2.

:~ a. [:1] :~ b1. [:2] :~ b2. [:2]

Best model: a Cost ([Weight:Level]): <[1:1],[0:2]>

G. Ianni Unit 2 � ASP Extensions

Page 24: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Weak Constraints: Examples /2

a v b.

:~ a. [1:] :~ a. [1:] :~ b. [2:]

Best model: b Cost ([Weight:Level]): <[2:1]>Best model: a Cost ([Weight:Level]): <[2:1]>

a v b1 v b2.

:~ a. [:1] :~ b1. [:2] :~ b2. [:2]

Best model: a Cost ([Weight:Level]): <[1:1],[0:2]>

G. Ianni Unit 2 � ASP Extensions

Page 25: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Weak Constraints: Examples /2

a v b.

:~ a. [1:] :~ a. [1:] :~ b. [2:]

Best model: b Cost ([Weight:Level]): <[2:1]>Best model: a Cost ([Weight:Level]): <[2:1]>

a v b1 v b2.

:~ a. [:1] :~ b1. [:2] :~ b2. [:2]

Best model: a Cost ([Weight:Level]): <[1:1],[0:2]>

G. Ianni Unit 2 � ASP Extensions

Page 26: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Weak Constraints: Examples /2

a v b.

:~ a. [1:] :~ a. [1:] :~ b. [2:]

Best model: b Cost ([Weight:Level]): <[2:1]>Best model: a Cost ([Weight:Level]): <[2:1]>

a v b1 v b2.

:~ a. [:1] :~ b1. [:2] :~ b2. [:2]

Best model: a Cost ([Weight:Level]): <[1:1],[0:2]>

G. Ianni Unit 2 � ASP Extensions

Page 27: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

A bigger example - Employee Assignment

• Goal: Divide employees in two project groups p1 and p21.

1 Skills of group members should be di�erent.2 Persons in the same group should not be married to each other.3 Members of a group should possibly know each other.

• Requirement 1) is more important than 2) and 3), which areequally important

• Layers express the relative importance of the requirements.

assign(X,p1) v assign(X,p2) :- employee(X).

:~ assign(X,P), assign(Y,P), same_skill(X,Y). [:2]

:~ assign(X,P), assign(Y,P), married(X,Y). [:1]

:~ assign(X,P), assign(Y,P), X!=Y, not know(X,Y).[:1]

1Example assignment.dlvG. Ianni Unit 2 � ASP Extensions

Page 28: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

A bigger example - Employee Assignment

• Goal: Divide employees in two project groups p1 and p21.

1 Skills of group members should be di�erent.2 Persons in the same group should not be married to each other.3 Members of a group should possibly know each other.

• Requirement 1) is more important than 2) and 3), which areequally important

• Layers express the relative importance of the requirements.

assign(X,p1) v assign(X,p2) :- employee(X).

:~ assign(X,P), assign(Y,P), same_skill(X,Y). [:2]

:~ assign(X,P), assign(Y,P), married(X,Y). [:1]

:~ assign(X,P), assign(Y,P), X!=Y, not know(X,Y).[:1]

1Example assignment.dlvG. Ianni Unit 2 � ASP Extensions

Page 29: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

A bigger example - Employee Assignment

• Goal: Divide employees in two project groups p1 and p21.

1 Skills of group members should be di�erent.2 Persons in the same group should not be married to each other.3 Members of a group should possibly know each other.

• Requirement 1) is more important than 2) and 3), which areequally important

• Layers express the relative importance of the requirements.

assign(X,p1) v assign(X,p2) :- employee(X).

:~ assign(X,P), assign(Y,P), same_skill(X,Y). [:2]

:~ assign(X,P), assign(Y,P), married(X,Y). [:1]

:~ assign(X,P), assign(Y,P), X!=Y, not know(X,Y).[:1]

1Example assignment.dlvG. Ianni Unit 2 � ASP Extensions

Page 30: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

A bigger example - Employee Assignment

• Goal: Divide employees in two project groups p1 and p21.

1 Skills of group members should be di�erent.2 Persons in the same group should not be married to each other.3 Members of a group should possibly know each other.

• Requirement 1) is more important than 2) and 3), which areequally important

• Layers express the relative importance of the requirements.

assign(X,p1) v assign(X,p2) :- employee(X).

:~ assign(X,P), assign(Y,P), same_skill(X,Y). [:2]

:~ assign(X,P), assign(Y,P), married(X,Y). [:1]

:~ assign(X,P), assign(Y,P), X!=Y, not know(X,Y).[:1]

1Example assignment.dlvG. Ianni Unit 2 � ASP Extensions

Page 31: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

A bigger example - Employee Assignment

• Goal: Divide employees in two project groups p1 and p21.

1 Skills of group members should be di�erent.2 Persons in the same group should not be married to each other.3 Members of a group should possibly know each other.

• Requirement 1) is more important than 2) and 3), which areequally important

• Layers express the relative importance of the requirements.

assign(X,p1) v assign(X,p2) :- employee(X).

:~ assign(X,P), assign(Y,P), same_skill(X,Y). [:2]

:~ assign(X,P), assign(Y,P), married(X,Y). [:1]

:~ assign(X,P), assign(Y,P), X!=Y, not know(X,Y).[:1]

1Example assignment.dlvG. Ianni Unit 2 � ASP Extensions

Page 32: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

A bigger example - Employee Assignment

• Goal: Divide employees in two project groups p1 and p21.

1 Skills of group members should be di�erent.2 Persons in the same group should not be married to each other.3 Members of a group should possibly know each other.

• Requirement 1) is more important than 2) and 3), which areequally important

• Layers express the relative importance of the requirements.

assign(X,p1) v assign(X,p2) :- employee(X).

:~ assign(X,P), assign(Y,P), same_skill(X,Y). [:2]

:~ assign(X,P), assign(Y,P), married(X,Y). [:1]

:~ assign(X,P), assign(Y,P), X!=Y, not know(X,Y).[:1]

1Example assignment.dlvG. Ianni Unit 2 � ASP Extensions

Page 33: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

A bigger example - Employee Assignment

• Goal: Divide employees in two project groups p1 and p21.

1 Skills of group members should be di�erent.2 Persons in the same group should not be married to each other.3 Members of a group should possibly know each other.

• Requirement 1) is more important than 2) and 3), which areequally important

• Layers express the relative importance of the requirements.

assign(X,p1) v assign(X,p2) :- employee(X).

:~ assign(X,P), assign(Y,P), same_skill(X,Y). [:2]

:~ assign(X,P), assign(Y,P), married(X,Y). [:1]

:~ assign(X,P), assign(Y,P), X!=Y, not know(X,Y).[:1]

1Example assignment.dlvG. Ianni Unit 2 � ASP Extensions

Page 34: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

A bigger example - Employee Assignment

• Goal: Divide employees in two project groups p1 and p21.

1 Skills of group members should be di�erent.2 Persons in the same group should not be married to each other.3 Members of a group should possibly know each other.

• Requirement 1) is more important than 2) and 3), which areequally important

• Layers express the relative importance of the requirements.

assign(X,p1) v assign(X,p2) :- employee(X).

:~ assign(X,P), assign(Y,P), same_skill(X,Y). [:2]

:~ assign(X,P), assign(Y,P), married(X,Y). [:1]

:~ assign(X,P), assign(Y,P), X!=Y, not know(X,Y).[:1]

1Example assignment.dlvG. Ianni Unit 2 � ASP Extensions

Page 35: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

A bigger example - Employee Assignment

• Goal: Divide employees in two project groups p1 and p21.

1 Skills of group members should be di�erent.2 Persons in the same group should not be married to each other.3 Members of a group should possibly know each other.

• Requirement 1) is more important than 2) and 3), which areequally important

• Layers express the relative importance of the requirements.

assign(X,p1) v assign(X,p2) :- employee(X).

:~ assign(X,P), assign(Y,P), same_skill(X,Y). [:2]

:~ assign(X,P), assign(Y,P), married(X,Y). [:1]

:~ assign(X,P), assign(Y,P), X!=Y, not know(X,Y).[:1]

1Example assignment.dlvG. Ianni Unit 2 � ASP Extensions

Page 36: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

A bigger example - Employee Assignment

• Goal: Divide employees in two project groups p1 and p21.

1 Skills of group members should be di�erent.2 Persons in the same group should not be married to each other.3 Members of a group should possibly know each other.

• Requirement 1) is more important than 2) and 3), which areequally important

• Layers express the relative importance of the requirements.

assign(X,p1) v assign(X,p2) :- employee(X).

:~ assign(X,P), assign(Y,P), same_skill(X,Y). [:2]

:~ assign(X,P), assign(Y,P), married(X,Y). [:1]

:~ assign(X,P), assign(Y,P), X!=Y, not know(X,Y).[:1]

1Example assignment.dlvG. Ianni Unit 2 � ASP Extensions

Page 37: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

A bigger example - Employee Assignment

• Goal: Divide employees in two project groups p1 and p21.

1 Skills of group members should be di�erent.2 Persons in the same group should not be married to each other.3 Members of a group should possibly know each other.

• Requirement 1) is more important than 2) and 3), which areequally important

• Layers express the relative importance of the requirements.

assign(X,p1) v assign(X,p2) :- employee(X).

:~ assign(X,P), assign(Y,P), same_skill(X,Y). [:2]

:~ assign(X,P), assign(Y,P), married(X,Y). [:1]

:~ assign(X,P), assign(Y,P), X!=Y, not know(X,Y).[:1]

1Example assignment.dlvG. Ianni Unit 2 � ASP Extensions

Page 38: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

A bigger example - Employee Assignment

• Goal: Divide employees in two project groups p1 and p21.

1 Skills of group members should be di�erent.2 Persons in the same group should not be married to each other.3 Members of a group should possibly know each other.

• Requirement 1) is more important than 2) and 3), which areequally important

• Layers express the relative importance of the requirements.

assign(X,p1) v assign(X,p2) :- employee(X).

:~ assign(X,P), assign(Y,P), same_skill(X,Y). [:2]

:~ assign(X,P), assign(Y,P), married(X,Y). [:1]

:~ assign(X,P), assign(Y,P), X!=Y, not know(X,Y).[:1]

1Example assignment.dlvG. Ianni Unit 2 � ASP Extensions

Page 39: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Guess-Check-Optimize Methodology

• Extend the �Guess & Check� Methodology

• Use weak constraints to �lter out best (optimal) solutions

�Guess-Check-Optimize� : Divide P into three main parts:

Guessing Part

G ⊆ P: Answer_Sets(G ∪ FI ) represent �solution candidates� for instance I .

Checking Part (optional)

C ⊆ P: Answer_Sets(G ∪ C ∪ FI ) represent the admissible solutions for I .

Optimization Part (optional)

The optimization part O ⊆ P consists of weak constraints, and implicitlyde�nes an objective function f : Answer_Sets(G ∪ C ∪ FI ) → NThose answer sets minimizing f are selected.

G. Ianni Unit 2 � ASP Extensions

Page 40: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Guess-Check-Optimize Methodology

• Extend the �Guess & Check� Methodology

• Use weak constraints to �lter out best (optimal) solutions

�Guess-Check-Optimize� : Divide P into three main parts:

Guessing Part

G ⊆ P: Answer_Sets(G ∪ FI ) represent �solution candidates� for instance I .

Checking Part (optional)

C ⊆ P: Answer_Sets(G ∪ C ∪ FI ) represent the admissible solutions for I .

Optimization Part (optional)

The optimization part O ⊆ P consists of weak constraints, and implicitlyde�nes an objective function f : Answer_Sets(G ∪ C ∪ FI ) → NThose answer sets minimizing f are selected.

G. Ianni Unit 2 � ASP Extensions

Page 41: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Guess-Check-Optimize Methodology

• Extend the �Guess & Check� Methodology

• Use weak constraints to �lter out best (optimal) solutions

�Guess-Check-Optimize� : Divide P into three main parts:

Guessing Part

G ⊆ P: Answer_Sets(G ∪ FI ) represent �solution candidates� for instance I .

Checking Part (optional)

C ⊆ P: Answer_Sets(G ∪ C ∪ FI ) represent the admissible solutions for I .

Optimization Part (optional)

The optimization part O ⊆ P consists of weak constraints, and implicitlyde�nes an objective function f : Answer_Sets(G ∪ C ∪ FI ) → NThose answer sets minimizing f are selected.

G. Ianni Unit 2 � ASP Extensions

Page 42: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Guess-Check-Optimize Methodology

• Extend the �Guess & Check� Methodology

• Use weak constraints to �lter out best (optimal) solutions

�Guess-Check-Optimize� : Divide P into three main parts:

Guessing Part

G ⊆ P: Answer_Sets(G ∪ FI ) represent �solution candidates� for instance I .

Checking Part (optional)

C ⊆ P: Answer_Sets(G ∪ C ∪ FI ) represent the admissible solutions for I .

Optimization Part (optional)

The optimization part O ⊆ P consists of weak constraints, and implicitlyde�nes an objective function f : Answer_Sets(G ∪ C ∪ FI ) → NThose answer sets minimizing f are selected.

G. Ianni Unit 2 � ASP Extensions

Page 43: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Guess-Check-Optimize Methodology

• Extend the �Guess & Check� Methodology

• Use weak constraints to �lter out best (optimal) solutions

�Guess-Check-Optimize� : Divide P into three main parts:

Guessing Part

G ⊆ P: Answer_Sets(G ∪ FI ) represent �solution candidates� for instance I .

Checking Part (optional)

C ⊆ P: Answer_Sets(G ∪ C ∪ FI ) represent the admissible solutions for I .

Optimization Part (optional)

The optimization part O ⊆ P consists of weak constraints, and implicitlyde�nes an objective function f : Answer_Sets(G ∪ C ∪ FI ) → NThose answer sets minimizing f are selected.

G. Ianni Unit 2 � ASP Extensions

Page 44: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Guess-Check-Optimize Methodology

• Extend the �Guess & Check� Methodology

• Use weak constraints to �lter out best (optimal) solutions

�Guess-Check-Optimize� : Divide P into three main parts:

Guessing Part

G ⊆ P: Answer_Sets(G ∪ FI ) represent �solution candidates� for instance I .

Checking Part (optional)

C ⊆ P: Answer_Sets(G ∪ C ∪ FI ) represent the admissible solutions for I .

Optimization Part (optional)

The optimization part O ⊆ P consists of weak constraints, and implicitlyde�nes an objective function f : Answer_Sets(G ∪ C ∪ FI ) → NThose answer sets minimizing f are selected.

G. Ianni Unit 2 � ASP Extensions

Page 45: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Guess-Check-Optimize Methodology

• Extend the �Guess & Check� Methodology

• Use weak constraints to �lter out best (optimal) solutions

�Guess-Check-Optimize� : Divide P into three main parts:

Guessing Part

G ⊆ P: Answer_Sets(G ∪ FI ) represent �solution candidates� for instance I .

Checking Part (optional)

C ⊆ P: Answer_Sets(G ∪ C ∪ FI ) represent the admissible solutions for I .

Optimization Part (optional)

The optimization part O ⊆ P consists of weak constraints, and implicitlyde�nes an objective function f : Answer_Sets(G ∪ C ∪ FI ) → NThose answer sets minimizing f are selected.

G. Ianni Unit 2 � ASP Extensions

Page 46: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Social Dinner III

Task

Now that we have de�ned bottleChosen as the solution predicate,is there a way to select only the smallest sets of wines? Try toexpand wineCover4.dlv

?

Solution available as wineCover5.dlv

G. Ianni Unit 2 � ASP Extensions

Page 47: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Social Dinner III

Task

Now that we have de�ned bottleChosen as the solution predicate,is there a way to select only the smallest sets of wines? Try toexpand wineCover4.dlv

?

Solution available as wineCover5.dlv

G. Ianni Unit 2 � ASP Extensions

Page 48: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Social Dinner III

Task

Now that we have de�ned bottleChosen as the solution predicate,is there a way to select only the smallest sets of wines? Try toexpand wineCover4.dlv

:~ bottleChosen(X). [1:1]

Solution available as wineCover5.dlv

G. Ianni Unit 2 � ASP Extensions

Page 49: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Social Dinner III

Task

Now that we have de�ned bottleChosen as the solution predicate,is there a way to select only the smallest sets of wines? Try toexpand wineCover4.dlv

:~ bottleChosen(X). [1:1]

Solution available as wineCover5.dlv

G. Ianni Unit 2 � ASP Extensions

Page 50: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Weak Constraints with Weights

• A single weak constraints in some layer n is more importantthan all weak constraints in lower layers (n − 1, n − 2,...)together!

• Weak constraints are weighted to make �ner distinctionsamong elements of the same priority::˜ G1.[3.5:1] :˜ G2.[4.6:1]

• The weights of violated weak constraints are summed up foreach layer.

• Example: High School Time Tabling ProblemStructural Requirements > Pedagogical Requirements >Personal Wishes

G. Ianni Unit 2 � ASP Extensions

Page 51: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Weak Constraints with Weights

• A single weak constraints in some layer n is more importantthan all weak constraints in lower layers (n − 1, n − 2,...)together!

• Weak constraints are weighted to make �ner distinctionsamong elements of the same priority::˜ G1.[3.5:1] :˜ G2.[4.6:1]

• The weights of violated weak constraints are summed up foreach layer.

• Example: High School Time Tabling ProblemStructural Requirements > Pedagogical Requirements >Personal Wishes

G. Ianni Unit 2 � ASP Extensions

Page 52: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Weak Constraints with Weights

• A single weak constraints in some layer n is more importantthan all weak constraints in lower layers (n − 1, n − 2,...)together!

• Weak constraints are weighted to make �ner distinctionsamong elements of the same priority::˜ G1.[3.5:1] :˜ G2.[4.6:1]

• The weights of violated weak constraints are summed up foreach layer.

• Example: High School Time Tabling ProblemStructural Requirements > Pedagogical Requirements >Personal Wishes

G. Ianni Unit 2 � ASP Extensions

Page 53: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Weak Constraints with Weights

• A single weak constraints in some layer n is more importantthan all weak constraints in lower layers (n − 1, n − 2,...)together!

• Weak constraints are weighted to make �ner distinctionsamong elements of the same priority::˜ G1.[3.5:1] :˜ G2.[4.6:1]

• The weights of violated weak constraints are summed up foreach layer.

• Example: High School Time Tabling ProblemStructural Requirements > Pedagogical Requirements >Personal Wishes

G. Ianni Unit 2 � ASP Extensions

Page 54: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Traveling Salesperson

Given: Weighted directed graph G = (V ,E ,C) and a node a ∈ V of this graph.Task: Find a minimum-cost cycle (closed path) in G starting at a and going througheach node in V exactly once2.

• G stored by facts over predicates node(X) and arc(X,Y).• Starting node a is speci�ed by the predicate start (unary).

Guess:

inPath(X,Y,C) v outPath(X,Y,C) :- start(X), arc(X,Y,C).

inPath(X,Y,C) v outPath(X,Y,C) :- reached(X), arc(X,Y,C).

reached(X):- inPath(Y,X,C).

Check:

:- inPath(X,Y,_), inPath(X,Y1,_), Y <> Y1.

:- inPath(X,Y,_), inPath(X1,Y,_), X <> X1.

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

Optimize:

:~ inPath(X,Y,C). [C:1]

2Example tsp.dlvG. Ianni Unit 2 � ASP Extensions

Page 55: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Traveling Salesperson

Given: Weighted directed graph G = (V ,E ,C) and a node a ∈ V of this graph.Task: Find a minimum-cost cycle (closed path) in G starting at a and going througheach node in V exactly once2.

• G stored by facts over predicates node(X) and arc(X,Y).• Starting node a is speci�ed by the predicate start (unary).

Guess:

inPath(X,Y,C) v outPath(X,Y,C) :- start(X), arc(X,Y,C).

inPath(X,Y,C) v outPath(X,Y,C) :- reached(X), arc(X,Y,C).

reached(X):- inPath(Y,X,C).

Check:

:- inPath(X,Y,_), inPath(X,Y1,_), Y <> Y1.

:- inPath(X,Y,_), inPath(X1,Y,_), X <> X1.

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

Optimize:

:~ inPath(X,Y,C). [C:1]

2Example tsp.dlvG. Ianni Unit 2 � ASP Extensions

Page 56: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Traveling Salesperson

Given: Weighted directed graph G = (V ,E ,C) and a node a ∈ V of this graph.Task: Find a minimum-cost cycle (closed path) in G starting at a and going througheach node in V exactly once2.

• G stored by facts over predicates node(X) and arc(X,Y).• Starting node a is speci�ed by the predicate start (unary).

Guess:

inPath(X,Y,C) v outPath(X,Y,C) :- start(X), arc(X,Y,C).

inPath(X,Y,C) v outPath(X,Y,C) :- reached(X), arc(X,Y,C).

reached(X):- inPath(Y,X,C).

Check:

:- inPath(X,Y,_), inPath(X,Y1,_), Y <> Y1.

:- inPath(X,Y,_), inPath(X1,Y,_), X <> X1.

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

Optimize:

:~ inPath(X,Y,C). [C:1]

2Example tsp.dlvG. Ianni Unit 2 � ASP Extensions

Page 57: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Traveling Salesperson

Given: Weighted directed graph G = (V ,E ,C) and a node a ∈ V of this graph.Task: Find a minimum-cost cycle (closed path) in G starting at a and going througheach node in V exactly once2.

• G stored by facts over predicates node(X) and arc(X,Y).• Starting node a is speci�ed by the predicate start (unary).

Guess:

inPath(X,Y,C) v outPath(X,Y,C) :- start(X), arc(X,Y,C).

inPath(X,Y,C) v outPath(X,Y,C) :- reached(X), arc(X,Y,C).

reached(X):- inPath(Y,X,C).

Check:

:- inPath(X,Y,_), inPath(X,Y1,_), Y <> Y1.

:- inPath(X,Y,_), inPath(X1,Y,_), X <> X1.

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

Optimize:

:~ inPath(X,Y,C). [C:1]

2Example tsp.dlvG. Ianni Unit 2 � ASP Extensions

Page 58: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Social Dinner IV

Task

Let each wine bootle have a price encoded byprice(bottle,value). Modify wineCover5b.dlv and try tochoose the best cost selection of bottles.

?

Solution available at wineCover5c.dlv

G. Ianni Unit 2 � ASP Extensions

Page 59: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSemanticsExamplesThe Guess-Check-Optimize patternSocial Dinner

Social Dinner IV

Task

Let each wine bootle have a price encoded byprice(bottle,value). Modify wineCover5b.dlv and try tochoose the best cost selection of bottles.

:~ bottleChosen(X),prize(X,N). [N:1]

Solution available at wineCover5c.dlv

G. Ianni Unit 2 � ASP Extensions

Page 60: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregates

• Compute aggregate functions over a set of values, similar as inSQL (count, min, max, sum)

• A few examples:

:- actiontime(T), #count{ move(B,L,T) } >= 4.

small :- #max{ X : f(A,X,C), b(C,G) } < 3.

ok_price :- 30 <= #sum{ Price :

bought(Good),

price(Good,Price) } < 50.

• other solvers (e.g. Smodels) o�er similar constructs(cardinality atoms, weight constraints).

G. Ianni Unit 2 � ASP Extensions

Page 61: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregates

• Compute aggregate functions over a set of values, similar as inSQL (count, min, max, sum)

• A few examples:

:- actiontime(T), #count{ move(B,L,T) } >= 4.

small :- #max{ X : f(A,X,C), b(C,G) } < 3.

ok_price :- 30 <= #sum{ Price :

bought(Good),

price(Good,Price) } < 50.

• other solvers (e.g. Smodels) o�er similar constructs(cardinality atoms, weight constraints).

G. Ianni Unit 2 � ASP Extensions

Page 62: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregates

• Compute aggregate functions over a set of values, similar as inSQL (count, min, max, sum)

• A few examples:

:- actiontime(T), #count{ move(B,L,T) } >= 4.

small :- #max{ X : f(A,X,C), b(C,G) } < 3.

ok_price :- 30 <= #sum{ Price :

bought(Good),

price(Good,Price) } < 50.

• other solvers (e.g. Smodels) o�er similar constructs(cardinality atoms, weight constraints).

G. Ianni Unit 2 � ASP Extensions

Page 63: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregates

• Compute aggregate functions over a set of values, similar as inSQL (count, min, max, sum)

• A few examples:

:- actiontime(T), #count{ move(B,L,T) } >= 4.

small :- #max{ X : f(A,X,C), b(C,G) } < 3.

ok_price :- 30 <= #sum{ Price :

bought(Good),

price(Good,Price) } < 50.

• other solvers (e.g. Smodels) o�er similar constructs(cardinality atoms, weight constraints).

G. Ianni Unit 2 � ASP Extensions

Page 64: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregates

• Compute aggregate functions over a set of values, similar as inSQL (count, min, max, sum)

• A few examples:

:- actiontime(T), #count{ move(B,L,T) } >= 4.

small :- #max{ X : f(A,X,C), b(C,G) } < 3.

ok_price :- 30 <= #sum{ Price :

bought(Good),

price(Good,Price) } < 50.

• other solvers (e.g. Smodels) o�er similar constructs(cardinality atoms, weight constraints).

G. Ianni Unit 2 � ASP Extensions

Page 65: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregates

• Compute aggregate functions over a set of values, similar as inSQL (count, min, max, sum)

• A few examples:

:- actiontime(T), #count{ move(B,L,T) } >= 4.

small :- #max{ X : f(A,X,C), b(C,G) } < 3.

ok_price :- 30 <= #sum{ Price :

bought(Good),

price(Good,Price) } < 50.

• other solvers (e.g. Smodels) o�er similar constructs(cardinality atoms, weight constraints).

G. Ianni Unit 2 � ASP Extensions

Page 66: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregate Atoms � Syntax

• Symbolic Set: Expression

{Vars : Conj}of a list Vars of variables and a list Conj of literals (safetyrequired) (e.g. { X : f(A,X,C), b(C,G) }).

• Aggregate Function: Expression

f {Vars : Conj}where• f ∈ {#count,#min,#max ,#sum,#times}, and• {Vars : Conj} is a symbolic set

(e.g. #max{ X : f(A,X,C), b(C,G) } })

G. Ianni Unit 2 � ASP Extensions

Page 67: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregate Atoms � Syntax

• Symbolic Set: Expression

{Vars : Conj}of a list Vars of variables and a list Conj of literals (safetyrequired) (e.g. { X : f(A,X,C), b(C,G) }).

• Aggregate Function: Expression

f {Vars : Conj}where• f ∈ {#count,#min,#max ,#sum,#times}, and• {Vars : Conj} is a symbolic set

(e.g. #max{ X : f(A,X,C), b(C,G) } })

G. Ianni Unit 2 � ASP Extensions

Page 68: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregate Atoms � Syntax

• Symbolic Set: Expression

{Vars : Conj}of a list Vars of variables and a list Conj of literals (safetyrequired) (e.g. { X : f(A,X,C), b(C,G) }).

• Aggregate Function: Expression

f {Vars : Conj}where• f ∈ {#count,#min,#max ,#sum,#times}, and• {Vars : Conj} is a symbolic set

(e.g. #max{ X : f(A,X,C), b(C,G) } })

G. Ianni Unit 2 � ASP Extensions

Page 69: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregate Atoms � Syntax

• Symbolic Set: Expression

{Vars : Conj}of a list Vars of variables and a list Conj of literals (safetyrequired) (e.g. { X : f(A,X,C), b(C,G) }).

• Aggregate Function: Expression

f {Vars : Conj}where• f ∈ {#count,#min,#max ,#sum,#times}, and• {Vars : Conj} is a symbolic set

(e.g. #max{ X : f(A,X,C), b(C,G) } })

G. Ianni Unit 2 � ASP Extensions

Page 70: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregate Atoms � Syntax

• Symbolic Set: Expression

{Vars : Conj}of a list Vars of variables and a list Conj of literals (safetyrequired) (e.g. { X : f(A,X,C), b(C,G) }).

• Aggregate Function: Expression

f {Vars : Conj}where• f ∈ {#count,#min,#max ,#sum,#times}, and• {Vars : Conj} is a symbolic set

(e.g. #max{ X : f(A,X,C), b(C,G) } })

G. Ianni Unit 2 � ASP Extensions

Page 71: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregate Atoms � Syntax

• Symbolic Set: Expression

{Vars : Conj}of a list Vars of variables and a list Conj of literals (safetyrequired) (e.g. { X : f(A,X,C), b(C,G) }).

• Aggregate Function: Expression

f {Vars : Conj}where• f ∈ {#count,#min,#max ,#sum,#times}, and• {Vars : Conj} is a symbolic set

(e.g. #max{ X : f(A,X,C), b(C,G) } })

G. Ianni Unit 2 � ASP Extensions

Page 72: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregate Atoms � Syntax /2

• Aggregate Atom: Expression

Agg_Atom ::= val } f {Vars : Conj}| f {Vars : Conj} } val| vall }l f {Vars : Conj} }r valu

where• val , vall , valu are constants or variables,• } ∈ {<,>,≤,≥,= },• }l ,}r ∈ {<,≤}, and• f {Vars : Conj} is an aggregate function

(e.g. #max{ X : f(A,X,C), b(C,G) } < 3)

G. Ianni Unit 2 � ASP Extensions

Page 73: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregate Atoms � Syntax /2

• Aggregate Atom: Expression

Agg_Atom ::= val } f {Vars : Conj}| f {Vars : Conj} } val| vall }l f {Vars : Conj} }r valu

where• val , vall , valu are constants or variables,• } ∈ {<,>,≤,≥,= },• }l ,}r ∈ {<,≤}, and• f {Vars : Conj} is an aggregate function

(e.g. #max{ X : f(A,X,C), b(C,G) } < 3)

G. Ianni Unit 2 � ASP Extensions

Page 74: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregate Atoms � Syntax /2

• Aggregate Atom: Expression

Agg_Atom ::= val } f {Vars : Conj}| f {Vars : Conj} } val| vall }l f {Vars : Conj} }r valu

where• val , vall , valu are constants or variables,• } ∈ {<,>,≤,≥,= },• }l ,}r ∈ {<,≤}, and• f {Vars : Conj} is an aggregate function

(e.g. #max{ X : f(A,X,C), b(C,G) } < 3)

G. Ianni Unit 2 � ASP Extensions

Page 75: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregate Atoms � Syntax /2

• Aggregate Atom: Expression

Agg_Atom ::= val } f {Vars : Conj}| f {Vars : Conj} } val| vall }l f {Vars : Conj} }r valu

where• val , vall , valu are constants or variables,• } ∈ {<,>,≤,≥,= },• }l ,}r ∈ {<,≤}, and• f {Vars : Conj} is an aggregate function

(e.g. #max{ X : f(A,X,C), b(C,G) } < 3)

G. Ianni Unit 2 � ASP Extensions

Page 76: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregate Atoms � Syntax /2

• Aggregate Atom: Expression

Agg_Atom ::= val } f {Vars : Conj}| f {Vars : Conj} } val| vall }l f {Vars : Conj} }r valu

where• val , vall , valu are constants or variables,• } ∈ {<,>,≤,≥,= },• }l ,}r ∈ {<,≤}, and• f {Vars : Conj} is an aggregate function

(e.g. #max{ X : f(A,X,C), b(C,G) } < 3)

G. Ianni Unit 2 � ASP Extensions

Page 77: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregate Atoms � Syntax /2

• Aggregate Atom: Expression

Agg_Atom ::= val } f {Vars : Conj}| f {Vars : Conj} } val| vall }l f {Vars : Conj} }r valu

where• val , vall , valu are constants or variables,• } ∈ {<,>,≤,≥,= },• }l ,}r ∈ {<,≤}, and• f {Vars : Conj} is an aggregate function

(e.g. #max{ X : f(A,X,C), b(C,G) } < 3)

G. Ianni Unit 2 � ASP Extensions

Page 78: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregate Atoms � Semantics

• Informally:Suppose I is an interpretation.

• Evaluate symbolic set {Vars : Conj} with respect to I : Collectall instances of Vars for which Conj is true in I (Result:SemSet).

• Apply f on SemSet (Result: v = f (SemSet)).• Evaluate comparison val θ v resp. vall θl v ∧ v θr valu with

(instantiated) value val resp. values vall , valu.

• Appealing formal de�nition of semantics is a bit tricky

• Widely acknowledged proposal: Faber et al. [32].

G. Ianni Unit 2 � ASP Extensions

Page 79: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregate Atoms � Semantics

• Informally:Suppose I is an interpretation.

• Evaluate symbolic set {Vars : Conj} with respect to I : Collectall instances of Vars for which Conj is true in I (Result:SemSet).

• Apply f on SemSet (Result: v = f (SemSet)).• Evaluate comparison val θ v resp. vall θl v ∧ v θr valu with

(instantiated) value val resp. values vall , valu.

• Appealing formal de�nition of semantics is a bit tricky

• Widely acknowledged proposal: Faber et al. [32].

G. Ianni Unit 2 � ASP Extensions

Page 80: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregate Atoms � Semantics

• Informally:Suppose I is an interpretation.

• Evaluate symbolic set {Vars : Conj} with respect to I : Collectall instances of Vars for which Conj is true in I (Result:SemSet).

• Apply f on SemSet (Result: v = f (SemSet)).• Evaluate comparison val θ v resp. vall θl v ∧ v θr valu with

(instantiated) value val resp. values vall , valu.

• Appealing formal de�nition of semantics is a bit tricky

• Widely acknowledged proposal: Faber et al. [32].

G. Ianni Unit 2 � ASP Extensions

Page 81: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregate Atoms � Semantics

• Informally:Suppose I is an interpretation.

• Evaluate symbolic set {Vars : Conj} with respect to I : Collectall instances of Vars for which Conj is true in I (Result:SemSet).

• Apply f on SemSet (Result: v = f (SemSet)).• Evaluate comparison val θ v resp. vall θl v ∧ v θr valu with

(instantiated) value val resp. values vall , valu.

• Appealing formal de�nition of semantics is a bit tricky

• Widely acknowledged proposal: Faber et al. [32].

G. Ianni Unit 2 � ASP Extensions

Page 82: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregate Atoms � Semantics

• Informally:Suppose I is an interpretation.

• Evaluate symbolic set {Vars : Conj} with respect to I : Collectall instances of Vars for which Conj is true in I (Result:SemSet).

• Apply f on SemSet (Result: v = f (SemSet)).• Evaluate comparison val θ v resp. vall θl v ∧ v θr valu with

(instantiated) value val resp. values vall , valu.

• Appealing formal de�nition of semantics is a bit tricky

• Widely acknowledged proposal: Faber et al. [32].

G. Ianni Unit 2 � ASP Extensions

Page 83: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Aggregate Atoms � Semantics

• Informally:Suppose I is an interpretation.

• Evaluate symbolic set {Vars : Conj} with respect to I : Collectall instances of Vars for which Conj is true in I (Result:SemSet).

• Apply f on SemSet (Result: v = f (SemSet)).• Evaluate comparison val θ v resp. vall θl v ∧ v θr valu with

(instantiated) value val resp. values vall , valu.

• Appealing formal de�nition of semantics is a bit tricky

• Widely acknowledged proposal: Faber et al. [32].

G. Ianni Unit 2 � ASP Extensions

Page 84: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Social Dinner V

Task

Modify wineCover5c.dlv so that the weak constraint

:~ bottleChosen(X),prize(X,N). [N:1]

can be changed in

:~ totalcost(N). [N:1]

totalcost(N) :- #int(N),

? .

Solution at wineCover6.dlv

G. Ianni Unit 2 � ASP Extensions

Page 85: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Social Dinner V

Task

Modify wineCover5c.dlv so that the weak constraint

:~ bottleChosen(X),prize(X,N). [N:1]

can be changed in

:~ totalcost(N). [N:1]

totalcost(N) :- #int(N),

? .

Solution at wineCover6.dlv

G. Ianni Unit 2 � ASP Extensions

Page 86: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Social Dinner V

Task

Modify wineCover5c.dlv so that the weak constraint

:~ bottleChosen(X),prize(X,N). [N:1]

can be changed in

:~ totalcost(N). [N:1]

totalcost(N) :- #int(N),

? .

Solution at wineCover6.dlv

G. Ianni Unit 2 � ASP Extensions

Page 87: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Social Dinner V

Task

Modify wineCover5c.dlv so that the weak constraint

:~ bottleChosen(X),prize(X,N). [N:1]

can be changed in

:~ totalcost(N). [N:1]

totalcost(N) :- #int(N),

? .

Solution at wineCover6.dlv

G. Ianni Unit 2 � ASP Extensions

Page 88: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Social Dinner V

Task

Modify wineCover5c.dlv so that the weak constraint

:~ bottleChosen(X),prize(X,N). [N:1]

can be changed in

:~ totalcost(N). [N:1]

totalcost(N) :- #int(N),

#sum{ Y : bottleChosen(X),prize(X,Y) } = N.

Solution at wineCover6.dlv

G. Ianni Unit 2 � ASP Extensions

Page 89: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner

Social Dinner V

Task

Modify wineCover5c.dlv so that the weak constraint

:~ bottleChosen(X),prize(X,N). [N:1]

can be changed in

:~ totalcost(N). [N:1]

totalcost(N) :- #int(N),

#sum{ Y : bottleChosen(X),prize(X,Y) } = N.

Solution at wineCover6.dlv

G. Ianni Unit 2 � ASP Extensions

Page 90: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner Example

Frame logic: the idea

The molecular syntax typical of F-logic is quite useful formanipulating triple stores and complex join patterns:

Datalog Syntax

wineBottle("Brachetto"). isA("Brachetto","RedWine"),

isA("Brachetto","SweetWine"). prize("Brachetto",10).

F-Logic Syntax

"Brachetto" : wineBottle[isA-�{"RedWine","SweetWine"},

prize->10].

G. Ianni Unit 2 � ASP Extensions

Page 91: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner Example

Frame syntax: the idea

The molecular syntax typical of F-logic is quite useful formanipulating triple stores and complex join patterns:

Datalog Syntax

mainEntity(M) :- "foaf:PersonalProfileDocument"(X),

"foaf:primaryTopic"(X,M).

F-Logic Syntax

M : mainEntity :-

X:"foaf:PersonalProfileDocument"["foaf:primaryTopic"->M].

G. Ianni Unit 2 � ASP Extensions

Page 92: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner Example

Informal Syntax and Semantics

F-Logic molecule

subject : type[predicate1->object, ...,

predicate2-> >{ object1, ..., objectn },

...]

It is a syntactic shortcut to

Datalog conjunction of facts

type(subject),

predicate1(subject,object), ... , predicate2(subject,object1),

... , predicate2(subject, objectn)

• Objects can be nested frames (only atomic frames in rules' heads)• Subjects and Objects unify with terms of the language. Under higher order

extensions (see Unit 5), also Predicates and Types do.• F-Logic semantic features (inheritance, etc.) are not currently implemented, this

is only syntactic sugar.

G. Ianni Unit 2 � ASP Extensions

Page 93: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner Example

Informal Syntax and Semantics

F-Logic molecule

subject : type[predicate1->object, ...,

predicate2-> >{ object1, ..., objectn },

...]

It is a syntactic shortcut to

Datalog conjunction of facts

type(subject),

predicate1(subject,object), ... , predicate2(subject,object1),

... , predicate2(subject, objectn)

• Objects can be nested frames (only atomic frames in rules' heads)• Subjects and Objects unify with terms of the language. Under higher order

extensions (see Unit 5), also Predicates and Types do.• F-Logic semantic features (inheritance, etc.) are not currently implemented, this

is only syntactic sugar.

G. Ianni Unit 2 � ASP Extensions

Page 94: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner Example

Informal Syntax and Semantics

F-Logic molecule

subject : type[predicate1->object, ...,

predicate2-> >{ object1, ..., objectn },

...]

It is a syntactic shortcut to

Datalog conjunction of facts

type(subject),

predicate1(subject,object), ... , predicate2(subject,object1),

... , predicate2(subject, objectn)

• Objects can be nested frames (only atomic frames in rules' heads)• Subjects and Objects unify with terms of the language. Under higher order

extensions (see Unit 5), also Predicates and Types do.• F-Logic semantic features (inheritance, etc.) are not currently implemented, this

is only syntactic sugar.

G. Ianni Unit 2 � ASP Extensions

Page 95: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner Example

Informal Syntax and Semantics

F-Logic molecule

subject : type[predicate1->object, ...,

predicate2-> >{ object1, ..., objectn },

...]

It is a syntactic shortcut to

Datalog conjunction of facts

type(subject),

predicate1(subject,object), ... , predicate2(subject,object1),

... , predicate2(subject, objectn)

• Objects can be nested frames (only atomic frames in rules' heads)• Subjects and Objects unify with terms of the language. Under higher order

extensions (see Unit 5), also Predicates and Types do.• F-Logic semantic features (inheritance, etc.) are not currently implemented, this

is only syntactic sugar.

G. Ianni Unit 2 � ASP Extensions

Page 96: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner Example

Informal Syntax and Semantics

F-Logic molecule

subject : type[predicate1->object, ...,

predicate2-> >{ object1, ..., objectn },

...]

It is a syntactic shortcut to

Datalog conjunction of facts

type(subject),

predicate1(subject,object), ... , predicate2(subject,object1),

... , predicate2(subject, objectn)

• Objects can be nested frames (only atomic frames in rules' heads)• Subjects and Objects unify with terms of the language. Under higher order

extensions (see Unit 5), also Predicates and Types do.• F-Logic semantic features (inheritance, etc.) are not currently implemented, this

is only syntactic sugar.

G. Ianni Unit 2 � ASP Extensions

Page 97: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner Example

Informal Syntax and Semantics

F-Logic molecule

subject : type[predicate1->object, ...,

predicate2-> >{ object1, ..., objectn },

...]

It is a syntactic shortcut to

Datalog conjunction of facts

type(subject),

predicate1(subject,object), ... , predicate2(subject,object1),

... , predicate2(subject, objectn)

• Objects can be nested frames (only atomic frames in rules' heads)• Subjects and Objects unify with terms of the language. Under higher order

extensions (see Unit 5), also Predicates and Types do.• F-Logic semantic features (inheritance, etc.) are not currently implemented, this

is only syntactic sugar.

G. Ianni Unit 2 � ASP Extensions

Page 98: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner Example

Informal Syntax and Semantics

F-Logic molecule

subject : type[predicate1->object, ...,

predicate2-> >{ object1, ..., objectn },

...]

It is a syntactic shortcut to

Datalog conjunction of facts

type(subject),

predicate1(subject,object), ... , predicate2(subject,object1),

... , predicate2(subject, objectn)

• Objects can be nested frames (only atomic frames in rules' heads)• Subjects and Objects unify with terms of the language. Under higher order

extensions (see Unit 5), also Predicates and Types do.• F-Logic semantic features (inheritance, etc.) are not currently implemented, this

is only syntactic sugar.

G. Ianni Unit 2 � ASP Extensions

Page 99: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner Example

Informal Syntax and Semantics

F-Logic molecule

subject : type[predicate1->object, ...,

predicate2-> >{ object1, ..., objectn },

...]

It is a syntactic shortcut to

Datalog conjunction of facts

type(subject),

predicate1(subject,object), ... , predicate2(subject,object1),

... , predicate2(subject, objectn)

• Objects can be nested frames (only atomic frames in rules' heads)• Subjects and Objects unify with terms of the language. Under higher order

extensions (see Unit 5), also Predicates and Types do.• F-Logic semantic features (inheritance, etc.) are not currently implemented, this

is only syntactic sugar.

G. Ianni Unit 2 � ASP Extensions

Page 100: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner Example

Informal Syntax and Semantics

F-Logic molecule

subject : type[predicate1->object, ...,

predicate2-> >{ object1, ..., objectn },

...]

It is a syntactic shortcut to

Datalog conjunction of facts

type(subject),

predicate1(subject,object), ... , predicate2(subject,object1),

... , predicate2(subject, objectn)

• Objects can be nested frames (only atomic frames in rules' heads)• Subjects and Objects unify with terms of the language. Under higher order

extensions (see Unit 5), also Predicates and Types do.• F-Logic semantic features (inheritance, etc.) are not currently implemented, this

is only syntactic sugar.

G. Ianni Unit 2 � ASP Extensions

Page 101: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner Example

Frame Spaces

A Frame Space directive tells how frames are mapped to regularatoms

@triple.

A[brother->B] :- A[father->Y],

B[father->Y].

Maps to:

brother(A,B,triple) :-

father(A,Y,triple),

father(B,Y,triple).

@.

A[brother->B] :- A[father->Y],

B[father->Y].

Maps to:

brother(A,B) :- father(A,Y),

father(B,Y).

G. Ianni Unit 2 � ASP Extensions

Page 102: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner Example

Frame Spaces

A Frame Space directive tells how frames are mapped to regularatoms

@triple.

A[brother->B] :- A[father->Y],

B[father->Y].

Maps to:

brother(A,B,triple) :-

father(A,Y,triple),

father(B,Y,triple).

@.

A[brother->B] :- A[father->Y],

B[father->Y].

Maps to:

brother(A,B) :- father(A,Y),

father(B,Y).

G. Ianni Unit 2 � ASP Extensions

Page 103: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner Example

Frame Spaces

A Frame Space directive tells how frames are mapped to regularatoms

@triple.

A[brother->B] :- A[father->Y],

B[father->Y].

Maps to:

brother(A,B,triple) :-

father(A,Y,triple),

father(B,Y,triple).

@.

A[brother->B] :- A[father->Y],

B[father->Y].

Maps to:

brother(A,B) :- father(A,Y),

father(B,Y).

G. Ianni Unit 2 � ASP Extensions

Page 104: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner Example

Social Dinner VII

Task

Take wineCover7a.dlt. It is partially in frame syntax. Put thefollowing rule in frame logic syntax:

compliantBottle(X,Z) :- preferredWine(X,Y), isA(Z,Y).

Solution at wineCover7b.dlt

G. Ianni Unit 2 � ASP Extensions

Page 105: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner Example

Social Dinner VII

Task

Take wineCover7a.dlt. It is partially in frame syntax. Put thefollowing rule in frame logic syntax:

X[compliantBottle->Z] :- X[preferredWine->Y], Z[isA->Y].

Solution at wineCover7b.dlt

G. Ianni Unit 2 � ASP Extensions

Page 106: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsSocial Dinner Example

Social Dinner VII

Task

Take wineCover7a.dlt. It is partially in frame syntax. Put thefollowing rule in frame logic syntax:

X[compliantBottle->Z] :- X[preferredWine->Y], Z[isA->Y].

Solution at wineCover7b.dlt

G. Ianni Unit 2 � ASP Extensions

Page 107: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

The idea of templates

Imagine you want to encode all the possible permutations of agiven predicate p (assume maxint = |X : p(X )|)

First, I guess worlds of permutations

permutation(X,N) v -permutation(X,N) :- p(X),#int(N).

Then, I cut worlds I don't like

:- permutation(X,A),permutation(Z,A), Z <> X.

:- permutation(X,A),permutation(X,B), A <> B.

Also, each element must be in the partition

covered(X) :- permutation(X,A).

:- p(X), not covered(X).

G. Ianni Unit 2 � ASP Extensions

Page 108: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

The idea of templates

Imagine you want to encode all the possible permutations of agiven predicate p (assume maxint = |X : p(X )|)

First, I guess worlds of permutations

permutation(X,N) v -permutation(X,N) :- p(X),#int(N).

Then, I cut worlds I don't like

:- permutation(X,A),permutation(Z,A), Z <> X.

:- permutation(X,A),permutation(X,B), A <> B.

Also, each element must be in the partition

covered(X) :- permutation(X,A).

:- p(X), not covered(X).

G. Ianni Unit 2 � ASP Extensions

Page 109: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

The idea of templates

Imagine you want to encode all the possible permutations of agiven predicate p (assume maxint = |X : p(X )|)

First, I guess worlds of permutations

permutation(X,N) v -permutation(X,N) :- p(X),#int(N).

Then, I cut worlds I don't like

:- permutation(X,A),permutation(Z,A), Z <> X.

:- permutation(X,A),permutation(X,B), A <> B.

Also, each element must be in the partition

covered(X) :- permutation(X,A).

:- p(X), not covered(X).

G. Ianni Unit 2 � ASP Extensions

Page 110: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

The idea of templates

Imagine you want to encode all the possible permutations of agiven predicate p (assume maxint = |X : p(X )|)

First, I guess worlds of permutations

permutation(X,N) v -permutation(X,N) :- p(X),#int(N).

Then, I cut worlds I don't like

:- permutation(X,A),permutation(Z,A), Z <> X.

:- permutation(X,A),permutation(X,B), A <> B.

Also, each element must be in the partition

covered(X) :- permutation(X,A).

:- p(X), not covered(X).

G. Ianni Unit 2 � ASP Extensions

Page 111: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

The idea of templates - 2

• Thus, this �small� program encodes a search space ofpermutations

• But it can be reused and put in a library (let maxint bigenough here)

#template permutation{p(1)}(2)

{

permutation(X,N) v -permutation(X,N)

:- p(X),#int(N),

#count{ Y : p(Y) } = N1,

N <= N1, N > 0.

:- permutation(X,A),permutation(Z,A), Z <> X.

:- permutation(X,A),permutation(X,B), A <> B.

covered(X) :- permutation(X,A).

:- p(X), not covered(X).

}

G. Ianni Unit 2 � ASP Extensions

Page 112: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

The idea of templates - 2

• Thus, this �small� program encodes a search space ofpermutations

• But it can be reused and put in a library (let maxint bigenough here)

#template permutation{p(1)}(2)

{

permutation(X,N) v -permutation(X,N)

:- p(X),#int(N),

#count{ Y : p(Y) } = N1,

N <= N1, N > 0.

:- permutation(X,A),permutation(Z,A), Z <> X.

:- permutation(X,A),permutation(X,B), A <> B.

covered(X) :- permutation(X,A).

:- p(X), not covered(X).

}

G. Ianni Unit 2 � ASP Extensions

Page 113: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

Syntax and Semantics

Template de�nition:

#template closure{e(2)}(2)

{

closure(X,Y) :- e(X,Y).

closure(X,Y) :- e(X,Z),

closure(Z,Y).

}

#template max{p(1)}(1)

{

exceeded(X) :- p(X),p(Y), Y > X.

max(X) :- p(X),

not exceeded(X).

}

• e(2), p(1) = formal parameter list

• ..}(2), ..}(1) = output predicate arities

• closure, max = output predicate names

• exceeded = local predicate name

G. Ianni Unit 2 � ASP Extensions

Page 114: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

Syntax and Semantics

Template de�nition:

#template closure{e(2)}(2)

{

closure(X,Y) :- e(X,Y).

closure(X,Y) :- e(X,Z),

closure(Z,Y).

}

#template max{p(1)}(1)

{

exceeded(X) :- p(X),p(Y), Y > X.

max(X) :- p(X),

not exceeded(X).

}

• e(2), p(1) = formal parameter list

• ..}(2), ..}(1) = output predicate arities

• closure, max = output predicate names

• exceeded = local predicate name

G. Ianni Unit 2 � ASP Extensions

Page 115: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

Syntax and Semantics

Template de�nition:

#template closure{e(2)}(2)

{

closure(X,Y) :- e(X,Y).

closure(X,Y) :- e(X,Z),

closure(Z,Y).

}

#template max{p(1)}(1)

{

exceeded(X) :- p(X),p(Y), Y > X.

max(X) :- p(X),

not exceeded(X).

}

• e(2), p(1) = formal parameter list

• ..}(2), ..}(1) = output predicate arities

• closure, max = output predicate names

• exceeded = local predicate name

G. Ianni Unit 2 � ASP Extensions

Page 116: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

Syntax and Semantics

Template de�nition:

#template closure{e(2)}(2)

{

closure(X,Y) :- e(X,Y).

closure(X,Y) :- e(X,Z),

closure(Z,Y).

}

#template max{p(1)}(1)

{

exceeded(X) :- p(X),p(Y), Y > X.

max(X) :- p(X),

not exceeded(X).

}

• e(2), p(1) = formal parameter list

• ..}(2), ..}(1) = output predicate arities

• closure, max = output predicate names

• exceeded = local predicate name

G. Ianni Unit 2 � ASP Extensions

Page 117: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

Syntax and Semantics

Template de�nition:

#template closure{e(2)}(2)

{

closure(X,Y) :- e(X,Y).

closure(X,Y) :- e(X,Z),

closure(Z,Y).

}

#template max{p(1)}(1)

{

exceeded(X) :- p(X),p(Y), Y > X.

max(X) :- p(X),

not exceeded(X).

}

• e(2), p(1) = formal parameter list

• ..}(2), ..}(1) = output predicate arities

• closure, max = output predicate names

• exceeded = local predicate name

G. Ianni Unit 2 � ASP Extensions

Page 118: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

Syntax and Semantics

Template de�nition:

#template closure{e(2)}(2)

{

closure(X,Y) :- e(X,Y).

closure(X,Y) :- e(X,Z),

closure(Z,Y).

}

#template max{p(1)}(1)

{

exceeded(X) :- p(X),p(Y), Y > X.

max(X) :- p(X),

not exceeded(X).

}

• e(2), p(1) = formal parameter list

• ..}(2), ..}(1) = output predicate arities

• closure, max = output predicate names

• exceeded = local predicate name

G. Ianni Unit 2 � ASP Extensions

Page 119: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

Syntax and Semantics - 2

Template atoms:

clo(X,Y) :- closure{ edge(*,*) }(X,Y).

inPath(X,N) :- permutation{ clo(*,$) }(X,N).

maxAgePerSex(S,A) :- max{ person($,S,*) }(A).

• edge(*,*), clo(*,$), person($,S,*) = actualparameters

• closure{ edge(*,*) }(X,Y) = a template atom

• * = input terms

• $ = projection terms

• S = group-by (quanti�cation) term

• (X,Y), (X,N), S..A = output terms

G. Ianni Unit 2 � ASP Extensions

Page 120: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

Syntax and Semantics - 2

Template atoms:

clo(X,Y) :- closure{ edge(*,*) }(X,Y).

inPath(X,N) :- permutation{ clo(*,$) }(X,N).

maxAgePerSex(S,A) :- max{ person($,S,*) }(A).

• edge(*,*), clo(*,$), person($,S,*) = actualparameters

• closure{ edge(*,*) }(X,Y) = a template atom

• * = input terms

• $ = projection terms

• S = group-by (quanti�cation) term

• (X,Y), (X,N), S..A = output terms

G. Ianni Unit 2 � ASP Extensions

Page 121: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

Syntax and Semantics - 2

Template atoms:

clo(X,Y) :- closure{ edge(*,*) }(X,Y).

inPath(X,N) :- permutation{ clo(*,$) }(X,N).

maxAgePerSex(S,A) :- max{ person($,S,*) }(A).

• edge(*,*), clo(*,$), person($,S,*) = actualparameters

• closure{ edge(*,*) }(X,Y) = a template atom

• * = input terms

• $ = projection terms

• S = group-by (quanti�cation) term

• (X,Y), (X,N), S..A = output terms

G. Ianni Unit 2 � ASP Extensions

Page 122: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

Syntax and Semantics - 2

Template atoms:

clo(X,Y) :- closure{ edge(*,*) }(X,Y).

inPath(X,N) :- permutation{ clo(*,$) }(X,N).

maxAgePerSex(S,A) :- max{ person($,S,*) }(A).

• edge(*,*), clo(*,$), person($,S,*) = actualparameters

• closure{ edge(*,*) }(X,Y) = a template atom

• * = input terms

• $ = projection terms

• S = group-by (quanti�cation) term

• (X,Y), (X,N), S..A = output terms

G. Ianni Unit 2 � ASP Extensions

Page 123: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

Syntax and Semantics - 2

Template atoms:

clo(X,Y) :- closure{ edge(*,*) }(X,Y).

inPath(X,N) :- permutation{ clo(*,$) }(X,N).

maxAgePerSex(S,A) :- max{ person($,S,*) }(A).

• edge(*,*), clo(*,$), person($,S,*) = actualparameters

• closure{ edge(*,*) }(X,Y) = a template atom

• * = input terms

• $ = projection terms

• S = group-by (quanti�cation) term

• (X,Y), (X,N), S..A = output terms

G. Ianni Unit 2 � ASP Extensions

Page 124: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

Syntax and Semantics - 2

Template atoms:

clo(X,Y) :- closure{ edge(*,*) }(X,Y).

inPath(X,N) :- permutation{ clo(*,$) }(X,N).

maxAgePerSex(S,A) :- max{ person($,S,*) }(A).

• edge(*,*), clo(*,$), person($,S,*) = actualparameters

• closure{ edge(*,*) }(X,Y) = a template atom

• * = input terms

• $ = projection terms

• S = group-by (quanti�cation) term

• (X,Y), (X,N), S..A = output terms

G. Ianni Unit 2 � ASP Extensions

Page 125: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

Syntax and Semantics - 2

Template atoms:

clo(X,Y) :- closure{ edge(*,*) }(X,Y).

inPath(X,N) :- permutation{ clo(*,$) }(X,N).

maxAgePerSex(S,A) :- max{ person($,S,*) }(A).

• edge(*,*), clo(*,$), person($,S,*) = actualparameters

• closure{ edge(*,*) }(X,Y) = a template atom

• * = input terms

• $ = projection terms

• S = group-by (quanti�cation) term

• (X,Y), (X,N), S..A = output terms

G. Ianni Unit 2 � ASP Extensions

Page 126: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

Syntax and Semantics - 2

Template atoms:

clo(X,Y) :- closure{ edge(*,*) }(X,Y).

inPath(X,N) :- permutation{ clo(*,$) }(X,N).

maxAgePerSex(S,A) :- max{ person($,S,*) }(A).

• edge(*,*), clo(*,$), person($,S,*) = actualparameters

• closure{ edge(*,*) }(X,Y) = a template atom

• * = input terms

• $ = projection terms

• S = group-by (quanti�cation) term

• (X,Y), (X,N), S..A = output terms

G. Ianni Unit 2 � ASP Extensions

Page 127: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

The Hamiltonian Path problem

HP: �nd a path between nodes of a graph s.t. I cross each nodeexactly once. (permutation.dlt)

If I want to encode the HP problem with templates, I can do thisway:

path(X,N) :- permutation{node(*)}(X,N).

:- path(X,M), path(Y,N), not edge(X,Y), M = N+1.

Also, I can use permutation taking input predicates other thanunary:

path(X,N) :- permutation{edge(*,$)}(X,N).

• * = parameter

• $ = projection

G. Ianni Unit 2 � ASP Extensions

Page 128: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

The Hamiltonian Path problem

HP: �nd a path between nodes of a graph s.t. I cross each nodeexactly once. (permutation.dlt)

If I want to encode the HP problem with templates, I can do thisway:

path(X,N) :- permutation{node(*)}(X,N).

:- path(X,M), path(Y,N), not edge(X,Y), M = N+1.

Also, I can use permutation taking input predicates other thanunary:

path(X,N) :- permutation{edge(*,$)}(X,N).

• * = parameter

• $ = projection

G. Ianni Unit 2 � ASP Extensions

Page 129: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

The Hamiltonian Path problem

HP: �nd a path between nodes of a graph s.t. I cross each nodeexactly once. (permutation.dlt)

If I want to encode the HP problem with templates, I can do thisway:

path(X,N) :- permutation{node(*)}(X,N).

:- path(X,M), path(Y,N), not edge(X,Y), M = N+1.

Also, I can use permutation taking input predicates other thanunary:

path(X,N) :- permutation{edge(*,$)}(X,N).

• * = parameter

• $ = projection

G. Ianni Unit 2 � ASP Extensions

Page 130: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

The Hamiltonian Path problem

HP: �nd a path between nodes of a graph s.t. I cross each nodeexactly once. (permutation.dlt)

If I want to encode the HP problem with templates, I can do thisway:

path(X,N) :- permutation{node(*)}(X,N).

:- path(X,M), path(Y,N), not edge(X,Y), M = N+1.

Also, I can use permutation taking input predicates other thanunary:

path(X,N) :- permutation{edge(*,$)}(X,N).

• * = parameter

• $ = projection

G. Ianni Unit 2 � ASP Extensions

Page 131: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

The Hamiltonian Path problem

HP: �nd a path between nodes of a graph s.t. I cross each nodeexactly once. (permutation.dlt)

If I want to encode the HP problem with templates, I can do thisway:

path(X,N) :- permutation{node(*)}(X,N).

:- path(X,M), path(Y,N), not edge(X,Y), M = N+1.

Also, I can use permutation taking input predicates other thanunary:

path(X,N) :- permutation{edge(*,$)}(X,N).

• * = parameter

• $ = projection

G. Ianni Unit 2 � ASP Extensions

Page 132: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

The Hamiltonian Path problem

HP: �nd a path between nodes of a graph s.t. I cross each nodeexactly once. (permutation.dlt)

If I want to encode the HP problem with templates, I can do thisway:

path(X,N) :- permutation{node(*)}(X,N).

:- path(X,M), path(Y,N), not edge(X,Y), M = N+1.

Also, I can use permutation taking input predicates other thanunary:

path(X,N) :- permutation{edge(*,$)}(X,N).

• * = parameter

• $ = projection

G. Ianni Unit 2 � ASP Extensions

Page 133: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

Social Dinner VIII

Task

Try to expand wineCover7.dlt: de�ne a template subset forspecifying the search space of minimum cardinality subsets of wines.

#template subset{ p(1) }(1)

{

?

?

}

bottleChosen(X) :- ?

Solution at wineCover8.dlt

G. Ianni Unit 2 � ASP Extensions

Page 134: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

Social Dinner VIII

Task

Try to expand wineCover7.dlt: de�ne a template subset forspecifying the search space of minimum cardinality subsets of wines.

#template subset{ p(1) }(1)

{

?

?

}

bottleChosen(X) :- ?

Solution at wineCover8.dlt

G. Ianni Unit 2 � ASP Extensions

Page 135: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

Social Dinner VIII

Task

Try to expand wineCover7.dlt: de�ne a template subset forspecifying the search space of minimum cardinality subsets of wines.

#template subset{ p(1) }(1)

{

subset(X) v nonsubset(X) :- p(X).

:~ subset(X). [1:1]

}

bottleChosen(X) :- subset{compliantBottle($,*)}(X).

Solution at wineCover8.dlt

G. Ianni Unit 2 � ASP Extensions

Page 136: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

IdeaSyntax and SemanticsExamplesSocial Dinner Example

Social Dinner VIII

Task

Try to expand wineCover7.dlt: de�ne a template subset forspecifying the search space of minimum cardinality subsets of wines.

#template subset{ p(1) }(1)

{

subset(X) v nonsubset(X) :- p(X).

:~ subset(X). [1:1]

}

bottleChosen(X) :- subset{compliantBottle($,*)}(X).

Solution at wineCover8.dlt

G. Ianni Unit 2 � ASP Extensions

Page 137: Unit 2 -- ASP Extensions › asptut › slides › unit2.pdf · 2008-01-30 · Intro Weak constraints Aggregates Frame Syntax emplatesT References Unit 2 ASP Extensions G. Ianni Dipartimento

IntroWeak constraints

AggregatesFrame Syntax

TemplatesReferences

References

1 Weak Constraints: [11]2 Aggregates: [32]3 Templates: [13]4 Frame Logic: [48]5 Other extensions:http://www.tcs.hut.fi/Research/Logic/wasp/wp3/

[1] G. Alsaç and C. Baral.Reasoning in description logics using declarative logicprogramming.Technical Report ASU 2001-02, Arizona State University,2002.

[2] J. Angele, H. Boley, J. de Bruijn, D. Fensel, P. Hitzler,M. Kifer, R. Krummenacher, H. Lausen, A. Polleres, andR. Studer.Web rule language (WRL), Sept. 2005.W3C Member Submission,http://www.w3.org/Submission/WRL/.

[3] Christian Anger, Kathrin Konczak, and Thomas Linke.NoMoRe: A System for Non-Monotonic Reasoning.In LPNMR'01, pp. 406�410. 2001.

[4] Chandrabose Aravindan, J. Dix, and I. Niemelä.DisLoP: A Research Project on Disjunctive LogicProgramming.AI Communications, 10(3/4):151�165, 1997.

[5] C. Bell, A. Nerode, R.T. Ng, and V.S. Subrahmanian.Mixed Integer Programming Methods for ComputingNonmonotonic Deductive Databases.JACM, 41:1178�1215, 1994.

[6] T. Berners-Lee.Web for real people, April 2005.Keynote Speech at the 14th World Wide Web Conference(WWW2005), slides available athttp://www.w3.org/2005/Talks/0511-keynote-tbl/.

[7] P. A. Bonatti.Reasoning with In�nite Stable Models.In Proceedings of the Seventeenth International JointConference on Arti�cial Intelligence (IJCAI) 2001, pages603�610, Seattle, WA, USA, Aug. 2001. Morgan KaufmannPublishers.

[8] M. Brain and M. D. Vos.Debugging logic programs under the answer set semantics.In Answer Set Programming, 2005.

[9] F. Buccafurri, N. Leone, and P. Rullo.Enhancing Disjunctive Datalog by Constraints.IEEE TKDE, 12(5):845�860, 2000.

[10] J. D. Bruijn, A. Polleres, R. Lara, and D. Fensel.OWL DL vs. OWL Flight: Conceptual modeling and reasoningfor the semantic web.In Proceedings of the 14th World Wide Web Conference(WWW2005), Chiba, Japan, May 2005.

[11] F. Buccafurri, N. Leone, and P. Rullo.Strong and Weak Constraints in Disjunctive Datalog.In J. Dix, U. Furbach, and A. Nerode, editors, Proceedings ofthe 4th International Conference on Logic Programming andNon-Monotonic Reasoning (LPNMR'97), number 1265 inLNAI, pages 2�17, Dagstuhl, Germany, July 1997. Springer.

[12] P. Burek and R. Grabos.Dually structured concepts in the semantic web: Answer setprogramming approach.In Proceedings of the Second European Semantic WebConference, ESWC 2005, Heraklion, Crete, Greece, May 29 -June 1, 2005, LNCS 3532, pages 377�391, 2005.

[13] F. Calimeri, G. Ianni, G. Ielpa, A. Pietramala, and M. C.Santoro.A system with template answer set programs.In JELIA, pages 693�697, 2004.

[14] F. Calimeri and G. Ianni.External sources of computation for Answer Set Solvers.In C. Baral, G. Greco, N. Leone, and G. Terracina, editors,Logic Programming and Nonmonotonic Reasoning � 8thInternational Conference, LPNMR'05, Diamante, Italy,September 2005, Proceedings, volume 3662 of LNCS, pages105�118. Springer, Sept. 2005.

[15] Weidong Chen and David Scott Warren.Computation of Stable Models and Its Integration with LogicalQuery Processing.IEEE TKDE, 8(5):742�757, 1996.

[16] Paweª Cholewi«ski, V. Wiktor Marek, and M. Truszczy«ski.Default Reasoning System DeReS.In Proceedings of International Conference on Principles ofKnowledge Representation and Reasoning (KR '96), pp.518�528, Cambridge, Massachusetts, USA, 1996.

[17] Paweª Cholewi«ski, V.W. Marek, Artur Mikitiuk, andM. Truszczy«ski.Computing with Default Logic.Arti�cial Intelligence, 112(2�3):105�147, 1999.

[18] C. Cumbo, W. Faber, and G. Greco.Enhancing the magic-set method for disjunctive datalogprograms.In Proceedings of the the 20th International Conference onLogic Programming � ICLP'04, volume 3132 of LNCS, pages371�385, 2004.

[19] S. Decker, M. Sintek, and W. Nejdl.The model-theoretic semantics of TRIPLE, Nov. 2002.

[20] F. M. Donini, M. Lenzerini, D. Nardi, and A. Schaerf.AL-log: Integrating datalog and description logics.Journal of Intelligent Information Systems (JIIS),10(3):227�252, 1998.

[21] D. East and M. Truszczy«ski.Propositional Satis�ability in Answer-set Programming.In Proceedings of Joint German/Austrian Conference onArti�cial Intelligence, KI'2001, pp. 138�153. LNAI 2174, 2001.

[22] D. East and M. Truszczy«ski.dcs: An Implementation of DATALOG with Constraints.In NMR'2000, 2000.

[23] U. Egly, T. Eiter, H. Tompits, and S. Woltran.Solving Advanced Reasoning Tasks using Quanti�ed BooleanFormulas.In AAAI'00, pp. 417�422. AAAI Press / MIT Press, 2000.

[24] T. Eiter, W. Faber, N. Leone, G. Pfeifer, and A. Polleres.A Logic Programming Approach to Knowledge-State Planning,II: the DLVK System.Arti�cial Intelligence, 144(1�2):157�211, 2003.

[25] T. Eiter, M. Fink, H. Tompits, and S. Woltran.Strong and uniform equivalence in answer-set programming:Characterizations and complexity results for the non-groundcase.In AAAI, pages 695�700, 2005.

[26] T. Eiter, G. Ianni, R. Schindlauer, and H. Tompits.A Uniform Integration of Higher-Order Reasoning and ExternalEvaluations in Answer Set Programming.In International Joint Conference on Arti�cial Intelligence(IJCAI) 2005, pages 90�96, Edinburgh, UK, Aug. 2005.

[27] T. Eiter, T. Lukasiewicz, R. Schindlauer, and H. Tompits.Combining Answer Set Programming with Description Logicsfor the Semantic Web.In Principles of Knowledge Representation and Reasoning:Proceedings of the Ninth International Conference (KR2004),Whistler, Canada, pages 141�151, 2004.Extended Report RR-1843-03-13, Institut fürInformationssysteme, TU Wien, 2003.

[28] Eiter, T.; Ianni, G.; Schindlauer, R.; and Tompits, H.2006.E�ective Integration of Declarative Rules with externalEvaluations for Semantic Web Reasoning.In European Semantic Web Conference 2006, Proceedings.To appear.

[29] Thomas Eiter, Giovambattista Ianni, Roman Schindlauer, andHans Tompits.Towards e�cient evaluation of HEX programs.In Proceedings 11th International Workshop on NonmonotonicReasoning (NMR-2006), Answer Set Programming Track,June 2006.To appear.

[30] O. El-Khatib, E. Pontelli, and T. C. Son.Justi�cation and debugging of answer set programs in asp.In AADEBUG, pages 49�58, 2005.

[31] W. Faber, N. Leone, and G. Pfeifer.A Comparison of Heuristics for Answer Set Programming.In Proceedings of the 5th Dutch-German Workshop onNonmonotonic Reasoning Techniques and their Applications(DGNMR 2001), pages 64�75, Apr. 2001.

[32] W. Faber, N. Leone, and G. Pfeifer.Recursive aggregates in disjunctive logic programs: Semanticsand complexity.In J. J. Alferes and J. Leite, editors, Proceedings of the 9thEuropean Conference on Arti�cial Intelligence (JELIA 2004),number 3229 in LNAI, pages 200�212. Springer, Sept. 2004.

[33] W. Faber, N. Leone, and F. Ricca.Heuristics for Hard ASP Programs.In Nineteenth International Joint Conference on Arti�cialIntelligence (IJCAI-05), pages 1562�1563, Aug. 2005.

[34] P. Ferraris and V. Lifschitz.Weight constraints as nested expressions.TPLP, 5(1�2):45�74, 2005.

[35] W. Faber and G. Pfeifer.DLV homepage, since 1996.http://www.dlvsystem.com/.

[36] M. Gelfond and V. Lifschitz.Classical Negation in Logic Programs and DisjunctiveDatabases.NGC, 9:365�385, 1991.

[37] E. Giunchiglia and M. Maratea.On the relation between answer set and sat procedures (or,between cmodels and smodels).In ICLP, pages 37�51, 2005.

[38] J. Gressmann, T. Janhunen, R. E. Mercer, T. Schaub,S. Thiele, and R. Tichy.Platypus: A platform for distributed answer set solving.In LPNMR, pages 227�239, 2005.

[39] B. N. Grosof, I. Horrocks, R. Volz, and S. Decker.Description logic programs: Combining logic programs withdescription logics.In Proceedings of the Twelfth International World Wide WebConference, WWW2003, Budapest, Hungary, pages 48�57,2003.

[40] S. Heymans.Decidable Open Answer Set Programming.PhD thesis, Theoretical Computer Science Lab (TINF),Department of Computer Science, Vrije Universiteit Brussel,Feb. 2006.

[41] S. Heymans, D. V. Nieuwenborgh, and D. Vermeir.Semantic web reasoning with conceptual logic programs.In Rules and Rule Markup Languages for the Semantic Web:Third International Workshop (RuleML 2004), pages 113�127,Hiroshima, Japan, Nov. 2004.

[42] S. Heymans, D. V. Nieuwenborgh, and D. Vermeir.Nonmonotonic ontological and rule-based reasoning withextended conceptual logic programs.In Proceedings of the Second European Semantic WebConference, ESWC 2005. LNCS 3532, pages 392�407, 2005.

[43] I. Horrocks, B. Parsia, P. Patel-Schneider, and J. Hendler.Semantic web architecture: Stack or two towers?In F. Fages and S. Soliman, editors, Principles and Practice ofSemantic Web Reasoning (PPSWR 2005), number 3703 inLNCS, pages 37�41. SV, 2005.

[44] I. Horrocks, P. F. Patel-Schneider, H. Boley, S. Tabet,B. Grosof, and M. Dean.Swrl: A semantic web rule language combining owl and ruleml,May 2004.W3C Member Submission.http://www.w3.org/Submission/SWRL/.

[45] U. Hustadt, B. Motik, and U. Sattler.Reducing shiq-description logic to disjunctive datalogprograms.In Principles of Knowledge Representation and Reasoning:Proceedings of the Ninth International Conference (KR2004),Whistler, Canada, pages 152�162, 2004.

[46] ICONS homepage, since 2001.http://www.icons.rodan.pl/.

[47] T. Janhunen, I. Niemelä, D. Seipel, P. Simons, and J.-H. You.Unfolding Partiality and Disjunctions in Stable ModelSemantics.ACM TOCL, 2005.To appear.

[48] M. Kifer, G. Lausen, and J. Wu.Logical foundations of object-oriented and frame-basedlanguages.Journal of the ACM, 42(4):741�843, 1995.

[49] N. Leone, G. Gottlob, R. Rosati, T. Eiter, W. Faber, MichaelFink, Gianluigi Greco, G. Ianni, Edyta Kaªka, DomenicoLembo, Maurizio Lenzerini, Vincenzino Lio, Bartosz Nowicki,Marco Ruzzi, Witold Staniszkis, and Giorgio Terracina.The INFOMIX System for Advanced Integration of Incompleteand Inconsistent Data.In Proceedings of the 24th ACM SIGMOD InternationalConference on Management of Data (SIGMOD 2005), pp.915�917, Baltimore, Maryland, USA, 2005. ACM Press.

[50] N. Leone, G. Pfeifer, W. Faber, T. Eiter, G. Gottlob, S. Perri,and F. Scarcello.The DLV System for Knowledge Representation andReasoning.ACM TOCL, 2005.To appear.

[51] N. Leone, S. Perri, and F. Scarcello.Backjumping techniques for rules instantiation in the dlvsystem.In NMR, pages 258�266, 2004.

[52] A. Y. Levy and M.-C. Rousset.Combining horn rules and description logics in CARIN.Arti�cial Intelligence, 104:165 � 209, 1998.

[53] Yuliya Lierler.Disjunctive Answer Set Programming via Satis�ability.In Logic Programming and Nonmonotonic Reasoning � 8thInternational Conference, LPNMR'05, Diamante, Italy, 2005,Proceedings, LNCS 3662

[54] F. Lin and Y. Zhao.ASSAT: computing answer sets of a logic program by SATsolvers.Arti�cial Intelligence, 157(1-2):115�137, 2004.

[55] V. Marek, I. Niemelä, and M. Truszczy±ki.Logic programs with monotone cardinality atoms.In Proceedings LPNMR-2004, volume 2923 of LNCS, pages154�166, 2004.

[56] V.W. Marek and J.B. Remmel.On Logic Programs with Cardinality Constraints.In NMR'2002, pp. 219�228, 2002.

[57] N. McCain and H. Turner.Satis�ability Planning with Causal Theories.In KR'98, pp. 212�223. 1998.

[58] J. Mei, S. Liu, A. Yue, and Z. Lin.An extension to OWL with general rules.In Rules and Rule Markup Languages for the Semantic Web:Third International Workshop (RuleML 2004), pages 155�169,Hiroshima, Japan, Nov. 2004.

[59] B. Motik, U. Sattler, and R. Studer.Query answering for owl-dl with rules.Journal of Web Semantics: Science, Services and Agents onthe World Wide Web, 3(1):41�60, JUL 2005.

[60] B. Motik and R. Volz.Optimizing query answering in description logics usingdisjunctive deductive databases.In F. Bry, C. Lutz, U. Sattler, and M. Schoop, editors,Proceedings of the 10th International Workshop on KnowledgeRepresentation meets Databases (KRDB 2003), volume 79 ofCEUR Workshop Proceedings. CEUR-WS.org, Sept. 2003.

[61] I. Niemelä.The implementation of answer set solvers, 2004.Tutorial at ICLP 2004. Available at http://www.tcs.hut.fi/~init/papers/niemela-iclp04-tutorial.ps.gz/.

[62] I. Niemelä, P. Simons, and T. Soininen.Stable Model Semantics of Weight Constraint Rules.In LPNMR'99, pp. 107�116.

[63] N. Pelov.Non-monotone Semantics for Logic Programs withAggregates.Available at http://www.cs.kuleuven.ac.be/~pelov/papers/nma.ps.gz.,Oct. 2002.

[64] A. Rainer.Web Service Composition under Answer Set Programming.In KI-Workshop "Planen, Scheduling und Kon�gurieren,Entwerfenl" (PuK), 2005.

[65] R. Rosati.On the decidability and complexity of integrating ontologiesand rules.Journal of Web Semantics, 3(1):61�73, 2005.

[66] R. Rosati.DL+log : Tight integration of description logics anddisjunctive datalog.In KR2006, 2006.To appear.

[67] D. Seipel and Helmut Thöne.DisLog � A System for Reasoning in Disjunctive DeductiveDatabases.In Proceedings International Workshop on the DeductiveApproach to Information Systems and Databases (DAISD'94),pp. 325�343. Universitat Politecnica de Catalunya (UPC),1994.

[68] P. Simons.Smodels Homepage, since 1996.http://www.tcs.hut.fi/Software/smodels/.

[69] V.S. Subrahmanian, D. Nau, and C. Vago.WFS + Branch and Bound = Stable Models.IEEE TKDE, 7(3):362�377, 1995.

[70] T. Swift.Deduction in Ontologies via ASP.In V. Lifschitz and I. Niemelä, editors, Proc. of the SeventhInt.l Conf. on Logic Programming and NonmonotonicReasoning (LPNMR-7), LNCS, pages 275�288, FortLauderdale, Florida, USA, Jan. 2004. Springer.

[71] T. Syrjänen.Omega-restricted logic programs.In Proceedings of the 6th International Conference on LogicProgramming and Nonmonotonic Reasoning, Vienna, Austria,September 2001. Springer.

[72] WASP report (IST-2001-37004). Model applications andproofs-of-concept.http:

//www.kr.tuwien.ac.at/projects/WASP/report.html.

[73] WASP showcase.http:

//www.kr.tuwien.ac.at/projects/WASP/showcase.html.

[74] G. Yang and M. Kifer.On the semantics of anonymous identity and rei�cation.In CoopIS/DOA/ODBASE, pages 1047�1066, 2002.

[75] G. Yang, M. Kifer, and C. Zhao."�ora-2: A rule-based knowledge representation and inferenceinfrastructure for the semantic web.".In R. Meersman, Z. Tari, and D. C. Schmidt, editors,CoopIS/DOA/ODBASE, pages 671�688, 2003.

G. Ianni Unit 2 � ASP Extensions