1Graph::AdjacencyMatrix(U3s)er Contributed Perl DocumentatGiroanph::AdjacencyMatrix(3)
2
3
4
6 Graph::AdjacencyMatrix - create and query the adjacency matrix of graph
7 G
8
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
29 You can use "Graph::AdjacencyMatrix" to compute the adjacency matrix
30 and optionally also the distance matrix of a graph, and after that
31 query the adjacencyness between vertices by using the "is_adjacent()"
32 method, or query the distance between vertices by using the
33 "distance()" method.
34
35 By default the edge attribute used for distance is "w", but you can
36 change that in new(), see below.
37
38 If you modify the graph after creating the adjacency matrix of it, the
39 adjacency matrix and the distance matrix may become invalid.
40
42 Class Methods
43 new($g)
44 Construct the adjacency matrix of the graph $g.
45
46 new($g, options)
47 Construct the adjacency matrix of the graph $g with options as a
48 hash. The known options are
49
50 distance_matrix => boolean
51 By default only the adjacency matrix is computed. To
52 compute also the distance matrix, use the attribute
53 "distance_matrix" with a true value to the new()
54 constructor.
55
56 attribute_name => attribute_name
57 By default the edge attribute used for distance is "w".
58 You can change that by giving another attribute name with
59 the "attribute_name" attribute to new() constructor. Using
60 this attribute also implicitly causes the distance matrix
61 to be computed.
62
63 Object Methods
64 is_adjacent($u, $v)
65 Return true if the vertex $v is adjacent to vertex $u, or false if
66 not.
67
68 distance($u, $v)
69 Return the distance between the vertices $u and $v, or "undef" if
70 the vertices are not adjacent.
71
72 adjacency_matrix
73 Return the adjacency matrix itself (a list of bitvector scalars).
74
75 vertices
76 Return the list of vertices (useful for indexing the adjacency
77 matrix).
78
80 The algorithm used to create the matrix is two nested loops, which is
81 O(V**2) in time, and the returned matrices are O(V**2) in space.
82
84 Graph::TransitiveClosure, Graph::BitMatrix
85
87 Jarkko Hietaniemi jhi@iki.fi
88
90 This module is licensed under the same terms as Perl itself.
91
92
93
94perl v5.28.0 2014-03-09 Graph::AdjacencyMatrix(3)