CONOPT
Loading...
Searching...
No Matches

Enumerations

enum class  ConoptConstraintType { ConoptConstraintType::Eq = 0 , ConoptConstraintType::GtEq , ConoptConstraintType::LtEq , ConoptConstraintType::Free }
 the constraint type More...
 
enum class  ConoptObjectiveElement { ConoptObjectiveElement::Variable = 0 , ConoptObjectiveElement::Constraint }
 the element that is used for the objective function More...
 
enum class  ConoptSense { ConoptSense::Minimize = -1 , ConoptSense::Maximize = 1 }
 the objective sense More...
 

Functions

virtual int ConoptModelData::readMatrix (double lower[], double curr[], double upper[], int vsta[], int type[], double rhs[], int esta[], int colsta[], int rowno[], double value[], int nlflag[], int numvar, int numcon, int numnz)
 loads the structure of the model into CONOPT.
 
void ConoptModelData::setProblemDimension (unsigned int numvar, unsigned int numcons, unsigned int numnz, unsigned int numnlnz)
 sets the problem dimension. This is called if the user wants to implement a custom readMatrix() method.
 
int ConoptModelData::addConstraint (ConoptConstraintType constype, double rhs, int slackstatus=-1)
 adds a constraint to the problem. The non-zero coefficients are added later
 
int ConoptModelData::addConstraint (ConoptConstraintType constype, double rhs, const std::vector< int > &varindex, const std::vector< double > &value, const std::vector< int > &nlflag, int slackstatus=-1)
 adds a constraint to the problem. The matrix non-zeros are added based on the supplied variables
 
int ConoptModelData::addVariable (double lower, double upper, double curr=0, int varstatus=-1)
 adds a variable to the model. The non-zero coefficients are added later.
 
int ConoptModelData::addVariable (double lower, double upper, const std::vector< int > &consindex, const std::vector< double > &value, const std::vector< int > &nlflag, double curr=0, int varstatus=-1)
 adds a variable to the problem. The matrix non-zeros are added based on the supplied constraints.
 
void ConoptModelData::setObjectiveElement (ConoptObjectiveElement elem, int elemindex)
 sets the index for the objective variable or constraint
 
void ConoptModelData::setOptimizationSense (ConoptSense sense)
 sets the optimisation direction.
 
void ConoptModelData::setInitialStatusOption (int inistat)
 the setting to indicate how the initial status of the variables and slack variables will be handled.
 

Detailed Description

Methods that are used to define the model to be solved by CONOPT.

There are two ways to define the model:

  1. using the traditional method by defining a ConoptModelData::readMatrix method, which is an approach similar the C API callback methods.
  2. iteratively add variables and constraints using the ConoptModelData::addConstraint and ConoptModelData::addVariable methods.

Either method achieves the same result of defining the model. However, the latter calls an internally defined readMatrix method. As such, there is a small memory and processing overhead.

Enumeration Type Documentation

◆ ConoptConstraintType

enum class ConoptConstraintType
strong

the constraint type

This is supplied when adding constraints using the ConoptModelData::addConstraint() methods.

Enumerator
Eq 

equality constraint

GtEq 

greater than or equal to constraint

LtEq 

greater than or equal to constraint

Free 

an unrestricted constraint. This is used when specifying the objective function.

Definition at line 27 of file defines.h.

◆ ConoptObjectiveElement

enum class ConoptObjectiveElement
strong

the element that is used for the objective function

This can be either a single variable or a constraint. If the objective function is a constraint, then the constraint must be added with the type ConoptConstraintType::Free.

Note
an objective element must be specified.
Enumerator
Variable 

the objective is given by a single variable

Constraint 

the objective is given by the value of an equation

Definition at line 45 of file defines.h.

◆ ConoptSense

enum class ConoptSense
strong

the objective sense

Enumerator
Minimize 

a minimisation problem (default)

Maximize 

a maximisation problem

Definition at line 56 of file defines.h.

Function Documentation

◆ readMatrix()

virtual int ConoptModelData::readMatrix ( double lower[],
double curr[],
double upper[],
int vsta[],
int type[],
double rhs[],
int esta[],
int colsta[],
int rowno[],
double value[],
int nlflag[],
int numvar,
int numcon,
int numnz )
virtual

loads the structure of the model into CONOPT.

Using the C++ interface, there are two ways to load the model into CONOPT. The first method follows the process used for the Fortran and C interfaces. This involves:

  1. setting the problem dimension by calling setProblemDimension().
  2. set the objective element (constraint or variable) by calling setObjectiveElement().
  3. set the optimisation sense by calling setOptimizationSense().
  4. implementing a readMatrix() method that loads the model using a column-oriented sparse matrix format. For more details regarding the parameters of the readMatrix() method, please see Defining the Model

The second method makes use of the convenience functions included in the C++ interface. Within the ConoptModelData the methods addConstraint() and addVariable() are provided. As such, to load the model into CONOPT, you must:

  1. write a member function for building the model.
  2. in the build model function, call addVariable() for each variable to be added to the problem.
  3. in the build model function, call addConstraint() for each constraint to be added to the problem. When adding a constraint, you should specify the variables (by index), coefficients and non-linear flags (for all nonlinear terms).
  4. set the objective element (constraint or variable) by calling setObjectiveElement().
  5. set the optimisation sense by calling setOptimizationSense(). When the solve method is called, the default readMatrix() method will be called, which will load the model into CONOPT as specified by the calls to addVariable() and addConstraint().

where:

  • LOWER: Vector of lower bounds on the variables. CONOPT will fill the vector with a special internal value that represent minus infinity or no lower bound before issuing the callback.
  • CURR: Vector of initial values of the variables. CONOPT will fill the vector with the default initial value of zero before issuing the callback.
  • UPPER: Vector of upper bounds on the variables. CONOPT will fill the vector with a special internal value that represent plus infinity or no upper bound before issuing the callback.
  • VSTA: Vector of initial status values for the variable. VSTA is only used if ConoptModelData::setInitialStatusOption was called with IniStat = 1 or 2.

    If `IniStat = 1` the value of `VSTA` must be defined as:
    - <b>0:</b> The variable is initialized non-basic (if `CURR = LOWER` or
    `CURR = UPPER`) or super-basic, and
    - <b>1:</b> The variable is initialized basic
    
    and if `IniStat = 2` the value of `VSTA` must be defined as:
    - <b>0:</b> The variable is initialized at lower bound
    - <b>1:</b> The variable is initialized at upper bound
    - <b>2:</b> The variable is initialized basic, and
    - <b>3:</b> The variable is initialized superbasic.
    

    IniStat = 1 is simple to implement by hand, while IniStat = 2 is consistent with the output status defined in the Solution callback method. Note that if the numerical value in CURR are inconsistent with the status value, the numerical values will be used.

    If IniStat = 0 (the default value) CONOPT will not use VSTA and you do not have to define it.


  • TYPE: Vector of equation types. The values of TYPE have the following meaning:

    • 0: An equality constraint.
    • 1: A greater than or equal constraint.
    • 2: A less than or equal constraint.
    • 3: A free row.

    There is no default value for TYPE so it must be defined for all constraints. Note that CONOPT does not accept ranges.


  • RHS: Vector of right hand sides values. The default value is zero.
  • ESTA: Vector of initial status values for the slacks in the constraints. ESTA is only used if ConoptModelData::setInitialStatusOption was called with IniStat = 1 or 2.

    If `IniStat = 1` the value of `ESTA` must be defined as:
    - <b>0:</b> The slack is initialized non-basic (if the constraint is binding in the initial point) or super-basic, and
    - <b>1:</b> The slack is initialized basic
    
    and if `IniStat = 2` the value of `ESTA` must be defined as:
    - <b>0:</b> The slack is initialized at lower bound.
    - <b>1:</b> The slack is initialized at upper bound.
    - <b>2:</b> The slack is initialized basic, and
    - <b>3:</b> The slack is initialized superbasic.
    

    Again, IniStat = 1 is simple to implement by hand, while IniStat = 2 is consistent with the output status defined in Solution callback method.

    If IniStat = 0 (the default value) then CONOPT will not use ESTA.

  • COLSTA: Vector of start of column pointers. All non-zero Jacobian elements must be sorted by column, i.e. all elements in column i comes before all elements in column i+1. COLSTA points to the first element in each column. If you have selected Base = 1 (Fortran conventions) then COLSTA must therefore satisfy: COLSTA(1) = 1 and COLSTA(N+1) = NZ+1. If you have selected Base = 0 (C conventions) then COLSTA must therefore satisfy: COLSTA[0] = 0 and COLSTA[N] = NZ. COLSTA must in both cases be increasing.
  • ROWNO: Vector of row or equation numbers of the non-zeros. The numbers must be in the range 1 through M inclusive if you have defined Base = 1 (Fortran conventions) and in the range 0 to M-1 inclusive if you have defined Base = 0 (C conventions). Although the columns are sorted, the rows do not have to be sorted within each column.
  • VALUE: Vector of values of the Jacobian elements. VALUE must be defined for all constant Jacobian elements, i.e. elements for which the following NLFLAG = 0. VALUE does not have to be defined for varying Jacobian elements.
  • NLFLAG: Vector of nonlinearity flags:

    • 0: The non-zero is constant, i.e. the variable appears linearly.
    • 1: The non-zero is varying, i.e. the variable appears nonlinearly

    NLFLAG is not read if the model is linear, i.e. if NLNZ = 0, otherwise it must be defined. Note that if you have an LP model, you should probably select a specialized LP algorithm instead of CONOPT.

  • N: Number of variables as defined in ConoptModelData::setProblemDimension.
  • M: Number of constraints as defined in ConoptModelData::setProblemDimension.
  • NZ: Number of Jacobian elements as defined in ConoptModelData::setProblemDimension.

The lower bounds in LOWER must be less than or equal to the upper bounds in UPPER. Some of the bounds may be -INF or +INF, which are the bounds CONOPT assigns by default. If a bound is infinite, the user should normally not change the corresponding entry in LOWER or UPPER. If it is more convenient for the modeler to assign a value representing infinity it should be done using the values that are present in LOWER and UPPER when ReadMatrix is called, for example taken from the first element before any assignments are done. As an alternative, you may define the numerical value of Infinity to be used by the solution algorithm in option RTMAXV and store the same value in UPPER and -RTMAXV in LOWER.

The values in CURR, both those defined by the modeler and those defined by default, are without warning moved to the nearest bound if they are outside the bounds.

Note
CONOPT assumes that all functions are defined for all values of the variables between their bounds. CONOPT will never attempt to evaluate the functions in points outside the bounds specified by LOWER and UPPER.

◆ setProblemDimension()

void ConoptModelData::setProblemDimension ( unsigned int numvar,
unsigned int numcons,
unsigned int numnz,
unsigned int numnlnz )

sets the problem dimension. This is called if the user wants to implement a custom readMatrix() method.

NOTE: it is not possible to call setProblemDimension() and addConstraint() or addVariable(). The latter functions can only be used if the problem dimension is not set and the default readMatrix() method is used.

Parameters
numvarthe number of variables in the problem
numconsthe number of constraints in the problem
numnzthe number of non-zeros in the constraint matrix
numnlnzthe number of nonlinear non-zeros in the constraint matrix

◆ addConstraint() [1/2]

int ConoptModelData::addConstraint ( ConoptConstraintType constype,
double rhs,
int slackstatus = -1 )

adds a constraint to the problem. The non-zero coefficients are added later

Parameters
constypethe type of constraint, 0: ==, 1: >=, 2: <=, 3: free
rhsthe right hand side
slackstatusinitial status of the slack variables, see IniStat

◆ addConstraint() [2/2]

int ConoptModelData::addConstraint ( ConoptConstraintType constype,
double rhs,
const std::vector< int > & varindex,
const std::vector< double > & value,
const std::vector< int > & nlflag,
int slackstatus = -1 )

adds a constraint to the problem. The matrix non-zeros are added based on the supplied variables

Parameters
constypethe type of constraint, 0: ==, 1: >=, 2: <=, 3: free
rhsthe right hand side
varindexthe variables this constraint has non-zero coefficients
valuethe non-zero of the variable
nlflagflag to set whether the variable belongs to a non-linear term
slackstatusinitial status of the slack variables, see IniStat

◆ addVariable() [1/2]

int ConoptModelData::addVariable ( double lower,
double upper,
double curr = 0,
int varstatus = -1 )

adds a variable to the model. The non-zero coefficients are added later.

Parameters
lowerlower bound for the variable
upperupper bound for the variable
currinitial value of the variable, can be set to 0
varstatusinitial status of the variable, see IniStat

◆ addVariable() [2/2]

int ConoptModelData::addVariable ( double lower,
double upper,
const std::vector< int > & consindex,
const std::vector< double > & value,
const std::vector< int > & nlflag,
double curr = 0,
int varstatus = -1 )

adds a variable to the problem. The matrix non-zeros are added based on the supplied constraints.

Parameters
lowerlower bound for the variable
upperupper bound for the variable
consindexthe constraints this variable has non-zero coefficients
valuethe non-zero of the variable
nlflagflag to set whether the variable belongs to a non-linear term
currinitial value of the variable, can be set to 0
varstatusinitial status of the variable, see IniStat

◆ setObjectiveElement()

void ConoptModelData::setObjectiveElement ( ConoptObjectiveElement elem,
int elemindex )

sets the index for the objective variable or constraint

◆ setOptimizationSense()

void ConoptModelData::setOptimizationSense ( ConoptSense sense)

sets the optimisation direction.

◆ setInitialStatusOption()

void ConoptModelData::setInitialStatusOption ( int inistat)

the setting to indicate how the initial status of the variables and slack variables will be handled.

The initial status is set in the addVariable() and addConstraint() methods, or in the readMatrix() method if the classical model input approach is used. By default, the value of inistat is 0, which means that the variable and slack status is ignored.

If inistat == 1: The variable status has the following behaviour:

  • 0: The variable is initialized non-basic (if curr = lower or curr = upper) or super-basic, and
  • 1: The variable is initialized basic The slack status has the following behaviour:
  • 0: The slack is initialized non-basic (if the constraint is binding in the initial point) or super-basic,
  • 1: The slack is initialized basic

If inistat == 2: The variable status has the following behaviour:

  • 0: The variable is initialized at lower bound
  • 1: The variable is initialized at upper bound
  • 2: The variable is initialized basic, and
  • 3: The variable is initialized superbasic. The slack status has the following behaviour:
  • 0: The slack is initialized at lower bound.
  • 1: The slack is initialized at upper bound.
  • 2: The slack is initialized basic, and
  • 3: The slack is initialized superbasic.