I have an example problem in Answer Set Programming (ASP). When I try to make the equivalent code in Prolog, I keep getting stuck with the not
blocked.
This is the ASP code:
road(berlin,potsdam).
road(potsdam,werder).
road(werder,brandenburg).
road(X,Y) :- road(Y,X).
blocked(werder,brandenburg).
route(X,Y) :- road(X,Y), not blocked(X,Y).
route(X,Y) :- route(X,Z), route(Z,Y).
drive(X) :- route(berlin,X).
#show drive/1
The answer is: drive(potsdam)
, drive(werder)
, drive(berlin)
.
In Prolog, I initially thought it would be as simple as changing the not
to \+
. When I query drive(X).
, it recursively generates the X = potsdam
answer. I know that Prolog and ASP work differently but I just can't figure it out.