Commit 55341313 authored by POTTIER Francois's avatar POTTIER Francois

Improved the manner in which [Astar] reports paths.

The identity of the source node is included, which is
useful when there are multiple source nodes.
parent fceefd11
......@@ -59,6 +59,21 @@ end) = struct
(* Nodes with low priorities are dealt with first. *)
type priority = cost
(* Paths back to a source (visible by the user). *)
type path =
| Edge of G.label * path
| Source of G.node
let rec follow labels path =
match path with
| Source node ->
node, labels
| Edge (label, path) ->
follow (label :: labels) path
let reverse path =
follow [] path
type inode = {
(* Graph node associated with this internal record. *)
this: G.node;
......@@ -67,7 +82,7 @@ end) = struct
(* Estimated cost of the best path from this node to a goal node. (hhat) *)
estimate: cost;
(* Best known path from a source node to this node. *)
mutable path: G.label list;
mutable path: path;
(* Previous node on doubly linked priority list *)
mutable prev: inode;
(* Next node on doubly linked priority list *)
......@@ -210,7 +225,7 @@ end) = struct
this = node;
cost = 0;
estimate = estimate node;
path = [];
path = Source node;
prev = inode;
next = inode;
priority = -1
......@@ -268,7 +283,7 @@ end) = struct
assert (0 <= new_fhat); (* failure means overflow *)
P.add_or_decrease ison new_fhat;
ison.cost <- new_cost;
ison.path <- label :: inode.path
ison.path <- Edge (label, inode.path)
end
with Not_found ->
......@@ -280,7 +295,7 @@ end) = struct
this = son;
cost = new_cost;
estimate = estimate son;
path = label :: inode.path;
path = Edge (label, inode.path);
prev = ison;
next = ison;
priority = -1
......
......@@ -30,10 +30,22 @@ module Make (G : sig
end) : sig
(* A path (from a target node back to some source node) is described by a
series of labels and ends in a source node. *)
type path =
| Edge of G.label * path
| Source of G.node
(* A path can also be presented as a pair of a source node and a list of
labels, which describe the edges from the source node to a target node. *)
val reverse: path -> G.node * G.label list
(* Search. Newly discovered nodes are presented to the user, in order of
increasing distance from the source nodes, by invoking the user-supplied
function [f]. At the end, a mapping of nodes to distances to the source
nodes and a mapping of nodes to shortest paths are returned. *)
val search: (G.node * G.label list -> unit) -> (G.node -> int) * (G.node -> G.label list)
val search: (G.node * path -> unit) -> (G.node -> int) * (G.node -> path)
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment