0

Previously I wrote the predicate, reach(Arrivals,Departure) to find a list of names of departure points from which I can get to a given point arrivals. Now, how can I make sure that the total cost from the calculated route does not exceed a given limit, for example now it`s work like this:

?-reach(krum, Departure).
Answer: Departure = [uzhorod].

in this example, the total cost of the route = 6000, how can it be implemented if 7000 is entered, it is false and if 6000 is true.

This is my facts:

trip(01, kuiv, odessa, 1500).
trip(02, kuiv, lviv, 700).
trip(08, lviv, zaporizhya, 700).
trip(03, uzhorod, krum, 6000).
trip(04, vunohradiv, odessa, 2540).
trip(05, ternopil, kuiv, 3800).
trip(06, zaporizhya, donetsk, 900).
trip(07, lytsk, mariupol, 7500).

trip(Id, Departure, Arrivals, Price)

This is my code:

reachable(D, D, _).
reachable(Departure, Arrival, Visited) :-
    trip(_, Departure, Point, _),
    \+ member(Point, Visited),
    reachable(Point, Arrival, [Point|Visited]).
reachable(Departure, Arrival) :-
    reachable(Departure, Arrival, [Departure]).


reach(Arrival, Departures) :-
    setof(
        Departure,
        reachable(Departure, Arrival),
        Departures
    ).
Mashka
  • 35
  • 4
  • 1
    This is hardly an original problem. You could Google for similar code and hints: E.g. https://www.google.com/search?q=prolog+path+cost+limit – brebs Nov 17 '22 at 22:11

0 Answers0