47
N.F. Zhou, KR'12 1 BPSolver’s Solutions to the ASP Competition Problems Neng-Fa Zhou 周 周周 The City University of New York [email protected] u

BPSolver’s Solutions to the ASP Competition Problems

  • Upload
    kamin

  • View
    38

  • Download
    0

Embed Size (px)

DESCRIPTION

BPSolver’s Solutions to the ASP Competition Problems. Neng-Fa Zhou 周 能法 The City University of New York [email protected]. Outline. Overview of the ASP competition B-Prolog’s features BPSolver’s winning solutions BPSolver’s hopeful solutions BPSolver’s losing solutions - PowerPoint PPT Presentation

Citation preview

Page 1: BPSolver’s Solutions to the ASP Competition Problems

N.F. Zhou, KR'12 1

BPSolver’s Solutions to the ASP Competition Problems

Neng-Fa Zhou周 能法

The City University of New [email protected]

Page 2: BPSolver’s Solutions to the ASP Competition Problems

Outline

Overview of the ASP competition B-Prolog’s features BPSolver’s winning solutions BPSolver’s hopeful solutions BPSolver’s losing solutions Observations

N.F. Zhou, KR'12 2

Page 3: BPSolver’s Solutions to the ASP Competition Problems

Overview of ASP Competition (Model & Solve) Principles

– To foster open comparison of ASP with any other declarative paradigm

– To foster development of new language constructs

– To foster development of new heuristics and/or algorithms

N.F. Zhou, KR'12 3

Page 4: BPSolver’s Solutions to the ASP Competition Problems

Overview of ASP Competition (Model & Solve) Participants

– Aclasp (Gringo + Clasp + Gecode)– BPSolver (B-Prolog)– EZCSP (Gringo + Clasp + B-Prolog)– Fastdownward (PDDL)– IDP (grounder Gidl + MinisatID) – Potassco (Gringo + Clasp + Gecode)

N.F. Zhou, KR'12 4

Page 5: BPSolver’s Solutions to the ASP Competition Problems

Overview of ASP Competition (Model & Solve) Benchmarks (34)

– P-problems (7)– NP-problems (19)– Beyond NP problems (2)– Optimization problems (6)

N.F. Zhou, KR'12 5

Page 6: BPSolver’s Solutions to the ASP Competition Problems

Another View of the Results(Clasp Vs. B-Prolog)

N.F. Zhou, KR'12 6

Page 7: BPSolver’s Solutions to the ASP Competition Problems

Overview of the ASP competition B-Prolog’s features BPSolver’s winning solutions BPSolver’s hopeful solutions BPSolver’s losing solutions Observations

Outline

N.F. Zhou, KR'12 7

Page 8: BPSolver’s Solutions to the ASP Competition Problems

N.F. Zhou, KR'12 8

B-Prolog =Prolog + Tabling + CLP(FD) Prolog enhanced with

– Array subscripts

– Loop constructs

Tabling– Memorize and reuse intermediate results

• Suitable for dynamic programming problems

CLP(FD)– Constraint Logic Programming over Finite Domains

• Suitable for constraint satisfaction problems (NP-complete)

Page 9: BPSolver’s Solutions to the ASP Competition Problems

9

Array Subscripts in B-Prolog

In arithmetic expressions

In arithmetic constraints

In calls to @= and @:=

In any other context, X[I1,…,In] is the same as X^[I1,…,In]

S is X[1]+X[2]+X[3]

X[1]+X[2] #= X[3]

X[1,2] @= 100X[1,2] @:= 100

N.F. Zhou, KR'12

Page 10: BPSolver’s Solutions to the ASP Competition Problems

Loop Constructs in B-Prolog

foreach– foreach(E1 in D1, . . ., En in Dn, LVars, Goal)

– Example:• foreach(A in [a,b], I in 1..2, writeln((A,I))

List comprehension– [T : E1 in D1, . . ., En in Dn, LVars, Goal]

– Examples:• L @= [(A,I): A in [a,b], I in 1..2].• sum([A[I,J] : I in 1..N, J in 1..N]) #= N*N

N.F. Zhou, KR'12 10

Page 11: BPSolver’s Solutions to the ASP Competition Problems

More Examples

Create a list of 10 random integers

Create a matrix of random integers

N.F. Zhou, KR'12 11

L @= [X : I in 1..10, [X], X is random]

matrix(NRow,NCols,M):- M @= [R : I in 1..NRows, [R], (R @= [X : J in 1..NCols, [X],X is random])].

Page 12: BPSolver’s Solutions to the ASP Competition Problems

N.F. Zhou, KR'12 12

Tabling in B-Prolog

Eliminate infinite loops

Reduce redundant computations

:-table path/2.path(X,Y):-edge(X,Y).path(X,Y):-edge(X,Z),path(Z,Y).

:-table fib/2.fib(0,1).fib(1,1).fib(N,F):-

N>1,     N1 is N-1,fib(N1,F1),

N2 is N-2,fib(N2,F2),F is F1+F2.

Page 13: BPSolver’s Solutions to the ASP Competition Problems

The Table-All Approach

Characteristics– All the arguments of a tabled subgoal are used in

variant checking– All answers are tabled

Problems– The number of answers may be too large or even

infinite for DP and ML problems– When computing aggregates, tabling

noncontributing answers is a waste

N.F. Zhou, KR'12 13

Page 14: BPSolver’s Solutions to the ASP Competition Problems

N.F. Zhou, KR'12 14

Mode-Directed Tabling in B-Prolog Table mode declaration

– C: Cardinality limit

– Modes• + : input• - : output• min: minimized• max: maximized

:-table p(M1,...,Mn):C.

Page 15: BPSolver’s Solutions to the ASP Competition Problems

N.F. Zhou, KR'12 15

Example: Shortest Path Problem

sp(X,Y,P,W)– P is a path between X and Y with minimal

weight W.

:-table sp(+,+,-,min). sp(X,Y,[(X,Y)],W) :- edge(X,Y,W). sp(X,Y,[(X,Z)|Path],W) :- edge(X,Z,W1), sp(Z,Y,Path,W2), W is W1+W2.

Page 16: BPSolver’s Solutions to the ASP Competition Problems

N.F. Zhou, KR'12 16

CLP(FD) in B-Prolog

A rich set of built-in constraints – Unification and arithmetic constraints (#=, #\=, #>,

#>=, #<, #=<)– Global constraints

A glass-box approach to the implementation– All propagators are described in Action Rules

(TPLP’06)– Action Rules is open to the user for describing

problem-specific propagators A rich set of labeling options

Page 17: BPSolver’s Solutions to the ASP Competition Problems

Global Constraints in B-Prolog all_different(L) & all_distinct(L)

– post_neqs(L)

circuit(L) count(V,L,RelOp,N)

– exactly(N,L,V)– atleast(N,L,V)– atmost(N,L,V)

cumulative(Starts,Durations,Resources,Limit)– serialized(Starts,Durations)

diffn(L) element(I,L,V) path_from_to(From,To,L)& path_from_to(From,To,L,Lab)

N.F. Zhou, KR'12 17

Page 18: BPSolver’s Solutions to the ASP Competition Problems

Overview of the ASP competition B-Prolog’s features BPSolver’s winning solutions BPSolver’s hopeful solutions BPSolver’s losing solutions Observations

Outline

N.F. Zhou, KR'12 18

Page 19: BPSolver’s Solutions to the ASP Competition Problems

BPSolver’s Winning Solutions

N.F. Zhou, KR'12 19

Page 20: BPSolver’s Solutions to the ASP Competition Problems

Winning Solutions in Prolog

Grammar-Based Information Extraction– Parsing

Labyrinth– State space search

Tomography– Network covering

N.F. Zhou, KR'12 20

Page 21: BPSolver’s Solutions to the ASP Competition Problems

Winning Solutions With Tabling

Reachability Hydraulic Planning Hydraulic Leaking Airport Pickup Hanoi Tower

N.F. Zhou, KR'12 21

Page 22: BPSolver’s Solutions to the ASP Competition Problems

Reachability

N.F. Zhou, KR'12 22

:-table reach/1.reach(X):- start(X).reach(Y):- reach(X), edge(X,Y).

Page 23: BPSolver’s Solutions to the ASP Competition Problems

Hydraulic Planning

N.F. Zhou, KR'12 23

:-table pressurize(+,-,min).pressurize(Node,Plan,Len):- full(Node),!, Plan=[],Len=0.pressurize(Node,[Valve|Plan],Len):- link(AnotherNode,Node,Valve), \+ stuck(Valve), pressurize(AnotherNode,Plan,Len1), Len is Len1+1.

Page 24: BPSolver’s Solutions to the ASP Competition Problems

Hydraulic Leaking

N.F. Zhou, KR'12 24

:-table pressurize(+,-,min).pressurize(Node,Plan,(Leaks,Len)):- full(Node),!, Plan=[],Leaks=0,Len=0.pressurize(Node,[Valve|Plan],(Leaks,Len)):- link(AnotherNode,Node,Valve), \+ stuck(Valve), pressurize(AnotherNode,Plan,(Leaks1,Len1)), Len is Len1+1, (leaking(Valve)-> Leaks is Leaks1+1 ; Leaks is Leaks1 ).

Page 25: BPSolver’s Solutions to the ASP Competition Problems

Airport Pickup

Passengers at Airport #1 want to move to Airport #2 and vice versa

A certain number of vehicles are available Some of the locations are gas stations

N.F. Zhou, KR'12 25

CITY MAP

Page 26: BPSolver’s Solutions to the ASP Competition Problems

Solution to Airport Pickup

N.F. Zhou, KR'12 26

:-table move_vehicle(+,+,+,+,max,-).move_vehicle(X,X,_Cap,GasLevel,Objective,Steps):- Objective=(GasLevel,0),Steps=[].move_vehicle(X,Y,Cap,GasLevel,Objective,[drive(Z)|Steps]):- (driveway(X,Z,GasNeeded);driveway(Z,X,GasNeeded)), GasLevel>=GasNeeded, GasLevel1 is GasLevel-GasNeeded, move_vehicle(Z,Y,Cap,GasLevel1,Objective1,Steps), Objective1=(AfterGasLevel,MLen), MLen1 is MLen-1, Objective=(AfterGasLevel,MLen1).move_vehicle(X,Y,Cap,GasLevel,Objective,[refuel|Steps]):- gasstation(X), GasLevel<Cap, move_vehicle(X,Y,Cap,Cap,Objective1,Steps), Objective1=(AfterGasLevel,MLen), MLen1 is MLen-1, Objective=(AfterGasLevel,MLen1).

Page 27: BPSolver’s Solutions to the ASP Competition Problems

Hanoi Tower (4-Pegs)

N.F. Zhou, KR'12 27

A B C D A B C D

Two snapshots from the sequence by the Frame-Stewart algorithm

Page 28: BPSolver’s Solutions to the ASP Competition Problems

Problem Reduction

If the largest disk is in its final position, remove it.

N.F. Zhou, KR'12 28

A B C D A B C D

Page 29: BPSolver’s Solutions to the ASP Competition Problems

Create an Intermediate State

Subproblems

N.F. Zhou, KR'12 29

A B C D A B C D

A B C D A B C D

Sub-prob-1

Sub-prob-2

Page 30: BPSolver’s Solutions to the ASP Competition Problems

The Solution(4-Peg Hanoi Tower)

N.F. Zhou, KR'12 30

:-table plan4(+,+,+,-,min).plan4(N,_CState,_GState,Plan,Len):-N=:=0,!,Plan=[],Len=0.plan4(N,CState,GState,Plan,Len):- reduce_prob(N,CState,GState,CState1,GState1),!, N1 is N-1, plan4(N1,CState1,GState1,Plan,Len).plan4(N,CState,GState,Plan,Len):- partition_disks(N,CState,GState,ItState,Mid,Peg), remove_larger_disks(CState,Mid,CState1), plan4(Mid,CState1,ItState,Plan1,Len1), % sub-prob1 remove_smaller_or_equal_disks(CState,Mid,CState2), remove_smaller_or_equal_disks(GState,Mid,GState2), N1 is N-Mid, plan3(N1,CState2,GState2,Peg,Plan2,Len2), % sub-prob2 remove_larger_disks(GState,Mid,GState1), plan4(Mid,ItState,GState1,Plan3,Len3), % sub-prob3 append(Plan1,Plan2,Plan3,Plan), Len is Len1+Len2+Len3.

Page 31: BPSolver’s Solutions to the ASP Competition Problems

Winning Solutions in CLP(FD)

Tangram Magic Square Sets (all_different) Weight-Assignment Tree (element) Knight Tour (circuit) Disjunctive Scheduling (post_disjunctive_tasks) Maximal Clique

N.F. Zhou, KR'12 31

Page 32: BPSolver’s Solutions to the ASP Competition Problems

Magic Square Sets

N.F. Zhou, KR'12 32

semi(Board,N,Magic):- foreach(I in 1..N, sum([Board[I,J] : J in 1..N])#=Magic), foreach(J in 1..N, sum([Board[I,J] : I in 1..N])#=Magic).

normal(Board,N,Magic):- sum([Board[I,I] : I in 1..N]) #= Magic, sum([Board[I,N-I+1] : I in 1..N]) #= Magic.

Page 33: BPSolver’s Solutions to the ASP Competition Problems

Overview of the ASP competition B-Prolog’s features BPSolver’s winning solutions BPSolver’s hopeful solutions BPSolver’s losing solutions Observations

Outline

N.F. Zhou, KR'12 33

Page 34: BPSolver’s Solutions to the ASP Competition Problems

BPSolver’s Hopeful Solutions

Graph Coloring (Ranking = 5) Sokoban Optimization (Ranking = 4)

N.F. Zhou, KR'12 34

Page 35: BPSolver’s Solutions to the ASP Competition Problems

Graph Coloring

Model-1 (neq)• For each two neighbors i and j, CiCj

Model-2 (all_distinct)• For each complete subgraph (clique) {i1,i2,…,ik},

all_distinct([Ci1, Ci2,…, Cik])

• post_neqs(Neqs) in B-Prolog

Model-3 (Model-2 + symmetry breaking)– Allen Van Gelder: Another look at graph coloring via

propositional satisfiabilityN.F. Zhou, KR'12 35

Page 36: BPSolver’s Solutions to the ASP Competition Problems

Graph Coloring in B-Prolog

N.F. Zhou, KR'12 36

Go:- create_vars(Vars), generate_neqs(Vars,Neqs), post_neqs(Neqs,Cliques), largest_clique(Cliques,LClique), (labeling(LClique)-> labeling_ffc(Vars),!;fail), output(Vars).

Page 37: BPSolver’s Solutions to the ASP Competition Problems

Performance Comparison(Model-2 Vs. Model-3)

N.F. Zhou, KR'12 37

Page 38: BPSolver’s Solutions to the ASP Competition Problems

The Sokoban Problem

N.F. Zhou, KR'12 38

[push(c6r3,down,c6r5), push(c5r4,left,c3r4), push(c3r4,down,c3r5), push(c5r5,up,c5r4), push(c6r5,left,c5r5), push(c5r4,right,c6r4), push(c5r5,up,c5r4), push(c6r4,up,c6r3), push(c5r4,left,c4r4), push(c6r3,down,c6r4), push(c3r5,up,c3r3), push(c4r4,left,c3r4), push(c6r4,left,c4r4)]

Page 39: BPSolver’s Solutions to the ASP Competition Problems

BPSolver’s Solution to Sokoban

N.F. Zhou, KR'12 39

Page 40: BPSolver’s Solutions to the ASP Competition Problems

The Competition Results

N.F. Zhou, KR'12 40

Page 41: BPSolver’s Solutions to the ASP Competition Problems

BPSolver’s Losing Solutions(Score) Partner Units (0) Reverse Folding (0) Strategic Companies (0) Company Controls Optimize (0) Stable Marriage (5) Solitaire (28) Maze Generation (49)

N.F. Zhou, KR'12 41

Page 42: BPSolver’s Solutions to the ASP Competition Problems

A Common Interface to SAT and LP/MIP

N.F. Zhou, KR'12 42

queens(N):- length(Qs,N), Qs :: 1..N, foreach(I in 1..N-1, J in I+1..N, (Qs[I] $\= Qs[J], Qs[I]-Qs[J] $\= J-I, Qs[J]-Qs[I] $\= J-I)), sat_solve(Qs), writeln(Qs).

Page 43: BPSolver’s Solutions to the ASP Competition Problems

Numberlink

N.F. Zhou, KR'12 43

Page 44: BPSolver’s Solutions to the ASP Competition Problems

N.F. Zhou, KR'12 44

B-Prolog =Prolog + Tabling + CLP(FD)+SAT

Prolog enhanced with – Array subscripts

– Loop constructs

Tabling– Memorize and reuse intermediate results

• Suitable for dynamic programming problems

CLP(FD) & SAT– Constraint Logic Programming over Finite Domains

• Suitable for constraint satisfaction problems (NP-complete)

Page 45: BPSolver’s Solutions to the ASP Competition Problems

Observations

ASP vs B-Prolog– ASP encodings are generally shorter than BP

encodings

Grounding vs. top-down tabled evaluation SAT vs. CP

N.F. Zhou, KR'12 45

Page 46: BPSolver’s Solutions to the ASP Competition Problems

Resources

BPSolver’s solutions– www.sci.brooklyn.cuny.edu/~zhou/asp11/– www.probp.com/asp11/

B-Prolog– www.probp.com

Papers– www.sci.brooklyn.cuny.edu/~zhou/

N.F. Zhou, KR'12 46

Page 47: BPSolver’s Solutions to the ASP Competition Problems

Thanks

ASP competition organization committee BPSolver team members

– Agostino Dovier– Yuanlin Zhang

NSF and PSC-CUNY

N.F. Zhou, KR'12 47