if (report_load) alert("lib/lib.js load started"); 

var qs_search_file = "fctsearch.htm"; 
 
function search_fctname(form, field) {
   document.location= qs_search_file + "?fctname=" +
       document.forms[form].elements[field].value;  
} 

function search_form() 
{
   return '<FORM style="margin-bottom: 0px; margin-top: 0px;" name="search">' + 
	       '<INPUT vpsace=0 type="button" value="Function Search" ' + 
	              'onClick="search_fctname(\'search\',\'fctname\')">' +  
	       '<INPUT vspace=0 name=fctname size=20 value="">' + 
	       '</FORM>'; 
}

var my_parameters = get_params(document.location); 
var my_param = new Object(); 
my_param.name = get_param(my_parameters, 'fctname');
if (my_param.name != undefined) {
   var loc = new String(document.location); 
   var pat = new RegExp(qs_search_file + "\?"); 
   if (loc.match(pat)) {
      // alert("already in search.htm"); 
   } else { 
      //alert("goto searching"); 
      document.location= qs_search_file + "?fctname=" + my_param.name; 
   }
}

var qs_n_chapter = -1; 
var qs_user_chapter = new Array(); 
var qs_user_fct = new Array(); 

function qs_get_chapter(i) 
{
  return qs_user_chapter[i];
}

function qs_def_chapter(s, l)
{
  qs_n_chapter++; 
  o = new Object(); 
  o.name = s; 
  if (l != undefined) {
     o.label = l; 
  } else {  
     o.label = qs_n_chapter;
  } 
  o.fcts = new Array(); 
  qs_user_chapter[qs_n_chapter] = o; 
  return qs_n_chapter;
}

function qs_fct_get_target(f) 
{
   return String(f).toLowerCase() + ".htm";
} 

function qs_def_fct(f, d) 
{
  c = qs_get_chapter(qs_n_chapter); 
  len = c.fcts.length; 
  c.fcts[len] = new Object(); 
  c.fcts[len].name = f; 
  c.fcts[len].desc = d; 
  c.fcts[len].target = qs_fct_get_target(f); 
}

function qs_fctlist_search(fname) 
{
   var pattern = new RegExp(fname); 
   var list = new Array(); 
   for (c = 0; c < qs_user_chapter.length; c++) {
      ch = qs_user_chapter[c]; 
      for (i = 0; i < ch.fcts.length; i++) {
	f = new String(ch.fcts[i].name); 
	d = new String(ch.fcts[i].desc); 
        if (f.match(pattern) || d.match(pattern)) {
            list[list.length] = ch.fcts[i]; 
        }
      } 
   } 
   return list; 
}

function qs_fctlist_make_table(fcts) 
{
   wd(qs_table_start(0)); 
   wd(qs_spacer_row(1, 16)); 
   if (fcts.length == 0) {
      wd("<tr>"); 
      wd(qs_spacer_col(32, 1)); 
      wd("<td> Could not find any functions</td>"); 
   } else {
      for (i = 0; i < fcts.length; i++) {
         f = fcts[i]; 
         wd("<tr>"); 
         wd(qs_spacer_col(32, 1)); 
         wd("<td>" + qs_ref(f.name, f.target) + "</td>"); 
         wd(qs_spacer_col(16, 1)); 
         wd("<td>" + f.desc + "</td>"); 
         wd("</tr>"); 
      }
   }
   wd(qs_spacer_row(1, 16)); 
   wd(qs_table_finish()); 
}

function qs_list_chapter(ci, nospacer) 
{
   if (nospacer == undefined) { 
      wd(qs_spacer_row(1, 16)); 
   }
   chap = qs_user_chapter[ci]; 
   wd("<tr><td colspan=2><a name='" + chap.label + "'>" + chap.name + "</a></td></tr>"); 
   for (i=0; i < chap.fcts.length; i++) { 
      qs_fct(chap.fcts[i].name, chap.fcts[i].target, chap.fcts[i].desc); 
   }
} 

function qs_fct(s, t, status) 
{
    wd("<tr>"); 
    wd(qs_spacer_col(16, 1, 1)); 
    wd("<td>" + qs_ref(s, t, status) + "</td>"); 
    wd("</tr>"); 
}

function qs_guide_start() 
{
   wd(qs_table_start(0, 624)); 
   wd("<TR><TD valign=top>");  
   wd(qs_table_start(0)); 
}

function  qs_guide_next_col() 
{
   wd(qs_table_finish()); 
   wd("</TD>"); 
   wd(qs_spacer_col(16, 1, 1)); 
   wd("<TD valign=top>"); 
   wd(qs_table_start(0));
}

function qs_guide_finish() 
{
   wd(qs_table_finish()); 
   wd("</TD></TR>"); 
   wd(qs_table_finish()); 
}

qs_def_chapter("Creating an LP Problem", "creating");
qs_def_fct("QScreate_prob",	"initialize a new data structure with an empty problem"); 
qs_def_fct("QSread_prob",	"read a problem from a named file");  
qs_def_fct("QSload_prob",	"build a problem from user data");  
qs_def_fct("QSfree_prob",	"free the data structure for a problem");  

qs_def_chapter("Optimizing an LP Problem", "optimizing");
qs_def_fct("QSopt_dual",	"solve the LP problem with the dual simplex algorithm"); 
qs_def_fct("QSopt_primal",	"solve the LP problem with the primal simplex algorithm"); 

qs_def_chapter("Accessing an LP Solution", "solution"); 
qs_def_fct("QSget_status",	"obtain the solution status"); 
qs_def_fct("QSget_solution",	"copy various solution data into arrays"); 
qs_def_fct("QSget_objval",	"get the current objective function value"); 
qs_def_fct("QSget_x_array",	"copy the solution vector into an array"); 
qs_def_fct("QSget_pi_array",	"copy the values of the dual variables into an array"); 
qs_def_fct("QSget_slack_array",	"copy the constraint slack values into an array"); 
qs_def_fct("QSget_rc_array",	"copy the reduced costs into an array"); 
qs_def_fct("QSget_named_x",	"obtain the solution value of a named variable"); 
qs_def_fct("QSget_named_rc",	"obtain the reduced cost of a named variable"); 
qs_def_fct("QSget_named_pi",	"obtain the dual value associated with a named row"); 
qs_def_fct("QSget_named_slack",	"obtain the slack value associated with a named row"); 

qs_def_chapter("Modifying an LP Problem",  "modifying");
qs_def_fct("QSnew_col",	"create a new empty column (variable) in the problem"); 
qs_def_fct("QSadd_cols",	"add a set of columns to the problem"); 
qs_def_fct("QSadd_col",	"add a single column to the problem"); 
qs_def_fct("QSdelete_cols",	"delete a set of columns from the problem"); 
qs_def_fct("QSdelete_col",	"delete a single column from the problem"); 
qs_def_fct("QSdelete_setcols",	"delete a set of columns specified by flags"); 
qs_def_fct("QSdelete_named_column",	"delete a column specified by name"); 
qs_def_fct("QSdelete_named_columns_list",	"delete a list of columns, specified by names"); 
qs_def_fct("QSnew_row",	"create a new empty row (constraint) in the problem"); 
qs_def_fct("QSadd_rows",	"add a set of rows to the problem"); 
qs_def_fct("QSadd_row",	"add a single row to the problem"); 
qs_def_fct("QSdelete_rows",	"delete a set of rows from the problem"); 
qs_def_fct("QSdelete_row",	"delete a single row from the problem"); 
qs_def_fct("QSdelete_setrows",	"delete a set of rows specified by flags"); 
qs_def_fct("QSdelete_named_row",	"delete a row specified by name"); 
qs_def_fct("QSdelete_named_rows_list",	"delete a list of rows, specified by names"); 
qs_def_fct("QSchange_coef",	"change a coefficient in the constraint matrix"); 
qs_def_fct("QSchange_objcoef",	"change a coefficient in the objective function"); 
qs_def_fct("QSchange_objsense",	"change the sense of the objective function"); 
qs_def_fct("QSchange_rhscoef",	"change a coefficient in the right-hand-side"); 
qs_def_fct("QSchange_senses",	"change the sense of a set of constraints"); 
qs_def_fct("QSchange_sense",	"change the sense of a single constraint"); 
qs_def_fct("QSchange_bounds",	"change the lower or upper bounds for a set of variables"); 
qs_def_fct("QSchange_bound",	"change the lower or upper bound for a single variable"); 

qs_def_chapter("Accessing LP Problem Data", "accessing");
qs_def_fct("QSget_probname",	"copy the problem name"); 
qs_def_fct("QSget_objname",	"copy the objective name"); 
qs_def_fct("QSget_colcount",	"return the number of columns (variables) in the problem"); 
qs_def_fct("QSget_rowcount",	"return the number of rows (constraints) in the problem"); 
qs_def_fct("QSget_nzcount",	"return the number of non-zeros in the constraint matrix"); 
qs_def_fct("QSget_obj",	"copy the objective function coefficients into an array"); 
qs_def_fct("QSget_rhs",	"copy the right-hand-side values into an array"); 
qs_def_fct("QSget_bound",	"obtain a lower or upper bound for a variable"); 
qs_def_fct("QSget_bounds",	"copy the lower and upper bounds into arrays"); 
qs_def_fct("QSget_columns",	"copy all columns"); 
qs_def_fct("QSget_columns_list",	"copy a list of columns"); 
qs_def_fct("QSget_rows",	"copy all rows"); 
qs_def_fct("QSget_rows_list",	"copy a list of rows"); 
qs_def_fct("QSget_column_index",	"obtain the index of a named column"); 
qs_def_fct("QSget_row_index",	"obtain the index of a named row"); 
qs_def_fct("QSget_colnames",	"copy the names of the columns in the problem"); 
qs_def_fct("QSget_rownames",	"copy the names of the rows in the problem"); 
qs_def_fct("QSget_intcount",	"obtain the number of integer variables"); 
qs_def_fct("QSget_intflags",	"get flags indicating the integer variables"); 

qs_def_chapter("Working with an LP Basis", "basis");
qs_def_fct("QSget_basis",	"get the current basis"); 
qs_def_fct("QSwrite_basis",	"write a basis to a file"); 
qs_def_fct("QSread_basis",	"read a basis from a file"); 
qs_def_fct("QSload_basis",	"load a basis stored in a basis structure"); 
qs_def_fct("QSread_and_load_basis",	"read and load a basis"); 
qs_def_fct("QSfree_basis",	"free the basis structure"); 
qs_def_fct("QSget_basis_array",	"copy the current basis into arrays"); 
qs_def_fct("QSload_basis_array",	"load a basis specified by arrays"); 
qs_def_fct("QSget_basis_and_row_norms_array",	"copy the basis and row norms");
qs_def_fct("QSload_basis_and_row_norms_array",	"load a basis and row norms"); 

qs_def_chapter("Utility Routines", "utility");
qs_def_fct("QSfree", "free standard memory allocated by QSopt functions "); 
qs_def_fct("QSset_param",	"set the value of a specified parameter"); 
qs_def_fct("QSget_param",	"obtain the value of a specified parameter"); 
qs_def_fct("QSset_param_double",	"set the value of a numerical parameter"); 
qs_def_fct("QSget_param_double",	"obtain the value of a numerical parameter"); 
qs_def_fct("QSwrite_prob",	"write the problem to a named file"); 
qs_def_fct("QSwrite_prob_file",	"write the problem to an open file"); 

qs_def_chapter("Advanced Computational Routines", "advanced");
qs_def_fct("QSopt_strongbranch",	"compute values used with strong-branching"); 
qs_def_fct("QSopt_pivotin_col",	"pivot columns into the basis"); 
qs_def_fct("QSopt_pivotin_row",	"pivot logical variables into the basis"); 
qs_def_fct("QScompute_row_norms",	"recompute the dual steepest-edge norms"); 
qs_def_fct("QStest_row_norms",	"check if dual steepest-edge norms are available"); 
qs_def_fct("QSget_infeas_array",	"obtain a certificate of LP infeasibility"); 

if (report_load) alert("lib/lib.js loaded"); 
