QSopt 0.5 Alpha
All Rights Reserved

qs
Class Problem

java.lang.Object
  extended byLibProblem
      extended byqs.Problem

public class Problem
extends LibProblem

The Problem class wraps all information defining a linear problem as well as the choice of solution algorithm. It supplies the methods necessary to create linear problems, manipulate, solve, and read them from and write them to files.

This implementation is based on an early version of the QSopt callable function library written in the C programming language. QSopt's documentation of the C library is accessible on the QSopt web site .

Each method of the Problem class is based on a C function. For example
    void Problem.get_status() is based on
           int QSget_status(QSprob p) and
    public void Problem.new_row(double rhs, char sense, String name) is based on
           int QSnew_row (QSprob p, double rhs, char sense, const char *name)
Most of the library's C functions return a non zero integer value to indicate failure. The corresponding Java methods throw a QSException instead.

Instead of describing the JAVA methods in detail the documentation refers the reader to their corresponding C functions. Their documentation can be found on the QSopt website's function list .

See Also:
Serialized Form

Constructor Summary
Problem()
          create an empty linear problem; see QScreate_prob
Problem(java.lang.String nm)
          create an empty linear problem; see QScreate_prob
Problem(java.lang.String probname, int ncols, int nrows, int[] cmatcnt, int[] cmatbeg, int[] cmatind, double[] cmatval, int objsense, double[] obj, double[] rhs, char[] sense, double[] lower, double[] upper, java.lang.String[] colnames, java.lang.String[] rownames)
          create a Problem; see QSload_prob
 
Method Summary
 void add_cols(int num, int[] cmatcnt, int[] cmatbeg, int[] cmatind, double[] cmatval, double[] obj, double[] lower, double[] upper, java.lang.String[] names)
          add a set of columns (variables) to the problem; see QSadd_cols
 void add_rows(int num, int[] rmatcnt, int[] rmatbeg, int[] rmatind, double[] rmatval, double[] rhs, char[] sense, java.lang.String[] names)
          add a set of rows to the problem; see QSadd_rows
 void change_bounds(int num, int[] collist, char[] lu, double[] bounds)
          change the lower or upper bounds for a set of variables; see QSchange_bounds
 void change_objsense(int sense)
          Change the sense of the objective function; see QSchange_objsense
 void change_sense(int num, int[] rowlist, char[] sense)
          change the sense of a set of constraints; see QSchange_senses
 void compute_row_norms()
          compute_row_norms; see QScompute_row_norms
 void delete_cols(int num, int[] dellist)
          delete a set of columns from the problem; see QSdelete_cols
 void delete_rows(int num, int[] dellist)
          delete a set of rows from the problem; see QSdelete_rows
 void delete_setrows(int[] flags)
          delete a set of rows specified by flags; see QSdelete_setrows
 void free()
          free all internal memory; see QSfree_prob
 void get_basis_and_row_norms_array(char[] cstat, char[] rstat, double[] rownorms)
          copy the basis and row norms; see QSget_basis_and_row_norms_array
 void get_basis_array(char[] cstat, char[] rstat)
          copy the current basis into arrays; see QSget_basis_array
 int get_colcount()
          return the number of columns (variables) in the problem, see QSget_colcount
 void get_colnames(java.lang.String[] colnames)
          copy the names of the columns in the problem, see QSget_colnames
 java.lang.String get_name()
          copy the problem name, see QSget_probname
 int get_nzcount()
          return the number of non-zeros in the constraint matrix.
 void get_obj(double[] obj)
          copy the objective function coefficients into an array.
 java.lang.String get_objname()
          copy the objective name; see QSget_objname
 double get_objval()
          get the current objective function value; see QSget_objval
 void get_pi_array(double[] pi)
          copy the values of the dual variables into an array; see QSget_pi_array
 void get_rc_array(double[] rc)
          copy the constraint reduced cost values into an array; see QSget_rc_array
 java.lang.String get_rhsname()
          obtain the index of a named row see QSget_row_index
 int get_rowcount()
          return the number of rows (constraints) in the problem, see QSget_rowcount
 void get_rownames(java.lang.String[] rownames)
          copy the names of the rows in the problem, see QSget_rownames
 void get_slack_array(double[] slack)
          copy the constraint slack values into an array; see QSget_slack_array
 double get_solution(double[] x, double[] pi, double[] slack, double[] rc)
          copy various solution data into arrays; see QSget_solution
 int get_status()
          retrieve the problem's status.
 void get_x_array(double[] x)
          copy the solution vector into an array; see QSget_x_array
 int getparam(int whichparam)
          obtain the value of a specified parameter; see QSget_param
 void load_basis_and_row_norms_array(char[] cstat, char[] rstat, double[] rownorms)
          copy the basis and row norms; see QSload_basis_and_row_norms_array
 void load_basis_array(char[] cstat, char[] rstat)
          copy the current basis into arrays; see QSload_basis_array
 void load_basis(Basis B)
          load a basis stored in a basis structure; see QSload_basis
 void new_row(double rhs, char sense, java.lang.String name)
          create a new empty row (constraint) in the problem; see QSnew_row
 void opt_dual()
          solve the LP problem with the dual simplex algorithm; see QSopt_dual
 void opt_primal()
          solve the LP problem with the primal simplex algorithm; see QSopt_primal
 int print_pi(Reporter r, boolean nonZerosOnly, int precision)
          print the values of the Problem's dual variables to the Reporter's stream
 int print_rc(Reporter r, boolean nonZerosOnly, int precision)
          print the reduced cost values of the Problem's variables to the Reporter's stream
 int print_slack(Reporter r, boolean nonZerosOnly, int precision)
          print the slack values of the Problem's constraints to the Reporter's stream
 int print_x(Reporter r, boolean nonZerosOnly, int precision)
          print the values of the Problem's variables to the Reporter's stream
static Problem read_lp(java.io.Reader r, java.lang.String name)
          read a problem from an LP source; see QSread_prob
static Problem read_lp(java.lang.String fname)
          read a problem from an LP file; see QSread_prob
static Problem read_mps(java.io.Reader r, java.lang.String name)
          read a problem from an MPS source; see QSread_prob
static Problem read_mps(java.lang.String fname)
          read a problem from an MPS file; see QSread_prob
static Problem read(java.io.Reader r, java.lang.String fname, boolean isMps)
          read a problem from Reader; see QSread_prob
static Problem read(java.lang.String fname, boolean isMps)
          read a problem from an MPS or LP file; see QSread_prob; fname may be givem as a plain file name or a "file:", "http:" url;
 void setparam(int whichparam, int newvalue)
          set the value of a specified parameter, see QSset_param
 void write_basis(java.lang.String filename)
          write a basis to a file, see QSwrite_basis
 void write_lp(java.lang.String filename)
          write the problem in LP format to a named file, see QSwrite_prob
 void write_mps(java.lang.String filename)
          write the problem to a named file, see QSwrite_prob
 void write(Reporter rep, boolean isMps)
          write the problem to Reporter's stream see QSwrite_prob
 void write(java.lang.String filename, boolean isMps)
          write the problem in LP or MPS format to a named file, see QSwrite_prob
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Problem

public Problem()
create an empty linear problem; see QScreate_prob


Problem

public Problem(java.lang.String nm)
create an empty linear problem; see QScreate_prob


Problem

public Problem(java.lang.String probname,
               int ncols,
               int nrows,
               int[] cmatcnt,
               int[] cmatbeg,
               int[] cmatind,
               double[] cmatval,
               int objsense,
               double[] obj,
               double[] rhs,
               char[] sense,
               double[] lower,
               double[] upper,
               java.lang.String[] colnames,
               java.lang.String[] rownames)
        throws QSException
create a Problem; see QSload_prob

Method Detail

add_cols

public void add_cols(int num,
                     int[] cmatcnt,
                     int[] cmatbeg,
                     int[] cmatind,
                     double[] cmatval,
                     double[] obj,
                     double[] lower,
                     double[] upper,
                     java.lang.String[] names)
              throws QSException
add a set of columns (variables) to the problem; see QSadd_cols

Throws:
QSException

add_rows

public void add_rows(int num,
                     int[] rmatcnt,
                     int[] rmatbeg,
                     int[] rmatind,
                     double[] rmatval,
                     double[] rhs,
                     char[] sense,
                     java.lang.String[] names)
              throws QSException
add a set of rows to the problem; see QSadd_rows

Throws:
QSException

change_bounds

public void change_bounds(int num,
                          int[] collist,
                          char[] lu,
                          double[] bounds)
                   throws QSException
change the lower or upper bounds for a set of variables; see QSchange_bounds

Throws:
QSException

change_objsense

public void change_objsense(int sense)
Change the sense of the objective function; see QSchange_objsense


change_sense

public void change_sense(int num,
                         int[] rowlist,
                         char[] sense)
                  throws QSException
change the sense of a set of constraints; see QSchange_senses

Throws:
QSException

compute_row_norms

public void compute_row_norms()
                       throws QSException
compute_row_norms; see QScompute_row_norms

Throws:
QSException

delete_cols

public void delete_cols(int num,
                        int[] dellist)
                 throws QSException
delete a set of columns from the problem; see QSdelete_cols

Throws:
QSException

delete_rows

public void delete_rows(int num,
                        int[] dellist)
                 throws QSException
delete a set of rows from the problem; see QSdelete_rows

Throws:
QSException

delete_setrows

public void delete_setrows(int[] flags)
                    throws QSException
delete a set of rows specified by flags; see QSdelete_setrows

Throws:
QSException

free

public void free()
free all internal memory; see QSfree_prob


get_basis_and_row_norms_array

public void get_basis_and_row_norms_array(char[] cstat,
                                          char[] rstat,
                                          double[] rownorms)
                                   throws QSException
copy the basis and row norms; see QSget_basis_and_row_norms_array

Throws:
QSException

get_basis_array

public void get_basis_array(char[] cstat,
                            char[] rstat)
                     throws QSException
copy the current basis into arrays; see QSget_basis_array

Throws:
QSException

get_colcount

public int get_colcount()
return the number of columns (variables) in the problem, see QSget_colcount


get_colnames

public void get_colnames(java.lang.String[] colnames)
copy the names of the columns in the problem, see QSget_colnames


get_name

public java.lang.String get_name()
copy the problem name, see QSget_probname


get_nzcount

public int get_nzcount()
return the number of non-zeros in the constraint matrix. see QSget_nzcount


get_obj

public void get_obj(double[] obj)
             throws QSException
copy the objective function coefficients into an array. see QSget_obj

Throws:
QSException

get_objname

public java.lang.String get_objname()
                             throws QSException
copy the objective name; see QSget_objname

Throws:
QSException

get_objval

public double get_objval()
                  throws QSException
get the current objective function value; see QSget_objval

Throws:
QSException

get_pi_array

public void get_pi_array(double[] pi)
                  throws QSException
copy the values of the dual variables into an array; see QSget_pi_array

Throws:
QSException

get_rc_array

public void get_rc_array(double[] rc)
                  throws QSException
copy the constraint reduced cost values into an array; see QSget_rc_array

Throws:
QSException

get_rhsname

public java.lang.String get_rhsname()
obtain the index of a named row see QSget_row_index


get_rowcount

public int get_rowcount()
return the number of rows (constraints) in the problem, see QSget_rowcount


get_rownames

public void get_rownames(java.lang.String[] rownames)
                  throws QSException
copy the names of the rows in the problem, see QSget_rownames

Throws:
QSException

get_slack_array

public void get_slack_array(double[] slack)
                     throws QSException
copy the constraint slack values into an array; see QSget_slack_array

Throws:
QSException

get_solution

public double get_solution(double[] x,
                           double[] pi,
                           double[] slack,
                           double[] rc)
                    throws QSException
copy various solution data into arrays; see QSget_solution

Throws:
QSException

get_status

public int get_status()
retrieve the problem's status. see QSget_status


get_x_array

public void get_x_array(double[] x)
                 throws QSException
copy the solution vector into an array; see QSget_x_array

Throws:
QSException

getparam

public int getparam(int whichparam)
             throws QSException
obtain the value of a specified parameter; see QSget_param

Throws:
QSException

load_basis_and_row_norms_array

public void load_basis_and_row_norms_array(char[] cstat,
                                           char[] rstat,
                                           double[] rownorms)
                                    throws QSException
copy the basis and row norms; see QSload_basis_and_row_norms_array

Throws:
QSException

load_basis_array

public void load_basis_array(char[] cstat,
                             char[] rstat)
                      throws QSException
copy the current basis into arrays; see QSload_basis_array

Throws:
QSException

load_basis

public void load_basis(Basis B)
                throws QSException
load a basis stored in a basis structure; see QSload_basis

Throws:
QSException

new_row

public void new_row(double rhs,
                    char sense,
                    java.lang.String name)
             throws QSException
create a new empty row (constraint) in the problem; see QSnew_row

Throws:
QSException

opt_dual

public void opt_dual()
              throws QSException
solve the LP problem with the dual simplex algorithm; see QSopt_dual

Throws:
QSException

opt_primal

public void opt_primal()
                throws QSException
solve the LP problem with the primal simplex algorithm; see QSopt_primal

Throws:
QSException

print_pi

public int print_pi(Reporter r,
                    boolean nonZerosOnly,
                    int precision)
             throws QSException
print the values of the Problem's dual variables to the Reporter's stream

Throws:
QSException

print_rc

public int print_rc(Reporter r,
                    boolean nonZerosOnly,
                    int precision)
             throws QSException
print the reduced cost values of the Problem's variables to the Reporter's stream

Throws:
QSException

print_slack

public int print_slack(Reporter r,
                       boolean nonZerosOnly,
                       int precision)
                throws QSException
print the slack values of the Problem's constraints to the Reporter's stream

Throws:
QSException

print_x

public int print_x(Reporter r,
                   boolean nonZerosOnly,
                   int precision)
            throws QSException
print the values of the Problem's variables to the Reporter's stream

Throws:
QSException

read_lp

public static Problem read_lp(java.io.Reader r,
                              java.lang.String name)
read a problem from an LP source; see QSread_prob


read_lp

public static Problem read_lp(java.lang.String fname)
                       throws java.io.IOException
read a problem from an LP file; see QSread_prob

Throws:
java.io.IOException

read_mps

public static Problem read_mps(java.io.Reader r,
                               java.lang.String name)
read a problem from an MPS source; see QSread_prob


read_mps

public static Problem read_mps(java.lang.String fname)
                        throws java.io.IOException
read a problem from an MPS file; see QSread_prob

Throws:
java.io.IOException

read

public static Problem read(java.io.Reader r,
                           java.lang.String fname,
                           boolean isMps)
                    throws java.io.IOException
read a problem from Reader; see QSread_prob

Throws:
java.io.IOException

read

public static Problem read(java.lang.String fname,
                           boolean isMps)
                    throws java.io.IOException
read a problem from an MPS or LP file; see QSread_prob; fname may be givem as a plain file name or a "file:", "http:" url;

Returns:
returns null if the input file does contain errors
Throws:
java.io.IOException

setparam

public void setparam(int whichparam,
                     int newvalue)
              throws QSException
set the value of a specified parameter, see QSset_param

Throws:
QSException

write_basis

public void write_basis(java.lang.String filename)
                 throws QSException
write a basis to a file, see QSwrite_basis

Throws:
QSException

write_lp

public void write_lp(java.lang.String filename)
              throws java.io.IOException,
                     QSException
write the problem in LP format to a named file, see QSwrite_prob

Throws:
java.io.IOException
QSException

write_mps

public void write_mps(java.lang.String filename)
               throws java.io.IOException
write the problem to a named file, see QSwrite_prob

Throws:
java.io.IOException

write

public void write(Reporter rep,
                  boolean isMps)
           throws QSException
write the problem to Reporter's stream see QSwrite_prob

Throws:
QSException

write

public void write(java.lang.String filename,
                  boolean isMps)
           throws java.io.IOException,
                  QSException
write the problem in LP or MPS format to a named file, see QSwrite_prob

Throws:
java.io.IOException
QSException

QSopt 0.5 Alpha
QSopt Home