Article View: comp.lang.prolog
Article #2368Representing graphs?
From: Ari Juhani Huttunen
Date: Sun, 23 Jun 1991 00:11
Date: Sun, 23 Jun 1991 00:11
43 lines
1514 bytes
1514 bytes
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.
Technical Details
Message-ID:
<ARI.HUTTUNEN.91Jun23021130@wonderwoman.hut.fi>Path:
arc1-ca.pugleaf.net!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.HuttunenShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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: <ARI.HUTTUNEN.91Jun23021130@wonderwoman.hut.fi> 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