-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtucker.cgi
executable file
·151 lines (121 loc) · 4.83 KB
/
tucker.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/perl
use strict;
use HTML::Element;
use CGI qw(:header :start_html :end_html :param);
use CGI::Carp qw(fatalsToBrowser);
# INSTALLATION: configure paths specific to installation, i.e. make them correct paths for your system
my $tmp_path = '/tmp/';
my $examples_path = '/var/www/tucker/examples/';
my $LP_titles = $examples_path . 'LP-titles.txt';
my $qs = $ENV{QUERY_STRING};
my $XHTML_VALIDATOR;
my $EMPTY_STRING = q{};
#use Tableau_Float;
use Tableau;
my $tableau_object = Tableau->new;
print header;
print start_html(
-title=> 'Tucker Tableau Session',
-style=> '/css/tucker.css',
)
;
# optimize when in optimize mode.
if ( $qs =~ m{session=(.*?)&mode=optimize&row=(\d+)&col=(\d+)} ) {
my $session = $1;
my $cgi = CGI->new;
my $is_example = $qs =~ m{example} ? 1 : 0;
$tableau_object->set_tableau($session, $is_example, $tmp_path, $examples_path);
print $tableau_object->get_title_as_HTML;
if ( $cgi->param('show_tableau') eq 'all' ) {
$tableau_object->set_html_matrix(0,$session);
#print $tableau_object->get_html_matrix;
print $tableau_object->tucker_tableau_as_HTML;
}
$tableau_object->pivot($2,$3);
# pivot until optimal.
# use counter to exit when caught in BIG loop
my $counter = 0;
until ($tableau_object->is_solution_optimal ) {
$counter++;
die "Too many loops" if ($counter > 1000);
# print each tableau if in trace mode (show_tableau - all)
if ( $cgi->param('show_tableau') eq 'all' ) {
$tableau_object->set_html_matrix(0,$session);
#print $tableau_object->get_title_as_HTML;
#print $tableau_object->get_html_matrix;
print $tableau_object->tucker_tableau_as_HTML;
#print $tableau_object->current_solution_as_HTML;
}
my %bland_pivot = $tableau_object->get_bland_simplex_pivot;
my @bland_pivot = %bland_pivot;
my @real_pivot = map { $_ + 1 } @bland_pivot;
#print "pivoting on: ", join ', ', @real_pivot, "<br />\n";
$tableau_object->pivot($bland_pivot[1]+1, $bland_pivot[0]+1);
}
$tableau_object->set_html_matrix(0,$session);
$tableau_object->save_html_tableau_to_file($1, 0, $tmp_path, $examples_path);
#print $tableau_object->get_html_matrix;
print $tableau_object->tucker_tableau_as_HTML;
print $tableau_object->current_solution_as_HTML;
}
# pivot when in pivot mode
elsif ( $qs =~ m{session=(.*?)&mode=pivot&row=(\d+)&col=(\d+)} ) {
my $session = $1;
$tableau_object->set_tableau($1, 0, $tmp_path, $examples_path);
$tableau_object->pivot($2,$3);
$tableau_object->set_html_matrix(1,$1);
$tableau_object->save_html_tableau_to_file($1, 0, $tmp_path, $examples_path);
print $tableau_object->get_title_as_HTML;
print $tableau_object->tucker_tableau_as_HTML;
print $tableau_object->current_solution_as_HTML;
#print $tableau_object->get_optimize_link($session) if !$tableau_object->is_solution_optimal;
}
# load example from file
elsif ( $qs =~ m{mode=load&example=(.*)} ) {
# set random number for temporary session derived from loaded example
srand;
my $session = rand;
$tableau_object->set_tableau($1, 1, $tmp_path, $examples_path);
$tableau_object->set_html_matrix(1,$session);
$tableau_object->save_html_tableau_to_file($session, 0, $tmp_path, $examples_path);
print $tableau_object->get_title_as_HTML;
#print $tableau_object->get_html_matrix;
print $tableau_object->tucker_tableau_as_HTML;
print $tableau_object->current_solution_as_HTML($session);
#print $tableau_object->get_optimize_link($session) if !$tableau_object->is_solution_optimal;
}
else {
print $tableau_object->get_example_list_as_HTML ($LP_titles);
print "<p>";
print qq{<a href="/perl/Tucker/create-LP.cgi">Input</a> a New LP Example<br />};
print qq{<a href="/perl/Tucker/create-LP.cgi?mode=return_random_LP">Generate</a> a Random LP };
print "</p>";
}
# if there is a query string then we are not at the home page, thus print home page link
print_home_page_link();
#print_xhtml_validator_link();
print end_html;
####---- subs down under
sub print_home_page_link {
if ( $ENV{QUERY_STRING} ) {
my $home_page_url;
my $a = HTML::Element->new('a', href => $ENV{SCRIPT_NAME});
$a->push_content( 'Home' );
my $home_page = $a->as_HTML();
print '<p>', $home_page, '</p>';
}
}
sub print_xhtml_validator_link {
print "<hr />";
print $XHTML_VALIDATOR;
}
BEGIN {
use Readonly;
Readonly $XHTML_VALIDATOR => <<'END_VALIDATOR';
<div class="validator">
<a href="http://validator.w3.org/check?uri=referer">
<img src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a>
</div>
END_VALIDATOR
}