C API Reference
The Cardinal Optimizer provides a C API library for advanced usage.
This section documents all the COPT constants,
API functions, parameters and attributes listed in copt.h
.
Constants
There are three types of constants.
Constructing models, such as optimization directions, constraint senses or variable types.
Accessing solution results, such as API return code, basis status and LP status.
Monitoring optimization progress, such as callback context.
Optimization directions
For different optimization scenarios, it may be required to either maximize or minimize the objective function. There are two optimization directions:
COPT_MINIMIZE
For minimizing the objective function.
COPT_MAXIMIZE
For maximizing the objective function.
The optimization direction is automatically
set when reading in a problem from file.
It can also be set explicitly using COPT_SetObjSense
.
Infinity
In COPT, the infinite bound is represented by a large value,
which can be set using the double parameter
COPT_DBLPARAM_INFBOUND
,
whose default value is also available as a constant:
COPT_INFINITY
The default value (
1e30
) of the infinite bound.
Undefined Value
In COPT, the undefined value is represented by another large value. For example, the default solution value of MIP start is set to a constant:
COPT_UNDEFINED
Undefined value(
1e40`
).
Constraint senses
NOTE: Using constraint senses is supported by COPT but not recommended. We recommend defining constraints using explicit lower and upper bounds.
Traditionally, for optimization models, constraints are defined using senses. The most common constraint senses are:
COPT_LESS_EQUAL
For constraint in the form of \(g(x) \leq b\)
COPT_GREATER_EQUAL
For constraint in the form of \(g(x) \geq b\)
COPT_EQUAL
For constraint in the form of \(g(x) = b\)
In additional, there are two less used constraint senses:
COPT_FREE
For unconstrained expression
COPT_RANGE
For constraints with both lower and upper bounds in the form of \(l \leq g(x) \leq u\).
Please refer to documentation of
COPT_LoadProb
regarding how to useCOPT_RANGE
to define a constraints with both lower and upper bounds.
Variable types
Variable types are used for defining whether a variable is continuous or integral.
COPT_CONTINUOUS
Non-integer continuous variables
COPT_BINARY
Binary variables
COPT_INTEGER
Integer variables
SOS-constraint types
SOS constraint (Special Ordered Set) is a kind of special constraint that places restrictions on the values that a set of variables can take.
COPT currently support two types of SOS constraints, one is SOS1 constraint, where at most one variable in the constraint is allowed to take a non-zero value, the other is SOS2 constraint, where at most two variables in the constraint are allowed to take non-zero value, and those non-zero variables must be contiguous. Variables in SOS constraints are allowed to be continuous, binary and integer.
COPT_SOS_TYPE1
SOS1 constraint
COPT_SOS_TYPE2
SOS2 constraint
Indicator constraint
Indicator constraint is a kind of logical constraints in COPT, used to describe the relationship between the value of the binary variable \(y\) and whether the linear constraint \(a^{T}x \leq b\) is satisfied. Currently, COPT supports three types of indicator constraints:
COPT_INDICATOR_IF
If-Then:
If \(y=f\) , then the linear constraint \(a^{T}x \leq b\) is satisfied.
If \(y\ne f\) , then the linear constraint \(a^{T}x \leq b\) is invalid (may be violated).
COPT_INDICATOR_ONLYIF
Only-If:
If the linear constraint \(a^{T}x \leq b\) is satisfied, then \(y=f\) .
If the linear constraint \(a^{T}x \leq b\) is not satisfied, then \(y\) can be 0 or 1.
COPT_INDICATOR_IFANDONLYIF
If-and-Only-If:
The linear constraint \(a^{T}x \leq b\) and \(y=f\) must be satisfied simultaneously or not satisfied simultaneously.
SOC constraint type
The Second-Order-Cone (SOC) constraint is a special type of quadratic constraints. COPT supports two types of SOC constraints:
COPT_CONE_QUAD
: Regular Second-Order-Cone
COPT_CONE_RQUAD
: Rotated Second-Order-Cone
Exponential cone constraint type
COPT supports two types of exponential cone contraints:
COPT_EXPCONE_PRIMAL
: Primal exponential cone
COPT_EXPCONE_DUAL
: Dual exponential cone
Quadratic objective function
Besides linear objective function, COPT also supports general convex quadratic objective function.
The mathematical form is:
Where, \(x\) is an array of variables, \(Q\) is the quadratic part of the quadratic objective funtion and \(c\) is the linear part.
Quadratic constraint
Besides the special type of quadratic constraint, Second-Order-Cone (SOC) constraint, COPT also supports general convex quadratic constraint.
The mathematical form is:
Where, \(x\) is an array of variables, \(Q\) is the quadratic part of the quadratic constraint and \(c\) is the linear part.
Basis status
For an LP problem with \(n\) variables and \(m\) constraints, the constraints are treated as slack variables internally, resulting in \(n+m\) variables. When solving an LP problem using the simplex method, the simplex method fixes \(n\) variables at one of their bounds, and then computes solutions for the other \(m\) variables. The \(m\) variables with computed solution are called basic variables, and the other \(n\) variables are called non-basic variables. The simplex progress and its final solution can be defined using the basis status of all the variables and constraints.
The basis status supported by COPT are:
COPT_BASIS_LOWER
The variable is non-basic at its lower bound.
COPT_BASIS_BASIC
The variable is basic.
COPT_BASIS_UPPER
The variable is non-basic at its upper bound.
COPT_BASIS_SUPERBASIC
The variable is non-basic but not any of its bounds.
COPT_BASIS_FIXED
The variable is non-basic and fixed at its bound.
LP solution status
The solution status of an LP problem is called LP status,
which can be obtained using integer attribute
COPT_INTATTR_LPSTATUS
.
Possible LP status values are:
COPT_LPSTATUS_UNSTARTED
The LP optimization is not started yet.
COPT_LPSTATUS_OPTIMAL
The LP problem is solved to optimality.
COPT_LPSTATUS_INFEASIBLE
The LP problem is infeasible.
COPT_LPSTATUS_UNBOUNDED
The LP problem is unbounded.
COPT_LPSTATUS_NUMERICAL
Numerical trouble encountered.
COPT_LPSTATUS_TIMEOUT
The LP optimization is stopped because of time limit.
COPT_LPSTATUS_UNFINISHED
The LP optimization is stopped but the solver cannot provide a solution because of numerical difficulties.
COPT_LPSTATUS_IMPRECISE
The solution is imprecise.
COPT_LPSTATUS_INTERRUPTED
The LP optimization is stopped by user interrupt.
MIP solution status
The solution status of an MIP problem is called MIP status,
which can be obtained using integer attribute
COPT_INTATTR_MIPSTATUS
.
Possible MIP status values are:
COPT_MIPSTATUS_UNSTARTED
The MIP optimization is not started yet.
COPT_MIPSTATUS_OPTIMAL
The MIP problem is solved to optimality.
COPT_MIPSTATUS_INFEASIBLE
The MIP problem is infeasible.
COPT_MIPSTATUS_UNBOUNDED
The MIP problem is unbounded.
COPT_MIPSTATUS_INF_OR_UNB
The MIP problem is infeasible or unbounded.
COPT_MIPSTATUS_NODELIMIT
The MIP optimization is stopped because of node limit.
COPT_MIPSTATUS_TIMEOUT
The MIP optimization is stopped because of time limit.
COPT_MIPSTATUS_UNFINISHED
The MIP optimization is stopped but the solver cannot provide a solution because of numerical difficulties.
COPT_MIPSTATUS_INTERRUPTED
The MIP optimization is stopped by user interrupt.
Callback context
CBCONTEXT_INCUMBENT
Invokes the callback after a new incumbent was found.
COPT_CBCONTEXT_MIPNODE
Invokes the callback after a MIP node was processed.
COPT_CBCONTEXT_MIPRELAX
Invokes the callback when an LP-relaxation was solved.
COPT_CBCONTEXT_MIPSOL
Invokes the callback when a new MIP candidate solution is found.
API function return code
When an API function finishes, it returns an integer return code, which indicates whether the API call was finished okay or failed. In case of failure, it specifies the reason of the failure.
Possible COPT API function return codes are:
COPT_RETCODE_OK
The API call finished successfully.
COPT_RETCODE_MEMORY
The API call failed because of memory allocation failure.
COPT_RETCODE_FILE
The API call failed because of file input or output failure.
COPT_RETCODE_INVALID
The API call failed because of invalid data.
COPT_RETCODE_LICENSE
The API call failed because of license validation failure. In this case, further information can be obtained by calling
COPT_GetLicenseMsg
.COPT_RETCODE_INTERNAL
The API call failed because of internal error.
COPT_RETCODE_THREAD
The API call failed because of thread error.
COPT_RETCODE_SERVER
The API call failed because of remote server error.
COPT_RETCODE_NONCONVEX
The API call failed because of problem is nonconvex.
Client configuration
For floating and cluster clients, users are allowed to set client configuration parameters, currently available settings are:
COPT_CLIENT_CLUSTER
IP address of cluster server.
COPT_CLIENT_FLOATING
IP address of token server.
COPT_CLIENT_PASSWORD
Password of cluster server.
COPT_CLIENT_PORT
Connection port of token server.
COPT_CLIENT_WAITTIME
Wait time of client.
Other constants
COPT_BUFFSIZE
Defines the recommended buffer size when obtaining a C-style string message from COPT library. This can be used with, for example,
COPT_GetBanner
,COPT_GetRetcodeMsg
etc.
Attributes
Problem information
COPT_INTATTR_COLS
or"Cols"
Integer attribute.
Number of variables (columns) in the problem.
COPT_INTATTR_PSDCOLS
or"PSDCols"
Integer attribute.
Number of PSD variables in the problem.
COPT_INTATTR_ROWS
or"Rows"
Integer attribute.
Number of constraints (rows) in the problem.
COPT_INTATTR_ELEMS
or"Elems"
Integer attribute.
Number of non-zero elements in the coefficient matrix.
COPT_INTATTR_QELEMS
or"QElems"
Integer attribute.
Number of non-zero quadratic elements in the quadratic objective function.
COPT_INTATTR_PSDELEMS
or"PSDElems"
Integer attribute.
Number of PSD terms in objective function.
COPT_INTATTR_SYMMATS
or"SymMats"
Integer attribute.
Number of symmetric matrices in the problem.
COPT_INTATTR_BINS
or"Bins"
Integer attribute.
Number of binary variables.
COPT_INTATTR_INTS
or"Ints"
Integer attribute.
Number of integer variables.
COPT_INTATTR_SOSS
or"Soss"
Integer attribute.
Number of SOS constraints.
COPT_INTATTR_CONES
or"Cones"
Integer attribute.
Number of Second-Order-Cone constraints.
COPT_INTATTR_EXPCONES
or"ExpCones"
Integer attribute.
Number of exponential cone constraints.
COPT_INTATTR_AFFINECONES
or"AffineCones"
Integer attribute.
Number of affine cone constraints.
COPT_INTATTR_QCONSTRS
or"QConstrs"
Integer attribute.
Number of quadratic constraints.
COPT_INTATTR_PSDCONSTRS
or"PSDConstrs"
Integer attribute.
Number of PSD constraints.
COPT_INTATTR_LMICONSTRS
or"LMIConstrs"
Integer attribute.
Number of LMI constraints.
COPT_INTATTR_INDICATORS
or"Indicators"
Integer attribute.
Number of indicator constraints.
COPT_INTATTR_OBJSENSE
or"ObjSense"
Integer attribute.
The optimization direction.
COPT_DBLATTR_OBJCONST
or"ObjConst"
Double attribute.
The constant part of the objective function.
COPT_INTATTR_HASQOBJ
or"HasQObj"
Integer attribute.
Whether the problem has quadratic objective function.
COPT_INTATTR_HASPSDOBJ
or"HasPSDObj"
Integer attribute.
Whether the problem has PSD terms in objective function.
COPT_INTATTR_ISMIP
or"IsMIP"
Integer attribute.
Whether the problem is a MIP.
Solution information
COPT_INTATTR_LPSTATUS
or"LpStatus"
Integer attribute.
The LP status. Please refer to Constants: LP solution status for possible values.
COPT_INTATTR_MIPSTATUS
or"MipStatus"
Integer attribute.
The MIP status. Please refer to Constants: MIP solution status for possible values.
COPT_INTATTR_SIMPLEXITER
or"SimplexIter"
Integer attribute.
Number of simplex iterations performed.
COPT_INTATTR_BARRIERITER
or"BarrierIter"
Integer attribute.
Number of barrier iterations performed.
COPT_INTATTR_NODECNT
or"NodeCnt"
Integer attribute.
Number of explored nodes.
COPT_INTATTR_POOLSOLS
or"PoolSols"
Integer attribute.
Number of solutions in solution pool.
COPT_INTATTR_TUNERESULTS
or"TuneResults"
Integer attribute.
Number of parameter tuning results
COPT_INTATTR_HASLPSOL
or"HasLpSol"
Integer attribute.
Whether LP solution is available.
COPT_INTATTR_HASBASIS
or"HasBasis"
Integer attribute.
Whether LP basis is available.
COPT_INTATTR_HASDUALFARKAS
or"HasDualFarkas"
Integer attribute.
Whether the dual Farkas of an infeasible LP problem is available.
COPT_INTATTR_HASPRIMALRAY
or"HasPrimalRay"
Integer attribute.
Whether the primal ray of an unbounded LP problem is available.
COPT_INTATTR_HASMIPSOL
or"HasMipSol"
Integer attribute.
Whether MIP solution is available.
COPT_INTATTR_IISCOLS
or"IISCols"
Integer attribute.
Number of bounds of columns in IIS.
COPT_INTATTR_IISROWS
or"IISRows"
Integer attribute.
Number of rows in IIS.
COPT_INTATTR_IISSOSS
or"IISSOSs"
Integer attribute.
Number of SOS constraints in IIS.
COPT_INTATTR_IISINDICATORS
or"IISIndicators"
Integer attribute.
Number of indicator constraints in IIS.
COPT_INTATTR_HASIIS
or"HasIIS"
Integer attribute.
Whether IIS is available.
COPT_INTATTR_HASFEASRELAXSOL
or"HasFeasRelaxSol"
Integer attribute.
Whether feasibility LP-relaxation solution is available.
COPT_INTATTR_ISMINIIS
or"IsMinIIS"
Integer attribute.
Whether the computed IIS is minimal.
COPT_DBLATTR_LPOBJVAL
or"LpObjval"
Double attribute.
The LP objective value.
COPT_DBLATTR_BESTOBJ
or"BestObj"
Double attribute.
Best integer objective value for MIP.
COPT_DBLATTR_BESTBND
or"BestBnd"
Double attribute.
Best bound for MIP.
COPT_DBLATTR_BESTGAP
or"BestGap"
Double attribute.
Best relative gap for MIP.
COPT_DBLATTR_FEASRELAXOBJ
orFeasRelaxObj
Double attribute.
Feasibility relaxation objective value.
COPT_DBLATTR_SOLVINGTIME
or"SolvingTime"
Double attribute.
The time spent for the optimization (in seconds).
Information
Problem information
COPT_DBLINFO_OBJ
or"Obj"
Double information.
Objective cost of columns.
COPT_DBLINFO_LB
or"LB"
Double information.
Lower bounds of columns or rows.
COPT_DBLINFO_UB
or"UB"
Double information.
Upper bounds of columns or rows.
Solution information
COPT_DBLINFO_VALUE
or"Value"
Double information.
Solution of columns.
COPT_DBLINFO_SLACK
or"Slack"
Double information.
Solution of slack variables, also known as activities of constraints. Only available for LP problem.
COPT_DBLINFO_DUAL
or"Dual"
Double information.
Solution of dual variables. Only available for LP problem.
COPT_DBLINFO_REDCOST
or"RedCost"
Double information.
Reduced cost of columns. Only available for LP problem.
Dual Farkas and primal ray
Advanced topic. When an LP is infeasible or unbounded, the solver can return the dual Farkas or primal ray to prove it.
COPT_DBLINFO_DUALFARKAS
or"DualFarkas"
Double information.
The dual Farkas for constraints of an infeasible LP problem. Please enable the parameter
"ReqFarkasRay"
to ensure that the dual Farkas is available when the LP is infeasible.Without loss of generality, the concept of the dual Farkas can be conveniently demonstrated using an LP problem with general variable bounds and equality constraints: \(Ax = 0 \text{ and } l \leq x \leq u\). When the LP is infeasible, a dual Farkas vector \(y\) can prove that the system has conflict that \(\max y^TAx < y^T b = 0\). Computing \(\max y^TAx\): with the vector \(\hat{a} = y^TA\), choosing variable bound \(x_i = l_i\) when \(\hat{a}_i < 0\) and \(x_i = u_i\) when \(\hat{a}_i > 0\) gives the maximal possible value of \(y^TAx\) for any \(x\) within their bounds.
Some application relies on the alternate conflict \(\min \bar{y}^TAx > \bar{y}^T b = 0\). This can be achieved by negating the dual Farkas, i.e. \(\bar{y}=-y\) returned by the solver.
In very rare cases, the solver may fail to return a valid dual Farkas. For example when the LP problem slightly infeasible by tiny amount, which We recommend to study and to repair the infeasibility using FeasRelax instead.
COPT_DBLINFO_PRIMALRAY
or"PrimalRay"
Double information.
The primal ray for variables of an unbounded LP problem. Please enable the parameter
"ReqFarkasRay"
to ensure that the primal ray is available when an LP is unbounded.For a minimization LP problem in the standard form: \(\min c^T x, Ax = b \text{ and } x \geq 0\), a primal ray vector \(r\) satisfies that \(r \geq 0, Ar = 0 \text{ and } c^T r < 0\).
Feasibility relaxation information
COPT_DBLINFO_RELAXLB
or"RelaxLB"
Double information.
Feasibility relaxation values for lower bounds of columns or rows.
COPT_DBLINFO_RELAXUB
or"RelaxUB"
Double information.
Feasibility relaxation values for upper bounds of columns or rows.
COPT_DBLINFO_RELAXVALUE
or"RelaxValue"
Double information.
Solutions for the original model variables (columns) in the feasibility relaxation model.
Callback information
COPT_CBINFO_BESTOBJ
or"BestObj"
Double information.
Current best objective.
COPT_CBINFO_BESTBND
or"BestBnd"
Double information.
Current best objective bound.
COPT_CBINFO_HASINCUMBENT
or"HasIncumbent"
Integer information.
Whether an incumbent is available.
COPT_CBINFO_INCUMBENT
or"Incumbent"
Double information.
Current best feasible solution.
COPT_CBINFO_MIPCANDIDATE
or"MipCandidate"
Double information.
Current feasible solution candidate.
COPT_CBINFO_MIPCANDOBJ
or"MipCandObj"
Double information.
Objective value for current feasible solution candidate.
COPT_CBINFO_RELAXSOLUTION
or"RelaxSolution"
Double information.
Current solution of LP-relaxation.
COPT_CBINFO_RELAXSOLOBJ
or"RelaxSolObj"
Double information.
Current objective of LP-relaxation.
COPT_CBINFO_NODESTATUS
or"NodeStatus"
Integer information.
The solution status of the LP-relaxation problem at the current node.
For possible values, please refer to: General Constants Chapter: Solution Status (Part), except for
NODELIMIT
,UNSTARTED
,INF_OR_UNB
.
Parameters
Limits and tolerances
COPT_DBLPARAM_TIMELIMIT
or"TimeLimit"
Double parameter.
Time limit of the optimization.
Default: 1e20
Minimal: 0
Maximal: 1e20
COPT_DBLPARAM_SOLTIMELIMIT
or"SolTimeLimit"
Double parameter.
Time limit if a primal feasible solution has been found.
Default: 1e20
Minimal: 0
Maximal: 1e20
COPT_INTPARAM_NODELIMIT
or"NodeLimit"
Integer parameter.
Node limit of the optimization.
Default: -1
Minimal: -1
Maximal:
INT_MAX
COPT_INTPARAM_BARITERLIMIT
or"BarIterLimit"
Integer parameter.
Iteration limit of barrier method.
Default: 500
Minimal: 0
Maximal:
INT_MAX
COPT_DBLPARAM_MATRIXTOL
or"MatrixTol"
Double parameter.
Input matrix coefficient tolerance.
Default: 1e-10
Minimal: 0
Maximal: 1e-7
COPT_DBLPARAM_FEASTOL
or"FeasTol"
Double parameter.
The feasibility tolerance.
Default: 1e-6
Minimal: 1e-9.
Maximal: 1e-4
COPT_DBLPARAM_DUALTOL
or"DualTol"
Double parameter.
The tolerance for dual solutions and reduced cost.
Default: 1e-6
Minimal: 1e-9
Maximal: 1e-4
COPT_DBLPARAM_INTTOL
or"IntTol"
Double parameter.
The integrality tolerance for variables.
Default: 1e-6
Minimal: 1e-9
Maximal: 1e-1
COPT_DBLPARAM_RELGAP
or"RelGap"
Double parameter.
The relative gap of optimization.
Default: 1e-4
Minimal: 0
Maximal:
DBL_MAX
COPT_DBLPARAM_ABSGAP
or"AbsGap"
Double parameter.
The absolute gap of optimization.
Default: 1e-6
Minimal: 0
Maximal:
DBL_MAX
Presolving and scaling
COPT_INTPARAM_PRESOLVE
or"Presolve"
Integer parameter.
Level of presolving before solving a model.
Default: -1
Possible values:
-1: Automatic
0: Off
1: Fast
2: Normal
3: Aggressive
COPT_INTPARAM_SCALING
or"Scaling"
Integer parameter.
Whether to perform scaling before solving a problem.
Default: -1
Possible values:
-1: Choose automatically.
0: No scaling.
1: Apply scaling.
COPT_INTPARAM_DUALIZE
or"Dualize"
Integer parameter.
Whether to dualize a problem before solving it.
Default: -1
Possible values:
-1: Choose automatically.
0: No dualizing.
1: Dualizing the problem.
Other parameters
COPT_INTPARAM_LOGGING
or"Logging"
Integer parameter.
Whether to print optimization logs.
Default: 1
Possible values:
0: No optimization logs.
1: Print optimization logs.
COPT_INTPARAM_LOGTOCONSOLE
or"LogToConsole"
Integer parameter.
Whether to print optimization logs to console.
Default: 1
Possible values:
0: No optimization logs to console.
1: Print optimization logs to console.
API Functions
The documentations for COPT API functions are grouped by their purposes.
All the return values of COPT API functions are integers, and possible return values are documented in the constants section.
Creating the environment and problem
COPT_CreateEnvConfig
Synopsis
int COPT_CreateEnvConfig(copt_env_config **p_config)
Description
Create a COPT client configuration.
Arguments
p_config
Output pointer to COPT client configuration.
COPT_DeleteEnvConfig
Synopsis
int COPT_DeleteEnvConfig(copt_env_config **p_config)
Description
Delete COPT client configuration.
Arguments
p_config
Input pointer to COPT client configuration.
COPT_SetEnvConfig
Synopsis
int COPT_SetEnvConfig(copt_env_config *config, const char *name, const char *value)
Description
Set COPT client configuration.
Arguments
config
COPT client configuration.
name
Name of configuration parameter.
value
Value of configuration parameter.
COPT_CreateEnv
Synopsis
int COPT_CreateEnv(copt_env **p_env)
Description
Creates a COPT environment.
Calling this function is the first step when using the COPT library. It validates the license, and when the license is okay, the resulting environment variable will allow for creating COPT problems. When the license validation fails, more information can be obtained using
COPT_GetLicenseMsg
to help identify the issue.Arguments
p_env
The output pointer to a variable holding COPT environment.
COPT_CreateEnvWithPath
Synopsis
int COPT_CreateEnvWithPath(const char *licDir, copt_env **p_env)
Description
Creates a COPT environment, directory of license files is specified by argument
licDir
.Calling this function is the first step when using the COPT library. It validates the license, and when the license is okay, the resulting environment variable will allow for creating COPT problems. When the license validation fails, more information can be obtained using
COPT_GetLicenseMsg
to help identify the issue.Arguments
licDir
Directory of license files.
p_env
Output pointer to a variable holding COPT environment.
COPT_CreateEnvWithConfig
Synopsis
int COPT_CreateEnvWithConfig(copt_env_config *config, copt_env **p_env)
Description
Creates a COPT environment, client configuration is specified by argument
config
.Calling this function is the first step when using the COPT library. It validates the client configuration, and when the license is okay, the resulting environment variable will allow for creating COPT problems. When the license validation fails, more information can be obtained using
COPT_GetLicenseMsg
to help identify the issue.Arguments
config
Client configuration.
p_env
Output pointer to a variable holding COPT environment.
COPT_DeleteEnv
Synopsis
int COPT_DeleteEnv(copt_env **p_env)
Description
Deletes the COPT environment created by
COPT_CreateEnv
.Arguments
p_env
Input pointer to a variable holding COPT environment.
COPT_GetLicenseMsg
Synopsis
int COPT_GetLicenseMsg(copt_env *env, char *buff, int buffSize)
Description
Returns a C-style string regarding the license validation information. Please refer to this function when
COPT_CreateEnv
fails.Arguments
env
The COPT environment.
buff
A buffer for holding the resulting string.
buffSize
The size of the above buffer.
COPT_CreateProb
Synopsis
int COPT_CreateProb(copt_env *env, copt_prob **p_prob)
Description
Creates an empty COPT problem.
Arguments
env
The COPT environment.
p_prob
Output pointer to a variable holding the COPT problem.
COPT_CreateCopy
Synopsis
int COPT_CreateCopy(copt_prob *src_prob, copt_prob **p_dst_prob)
Description
Create a deep-copy of an COPT problem.
Note: The parameter settings will be copied too. To solve the copied problem with different parameters, users should reset its parameters to default by calling
COPT_ResetParam
first, and then set parameters as needed.Arguments
src_prob
The pointer to a varialbe hoding the COPT problem to be copied.
p_dst_prob
Output pointer to a variable hodling the copied COPT problem.
COPT_ClearProb
Synopsis
int COPT_ClearProb(copt_prob *prob)
Description
Clear COPT problem data (excluding callback function).
Arguments
prob
COPT problem.
COPT_DeleteProb
Synopsis
int COPT_DeleteProb(copt_prob **p_prob)
Description
Deletes the COPT problem created using
COPT_CreateProb
Arguments
p_prob
Input pointer to a variable holding the COPT problem.
Building and modifying a problem
COPT_LoadProb
Synopsis
int COPT_LoadProb(
copt_prob *prob,
int nCol,
int nRow,
int iObjSense,
double dObjConst,
const double *obj,
const int *colMatBeg,
const int *colMatCnt,
const int *colMatIdx,
const double *colMatElem,
const char *colType,
const double *colLower,
const double *colUpper,
const char *rowSense,
const double *rowBound,
const double *rowUpper,
char const *const *colNames,
char const *const *rowNames)
Description
Loads a problem defined by arrays.
Arguments
prob
The COPT problem.
nCol
Number of variables (coefficient matrix columns).
nRow
Number of constraints (coefficient matrix rows).
iObjSense
The optimization sense, either
COPT_MAXIMIZE
orCOPT_MINIMIZE
.
dObjConst
The constant part of the objective function.
obj
Objective coefficients of variables.
colMatBeg, colMatCnt, colMatIdx
andcolMatElem
Defines the coefficient matrix in compressed column storage (CCS) format. Please see other information for an example of the CCS format.
If
colMatCnt
isNULL
,colMatBeg
will need to have length ofnCol+1
, and the begin and end pointers to the i-th matrix column coefficients are defined usingcolMatBeg[i]
andcolMatBeg[i+1]
.If
colMatCnt
is provided, the begin and end pointers to the i-th column coefficients are defined usingcolMatBeg[i]
andcolMatBeg[i] + colMatCnt[i]
.
colType
Types of variables.
If
colType
isNULL
, all variables will be continuous.
colLower
andcolUpper
Lower and upper bounds of variables.
If
colLower
isNULL
, lower bounds will be 0.If
colUpper
isNULL
, upper bounds will be infinity.
rowSense
Senses of constraint.
Please refer to the list of all senses constants for all the supported types.
If
rowSense
isNULL
, thenrowBound
androwUpper
will be treated as lower and upper bounds for constraints. This is the recommended method for defining constraints.If
rowSense
is provided, thenrowBound
androwUpper
will be treated as RHS and range for constraints. In this case,rowUpper
is only required when there areCOPT_RANGE
constraints, where thelower bound is
rowBound[i] - fabs(rowUpper[i])
upper bound is
rowBound[i]
rowBound
Lower bounds or RHS of constraints.
rowUpper
Upper bounds or range of constraints.
colNames
androwNames
Names of variables and constraints. Can be
NULL
.Other information
The compressed column storage (CCS) is a common format for storing sparse matrix. We demonstrate how to store the example matrix with 4 columns and 3 rows in the CCS format.
// Compressed column storage using colMatBeg
colMatBeg[5] = { 0, 1, 3, 5, 6};
colMatIdx[6] = { 0, 0, 1, 1, 2, 2};
colMatElem[6] = {1.1, 1.2, 2.2, 2.3, 3.3, 3.4};
// Compressed column storage using both colMatBeg and colMatCnt.
// The * in the example represents unused spaces.
colMatBeg[4] = { 0, 1, 5, 7};
colMatCnt[4] = { 1, 2, 2, 1};
colMatIdx[6] = { 0, 0, 1, 1, 2, *, *, 2};
colMatElem[6] = {1.1, 1.2, 2.2, 2.3, 3.3, *, *, 3.4};
COPT_AddCol
Synopsis
int COPT_AddCol(
copt_prob *prob,
double dColObj,
int nColMatCnt,
const int *colMatIdx,
const double *colMatElem,
char cColType,
double dColLower,
double dColUpper,
const char *colName)
Description
Adds one variable (column) to the problem.
Arguments
prob
The COPT problem.
dColObj
The objective coefficient of the variable.
nColMatCnt
Number of non-zero elements in the column.
colMatIdx
Row index of non-zero elements in the column.
colMatElem
Values of non-zero elements in the column.
cColType
The type of the variable.
dColLower
anddColUpper
The lower and upper bounds of the variable.
colName
The name of the variable. Can be
NULL
.
COPT_AddPSDCol
Synopsis
int COPT_AddPSDCol(copt_prob *prob, int colDim, const char *name)
Description
Add a PSD variable to the problem.
Arguments
prob
The COPT problem.
colDim
Dimension of new PSD variable.
name
Name of new PSD variable. Can be
NULL
.
COPT_AddRow
Synopsis
int COPT_AddRow(
copt_prob *prob,
int nRowMatCnt,
const int *rowMatIdx,
const double *rowMatElem,
char cRowSense,
double dRowBound,
double dRowUpper,
const char *rowName)
Description
Adds one constraint (row) to the problem.
Arguments
prob
The COPT problem.
nRowMatCnt
Number of non-zero elements in the row.
rowMatIdx
Column index of non-zero elements in the row.
rowMatElem
Values of non-zero elements in the row.
cRowSense
The sense of the row.
Please refer to the list of all senses constants for all the supported types.
If
cRowSense
is 0, thendRowBound
anddRowUpper
will be treated as lower and upper bounds for the constraint. This is the recommended method for defining constraints.If
cRowSense
is provided, thendRowBound
anddRowUpper
will be treated as RHS and range for the constraint. In this case,dRowUpper
is only required whencRowSense = COPT_RANGE
, wherelower bound is
dRowBound - dRowUpper
upper bound is
dRowBound
dRowBound
Lower bound or RHS of the constraint.
dRowUpper
Upper bound or range of the constraint.
rowName
The name of the constraint. Can be
NULL
.
COPT_AddCols
Synopsis
int COPT_AddCols(
copt_prob *prob,
int nAddCol,
const double *colObj,
const int *colMatBeg,
const int *colMatCnt,
const int *colMatIdx,
const double *colMatElem,
const char *colType,
const double *colLower,
const double *colUpper,
char const *const *colNames)
Description
Adds
nAddCol
variables (columns) to the problem.Arguments
prob
The COPT problem.
nAddCol
Number of new variables.
colObj
Objective coefficients of new variables.
colMatBeg, colMatCnt, colMatIdx
andcolMatElem
Defines the coefficient matrix in compressed column storage (CCS) format. Please see other information of
COPT_LoadProb
for an example of the CCS format.
colType
Types of new variables.
colLower
andcolUpper
Lower and upper bounds of new variables.
If
colLower
isNULL
, lower bounds will be 0.If
colUpper
isNULL
, upper bounds will beCOPT_INFINITY
.
colNames
Names of new variables. Can be
NULL
.
COPT_AddPSDCols
Synopsis
int COPT_AddPSDCols(copt_prob *prob, int nAddCol, const int* colDims, char const *const *names)
Description
Add
nAddCol
PSD variables to the problem.Arguments
prob
The COPT problem.
nAddCol
Number of new PSD variables.
colDims
Dimensions of new PSD variables.
names
Names of new PSD variables. Can be
NULL
.
COPT_AddRows
Synopsis
int COPT_AddRows(
copt_prob *prob,
int nAddRow,
const int *rowMatBeg,
const int *rowMatCnt,
const int *rowMatIdx,
const double *rowMatElem,
const char *rowSense,
const double *rowBound,
const double *rowUpper,
char const *const *rowNames)
Description
Adds
nAddRow
constraints (rows) to the problem.Arguments
prob
The COPT problem.
nAddRow
Number of new constraints.
rowMatBeg, rowMatCnt, rowMatIdx
androwMatElem
Defines the coefficient matrix in compressed row storage (CRS) format. The CRS format is similar to the CCS format described in the other information of
COPT_LoadProb
.
rowSense
Senses of new constraints.
Please refer to the list of all senses constants for all the supported types.
If
rowSense
isNULL
, thenrowBound
androwUpper
will be treated as lower and upper bounds for constraints. This is the recommended method for defining constraints.If
rowSense
is provided, thenrowBound
androwUpper
will be treated as RHS and range for constraints. In this case,rowUpper
is only required when there areCOPT_RANGE
constraints, where thelower bound is
rowBound[i] - fabs(rowUpper[i])
upper bound is
rowBound[i]
rowBound
Lower bounds or RHS of new constraints.
rowUpper
Upper bounds or range of new constraints.
rowNames
Names of new constraints. Can be
NULL
.
COPT_AddSOSs
Synopsis
int COPT_AddSOSs(
copt_prob *prob,
int nAddSOS,
const int *sosType,
const int *sosMatBeg,
const int *sosMatCnt,
const int *sosMatIdx,
const double *sosMatWt)
Description
Add
nAddSOS
SOS constraints to the problem. IfsosMatWt
isNULL
, then COPT will generate it internally.Note: if a problem contains SOS constraints, the problem is a MIP.
Arguments
prob
The COPT problem.
nAddSOS
Number of new SOS constraints.
sosType
Types of SOS constraints.
sosMatBeg, sosMatCnt, sosMatIdx
andsosMatWt
Defines the coefficient matrix in compressed row storage (CRS) format. The CRS format is similar to the CCS format described in the other information of
COPT_LoadProb
.
sosMatWt
Weights of variables in SOS constraints. Can be
NULL
.
COPT_AddCones
Synopsis
int COPT_AddCones(
copt_prob *prob,
int nAddCone,
const int *coneType,
const int *coneBeg,
const int *coneCnt,
const int *coneIdx)
Description
Add
nAddCone
Second-Order-Cone (SOC) constraints.Arguments
prob
The COPT problem.
nAddCone
Number of new SOC constraints.
coneType
Types of SOC constraints.
coneBeg, coneCnt, coneIdx
Defines the coefficient matrix in compressed row storage (CRS) format. The CRS format is similar to the CCS format described in the other information of
COPT_LoadProb
.
COPT_AddExpCones
Synopsis
int COPT_AddExpCones(
copt_prob *prob,
int nAddCone,
const int *coneType,
const int *coneIdx)
Description
Add
nAddCone
exponential cone constraints.Arguments
prob
The COPT problem.
nAddCone
Number of new exponential cone constraints.
coneType
Types of exponential cone constraints.
coneIdx
Array of subscripts for the variables that constitute the exponential cone constraints.
COPT_AddAffineCone
Synopsis
int COPT_AddAffineCone(
copt_prob *prob,
int coneType,
int nConeDim,
int nAlphaDim,
const double *alphaElem,
const int *psdBeg,
const int *psdCnt,
const int *psdColIdx,
const int *psdMatIdx,
const int *rowMatBeg,
const int *rowMatCnt,
const int *rowMatIdx,
const double *rowMatElem,
const double *rowConst,
const char *name)
Description
Add the affine cone constraints.
Arguments
prob
The COPT model.
coneType
The type of the affine cone. Please refer to SOC constraint types and Exponential Cone type for possible values.
nConeDim
The dimension of the affine cone.
nAlphaDim
Reserved parameter, currently not in use.
alphaElem
Reserved parameter, currently not in use.
psdBeg, psdCnt, psdColIdx, psdMatIdx
Represents the PSD terms in the affine cone.
psdBeg
indicates the starting position of the PSD terms in each affine cone term,psdCnt
specifies the number of PSD terms,psdColIdx
indicates the index of the PSD variable, andpsdMatIdx
refers to the index of the symmetric matrix.
rowMatBeg, rowMatCnt, rowMatIdx, rowMatElem
Represents the linear terms in the affine cone.
The coefficient matrix is provided in CRS-format. For detailed examples, please refer to Additional Information in
COPT_LoadProb
.
rowConst
The constant terms in the affine cone.
name
The name of the affine cone.
COPT_AddQConstr
Synopsis
int COPT_AddQConstr(
copt_prob *prob,
int nRowMatCnt,
const int *rowMatIdx,
const int *rowMatElem,
int nQMatCnt,
const int *qMatRow,
const int *qMatCol,
const double *qMatElem,
char cRowSense,
double dRowBound, const char *name)
Description
Add a general quadratic constraint.
Note Only convex quadratic constraint is currently supported.
Arguments
prob
The COPT problem.
nRowMatCnt
Number of non-zero linear terms of the quadratic constraint (row).
rowMatIdx
Column index of non-zero linear terms of the quadratic constraint (row).
rowMatElem
Values of non-zero linear terms of the quadratic constraint (row).
nQMatCnt
Number of non-zero quadratic terms of the quadratic constraint (row).
qMatRow
Row index of non-zero quadratic terms of the quadratic constraint (row).
qMatCol
Column index of non-zero quadratic terms of the quadratic constraint (row).
qMatElem
Values of non-zero quadratic terms of the quadratic constraint (row).
cRowSense
The sense of the quadratic constraint (row).
dRowBound
Right hand side of the quadratic constraint (row).
name
Name of the quadratic constraint (row).
COPT_AddPSDConstr
Synopsis
int COPT_AddPSDConstr(
copt_prob *prob,
int nRowMatCnt,
const int *rowMatIdx,
const int *rowMatElem,
int nColCnt,
const int *psdColIdx,
const int *symMatIdx,
char cRowSense,
double dRowBound,
double dRowUpper,
const char *name)
Description
Add a PSD constraint.
Arguments
prob
The COPT problem.
nRowMatCnt
Number of non-zero linear terms of the PSD constraint.
rowMatIdx
Column index of non-zero linear terms of the PSD constraint.
rowMatElem
Values of non-zero linear terms of the PSD constraint.
nColCnt
Number of PSD terms of the PSD constraint.
psdColIdx
PSD variable index of PSD terms of the PSD constraint.
symMatIdx
Symmetric matrix index of PSD terms of the PSD constraint.
cRowSense
Senses of new PSD constraint.
Please refer to the list of all senses constants for all the supported types.
If
cRowSense
is 0, thendRowBound
anddRowUpper
will be treated as lower and upper bounds for the constraint. This is the recommended method for defining constraints.If
cRowSense
is provided, thendRowBound
anddRowUpper
will be treated as RHS and range for the constraint. In this case,dRowUpper
is only required whencRowSense = COPT_RANGE
, wherelower bound is
dRowBound - dRowUpper
upper bound is
dRowBound
dRowBound
Lower bound or RHS of the PSD constraint.
dRowUpper
Upper bound or range of the PSD constraint.
name
Name of the PSD constraint. Can be
NULL
.
COPT_AddLMIConstr
Synopsis
int COPT_AddLMIConstr(
copt_prob *prob,
int nDim,
int nLMIMatCnt,
const int *colIdx,
const int *symMatIdx,
int constMatIdx,
const char *name)
Description
Add a LMI constraint to the problem.
Arguments
prob
The COPT problem.
nDim
Dimension of symmetric matrix in the LMI constraint.
nLMIMatCnt
Number of coefficient matrix entries in the LMI constraint.
colIdx
Index of scalar variable in the LMI constraint.
symMatIdx
Index of symmetric coefficient matrix in the LMI constraint.
constMatIdx
Index of constant-term symmetric matrix in the LMI constraint.
name
Name of LMI constraint. Can be
NULL
.
COPT_AddIndicator
Synopsis
int COPT_AddIndicator(
copt_prob *prob,
int binColIdx,
int binColVal,
int nRowMatCnt,
const int *rowMatIdx,
const double *rowMatElem,
char cRowSense, double dRowBound)
Description
Add an indicator constraint to the problem.
Arguments
prob
The COPT problem.
binColIdx
Index of indicator variable (column).
binColVal
Value of indicator variable (column).
nRowMatCnt
Number of non-zero elements in the linear constraint (row).
rowMatIdx
Column index of non-zero elements in the linear constraint (row).
rowMatElem
Values of non-zero elements in the linear constraint (row).
cRowSense
The sense of the linear constraint (row). Options are:
COPT_EQUAL
,COPT_LESS_EQUAL
andCOPT_GREATER_EQUAL
.
dRowBound
Right hand side of the linear constraint (row).
COPT_AddIndicators
Synopsis
int COPT_AddIndicators(
copt_prob *prob,
int nInd,
int *indType,
int *binColIdx,
int *binColVal,
const int *rowMatBeg,
const int *RowMatCnt,
const int *rowMatIdx,
const double *rowMatElem,
char cRowSense,
double *dRowBound,
char const *const indNames);
Description
Add
nInd
indicator constraints to the problem.Arguments
prob
The COPT problem.
nInd
Number of indicator constraints.
indType
Type for indcator constraints. Please refer to Indicator constraint types for possible values.
binColIdx
Index of indicator variable (column).
binColVal
Value of indicator variable (column).
rowMatBeg, rowMatCnt, rowMatIdx
androwMatElem
Defines the coefficient matrix in compressed row storage (CRS) format for linear constraint in the indcator constrsints.
Please see other information of
COPT_LoadProb
for an example of the CRS format.
cRowSense
The sense of the linear constraint (row). Options are:
COPT_EQUAL
,COPT_LESS_EQUAL
andCOPT_GREATER_EQUAL
.
dRowBound
Right hand side of the linear constraint (row).
indNames
Names for indicator constraints.
COPT_AddSymMat
Synopsis
int COPT_AddSymMat(copt_prob *prob, int ndim, int nelem, int *rows, int *cols, double *elems)
Description
Add a symmetric matrix to the problem. (Expect lower triangle part)
Arguments
prob
The COPT problem.
ndim
Dimension of symmetric matrix.
nelem
Number of non-zeros of symmetric matrix.
rows
Row index of symmetric matrix.
cols
Column index of symmetric matrix.
elems
Nonzero elements of symmetric matrix.
COPT_DelCols
Synopsis
int COPT_DelCols(copt_prob *prob, int num, const int *list)
Description
Deletes
num
variables (columns) from the problem.Arguments
prob
The COPT problem.
num
Number of variables to be deleted.
list
A list of index of variables to be deleted.
COPT_DelPSDCols
Synopsis
int COPT_DelPSDCols(copt_prob *prob, int num, const int *list)
Description
Deletes
num
PSD variables from the problem.Arguments
prob
The COPT problem.
num
Number of PSD variables to be deleted.
list
A list of index of PSD variables to be deleted.
COPT_DelRows
Synopsis
int COPT_DelRows(copt_prob *prob, int num, const int *list)
Description
Deletes
num
constraints (rows) from the problem.Arguments
prob
The COPT problem.
num
The number of constraints to be deleted.
list
The list of index of constraints to be deleted.
COPT_DelSOSs
Synopsis
int COPT_DelSOSs(copt_prob *prob, int num, const int *list)
Description
Deletes
num
SOS constraints from the problem.Arguments
prob
The COPT problem.
num
The number of SOS constraints to be deleted.
list
The list of index of SOS constraints to be deleted.
COPT_DelCones
Synopsis
int COPT_DelCones(copt_prob *prob, int num, const int *list)
Description
Deletes
num
Second-Order-Cone (SOC) constraints from the problem.Arguments
prob
The COPT problem.
num
The number of SOC constraints to be deleted.
list
The list of index of SOC constraints to be deleted.
COPT_DelExpCones
Synopsis
int COPT_DelExpCones(copt_prob *prob, int num, const int *list)
Description
Deletes
num
exponential cone constraints from the problem.Arguments
prob
The COPT problem.
num
The number of exponential cone constraints to be deleted.
list
The list of index of exponential cone constraints to be deleted.
COPT_DelAffineCones
Synopsis
int COPT_DelAffineCones(copt_prob *prob, int num, const int *list)
Description
Deletes
num
affine cone constraints from the problem.Arguments
prob
The COPT problem.
num
The number of affine cone constraints to be deleted.
list
The list of index of affine cone constraints to be deleted.
COPT_DelQConstrs
Synopsis
int COPT_DelQConstrs(copt_prob *prob, int num, const int *list)
Description
Deletes
num
quadratic constraints from the problem.Arguments
prob
The COPT problem.
num
The number of quadratic constraints to be deleted.
list
The list of index of quadratic constraints to be deleted.
COPT_DelPSDConstrs
Synopsis
int COPT_DelPSDConstrs(copt_prob *prob, int num, const int *list)
Description
Deletes
num
PSD constraints from the problem.Arguments
prob
The COPT problem.
num
The number of PSD constraints to be deleted.
list
The list of index of PSD constraints to be deleted.
COPT_DelLMIConstrs
Synopsis
int COPT_DelLMIConstrs(copt_prob *prob, int num, const int *list)
Description
Deletes
num
LMI constraints from the problem.Arguments
prob
The COPT problem.
num
The number of LMI constraints to be deleted.
list
The list of index of LMI constraints to be deleted.
COPT_DelIndicators
Synopsis
int COPT_DelIndicators(copt_prob *prob, int num, const int *list)
Description
Deletes
num
indicator constraints from the problem.Arguments
prob
The COPT problem.
num
The number of indicator constraints to be deleted.
list
The list of index of indicator constraints to be deleted.
COPT_DelQuadObj
Synopsis
int COPT_DelQuadObj(copt_prob *prob)
Description
Deletes the quadratic terms from the quadratic objective function.
Arguments
prob
The COPT problem.
COPT_DelPSDObj
Synopsis
int COPT_DelPSDObj(copt_prob *prob)
Description
Deletes the PSD terms from objective function.
Arguments
prob
The COPT problem.
COPT_SetElem
Synopsis
int COPT_SetElem(copt_prob *prob, int iCol, int iRow, double newElem)
Description
Set coefficient of specified row and column.
Note: If
newElem
is smaller than or equal to parameterMatrixTol
, the coefficient will be set as zero.Arguments
prob
The COPT problem.
iCol
Column index.
iRow
Row index.
newElem
New coefficient.
COPT_SetElems
Synopsis
int COPT_SetElems(copt_prob *prob, int nelem, const int *cols, const int *rows, const double *elems)
Description
Set the coefficients of the specified columns and rows in batches.
Note The index pairs of columns and rows cannot appear repeatedly.
Arguments
prob
The COPT problem.
nelem
The number of new coefficients to be set.
cols
Column indexes.
rows
Row indexes.
elems
The values of the new coefficients to be set.
COPT_SetPSDElem
Synopsis
int COPT_SetPSDElem(copt_prob *prob, int iCol, int iRow, int newIdx)
Description
Set symmetric matrix index for given PSD term of PSD constraint.
Arguments
prob
The COPT problem.
iCol
PSD variable index.
iRow
PSD constraint index.
newIdx
New symmetric matrix index.
COPT_SetLMIElem
Synopsis
int COPT_SetLMIElem(copt_prob *prob, int iCol, int iRow, int newIdx)
Description
Set symmetric matrix index for given term of LMI constraint.
Arguments
prob
The COPT problem.
iCol
Scalar variable index.
iRow
LMI constraint index.
newIdx
New coefficient symmetric matrix index.
COPT_SetObjSense
Synopsis
int COPT_SetObjSense(copt_prob *prob, int iObjSense)
Description
Change the objective function sense.
Arguments
prob
The COPT problem.
iObjSense
The optimization sense, either
COPT_MAXIMIZE
orCOPT_MINIMIZE
.
COPT_SetObjConst
Synopsis
int COPT_SetObjConst(copt_prob *prob, double dObjConst)
Description
Set the constant term of objective function.
Arguments
prob
The COPT problem.
dObjConst
The constant term of objective function.
COPT_SetColObj/Type/Lower/Upper/Names
Synopsis
int COPT_SetColObj(copt_prob *prob, int num, const int *list, const double *obj)
int COPT_SetColType(copt_prob *prob, int num, const int *list, const char *type)
int COPT_SetColLower(copt_prob *prob, int num, const int *list, const double *lower)
int COPT_SetColUpper(copt_prob *prob, int num, const int *list, const double *upper)
int COPT_SetColNames(copt_prob *prob, int num, const int *list, char const *const *names)
Description
These five API functions each modifies
objective coefficients
variable types
lower bounds
upper bounds
names
of
num
variables (columns) in the problem.Arguments
prob
The COPT problem.
num
Number of variables to modify.
list
A list of index of variables to modify.
obj
New objective coefficients for each variable in the
list
.
types
New types for each variable in the
list
.
lower
New lower bounds for each variable in the
list
.
upper
New upper bounds for each variable in the
list
.
names
New names for each variable in the
list
.
COPT_SetPSDColNames
Synopsis
int COPT_SetPSDColNames(copt_prob *prob, int num, const int *list, char const *const *names)
Description
Modify names of
num
PSD variables.Arguments
prob
The COPT problem.
num
Number of PSD variables to modify.
list
A list of index of PSD variables to modify.
names
New names for each PSD variable in the
list
.
COPT_SetRowLower/Upper/Names
Synopsis
int COPT_SetRowLower(copt_prob *prob, int num, const int *list, const double *lower)
int COPT_SetRowUpper(copt_prob *prob, int num, const int *list, const double *upper)
int COPT_SetRowNames(copt_prob *prob, int num, const int *list, char const *const *names)
Description
These three API functions each modifies
lower bounds
upper bounds
names
of
num
constraints (rows) in the problem.Arguments
prob
The COPT problem.
num
Number of constraints to modify.
list
A list of index of constraints to modify.
lower
New lower bounds for each constraint in the
list
.
upper
New upper bounds for each constraint in the
list
.
names
New names for each constraint in the
list
.
COPT_SetQConstrSense/Rhs/Names
Synopsis
int COPT_SetQConstrSense(copt_prob *prob, int num, const int *list, const char *sense)
int COPT_SetQConstrRhs(copt_prob *prob, int num, const int *list, const double *rhs)
int COPT_SetQConstrNames(copt_prob *prob, int num, const int *list, char const *const *names)
Description
These three API functions each modifies
senses
RHS
names
of
num
quadratic constraints (rows) in the problem.Arguments
prob
The COPT problem.
num
Number of quadratic constraints to modify.
list
A list of index of quadratic constraints to modify.
sense
New senses for each quadratic constraint in the
list
.
rhs
New RHS for each quadratic constraint in the
list
.
names
New names for each quadratic constraint in the
list
.
COPT_SetPSDConstrLower/Upper/Names
Synopsis
int COPT_SetPSDConstrLower(copt_prob *prob, int num, const int *list, const double *lower)
int COPT_SetPSDConstrUpper(copt_prob *prob, int num, const int *list, const double *upper)
int COPT_SetPSDConstrNames(copt_prob *prob, int num, const int *list, char const *const *names)
Description
These three API functions each modifies
lower bounds
upper bounds
names
of
num
PSD constraints in the problem.Arguments
prob
The COPT problem.
num
Number of PSD constraints to modify.
list
A list of index of PSD constraints to modify.
lower
New lower bounds for each PSD constraint in the
list
.
upper
New upper bounds for each PSD constraint in the
list
.
names
New names for each PSD constraint in the
list
.
COPT_SetLMIConstrRhs
Synopsis
int COPT_SetLMIConstrRhs(copt_prob *prob, int num, const int *list, const int *newIdx)
Description
Modify the constant-term symmetric matrix of
num
LMI constraints.Arguments
prob
The COPT problem.
num
Number of LMI constraints to modify.
list
A list of index of LMI constraints to modify.
newIdx
The new index of the constant-term symmetric matrix to be set.
COPT_SetIndicatorNames
Synopsis
int COPT_SetIndicatorNames(copt_prob *prob, int num, const int *list, char const *const *names)
Description
Modifies names of
num
indicator constraints in the problem.Arguments
prob
The COPT problem.
num
Number of indicator constraints to modify.
list
A list of indexes of indicator constraints to modify.
names
New names for each indicator constraint in the
list
.
COPT_SetAffineConeNames
Synopsis
int COPT_SetAffineConeNames(copt_prob *prob, int num, const int *list, char const *const *names)
Description
Modifies names of
num
affine cones in the problem.Arguments
prob
The COPT problem.
num
Number of affine cones to modify.
list
A list of indexes of affine cones to modify.
names
New names for each affine cone in the
list
.
COPT_SetLMIConstrNames
Synopsis
int COPT_SetLMIConstrNames(copt_prob *prob, int num, const int *list, char const *const *names)
Description
Modify the names of
num
LMI constraints.Arguments
prob
The COPT problem.
num
Number of LMI constraints to modify.
list
A list of index of LMI constraints to modify.
names
New names for each LMI constraint in the
list
.
COPT_ReplaceColObj
Synopsis
int COPT_ReplaceColObj(copt_prob *prob, int num, const int *list, const double *obj)
Description
Replace objective function with new objective function represented by specified objective costs.
Arguments
prob
The COPT problem.
num
Number of variables to be modified.
list
Index of variables to be modified.
obj
Objective costs of modified variables.
COPT_ReplacePSDObj
Synopsis
int COPT_ReplacePSDObj(copt_prob *prob, int num, const int *list, const int *idx)
Description
Replace PSD terms in objective function with specified PSD terms.
Arguments
prob
The COPT problem.
num
Number of PSD variables to be modified.
list
Index of PSD variables to be modified.
idx
Symmetric matrix index of modified PSD variables.
COPT_SetQuadObj
Synopsis
int COPT_SetQuadObj(copt_prob *prob, int num, int *qRow, int *qCol, double *qElem)
Description
Set the quadratic terms of the quadratic objective function.
Arguments
prob
The COPT problem.
num
Number of non-zero quadratic terms of the quadratic objective function.
qRow
Row index of non-zero quadratic terms of the quadratic objective function.
qCol
Column index of non-zero quadratic terms of the quadratic objective function.
qElem
Values of non-zero quadratic terms of the quadratic objective function.
COPT_SetPSDObj
Synopsis
int COPT_SetPSDObj(copt_prob *prob, int iCol, int newIdx)
Description
Set PSD terms of objective function.
Arguments
prob
The COPT problem.
iCol
PSD variable index.
newIdx
Symmetric matrix index.
Reading and writing the problem
COPT_ReadMps
Synopsis
int COPT_ReadMps(copt_prob *prob, const char *mpsfilename)
Description
Reads a problem from a MPS file.
Arguments
prob
The COPT problem.
mpsfilename
The path to the MPS file.
COPT_ReadLp
Synopsis
int COPT_ReadLp(copt_prob *prob, const char *lpfilename)
Description
Read a problem from a LP file.
Arguments
prob
The COPT problem.
lpfilename
The path to the LP file.
COPT_ReadSDPA
Synopsis
int COPT_ReadSDPA(copt_prob *prob, const char *sdpafilename)
Description
Reads a problem from SDPA format file.
Arguments
prob
The COPT problem.
sdpafilename
The path to the SDPA format file.
COPT_ReadCbf
Synopsis
int COPT_ReadCbf(copt_prob *prob, const char *cbffilename)
Description
Reads a problem from CBF format file.
Arguments
prob
The COPT problem.
cbffilename
The path to the CBF format file.
COPT_ReadBin
Synopsis
int COPT_ReadBin(copt_prob *prob, const char *binfilename)
Description
Reads a problem from a COPT binary format file.
Arguments
prob
The COPT problem.
binfilename
The path to the COPT binary format file.
COPT_ReadBlob
Synopsis
int COPT_ReadBlob(copt_prob *prob, void *blob, COPT_INT64 len)
Description
Reads a problem from COPT serialized data.
Arguments
prob
The COPT problem.
blob
Serialized data.
len
Length of serialized data.
COPT_WriteMps
Synopsis
int COPT_WriteMps(copt_prob *prob, const char *mpsfilename)
Description
Writes the problem to a MPS file.
Arguments
prob
The COPT problem.
mpsfilename
The path to the MPS file.
COPT_WriteMpsStr
Synopsis
int COPT_WriteMpsStr(copt_prob *prob, char *str, int nStrSize, int *pReqSize)
Description
Writes the problem to a string buffer as MPS format.
Arguments
prob
The COPT problem.
str
String buffer of MPS-format problem.
nStrSize
The size of string buffer.
pReqSize
Minimum space requirement of string buffer for problem.
COPT_WriteLp
Synopsis
int COPT_WriteLp(copt_prob *prob, const char *lpfilename)
Description
Writes the problem to a LP file.
Arguments
prob
The COPT problem.
lpfilename
The path to the LP file.
COPT_WriteCbf
Synopsis
int COPT_WriteCbf(copt_prob *prob, const char *cbffilename)
Description
Writes the problem to a CBF format file.
Arguments
prob
The COPT problem.
cbffilename
The path to the CBF format file.
COPT_WriteBin
Synopsis
int COPT_WriteBin(copt_prob *prob, const char *binfilename)
Description
Writes the problem to a COPT binary format file.
Arguments
prob
The COPT problem.
binfilename
The path to the COPT binary format file.
COPT_WriteBlob
Synopsis
int COPT_WriteBlob(copt_prob *prob, int tryCompress, void **p_blob, COPT_INT64 *pLen)
Description
Writes the problem to COPT serialized data.
Arguments
prob
The COPT problem.
tryCompress
Whether to compress data.
p_blob
Output pointer of serialized data.
pLen
Pointer to length of serialized data.
Solving the problem and accessing solutions
COPT_SolveLp
Synopsis
int COPT_SolveLp(copt_prob *prob)
Description
Solves the LP, QP, QCP, SOCP and SDP problem.
If problem is a MIP, then integer restrictions on variables will be ignored, and SOS constraints, indicator constraints will be discarded, and the problem will be solved as a LP.
Arguments
prob
The COPT problem.
COPT_Solve
Synopsis
int COPT_Solve(copt_prob *prob)
Description
Solves the problem.
Arguments
prob
The COPT problem.
COPT_GetSolution
Synopsis
int COPT_GetSolution(copt_prob *prob, double *colVal)
Description
Obtains MIP solution.
Arguments
prob
The COPT problem.
colVal
Solution values of variables.
COPT_GetPoolObjVal
Synopsis
int COPT_GetPoolObjVal(copt_prob *prob, int iSol, double *p_objVal)
Description
Obtains the
iSol
-th objective value in solution pool.Arguments
prob
The COPT problem.
iSol
Index of solution.
p_objVal
Pointer to objective value.
COPT_GetPoolSolution
Synopsis
int COPT_GetPoolSolution(copt_prob *prob, int iSol, int num, const int *list, double *colVal)
Description
Obtains the
iSol
-th solution.Arguments
prob
The COPT problem.
iSol
Index of solution.
num
Number of columns.
list
Index of columns. Can be
NULL
.
colVal
Array of solution.
COPT_GetLpSolution
Synopsis
int COPT_GetLpSolution(copt_prob *prob, double *value, double *slack, double *rowDual, double *redCost)
Description
Obtains LP, QP, QCP, SOCP and SDP solutions.
Note: For SDP, please use
COPT_GetPSDColInfo
to obtain primal/dual solution of PSD variable.Arguments
prob
The COPT problem.
value
Solution values of variables. Can be
NULL
.
slack
Solution values of slack variables. They are also known as activities of constraints. Can be
NULL
.
rowDual
Dual values of constraints. Can be
NULL
.
redCost
Reduced cost of variables. Can be
NULL
.
COPT_SetLpSolution
Synopsis
int COPT_SetLpSolution(copt_prob *prob, double *value, double *slack, double *rowDual, double *redCost)
Description
Set LP solution.
Arguments
prob
The COPT problem.
value
Solution values of variables.
slack
Solution values of slack variables.
rowDual
Dual values of constraints.
redCost
Reduced cost of variables.
COPT_GetBasis
Synopsis
int COPT_GetBasis(copt_prob *prob, int *colBasis, int *rowBasis)
Description
Obtains LP basis.
Arguments
prob
The COPT problem.
colBasis
androwBasis
The basis status of variables and constraints. Please refer to basis constants for possible values and their meanings.
COPT_SetBasis
Synopsis
int COPT_SetBasis(copt_prob *prob, const int *colBasis, const int *rowBasis)
Description
Sets LP basis. It can be used to warm-start an LP optimization.
Arguments
prob
The COPT problem.
colBasis
androwBasis
The basis status of variables and constraints. Please refer to basis constants for possible values and their meanings.
COPT_SetSlackBasis
Synopsis
int COPT_SetSlackBasis(copt_prob *prob)
Description
Sets a slack basis for LP. The slack basis is the default starting basis for an LP problem. This API function can be used to restore an LP problem to its starting basis.
Arguments
prob
The COPT problem.
COPT_Reset
Synopsis
int COPT_Reset(copt_prob *prob, int iClearAll)
Description
Reset basis and LP/MIP solution in problem, which forces next solve start from scratch. If
iClearAll
is1
, then clear additional information such as MIP start as well.Arguments
prob
The COPT problem.
iClearAll
Whether to clear additional information.
COPT_ReadSol
Synopsis
int COPT_ReadSol(copt_prob *prob, const char *solfilename)
Description
Reads a MIP solution from file as MIP start information.
Note: The default solution value is 0, i.e. a partial solution will be automatically filled in with zeros.
Arguments
prob
The COPT problem.
solfilename
The path to the solution file.
COPT_WriteSol
Synopsis
int COPT_WriteSol(copt_prob *prob, const char *solfilename)
Description
Writes a LP/MIP solution to a file.
Arguments
prob
The COPT problem.
solfilename
The path to the solution file.
COPT_WritePoolSol
Synopsis
int COPT_WritePoolSol(copt_prob *prob, int iSol, const char *solfilename)
Description
Writes selected pool solution to a file.
Arguments
prob
The COPT problem.
iSol
Index of pool solution.
solfilename
The path to the solution file.
COPT_WriteBasis
Synopsis
int COPT_WriteBasis(copt_prob *prob, const char *basfilename)
Description
Writes the internal LP basis to a file.
Arguments
prob
The COPT problem.
basfilename
The path to the basis file.
COPT_ReadBasis
Synopsis
int COPT_ReadBasis(copt_prob *prob, const char *basfilename)
Description
Reads the LP basis from a file. It can be used to warm-start an LP optimization.
Arguments
prob
The COPT problem.
basfilename
The path to the basis file.
Accessing information of problem
COPT_GetCols
Synopsis
int COPT_GetCols(
copt_prob *prob,
int nCol,
const int *list,
int *colMatBeg,
int *colMatCnt,
int *colMatIdx,
double *colMatElem,
int nElemSize,
int *pReqSize)
Description
Extract coefficient matrix by columns.
In general, users need to call this function twice to accomplish the task. Firstly, by passing
NULL
to argumentscolMatBeg
,colMatCnt
,colMatIdx
andcolMatElem
, we get number of non-zeros elements bypReqSize
specified bynCol
andlist
. Secondly, allocate sufficient memory for CCS-format matrix and call this function again to extract coefficient matrix. If the memory of coefficient matrix passed to function is not sufficient, then return the firstnElemSize
non-zero elements, and the minimal required length of non-zero elements bypReqSize
. Iflist
isNULL
, then the firstnCol
columns will be returned.Arguments
prob
The COPT problem.
nCol
Number of columns.
list
Index of columns. Can be
NULL
.
colMatBeg, colMatCnt, colMatIdx
andcolMatElem
Defines the coefficient matrix in compressed column storage (CCS) format. Please see other information of
COPT_LoadProb
for an example of the CCS format.
nElemSize
Length of array for non-zero coefficients.
pReqSize
Pointer to minimal length of array for non-zero coefficients. Can be
NULL
.
COPT_GetPSDCols
Synopsis
int COPT_GetPSDCols(copt_prob *prob, int nCol, int *list, int* colDims, int *colLens)
Description
Get dimension and flattened length of
nCol
PSD variables.Arguments
prob
The COPT problem.
nCol
Number of PSD variables.
list
Index of PSD variables. Can be
NULL
.
colDims
Dimension of PSD variables.
colLens
Flattened length of PSD variables.
COPT_GetRows
Synopsis
int COPT_GetRows(
copt_prob *prob,
int nRow,
const int *list,
int *rowMatBeg,
int *rowMatCnt,
int *rowMatIdx,
double *rowMatElem,
int nElemSize,
int *pReqSize)
Description
Extract coefficient matrix by rows.
In general, users need to call this function twice to accomplish the task. Firstly, by passing
NULL
to argumentsrowMatBeg
,rowMatCnt
,rowMatIdx
androwMatElem
, we get number of non-zeros elements bypReqSize
specified bynRow
andlist
. Secondly, allocate sufficient memory for CRS-format matrix and call this function again to extract coefficient matrix. If the memory of coefficient matrix passed to function is not sufficient, then return the firstnElemSize
non-zero elements, and the minimal required length of non-zero elements bypReqSize
. Iflist
isNULL
, then the firstnRow
rows will be returned.Arguments
prob
The COPT problem.
nRow
Number of rows.
list
Index of rows. Can be
NULL
.
rowMatBeg, rowMatCnt, rowMatIdx
androwMatElem
Defines the coefficient matrix in compressed row storage (CRS) format. Please see other information of
COPT_LoadProb
for an example of the CRS format.
nElemSize
Length of array for non-zero coefficients.
pReqSize
Pointer to minimal length of array for non-zero coefficients. Can be
NULL
.
COPT_GetElem
Synopsis
int COPT_GetElem(copt_prob *prob, int iCol, int iRow, double *p_elem)
Description
Get coefficient of specified row and column.
Arguments
prob
The COPT problem.
iCol
Column index.
iRow
Row index.
p_elem
Pointer to requested coefficient.
COPT_GetPSDElem
Synopsis
int COPT_GetPSDElem(copt_prob *prob, int iCol, int iRow, int *p_idx)
Description
Get symmetric matrix index of specified PSD constraint and PSD variable.
Arguments
prob
The COPT problem.
iCol
PSD variable index.
iRow
PSD constraint index.
p_idx
Pointer to requested symmetric matrix index.
COPT_GetLMIElem
Synopsis
int COPT_GetLMIElem(copt_prob *prob, int iCol, int iRow, int *p_idx)
Description
Get symmetric matrix index of specified LMI constraint and scalar variable.
Arguments
prob
The COPT problem.
iCol
Scalar variable index.
iRow
LMI constraint index.
p_idx
Pointer to requested coefficient matrix index.
COPT_GetSymMat
Synopsis
int COPT_GetSymMat(
copt_prob *prob,
int iMat,
int *p_nDim,
int *p_nElem,
int *rows,
int *cols,
double *elems)
Description
Get specified symmetric matrix.
In general, users need to call this function twice to accomplish the task. Firstly, by passing
NULL
to argumentsrows
,cols
andelems
, we get dimension and number of non-zeros of symmetric matrix byp_nDim
andp_nElem
, then allocate enough memory forrows
,cols
andelems
and call this function to get the data of symmetric matrix.Arguments
prob
The COPT problem.
iMat
Symmetric matrix index.
p_nDim
Pointer to dimension of symmetric matrix.
p_nElem
Pointer to number of nonzeros of symmetric matrix.
rows
Row index of symmetric matrix.
cols
Column index of symmetric matrix.
elems
Nonzero elements of symmetric matrix.
COPT_GetQuadObj
Synopsis
int COPT_GetQuadObj(copt_prob* prob, int* p_nQElem, int* qRow, int* qCol, double* qElem)
Description
Get the quadratic terms of the quadratic objective function.
Arguments
prob
The COPT problem.
p_nQElem
Pointer to number of non-zero quadratic terms . Can be
NULL
.
qRow
Row index of non-zero quadratic terms of the quadratic objective function.
qCol
Column index of non-zero quadratic terms of the quadratic objective function.
qElem
Values of non-zero quadratic terms of the quadratic objective function.
COPT_GetPSDObj
Synopsis
int COPT_GetPSDObj(copt_prob *prob, int iCol, int *p_idx)
Description
Get the specified PSD term of objective function.
Arguments
prob
The COPT problem.
iCol
PSD variable index.
p_idx
Pointer to symmetric matrix index.
COPT_GetSOSs
Synopsis
int COPT_GetSOSs(
copt_prob *prob,
int nSos,
const int *list,
int *sosMatBeg,
int *sosMatCnt,
int *sosMatIdx,
double *sosMatWt,
int nElemSize,
int *pReqSize)
Description
Get the weight matrix of SOS constraints.
In general, users need to call this function twice to accomplish the task. Firstly, by passing
NULL
to argumentssosMatBeg
,sosMatCnt
,sosMatIdx
andsosMatWt
, we get number of non-zeros elements bypReqSize
specified bynSos
andlist
. Secondly, allocate sufficient memory for CRS-format matrix and call this function again to extract weight matrix. If the memory of weight matrix passed to function is not sufficient, then return the firstnElemSize
non-zero elements, and the minimal required length of non-zero elements bypReqSize
. Iflist
isNULL
, then the firstnSos
rows will be returned.Arguments
prob
The COPT problem.
nSos
Number of SOS constraints.
list
Index of SOS constraints. Can be
NULL
.
sosMatBeg, sosMatCnt, sosMatIdx
andsosMatWt
Defines the weight matrix of SOS constraints in compressed row storage (CRS) format. Please see other information of
COPT_LoadProb
for an example of the CRS format.
nElemSize
Length of array for non-zero weights.
pReqSize
Pointer to minimal length of array for non-zero weights. Can be
NULL
.
COPT_GetCones
Synopsis
int COPT_GetCones(
copt_prob *prob,
int nCone,
const int *list,
int *coneBeg,
int *coneCnt,
int *coneIdx,
int nElemSize,
int *pReqSize)
Description
Get the matrix of Second-Order-Cone (SOC) constraints.
In general, users need to call this function twice to accomplish the task. Firstly, by passing
NULL
to argumentsconeBeg
,coneCnt
andconeIdx
, we get number of subscripts of variables bypReqSize
specified bynCone
andlist
. Secondly, allocate sufficient memory for CRS-format matrix and call this function again to extract weight matrix. If the memory of weight matrix passed to function is not sufficient, then return the firstnElemSize
subscripts of variables, and the minimal required length of non-zero elements bypReqSize
. Iflist
isNULL
, then the firstnCone
rows will be returned.Arguments
prob
The COPT problem.
nCone
Number of SOC constraints.
list
Index of SOC constraints. Can be
NULL
.
coneBeg, coneCnt, coneIdx
Defines the matrix of SOC constraints in compressed row storage (CRS) format. Please see other information of
COPT_LoadProb
for an example of the CRS format.
nElemSize
Length of array for non-zero weights.
pReqSize
Pointer to minimal length of array for non-zero weights. Can be
NULL
.
COPT_GetExpCones
Synopsis
int COPT_GetExpCones(
copt_prob *prob,
int nCone,
const int *list,
int *coneType,
int *coneIdx,
int nElemSize,
int *pReqSize)
Description
Get the array of exponential cone constraints.
In general, users need to call this function twice to accomplish the task. Firstly, by passing
NULL
to argumentsconeIdx
, we get number of subscripts of variables bynElemSizes
specified bynCone
andlist
. Secondly, allocate sufficient memory for array and call this function again to extract weight array. If the memory of weight array passed to function is not sufficient, then return the firstnElemSize
subscripts, and the minimal required length of subscripts bypReqSize
. Iflist
isNULL
, then the firstnCone
rows will be returned.Arguments
prob
The COPT problem.
nCone
Number of exponential cone constraints.
list
Index of exponential cone constraints. Can be
NULL
.
coneType
Type of exponential cone constraints. Please refer to Exponential Cone type for possible values.
coneIdx
Array of subscripts of variables constituting the exponential cone constraints.
nElemSize
Length of array for subscripts of variables.
pReqSize
Pointer to minimal length of array for subscripts of variables. Can be
NULL
.
COPT_GetAffineCone
Synopsis
int COPT_GetAffineCone(
copt_prob *prob,
int affConeIdx,
int *coneType,
int *nConeDim,
int *nAlphaDim,
double *alphaElem,
int *psdBeg,
int *psdCnt,
int *psdColIdx,
int *psdMatIdx,
int nPsdElemSize,
int *pPsdReqSize,
int *rowMatBeg,
int *rowMatCnt,
int *rowMatIdx,
double *rowMatElem,
double *rowConst,
int nElemSize,
int *pReqSize)
Description
Retrieve the array of affine cone constraints from the model.
Generally, the user needs to call this function twice to complete the extraction of the affine cone constraint.
First, pass
NULL
toaffConeIdx
to obtain the number of indices for the affine cone constraint array specified bynConeDim
andlist
throughpReqSize
. Then, allocate appropriate space for the array parameters, and call the function again to retrieve the specified affine cone constraint array.If the length of the affine cone constraint array passed in is insufficient, the function will return the first
nElemSize
variable index arrays and return the minimum required array length throughpReqSize
. Iflist
isNULL
, the function returns the affine cone constraint array corresponding to the firstnConeDim
rows.Arguments
prob
The COPT problem.
affConeIdx
The index of the affine cone.
coneType
The type of the affine cone. Please refer to SOC constraint types and Exponential Cone type for possible values.
nConeDim
The dimension of the affine cone.
nAlphaDim
Reserved parameter, currently not in use.
alphaElem
Reserved parameter, currently not in use.
psdBeg, psdCnt, psdColIdx, psdMatIdx
Represents the PSD terms in the affine cone.
psdBeg
indicates the starting position of the PSD terms in each affine cone term,psdCnt
specifies the number of PSD terms,psdColIdx
indicates the index of the PSD variable, andpsdMatIdx
refers to the index of the symmetric matrix.First, the number of PSD terms is returned via
pPsdReqSize
, andnPsdElemSize
represents the number of PSD terms to be retrieved.
rowMatBeg, rowMatCnt, rowMatIdx, rowMatElem
Represents the linear terms in the affine cone.
The coefficient matrix is provided in CRS-format. For detailed examples, please refer to Additional Information in
COPT_LoadProb
.
rowConst
The constant term in the affine cone.
nElemSize
Length of array for subscripts of variables.
pReqSize
Pointer to minimal length of array for subscripts of variables of the affine cone. Can be
NULL
.
COPT_GetQConstr
Synopsis
int COPT_GetQConstr(
copt_prob *prob,
int qConstrIdx,
int *qMatRow,
int *qMatCol,
double *qMatElem,
int nQElemSize,
int *pQReqSize,
int *rowMatIdx,
double *rowMatElem,
char *cRowSense,
double *dRowBound,
int nElemSize,
int *pReqSize)
Description
Get quadratic constraint.
In general, users need to call this function twice to accomplish the task. Firstly, by passing
NULL
to argumentsqMatRow
,qMatCol
,qMatElem
,rowMatIdx
androwMatElem
, we get number of non-zero quadratic terms bypQReqSize
and number of non-zero linear terms bypReqSize
specified byqConstrIdx
. Secondly, allocate sufficient memory for the quadratic terms and the linear terms, and call this function again to extract the quadratic constraint. If the memory of the array of the quadratic terms passed to function is not sufficient, then return the firstnQElemSize
quadratic terms, and the minimal required length of quadratic terms bypQReqSize
. If the memory of the array of the linear terms passed to function is not sufficient, then return the firstnElemSize
linear terms, and the minimal required length of linear terms bypReqSize
.Arguments
prob
The COPT problem.
qConstrIdx
Index of the quadratic constraint.
qMatRow
Row index of non-zero quadratic terms of the quadratic constraint (row).
qMatCol
Column index of non-zero quadratic terms of the quadratic constraint (row).
qMatElem
Values of non-zero quadratic terms of the quadratic constraint (row).
nQElemSize
Length of array for non-zero quadratic terms of the quadratic constraint (row).
pQReqSize
Pointer to minimal length of array for non-zero quadratic terms of the quadratic constraint (row). Can be
NULL
.
rowMatIdx
Column index of non-zero linear terms of the quadratic constraint (row).
rowMatElem
Values of non-zero linear terms of the quadratic constraint (row).
cRowSense
The sense of the quadratic constraint (row).
dRowBound
Right hand side of the quadratic constraint (row).
nElemSize
Length of array for non-zero linear terms of the quadratic constraint (row).
pReqSize
Pointer to minimal length of array for non-zero linear terms of the quadratic constraint (row). Can be
NULL
.
COPT_GetPSDConstr
Synopsis
int COPT_GetPSDConstr(
copt_prob *prob,
int psdConstrIdx,
int *psdColIdx,
int *symMatIdx,
int nColSize,
int *pColReqSize,
int *rowMatIdx,
double *rowMatElem,
double *dRowLower,
double *dRowUpper,
int nElemSize,
int *pReqSize)
Description
Get PSD constraint.
In general, users need to call this function twice to accomplish the task. Fisrtly, by passing
NULL
to argumentspsdColIdx
andsymMatIdx
, we get number of PSD terms bypColReqSize
specified bypsdConstrIdx
, by passingNULL
to argumentsrowMatIdx
androwMatElem
, we get number of linear terms bypReqSize
specified byqConstrIdx
. Secondly, allocate sufficient memory for the PSD terms and the linear terms, and call this function again to extract the PSD constraint. If the memory of the array of the PSD terms passed to function is not sufficient, then return the firstnColSize
PSD terms, and the minimal required length of PSD terms bypColReqSize
. If the memory of the array of the linear terms passed to function is not sufficient, then return the firstnElemSize
linear terms, and the minimal required length of linear terms bypReqSize
.Arguments
prob
The COPT problem.
psdConstrIdx
PSD constraint index.
psdColIdx
PSD variable index.
symMatIdx
Symmetric matrix index.
nColSize
Length of array for PSD terms of the PSD constraint.
pColReqSize
Pointer to minimal length of array for PSD terms of the PSD constraint. Can be
NULL
.
rowMatIdx
Column index of non-zero linear terms of the PSD constraint.
rowMatElem
Values of non-zero linear terms of the PSD constraint.
dRowLower
Pointer to lower bound of the PSD constraint.
dRowUpper
Pointer to upper bound of the PSD constraint.
nElemSize
Length of array for non-zero linear terms of the PSD constraint.
pReqSize
Pointer to minimal length of array for non-zero linear terms of the PSD constraint (row). Can be
NULL
.
COPT_GetLMIConstr
Synopsis
int COPT_GetLMIConstr(
copt_prob *prob,
int lmiConstrIdx,
int *nDim,
int *nLMILen,
int *colIdx,
int *symMatIdx,
int *constMatIdx,
int nElemSize,
int *pReqSize)
Description
Gets the LMI constraint with the specified index in the model.
Arguments
prob
The COPT problem.
lmiConstrIdx
LMI constraint index.
nDim
Pointer to the dimension of symmetric matrix in the LMI constraint.
nLMILen
Pointer to the flattened length of the LMI constraint.
colIdx
Index of scalar variable in the LMI constraint.
symMatIdx
Index of symmetric coefficient matrix in the LMI constraint.
constMatIdx
Pointer to the index of symmetric constant-term matrix in the LMI constraint.
nElemSize
Length of array for non-zero linear terms of the LMI constraint.
pReqSize
Pointer to minimal length of array for non-zero linear terms of the LMI constraint (row). Can be
NULL
.
COPT_GetIndicator
Synopsis
int COPT_GetIndicator(
copt_prob *prob,
int rowIdx,
int *binColIdx,
int *binColVal,
int *nRowMatCnt,
int *rowMatIdx,
double *rowMatElem,
char *cRowSense,
double *dRowBound,
int nElemSize,
int *pReqSize)
Description
Get the data of an indicator constraint.
In general, users need to call this function twice to accomplish the task. Firstly, by passing
NULL
to argumentsnRowMatCnt
,rowMatIdx
androwMatElem
, we get number of non-zeros elements bypReqSize
specified byrowIdx
. Secondly, allocate sufficient memory for sparse row vector and call this function again to extract data.If the memory of sparse row vector passed to function is not sufficient, then return the first
nElemSize
non-zero elements, and the minimal required length of non-zero elements bypReqSize
.Arguments
prob
The COPT problem.
rowIdx
Index of the indicator constraint.
binColIdx
Index of the indicator variable (column).
binColVal
Value of the indicator variable (column).
nRowMatCnt
Number of non-zeros elements in the linear constraint (row).
rowMatIdx
Column index of non-zeros elements in the linear constraint (row).
rowMatElem
Values of non-zero elements in the linear constraint (row).
cRowSense
The sense of the linear constraint (row).
dRowBound
Right hand side of the linear constraint (row).
nElemSize
Length of array for non-zero coefficients.
pReqSize
Pointer to minimal length of array for non-zero coefficients. Can be
NULL
.
COPT_GetIndicators
Synopsis
int COPT_GetIndicators(
copt_prob *prob,
int nInd,
int *list,
int *indType,
int *binColIdx,
int *binColVal,
int *rowMatBeg,
int *rowMatCnt,
int *rowMatIdx,
double *rowMatElem,
char *cRowSense,
double *dRowBound,
int nElemSize,
int *pReqSize)
Description
Get the data of a set of indicator constraints.
In general, users need to call this function twice to accomplish the task. Firstly, by passing
NULL
to argumentsrowMatBeg
,rowMatCnt
,rowMatIdx
, we get number of non-zeros elements bypReqSize
specified bynInd
andlist
. Secondly, allocate sufficient memory for CRS-format matrix and call this function again to extract coefficient matrix.If the memory of coefficient matrix passed to function is not sufficient, then return the first
nElemSize
non-zero elements, and the minimal required length of non-zero elements bypReqSize
. Iflist
isNULL
, then the firstnInd
rows will be returned.Arguments
prob
The COPT problem.
nInd
Number of indicator constraints (rows).
list
Index of indicator constraints. Can be
NULL
.
indType
Type of indicator constraints. Please refer to Indicator constraint types for possible values.
binColIdx
Index of the indicator variable (column).
binColVal
Value of the indicator variable (column).
rowMatBeg, rowMatCnt, rowMatIdx
androwMatElem
Defines the coefficient matrix of indcator constrants in compressed row storage (CRS) format. Please see other information of
COPT_LoadProb
for an example of the CRS format.
cRowSense
The sense of the linear constraint (row).
dRowBound
Right hand side of the linear constraint (row).
nElemSize
Length of array for non-zero coefficients.
pReqSize
Pointer to minimal length of array for non-zero coefficients. Can be
NULL
.
COPT_GetColIdx
Synopsis
int COPT_GetColIdx(copt_prob *prob, const char *colName, int *p_iCol)
Description
Get index of column by name.
Arguments
prob
The COPT problem.
colName
Name of column.
p_iCol
Pointer to index of column.
COPT_GetPSDColIdx
Synopsis
int COPT_GetPSDColIdx(copt_prob *prob, const char *psdColName, int *p_iPSDCol)
Description
Get index of PSD variable by name.
Arguments
prob
The COPT problem.
psdColName
Name of PSD variable.
p_iPSDCol
Pointer to index of PSD variable.
COPT_GetRowIdx
Synopsis
int COPT_GetRowIdx(copt_prob *prob, const char *rowName, int *p_iRow)
Description
Get index of row by name.
Arguments
prob
The COPT problem.
rowName
Name of row.
p_iRow
Pointer to index of row.
COPT_GetQConstrIdx
Synopsis
int COPT_GetQConstrIdx(copt_prob *prob, const char *qConstrName, int *p_iQConstr)
Description
Get index of quadratic constraint by name.
Arguments
prob
The COPT problem.
qConstrName
Name of quadratic constraint.
p_iQConstr
Pointer to index of quadratic constraint.
COPT_GetPSDConstrIdx
Synopsis
int COPT_GetPSDConstrIdx(copt_prob *prob, const char *psdConstrName, int *p_iPSDConstr)
Description
Get index of PSD constraint by name.
Arguments
prob
The COPT problem.
psdConstrName
Name of PSD constraint.
p_iPSDConstr
Pointer to index of PSD constraint.
COPT_GetLMIConstrIdx
Synopsis
int COPT_GetLMIConstrIdx(copt_prob *prob, const char *lmiConstrName, int *p_iLMIConstr)
Description
Get index of LMI constraint by name.
Arguments
prob
The COPT problem.
lmiConstrName
Name of LMI constraint.
p_iLMIConstr
Pointer to index of LMI constraint.
COPT_GetIndicatorIdx
Synopsis
int COPT_GetIndicatorIdx(copt_prob *prob, const char *indicatorName, int *p_iIndicator)
Description
Get index of indicator constraint by name.
Arguments
prob
The COPT problem.
indicatorName
Name of indicator constraint.
p_iIndicator
Pointer to index of indicator constraint.
COPT_GetAffineConeIdx
Synopsis
int COPT_GetAffineConeIdx(copt_prob *prob, const char *affConeName, int *p_iAffCone)
Description
Get index of affine cone by name.
Arguments
prob
The COPT problem.
affConeName
Name of affine cone.
p_iAffCone
Pointer to index of affine cone.
COPT_GetColInfo
Synopsis
int COPT_GetColInfo(copt_prob *prob, const char *infoName, int num, const int *list, double *info)
Description
Get information of column. If
list
isNULL
, then information of the firstnum
columns will be returned.Arguments
prob
The COPT problem.
infoName
Name of information. Please refer to Information for supported information.
num
Number of columns.
list
Index of columns. Can be
NULL
.
info
Array of information.
COPT_GetPSDColInfo
Synopsis
int COPT_GetPSDColInfo(copt_prob *prob, const char *infoName, int iCol, double *info)
Description
Get information of PSD variable.
Arguments
prob
The COPT problem.
infoName
Name of information. Please refer to Information for supported information.
iCol
Index of PSD variable.
info
Array of information.
COPT_GetRowInfo
Synopsis
int COPT_GetRowInfo(copt_prob *prob, const char *infoName, int num, const int *list, double *info)
Description
Get information of row. If
list
isNULL
, then information of the firstnum
rows will be returned.Arguments
prob
The COPT problem.
infoName
Name of information. Please refer to Information for supported information.
num
Number of rows.
list
Index of rows. Can be
NULL
.
info
Array of information.
COPT_GetQConstrInfo
Synopsis
int COPT_GetQConstrInfo(copt_prob *prob, const char *infoName, int num, const int *list, double *info)
Description
Get information of quadratic constraints. If
list
isNULL
, then information of the firstnum
quadratic constraints will be returned.Arguments
prob
The COPT problem.
infoName
Name of information. Please refer to Information for supported information.
num
Number of quadratic constraints.
list
Index of quadratic constraints. Can be
NULL
.
info
Array of information.
COPT_GetPSDConstrInfo
Synopsis
int COPT_GetPSDConstrInfo(copt_prob *prob, const char *infoName, int num, const int* list, double *info)
Description
Get information of PSD constraints. If
list
isNULL
, then information of the firstnum
PSD constraints will be returned.Arguments
prob
The COPT problem.
infoName
Name of information. Please refer to Information for supported information.
num
Number of PSD constraints.
list
Index of PSD constraints. Can be
NULL
.
info
Array of information.
COPT_GetLMIConstrInfo
Synopsis
int COPT_GetLMIConstrInfo(copt_prob *prob, const char *infoName, int iLMI, double *info)
Description
Get a set of information about LMI constraints.
Arguments
prob
The COPT problem.
infoName
Name of information. Possible values are:
COPT_DBLINFO_SLACK
andCOPT_DBLINFO_DUAL
.
iLMI
The index of the LMI constraint whose information is to be retrieved.
info
Array of information.
COPT_GetColType
Synopsis
int COPT_GetColType(copt_prob *prob, int num, const int *list, char *type)
Description
Get types of columns. If
list
isNULL
, then types of the firstnum
columns will be returned.Arguments
prob
The COPT problem.
num
Number of columns.
list
Index of columns. Can be
NULL
.
type
Types of columns.
COPT_GetColBasis
Synopsis
int COPT_GetColBasis(copt_prob *prob, int num, const int *list, int *colBasis)
Description
Get basis status of columns. If
list
isNULL
, then basis status of the firstnum
columns will be returned.Arguments
prob
The COPT problem.
num
Number of columns.
list
Index of columns. Can be
NULL
.
colBasis
Basis status of columns.
COPT_GetRowBasis
Synopsis
int COPT_GetRowBasis(copt_prob *prob, int num, const int *list, int *rowBasis)
Description
Get basis status of rows. If
list
isNULL
, then basis status of the firstnum
rows will be returned.Arguments
prob
The COPT problem.
num
Number of rows.
list
Index of rows. Can be
NULL
.
rowBasis
Basis status of rows.
COPT_GetQConstrSense
Synopsis
int COPT_GetQConstrSense(copt_prob *prob, int num, const int *list, char *sense)
Description
Get senses of quadratic constraints. If
list
isNULL
, then types of the firstnum
quadratic constraints will be returned.Arguments
prob
The COPT problem.
num
Number of quadratic constraints.
list
Index of quadratic constraints. Can be
NULL
.
sense
Array of senses.
COPT_GetQConstrRhs
Synopsis
int COPT_GetQConstrRhs(copt_prob *prob, int num, const int *list, double *rhs)
Description
Get RHS of quadratic constraints. If
list
isNULL
, then types of the firstnum
quadratic constraints will be returned.Arguments
prob
The COPT problem.
num
Number of quadratic constraints.
list
Index of quadratic constraints. Can be
NULL
.
rhs
Array of RHS.
COPT_GetColName
Synopsis
int COPT_GetColName(copt_prob *prob, int iCol, char *buff, int buffSize, int *pReqSize)
Description
Get name of column by index. If memory of
buff
is not sufficient, then return the firstbuffSize
length of sub-string, and the length of name requested bypReqSize
. Ifbuff
isNULL
, then we can get the length of name requested bypReqSize
.Arguments
prob
The COPT problem.
iCol
Index of column.
buff
Buffer for storing name.
buffSize
Length of the buffer.
pReqSize
Length of the requested name. Can be
NULL
.
COPT_GetPSDColName
Synopsis
int COPT_GetPSDColName(copt_prob *prob, int iPSDCol, char *buff, int buffSize, int *pReqSize)
Description
Get name of PSD variable by index. If memory of
buff
is not sufficient, then return the firstbuffSize
length of sub-string, and the length of name requested bypReqSize
. Ifbuff
isNULL
, then we can get the length of name requested bypReqSize
.Arguments
prob
The COPT problem.
iPSDCol
Index of PSD variable.
buff
Buffer for storing name.
buffSize
Length of the buffer.
pReqSize
Length of the requested name. Can be
NULL
.
COPT_GetRowName
Synopsis
int COPT_GetRowName(copt_prob *prob, int iRow, char *buff, int buffSize, int *pReqSize)
Description
Get name of row by index. If memory of
buff
is not sufficient, then return the firstbuffSize
length of sub-string, and the length of name requested bypReqSize
. Ifbuff
isNULL
, then we can get the length of name requested bypReqSize
.Arguments
prob
The COPT problem.
iRow
Index of row.
buff
Buffer for storing name.
buffSize
Length of the buffer.
pReqSize
Length of the requested name. Can be
NULL
.
COPT_GetQConstrName
Synopsis
int COPT_GetQConstrName(copt_prob *prob, int iQConstr, char *buff, int buffSize, int *pReqSize)
Description
Get name of quadratic constraint by index. If memory of
buff
is not sufficient, then return the firstbuffSize
length of sub-string, and the length of name requested bypReqSize
. Ifbuff
isNULL
, then we can get the length of name requested bypReqSize
.Arguments
prob
The COPT problem.
iQConstr`
Index of quadratic constraint.
buff
Buffer for storing name.
buffSize
Length of the buffer.
pReqSize
Length of the requested name. Can be
NULL
.
COPT_GetPSDConstrName
Synopsis
int COPT_GetPSDConstrName(copt_prob *prob, int iPSDConstr, char *buff, int buffSize, int *pReqSize)
Description
Get name of PSD constraint by index. If memory of
buff
is not sufficient, then return the firstbuffSize
length of sub-string, and the length of name requested bypReqSize
. Ifbuff
isNULL
, then we can get the length of name requested bypReqSize
.Arguments
prob
The COPT problem.
iPSDConstr`
Index of PSD constraint.
buff
Buffer for storing name.
buffSize
Length of the buffer.
pReqSize
Length of the requested name. Can be
NULL
.
COPT_GetLMIConstrName
Synopsis
int COPT_CALL COPT_GetLMIConstrName(copt_prob *prob, int iLMIConstr, char *buff, int buffSize, int *pReqSize)
Description
Get name of LMI constraint by index. If memory of
buff
is not sufficient, then return the firstbuffSize
length of sub-string, and the length of name requested bypReqSize
. Ifbuff
isNULL
, then we can get the length of name requested bypReqSize
.Arguments
prob
The COPT problem.
iLMIConstr
Index of LMI constraint.
buff
Buffer for storing name.
buffSize
Length of the buffer.
pReqSize
Length of the requested name. Can be
NULL
.
COPT_GetIndicatorName
Synopsis
int COPT_GetIndicatorName(copt_prob *prob, int iIndicator, char *buff, int buffSize, int *pReqSize)
Description
Get name of indicator constraints by index. If memory of
buff
is not sufficient, then return the firstbuffSize
length of sub-string, and the length of name requested bypReqSize
. Ifbuff
isNULL
, then we can get the length of name requested bypReqSize
.Arguments
prob
The COPT problem.
iIndicator
Index of indicator constraint.
buff
Buffer for storing name.
buffSize
Length of the buffer.
pReqSize
Length of the requested name. Can be
NULL
.
COPT_GetAffineConeName
Synopsis
int COPT_GetAffineConeName(copt_prob *prob, int iAffCone, char *buff, int buffSize, int *pReqSize)
Description
Get name of affine cone by index. If memory of
buff
is not sufficient, then return the firstbuffSize
length of sub-string, and the length of name requested bypReqSize
. Ifbuff
isNULL
, then we can get the length of name requested bypReqSize
.Arguments
prob
The COPT problem.
iAffCone
Index of affine cone.
buff
Buffer for storing name.
buffSize
Length of the buffer.
pReqSize
Length of the requested name. Can be
NULL
.
COPT_GetLMIConstrRhs
Synopsis
int COPT_GetLMIConstrRhs(copt_prob *prob, int num, const int *list, int *constMatIdx)
Description
Get the constant-term symmetric matrix of
num
LMI constraints.Arguments
prob
The COPT problem.
num
Number of LMI constraints.
list
Index of LMI constraints.
constMatIdx
Index of constant-term symmetric in the LMI constraints.
Accessing and setting parameters
COPT_SetIntParam
Synopsis
int COPT_SetIntParam(copt_prob *prob, const char *paramName, int intParam)
Description
Sets an integer parameter.
Arguments
prob
The COPT problem.
paramName
The name of the integer parameter.
intParam
The value of the integer parameter.
COPT_GetIntParam, COPT_GetIntParamDef/Min/Max
Synopsis
int COPT_GetIntParam(copt_prob *prob, const char *paramName, int *p_intParam)
int COPT_GetIntParamDef(copt_prob *prob, const char *paramName, int *p_intParam)
int COPT_GetIntParamMin(copt_prob *prob, const char *paramName, int *p_intParam)
int COPT_GetIntParamMax(copt_prob *prob, const char *paramName, int *p_intParam)
Description
Gets the
current
default
minimal
maximal
value of an integer parameter.
Arguments
prob
The COPT problem.
paramName
The name of the integer parameter.
p_intParam
Pointer to the value of the integer parameter.
COPT_SetDblParam
Synopsis
int COPT_SetDblParam(copt_prob *prob, const char *paramName, double dblParam)
Description
Sets a double parameter.
Arguments
prob
The COPT problem.
paramName
The name of the double parameter.
dblParam
The value of the double parameter.
COPT_GetDblParam, COPT_GetDblParamDef/Min/Max
Synopsis
int COPT_GetDblParam(copt_prob *prob, const char *paramName, double *p_dblParam)
int COPT_GetDblParamDef(copt_prob *prob, const char *paramName, double *p_dblParam)
int COPT_GetDblParamMin(copt_prob *prob, const char *paramName, double *p_dblParam)
int COPT_GetDblParamMax(copt_prob *prob, const char *paramName, double *p_dblParam)
Description
Gets the
current
default
minimal
maximal
value of a double parameter.
Arguments
prob
The COPT problem.
paramName
The name of the double parameter.
p_dblParam
Pointer to the value of the double parameter.
COPT_ResetParam
Synopsis
int COPT_ResetParam(copt_prob *prob)
Description
Reset parameters to default settings.
Arguments
prob
The COPT problem.
COPT_WriteParam
Synopsis
int COPT_WriteParam(copt_prob *prob, const char *parfilename)
Description
Writes user defined parameters to a file. This API function will write out all the parameters that are different from their default values.
Arguments
prob
The COPT problem.
parfilename
The path to the parameter file.
COPT_WriteParamStr
Synopsis
int COPT_WriteParamStr(copt_prob *prob, char *str, int nStrSize, int *pReqSize)
Description
Writes the modified parameters to a string buffer.
Arguments
prob
The COPT problem.
str
String buffer of modified parameters.
nStrSize
The size of string buffer.
pReqSize
Minimum space requirement of string buffer for modified parameters.
COPT_ReadParam
Synopsis
int COPT_ReadParam(copt_prob *prob, const char *parfilename)
Description
Reads and applies parameters settings as defined in the parameter file.
Arguments
prob
The COPT problem.
parfilename
The path to the parameter file.
COPT_ReadParamStr
Synopsis
int COPT_ReadParamStr(copt_prob *prob, const char *strParam)
Description
Read parameter settings from string buffer, and set parameters in COPT.
Arguments
prob
The COPT problem.
strParam
String buffer of parameter settings.
Accessing attributes
COPT_GetIntAttr
Synopsis
int COPT_GetIntAttr(copt_prob *prob, const char *attrName, int *p_intAttr)
Description
Gets the value of an integer attribute.
Arguments
prob
The COPT problem.
attrName
The name of the integer attribute.
p_intAttr
Pointer to the value of the integer attribute.
COPT_GetDblAttr
Synopsis
int COPT_GetDblAttr(copt_prob *prob, const char *attrName, int *p_dblAttr)
Description
Gets the value of an double attribute.
Arguments
prob
The COPT problem.
attrName
The name of the double attribute.
p_dblAttr
Pointer to the value of the double attribute.
Logging utilities
COPT_SetLogFile
Synopsis
int COPT_SetLogFile(copt_prob *prob, char *logfilename)
Description
Set log file for the problem.
Arguments
prob
The COPT problem.
logfilename
The path to the log file.
COPT_SetLogCallback
Synopsis
int COPT_SetLogCallback(copt_prob *prob, void (*logcb)(char *msg, void *userdata), void *userdata)
Description
Set message callback for the problem.
Arguments
prob
The COPT problem.
logcb
Callback function for message.
userdata
User defined data. The data will be passed to the solver without modification.
MIP start utilities
COPT_AddMipStart
Synopsis
int COPT_AddMipStart(copt_prob *prob, int num, const int *list, double *colVal)
Description
Add MIP start information for the problem. If
list
isNULL
, then information of the firstnum
columns will be added.One MIP start information will be added for each call to this function.
Arguments
prob
The COPT problem.
num
Number of variables (columns).
list
Index of variables (columns). Can be
NULL
.
colVal
MIP start information.
COPT_ReadMst
Synopsis
int COPT_ReadMst(copt_prob *prob, const char *mstfilename)
Description
Read MIP start information from file, and used as initial solution for the problem.
Arguments
prob
The COPT problem.
mstfilename
The path to the MIP start file.
COPT_WriteMst
Synopsis
int COPT_WriteMst(copt_prob *prob, const char *mstfilename)
Description
Write solution or existed MIP start information in problem to file.
Arguments
prob
The COPT problem.
mstfilename
The path to the MIP start file.
IIS utilities
COPT_ComputeIIS
Synopsis
int COPT_ComputeIIS(copt_prob *prob)
Description
Compute IIS (Irreducible Inconsistent Subsystem) for infeasible problem.
Arguments
prob
The COPT problem.
COPT_GetColLowerIIS
Synopsis
int COPT_GetColLowerIIS(copt_prob *prob, int num, const int *list, int *colLowerIIS)
Description
Get IIS status of lower bounds of columns. If
list
isNULL
, then IIS status of the firstnum
columns will be returned.Arguments
prob
The COPT problem.
num
Number of columns.
list
Index of columns. Can be
NULL
.
colLowerIIS
IIS status of lower bounds of columns.
COPT_GetColUpperIIS
Synopsis
int COPT_GetColUpperIIS(copt_prob *prob, int num, const int *list, int *colUpperIIS)
Description
Get IIS status of upper bounds of columns. If
list
isNULL
, then IIS status of the firstnum
columns will be returned.Arguments
prob
The COPT problem.
num
Number of columns.
list
Index of columns. Can be
NULL
.
colUpperIIS
IIS status of upper bounds of columns.
COPT_GetRowLowerIIS
Synopsis
int COPT_GetRowLowerIIS(copt_prob *prob, int num, const int *list, int *rowLowerIIS)
Description
Get IIS status of lower bounds of rows. If
list
isNULL
, then IIS status of the firstnum
rows will be returned.Arguments
prob
The COPT problem.
num
Number of rows.
list
Index of rows. Can be
NULL
.
rowLowerIIS
IIS status of lower bounds of rows.
COPT_GetRowUpperIIS
Synopsis
int COPT_GetRowUpperIIS(copt_prob *prob, int num, const int *list, int *rowUpperIIS)
Description
Get IIS status of upper bounds of rows. If
list
isNULL
, then IIS status of the firstnum
rows will be returned.Arguments
prob
The COPT problem.
num
Number of rows.
list
Index of rows. Can be
NULL
.
rowUpperIIS
IIS status of upper bounds of rows.
COPT_GetSOSIIS
Synopsis
int COPT_GetSOSIIS(copt_prob *prob, int num, const int *list, int *sosIIS)
Description
Get IIS status of SOS constraints. If
list
isNULL
, then IIS status of the firstnum
SOS constraints will be returned.Arguments
prob
The COPT problem.
num
Number of SOS constraints.
list
Index of SOS constraints. Can be
NULL
.
sosIIS
IIS status of SOS constraints.
COPT_GetIndicatorIIS
Synopsis
int COPT_GetIndicatorIIS(copt_prob *prob, int num, const int *list, int *indicatorIIS)
Description
Get IIS status of indicator constraints. If
list
isNULL
, then IIS status of the firstnum
indicator constraints will be returned.Arguments
prob
The COPT problem.
num
Number of indicator constraints.
list
Index of indicator constraints. Can be
NULL
.
indicatorIIS
IIS status of indicator constraints.
Feasibility relaxation utilities
COPT_FeasRelax
Synopsis
int COPT_FeasRelax(copt_prob *prob, double *colLowPen, double *colUppPen, double *rowBndPen, double *rowUppPen)
Description
Compute feasibility relaxation to infeasible problem.
Arguments
prob
The COPT problem.
colLowPen
Penalty for lower bounds of columns. If
NULL
, then no relaxation for lower bounds of columns are allowed; If penalty incolLowPen
isCOPT_INFINITY
, then no relaxation is allowed for corresponding bound.
colUppPen
Penalty for upper bounds of columns. If
NULL
, then no relaxation for upper bounds of columns are allowed; If penalty incolUppen
isCOPT_INFINITY
, then no relaxation is allowed for corresponding bound.
rowBndPen
Penalty for bounds of rows. If
NULL
, then no relaxation for bounds of rows are allowed; If penalty inrowBndPen
isCOPT_INFINITY
, then no relaxation is allowed for corresponding bound.
rowUppPen
Penalty for upper bounds of rows. If problem has two-sided rows, and
rowUppPen
is notNULL
, thenrowUppPen
is penalty for upper bounds of rows; If penalty inrowUppPen
isCOPT_INFINITY
, then no relaxation is allowed for corresponding bound.Note: Normally, just set
rowUppPen
toNULL
.
COPT_WriteRelax
Synopsis
int COPT_WriteRelax(copt_prob *prob, const char *relaxfilename)
Description
Write feasrelax problem to file.
Arguments
prob
The COPT problem.
relaxfilename
Name of feasrelax problem file.
Parameter tuning utilities
COPT_Tune
Synopsis
int COPT_Tune(copt_prob *prob)
Description
Parameter tuning of the model.
Arguments
prob
COPT model.
COPT_LoadTuneParam
Synopsis
int COPT_LoadTuneParam(copt_prob *prob, int idx)
Description
Load the parameter tuning results of the specified number into the model.
Arguments
prob
COPT model.
idx
The number of the parameter tuning result.
COPT_ReadTune
Synopsis
int COPT_ReadTune(copt_prob *prob, const char *tunefilename)
Description
Read the parameter combination to be tuned from the tuning file to the model.
Arguments
prob
COPT model.
tunefilename
Tuning file names.
COPT_WriteTuneParam
Synopsis
int COPT_WriteTuneParam(copt_prob *prob, int idx, const char *parfilename)
Description
Output the parameter tuning result of the specified number to the parameter file.
Arguments
prob
COPT model.
idx
The number of the parameter tuning result.
parfilename
parameter file name.
Callback utilities
Certain callback utilities methods can only be called in certain contexts, which are listed below:
Context |
Methods |
---|---|
COPT_CBCONTEXT_INCUMBENT |
|
COPT_CBCONTEXT_MIPSOL |
COPT_AddCallbackLazyConstr, COPT_AddCallbackLazyConstrs, COPT_AddCallbackSolution, COPT_GetCallbackInfo |
COPT_CBCONTEXT_MIPRELAX |
COPT_AddCallbackUserCut, COPT_AddCallbackUserCuts, COPT_AddCallbackSolution, COPT_GetCallbackInfo |
COPT_CBCONTEXT_MIPNODE |
COPT_AddLazyConstr
Synopsis
int COPT_AddLazyConstr(
copt_prob *prob,
int nRowMatCnt,
const int *rowMatIdx,
const double *rowMatElem,
char cRowSense,
double dRowBound,
double dRowUpper,
const char *rowName)
Description
Add a lazy constraint to the MIP model.
Arguments
prob
The COPT problem.
nRowMatCnt
Number of non-zero elements in the lazy constraint.
rowMatIdx
Column index of non-zero elements in the lazy constraint.
rowMatElem
Values of non-zero elements in the lazy constraint.
cRowSense
The sense of the new lazy constraint.
Please refer to Constraint senses for all the supported types.
If
cRowSense
is 0, thendRowBound
anddRowUpper
will be treated as lower and upper bounds for the constraint. This is the recommended method for defining constraints.If
cRowSense
is provided, thendRowBound
anddRowUpper
will be treated as RHS and range for the constraint. In this case,dRowUpper
is only required whencRowSense = COPT_RANGE
, wherelower bound is
dRowBound - dRowUpper
upper bound is
dRowBound
dRowBound
Lower bound or RHS of the lazy constraint.
dRowUpper
Upper bound or range of the lazy constraint.
rowName
The name of the lazy constraint. Can be
NULL
.
COPT_AddLazyConstrs
Synopsis
int COPT_AddLazyConstrs(
copt_prob *prob,
int nAddRow,
const int *rowMatBeg,
const int *rowMatCnt,
const int *rowMatIdx,
const double *rowMatElem,
const char *rowSense,
const double *rowBound,
const double *rowUpper,
char const *const *rowNames)
Description
Add a set of lazy constraints to the MIP model.
Arguments
prob
The COPT problem.
nAddRow
Number of new lazy constraints.
rowMatBeg, rowMatCnt, rowMatIdx
androwMatElem
Defines the coefficient matrix in compressed row storage (CRS) format. The CRS format is similar to the CCS format described in the other information of
COPT_LoadProb
.
rowSense
Senses of new lazy constraints.
Please refer to Constraint senses for all the supported types.
If
rowSense
isNULL
, thenrowBound
androwUpper
will be treated as lower and upper bounds for constraints. This is the recommended method for defining constraints.If
rowSense
is provided, thenrowBound
androwUpper
will be treated as RHS and range for constraints. In this case,rowUpper
is only required when there areCOPT_RANGE
constraints, where thelower bound is
rowBound[i] - fabs(rowUpper[i])
upper bound is
rowBound[i]
rowBound
Lower bounds or RHS of new lazy constraints.
rowUpper
Upper bounds or range of new lazy constraints.
rowNames
Names of new lazy constraints. Can be
NULL
.
COPT_AddUserCut
Synopsis
int COPT_AddUserCut(
copt_prob* prob,
int nRowMatCnt,
const int* rowMatIdx,
const double* rowMmatElem,
char cRowSense,
double dRowBound,
double dRowUpper,
const char* rowName)
Description
Add a user cut to the MIP model.
Arguments
prob
The COPT problem.
nRowMatCnt
Number of non-zero elements in the user cut.
rowMatIdx
Column index of non-zero elements in the user cut.
rowMatElem
Values of non-zero elements in the user cut.
cRowSense
The sense of the user cut.
Please refer to Constraint senses for all the supported types.
If
cRowSense
is 0, thendRowBound
anddRowUpper
will be treated as lower and upper bounds for the constraint. This is the recommended method for defining constraints.If
cRowSense
is provided, thendRowBound
anddRowUpper
will be treated as RHS and range for the constraint. In this case,dRowUpper
is only required whencRowSense = COPT_RANGE
, wherelower bound is
dRowBound - dRowUpper
upper bound is
dRowBound
dRowBound
Lower bound or RHS of the user cut.
dRowUpper
Upper bound or range of the user cut.
rowName
The name of the user cut. Can be
NULL
.
COPT_AddUserCuts
Synopsis
int COPT_CALL COPT_AddUserCuts(
copt_prob *prob,
int nAddRow,
const int *rowMatBeg,
const int *rowMatCnt,
const int *rowMatIdx,
const double *rowMatElem,
const char *rowSense,
const double *rowBound,
const double *rowUpper,
char const *const *rowNames)
Description
Add a set of user cuts to the MIP model.
Arguments
prob
The COPT problem.
nAddRow
Number of new user cuts.
rowMatBeg, rowMatCnt, rowMatIdx
androwMatElem
Defines the coefficient matrix in compressed row storage (CRS) format. The CRS format is similar to the CCS format described in the other information of
COPT_LoadProb
.
rowSense
Senses of new user cuts.
Please refer to Constraint senses for all the supported types.
If
rowSense
isNULL
, thenrowBound
androwUpper
will be treated as lower and upper bounds for constraints. This is the recommended method for defining constraints.If
rowSense
is provided, thenrowBound
androwUpper
will be treated as RHS and range for constraints. In this case,rowUpper
is only required when there areCOPT_RANGE
constraints, where thelower bound is
rowBound[i] - fabs(rowUpper[i])
upper bound is
rowBound[i]
rowBound
Lower bounds or RHS of new user cuts.
rowUpper
Upper bounds or range of new user cuts.
rowNames
Names of new user cuts. Can be
NULL
.
COPT_SetCallback
Synopsis
int COPT_SetCallback(
copt_prob *prob,
int (COPT_CALL *cb)(copt_prob *prob, void *cbdata, int cbctx, void *userdata),
int cbctx,
void *userdata)
Description
Set the callback function of the model.
Arguments
prob
The COPT problem.
cb
Callback function.
cbctx
Callback context. Please refer to Callback context .
userdata
User defined data. The data will be passed to the solver without modification.
COPT_GetCallbackInfo
Synopsis
int COPT_GetCallbackInfo(void *cbdata, const char* cbinfo, void *p_val)
Description
Retrieve the value of the specified callback information.
Arguments
cbdata
The cbdata argument that was passed into the user callback by COPT. This argument must be passed unmodified from the user callback to COPT_GetCallbackInfo().
cbinfo
The name of the callback information. Please refer to Callback information for possible values.
p_val
Pointer to the value of the callback information.
COPT_AddCallbackSolution
Synopsis
int COPT_AddCallbackSolution(void *cbdata, const double *sol, double* p_objval)
Description
Set feasible solutions for the specified variables.
Arguments
cbdata
The cbdata argument that was passed into the user callback by COPT. This argument must be passed unmodified from the user callback to COPT_AddCallbackSolution().
sol
The solution vector.
p_objval
Pointer to the objective value for solution.
COPT_AddCallbackUserCut
Synopsis
int COPT_AddCallbackUserCut(
void *cbdata,
int nRowMatCnt,
const int *rowMatIdx,
const double *rowMatElem,
char cRowSense,
double dRowRhs)
Description
Add a user cut to the MIP model from within the callback function.
Arguments
cbdata
The cbdata argument that was passed into the user callback by COPT. This argument must be passed unmodified from the user callback to COPT_AddCallbackUserCut().
nRowMatCnt
Number of non-zero elements in the user cut.
rowMatIdx
Column index of non-zero elements in the user cut.
rowMatElem
Values of non-zero elements in the user cut.
cRowSense
The sense of the new user cut. It supports for
LESS_EQUAL
,GREATER_EQUAL
,EQUAL
andFREE
.The user cut added from within callback can only have a single bound.
dRowRhs
RHS of the user cut.
COPT_AddCallbackUserCuts
Synopsis
int COPT_AddCallbackUserCuts(
void *cbdata,
int nAddRow,
const int *rowMatBeg,
const int *rowMatCnt,
const int *rowMatIdx,
const double *rowMatElem,
const char *rowSense,
const double *rowRhs)
Description
Add a set of user cuts to the MIP model from within the callback function.
Arguments
cbdata
The cbdata argument that was passed into the user callback by COPT. This argument must be passed unmodified from the user callback to COPT_AddCallbackUserCuts().
nAddRow
Number of new user cuts.
rowMatBeg, rowMatCnt, rowMatIdx
androwMatElem
Defines the coefficient matrix in compressed row storage (CRS) format. The CRS format is similar to the CCS format described in the other information of
COPT_LoadProb
.
rowSense
Senses of new user cuts. It supports for
LESS_EQUAL
,GREATER_EQUAL
,EQUAL
andFREE
.The user cuts added from within callback can only have single bounds.
rowRhs
RHS of new user cuts.
COPT_AddCallbackLazyConstr
Synopsis
int COPT_AddCallbackLazyConstr(
void *cbdata,
int nRowMatCnt,
const int *rowMatIdx,
const double *rowMatElem,
char cRowSense,
double dRowRhs)
Description
Add a lazy constraint to the MIP model from within the callback function.
Arguments
cbdata
The cbdata argument that was passed into the user callback by COPT. This argument must be passed unmodified from the user callback to COPT_AddCallbackLazyConstr().
nRowMatCnt
Number of non-zero elements in the lazy constraint.
When
nRowMatCnt<=0
, the MIP candidate solution will be directly rejected without adding a lazy constraint. AndrowMatIdx
,rowMatElem
,cRowSense
anddRowRhs
will be ignored.
rowMatIdx
Column index of non-zero elements in the lazy constraint.
rowMatElem
Values of non-zero elements in the lazy constraint.
cRowSense
The sense of new lazy constraint. It supports for
LESS_EQUAL
,GREATER_EQUAL
,EQUAL
andFREE
.The lazy constraint added from within callback can only have a single bound.
dRowRhs
RHS of the lazy constraint.
COPT_AddCallbackLazyConstrs
Synopsis
int COPT_AddCallbackLazyConstrs(
void *cbdata,
int nAddRow,
const int *rowMatBeg,
const int *rowMatCnt,
const int *rowMatIdx,
const double *rowMatElem,
const char *rowSense,
const double *rowRhs)
Description
Add a set of lazy constraints to the MIP model from within the callback function.
Arguments
cbdata
The cbdata argument that was passed into the user callback by COPT. This argument must be passed unmodified from the user callback to COPT_AddCallbackLazyConstrs().
nAddRow
Number of new lazy constraints.
When
nAddRow<=0
, the MIP candidate solution will be directly rejected without adding lazy constraints.And other parameters(apart from
cbdata
) will be ignored.
rowMatBeg, rowMatCnt, rowMatIdx
androwMatElem
Defines the coefficient matrix in compressed row storage (CRS) format. The CRS format is similar to the CCS format described in the other information of
COPT_LoadProb
.
rowSense
Senses of new lazy constraints. It supports for
LESS_EQUAL
,GREATER_EQUAL
,EQUAL
andFREE
.The lazy constraints added from within callback can only have single bounds.
rowRhs
RHS of new lazy constraints.
Note: If the user gives a solution to COPT in a callback, the user should ensure that this fulfills the lazy constraint callback since that won’t be called for user-provided solutions.
Other API functions
COPT_GetRetcodeMsg
Synopsis
int COPT_GetRetcodeMsg(int code, char *buff, int buffSize)
Description
Obtains a C-style string which explains a return code value in plain text.
Arguments
code
The return code from a COPT API function.
buff
A buffer for holding the resulting string.
buffSize
The size of the above buffer.
COPT_Interrupt
Synopsis
int COPT_Interrupt(copt_prob *prob)
Description
Interrupt solving process of current problem.
Arguments
prob
The COPT problem.