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, 'b, 'c, 'd, 'e)
t
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 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 -> pred:'b Sette.t -> succ:'b Sette.t -> 'f) ->
('b -> 'd -> pred:'a array -> succ:'a array -> '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 predecssor 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 : ('a, 'b, 'c, 'd, 'e) t -> 'a -> 'a list
val topological_sort_multi : 'a -> 'b -> ('a, 'b, 'c, 'd, 'e) t -> 'a Sette.t -> 'a list
val topological_sort_filter_multi : 'a ->
'b -> ('a, 'b, 'c, 'd, 'e) t -> ('b -> bool) -> 'a Sette.t -> 'a list
f hedge
succ
tells whether the given dependency should be taken into account or
not in the sort.val reachable : ('a, 'b, 'c, 'd, 'e) t -> 'a -> 'a Sette.t * 'b Sette.t
val reachable_multi : 'a ->
'b -> ('a, 'b, 'c, 'd, 'e) t -> 'a Sette.t -> 'a Sette.t * 'b Sette.t
val reachable_filter_multi : 'a ->
'b ->
('a, 'b, 'c, 'd, 'e) t ->
('b -> bool) -> 'a Sette.t -> 'a Sette.t * 'b Sette.t
val cfc : ('a, 'b, 'c, 'd, 'e) t -> 'a -> 'a 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 -> ('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 cfc_filter_multi : 'a ->
'b ->
('a, 'b, 'c, 'd, 'e) t -> ('b -> bool) -> 'a Sette.t -> 'a list list
val cfc_priority_multi : 'a ->
'b ->
('a, 'b, 'c, 'd, 'e) t -> ('b -> int) -> 'a Sette.t -> 'a list list
The priority function p:'b -> int
filters out hyperedges b
such that
p b<0
, and explores first hyperedges b
with the highest priority.
val scfc : ('a, 'b, 'c, 'd, 'e) t -> 'a -> 'a 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 -> ('a, 'b, 'c, 'd, 'e) t -> 'a Sette.t -> 'a Ilist.t
val scfc_filter_multi : 'a ->
'b ->
('a, 'b, 'c, 'd, 'e) t -> ('b -> bool) -> 'a Sette.t -> 'a Ilist.t
val scfc_priority_multi : 'a ->
'b ->
('a, 'b, 'c, 'd, 'e) t -> ('b -> int) -> '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 : ?titlestyle:string ->
?vertexstyle:string ->
?hedgestyle: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 the provided escaped
(see
below) 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 ~titlestyle="shape=ellipse,style=bold,style=filled,fontsize=20"
~vertexstyle="shape=box,fontsize=12" ~hedgestyle="shape=ellipse,fontsize=12"
~title="" ...
.
val escaped : ?linebreak:char -> string -> string
linebreak
(default
'\n'
). When used for DOT output, '\l'
and '\r'
produces respectively
left or righjt justified lines, instead of center justified lines.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: