Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!news.funet.fi!funic!nntp.hut.fi!nntp!Ari.Huttunen From: Ari.Huttunen@hut.fi (Ari Juhani Huttunen) Newsgroups: comp.lang.prolog Subject: Representing graphs? Message-ID: Date: 23 Jun 91 00:11:30 GMT Sender: usenet@nntp.hut.fi (Usenet pseudouser id) Distribution: comp Organization: Helsinki University of Technology, Finland Lines: 43 Nntp-Posting-Host: wonderwoman.hut.fi I would like to know if this is a good way to represent graphs or an ugly hack. The idea is to have fast access to the current location in the graph and it's near neighbours. And since SB-prolog doesn't encourage asserting and the graph has to be created while running... graph(X) :- X = vertice(x,[A,B,C]), A = vertice(a,[D,X]), D = vertice(d,[A]), B = vertice(b,[X,G]), C = vertice(c,[X,E]), E = vertice(e,[C,F]), G = vertice(g,[F,B]), F = vertice(f,[E,G]). test :- graph(X), writevertice(X), move(X,Y), writevertice(Y), move(Y,Z), writevertice(Z). move(vertice(_,[Y|Ys]),Y). writevertice(vertice(Name,ConnectedTo)) :- names(ConnectedTo,Names), write(Name), write('-->'), writelist(Names), nl. names([vertice(Name,_)|Vertices],[Name|Names]) :- names(Vertices,Names). names([],[]). writelist([X|Xs]) :- write(X), writelist(Xs). writelist([]). -- Ari Huttunen puhelin: 90-7285944 T{m{ tila vuokrattavana.