NAME
Graph::Weighted - A weighted graph implementation
SYNOPSIS
use Graph::Weighted;
$g = Graph::Weighted->new(
data => {
a => { b => 1, c => 2, }, # Nodes with two edges.
b => { a => 1, c => 3, },
c => { a => 2, b => 3, },
d => { c => 1, }, # A vertex with one edge.
e => {}, # A vertex with no edges.
}
);
$g->reset_graph;
$g = Graph::Weighted->new();
$g->load(
[ [ 0, 1, 2 ],
[ 1, 0, 3 ],
[ 2, 3, 0 ], ]
);
$w = $g->graph_weight;
$heaviest = $g->heaviest_vertices;
$lightest = $g->lightest_vertices;
$x = $g->vertex_weight($heaviest->[$i]) if @$heaviest;
$y = $g->vertex_weight($lightest->[$j]) if @$lightest;
$x = $g->vertex_weight(0);
$y = $g->vertex_weight(0, $x + 1);
$m = $g->matrix;
ABSTRACT
A weighted graph implementation
DESCRIPTION
A Graph::Weighted
object represents a subclass of Graph
with weighted attributes that are taken from a 2D matrix (HoH or NxN LoL) of numerical values.
Initially, the weights of the vertices are set to the sum of their outgoing edge weights. This is mutable, however, and can be set to any value desired, after initialization, with the vertex_weight
method.
PUBLIC METHODS
- new HASH
- reset_graph
-
Erase the graph's vertices, edges and attributes.
- load HASHREF | ARRAYREF
-
Turn the given two dimensional hash or (2D, square) array reference into the vertices and weighted edges of a
Graph
object. - matrix
-
Return the two dimensional hash used for vertices and weighted edges.
- graph_weight
-
Get the total weight of the graph, by summing all the vertex weights.
- vertex_weight SCALAR [, SCALAR]
-
Return the weight of a vertex. This method can also be used to set the vertex weight, if a second argument is provided.
When the second argument is provided, the weight it represents is distributed evenly to the vertex's outgoing edges, and the total weight of the entire graph is adjusted accordingly.
- edge_weight SCALAR, SCALAR [, SCALAR]
-
Return the weight of an edge. This method can also be used to set the edge weight, if a third argument is provided.
When the third argument is provided, the weight it represents is used to replace the weight of the edge between the vertex (first argument) and it's neighbor (second argument). Lastly, the total weight of the entire graph and the weight of the vertex are adjusted accordingly.
- heaviest_vertices
-
Return the array reference of vertices with the most weight.
- lightest_vertices
-
Return the array reference of vertices with the least weight.
PRIVATE METHODS
SEE ALSO
TO DO
Handle clusters of vertices and sub-graphs.
AUTHOR
Gene Boggs <cpan@ology.net>
COPYRIGHT AND LICENSE
Copyright 2003 by Gene Boggs
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.