simplex_table.pl

00001 #! /usr/bin/perl
00002 # Implementation of Simplex Algorithm
00003 # © Mark Hutchinson 2004
00004 # Tableau entry creator
00005 
00006 use CGI qw/:standard *table *tr *center/;
00007 
00008 sub data_error {
00009     my $arg;
00010     $arg=$_[0];
00011     print header,
00012           start_html("Error: $arg"),
00013           h1("Error: $arg"),
00014           p(
00015           "There is a problem with the data supplied to the script ",
00016           i("simplex_table.pl"),
00017           "."),
00018           p(
00019           "Please ",
00020           a({-href=>"../simplex.html"},"return to the form page"),
00021           " and try again."),
00022           end_html;
00023           exit;
00024 }
00025 
00026 if(param() eq ""){
00027     &data_error("No data");
00028 }else{
00029     ($vars,$objs,$cons)=(param('novars'),param('noobjs'),param('nocons'));
00030     foreach $a ($vars,$objs,$cons){
00031         &data_error("Incomplete data") if $a==0;
00032         &data_error("Data are not all positive integers") unless $a>0;
00033     }
00034     print header,
00035           start_html("Simplex Algorithm"),
00036           h1('Simplex Algorithm'),
00037           p(
00038           "Please enter the initial tableau in the boxes below.  If you are using artificial variables, select which objective function they exist for (i.e. when they will be removed).  The second line should contain all the variable names.  Select 'Maximise' or 'Minimise' on each objective function depending on what you want.  You may enter fractions in the form a/b/c or b/c (and are strongly advised to do so instead of entering decimals).  If you want a subscript (eg. S<sub>1</sub>) to appear in a name, use '\\' to start and '/' to end it (so S<sub>1</sub> would be '<tt>S\\1/</tt>')."),
00039           p(
00040           "'Display as improper fractions' means as <sup>7</sup>/<sub>2</sub> rather than as 3<sup>1</sup>/<sub>2</sub>. (If your browser doesn't show the previous fraction as 'three and a half', it cannot handle certain tags which are used in fractions.  Either use decimals or select 'Display +/- sign in mixed fractions' to display it as 3+<sup>1</sup>/<sub>2</sub>.)"),
00041           start_form(-method=>'get',-action=>'simplex.pl'),
00042           hidden('novars',$vars),
00043           hidden('noobjs',$objs),
00044           hidden('nocons',$cons),
00045           start_center,
00046           start_table({-width=>'100%',-cols=>$vars+2,-border=>1,-cellspacing=>0,-cellpadding=>0}),
00047           '<tr align="center" valign="top" bgcolor="#DDDDDD">',
00048           td({-align=>'center'},'Remove after:');
00049     @temp=('Never');
00050     for ($i=1;$i<$objs;$i++){
00051         push @temp,$i;
00052     }
00053     for ($i=1;$i<=$vars;$i++){
00054         $default=param('r'.$i);
00055         $default=$temp[0] if($default eq '');
00056         print td({-align=>'center'},popup_menu('r'.$i,\@temp,$default));
00057     }
00058     print td({-align=>'center'},'&nbsp;'),
00059           '</tr><tr align="center" valign="top">',
00060           td({-align=>'center'},'Names:');
00061     for ($i=1;$i<=$vars;$i++){
00062           $default=param('n'.$i);
00063           print td({-align=>'center'},textfield('n'.$i,$default,'3',));
00064     }
00065     print td({-align=>'center'},'RHS'),
00066           '</tr>';
00067     for ($j=0;$j<$objs;$j++){
00068           $default=param('m'.$j);
00069           $default='Maximise' if($default eq '');
00070           print '<tr align="center" valign="top" bgcolor="#DDDDDD">',
00071                 td({-align=>'center'},popup_menu('m'.$j,['Maximise','Minimise']));
00072           for ($i=1;$i<=$vars+1;$i++){
00073               $default=param('d'.$j.'_'.$i);
00074               print td({-align=>'center'},textfield('d'.$j.'_'.$i,$default,'3'));
00075           }
00076           print '</tr>';
00077     }
00078     $put="Constraints:";
00079     for ($j=0;$j<$cons;$j++){
00080           print '<tr align="center" valign="top">',
00081                 td({-align=>'center'},$put);
00082                 for ($i=1;$i<=$vars+1;$i++){
00083                     $default=param('d'.($objs+$j).'_'.$i);
00084                     print td({-align=>'center'},textfield('d'.($objs+$j).'_'.$i,$default,'3'));
00085                 }
00086           $put='&nbsp;';
00087     }
00088     $default=param('fdsip');
00089     $default='Display as mixed fractions' if($default eq '');
00090     print end_table,
00091           end_center,
00092           start_table({-cols=>2,-border=>0,-cellspacing=>0,-cellpadding=>0}),
00093           '<tr align="left" valign="top">',
00094           td({-valign=>'top'},
00095           radio_group(-name=>'fdisp',-values=>['Display as mixed fractions','Display as improper fractions','Display as decimals'],-default=>$default,-linebreak=>'true'));
00096     $default=param('showsign');
00097     $default='' if($default eq '');
00098     print td({-valign=>'top'},
00099           checkbox(-name=>'showsign',-label=>'Display +/- sign in mixed fractions')),
00100           '</tr>',
00101           end_table,
00102           br,
00103           reset,
00104           submit('Process'),
00105           end_form,
00106           hr,
00107           font({-size=>'-1'},"This implementation of the Simplex algorithm is &copy; Mark Hutchinson 2004."),
00108           end_html;
00109           
00110           
00111 }

Generated on Tue May 25 20:02:42 2004 for Simplex by doxygen 1.3.3