#!/usr/bin/env perl
# Generate random graph, for the sake of testing the genetic algoritms
# $Id: randgraph.pl 606 2008-05-12 15:37:58Z rick $
# Rick van der Zwet
# Licence: BSD

$MAX_LENGTH=20;

if ( not defined($ARGV[1]) ) {
    print "Usage <program> <size_of_array> <CHANCE on arch>\n";
    exit 1;
}

$NODES = $ARGV[0];
$CHANCE = $ARGV[1];

print "$NODES\n";
foreach $i (0 .. ($NODES-1)) {
    foreach $j (0 .. ($NODES-1)) {
        if ($i == $j) {
            printf  "%02i ", 0;
        } elsif ($j < $i) {
            printf "%02i ", $distance[$j][$i];
        } else {
            if (int(rand(100)) < $CHANCE) {
                $length = int(rand($MAX_LENGTH)) + 1;
            } else {
                $length = 0;
            }
            $distance[$i][$j] = $length;
            printf "%02i ", $length;
        }
    }
    print "\n";
}
