1Graph::AdjacencyMatrix(U3s)er Contributed Perl DocumentatGiroanph::AdjacencyMatrix(3)
2
3
4

NAME

6       Graph::AdjacencyMatrix - create and query the adjacency matrix of graph
7       G
8

SYNOPSIS

10           use Graph::AdjacencyMatrix;
11           use Graph::Directed; # or Undirected
12
13           my $g  = Graph::Directed->new;
14           $g->add_...(); # build $g
15
16           my $am = Graph::AdjacencyMatrix->new($g);
17           $am->is_adjacent($u, $v)
18
19           my $am = Graph::AdjacencyMatrix->new($g, distance_matrix => 1);
20           $am->distance($u, $v)
21
22           my $am = Graph::AdjacencyMatrix->new($g, attribute_name => 'length');
23           $am->distance($u, $v)
24
25           my $am = Graph::AdjacencyMatrix->new($g, ...);
26           my @V  = $am->vertices();
27
28           $g = Graph->new(multiedged => 1);
29           $g->add_...(); # build $g
30           $am = Graph::AdjacencyMatrix->new($g, distance_matrix => 1);
31           $am->distance($u, $v) # returns hash-ref of ID => distance
32

DESCRIPTION

34       You can use "Graph::AdjacencyMatrix" to compute the adjacency matrix
35       and optionally also the distance matrix of a graph, and after that
36       query the adjacencyness between vertices by using the is_adjacent()
37       method, or query the distance between vertices by using the distance()
38       method.
39
40       By default the edge attribute used for distance is "w", but you can
41       change that in new(), see below.
42
43       If you modify the graph after creating the adjacency matrix of it, the
44       adjacency matrix and the distance matrix may become invalid.
45

Methods

47   Class Methods
48       new($g)
49           Construct the adjacency matrix of the graph $g.
50
51       new($g, options)
52           Construct the adjacency matrix of the graph $g with options as a
53           hash.  The known options are
54
55           distance_matrix => boolean
56                   By default only the adjacency matrix is computed.  To
57                   compute also the distance matrix, use the attribute
58                   "distance_matrix" with a true value to the new()
59                   constructor.
60
61           attribute_name => attribute_name
62                   By default the edge attribute used for distance is "w".
63                   You can change that by giving another attribute name with
64                   the "attribute_name" attribute to new() constructor.  Using
65                   this attribute also implicitly causes the distance matrix
66                   to be computed.
67
68   Object Methods
69       is_adjacent($u, $v)
70           Return true if the vertex $v is adjacent to vertex $u, or false if
71           not.
72
73       distance($u, $v)
74           Return the distance between the vertices $u and $v, or "undef" if
75           the vertices are not adjacent.
76
77           If the underlying graph is multiedged, returns hash-ref of ID
78           mapped to distance. If a given edge ID does not have the attribute
79           defined, it will not be represented. If no edge IDs have the
80           attribute, "undef" will be returned.
81
82       adjacency_matrix
83           Return the adjacency matrix itself (a list of bitvector scalars).
84
85       vertices
86           Return the list of vertices (useful for indexing the adjacency
87           matrix).
88

ALGORITHM

90       The algorithm used to create the matrix is two nested loops, which is
91       O(V**2) in time, and the returned matrices are O(V**2) in space.
92

SEE ALSO

94       Graph::TransitiveClosure, Graph::BitMatrix
95
97       Jarkko Hietaniemi jhi@iki.fi
98

LICENSE

100       This module is licensed under the same terms as Perl itself.
101
102
103
104perl v5.38.0                      2023-07-25         Graph::AdjacencyMatrix(3)
Impressum