Prolog Special Path Finding

Multi tool use
Multi tool use


Prolog Special Path Finding



I'm new to Prolog and I'm struggling doing a task. So, we have 2 types of edges, one for car and one for bus. They are symmetrical. There is no distance, just direction. For example:


car(berlin, munich).
car(berlin, stuttgart).
car(mainz, munich).

bus(augsburg, berlin).
bus(köln, dortmund).
bus(dortmund, stuttgart).



My task is to find if there is a path between a 'Start' and 'End Location', which has been resolved but now comes the "hard" part. We have to find a path that changes max ONE time between bus and car. Also if I'm in a bus I have to get to my end location just within buses or change one time the bus with a car(of course we can then change between cars, but not back to bus).



Also I've found a way to find the path but just for bus paths, not cars and it looks like this.


isPath(from, to) :- isPath(from, to, ).
isPath(from, to, _) :- bus(from, to).
isPath(from, to, visited) :-
+ member(from, visited),
bus(from, X),
isPath(X, to, [from|visited]).



I'm sure it is not that hard, I just have to save somehow the fact that the bus/car has been changed with the other one.



Can someone help me?



Thanks!





Variables in Prolog must begin with a capital letter (or _ if they're anonymous). To solve your problem, you'll need to include an argument that indicates whether a change between bus and car has occurred, or include that information as part of your path and check for it using member/2.
– lurker
Jul 2 at 15:18



_


member/2





Can you give me an example? I don't understand how to include something like this.
– Razor
Jul 2 at 15:28









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

u44Yl 614usrwz0Ad70
MsVaATuxV9QUznRbNJtS

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications