Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: Dijkstra Shortest Path

From: tomc:darkwing:uoregon at: 1-Jan-2002 15:00

Hi Allen, couldn't resist. rebol[title: "call dijk"] ; load/include a graph object and two functions, init-graph and dijk do ; which will also include a heap from the same place comment{ expects data as an edge-list with weights in file format: node1 node2 weight1_2 newline ... ex: s u 10 s x 5 u v 1 u x 2 x u 3 x v 9 x y 2 v y 4 y v 6 y s 7 } ; read data into a graph g: init-graph read/lines ; pick a start node at random start: pick g/nodes random (length? g/nodes) ;;; run Dijkstra's dijk g start/id ; see what the shortest distance from the start to each node is ; also be able to recover the path by stepping to the previous node print ["node-id distance previous-id"] foreach n g/nodes[print[n/id tab n/distance tab n/previous/id]] print "" On Thu, 27 Dec 2001, Allen Kamp wrote: