Module Bigraph.Sparse
type t
The type of Boolean matrices. Only true values are stored in the matrix as row-column pairs. For example adding value
"(2, 1)"
means that the second element in the third row of the matrix is true.
Basic operations
val make : int -> int -> t
make r c
returns an empty matrix withr
rows andc
columns.
val to_string : t -> string
Return the string representation of a matrix.
"0" = false
and"1" = true
.
val pp : Stdlib.Format.formatter -> t -> unit
Pretty printer
val apply_rows : Iso.t -> t -> t
apply_rows iso m
returns matrixm
with the rows reordered according toiso
. The domain ofiso
is assumed to be{0,...,r}
withr
the number of rows ofm
.
val apply_cols : Iso.t -> t -> t
Same as
apply_rows
but on columns.
val apply : Iso.t -> t -> t
Same as
apply_rows
but on both rows and columns. The matrix is assumed square.
val parse_vectors : int list list -> int -> t
parse_vectors l r
parses listl
of column vectors to a matrix withr
rows andc
columns, withc
the length ofl
. Example:parse_vectors [[0;1;2];[1;2]] 4
is parsed to the following 4x2 matrix10 11 11 00
val parse_string : int -> int -> int -> Stdlib.String.t list -> (t * t) * (t * t)
parse_string r n s rows
parses listrows
of rows encoded as'0''1'
strings. The resulting matrix is split as follows:+-----------+-----------+ | | | | a | b | | | | +-----------+-----------+ | | | | c | d | | | | +-----------+-----------+
with
a: r * n
,b: r * s
,c: n * n
, andd: n * s
.- raises Invalid_argument
when the input strings are not in the correct format.
val dom : t -> IntSet.t
Return the domain of a matrix, that is the set of rows having at least one
true
element.
val codom : t -> IntSet.t
Return the codomain of a matrix, that is the set of columns having at least one
true
element.
val iter : (int -> int -> unit) -> t -> unit
Same as
Map.iter
.
val fold : (int -> int -> 'a -> 'a) -> t -> 'a -> 'a
Fold iterating over every pair
(i, j)
defined by the map.
val fold_c : (int -> IntSet.t -> 'a -> 'a) -> t -> 'a -> 'a
Dual of
Sparse.fold_r
.
val add : int -> int -> t -> t
add i j m
adds element(i,j)
. Argumentsi
andj
are assumed to be valid indexes.
val add_list : t -> (int * int) list -> t
Add a list of elements as in
Sparse.add
.
val entries : t -> int
Return the number of
true
elements in a matrix. This is equivalent to the number of edges in a graph.
val edges : t -> (int * int) list
Return the representation of a binary matrix as a list of edges.
val mem : t -> int -> int -> bool
mem m i j
returnstrue
if edge(i,j)
is defined bym
.
Matrix operations
val row : int -> t
row n
returns a row vector ofn
true
elements.
val col : int -> t
col n
returns a column vector ofn
true
elements.
val diag : int -> t
diag n
returns a square matrix of sizen
with alltrue
elements on the diagonal.
val tens : t -> t -> t
tens a b
returns the tensor product of matricesa
andb
. The tensor product is defined according to the following schema:+-----------+-----------+ | | | | a | | | | | +-----------+-----------+ | | | | | b | | | | +-----------+-----------+
val append : t -> t -> t
append a b
appends matrixb
to the right of matrixa
. The two matrices are assumed to have the same number of rows. This operation is described by the diagram below:+-----------+-----------+ | | | | a | b | | | | +-----------+-----------+
val stack : t -> t -> t
stack a b
stacks matrixa
on top of matrixb
. The two matrices are assumed to have the same number of columns. This operation is described by the following diagram:+-----------+ | | | a | | | +-----------+ | | | b | | | +-----------+
val glue : t -> t -> t -> t -> t
tens a b c d
computes the matrix defined below:+-----------+-----------+ | | | | a | b | | | | +-----------+-----------+ | | | | c | d | | | | +-----------+-----------+
Graph operations
val siblings : t -> int -> IntSet.t
siblings i m
returns the set of siblings ofi
. Two nodes are siblings if they share a parent.
val partners : t -> int -> IntSet.t
Dual of
Sparse.siblings
.
val descendants : t -> int -> IntSet.t
descendants m i
returns the set of nodes reachable fromi
in graphm
.
val connected_comps : t -> IntSet.t list
Return a list of the connected components of an undirected graph.
val levels : t -> IntSet.t list
levels m
returns the level decomposition ofm
. Each level is obtained by iteratively removing the leaves in the graph until no nodes are left. Argumentm
is assumed square.
val row_eq : t -> IntSet.t -> IntSet.t
row_eq m js
computes a set of rows such that the union of their children set is equal tojs
.
val col_eq : t -> IntSet.t -> IntSet.t
Dual of
Sparse.row_eq
.