Graph-Undirected-Hamiltonicity
view release on metacpan or search on metacpan
script/hamilton.pl view on Meta::CPAN
#!/usr/bin/env perl
use Modern::Perl;
use Carp;
use Getopt::Long;
use Graph::Undirected::Hamiltonicity;
use Graph::Undirected::Hamiltonicity::Transforms qw(string_to_graph);
use Graph::Undirected::Hamiltonicity::Spoof qw(&spoof_known_hamiltonian_graph
&spoof_randomish_graph
);
use Graph::Undirected::Hamiltonicity::Wolfram qw(:all);
$| = 1; # piping hot pipes
my $graph_file = '';
my $graph_text = '';
my $v = 0;
my $e = 0;
my $count = 1;
my $output_format = 'none';
my $help = 0;
my @G = ();
GetOptions(
"graph_file|f=s" => \$graph_file,
"graph_text|t=s" => \$graph_text,
"vertices|v=i" => \$v,
"edges|e=i" => \$e,
"count|c=i" => \$count,
"output_format|o=s" => \$output_format,
"help|h" => \$help
) or show_usage_and_exit("Error in command line arguments\n");
show_usage_and_exit() if $help;
if ($graph_file) {
open( my $fh, "<", $graph_file )
or croak "Could not open [$graph_file][$!]\n";
while ( defined( my $line = <$fh> ) ) {
chomp $line;
next if $line =~ /^\s*#/; ### allow comments
$line =~ s/[^0-9,=]+//g;
next unless $line;
push @G, string_to_graph($line);
}
close($fh);
} elsif ($graph_text) {
push @G, string_to_graph($graph_text);
} elsif ($v) {
$count ||= 1;
for ( my $i = 0; $i < $count; $i++ ) {
push @G, spoof_randomish_graph( $v, $e );
}
} else {
show_usage_and_exit("Please provide --f, or --t, or --v");
}
$ENV{HC_OUTPUT_FORMAT} =
( $output_format =~ /^(html|text|none)$/ ) ? $output_format : 'none';
( run in 0.978 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )