Logic programming with solution preferences
Download
1 / 25

Logic Programming with Solution Preferences - PowerPoint PPT Presentation


  • 443 Views
  • Updated On :

Logic Programming with Solution Preferences Hai-Feng Guo University of Nebraska at Omaha, USA Preference Logic Programming (PLP) Proposed by Bharat Jayaraman (ICLP’95, POPL’96).

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Logic Programming with Solution Preferences ' - ostinmannual


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Logic programming with solution preferences l.jpg

Logic Programming with Solution Preferences

Hai-Feng Guo

University of Nebraska at Omaha, USA


Preference logic programming plp l.jpg
Preference Logic Programming(PLP)

  • Proposed by Bharat Jayaraman (ICLP’95, POPL’96).

  • PLP is an extension of constraint logic programming for declaratively specifying optimization problems requiring comparison and selection among alternative solutions.


Optimization problems l.jpg
Optimization Problems

  • Traditional specification:

    • A set of constraints

    • Minimizing (or maximizing) an objective function

  • Difficult to specify in the following cases

    • compound objectives

    • optimization over structural domains


Optimization using plp l.jpg
Optimization using PLP

  • Specification in PLP

    • A set of constraints

    • Solution preference rules

  • Advantages

    • Separate optimization from problem specification

    • Declarativity and flexibility


A simple example search for a lowest cost path l.jpg
A simple example: search for a lowest-cost path

path(X, X, 0, 0, []).

path(X, Y, C, D, [(X, Y)]) :- edge(X, Y, C, D).

path(X, Y, C, D, [(X, Z) | P]) :- edge(X, Z, C1, D1), path(Z, Y, C2, D2, P), D is D1 + D2, C is C1 + C2.

edge(a, b, 3, 4). … …

path(X,Y,C1, D1,_) <<< path(X,Y,C2, D2,_) :- C2 < C1.

path(X,Y,C1, D1,_) <<< path(X,Y,C2, D2,_) :- C1 = C2, D2 < D1.


Solution preferences in tabled prolog l.jpg
Solution Preferences in Tabled Prolog

  • Brief introduction of Tabled Prolog

  • Mode-directed tabled predicates

  • Support solution preferences


Tabled prolog l.jpg
Tabled Prolog

  • A tabled Prolog system

    • terminates more often by computing fixed points

    • avoids redundant computation by memoing the computed answers

    • keeps the declarative and procedural semantics consistent for any definite Prolog programs with bounded-size terms.


Reachability l.jpg

:- table reach/2.

reach(X, Y) :- reach(X, Z), arc(Z, Y).

reach(X, Y) :- arc(X, Y).

arc(a, b).

arc(a, c).

arc(b, a).

:- reach(a, X).

:- table reach/3.

reach(X, Y, E) :- reach(X, Z, E1),

arc(Z, Y, E2),

append(E1, E2, E).

reach(X, Y, E) :- arc(X, Y, E).

arc(a, b, [(a, b)]).

arc(a, c, [(a, c)]).

arc(b, a, [(b, a)]).

:- reach(a, X, P).

Reachability

c

a

b


How tabled answers are collected l.jpg
How tabled answers are collected?

  • When an answer to a tabled subgoal is generated, variant checking is used to check whether it has been already tabled.

  • Observation: for collecting paths for the reachability problem, we need only one simple path for each pair of nodes. A second possible path for the same pair of nodes could be thought of as a variant answer.


Indexed non indexed l.jpg
Indexed / Non-indexed

  • The arguments of each tabled predicate are divided into indexed and non-indexed ones.

  • Only indexed arguments are used for variant checking for collecting tabled answers.

  • Non-indexed arguments are treated as no difference.


Mode declaration for tabled predicates l.jpg
Mode Declaration for Tabled Predicates

:- table p(a1, …, an).

  • p/n is a predicate name, n > 0;

  • each ai has one of the following forms:

    • + denotes that this indexed argument is used for variant checking;

    •  denotes that this non-indexed argument is not used for variant checking.


Reachability12 l.jpg

:- table reach(+, +, –).

reach(X, Y, E) :- reach(X, Z, E1),

arc(Z, Y, E2),

append(E1, E2, E).

reach(X, Y, E) :- arc(X, Y, E).

arc(a, b, [(a, b)]).

arc(a, c, [(a, c)]).

arc(b, a, [(b, a)]).

:- reach(a, X, P).

Reachability

c

a

b


Built in modes for tabled predicates l.jpg
Built-in Modes for Tabled Predicates


A shortest path l.jpg
A shortest path

:- table path(+,+,min,–).

path(X, X, 0, []).

path(X, Y, D, [e(X, Y)]) :- edge(X, Y, D).

path(X, Y, D, [e(X, Z) | P]) :- edge(X, Z, D1), path(Z, Y, D2, P), D is D1 + D2.

edge(a,b,4). edge(b,a,3). edge(b,c,2). … …


Syntax l.jpg
Syntax

  • A Prolog program with solution preferences consists of three parts:

  • Constraints/rules to the general problem;

  • Specify which predicate to be optimized with a mode declaration;

  • Optimization criteria using a set of preference clauses in a form of:

    T1 <<< T2 :- B1, B2, …, Bn. (n≥0)


A lowest cost path l.jpg
A lowest-cost path

path(X, X, 0, 0, []).

path(X, Y, C, D, [e(X, Y)]) :- edge(X, Y, C, D).

path(X, Y, C, D, [e(X, Z) | P]) :- edge(X, Z, C1, D1), path(Z, Y, C2, D2, P), D is D1 + D2, C is C1 + C2.

:- table path(+,+,<<<,<<<, –).

path(X,Y,C1, D1,_) <<< path(X,Y,C2, D2,_) :- C2 < C1.

Path(X,Y,C1, D1,_) <<< path(X,Y,C2, D2,_) :- C1 = C2, D2 < D1.


Challenge l.jpg
Challenge

  • How the defined solution preferences take effects automatically on pruning suboptimal answers and their dependents during the computation?

    • The solution preferences --- Prolog programming level

    • The answer collection --- the system level


A na ve transformation l.jpg
A naïve transformation

pathNew(X, X, 0, 0, []).

pathNew(X, Y, C, D, [(X,Y)]) :- edge(X, Y, C, D).

pathNew(X, Y, C, D, [(X, Z)|P]) :-

edge(X, Z, C1, D1), path(Z, Y, C2, D2, P),

C is C1 + C2, D is D1 + D2.

:- table path(+, +, last, -, -).

path(X, Y, C1, D1, _) <<< path(X, Y, C2, D2, _) :-

C2 < C1.

path(X, Y, C1, D1, _) <<< path(X, Y, C2, D2, _) :-

C1 = C2, D2 < D1.

path(X, Y, C, D, P) :-

pathNew(X, Y, C, D, P),

( path(X, Y, C1, D1, P1) ->

path(X, Y, C1, D1, P1) <<< path(X, Y, C, D, P)

; true

).


Limitation l.jpg
Limitation

  • The answer set over <<< has a total order relation:

    • Every two answers are comparable in terms of <<<;

    • Contradictory preferences are not allowed in the program;

    • It is assumed that there is only a single optimal answer.


Updatetable 1 l.jpg
updateTable/1

updateTable(Ans) :-

allTabledAnswers(TabAns),

updateTabledAnswers(TabAns, Ans).

updateTabledAnswers(TabAns, Ans) :-

compareToTabled(TabAns, Ans, Flist, AnsFlag),

removeTabledAnswers(Flist),

AnsFlag == 0.

compareToTabled([], _, [], Flag) :-

(var(Flag) -> Flag = 0; true).

compareToTabled([T | Ttail], Ans, [F | Ftail], Flag) :-

(T <<< Ans -> F = 1; F = 0),

(Ans <<< T -> Flag = 1; true),

compareToTabled(Ttail, Ans, Ftail, Flag).


Updatetable ans l.jpg
updateTable(Ans)

  • It is invoked when a new answer Ans to a tabled subgoal is obtained;

  • It determines whether Ans is less preferred than any current tabled answer; if so, Ans is discarded;

  • It also determines whether Ans is better preferred than any current tabled answer; if so, those tabled answers are removed from the table.


Embedding preferences via an interface predicate l.jpg
Embedding Preferences via an Interface Predicate

path(X, X, 0, 0, []) :-

updateTable(path(X,X,0,0,[])).

path(X, Y, C, D, [(X,Y)]) :-

edge(X, Y, C, D), updateTable(path(X,Y,C,D,[(X,Y)])).

path(X, Y, C, D, [(X, Z)|P]) :-

edge(X, Z, C1, D1), path(Z, Y, C2, D2, P),

C is C1 + C2, D is D1 + D2,

updateTable(path(X,Y,C,D,[(X,Z)|P]).

:- table path(+, +, <<<, <<<, -).

path(X, Y, C1, D1, _) <<< path(X, Y, C2, D2, _) :-

C2 < C1.

path(X, Y, C1, D1, _) <<< path(X, Y, C2, D2, _) :-

C1 = C2, D2 < D1.


Flexibility l.jpg
Flexibility

  • Support multiple optimal answers

  • If two answers are not comparable, then both of them can be optimal atoms.

  • If contradictory preferences occurs, e.g, p(a) <<< p(b) and p(b) <<< p(a), then both p(a) and p(b) should be removed from the table.



Conclusions l.jpg
Conclusions

  • Programming with Preferences is a declarative paradigm for specifying optimization problems requiring comparison and selection among alternative solutions.

  • A tabled Prolog system with mode declaration scheme provides an easy vehicle for the implementation.


ad