#!/usr/bin/perl
use strict;
use warnings;
use Graph::Weighted;
my $g = Graph::Weighted->new;

my $attr = 'magnitude';

$g->populate(
    [
        [ 0, 1, 2, 0, 0 ], # Vertex 0 with 5 edges of weight 3
        [ 1, 0, 3, 0, 0 ], #    "   1        "               4
        [ 2, 3, 0, 0, 0 ], #    "   2        "               5
        [ 0, 0, 1, 0, 0 ], #    "   3        "               1
        [ 0, 0, 0, 0, 0 ], #    "   4        "               0
    ]
);
$g->populate(
    {
        0 => { 1=>2, 2=>1 },             # Vertex with 2 edges of weight 3
        1 => { 0=>3, 2=>1 },             #      "      2        "        4
        2 => { 0=>3, 1=>2 },             #      "      2        "        5
        3 => { 1=>2 },                   #      "      1        "        2
        4 => { 0=>1, 1=>1, 2=>1, 3=>1 }, #      "      4        "        4
    },
    $attr
);

# Show each vertex and its edges.
for my $v (sort { $a <=> $b } $g->vertices) {
    warn sprintf "V: %s w=%.2f, %s=%.2f\n",
        $v,
        $g->get_weight($v) || 0,
        $attr, $g->get_attr($v, $attr);
    for my $n (sort { $a <=> $b } $g->neighbors($v)) {
        warn sprintf "\tE: >%s w=%.2f, %s=%.2f\n",
            $n,
            $g->get_weight([$v, $n]),
            $attr, $g->get_attr([$v, $n], $attr);
    }
}
