![]() |
![]()
| ![]() |
![]()
NAMEGraph::AdjacencyMatrix - create and query the adjacency matrix of graph G SYNOPSISuse Graph::AdjacencyMatrix; use Graph::Directed; # or Undirected my $g = Graph::Directed->new; $g->add_...(); # build $g my $am = Graph::AdjacencyMatrix->new($g); $am->is_adjacent($u, $v) my $am = Graph::AdjacencyMatrix->new($g, distance_matrix => 1); $am->distance($u, $v) my $am = Graph::AdjacencyMatrix->new($g, attribute_name => 'length'); $am->distance($u, $v) my $am = Graph::AdjacencyMatrix->new($g, ...); my @V = $am->vertices(); $g = Graph->new(multiedged => 1); $g->add_...(); # build $g $am = Graph::AdjacencyMatrix->new($g, distance_matrix => 1); $am->distance($u, $v) # returns hash-ref of ID => distance DESCRIPTIONYou can use "Graph::AdjacencyMatrix" to compute the adjacency matrix and optionally also the distance matrix of a graph, and after that query the adjacencyness between vertices by using the is_adjacent() method, or query the distance between vertices by using the distance() method. By default the edge attribute used for distance is "w", but you can change that in new(), see below. If you modify the graph after creating the adjacency matrix of it, the adjacency matrix and the distance matrix may become invalid. MethodsClass Methods
Object Methods
ALGORITHMThe algorithm used to create the matrix is two nested loops, which is O(V**2) in time, and the returned matrices are O(V**2) in space. SEE ALSOGraph::TransitiveClosure, Graph::BitMatrix AUTHOR AND COPYRIGHTJarkko Hietaniemi jhi@iki.fi LICENSEThis module is licensed under the same terms as Perl itself.
|