Skip to content

Commit

Permalink
fix cargo example
Browse files Browse the repository at this point in the history
  • Loading branch information
rkaminsk committed Feb 15, 2024
1 parent 9ce83a7 commit 95795ca
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions examples/logistics/encoding.lp
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,36 @@ at(A,L) :- 'at(A,L), not -at(A,L), _airplane(A).
at(P,L) :- 'at(P,L), not -at(P,L), _package(P).
-at(P,L) :- at(P,M), _location(L), L!=M, _package(P).

%%%%%%%%%%% Loading objects / unloading objects
%%%%%%%%%%% Loading objects

loaded(P) :- in(P,V).
{ load(P,V) } :- _package(P), 'at(P,L), _vehicle(V), 'at(V,L), not 'in(P,V), not 'loaded(P).
:- { load(P,V) } > 1, _package(P).

can_load(P,V) :- _package(P), 'at(P,L), _vehicle(V), 'at(V,L), not 'in(P,V), not 'loaded(P).
in(P,V) :- load(P,V).
loaded(P) :- in(P,V).

%%%%%%%%%%% Unloading objects

can_unload(P,V) :- _package(P), 'in(P,V).
{ unload(P,V) } :- _package(P), 'in(P,V).

% Frame axiom for "in"
in(P,V) :- 'in(P,V), not unload(P,V).

%%%%%%%%%%% Moving vehicles

can_move(T,L) :- _truck(T), 'at(T,M), _in_city(M,C), _in_city(L,C), L!=M.
can_move(A,L) :- _airplane(A), 'at(A,M), _airport(L), L!=M.
at(V,L) :- move(V,L).
moved(V) :- move(V,_).
{ move(T,L) } :- _truck(T), 'at(T,M), _in_city(M,C), _in_city(L,C), L!=M.
{ move(A,L) } :- _airplane(A), 'at(A,M), _airport(L), L!=M.
:- { move(V,L) } > 1, _vehicle(V).

{load(P,V):can_load(P,V); unload(P,V): can_unload(P,V) } :- _vehicle(V).
cargo(V) :- load(P,V).
cargo(V) :- unload(P,V).
0 {move(V,L): can_move(V,L)} 1 :- _vehicle(V), not cargo(V).
:- move(V,L), cargo(V).

at(V,L) :- move(V,L).
moved(V) :- move(V,_).

#program always.
%:- at(O,L), at(O,M), L!=M.

at(P,L) :- in(P,V), at(V,L).

% Control rule: if we move a vehicle, it keeps unmoved until some cargo is done
Expand All @@ -53,4 +57,10 @@ at(P,L) :- in(P,V), at(V,L).
:- _goal_at(P,L), not at(P,L), not _testing.
:- _goal_at(P,L), loaded(P), not _testing.


#defined in/3.
#defined load/3.
#defined loaded/2.
#defined move/3.
#defined moved/2.
#defined testing/1.
#defined unload/3.

0 comments on commit 95795ca

Please sign in to comment.