feat: add a filter
This commit is contained in:
parent
e611b1eb00
commit
89139ffe3c
2 changed files with 12 additions and 3 deletions
|
|
@ -2,10 +2,16 @@ open Graph
|
|||
|
||||
let child_nodes (gr : 'a graph) (a: id) = List.map (fun x -> x.tgt) (out_arcs gr a)
|
||||
|
||||
let find_path (gr: 'a graph) (begin_node: id) (end_node: id) =
|
||||
let find_path (gr: 'a graph) (begin_node: id) (end_node: id) (filter: 'a arc -> bool)=
|
||||
let rec find_way s acu =
|
||||
let s_child = child_nodes gr s in
|
||||
|
||||
let arc x1 x2 =
|
||||
match find_arc gr x1 x2 with
|
||||
| Some x -> x
|
||||
| None -> raise Not_found
|
||||
in
|
||||
|
||||
if s == end_node then
|
||||
acu
|
||||
else
|
||||
|
|
@ -15,7 +21,10 @@ let find_path (gr: 'a graph) (begin_node: id) (end_node: id) =
|
|||
| [] -> raise Not_found
|
||||
| x::rest ->
|
||||
try
|
||||
find_way x (acu@[x])
|
||||
if (filter (arc s x)) then
|
||||
find_way x (acu@[x])
|
||||
else
|
||||
fp rest
|
||||
with
|
||||
| Not_found -> fp rest
|
||||
in fp next_rec
|
||||
|
|
|
|||
|
|
@ -4,4 +4,4 @@ open Graph
|
|||
val child_nodes: 'a graph -> id -> id list
|
||||
|
||||
(* search path between 2 node and return the path : a list of node *)
|
||||
val find_path: 'a graph -> id -> id -> id list
|
||||
val find_path: 'a graph -> id -> id -> ('a arc -> bool) -> id list
|
||||
Loading…
Reference in a new issue