line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Graph::Undirected::Hamiltonicity::Wolfram; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
624
|
use Modern::Perl; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
4
|
1
|
|
|
1
|
|
131
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
5
|
1
|
|
|
1
|
|
447
|
use Config::INI::Reader; |
|
1
|
|
|
|
|
33724
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
1
|
|
571
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
38397
|
|
|
1
|
|
|
|
|
38
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
8
|
use Exporter qw(import); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
416
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw(&is_hamiltonian_per_wolfram |
11
|
|
|
|
|
|
|
&get_url_from_config); |
12
|
|
|
|
|
|
|
our @EXPORT = qw(&is_hamiltonian_per_wolfram); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => \@EXPORT_OK, ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
############################################################################## |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub is_hamiltonian_per_wolfram { |
19
|
0
|
|
|
0
|
1
|
0
|
my ($g) = @_; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
### Cover up limitations of Wolfram Language script |
22
|
0
|
|
|
|
|
0
|
my $vertices = $g->vertices(); |
23
|
0
|
0
|
|
|
|
0
|
return 0 if $vertices == 0; |
24
|
0
|
0
|
|
|
|
0
|
return 1 if $vertices == 1; |
25
|
0
|
|
|
|
|
0
|
foreach my $vertex ( $g->vertices() ) { |
26
|
0
|
0
|
|
|
|
0
|
return 0 if $g->degree($vertex) < 2; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
### Create a user agent object |
30
|
0
|
|
|
|
|
0
|
my $ua = LWP::UserAgent->new; |
31
|
0
|
|
|
|
|
0
|
$ua->agent("HamiltonCycleFinder/0.1 "); |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
my $url = get_url_from_config(); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
### Create a request |
36
|
0
|
|
|
|
|
0
|
my $req = HTTP::Request->new( POST => $url ); |
37
|
0
|
|
|
|
|
0
|
$req->content_type('application/x-www-form-urlencoded'); |
38
|
0
|
|
|
|
|
0
|
$req->content("x=" . $g->stringify() ); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Pass request to the user agent and get a response back |
41
|
0
|
|
|
|
|
0
|
my $res = $ua->request($req); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Check the outcome of the response |
44
|
0
|
0
|
|
|
|
0
|
if ( $res->is_success ) { |
45
|
0
|
|
|
|
|
0
|
my $output = $res->content; |
46
|
0
|
|
|
|
|
0
|
return $output; |
47
|
|
|
|
|
|
|
} else { |
48
|
0
|
|
|
|
|
0
|
my $message = "ERROR:" . $res->status_line; |
49
|
0
|
|
|
|
|
0
|
croak $message; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
############################################################################## |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub get_url_from_config { |
57
|
1
|
|
|
1
|
0
|
77
|
my $file = $ENV{HOME} . '/hamilton.ini'; |
58
|
1
|
0
|
33
|
|
|
58
|
return unless ( -e $file && -f _ && -r _ ); |
|
|
|
33
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $hash; |
61
|
0
|
|
|
|
|
|
eval { |
62
|
0
|
|
|
|
|
|
$hash = Config::INI::Reader->read_file($file); |
63
|
|
|
|
|
|
|
}; |
64
|
0
|
0
|
|
|
|
|
if ( $@ ) { |
65
|
0
|
|
|
|
|
|
carp "EXCEPTION: [$@]\n"; |
66
|
0
|
|
|
|
|
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $url = $hash->{wolfram}->{url}; |
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
if ( $url =~ /^http/ ) { |
72
|
0
|
|
|
|
|
|
$url =~ s{^https://}{http://}; |
73
|
0
|
|
|
|
|
|
return $url; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
############################################################################## |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; # End of Graph::Undirected::Hamiltonicity::Wolfram |