ilog.cplex.example
Class CpxProblem

java.lang.Object
  |
  +--ilog.cplex.example.CpxProblem

public class CpxProblem
extends java.lang.Object

Cplex solver and problem class. Each object of this class will allocate its own CPXLP and CPXENV object. As a consequence each object grabs its own license which is freed only upon destruction of the CpxProblem Java object. Since this may occur any time when the Java garbage collector decides to, it is advised to call method CpxProblem.dispose() explicitly. The user is assumed to be familiar with the C callable library.


Field Summary
static char Continuous
          constant for continuous variable type
static char Equal
          constant for equality constraint sense
static char GreaterEqual
          constant for greater or equal constraint sense
static double Infinity
          constant for inifinity bounds.
static char Integer
          constant for integer variable type
static char LessEqual
          constant for less or equal constraint sense
static int Maximize
          constant for maximiztion objective sense
static int Minimize
          constant for minimzation objective sense
 
Constructor Summary
CpxProblem()
          Creates one CPLEX solver and problem representation object.
 
Method Summary
 void addCols(double[] obj, CpxSparseVector[] cols, double[] lb, double[] ub, char[] type)
          Add columns to the problem stored in the CpxProblem object.
 void addRows(CpxSparseVector[] rows, char[] senses, double[] rhs)
          Add rows to the problem stored in the CpxProblem object.
 void baropt()
          Call the barrier algorithm to optimize the problem in the CpxProblem object.
 void dispose()
          Destructor.
 void dualopt()
          Call the dual simplex algorithm to optimize the problem in the CpxProblem object.
protected  void finalize()
           
 void getBase(int[] cstat, int[] rstat)
          Obtain basis information of the current solution.
 double getDblQuality(int which)
          Obtain double-valued quality information about the current solution.
 void getDj(double[] x)
          Obtain the reduced cost vector of the current solution.
 int getIntQuality(int which)
          Obtain integer-valued quality information about the current solution.
 int getItcnt()
          return the number of iteration from the last simplex run.
 int getNCols()
          return the number of columns of the problem stored in the CpxProblem object.
 int getNRows()
          return the number of rows of the problem stored in the CpxProblem object.
 double getObj()
          return the objective value of the solution currently stored in the CpxProblem object.
 void getPi(double[] x)
          Obtain the dual solution vector of the current solution.
 void getSlack(double[] x)
          Obtain the vector of slack values for the current solution.
 int getStatus()
          return the current solution status.
 void getX(double[] x)
          Obtain the primal solution vector of the current solution.
 void hybbaropt()
          Call the barrier algorithm followed by primal crossover to optimize the problem in the CpxProblem * object.
 void hybnetopt()
          Call the network simplex algorithm followed by dual simplex to optimize the problem in the CpxProblem object.
 void mipopt()
          Call the MIP optimizer to solve the problem in the CpxProblem object.
 void primopt()
          Call the primal simplex algorithm to optimize the problem in the CpxProblem object.
 void read(java.lang.String file)
          Read an LP, MPS or SAV file from the file system.
 void setCoefs(int[] rind, int[] cind, double[] val)
          Set nonzero coefficients in the problem stored in the CpxProblem object.
 void setObjSense(int sense)
          return the objective sense of the problem stored in the CpxProblem object.
 void setParam(int which, double value)
          Set a CPLEX double-valued paramter.
 void setParam(int which, int value)
          Set a CPLEX integer-valued paramter.
 void write(java.lang.String file)
          Write a LP, MPS or SAV format file to the file system.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Infinity

public static final double Infinity
constant for inifinity bounds.

Minimize

public static final int Minimize
constant for minimzation objective sense

Maximize

public static final int Maximize
constant for maximiztion objective sense

Equal

public static final char Equal
constant for equality constraint sense

LessEqual

public static final char LessEqual
constant for less or equal constraint sense

GreaterEqual

public static final char GreaterEqual
constant for greater or equal constraint sense

Integer

public static final char Integer
constant for integer variable type

Continuous

public static final char Continuous
constant for continuous variable type
Constructor Detail

CpxProblem

public CpxProblem()
           throws CpxException
Creates one CPLEX solver and problem representation object. The CPLEX object are created as C object that are linked to Java through JNI (the Java Native Interface). Hence, CpxProblem objects can only be created on machines that have libjavacplex65.so or javacplex65.dll installed on UNIX or Windows plattforms, respectively. A valid CPLEX license must also exist on the machine.
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object

dispose

public void dispose()
             throws java.lang.Throwable
Destructor. It is advised to call this function explicitly to destroy a CpxProblem object, rather than relying on the Java garbage collector to call the destructor at some arbirary time in the future. Calling it explicitly will ensure that the CPLEX license is released at this time.

read

public void read(java.lang.String file)
          throws CpxException
Read an LP, MPS or SAV file from the file system.
Parameters:
file - the name of the file to be read.

write

public void write(java.lang.String file)
           throws CpxException
Write a LP, MPS or SAV format file to the file system.
Parameters:
file - the name of the file to be written. The extension of the file name determines what format the file will be written in.

dualopt

public void dualopt()
             throws CpxException
Call the dual simplex algorithm to optimize the problem in the CpxProblem object. The loaded problem must not contain any integer variables.

primopt

public void primopt()
             throws CpxException
Call the primal simplex algorithm to optimize the problem in the CpxProblem object. The loaded problem must not contain any integer variables.

baropt

public void baropt()
            throws CpxException
Call the barrier algorithm to optimize the problem in the CpxProblem object. The loaded problem must not contain any integer variables.

hybbaropt

public void hybbaropt()
               throws CpxException
Call the barrier algorithm followed by primal crossover to optimize the problem in the CpxProblem * object. The loaded problem must not contain any integer variables.

hybnetopt

public void hybnetopt()
               throws CpxException
Call the network simplex algorithm followed by dual simplex to optimize the problem in the CpxProblem object. The loaded problem must not contain any integer variables.

mipopt

public void mipopt()
            throws CpxException
Call the MIP optimizer to solve the problem in the CpxProblem object. The loaded problem must contain at least one integer variable.

getObj

public double getObj()
              throws CpxException
return the objective value of the solution currently stored in the CpxProblem object.

getItcnt

public int getItcnt()
             throws CpxException
return the number of iteration from the last simplex run.

getStatus

public int getStatus()
              throws CpxException
return the current solution status.

getNCols

public int getNCols()
             throws CpxException
return the number of columns of the problem stored in the CpxProblem object.

getNRows

public int getNRows()
             throws CpxException
return the number of rows of the problem stored in the CpxProblem object.

setObjSense

public void setObjSense(int sense)
                 throws CpxException
return the objective sense of the problem stored in the CpxProblem object.

addRows

public void addRows(CpxSparseVector[] rows,
                    char[] senses,
                    double[] rhs)
             throws CpxException
Add rows to the problem stored in the CpxProblem object.
Parameters:
rows - an array of sparse vectors containing the column indices and associated nonzero coefficients of the rows to be added.
senses - an array of characters CpxProblem.Equal, CpxProblem.LessEqual, or CpxProblem.GreaterEqual that indicate the constraint sense of the rows to be added.
rhs - an array of right hand side values for the rows to be added.

addCols

public void addCols(double[] obj,
                    CpxSparseVector[] cols,
                    double[] lb,
                    double[] ub,
                    char[] type)
             throws CpxException
Add columns to the problem stored in the CpxProblem object.
Parameters:
obj - an array of objective value coefficients for the columns to be added.
cols - an array of sparse vectors containing the row indices and associated nonzero coefficients of the columns to be added.
lb - an array of lower bound values for the columns to be added.
ub - an array of upper bound values for the columns to be added.
type - an array of variable type characters CpxProblem.Integer or CpxProblem.Continous for the columns to be added.

setCoefs

public void setCoefs(int[] rind,
                     int[] cind,
                     double[] val)
              throws CpxException
Set nonzero coefficients in the problem stored in the CpxProblem object.
Parameters:
rind - an array of row indices for the coefficients to be set.
cind - an array of column indices for the coefficients to be set.
val - an array of values for the coefficients to be set.

getBase

public void getBase(int[] cstat,
                    int[] rstat)
             throws CpxException
Obtain basis information of the current solution.
Parameters:
cstat - an array where the column status values are copied to.
rstat - an array where the row status values are copied to.

getX

public void getX(double[] x)
          throws CpxException
Obtain the primal solution vector of the current solution.
Parameters:
x - an array where the primal solution values are copied to.

getPi

public void getPi(double[] x)
           throws CpxException
Obtain the dual solution vector of the current solution.
Parameters:
x - an array where the dual solution values are copied to.

getDj

public void getDj(double[] x)
           throws CpxException
Obtain the reduced cost vector of the current solution.
Parameters:
x - an array where the reduced cost values are copied to.

getSlack

public void getSlack(double[] x)
              throws CpxException
Obtain the vector of slack values for the current solution.
Parameters:
x - an array where the slack values are copied to.

getDblQuality

public double getDblQuality(int which)
                     throws CpxException
Obtain double-valued quality information about the current solution.
Parameters:
which - an integer indicating the type of information to be returned.

getIntQuality

public int getIntQuality(int which)
                  throws CpxException
Obtain integer-valued quality information about the current solution.
Parameters:
which - an integer indicating the type of information to be returned.

setParam

public void setParam(int which,
                     int value)
              throws CpxException
Set a CPLEX integer-valued paramter.
Parameters:
which - an integer indicating the integer parameter to be set.
value - the new parameter value.

setParam

public void setParam(int which,
                     double value)
              throws CpxException
Set a CPLEX double-valued paramter.
Parameters:
which - an integer indicating the double parameter to be set.
value - the new parameter value.