Download presentation

Presentation is loading. Please wait.

Published byBailey Kennedy Modified over 4 years ago

1
Logic Programming with Solution Preferences Hai-Feng Guo University of Nebraska at Omaha, USA

2
Preference Logic Programming (PLP) Proposed by Bharat Jayaraman (ICLP95, POPL96). PLP is an extension of constraint logic programming for declaratively specifying optimization problems requiring comparison and selection among alternative solutions.

3
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

4
Optimization using PLP Specification in PLP A set of constraints Solution preference rules Advantages Separate optimization from problem specification Declarativity and flexibility

5
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.

6
Solution Preferences in Tabled Prolog Brief introduction of Tabled Prolog Mode-directed tabled predicates Support solution preferences

7
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.

8
Reachability :- 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). abc

9
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.

10
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.

11
Mode Declaration for Tabled Predicates :- table p(a 1, …, a n ). p/n is a predicate name, n > 0; each a i 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.

12
Reachability :- 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). abc

13
Built-in Modes for Tabled Predicates ModesInformal Semantics + – min max last <<< an indexed argument non-indexed / for the first answer non-indexed / for the minimal non-indexed / for the maximal non-indexed / for the last answer non-indexed / for user-defined preferences

14
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). … …

15
Syntax A Prolog program with solution preferences consists of three parts: 1. Constraints/rules to the general problem; 2. Specify which predicate to be optimized with a mode declaration; 3. Optimization criteria using a set of preference clauses in a form of: T1 <<< T2 :- B1, B2, …, Bn. (n0)

16
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.

17
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

18
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 ).

19
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.

20
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 F = 1; F = 0), (Ans Flag = 1; true), compareToTabled(Ttail, Ans, Ftail, Flag).

21
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.

22
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.

23
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.

24
Experiments: seconds/(ratio) matrixlcsobstapspknap without preferences 1.47 (1.0) 0.80 (1.0) 1.50 (1.0) 3.14 (1.0) 99.69 (1.0) Preferences with a naïve transformation 0.37 (0.25) 0.53 (0.66) 0.38 (0.25) 3.11 (0.99) 77.45 (0.78) Preferences with an interface predicate 1.06 (0.72) 0.70 (0.88) 1.11 (0.74) 2.63 (0.84) 58.96 (0.59)

25
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.

Similar presentations

Presentation is loading. Please wait....

OK

PLANNING UNDER UNCERTAINTY REGRET THEORY.

PLANNING UNDER UNCERTAINTY REGRET THEORY.

© 2018 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google