prolog - Error 1, Backtrack Stack Full -


im trying write program in prolog determine if there way place place. these relations:

road(ny,florida). road(washington,florida). road(washington,texas). road(vegas,california). 

i want write: there_is_way(x,y) determine if there way or not. example:

?- road(florida,ny). no ?-there_is_way(florida,ny). yes 

this code:

there_is_way(x,y):- road(x,y);                         road(y,x);                         road(x,z),road(z,y),x\=y;                         road(x,z),road(y,z),x\=y;                         road(z,x),road(z,y),x\=y;                         road(z,x),road(y,z),x\=y. there_is_way(x,y):-                         road(z,y),there_is_way(x,z). there_is_way(x,y):-                         road(y,z),there_is_way(x,z). 

but unfortunately "error 1, backtrack stack full".

someone?

thank you

first, need symmetric definition:

:- meta_predicate symm(2, ?,  ?).  symm(p_2, a, b) :-    call(p_2, a, b). symm(p_2, a, b) :-    call(p_2, b, a). 

now, using closure0/3

there_is_way(a, b) :-    closure0(symm(road), a, b). 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -