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 "dis‐
33 tance()" 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
44 new($g)
45 Construct the adjacency matrix of the graph $g.
46
47 new($g, options)
48 Construct the adjacency matrix of the graph $g with options as a
49 hash. The known options are
50
51 distance_matrix => boolean
52 By default only the adjacency matrix is computed. To com‐
53 pute also the distance matrix, use the attribute "dis‐
54 tance_matrix" with a true value to the new() 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
65 is_adjacent($u, $v)
66 Return true if the vertex $v is adjacent to vertex $u, or false if
67 not.
68
69 distance($u, $v)
70 Return the distance between the vertices $u and $v, or "undef" if
71 the vertices are not adjacent.
72
73 adjacency_matrix
74 Return the adjacency matrix itself (a list of bitvector scalars).
75
76 vertices
77 Return the list of vertices (useful for indexing the adjacency
78 matrix).
79
81 The algorithm used to create the matrix is two nested loops, which is
82 O(V**2) in time, and the returned matrices are O(V**2) in space.
83
85 Graph::TransitiveClosure, Graph::BitMatrix
86
88 Jarkko Hietaniemi jhi@iki.fi
89
91 This module is licensed under the same terms as Perl itself.
92
93
94
95perl v5.8.8 2004-11-08 Graph::AdjacencyMatrix(3)