I'm writing a program about roads...
For example I have road(1, a, b, 2) (road no. 1 from a to b taking up 2 units of fuel). The point is if I have road(1, a, b, 2) I must also have road(1, b, a, 2) but if I use one I cannot use another, otherwise the program will loop.
What can I write so that if the program uses this one fact, it cannot use another?
I'm not sure I understood you, but maybe -
direct_road(1,a,b,2).
direct_road(1,b,a,2).
road(X,A,B,Y) :-
direct_road(X,A,B,Y),
direct_road(X,B,A,Y).
You can use one rule to capture the symmetry, but put it after all other rules with same name and arity. If there exist any solutions for whatever your query is, they will be shown before getting into any sort of infinite loop.
road(R,A,B,F) :- road(R,B,A,F).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With