module SHGraph:Oriented hypergraphssig
..end
This module provides an abstract datatypes and functions for manipulating hypergraphs, that is, graphs where edges relates potentially more than 2 vertices. The considered hypergraphs are oriented: one distinguishes for a vertex incoming and outgoing hyperedges, and for an hyperedge incoming (or origin) and outgoing (or destination) vertices.
Origin and destination vertices of an hyperedge are ordered (by using arrays), in contrast with incoming and outgoing hyperedges of a vertex.
A possible use of such hypergraphs is the representation of a (fixpoint) equation system, where the unknown are the vertices and the functions the hyperedges, taking a vector of unknowns as arguments and delivering a vector of results.
A last note about the notion of connectivity, which is relevant for operations
like depth-first-search, reachability and connex components notions. A
destination vertex of an hyperedge is considered as reachable from an origin
vertex through this hyperedge only if all origin vertices are reachable.
type
'a
priority =
| |
Filter of |
|||
| |
Priority of |
(* | Filtering or priority function (used by SHGraph.topological_sort , SHGraph.cfc ,
SHGraph.scfc , SHGraph.topological_sort_multi , SHGraph.cfc_multi , SHGraph.scfc_multi ).
| *) |
type ('a, 'b)
compare = {
|
hashv : |
|
hashh : |
|
comparev : |
|
compareh : |
type ('a, 'b)
vertex_n = {
|
attrvertex : |
|
mutable predhedge : |
|
mutable succhedge : |
type ('a, 'b)
hedge_n = {
|
attrhedge : |
|
predvertex : |
|
succvertex : |
type ('a, 'b, 'c, 'd, 'e)
graph = {
|
vertex : |
|
hedge : |
|
info : |
val stdcompare : ('a, 'b) compare
type('a, 'b, 'c, 'd, 'e)
t =('a, 'b, 'c, 'd, 'e) graph
val create : int -> 'a -> ('b, 'c, 'd, 'e, 'a) t
create n data
creates an hypergraph, using n
for the initial size
of internal hashtables, and data
for the user informationval clear : ('a, 'b, 'c, 'd, 'e) t -> unit
val is_empty : ('a, 'b, 'c, 'd, 'e) t -> bool
val size_vertex : ('a, 'b, 'c, 'd, 'e) t -> int
val size_hedge : ('a, 'b, 'c, 'd, 'e) t -> int
val size_edgevh : ('a, 'b, 'c, 'd, 'e) t -> int
val size_edgehv : ('a, 'b, 'c, 'd, 'e) t -> int
val size : ('a, 'b, 'c, 'd, 'e) t -> int * int * int * int
size graph
returns (nbvertex,nbhedge,nbedgevh,nbedgehv)
val attrvertex : ('a, 'b, 'c, 'd, 'e) t -> 'a -> 'c
attrvertex graph vertex
returns the information associated to the
vertex vertex
val attrhedge : ('a, 'b, 'c, 'd, 'e) t -> 'b -> 'd
attrhedge graph hedge
returns the information associated to the
hyperedge hedge
val info : ('a, 'b, 'c, 'd, 'e) t -> 'e
info g
returns the user-information attached to the graph g
val is_vertex : ('a, 'b, 'c, 'd, 'e) t -> 'a -> bool
val is_hedge : ('a, 'b, 'c, 'd, 'e) t -> 'b -> bool
val succhedge : ('a, 'b, 'c, 'd, 'e) t -> 'a -> 'b Sette.t
val predhedge : ('a, 'b, 'c, 'd, 'e) t -> 'a -> 'b Sette.t
val succvertex : ('a, 'b, 'c, 'd, 'e) t -> 'b -> 'a array
val predvertex : ('a, 'b, 'c, 'd, 'e) t -> 'b -> 'a array
val succ_vertex : ('a, 'b, 'c, 'd, 'e) t -> 'a -> 'a Sette.t
val pred_vertex : ('a, 'b, 'c, 'd, 'e) t -> 'a -> 'a Sette.t
val add_vertex : ('a, 'b, 'c, 'd, 'e) t -> 'a -> 'c -> unit
val add_hedge : ('a, 'b, 'c, 'd, 'e) t ->
'b -> 'd -> pred:'a array -> succ:'a array -> unit
Failure
exception is raised.val replace_attrvertex : ('a, 'b, 'c, 'd, 'e) t -> 'a -> 'c -> unit
val replace_attrhedge : ('a, 'b, 'c, 'd, 'e) t -> 'b -> 'd -> unit
val remove_vertex : ('a, 'b, 'c, 'd, 'e) t -> 'a -> unit
val remove_hedge : ('a, 'b, 'c, 'd, 'e) t -> 'b -> unit
val iter_vertex : ('a, 'b, 'c, 'd, 'e) t ->
('a -> 'c -> pred:'b Sette.t -> succ:'b Sette.t -> unit) -> unit
f vertex attrvertex succhedges predhedges
to all
vertices of the graph. succhedges
(resp. predhedges
) is the set of
successor (resp. predecessor) hyperedges of the vertexval iter_hedge : ('a, 'b, 'c, 'd, 'e) t ->
('b -> 'd -> pred:'a array -> succ:'a array -> unit) -> unit
f hedge attrhedge succvertices predvertices
to
all hyperedges of the graph. succvertices
(resp. predvertices
) is the
set of successor (resp. predecessor) vertices of the hyperedgefold
versions of the previous functions.val fold_vertex : ('a, 'b, 'c, 'd, 'e) t ->
('a -> 'c -> pred:'b Sette.t -> succ:'b Sette.t -> 'f -> 'f) -> 'f -> 'f
val fold_hedge : ('a, 'b, 'c, 'd, 'e) t ->
('b -> 'd -> pred:'a array -> succ:'a array -> 'f -> 'f) -> 'f -> 'f
map
versions of the previous functions.val map : ('a, 'b, 'c, 'd, 'e) t ->
('a -> 'c -> 'f) ->
('b -> 'd -> 'g) -> ('e -> 'h) -> ('a, 'b, 'f, 'g, 'h) t
val copy : ('a -> 'b -> 'c) ->
('d -> 'e -> 'f) ->
('g -> 'h) ->
('a, 'd, 'b, 'e, 'g) t -> ('a, 'd, 'c, 'f, 'h) t
val transpose : ('a -> 'b -> 'c) ->
('d -> 'e -> 'f) ->
('g -> 'h) ->
('a, 'd, 'b, 'e, 'g) t -> ('a, 'd, 'c, 'f, 'h) t
copy
, but hyperedges are reversed: successor vertices
and predecessor vertices are exchanged.val min : ('a, 'b, 'c, 'd, 'e) t -> 'a Sette.t
val max : ('a, 'b, 'c, 'd, 'e) t -> 'a Sette.t
val topological_sort : ?priority:'a priority ->
('b, 'a, 'c, 'd, 'e) t -> 'b -> 'b list
val topological_sort_multi : 'a ->
'b ->
?priority:'b priority ->
('a, 'b, 'c, 'd, 'e) t -> 'a Sette.t -> 'a list
val reachable : ?filter:('a -> bool) ->
('b, 'a, 'c, 'd, 'e) t -> 'b -> 'b Sette.t * 'a Sette.t
val reachable_multi : 'a ->
'b ->
?filter:('b -> bool) ->
('a, 'b, 'c, 'd, 'e) t -> 'a Sette.t -> 'a Sette.t * 'b Sette.t
val cfc : ?priority:'a priority ->
('b, 'a, 'c, 'd, 'e) t -> 'b -> 'b list list
cfc graph vertex
returns a decomposition of the graph. The exploration
is done from the initial vertex vertex
, and only reachable vertices are
included in the result. The result has the structure [comp1 comp2 comp3
...]
where each component is defined by a list of vertices. The ordering
of component correspond to a linearization of the partial order between the
components.
val cfc_multi : 'a ->
'b ->
?priority:'b priority ->
('a, 'b, 'c, 'd, 'e) t -> 'a Sette.t -> 'a list list
cfc dummy_vertex dummy_hedge graph setvertices
returns a decomposition of
the graph, explored from the set of initial vertices
setvertices
. dummy_vertex
and dummy_hedge
are resp. unused vertex and
hyperedge identifiers.
val scfc : ?priority:'a priority ->
('b, 'a, 'c, 'd, 'e) t -> 'b -> 'b Ilist.t
scfc graph vertex
returns a decomposition of the graph. The exploration
is done from the initial vertex vertex
, and only reachable vertices are
included in the result. The result has the structure [comp1 comp2 comp3
...]
where each component is in turn decomposed into components.
val scfc_multi : 'a ->
'b ->
?priority:'b priority ->
('a, 'b, 'c, 'd, 'e) t -> 'a Sette.t -> 'a Ilist.t
val print : (Format.formatter -> 'a -> unit) ->
(Format.formatter -> 'b -> unit) ->
(Format.formatter -> 'c -> unit) ->
(Format.formatter -> 'd -> unit) ->
(Format.formatter -> 'e -> unit) ->
Format.formatter -> ('a, 'b, 'c, 'd, 'e) t -> unit
'a
), hedges ('b
), vertex
attributes ('c
), hedge attributes ('d
), and the user information
('e
).val print_dot : ?style:string ->
?titlestyle:string ->
?vertexstyle:string ->
?hedgestyle:string ->
?fvertexstyle:('a -> string) ->
?fhedgestyle:('b -> string) ->
?title:string ->
(Format.formatter -> 'a -> unit) ->
(Format.formatter -> 'b -> unit) ->
(Format.formatter -> 'a -> 'c -> unit) ->
(Format.formatter -> 'b -> 'd -> unit) ->
Format.formatter -> ('a, 'b, 'c, 'd, 'e) t -> unit
BE CAUTIOUS. as the DOT files vertices and hedges are actually nodes, the user should take care to avoid name conflicts between vertex and hedge names.
BE CAUTIOUS: the output of the function will be enclosed bewteen
quotes. If ever the output contains line break, or other special
characters, it should be escaped. A possible scheme to do this is to
first output to Format.str_formatter
with a standard printing function,
then to escape the resulting string and to output the result. This gives
something like:
print_attrvertex Format.str_formatter vertex attr;
Format.pp_print_string fmt (String.escaped (Format.flush_str_formatter
()));
.
Concerning the escape function, you may use String.escaped
, which will
produce center justified line breaks, or Print.escaped
which allows
also to choose between center, left and right justified lines.
The optional arguments allows to customize the style. The default setting corresponds to:
print_dot ~style="ranksep=0.1; size=\"7,10\";" ~titlestyle="shape=ellipse,style=bold,style=filled,fontsize=20"
~vertexstyle="shape=box,fontsize=12" ~hedgestyle="shape=ellipse,fontsize=12"
~title="" ...
.
module type T =sig
..end
XXX_multi
which does not need any more a dummy
value of type vertex
(resp. hedge
).module type S =sig
..end
module Make:
module Compare:sig
..end