Graph-Undirected-Hamiltonicity
view release on metacpan or search on metacpan
script/cgi-bin/hc.cgi view on Meta::CPAN
#!/usr/bin/env perl
#
# This script demonstrates the functionality of the
# Graph::Undirected::Hamiltonicity module.
#
# It uses CGI::Minimal to keep it fairly portable.
#
use Modern::Perl;
use CGI::Minimal;
use Graph::Undirected;
use Graph::Undirected::Hamiltonicity;
use Graph::Undirected::Hamiltonicity::Transforms qw(&string_to_graph);
$ENV{HC_OUTPUT_FORMAT} = 'html';
$| = 1;
my ( $self_url ) = split /\?/, $ENV{REQUEST_URI};
say qq{Content-Type: text/html\n};
say <<'END_OF_HEADER';
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hamiltonian Cycle Detector</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.8.0/jquery.modal.min.css" integrity="sha256-rll6wTV76AvdluCY5Pzv2xJfw2x7UXnK+fGfj9tQocc=" crossorigin="anonymous" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.8.0/jquery.modal.min.js" integrity="sha256-UeH9wuUY83m/pXN4vx0NI5R6rxttIW73OhV0fE0p/Ac=" crossorigin="anonymous"></script>
<script>
// -----------------------------------------------------------------------------
function random_integer(min,max) {
return Math.floor((Math.random() * max) + min);
}
// -----------------------------------------------------------------------------
function spoof_graph(v, min_e) {
if ( min_e < v ) {
min_e = random_integer(v, ( v * v - v ) / 2 );
}
var X = new Array();
for ( var h=0; h < v; h++ ) {
X[h] = new Array();
}
for ( var i=0; i < min_e; i++ ) {
var vertex1 = random_integer(0,v);
var vertex2 = random_integer(0,v);
if (vertex1 == vertex2) continue;
if ( X[vertex1].indexOf(vertex2) !== -1 ) continue;
X[vertex1].push(vertex2);
X[vertex2].push(vertex1);
}
for ( var j=0; j < v; j++ ) {
var neighbors = X[j].length;
if (neighbors > 1) continue;
while ( neighbors < 2 ) {
var vertex1 = j;
var vertex2 = random_integer(0,v);
if (vertex1 == vertex2) continue;
if (X[vertex1].indexOf(vertex2) !== -1) continue;
X[vertex1].push(vertex2);
X[vertex2].push(vertex1);
neighbors++;
}
}
var edge_pairs = new Array();
for ( var m=0; m < v; m++ ) {
for ( var n=0; n < X[m].length; n++ ) {
if ( m > X[m][n] ) continue;
edge_pairs.push( m + "=" + X[m][n] );
( run in 1.864 second using v1.01-cache-2.11-cpan-119454b85a5 )