package fungi
A pure functional graph library
Install
Dune Dependency
Authors
Maintainers
Sources
0.1.4.tar.gz
md5=59536953fb6d9766c68e9db89799112a
sha512=4b26e4a952cf73ebf30f92c0b348da1ca1521d82c120c052bf90a0878dbbacbe700ce81cb5c7ca135db6121cd5f2a1d5a4b9f4b14561335bb9f66f9e4b07b2ea
Description
A graph library based on functional adjacency list with some common graph algorithms implemented and a fibonacci heap.
README
Fungi (Fun-ctional G-raph Implementation)
This is an adjacency set based graph implementation with algorithms written in a functional style. It supports various path, flow, matching and scc algorithms with more to be added in the future. Some data structures will also be added to support the graph (Heap (done), LC-tree, UnionFind...etc).
Usage
to use the ocaml implementation
open Fungi;;
(* create a graph with string nodes and float edges *)
module SGraph = Graph.MakeGraph(struct
type t = string
type edge = float
let compare= String.compare
end);;
(* empty graph *)
let s = SGraph.empty;;
(* add nodes *)
let s' = SGraph.add "A" s;;
let s'' = SGraph.add "B" s';;
(* add edge without weight *)
let s'' = SGraph.add_edge "B" "A" s'';;
(* add directed edges (with weights on them) *)
let s'' = SGraph.add_weight 2. "A" "B" s'';;
(* add bidirectional weighted edges (with weights on them) *)
let s'' = SGraph.add_weight 2. "A" "B" s'';;
(* Use dijkstra to find the shortest path - we need the AST of our edge type
to compute paths (i.e Float.sub, Float.min ... etc) *)
module SPath = SGraph.Path.Compute(Graph.Biject(Float));;
let path = SPath.dijkstra "A" "B" s'';;
(* export graph to dot - build a serializer *)
module Ser = struct
let string_of_elt = Fun.id
let string_of_wgt = (Float.to_string)
let elt_of_string = Fun.id
let wgt_of_string = Float.of_string
end;;
module SGSer = SGraph.Serialize (Ser);;
(* global attributes *)
let gt = SGSer.StyleTbl.create 1;;
(* per edge style attributes *)
let et = SGSer.AttrbTbl.create 1;;
(* per node style attributes *)
let nt = SGSer.AttrbTbl.create 1;;
(* add some attributes *)
SGSer.StyleTbl.add gt "rankdir" "LR";;
SGSer.StyleTbl.add st "color" "green";;
(* create a sequence of strings for the dot fil *)
let z = SGSer.to_dot ~dir:true "toposort" gt nt et s'';;
(* print the graph dot sequence *)
z |> Seq.concat |> Seq.iter (fun s -> Format.printf "%s" (s ())) ;;
Dev Dependencies (5)
-
odoc
with-doc
-
core_bench
with-test
-
qcheck-alcotest
with-test
-
qcheck-core
with-test
-
alcotest
with-test
Used by
None
Conflicts
None
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page