Prolog questions

EuniceChen

Junior Member
May 22, 2012
1
0
0
Hi,

I'm a newbie in SWI-Prolog. After consulting many references it is still unclear to me why my code does not work as I expected. Any comment would be greatly appreciated.

My problem:
I defined an undirected graph g([v1, v2, v3], [e(v1, v3), e(v2, v3)]), that is, there are vertices v1, v2, v3 and edge e(v1, v3) and e(v2, v3). I would like to test if the following pattern exists in the graph: an undirected edge between v1 and v3, another between v2 and v3; no edge between v2 and v3.

My code:

g([v1, v2, v3], [e(v1, v3), e(v2, v3)]).
match_p(g(VS, ES), [VT1, VT2, VT3]).
match_p(g(VS, ES), [VT1, VT2, VT3]) :- member(e(VT1, VT3), ES), member(e(VT2, VT3), ES), not(member(e(VT1, VT2), ES)).

I queried match_p(g(V, E), V). and the program does not terminate. However I expected the answer to be true. Thanks.

Eunice