Answer Set Programming ASP: A new Paradigm for Knowledge Representation and Constraint Programming - PowerPoint PPT Presentation

1 / 52
About This Presentation
Title:

Answer Set Programming ASP: A new Paradigm for Knowledge Representation and Constraint Programming

Description:

Can acquire knowledge through various means such as learning ... Epistemic Logic [Moore 1978] Negation as failure [Clark 1978] Predicate completion [Clark 1980] ... – PowerPoint PPT presentation

Number of Views:87
Avg rating:3.0/5.0
Slides: 53
Provided by: Computin64
Category:

less

Transcript and Presenter's Notes

Title: Answer Set Programming ASP: A new Paradigm for Knowledge Representation and Constraint Programming


1
Answer Set Programming (ASP)A new Paradigm for
Knowledge Representation and Constraint
Programming
  • Some slides are taken from Barals talk at AAAI-05

2
Intelligent Agent
  • Can acquire knowledge through various means such
    as learning from experience, observations,
    reading, etc., and
  • Can reason with this knowledge to make plans,
    explain observations, achieve goals, etc.

3
To learn knowledge and to reason with it
  • we need to know how to represent knowledge in a
    computer readable format.
  • We need languages and corresponding methodologies
    to represent various kinds of knowledge.

4
Inadequacy of first order logic
  • They are monotonic More information one has,
    more consequences one gets.
  • Human communication is typically based on closed
    world assumption.

5
An Example of Closed World Assumption
  • ground-wet ? watering.
  • ground-wet ? raining.
  • In an open world, there could be others that
    cause ground-wet (we simply dont know, or have
    not said).
  • But in a closed world, what we said is all that
    we know, for Horn clauses, this is called Clark
    Completion,
  • Ground-wet ? watering ? raining

6
Approaches to Non-monotonic Reasoning
  • Circumscription McCarthy 1977
  • Default Reasoning Reiter 1978
  • Epistemic Logic Moore 1978
  • Negation as failure Clark 1978
  • Predicate completion Clark 1980
  • AIJ Volume 13, 1980, a special issue

7
Circumscription
  • Only consider minimal models for the
    circumscribed predicates
  • E.g.
  • bird(X) ? ab(X) ? flies(X)
  • To circumscribe predicate ab, we can assume
    ab(X)
  • unless ab(X) is known to be true. Thus, in lack
    of
  • information about a bird being abnormal, we
    conclude it
  • flies.

8
Circumscription
  • bird(X) ? ab(X) ? flies(X)
  • bird(tweety)
  • Models (after propositionalizing)
  • M1bird(tweety), ab(tweety),flies(tweet
    y)
  • M2bird(tweety), ab(tweety)
  • M3bird(tweety), flies(tweety)
  • M3 is smaller than others wrt predicate ab, and
    is the only intended model. Thus, flies(tweety)
    follows from the given formulas under
    circumscription.

9
Default Logic
  • We write default rules.
  • E.g.
  • bird(X) ab(X)
  • -----------------------
  • flies(X)
  • Reads if X is a bird, and it can be consistently
    assumed
  • that it is not abnormal, then it
    flies.

10
Answer Set Programming (ASP)
  • Key idea A problem is solved by representing it
    by a logic program whose stable models (also
    called answer sets) correspond to solutions to
    the problem.
  • The most popular form of programsnormal logic
    programs, consisting of rules of the form
  • A ? B1, , Bm, not C1, , not Cn
  • where A, Bjs and Cks are atoms in propositional
    logic
  • not Ci is called a default negation.

11
More General Forms
  • Disjunctive logic programming with rules of the
    form
  • A0 or or Al ? B1, , Bm, not C1, , not Cn
  • We will come back to this later, with other
    extensions.

12
Features of ASP
  • Its syntax uses the intuitive If-then form.
  • It is non-monotonic.
  • Can express defaults and their exceptions.
  • Can represent and reason with incomplete
    information.
  • Can express and answer problem solving queries.
  • Large body of building block results.
  • Various implementations Smodels, DLV, ASSAT,
    Clasp,

  • CModels,
  • Many applications built using it.
  • Its initial paper among the top 5 AI source
    documents in terms of citeseer citation.

13
How ASP differs from
  • Prolog ordering matters in Prolog can not
    handle cycles with not has extra-logical
    features does not have disjunction and is not
    declarative.
  • Logic Programming is a class of languages and
    many different semantics are proposed for not.
  • Classical Logic
  • Classical logic is monotonic.
  • Disjunction symbol or in ASP is non-classical.
  • The negation as failure symbol not in ASP is
    non-classical.

14
Normal logic program
  • A normal (logic) program in ASP is a collection
    of rules of the form
  • A ? B1, , Bm, not C1, , not Cn.
  • where A, Bjs and Cks are function-free atoms.
  • If the body is empty, we write
  • A ?.
  • Or simply
  • A.

15
Ground vs Non-Ground
  • A function-free program can be grounded
  • p(X) ? q(X), not s(X) . Function-free
  • p(X) ? q(f(X)), not s(X). Not function-free

16
  • Suppose we have constants a,b,c in our program,
    the rule
  • p(X) ? q(X), not s(X).
  • is a compact representation of three ground rules
  • p(a) ? q(a), not s(a).
  • p(b) ? q(b), not s(b).
  • p(c) ? q(c), not s(c).

17
Semantics
  • Informally, a stable model M of a ground program
    P is a set of ground atoms such that
  • Every rule is satisfied, i.e., for any rule in P
  • A ? B1, , Bm, not C1, , not Cn.
  • if Bi are satisfied in M and not Ci are also
    satisfied (not Cj is satisfied if Cj is not in
    M), then A is in M.
  • Every A ? M can be derived from a rule by a
    non-circular reasoning.

18
Examples
  • P1 a ? a.
  • M a is not a stable model (the
    derivation of a
  • is based on a circular reasoning),
  • but M is
  • P2 a ? not b.
  • a is the only stable model
  • P3 a ? not a.
  • It has no stable model

19
Examples
  • P4 a ? not b. b ? not a.
  • Two stable models a and b.

20
Examples
  • P4 a ? not b. b ? not a.
  • Two stable models a and b.
  • P5 a ? not b. b ? not a. a ? not a.
  • a is the only stable model.

21
Does tweety fly?
  • fly(X) ? bird(X), not ab(X).
  • ab(X) ? penguin(X).
  • bird(X) ? penguin(X).
  • bird(tweety).
  • - One stable model which contains fly(tweety).
  • But if we add
  • penguin(tweety).
  • We can no longer conclude fly(tweety)
  • fly(tweety) is false w.r.t. the only stable model

22
So, what exactly is a stable model of a normal
program
  • Idea you guess a set of atoms and verify it is
    indeed exactly the set of atoms that can be
    derived
  • The reduct of P w.r.t. M
  • h ? b1, , bm
  • h ? b1, , bm, not c1, , not
    cn is in P
  • and no ci is in M
  • M is a stable model of P iff M is the least
    model of

23
Stable model
  • For a normal program without negation (typically
    called positive program), its least model is the
    set of its atomic consequences.
  • P
  • a ? not b.
  • b ? not a.
  • M a is a stable model, since is
  • a ?.
  • its set of (atomic) consequences is precisely M
    itself.

24
Stable model
  • Why
  • a ? not a.
  • has no stable model?
  • The empty set is not a stable model. (Why?)
  • If Ma were a stable model, the reduct of
    program wrt a is the empty set, whose set of
    (atomic) consequences is also empty, not the same
    as M.

25
Constraints for disallowing
  • The head of a rule may be empty
  • ? B1, , Bm, not C1, , not Cn.
  • It says no stable model may contain all Bjs and
    none of Cjs.
  • This can actually be encoded by a rule, where f
    is a new symbol
  • f ? not f, B1, , Bm, not C1, , not Cn.

26
Generate-and-constrain first generate
  • To specify both possibilities a is in a solution
    or not, we can use a dummy a
  • a ? not a.
  • a ? not a.
  • Two stable models a, a the latter
    represents that a is not in solution

27
Generate-and-constrain first generate
  • To specify all subsets of a,b,c, we can write
  • a ? not a. b ? not b. c ? not
    c.
  • a ? not a. b ? not b. c ? not
    c.
  • Eight stable models each corresponding to a
    subset, e.g. a, b,c represents that a is in
    it, but not b, nor c.

28
Generate-and-constrain then constrain
  • Any subset of a,b,c such that a and b cannot be
    together.
  • a ? not a. b ? not b. c ? not
    c.
  • a ? not a. b ? not b. c ? not
    c.
  • ? a ,b.
  • What if we want to say whenever a is in a stable
    model, so is b?

29
3-colorability
  • Whether 3 colors, say red, blue, and yellow, are
    sufficient to color a map
  • A map is represented by a graph, with facts about
    nodes and arc as given, e.g,
  • vertex(a).
  • vertex(b).
  • arc(a,b).

30
3-colorability
  • Every vertex must be colored with exactly one
    color
  • color(V,r) ? vertex(V), not color(V,b), not
    color(V,y).
  • color(V,b) ? vertex(V), not color(V,r), not
    color(V,y).
  • color(V,y) ? vertex(V), not color(V,b), not
    color(V,r).
  • No adjacent vertices may be colored with the same
    color
  • ? vertex(V), vertex(U), arc(V,U),col(C),
    color(V,C),
  • color(U,C).
  • Of course, we need to say what colors are
  • col(r). col(b). col(y).

31
General colorability
  • A different encoding (more general but subtler)
  • color(V,C) ? node(V), col(C), not
    otherColor(V,C).
  • otherColor(V,C) ? node(V), col(C), not
    color(V,C).
  • ? node(V), col(C1), col(C2), color(V,C1),
    color(V,C2), C1? C2.
  • ? node(V), col(C), not color(V,C).
  • ? node(V), node(U), V ? U, arc(V,U), col(C ),
    color(V,C), color(U,C).

32
Hamiltonian Cycle
  • Given a set of facts defining the vertices and
    edges of a directed graph and a starting vertex
    v0, find a path that visits every vertex exactly
    once.

33
Hamiltonian Cycle
  • Any edge could be on such a path. We use in(U,V)
    to represent that edge(U,V) is on such a path.
  • in(U,V) ? edge(U,V), not out(U,V).
  • out(U,V) ? edge(U,V), not in(U,V).
  • out(U,V) is a dummy representing edge(U,V) is not
    on such a path.

34
Hamiltonian Cycle
  • A path must be chained to form a sequence over
    the edges on it
  • reachable(V) ? in(v0,V).
  • reachable(V) ? reachable(U), in(U,V).

35
Hamiltonian Cycle
  • A vertex cannot be visited more than once.
  • This can be defined as no more than one edge on
    such a path that goes into any vertex (similarly
    out of such an edge)
  • ? edge(U,V),in(U,V), edge(W,V)in(W,V), U ? W.
  • ? edge(U,V),in(U,V), edge(U,W),in(U,W), V ?
    W.

36
Hamiltonian Cycle
  • Dont forget to say that every vertex must be
    reached.
  • ? vertex(U), not reachable(U).

37
Extensions Cardinality constraint
  • A cardinality constraint is of form
  • L a1, , am, not b1, , not bk U
  • The constraint is satisfied by an interpretation
    I (a set of atoms) if the cardinality of the
    subset of the literals satisfied by I is between
    integers L and U, inclusive.
  • A cardinality constraint can be used anywhere in
    a rule.
  • E.g. P 0a, b, not d2 ?.
  • Is the head satisfied by interpretation
    a,b?

38
Cardinality constraint
  • Generate all subsets of a,b,c,d such that
    whenever a is in it so is b
  • 0a, b, c, d4 ?.
  • b ? a.
  • As 4 is the max number of literals that may be
    satisfied, you may omit it for simplicity
  • 0a, b, c, d ?.

39
Cardinality constraint
  • Generate all subsets of a,b,c,d such that if a
    is not in it, then b is in it.
  • 0a, b, c, d ?.
  • b ? not a.
  • Are they stable models?
  • M1 a,b,c M2 b,c,d,e

40
ASP Systems
  • Smodels (Helsinki Univ. of Tech.)
  • DLV (Vienna Univ. of Tech.)
  • ASSAT (HK Univ. of Sci. and Tech.)
  • Cmodel (U. of Texas at Austin)
  • Clasp (Universitat Potsdam)

41
The Smodels System
  • An efficient system for computing answer sets of
    normal programs (later exteneded to disjunctive
    programs).
  • Consists of two parts
  • Lparse ground a program
  • Smodels compute the stable models of the
    grounded program, based on DPLL.

42
Smodels
  • Syntax largely borrowed from Prolog.
  • a - not b.
  • b - not a.
  • - a.
  • A number of language constructs for convenience

43
Conditional Literals in Smodels
  • A short hand to express a set. It takes the form
  • l d
  • where l is an atom and d a domain predicate.
  • E.g. Set a vertex v to exactly one color among
  • red, blue and yellow
  • 1 setColor(v,C) color(C)1.
  • color(red). color(blue). color(yellow).
  • is equivalent to
  • 1setColor(v,red), setColor(v,blue),
    setColor(v,yellow) 1.

44
N-colorability
  • every vertex is colored with exactly one color.
  • 1 setColor(V,C) col(C) 1 - vertex(V).
  • facts representing colors
  • col(1..colors).
  • no adjacent vertices are colored with the same
    color
  • - vertex(V), vertex(U), arc(V,U), col(C ), U !
    V, setColor(V,C), setColor(U,C).
  • Typical command line
  • lparse -c colors3 coloring.lp smodels

45
Conditional literals in Smodels
  • Example
  • 1 p(I,J) d(I,J) 1.
  • d(I,J) - d(I),d(J).
  • d(1..2).
  • The first rule above is equivalent to
  • 1 p(1,1),p(1,2),p(2,1),p(2,2) 1.

46
Conditional literals in Smodels
  • Note the difference with the following program
  • 1 p(I,J) d(I) 1 - d(J).
  • d(1..2).
  • The first rule above is equivalent to
  • 1 p(I,1) d(I) 1 - d(1).
  • 1 p(I,2) d(I) 1 - d(2).
  • which are equivalent to
  • 1 p(1,1),p(2,1) 1 - d(1).
  • 1 p(1,2),p(2,2) 1 - d(2).

47
Hamiltonian Cycle Revisited
  • Any subset of edges can be on such a path
  • in(U,V) ? edge(U,V), not out(U,V).
  • out(U,V) ? edge(U,V), not in(U,V).
  • Now can be programmed as
  • 0 in(U,V) edge(U,V) .

48
Represent knowledge about Wumpus World
  • There is exactly one wumpus in all rooms
  • 1 at(I,J,wumpus) room(I,J) 1.
  • room(I,J) - col(I), row(J).
  • For a 4 by 4 grid, this is equivalent to exactly
    one atom being true in the set of 16
  • 1 at(1,1,wumpus), at(1,2,wumpus),. 1.

49
  • One or more adjacent rooms has a pit if breeze at
    current room
  • 1 at(Ni,Nj,pit) adjacent(I,J,Ni,Nj) -
  • room(I,J),
  • sensor(I,J,none,breeze).

50
N-queens problem
  • hide.
  • show q(X,Y).
  • d(1..queens).
  • 1 q(X,Y)d(Y) 1 - d(X).
  • - d(X), d(Y), d(X1), q(X,Y), q(X1,Y), X1 ! X.
  • - d(X), d(Y), d(Y1), q(X,Y), q(X,Y1), Y1 ! Y.
  • - d(X), d(Y), d(X1), d(Y1), q(X,Y), q(X1,Y1),
  • X ! X1, Y ! Y1, abs(X - X1) abs(Y - Y1).
  • - d(X), not hasq(X).
  • hasq(X) - d(X), d(Y), q(X,Y).
  • Typical command line
  • lparse -c queens8 queens.lp smodels

51
Weight constraints
  • We can replace cardinality by weights
  • L l1, w1 , lm wm U
  • where each li is an atom or a not_atom. Its
    satisfied when the sum of the satisfied lis is
    between L and U.
  • When all wi 1, it becomes a cardinality
    constraint.

52
Classic Negation
  • safe ? ? train. vs. safe ? not
    train.
  • Use a new name e.g., no_train, to represent it
  • safe ? no_train.
  • of course, they cannot be both in a stable model.
  • ? train, no_train.
Write a Comment
User Comments (0)
About PowerShow.com