Answer Set Programming Book
Answer Set Programming Book
Torsten Schaub
University of Potsdam
FMCAD@Cambridge
1 Motivation
2 Introduction
3 Modeling
4 Systems
5 Conclusion
1 Motivation
2 Nutshell
3 Shifting paradigms
4 Rooting ASP
5 ASP solving
6 Using ASP
Outline
1 Motivation
2 Nutshell
3 Shifting paradigms
4 Rooting ASP
5 ASP solving
6 Using ASP
Informatics
Problem Solution
6
?
Computer - Output
Informatics
Problem Solution
6
?
Computer - Output
Traditional programming
Problem Solution
6
?
Computer - Output
Traditional programming
Problem Solution
6
Programming Interpreting
?
Program - Output
Executing
Problem Solution
6
Interpreting
?
Computer - Output
Problem Solution
6
Modeling Interpreting
?
Representation - Output
Solving
Problem Solution
6
Modeling Interpreting
?
Representation - Output
Solving
Outline
1 Motivation
2 Nutshell
3 Shifting paradigms
4 Rooting ASP
5 ASP solving
6 Using ASP
ASP = DB+LP+KR+SAT
Outline
1 Motivation
2 Nutshell
3 Shifting paradigms
4 Rooting ASP
5 ASP solving
6 Using ASP
above(X,Y) :- on(X,Y).
above(X,Y) :- on(X,Z), above(Z,Y).
Prolog queries
?- above(a,c).
true.
?- above(c,a).
no.
above(X,Y) :- on(X,Y).
above(X,Y) :- on(X,Z), above(Z,Y).
Prolog queries
?- above(a,c).
true.
?- above(c,a).
no.
above(X,Y) :- on(X,Y).
above(X,Y) :- on(X,Z), above(Z,Y).
Prolog queries
?- above(a,c).
true.
?- above(c,a).
no.
above(X,Y) :- on(X,Y).
above(X,Y) :- on(X,Z), above(Z,Y).
?- above(c,a).
no.
Prolog queries
?- above(a,c).
Prolog queries
?- above(a,c).
Herbrand model
on(a, b), on(b, c), on(a, c), on(b, b),
above(a, b), above(b, c), above(a, c), above(b, b), above(c, b)
Herbrand model
on(a, b), on(b, c), on(a, c), on(b, b),
above(a, b), above(b, c), above(a, c), above(b, b), above(c, b)
Outline
1 Motivation
2 Nutshell
3 Shifting paradigms
4 Rooting ASP
5 ASP solving
6 Using ASP
above(X,Y) :- on(X,Y).
above(X,Y) :- on(X,Z), above(Z,Y).
above(X,Y) :- on(X,Y).
above(X,Y) :- on(X,Z), above(Z,Y).
above(X,Y) :- on(X,Y).
above(X,Y) :- on(X,Z), above(Z,Y).
ASP versus LP
ASP Prolog
Model generation Query orientation
Bottom-up Top-down
Modeling language Programming language
Rule-based format
Instantiation Unification
Flat terms Nested terms
(Turing +) NP(NP ) Turing
Outline
1 Motivation
2 Nutshell
3 Shifting paradigms
4 Rooting ASP
5 ASP solving
6 Using ASP
ASP solving
Problem Solution
Modeling Interpreting
?
Logic - Grounder - Solver - Stable
Program Models
Solving
SAT solving
Problem Solution
Programming Interpreting
?
Formula - Solver - Classical
(CNF) Models
Solving
Problem Solution
Modeling Interpreting
?
Logic - Grounder - Solver - Stable
Program Models
Solving
Problem Solution
Modeling KR Interpreting
?
Logic - Grounder - Solver - Stable
Program Models
LP DB Solving SAT DB+KR+LP
Outline
1 Motivation
2 Nutshell
3 Shifting paradigms
4 Rooting ASP
5 ASP solving
6 Using ASP
ASP = DB+LP+KR+SAT
7 Syntax
8 Semantics
9 Examples
10 Variables
11 Language constructs
12 Reasoning modes
Outline
7 Syntax
8 Semantics
9 Examples
10 Variables
11 Language constructs
12 Reasoning modes
Problem Solution
6
Modeling Interpreting
?
Logic Program - Stable Models
Solving
a0 ← a1 , . . . , am , ∼ am+1 , . . . , ∼ an
a0 ← a1 , . . . , am , ∼ am+1 , . . . , ∼ an
a0 ← a1 , . . . , am , ∼ am+1 , . . . , ∼ an
default classical
true, false if and or iff negation negation
source code :- , | not -
logic program ← , ; ∼ ¬
formula ⊥, > → ∧ ∨ ↔ ∼ ¬
Outline
7 Syntax
8 Semantics
9 Examples
10 Variables
11 Language constructs
12 Reasoning modes
Problem Solution
6
Modeling Interpreting
?
Logic Program - Stable Models
Solving
Formal Definition
Stable models of positive programs
Formal Definition
Stable models of positive programs
Formal Definition
Stable models of positive programs
Formal Definition
Stable models of positive programs
a0 ∨ ¬a1 ∨ · · · ∨ ¬am
a0 ∨ ¬a1 ∨ · · · ∨ ¬am
a0 ∨ ¬a1 ∨ · · · ∨ ¬am
Basic idea
Consider the logical formula Φ and its three
(classical) models: Φ q ∧ (q ∧ ¬r → p)
Basic idea
Consider the logical formula Φ and its three
(classical) models: Φ q ∧ (q ∧ ¬r → p)
Basic idea
Consider the logical formula Φ and its three
(classical) models: Φ q ∧ (q ∧ ¬r → p)
Basic idea
Consider the logical formula Φ and its three
(classical) models: Φ q ∧ (q ∧ ¬r → p)
Basic idea
Consider the logical formula Φ and its three
(classical) models: Φ q ∧ (q ∧ ¬r → p)
Basic idea
Consider the logical formula Φ and its three
(classical) models: Φ q ∧ (q ∧ ¬r → p)
Basic idea
Consider the logical formula Φ and its three
(classical) models: Φ q ∧ (q ∧ ¬r → p)
Basic idea
Consider the logical formula Φ and its three
(classical) models: Φ q ∧ (q ∧ ¬r → p)
Formal Definition
Stable model of normal programs
The reduct, P X , of a program P relative to a set X of atoms is
defined by
Formal Definition
Stable model of normal programs
The reduct, P X , of a program P relative to a set X of atoms is
defined by
Formal Definition
Stable model of normal programs
The reduct, P X , of a program P relative to a set X of atoms is
defined by
A closer look at P X
A closer look at P X
Outline
7 Syntax
8 Semantics
9 Examples
10 Variables
11 Language constructs
12 Reasoning modes
A first example
P = {p ← p, q ← ∼ p}
X PX Cn(P X )
∅ p ← p {q} 8
q ←
{p} p ← p ∅ 8
{q} p ← p {q} 4
q ←
{p, q} p ← p ∅ 8
A first example
P = {p ← p, q ← ∼ p}
X PX Cn(P X )
∅ p ← p {q} 8
q ←
{p} p ← p ∅ 8
{q} p ← p {q} 4
q ←
{p, q} p ← p ∅ 8
A first example
P = {p ← p, q ← ∼ p}
X PX Cn(P X )
∅ p ← p {q} 8
q ←
{p} p ← p ∅ 8
{q} p ← p {q} 4
q ←
{p, q} p ← p ∅ 8
A first example
P = {p ← p, q ← ∼ p}
X PX Cn(P X )
∅ p ← p {q} 8
q ←
{p} p ← p ∅ 8
{q} p ← p {q} 4
q ←
{p, q} p ← p ∅ 8
A first example
P = {p ← p, q ← ∼ p}
X PX Cn(P X )
∅ p ← p {q} 8
q ←
{p} p ← p ∅ 8
{q} p ← p {q} 4
q ←
{p, q} p ← p ∅ 8
A first example
P = {p ← p, q ← ∼ p}
X PX Cn(P X )
∅ p ← p {q} 8
q ←
{p} p ← p ∅ 8
{q} p ← p {q} 4
q ←
{p, q} p ← p ∅ 8
A first example
P = {p ← p, q ← ∼ p}
X PX Cn(P X )
∅ p ← p {q} 8
q ←
{p} p ← p ∅ 8
{q} p ← p {q} 4
q ←
{p, q} p ← p ∅ 8
A second example
P = {p ← ∼ q, q ← ∼ p}
X PX Cn(P X )
∅ p ← {p, q} 8
q ←
{p} p ← {p} 4
{q} {q} 4
q ←
{p, q} ∅ 8
A second example
P = {p ← ∼ q, q ← ∼ p}
X PX Cn(P X )
∅ p ← {p, q} 8
q ←
{p} p ← {p} 4
{q} {q} 4
q ←
{p, q} ∅ 8
A second example
P = {p ← ∼ q, q ← ∼ p}
X PX Cn(P X )
∅ p ← {p, q} 8
q ←
{p} p ← {p} 4
{q} {q} 4
q ←
{p, q} ∅ 8
A second example
P = {p ← ∼ q, q ← ∼ p}
X PX Cn(P X )
∅ p ← {p, q} 8
q ←
{p} p ← {p} 4
{q} {q} 4
q ←
{p, q} ∅ 8
A second example
P = {p ← ∼ q, q ← ∼ p}
X PX Cn(P X )
∅ p ← {p, q} 8
q ←
{p} p ← {p} 4
{q} {q} 4
q ←
{p, q} ∅ 8
A second example
P = {p ← ∼ q, q ← ∼ p}
X PX Cn(P X )
∅ p ← {p, q} 8
q ←
{p} p ← {p} 4
{q} {q} 4
q ←
{p, q} ∅ 8
A third example
P = {p ← ∼ p}
X PX Cn(P X )
∅ p ← {p} 8
{p} ∅ 8
A third example
P = {p ← ∼ p}
X PX Cn(P X )
∅ p ← {p} 8
{p} ∅ 8
A third example
P = {p ← ∼ p}
X PX Cn(P X )
∅ p ← {p} 8
{p} ∅ 8
A third example
P = {p ← ∼ p}
X PX Cn(P X )
∅ p ← {p} 8
{p} ∅ 8
Some properties
Some properties
Outline
7 Syntax
8 Semantics
9 Examples
10 Variables
11 Language constructs
12 Reasoning modes
An example
An example
An example
Outline
7 Syntax
8 Semantics
9 Examples
10 Variables
11 Language constructs
12 Reasoning modes
Problem Solution
6
Modeling Interpreting
?
Logic Program - Stable Models
Solving
Language Constructs
Variables (over the Herbrand Universe)
p(X) :- q(X) over constants {a, b, c} stands for
p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)
Conditional Literals
p :- q(X) : r(X) given r(a), r(b), r(c) stands for
p :- q(a), q(b), q(c)
Disjunction
p(X) | q(X) :- r(X)
Integrity Constraints
:- q(X), p(X)
Choice
2 { p(X,Y) : q(X) } 7 :- r(Y)
Aggregates
s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7
also: #sum, #avg, #min, #max, #even, #odd
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 52 / 178
Language constructs
Language Constructs
Variables (over the Herbrand Universe)
p(X) :- q(X) over constants {a, b, c} stands for
p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)
Conditional Literals
p :- q(X) : r(X) given r(a), r(b), r(c) stands for
p :- q(a), q(b), q(c)
Disjunction
p(X) | q(X) :- r(X)
Integrity Constraints
:- q(X), p(X)
Choice
2 { p(X,Y) : q(X) } 7 :- r(Y)
Aggregates
s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7
also: #sum, #avg, #min, #max, #even, #odd
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 52 / 178
Language constructs
Language Constructs
Variables (over the Herbrand Universe)
p(X) :- q(X) over constants {a, b, c} stands for
p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)
Conditional Literals
p :- q(X) : r(X) given r(a), r(b), r(c) stands for
p :- q(a), q(b), q(c)
Disjunction
p(X) | q(X) :- r(X)
Integrity Constraints
:- q(X), p(X)
Choice
2 { p(X,Y) : q(X) } 7 :- r(Y)
Aggregates
s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7
also: #sum, #avg, #min, #max, #even, #odd
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 52 / 178
Language constructs
Language Constructs
Variables (over the Herbrand Universe)
p(X) :- q(X) over constants {a, b, c} stands for
p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)
Conditional Literals
p :- q(X) : r(X) given r(a), r(b), r(c) stands for
p :- q(a), q(b), q(c)
Disjunction
p(X) | q(X) :- r(X)
Integrity Constraints
:- q(X), p(X)
Choice
2 { p(X,Y) : q(X) } 7 :- r(Y)
Aggregates
s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7
also: #sum, #avg, #min, #max, #even, #odd
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 52 / 178
Language constructs
Language Constructs
Variables (over the Herbrand Universe)
p(X) :- q(X) over constants {a, b, c} stands for
p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)
Conditional Literals
p :- q(X) : r(X) given r(a), r(b), r(c) stands for
p :- q(a), q(b), q(c)
Disjunction
p(X) | q(X) :- r(X)
Integrity Constraints
:- q(X), p(X)
Choice
2 { p(X,Y) : q(X) } 7 :- r(Y)
Aggregates
s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7
also: #sum, #avg, #min, #max, #even, #odd
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 52 / 178
Language constructs
Language Constructs
Variables (over the Herbrand Universe)
p(X) :- q(X) over constants {a, b, c} stands for
p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)
Conditional Literals
p :- q(X) : r(X) given r(a), r(b), r(c) stands for
p :- q(a), q(b), q(c)
Disjunction
p(X) | q(X) :- r(X)
Integrity Constraints
:- q(X), p(X)
Choice
2 { p(X,Y) : q(X) } 7 :- r(Y)
Aggregates
s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7
also: #sum, #avg, #min, #max, #even, #odd
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 52 / 178
Language constructs
Language Constructs
Variables (over the Herbrand Universe)
p(X) :- q(X) over constants {a, b, c} stands for
p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)
Conditional Literals
p :- q(X) : r(X) given r(a), r(b), r(c) stands for
p :- q(a), q(b), q(c)
Disjunction
p(X) | q(X) :- r(X)
Integrity Constraints
:- q(X), p(X)
Choice
2 { p(X,Y) : q(X) } 7 :- r(Y)
Aggregates
s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7
also: #sum, #avg, #min, #max, #even, #odd
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 52 / 178
Language constructs
Language Constructs
Variables (over the Herbrand Universe)
p(X) :- q(X) over constants {a, b, c} stands for
p(a) :- q(a), p(b) :- q(b), p(c) :- q(c)
Conditional Literals
p :- q(X) : r(X) given r(a), r(b), r(c) stands for
p :- q(a), q(b), q(c)
Disjunction
p(X) | q(X) :- r(X)
Integrity Constraints
:- q(X), p(X)
Choice
2 { p(X,Y) : q(X) } 7 :- r(Y)
Aggregates
s(Y) :- r(Y), 2 #count { p(X,Y) : q(X) } 7
also: #sum, #avg, #min, #max, #even, #odd
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 52 / 178
Reasoning modes
Outline
7 Syntax
8 Semantics
9 Examples
10 Variables
11 Language constructs
12 Reasoning modes
Problem Solution
6
Modeling Interpreting
?
Logic Program - Stable Models
Solving
Reasoning Modes
Satisfiability
Enumeration†
Projection†
Intersection‡
Union‡
Optimization
†
without solution recording
‡
without solution enumeration
14 Methodology
Satisfiability
Queens
Traveling Salesperson
Reviewer Assignment
Planning
Problem Solution
6
Modeling Interpreting
?
Logic Program - Stable Models
Solving
Outline
14 Methodology
Satisfiability
Queens
Traveling Salesperson
Reviewer Assignment
Planning
Problem Solution
Modeling Interpreting
?
Logic - Grounder - Solver - Stable
Program Models
Solving
Problem Solution
Modeling Interpreting
?
Logic - Grounder - Solver - Stable
Program Models
Solving
Problem Solution
Modeling Interpreting
?
Logic - Grounder - Solver - Stable
Program Models
Solving
Problem Solution
Modeling Interpreting
?
Logic - Grounder - Solver - Stable
Program Models
Solving
Problem Solution
Modeling Interpreting
?
Logic - Grounder - Solver - Stable
Program Models
Solving
Problem Solution
Modeling Interpreting
?
Logic - Grounder - Solver - Stable
Program Models
Solving
Problem Solution
Modeling Interpreting
?
Logic - Grounder - Solver - Stable
Program Models
6 Solving
Elaborating
Outline
14 Methodology
Satisfiability
Queens
Traveling Salesperson
Reviewer Assignment
Planning
Problem Solution
Modeling Interpreting
?
Logic - Grounder - Solver - Stable
Program Models
Solving
Graph coloring
Graph coloring
Graph coloring
3 5
1 2
Graph coloring
3 5
1 2
Graph coloring
Graph coloring
Graph coloring
Problem Solution
Modeling Interpreting
?
Logic - Grounder - Solver - Stable
Program Models
Solving
Graph coloring
node(1..6).
edge(1,2). edge(1,3). edge(1,4).
edge(2,4). edge(2,5). edge(2,6).
edge(3,1). edge(3,4). edge(3,5).
Problem
edge(4,1). edge(4,2).
instance
edge(5,3). edge(5,4). edge(5,6).
edge(6,2). edge(6,3). edge(6,5).
col(r). col(b). col(g).
1 { color(X,C) : col(C) } 1 :- node(X).
Problem
encoding
:- edge(X,Y), color(X,C), color(Y,C).
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 65 / 178
ASP solving process Graph coloring
Graph coloring
node(1..6).
edge(1,2). edge(1,3). edge(1,4).
edge(2,4). edge(2,5). edge(2,6).
edge(3,1). edge(3,4). edge(3,5).
Problem
edge(4,1). edge(4,2).
instance
edge(5,3). edge(5,4). edge(5,6).
edge(6,2). edge(6,3). edge(6,5).
col(r). col(b). col(g).
1 { color(X,C) : col(C) } 1 :- node(X).
Problem
encoding
:- edge(X,Y), color(X,C), color(Y,C).
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 65 / 178
ASP solving process Graph coloring
Graph coloring
node(1..6).
edge(1,2). edge(1,3). edge(1,4).
edge(2,4). edge(2,5). edge(2,6).
edge(3,1). edge(3,4). edge(3,5).
Problem
edge(4,1). edge(4,2).
instance
edge(5,3). edge(5,4). edge(5,6).
edge(6,2). edge(6,3). edge(6,5).
col(r). col(b). col(g).
1 { color(X,C) : col(C) } 1 :- node(X).
Problem
encoding
:- edge(X,Y), color(X,C), color(Y,C).
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 65 / 178
ASP solving process Graph coloring
Graph coloring
node(1..6).
edge(1,2). edge(1,3). edge(1,4).
edge(2,4). edge(2,5). edge(2,6).
edge(3,1). edge(3,4). edge(3,5).
Problem
edge(4,1). edge(4,2).
instance
edge(5,3). edge(5,4). edge(5,6).
edge(6,2). edge(6,3). edge(6,5).
col(r). col(b). col(g).
1 { color(X,C) : col(C) } 1 :- node(X).
Problem
encoding
:- edge(X,Y), color(X,C), color(Y,C).
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 65 / 178
ASP solving process Graph coloring
Graph coloring
node(1..6).
edge(1,2). edge(1,3). edge(1,4).
edge(2,4). edge(2,5). edge(2,6).
edge(3,1). edge(3,4). edge(3,5).
Problem
edge(4,1). edge(4,2).
instance
edge(5,3). edge(5,4). edge(5,6).
edge(6,2). edge(6,3). edge(6,5).
col(r). col(b). col(g).
1 { color(X,C) : col(C) } 1 :- node(X).
Problem
encoding
:- edge(X,Y), color(X,C), color(Y,C).
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 65 / 178
ASP solving process Graph coloring
Graph coloring
node(1..6).
edge(1,2). edge(1,3). edge(1,4).
edge(2,4). edge(2,5). edge(2,6).
edge(3,1). edge(3,4). edge(3,5).
Problem
edge(4,1). edge(4,2).
instance
edge(5,3). edge(5,4). edge(5,6).
edge(6,2). edge(6,3). edge(6,5).
col(r). col(b). col(g).
1 { color(X,C) : col(C) } 1 :- node(X).
Problem
encoding
:- edge(X,Y), color(X,C), color(Y,C).
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 65 / 178
ASP solving process Graph coloring
Graph coloring
node(1..6).
edge(1,2). edge(1,3). edge(1,4).
edge(2,4). edge(2,5). edge(2,6).
edge(3,1). edge(3,4). edge(3,5).
Problem
edge(4,1). edge(4,2).
instance
edge(5,3). edge(5,4). edge(5,6).
edge(6,2). edge(6,3). edge(6,5).
col(r). col(b). col(g).
1 { color(X,C) : col(C) } 1 :- node(X).
Problem
encoding
:- edge(X,Y), color(X,C), color(Y,C).
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 65 / 178
ASP solving process Graph coloring
Graph coloring
node(1..6).
edge(1,2). edge(1,3). edge(1,4).
edge(2,4). edge(2,5). edge(2,6).
edge(3,1). edge(3,4). edge(3,5).
Problem
edge(4,1). edge(4,2).
instance
edge(5,3). edge(5,4). edge(5,6).
edge(6,2). edge(6,3). edge(6,5).
col(r). col(b). col(g).
1 { color(X,C) : col(C) } 1 :- node(X).
Problem
encoding
:- edge(X,Y), color(X,C), color(Y,C).
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 65 / 178
ASP solving process Graph coloring
Graph coloring
node(1..6).
edge(1,2). edge(1,3). edge(1,4).
edge(2,4). edge(2,5). edge(2,6).
edge(3,1). edge(3,4). edge(3,5).
Problem
edge(4,1). edge(4,2).
instance
edge(5,3). edge(5,4). edge(5,6).
edge(6,2). edge(6,3). edge(6,5).
col(r). col(b). col(g).
1 { color(X,C) : col(C) } 1 :- node(X).
Problem
encoding
:- edge(X,Y), color(X,C), color(Y,C).
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 65 / 178
ASP solving process Graph coloring
color.lp
node(1..6).
edge(1,2). edge(1,3). edge(1,4).
edge(2,4). edge(2,5). edge(2,6).
edge(3,1). edge(3,4). edge(3,5).
Problem
edge(4,1). edge(4,2).
instance
edge(5,3). edge(5,4). edge(5,6).
edge(6,2). edge(6,3). edge(6,5).
col(r). col(b). col(g).
1 { color(X,C) : col(C) } 1 :- node(X).
Problem
encoding
:- edge(X,Y), color(X,C), color(Y,C).
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 65 / 178
ASP solving process Graph coloring
Problem Solution
Modeling Interpreting
?
Logic - Grounder - Solver - Stable
Program Models
Solving
Problem Solution
Modeling Interpreting
?
Logic - Grounder - Solver - Stable
Program Models
Solving
Models : 6
Time : 0.002s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s)
CPU Time : 0.000s
Models : 6
Time : 0.002s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s)
CPU Time : 0.000s
Problem Solution
Modeling Interpreting
?
Logic - Grounder - Solver - Stable
Program Models
Solving
A coloring
Answer: 6
edge(1,2) ... col(r) ... node(1) ... \
color(6,b) color(5,r) color(4,b) color(3,g) color(2,g) color(1,r)
3 5
1 2
A coloring
Answer: 6
edge(1,2) ... col(r) ... node(1) ... \
color(6,b) color(5,r) color(4,b) color(3,g) color(2,g) color(1,r)
3 5
1 2
Outline
14 Methodology
Satisfiability
Queens
Traveling Salesperson
Reviewer Assignment
Planning
Basic methodology
Methodology
Generate and Test (or: Guess and Check)
Nutshell
Logic program = Data + Generator + Tester ( + Optimizer)
Basic methodology
Methodology
Generate and Test (or: Guess and Check)
Nutshell
Logic program = Data + Generator + Tester ( + Optimizer)
Outline
14 Methodology
Satisfiability
Queens
Traveling Salesperson
Reviewer Assignment
Planning
Satisfiability testing
(a ∨ ¬b) ∧ (¬a ∨ b)
Logic Program:
Satisfiability testing
(a ∨ ¬b) ∧ (¬a ∨ b)
Logic Program:
Satisfiability testing
(a ∨ ¬b) ∧ (¬a ∨ b)
Logic Program:
Satisfiability testing
(a ∨ ¬b) ∧ (¬a ∨ b)
Logic Program:
Satisfiability testing
(a ∨ ¬b) ∧ (¬a ∨ b)
Logic Program:
Outline
14 Methodology
Satisfiability
Queens
Traveling Salesperson
Reviewer Assignment
Planning
Place n queens on an n × n
5
Z0Z0Z chess board
4
0Z0Z0 Queens must not attack one
3
Z0Z0Z another
2
0Z0Z0 Q Q Q
1
Z0Z0Z Q Q
1 2 3 4 5
row (1.. n ).
col (1.. n ).
Models : 1
Time : 0.000
Prepare : 0.000
Prepro . : 0.000
Solving : 0.000
row (1.. n ).
col (1.. n ).
{ queen(I,J) : row(I) : col(J) }.
Models : 3+
...
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 81 / 178
Methodology Queens
5
Z0Z0Z
4
0Z0Z0
3
Z0Z0Z
2
0Z0Z0
1
Z0Z0Z
1 2 3 4 5
5
Z0Z0Z
4
0Z0Z0
3
Z0Z0Z
2
0Z0Z0
1
L0Z0Z
1 2 3 4 5
5
Z0Z0Z
4
0Z0Z0
3
Z0Z0Z
2
QZ0Z0
1
Z0Z0Z
1 2 3 4 5
Placing n Queens
queens.lp
row (1.. n ).
col (1.. n ).
{ queen (I , J ) : row ( I ) : col ( J ) }.
:- not n { queen(I,J) } n.
Placing n Queens
Running . . .
5
L0Z0Z
4
QZ0Z0
3
L0Z0Z
2
QZ0Z0
1
L0Z0Z
1 2 3 4 5
5
Z0Z0Z
4
QZ0Z0
3
L0Z0Z
2
QZ0Z0
1
LQZ0Z
1 2 3 4 5
row (1.. n ).
col (1.. n ).
{ queen (I , J ) : row ( I ) : col ( J ) }.
: - not n { queen (I , J ) } n .
:- queen(I,J), queen(I,JJ), J != JJ.
:- queen(I,J), queen(II,J), I != II.
row (1.. n ).
col (1.. n ).
{ queen (I , J ) : row ( I ) : col ( J ) }.
: - not n { queen (I , J ) } n .
:- queen(I,J), queen(I,JJ), J != JJ.
:- queen(I,J), queen(II,J), I != II.
5
Z0Z0L
4
0Z0L0
3
Z0L0Z
2
0L0Z0
1
L0Z0Z
1 2 3 4 5
Diagonal Attack
queens.lp
row (1.. n ).
col (1.. n ).
{ queen (I , J ) : row ( I ) : col ( J ) }.
: - not n { queen (I , J ) } n .
: - queen (I , J ) , queen (I , JJ ) , J != JJ .
: - queen (I , J ) , queen ( II , J ) , I != II .
:- queen(I,J), queen(II,JJ), (I,J) != (II,JJ), I-J == II-JJ.
:- queen(I,J), queen(II,JJ), (I,J) != (II,JJ), I+J == II+JJ.
Diagonal Attack
Running . . .
Models : 1+
Time : 0.000
Prepare : 0.000
Prepro . : 0.000
Solving : 0.000
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 93 / 178
Methodology Queens
5
ZQZ0Z
4
0Z0ZQ
3
Z0L0Z
2
QZ0Z0
1
Z0ZQZ
1 2 3 4 5
Optimizing
queens-opt.lp
Outline
14 Methodology
Satisfiability
Queens
Traveling Salesperson
Reviewer Assignment
Planning
Traveling Salesperson
node(1..6).
Traveling Salesperson
node(1..6).
Traveling Salesperson
node(1..6).
Traveling Salesperson
reached(Y) :- cycle(1,Y).
reached(Y) :- cycle(X,Y), reached(X).
Traveling Salesperson
reached(Y) :- cycle(1,Y).
reached(Y) :- cycle(X,Y), reached(X).
Traveling Salesperson
reached(Y) :- cycle(1,Y).
reached(Y) :- cycle(X,Y), reached(X).
Traveling Salesperson
reached(Y) :- cycle(1,Y).
reached(Y) :- cycle(X,Y), reached(X).
Outline
14 Methodology
Satisfiability
Queens
Traveling Salesperson
Reviewer Assignment
Planning
Reviewer Assignment
by Ilkka Niemelä
:- assigned(P,R), coi(R,P).
:- assigned(P,R), not classA(R,P), not classB(R,P).
:- not 6 { assigned(P,R) : paper(P) } 9, reviewer(R).
Reviewer Assignment
by Ilkka Niemelä
:- assigned(P,R), coi(R,P).
:- assigned(P,R), not classA(R,P), not classB(R,P).
:- not 6 { assigned(P,R) : paper(P) } 9, reviewer(R).
Reviewer Assignment
by Ilkka Niemelä
:- assigned(P,R), coi(R,P).
:- assigned(P,R), not classA(R,P), not classB(R,P).
:- not 6 { assigned(P,R) : paper(P) } 9, reviewer(R).
Reviewer Assignment
by Ilkka Niemelä
:- assigned(P,R), coi(R,P).
:- assigned(P,R), not classA(R,P), not classB(R,P).
:- not 6 { assigned(P,R) : paper(P) } 9, reviewer(R).
Reviewer Assignment
by Ilkka Niemelä
:- assigned(P,R), coi(R,P).
:- assigned(P,R), not classA(R,P), not classB(R,P).
:- not 6 { assigned(P,R) : paper(P) } 9, reviewer(R).
Outline
14 Methodology
Satisfiability
Queens
Traveling Salesperson
Reviewer Assignment
Planning
holds(P,0) :- init(P).
holds(P,0) :- init(P).
holds(P,0) :- init(P).
holds(P,0) :- init(P).
15 Motivation
16 Integrity constraint
17 Choice rule
18 Cardinality rule
19 Weight rule
20 Conditional literal
21 Optimization statement
22 smodels format
Outline
15 Motivation
16 Integrity constraint
17 Choice rule
18 Cardinality rule
19 Weight rule
20 Conditional literal
21 Optimization statement
22 smodels format
Language extensions
Language extensions
Language extensions
Outline
15 Motivation
16 Integrity constraint
17 Choice rule
18 Cardinality rule
19 Weight rule
20 Conditional literal
21 Optimization statement
22 smodels format
Integrity constraint
Idea Eliminate unwanted solution candidates
Syntax An integrity constraint is of the form
← a1 , . . . , am , ∼ am+1 , . . . , ∼ an
x ← a1 , . . . , am , ∼ am+1 , . . . , ∼ an , ∼ x
Integrity constraint
Idea Eliminate unwanted solution candidates
Syntax An integrity constraint is of the form
← a1 , . . . , am , ∼ am+1 , . . . , ∼ an
x ← a1 , . . . , am , ∼ am+1 , . . . , ∼ an , ∼ x
Integrity constraint
Idea Eliminate unwanted solution candidates
Syntax An integrity constraint is of the form
← a1 , . . . , am , ∼ am+1 , . . . , ∼ an
x ← a1 , . . . , am , ∼ am+1 , . . . , ∼ an , ∼ x
Outline
15 Motivation
16 Integrity constraint
17 Choice rule
18 Cardinality rule
19 Weight rule
20 Conditional literal
21 Optimization statement
22 smodels format
Choice rule
Idea Choices over subsets
Syntax A choice rule is of the form
Choice rule
Idea Choices over subsets
Syntax A choice rule is of the form
Choice rule
Idea Choices over subsets
Syntax A choice rule is of the form
Choice rule
Idea Choices over subsets
Syntax A choice rule is of the form
a0 ← am+1 , . . . , an , ∼ an+1 , . . . , ∼ ao
a1 ← a0 , ∼ a1 ... am ← a0 , ∼ am
a1 ← ∼ a1 ... am ← ∼ am
a0 ← am+1 , . . . , an , ∼ an+1 , . . . , ∼ ao
a1 ← a0 , ∼ a1 ... am ← a0 , ∼ am
a1 ← ∼ a1 ... am ← ∼ am
a0 ← am+1 , . . . , an , ∼ an+1 , . . . , ∼ ao
a1 ← a0 , ∼ a1 ... am ← a0 , ∼ am
a1 ← ∼ a1 ... am ← ∼ am
Outline
15 Motivation
16 Integrity constraint
17 Choice rule
18 Cardinality rule
19 Weight rule
20 Conditional literal
21 Optimization statement
22 smodels format
Cardinality rule
Idea Control (lower) cardinality of subsets
Syntax A cardinality rule is the form
a0 ← l { a1 , . . . , am , ∼ am+1 , . . . , ∼ an }
Cardinality rule
Idea Control (lower) cardinality of subsets
Syntax A cardinality rule is the form
a0 ← l { a1 , . . . , am , ∼ am+1 , . . . , ∼ an }
Cardinality rule
Idea Control (lower) cardinality of subsets
Syntax A cardinality rule is the form
a0 ← l { a1 , . . . , am , ∼ am+1 , . . . , ∼ an }
Cardinality rule
Idea Control (lower) cardinality of subsets
Syntax A cardinality rule is the form
a0 ← l { a1 , . . . , am , ∼ am+1 , . . . , ∼ an }
a0 ← l { a1 , . . . , am , ∼ am+1 , . . . , ∼ an }
by a0 ← ctr (1, l)
where atom ctr (i, j) represents the fact that at least j of the literals
having an equal or greater index than i, are in a stable model
The definition of ctr /2 is given for 0 ≤ k ≤ l by the rules
a0 ← l { a1 , . . . , am , ∼ am+1 , . . . , ∼ an }
by a0 ← ctr (1, l)
where atom ctr (i, j) represents the fact that at least j of the literals
having an equal or greater index than i, are in a stable model
The definition of ctr /2 is given for 0 ≤ k ≤ l by the rules
a0 ← l { a1 , . . . , am , ∼ am+1 , . . . , ∼ an }
by a0 ← ctr (1, l)
where atom ctr (i, j) represents the fact that at least j of the literals
having an equal or greater index than i, are in a stable model
The definition of ctr /2 is given for 0 ≤ k ≤ l by the rules
a0 ← l { a1 , . . . , am , ∼ am+1 , . . . , ∼ an }
by a0 ← ctr (1, l)
where atom ctr (i, j) represents the fact that at least j of the literals
having an equal or greater index than i, are in a stable model
The definition of ctr /2 is given for 0 ≤ k ≤ l by the rules
a0 ← l { a1 , . . . , am , ∼ am+1 , . . . , ∼ an }
by a0 ← ctr (1, l)
where atom ctr (i, j) represents the fact that at least j of the literals
having an equal or greater index than i, are in a stable model
The definition of ctr /2 is given for 0 ≤ k ≤ l by the rules
a0 ← l { a1 , . . . , am , ∼ am+1 , . . . , ∼ an }
by a0 ← ctr (1, l)
where atom ctr (i, j) represents the fact that at least j of the literals
having an equal or greater index than i, are in a stable model
The definition of ctr /2 is given for 0 ≤ k ≤ l by the rules
a0 ← l { a1 , . . . , am , ∼ am+1 , . . . , ∼ an }
by a0 ← ctr (1, l)
where atom ctr (i, j) represents the fact that at least j of the literals
having an equal or greater index than i, are in a stable model
The definition of ctr /2 is given for 0 ≤ k ≤ l by the rules
An example
Program { a ←, c ← 1 {a, b} } has the stable model {a, c}
Translating the cardinality rule yields the rules
a ← c ← ctr (1, 1)
ctr (1, 2) ← ctr (2, 1), a
ctr (1, 1) ← ctr (2, 1)
ctr (2, 2) ← ctr (3, 1), b
ctr (2, 1) ← ctr (3, 1)
ctr (1, 1) ← ctr (2, 0), a
ctr (1, 0) ← ctr (2, 0)
ctr (2, 1) ← ctr (3, 0), b
ctr (2, 0) ← ctr (3, 0)
ctr (3, 0) ←
having stable model {a, ctr (3, 0), ctr (2, 0), ctr (1, 0), ctr (1, 1), c}
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 114 / 178
Cardinality rule
An example
Program { a ←, c ← 1 {a, b} } has the stable model {a, c}
Translating the cardinality rule yields the rules
a ← c ← ctr (1, 1)
ctr (1, 2) ← ctr (2, 1), a
ctr (1, 1) ← ctr (2, 1)
ctr (2, 2) ← ctr (3, 1), b
ctr (2, 1) ← ctr (3, 1)
ctr (1, 1) ← ctr (2, 0), a
ctr (1, 0) ← ctr (2, 0)
ctr (2, 1) ← ctr (3, 0), b
ctr (2, 0) ← ctr (3, 0)
ctr (3, 0) ←
having stable model {a, ctr (3, 0), ctr (2, 0), ctr (1, 0), ctr (1, 1), c}
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 114 / 178
Cardinality rule
a0 ← l { a1 , . . . , am , ∼ am+1 , . . . , ∼ an } u
a0 ← l { a1 , . . . , am , ∼ am+1 , . . . , ∼ an } u
a0 ← l { a1 , . . . , am , ∼ am+1 , . . . , ∼ an } u
Cardinality constraints
Syntax A cardinality constraint is of the form
l { a1 , . . . , am , ∼ am+1 , . . . , ∼ an } u
l ≤ | ({a1 , . . . , am } ∩ X ) ∪ ({am+1 , . . . , an } \ X ) | ≤ u
Cardinality constraints
Syntax A cardinality constraint is of the form
l { a1 , . . . , am , ∼ am+1 , . . . , ∼ an } u
l ≤ | ({a1 , . . . , am } ∩ X ) ∪ ({am+1 , . . . , an } \ X ) | ≤ u
Cardinality constraints
Syntax A cardinality constraint is of the form
l { a1 , . . . , am , ∼ am+1 , . . . , ∼ an } u
l ≤ | ({a1 , . . . , am } ∩ X ) ∪ ({am+1 , . . . , an } \ X ) | ≤ u
l0 S0 u0 ← l1 S1 u1 , . . . , ln Sn un
a ← b1 , . . . , bn , ∼ c1 , . . . , ∼ cn
S0 + ← a
← a, ∼ b0 bi ← li Si
← a, c0 ci ← ui +1 Si
l0 S0 u0 ← l1 S1 u1 , . . . , ln Sn un
a ← b1 , . . . , bn , ∼ c1 , . . . , ∼ cn
S0 + ← a
← a, ∼ b0 bi ← li Si
← a, c0 ci ← ui +1 Si
l0 S0 u0 ← l1 S1 u1 , . . . , ln Sn un
a ← b1 , . . . , bn , ∼ c1 , . . . , ∼ cn
S0 + ← a
← a, ∼ b0 bi ← li Si
← a, c0 ci ← ui +1 Si
l0 S0 u0 ← l1 S1 u1 , . . . , ln Sn un
a ← b1 , . . . , bn , ∼ c1 , . . . , ∼ cn
S0 + ← a
← a, ∼ b0 bi ← li Si
← a, c0 ci ← ui +1 Si
l0 S0 u0 ← l1 S1 u1 , . . . , ln Sn un
a ← b1 , . . . , bn , ∼ c1 , . . . , ∼ cn
S0 + ← a
← a, ∼ b0 bi ← li Si
← a, c0 ci ← ui +1 Si
l0 S0 u0 ← l1 S1 u1 , . . . , ln Sn un
a ← b1 , . . . , bn , ∼ c1 , . . . , ∼ cn
S0 + ← a
← a, ∼ b0 bi ← li Si
← a, c0 ci ← ui +1 Si
Outline
15 Motivation
16 Integrity constraint
17 Choice rule
18 Cardinality rule
19 Weight rule
20 Conditional literal
21 Optimization statement
22 smodels format
Weight rule
Syntax A weight rule is the form
a0 ← l { a1 = w1 , . . . , am = wm , ∼ am+1 = wm+1 , . . . , ∼ an = wn }
Weight rule
Syntax A weight rule is the form
a0 ← l { a1 = w1 , . . . , am = wm , ∼ am+1 = wm+1 , . . . , ∼ an = wn }
Weight constraints
Syntax A weight constraint is of the form
l { a1 = w1 , . . . , am = wm , ∼ am+1 = wm+1 , . . . , ∼ an = wn } u
Example 10 {course(db)=6,course(ai)=6,course(project)=8,course(xml)=3} 20
Weight constraints
Syntax A weight constraint is of the form
l { a1 = w1 , . . . , am = wm , ∼ am+1 = wm+1 , . . . , ∼ an = wn } u
Example 10 {course(db)=6,course(ai)=6,course(project)=8,course(xml)=3} 20
Weight constraints
Syntax A weight constraint is of the form
l { a1 = w1 , . . . , am = wm , ∼ am+1 = wm+1 , . . . , ∼ an = wn } u
Example 10 {course(db)=6,course(ai)=6,course(project)=8,course(xml)=3} 20
Weight constraints
Syntax A weight constraint is of the form
l { a1 = w1 , . . . , am = wm , ∼ am+1 = wm+1 , . . . , ∼ an = wn } u
Example 10 {course(db)=6,course(ai)=6,course(project)=8,course(xml)=3} 20
Outline
15 Motivation
16 Integrity constraint
17 Choice rule
18 Cardinality rule
19 Weight rule
20 Conditional literal
21 Optimization statement
22 smodels format
Conditional literals
Syntax A conditional literal is of the form
` : `1 : · · · : `n
is instantiated to
r(1); r(3) :- r(1), r(3), 1 {r(1), r(3)}.
Conditional literals
Syntax A conditional literal is of the form
` : `1 : · · · : `n
is instantiated to
r(1); r(3) :- r(1), r(3), 1 {r(1), r(3)}.
Conditional literals
Syntax A conditional literal is of the form
` : `1 : · · · : `n
is instantiated to
r(1); r(3) :- r(1), r(3), 1 {r(1), r(3)}.
Conditional literals
Syntax A conditional literal is of the form
` : `1 : · · · : `n
is instantiated to
r(1); r(3) :- r(1), r(3), 1 {r(1), r(3)}.
Conditional literals
Syntax A conditional literal is of the form
` : `1 : · · · : `n
is instantiated to
r(1); r(3) :- r(1), r(3), 1 {r(1), r(3)}.
Conditional literals
Syntax A conditional literal is of the form
` : `1 : · · · : `n
is instantiated to
r(1); r(3) :- r(1), r(3), 1 {r(1), r(3)}.
Conditional literals
Syntax A conditional literal is of the form
` : `1 : · · · : `n
is instantiated to
r(1); r(3) :- r(1), r(3), 1 {r(1), r(3)}.
Outline
15 Motivation
16 Integrity constraint
17 Choice rule
18 Cardinality rule
19 Weight rule
20 Conditional literal
21 Optimization statement
22 smodels format
Optimization statement
Idea Express cost functions subject to minimization and/or
maximization
Syntax A minimize statement is of the form
Optimization statement
Idea Express cost functions subject to minimization and/or
maximization
Syntax A minimize statement is of the form
Optimization statement
Idea Express cost functions subject to minimization and/or
maximization
Syntax A minimize statement is of the form
Optimization statement
A maximize statement of the form
Optimization statement
A maximize statement of the form
Outline
15 Motivation
16 Integrity constraint
17 Choice rule
18 Cardinality rule
19 Weight rule
20 Conditional literal
21 Optimization statement
22 smodels format
smodels format
Logic programs in smodels format consist of
normal rules
choice rules
cardinality rules
weight rules
optimization statements
Such a format is obtained by grounders lparse and gringo
23 Potassco
24 gringo
25 clasp
26 Siblings
claspfolio
clingcon
iclingo
oclingo
Outline
23 Potassco
24 gringo
25 clasp
26 Siblings
claspfolio
clingcon
iclingo
oclingo
http://potassco.sourceforge.net
http://potassco.sourceforge.net
http://potassco.sourceforge.net
Outline
23 Potassco
24 gringo
25 clasp
26 Siblings
claspfolio
clingcon
iclingo
oclingo
gringo
An example
d(a)
d(c)
d(d)
p(a, b)
p(b, c)
p(c, d)
p(X , Z ) ← p(X , Y ), p(Y , Z )
q(a)
q(b)
q(X ) ← ∼ r (X ), d(X )
r (X ) ← ∼ q(X ), d(X )
s(X ) ← ∼ r (X ), p(X , Y ), q(Y )
An example
Safe ?
d(a)
d(c)
d(d)
p(a, b)
p(b, c)
p(c, d)
p(X , Z ) ← p(X , Y ), p(Y , Z )
q(a)
q(b)
q(X ) ← ∼ r (X ), d(X )
r (X ) ← ∼ q(X ), d(X )
s(X ) ← ∼ r (X ), p(X , Y ), q(Y )
An example
Safe ?
d(a) 4
d(c) 4
d(d) 4
p(a, b) 4
p(b, c) 4
p(c, d) 4
p(X , Z ) ← p(X , Y ), p(Y , Z )
q(a) 4
q(b) 4
q(X ) ← ∼ r (X ), d(X )
r (X ) ← ∼ q(X ), d(X )
s(X ) ← ∼ r (X ), p(X , Y ), q(Y )
An example
Safe ?
d(a) 4
d(c) 4
d(d) 4
p(a, b) 4
p(b, c) 4
p(c, d) 4
p(X , Z ) ← p(X , Y ), p(Y , Z )
q(a) 4
q(b) 4
q(X ) ← ∼ r (X ), d(X )
r (X ) ← ∼ q(X ), d(X )
s(X ) ← ∼ r (X ), p(X , Y ), q(Y )
An example
Safe ?
d(a) 4
d(c) 4
d(d) 4
p(a, b) 4
p(b, c) 4
p(c, d) 4
p(X , Z ) ← p(X , Y ), p(Y , Z ) 4
q(a) 4
q(b) 4
q(X ) ← ∼ r (X ), d(X ) 4
r (X ) ← ∼ q(X ), d(X ) 4
s(X ) ← ∼ r (X ), p(X , Y ), q(Y ) 4
Match
A substitution is a mapping from variables to terms
Match
A substitution is a mapping from variables to terms
Match
A substitution is a mapping from variables to terms
Match
A substitution is a mapping from variables to terms
Naive instantiation
Algorithm 1: NaiveInstantiation
Input : A safe (first-order) logic program P
Output : A ground logic program P 0
1 D := ∅
2 P 0 := ∅
3 repeat
4 D 0 := D
5 foreach r ∈ P do
6 B := body (r )+
7 foreach θ ∈ Θ(B, D) do
8 D := D ∪ {head(r )θ}
9 P 0 := P 0 ∪ {r θ}
10 until D = D 0
7
10 p(c, d) p/2 r /1
11 12 13
Instantiation
SCC Θ(B, D) D P0
1 {∅} d(a) d(a) ←
2 {∅} d(c) d(c) ←
3 {∅} d(d) d(d) ←
5 {∅} q(a) q(a) ←
6 {∅} q(b) q(b) ←
7 {{X 7→ a}, q(a) ← ∼ r (a), d(a)
{X 7→ c}, q(c) q(c) ← ∼ r (c), d(c)
{X 7→ d}, q(d) q(d) ← ∼ r (d), d(d)
{X 7→ a}, r (a) ← ∼ q(a), d(a)
{X 7→ c}, r (c) r (c) ← ∼ q(c), d(c)
{X 7→ d}} r (d) r (d) ← ∼ q(d), d(d)
Instantiation
SCC Θ(B, D) D P0
8 {∅} p(a, b) p(a, b) ←
9 {∅} p(b, c) p(b, c) ←
10 {∅} p(c, d) p(c, d) ←
11 {{X 7→ a, Y 7→ b, Z 7→ c}, p(a, c) p(a, c) ← p(a, b), p(b, c)
{X 7→ b, Y 7→ c, Z 7→ d}} p(b, d) p(b, d) ← p(b, c), p(c, d)
{{X 7→ a, Y 7→ c, Z 7→ d}, p(a, d) p(a, d) ← p(a, c), p(c, d)
{X 7→ a, Y 7→ b, Z 7→ d}} p(a, d) ← p(a, b), p(b, d)
12 {{X 7→ a, Y 7→ b}, s(a) s(a) ← ∼ r (a), p(a, b), q(b)
{X 7→ a, Y 7→ c}, s(a) ← ∼ r (a), p(a, c), q(c)
{X 7→ a, Y 7→ d}, s(a) ← ∼ r (a), p(a, d), q(d)
{X 7→ b, Y 7→ c}, s(b) s(b) ← ∼ r (b), p(b, c), q(c)
{X 7→ b, Y 7→ d}, s(b) ← ∼ r (b), p(b, d), q(d)
{X 7→ c, Y 7→ d}} s(c) s(c) ← ∼ r (c), p(c, d), q(d)
Outline
23 Potassco
24 gringo
25 clasp
26 Siblings
claspfolio
clingcon
iclingo
oclingo
clasp
clasp is a native ASP solver combining conflict-driven search with
sophisticated reasoning techniques:
Advanced preprocessing including, like equivalence reasoning
lookback-based decision heuristics
restart policies
nogood deletion
progress saving
dedicated data structures for binary and ternary nogoods
lazy data structures (watched literals) for long nogoods
dedicated data structures for cardinality and weight constraints
lazy unfounded set checking based on “source pointers”
tight integration of unit propagation and unfounded set checking
various reasoning modes
parallel search
...
clasp
clasp is a native ASP solver combining conflict-driven search with
sophisticated reasoning techniques:
Advanced preprocessing including, like equivalence reasoning
lookback-based decision heuristics
restart policies
nogood deletion
progress saving
dedicated data structures for binary and ternary nogoods
lazy data structures (watched literals) for long nogoods
dedicated data structures for cardinality and weight constraints
lazy unfounded set checking based on “source pointers”
tight integration of unit propagation and unfounded set checking
various reasoning modes
parallel search
...
clasp
clasp is a native ASP solver combining conflict-driven search with
sophisticated reasoning techniques:
Advanced preprocessing including, like equivalence reasoning
lookback-based decision heuristics
restart policies
nogood deletion
progress saving
dedicated data structures for binary and ternary nogoods
lazy data structures (watched literals) for long nogoods
dedicated data structures for cardinality and weight constraints
lazy unfounded set checking based on “source pointers”
tight integration of unit propagation and unfounded set checking
various reasoning modes
parallel search
...
clasp
pursues a coarse-grained, task-parallel approach to parallel search
via shared memory multi-threading
up to 64 configurable (non-hierarchic) threads
clasp
pursues a coarse-grained, task-parallel approach to parallel search
via shared memory multi-threading
up to 64 configurable (non-hierarchic) threads
clasp
pursues a coarse-grained, task-parallel approach to parallel search
via shared memory multi-threading
up to 64 configurable (non-hierarchic) threads
clasp
pursues a coarse-grained, task-parallel approach to parallel search
via shared memory multi-threading
up to 64 configurable (non-hierarchic) threads
loop
propagate // deterministically assign literals
if no conflict then
if all variables assigned then return solution
else decide // non-deterministically assign some literal
else
if top-level conflict then return unsatisfiable
else
analyze // analyze conflict and add conflict constraint
backjump // unassign literals until conflict constraint is unit
Logic Solver 1. . . n
Program Conflict Recorded Nogoods
Resolution
Decision
Heuristic Propagation
Assignment Unit Post
Post
Propagation Propagation
Propagation
Atoms/Bodies
Logic Solver 1. . . n
Program Conflict Recorded Nogoods
Resolution
Decision
Heuristic Propagation
Assignment Unit Post
Post
Propagation Propagation
Propagation
Atoms/Bodies
Logic Solver 1. . . n
Program Conflict Recorded Nogoods
Resolution
Decision
Heuristic Propagation
Assignment Unit Post
Post
Propagation Propagation
Propagation
Atoms/Bodies
Logic Solver 1. . . n
Program Conflict Recorded Nogoods
Resolution
Decision
Heuristic Propagation
Assignment Unit Post
Post
Propagation Propagation
Propagation
Atoms/Bodies
clasp in context
clasp in context
clasp-t1
-t4
120 -t8
cryptominisat-2.9.2-t4
-t8
miraxt-2009-t4
-t8
plingeling-587-t4
100 -t8
manysat-1.1-t4
-t8
Solved instances
80
60
40
20
1 10 100 1000
Time in seconds
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 149 / 178
clasp
Using clasp
Using clasp
Using clasp
Using clasp
Using clasp
Outline
23 Potassco
24 gringo
25 clasp
26 Siblings
claspfolio
clingcon
iclingo
oclingo
Outline
23 Potassco
24 gringo
25 clasp
26 Siblings
claspfolio
clingcon
iclingo
oclingo
claspfolio
Models claspfolio
Models : 1+
Time : 11.445s (Solving: 10.58s 1st Model: 10.55s Unsat: 0.00s)
CPU Time : 11.410s
Models : 1+
Time : 11.445s (Solving: 10.58s 1st Model: 10.55s Unsat: 0.00s)
CPU Time : 11.410s
PRESOLVING
Reading from queens500
Solving...
claspfolio version 1.0.1 (based on clasp version 2.0.2)
Reading from queens500
Solving...
SATISFIABLE
Models : 1+
Time : 4.785s (Solving: 3.96s 1st Model: 3.92s Unsat: 0.00s)
CPU Time : 4.780s
PRESOLVING
Reading from queens500
Solving...
claspfolio version 1.0.1 (based on clasp version 2.0.2)
Reading from queens500
Solving...
SATISFIABLE
Models : 1+
Time : 4.785s (Solving: 3.96s 1st Model: 3.92s Unsat: 0.00s)
CPU Time : 4.780s
PRESOLVING
Reading from queens500
Solving...
claspfolio version 1.0.1 (based on clasp version 2.0.2)
Reading from queens500
Solving...
SATISFIABLE
Models : 1+
Time : 4.785s (Solving: 3.96s 1st Model: 3.92s Unsat: 0.00s)
CPU Time : 4.780s
PRESOLVING
Reading from queens500
Solving...
claspfolio version 1.0.1 (based on clasp version 2.0.2)
Reading from queens500
Solving...
SATISFIABLE
Models : 1+
Time : 4.785s (Solving: 3.96s 1st Model: 3.92s Unsat: 0.00s)
CPU Time : 4.780s
PRESOLVING
Reading from queens500
Solving...
UNKNOWN
Features : 84998,3994,0,250000,1.020,62.594,63.844,21.281,84998, \
3994,100,250000,1.020,62.594,63.844,21.281,84998,3994,250,250000, \
1.020,62.594,63.844,21.281,84998,3994,475,250000,1.020,62.594, \
63.844,21.281,757989,757989,0,510983,506992,3990,1,0,127.066,9983, \
1023958,502993,1994,518971,1,0,0,254994,0,3990,0.100,0.000,99.900, \
0,270303,812,4,0,812,2223,2223,262,262,2.738,2.738,0.000,812,812, \
2270.982,0,0.000
$ claspfolio --list-features
maxLearnt,Constraints,LearntConstraints,FreeVars,Vars/FreeVars, ...
PRESOLVING
Reading from queens500
Solving...
UNKNOWN
Features : 84998,3994,0,250000,1.020,62.594,63.844,21.281,84998, \
3994,100,250000,1.020,62.594,63.844,21.281,84998,3994,250,250000, \
1.020,62.594,63.844,21.281,84998,3994,475,250000,1.020,62.594, \
63.844,21.281,757989,757989,0,510983,506992,3990,1,0,127.066,9983, \
1023958,502993,1994,518971,1,0,0,254994,0,3990,0.100,0.000,99.900, \
0,270303,812,4,0,812,2223,2223,262,262,2.738,2.738,0.000,812,812, \
2270.982,0,0.000
$ claspfolio --list-features
maxLearnt,Constraints,LearntConstraints,FreeVars,Vars/FreeVars, ...
PRESOLVING
Reading from queens500
Solving...
UNKNOWN
Features : 84998,3994,0,250000,1.020,62.594,63.844,21.281,84998, \
3994,100,250000,1.020,62.594,63.844,21.281,84998,3994,250,250000, \
1.020,62.594,63.844,21.281,84998,3994,475,250000,1.020,62.594, \
63.844,21.281,757989,757989,0,510983,506992,3990,1,0,127.066,9983, \
1023958,502993,1994,518971,1,0,0,254994,0,3990,0.100,0.000,99.900, \
0,270303,812,4,0,812,2223,2223,262,262,2.738,2.738,0.000,812,812, \
2270.982,0,0.000
$ claspfolio --list-features
maxLearnt,Constraints,LearntConstraints,FreeVars,Vars/FreeVars, ...
PRESOLVING
Reading from queens500
Solving...
UNKNOWN
PRESOLVING
Reading from queens500
Solving...
UNKNOWN
PRESOLVING
Reading from queens500
Solving...
UNKNOWN
PRESOLVING
Reading from queens500
Solving...
Models : 1+
Time : 4.783s (Solving: 3.96s 1st Model: 3.93s Unsat: 0.00s)
CPU Time : 4.760s
PRESOLVING
Reading from queens500
Solving...
Models : 1+
Time : 4.783s (Solving: 3.96s 1st Model: 3.93s Unsat: 0.00s)
CPU Time : 4.760s
PRESOLVING
Reading from queens500
Solving...
Models : 1+
Time : 4.783s (Solving: 3.96s 1st Model: 3.93s Unsat: 0.00s)
CPU Time : 4.760s
PRESOLVING
Reading from queens500
Solving...
Models : 1+
Time : 4.783s (Solving: 3.96s 1st Model: 3.93s Unsat: 0.00s)
CPU Time : 4.760s
PRESOLVING
Reading from queens500
Solving...
Models : 1+
Time : 4.783s (Solving: 3.96s 1st Model: 3.93s Unsat: 0.00s)
CPU Time : 4.760s
Outline
23 Potassco
24 gringo
25 clasp
26 Siblings
claspfolio
clingcon
iclingo
oclingo
clingcon
clingcon
gringo clasp
Theory Theory Theory
Language Propagator Solver
time(0..t). $domain(0..500).
bucket(a). volume(a,0) $== 0.
bucket(b). volume(b,0) $== 100.
:- up(a,t).
time(0..t). $domain(0..500).
bucket(a). volume(a,0) $== 0.
bucket(b). volume(b,0) $== 100.
:- up(a,t).
time(0..t). $domain(0..500).
bucket(a). volume(a,0) $== 0.
bucket(b). volume(b,0) $== 100.
:- up(a,t).
time(0..t). $domain(0..500).
bucket(a). volume(a,0) $== 0.
bucket(b). volume(b,0) $== 100.
:- up(a,t).
time(0..t). $domain(0..500).
bucket(a). volume(a,0) $== 0.
bucket(b). volume(b,0) $== 100.
:- up(a,t).
time(0..t). $domain(0..500).
bucket(a). volume(a,0) $== 0.
bucket(b). volume(b,0) $== 100.
:- up(a,t).
time(0..t). $domain(0..500).
bucket(a). volume(a,0) $== 0.
bucket(b). volume(b,0) $== 100.
:- up(a,t).
time(0..t). $domain(0..500).
bucket(a). volume(a,0) $== 0.
bucket(b). volume(b,0) $== 100.
:- up(a,t).
time(0..t). $domain(0..500).
bucket(a). volume(a,0) $== 0.
bucket(b). volume(b,0) $== 100.
:- up(a,t).
:- up(a,4).
:- up(a,4).
:- up(a,4).
:- up(a,4).
:- up(a,4).
Answer: 1
pour(a,0) pour(a,1) pour(a,2) pour(a,3)
SATISFIABLE
Models : 1
Time : 0.000
Answer: 1
pour(a,0) pour(a,1) pour(a,2) pour(a,3)
SATISFIABLE
Models : 1
Time : 0.000
Answer: 1
pour(a,0) pour(a,1) pour(a,2) pour(a,3)
SATISFIABLE
Models : 1
Time : 0.000
Answer: 1
pour(a,0) pour(a,1) pour(a,2) pour(a,3)
SATISFIABLE
Models : 1
Time : 0.000
Answer: 1
pour(a,0) pour(a,1) pour(a,2) pour(a,3)
SATISFIABLE
Models : 1
Time : 0.000 Boolean variables
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 163 / 178
Siblings clingcon
Answer: 1
pour(a,0) pour(a,1) pour(a,2) pour(a,3)
SATISFIABLE
Models : 1
Time : 0.000 Non-Boolean variables
Torsten Schaub (KRR@UP) ASP FMCAD@Cambridge 163 / 178
Siblings clingcon
Answer: 1
pour(a,0) pour(a,1) pour(a,2) pour(a,3)
SATISFIABLE
Models : 1+
Time : 0.000
Answer: 1
pour(a,0) pour(a,1) pour(a,2) pour(a,3)
SATISFIABLE
Models : 1+
Time : 0.000
Answer: 1
pour(a,0) pour(a,1) pour(a,2) pour(a,3)
SATISFIABLE
Models : 1+
Time : 0.000
Answer: 1
pour(a,0) pour(a,1) pour(a,2) pour(a,3)
SATISFIABLE
Models : 1+
Time : 0.000
Outline
23 Potassco
24 gringo
25 clasp
26 Siblings
claspfolio
clingcon
iclingo
oclingo
iclingo
gringo clasp
iclingo
Logic - Stable
Program
- Grounder - Solver Models
6
Modeling
Logic - Stable
Program
- Grounder - Solver Models
6
Modeling
B
Pk - Grounder - Solver - Stable
Models
Qk
6
Modeling
B
Pk - Grounder - Solver - Stable
Models
Qk
B
Grounder Pk Solver - Stable
Models
Qk
B
Grounder P1 Solver - Stable
Models
Q1
B
Grounder P1
Q1
Solver 8
- Stable
Models
?
B
Grounder P1
Q1
Solver 8
- Stable
Models
?
B
Grounder P1 Solver - Stable
Models
?
B
Grounder P1 Solver - Stable
Models
P2
Q2
?
B
Grounder P1
P2
Solver 8
- Stable
Models
Q2
?
B
Grounder P1 Solver - Stable
Models
P2
?
B
Grounder P1 Solver - Stable
Models
P2
P3
Q3
?
B
Grounder P1
P2
Solver 8
- Stable
Models
P3
Q3
?
B
Grounder P1 Solver - Stable
Models
P2
P3
?
B
Grounder P1 Solver - Stable
Models
P2
P3
..
.
Pn
Qn
?
B
Grounder P1
P2
Solver 4
- Stable
Models
P3
..
.
Pn
Qn
holds(P,0) :- init(P).
#cumulative t.
1 { occ(A,t) : action(A) } 1.
:- occ(A,t), pre(A,F), not holds(F,t-1).
#volatile t.
:- query(F), not holds(F,t).
holds(P,0) :- init(P).
#cumulative t.
1 { occ(A,t) : action(A) } 1.
:- occ(A,t), pre(A,F), not holds(F,t-1).
#volatile t.
:- query(F), not holds(F,t).
holds(P,0) :- init(P).
#cumulative t.
1 { occ(A,t) : action(A) } 1.
:- occ(A,t), pre(A,F), not holds(F,t-1).
#volatile t.
:- query(F), not holds(F,t).
holds(P,0) :- init(P).
#cumulative t.
1 { occ(A,t) : action(A) } 1.
:- occ(A,t), pre(A,F), not holds(F,t-1).
#volatile t.
:- query(F), not holds(F,t).
Answer: 1
occ(a,1) occ(b,2)
SATISFIABLE
Models : 1
Total Steps : 2
Time : 0.000
Answer: 1
occ(a,1) occ(b,2)
SATISFIABLE
Models : 1
Total Steps : 2
Time : 0.000
Models : 0
Time : 0.000 (g: 0.000, p: 0.000, s: 0.000)
Rules : 27
Choices : 0
Conflicts: 0
=============== step 2 ===============
Answer: 1
occ(a,1) occ(b,2)
Models : 1
Time : 0.000 (g: 0.000, p: 0.000, s: 0.000)
Rules : 16
Choices : 0
Conflicts: 0
=============== Summary ===============
SATISFIABLE
Models : 1
Total Steps : 2
Time : 0.000
Models : 0
Time : 0.000 (g: 0.000, p: 0.000, s: 0.000)
Rules : 27
Choices : 0
Conflicts: 0
=============== step 2 ===============
Answer: 1
occ(a,1) occ(b,2)
Models : 1
Time : 0.000 (g: 0.000, p: 0.000, s: 0.000)
Rules : 16
Choices : 0
Conflicts: 0
=============== Summary ===============
SATISFIABLE
Models : 1
Total Steps : 2
Time : 0.000
Outline
23 Potassco
24 gringo
25 clasp
26 Siblings
claspfolio
clingcon
iclingo
oclingo
oclingo
gringo clasp
oclingo
Controller
Logic - Stable
Program
- Grounder - Solver Models
6
Modeling
Logic - Stable
Program
- Grounder - Solver Models
6
Modeling
B
Pk - Grounder - Solver - Stable
Models
Qk
6
Modeling
B
Pk - Grounder - Solver - Stable
Models
Qk
B
Grounder Pk Solver - Stable
Models
Qk
B
Grounder Pk Solver - Stable
Models
Qk
B
Grounder Pk Solver - Stable
Models
Qk
6
E1
F1
F1
E1
B
Grounder Pk Solver - Stable
Models
Qk
6
E1
F1
F1
E1
B
Grounder P1
..
.
Solver 4
- Stable
Models
6 Pn 1
Qn1
E1
F1
F1
E1
B
Grounder P1 Solver - Stable
.. Models
.
6 Pn 1
Qn1
E2 E1
F2 F1
F2
E2
E1
B
Grounder P1 Solver - Stable
.. Models
.
6 Pn 1
Qn1
E2 E1
F2 F1
F2
E2
E1
B
Grounder P1
..
.
Solver 4
- Stable
Models
6 Pn 2
Qn2
E2 E1
F2 F1
F2
E2
E1
B
Grounder P1 Solver - Stable
.. Models
.
6 Pn 2
Qn2
E3 E2 E1
F3 F2 F1
F3
E3
E2
E1
B
Grounder P1 Solver - Stable
.. Models
.
6 Pn 2
Qn2
E3 E2 E1
F3 F2 F1
F3
E3
E2
E1
B
Grounder P1
..
.
Solver 4
- Stable
Models
6 Pn 3
Qn3
E3 E2 E1
F3 F2 F1
F42
E42
..
.
E1
B
Grounder P1 Solver - Stable
.. Models
.
6 Pn41
Qn41
F42
E42
..
.
E1
B
Grounder P1
..
.
Solver 4
- Stable
Models
6 Pn42
Qn42
F42
E42
Update
..
.
E1
B
Grounder P1 Solver - Stable
.. Models
.
6 Pn42
Qn42
F42
E42
Query
..
.
E1
B
Grounder P1 Solver - Stable
.. Models
.
6 Pn42
Qn42
F42
E42
Erasure
..
.
8
E1
B
Grounder P1 Solver - Stable
.. Models
.
6 Pn42
Qn42
Elevator Control
#base.
floor(1..3).
atFloor(1,0).
#cumulative t.
#external request(F,t) : floor(F).
1 { atFloor(F-1;F+1,t) } 1 :- atFloor(F,t-1), floor(F).
:- atFloor(F,t), not floor(F).
requested(F,t) :- request(F,t), floor(F), not atFloor(F,t).
requested(F,t) :- requested(F,t-1), floor(F), not atFloor(F,t).
goal(t) :- not requested(F,t) : floor(F).
#volatile t.
:- not goal(t).
Pushing a button
oClingo acts as a server listening on a port
waiting for client requests
To issue such requests, a separate controller program
sends online progressions using network sockets
For instance,
#step 1.
request(3,1).
#endstep.
This process terminates when the client sends
#stop.
Pushing a button
oClingo acts as a server listening on a port
waiting for client requests
To issue such requests, a separate controller program
sends online progressions using network sockets
For instance,
#step 1.
request(3,1).
#endstep.
This process terminates when the client sends
#stop.
Pushing a button
oClingo acts as a server listening on a port
waiting for client requests
To issue such requests, a separate controller program
sends online progressions using network sockets
For instance,
#step 1.
request(3,1).
#endstep.
This process terminates when the client sends
#stop.
Pushing a button
oClingo acts as a server listening on a port
waiting for client requests
To issue such requests, a separate controller program
sends online progressions using network sockets
For instance,
#step 1.
request(3,1).
#endstep.
This process terminates when the client sends
#stop.
Outline
27 Summary
Summary
Summary
ASP = DB+LP+KR+SAT
4. Grounding Martin Gebser, Roland Kaminski, Benjamin Kaufmann, and Torsten Schaub
University of Potsdam
5. Characterizations
6. Solving
7. Systems SYNTHESIS LECTURES ON SAMPLE SERIES #1
M
8. Advanced modeling &C Morgan & cLaypool publishers
9. Conclusions
4. Grounding Martin Gebser, Roland Kaminski, Benjamin Kaufmann, and Torsten Schaub
University of Potsdam
5. Characterizations
6. Solving
7. Systems SYNTHESIS LECTURES ON SAMPLE SERIES #1
M
8. Advanced modeling &C Morgan & cLaypool publishers
9. Conclusions