C++ API Reference

The Cardinal Optimizer provides C++ API library. This chapter documents all COPT constants, including parameters and attributes, and API functions for C++ applications.

Constants

All C++ constants are the same as C constants. Please refer to C API Reference: Constants for more details.

Attributes

All C++ attributes are the same as C attributes. Please refer to C API Reference: Attributes for more details.

In the C++ API, user can get the attribute value by specifying the attribute name. The provided functions are as follows, please refer to C++ API: Model Class for details.

  • Model::GetIntAttr() : Get value of a COPT integer attribute.

  • Model::GetDblAttr() : Get value of a COPT double attribute.

Parameters

All C++ parameters are the same as C parameters. Please refer to C API Reference: Parameters for more details.

In the C++ API, user can get and set the parameter value by specifying the parameter name. The provided functions are as follows, please refer to C++ Model class for details.

  • Get detailed information of the specified parameter (current value/max/min): Model::GetParamInfo()

  • Get the current value of the specified integer/double parameter: Model::GetIntParam() / Model::GetDblParam()

  • Set the specified integer/double parameter value: Model::SetIntParam() / Model::SetDblParam()

C++ Modeling Classes

This chapter documents COPT C++ interface. Users may refer to C++ classes described below for details of how to construct and solve C++ models.

Envr

Essentially, any C++ application using Cardinal Optimizer should start with a COPT environment. COPT models are always associated with a COPT environment. User must create an environment object before populating models. User generally only need a single environment object in program.

EnvrConfig

If user connects to COPT remote services, such as floating token server or compute cluster, it is necessary to add config settings with EnvrConfig object.

Model

In general, a COPT model consists of a set of variables, a (linear) objective function on these variables, a set of constraints on there varaibles, etc. COPT model class encapsulates all required methods for constructing a COPT model.

Var

COPT variable object. Variables are always associated with a particular model. User creates a variable object by adding a variable to a model, rather than by using constructor of Var class.

VarArray

COPT variable array object. To store and access a set of C++ Var objects, Cardinal Optimizer provides C++ VarArray class, which defines the following methods.

Expr

COPT linear expression object. A linear expression consists of a constant term, a list of terms of variables and associated coefficients. Linear expressions are used to build constraints.

Constraint

COPT constraint object. Constraints are always associated with a particular model. User creates a constraint object by adding a constraint to a model, rather than by using constructor of Constraint class.

ConstrArray

COPT constraint array object. To store and access a set of C++ Constraint objects, Cardinal Optimizer provides C++ ConstrArray class, which defines the following methods.

ConstrBuilder

COPT constraint builder object. To help building a constraint, given a linear expression, constraint sense and right-hand side value, Cardinal Optimizer provides C++ ConstrBuilder class, which defines the following methods.

ConstrBuilderArray

COPT constraint builder array object. To store and access a set of C++ ConstrBuilder objects, Cardinal Optimizer provides C++ ConstrBuilderArray class, which defines the following methods.

Column

COPT column object. A column consists of a list of constraints and associated coefficients. Columns are used to represent the set of constraints in which a variable participates, and the asssociated coefficents.

ColumnArray

COPT column array object. To store and access a set of C++ Column objects, Cardinal Optimizer provides C++ ColumnArray class, which defines the following methods.

Sos

COPT SOS constraint object. SOS constraints are always associated with a particular model. User creates an SOS constraint object by adding an SOS constraint to a model, rather than by using constructor of Sos class.

An SOS constraint can be type 1 or 2 (COPT_SOS_TYPE1 or COPT_SOS_TYPE2).

SosArray

COPT SOS constraint array object. To store and access a set of C++ Sos objects, Cardinal Optimizer provides C++ SosArray class, which defines the following methods.

SosBuilder

COPT SOS constraint builder object. To help building an SOS constraint, given the SOS type, a set of variables and associated weights, Cardinal Optimizer provides C++ SosBuilder class, which defines the following methods.

SosBuilderArray

COPT SOS constraint builder array object. To store and access a set of C++ SosBuilder objects, Cardinal Optimizer provides C++ SosBuilderArray class, which defines the following methods.

GenConstr

COPT general constraint object. General constraints are always associated with a particular model. User creates a general constraint object by adding a general constraint to a model, rather than by using constructor of GenConstr class.

GenConstrArray

COPT general constraint array object. To store and access a set of C++ GenConstr objects, Cardinal Optimizer provides C++ GenConstrArray class, which defines the following methods.

GenConstrBuilder

COPT general constraint builder object. To help building a general constraint, given a binary variable and associated value, a linear expression and constraint sense, Cardinal Optimizer provides C++ GenConstrBuilder class, which defines the following methods.

GenConstrBuilderArray

COPT general constraint builder array object. To store and access a set of C++ GenConstrBuilder objects, Cardinal Optimizer provides C++ GenConstrBuilderArray class, which defines the following methods.

Cone

COPT cone constraint object. Cone constraints are always associated with a particular model. User creates a cone constraint object by adding a cone constraint to a model, rather than by using constructor of Cone class.

A cone constraint can be regular or rotated (COPT_CONE_QUAD or COPT_CONE_RQUAD).

ConeArray

COPT cone constraint array object. To store and access a set of C++ Cone objects, Cardinal Optimizer provides C++ ConeArray class, which defines the following methods.

ConeBuilder

COPT cone constraint builder object. To help building a cone constraint, given the cone type and a set of variables, Cardinal Optimizer provides C++ ConeBuilder class, which defines the following methods.

ConeBuilderArray

COPT cone constraint builder array object. To store and access a set of C++ ConeBuilder objects, Cardinal Optimizer provides C++ ConeBuilderArray class, which defines the following methods.

QuadExpr

COPT quadratic expression object. A quadratic expression consists of a linear expression, a list of variable pairs and associated coefficients of quadratic terms. Quadratic expressions are used to build quadratic constraints and objectives.

QConstraint

COPT quadratic constraint object. Quadratic constraints are always associated with a particular model. User creates a quadratic constraint object by adding a quadratic constraint to a model, rather than by using constructor of QConstraint class.

QConstrArray

COPT quadratic constraint array object. To store and access a set of C++ QConstraint objects, Cardinal Optimizer provides C++ QConstrArray class, which defines the following methods.

QConstrBuilder

COPT quadratic constraint builder object. To help building a quadratic constraint, given a quadratic expression, constraint sense and right-hand side value, Cardinal Optimizer provides C++ QConstrBuilder class, which defines the following methods.

QConstrBuilderArray

COPT quadratic constraint builder array object. To store and access a set of C++ QConstrBuilder objects, Cardinal Optimizer provides C++ QConstrBuilderArray class, which defines the following methods.

PsdVar

COPT PSD variable object. PSD variables are always associated with a particular model. User creates a PSD variable object by adding a PSD variable to model, rather than by constructor of PsdVar class.

PsdVarArray

COPT PSD variable array object. To store and access a set of PsdVar objects, Cardinal Optimizer provides PsdVarArray class, which defines the following methods.

PsdExpr

COPT PSD expression object. A PSD expression consists of a linear expression, a list of PSD variables and associated coefficient matrices of PSD terms. PSD expressions are used to build PSD constraints and objectives.

PsdConstraint

COPT PSD constraint object. PSD constraints are always associated with a particular model. User creates a PSD constraint object by adding a PSD constraint to model, rather than by constructor of PsdConstraint class.

PsdConstrArray

COPT PSD constraint array object. To store and access a set of PsdConstraint objects, Cardinal Optimizer provides PsdConstrArray class, which defines the following methods.

PsdConstrBuilder

COPT PSD constraint builder object. To help building a PSD constraint, given a PSD expression, constraint sense and right-hand side value, Cardinal Optimizer provides PsdConstrBuilder class, which defines the following methods.

PsdConstrBuilderArray

COPT PSD constraint builder array object. To store and access a set of PsdConstrBuilder objects, Cardinal Optimizer provides PsdConstrBuilderArray class, which defines the following methods.

SymMatrix

COPT symmetric matrix object. Symmetric matrices are always associated with a particular model. User creates a symmetric matrix object by adding a symmetric matrix to model, rather than by constructor of SymMatrix class.

Symmetric matrices are used as coefficient matrices of PSD terms in PSD expressions, PSD constraints or PSD objectives.

SymMatrixArray

COPT symmetric matrix object. To store and access a set of SymMatrix objects, Cardinal Optimizer provides SymMatrixArray class, which defines the following methods.

SymMatExpr

COPT symmetric matrix expression object. A symmetric matrix expression is a linear combination of symmetric matrices, which is still a symmetric matrix. However, by doing so, we are able to delay computing the final matrix until setting PSD constraints or PSD objective.

ProbBuffer

Buffer object for COPT problem. ProbBuffer object holds the (MPS) problem in string format.