8.4.4. Model Operations¶
- Model related APIs, includes:
Model creation and modification.
APIs to optimize model.
APIs to query model data or solution.
APIs to serialize model data to disk file, or load data from disk file.
Functions
Add a new linear constraint to model
Add a batch of constraints to model
Add a new quadratic constraint to model
Add a new psd constraint to model
Add a new psd variable to model
Add new quadratic objective terms to current objective function
Add a new range constraint (has both LHS and RHS) to model
Add a batch of range constraints to model
Add a new range psd constraint (has both LHS and RHS) to model
Add a new Special Ordered Set (SOS) constraint to model
Add a new indicator constraint to model
Add a new variable to model
Add a batch of variables to model
Change coefficients in constraint matrix
Compute an IIS(Irreducible Inconsistent Subsystem)
Create a (deep) copy from an existing model
Delete constraints from model
Delete quadratic constraints from model
Delete all quadratic objective terms from model
Delete SOS constraints from model
Delete general constraints from model
Delete variables from model by variable indices
Free an existing model and release all its associated resources
Retrieve a single constraint matrix coefficient
Retrieve a single linear constraint by its name
Retrieve a single quadratic constraint by its name
Get coefficient value associated with specified constraint and variable
Get a batch of constraints by index range
Retrieve a quadratic constraint by its index
Retrieve a single psd constraint matrix coefficient
Retrieve all quadratic objective terms from model
Retrieve the variables and weights of SOS constraints
Retrieve an indicator constraint by its index
Retrieve a variable by its name
Retrieve non-zeros for a range of variables from the constraint matrix
Create a new optimization model from an environment, and initialize the newly created model with provided arguments
Create a new optimization model from an environment, and initialize the newly created model with provided variables
Optimize a model
Load data to an existing model from file
Load a model from file
Reset the model to an unsolved state, discarding any previously computed solution
Set coefficient value associated with specified constraint and variable
Serialize model data to file
-
int MDOaddconstr(MDOmodel *model, int numnz, int *cind, double *cval, char sense, double rhs, const char *constrname)¶
Add a new linear constraint to model.
- Parameters
model (MDOmodel*) – [in] The model pointer.
numnz (int) – [in] Number of non-zeros.
cind (int*) – [in] Variable indices for non-zeros in the new constraint.
cval (double*) – [in] Non-zero values in the new constraint.
sense (char) –
[in] The sense of the new constraint. Valid sense types include:
MDO_EQUAL(‘=’) for equal,
MDO_LESS_EQUAL(‘<’) for less-than-or-equal,
MDO_GREATER_EQUAL(‘>’) for greater-than-or-equal.
rhs (double) – [in] The right-hand-side value of the new constraint.
constrname (const char*) – [in] The constraint name. Can be NULL.
- Returns
A response code that specifies the status of the function.
-
int MDOaddconstrs(MDOmodel *model, int numconstrs, int numnz, int *cbeg, int *cind, double *cval, char *sense, double *rhs, const char **constrnames)¶
Add a batch of constraints to model.
- Parameters
model (MDOmodel*) – [in] The model pointer.
numconstrs (int) – [in] The number of new constraints.
numnz (int) – [in] The total number of non-zeros for these new constraints.
cbeg (int*) –
[in] Constraint matrix non-zero values are passed into this function in Compressed Sparse Row (CSR) format. Each constraint in the constraint matrix is represented as a list of index-value pairs, where each index entry provides the variable index for a non-zero coefficient, and each value entry provides the corresponding non-zero value.
Each constraint in the model has a cbeg and clen value, indicating the start position of the non-zeros for that constraint in the cind and cval arrays. cbeg[i + 1] - cbeg[i] is the number of non-zero values for ith constraint. It should contain at least numconstrs elements. Can be NULL if numconstrs is zero.
For example, if vbeg[3] = 10 and cbeg[4] = 12 , that would indicate that constraint 3 has 2 (12 - 10) non-zero values associated to it. Their variable indices can be found in cind[10] and cind[11] , and the values for those non-zeros can be found in cval[10] and cval[11].
cind (int*) – [in] Variable indices associated with non-zero values.
cval (double*) – [in] Non-zero values associated with constraint matrix.
sense (char*) –
[in] The sense of the new constraints. it should contain at least numconstrs elements. Can be NULL if numconstrs is zero. Valid sense types include:
MDO_EQUAL(‘=’) for equal,
MDO_LESS_EQUAL(‘<’) for less-than-or-equal,
MDO_GREATER_EQUAL(‘>’) for greater-than-or-equal.
rhs (double*) – [in] The right-hand-side values of the new constraints. it should contain at least numconstrs elements. Can be NULL if numconstrs is zero.
constrnames (const char**) – [in] Constraint name for each new constraint. Can be NULL.
- Returns
A response code that specifies the status of the function.
-
int MDOaddqconstr(MDOmodel *model, int numlnz, int *lind, double *lval, int numqnz, int *qrow, int *qcol, double *qval, char sense, double rhs, const char *constrname)¶
Add a new quadratic constraint to model.
- Parameters
model (MDOmodel*) – [in] The model pointer.
numlnz (int) – [in] The nonzeros for linear part.
lind (int*) – [in] The associated variables for linear terms.
lval (double*) – [in] The coefficients for linear terms.
numqnz (int) – [in] The number of quadratic terms.
qrow (int*) – [in] The first variable list for quadratic terms.
qcol (int*) – [in] The second variable list for quadratic terms.
qval (double*) – [in] The quadratic coefficients.
sense (char) –
[in] The sense of the new constraint. Valid sense types include:
MDO_EQUAL(‘=’) for equal,
MDO_LESS_EQUAL(‘<’) for less-than-or-equal,
MDO_GREATER_EQUAL(‘>’) for greater-than-or-equal.
rhs (double) – [in] The right-hand-side value for new constraint.
constrname (const char*) – [in] The name of the new quadratic constraint.
- Returns
A response code that specifies the status of the function.
-
int MDOaddpsdconstr(MDOmodel *model, int numnz, int numpsdvars, int numpsdnz, int *cind, double *cval, int *psdvarind, int *mbgn, int *indices, double *values, char sense, double rhs, const char *constrname)¶
Add a new psd constraint to model.
- Parameters
model (MDOmodel*) – [in] The model pointer.
numnz (int) – [in] Number of non-zeros entries of psd constraint’s linear part.
numpsdvars (int) – [in] Number of psd variables associated.
numpsdnz (int) – [in] The total number of nonzero entries in all nonzero matrices in the psd constraint’s psd part.
cind (int*) – [in] Variable indices for non-zeros for linear part in the new psd constraint.
cval (double*) – [in] Non-zero values for linear part in the new psd constraint.
psdvarind (int*) – [in] Psd variable indices in the psd constraint’s psd part.
mbgn (int*) – [in] The beginning indices for first non-zero entry in each non-zero matrix.
indices (int*) – [in] The indices for non-zero entries of all non-zero matrices.
values (double*) – [in] The values for non-zero entries of all non-zero matrices.
sense (char) –
[in] The sense of the new psd constraint. Valid sense types include:
MDO_EQUAL(‘=’) for equal,
MDO_LESS_EQUAL(‘<’) for less-than-or-equal,
MDO_GREATER_EQUAL(‘>’) for greater-than-or-equal.
rhs (double) – [in] The right-hand-side value of the new psd constraint.
constrname (const char*) – [in] The psd constraint name. Can be NULL.
- Returns
A response code that specifies the status of the function.
-
int MDOaddpsdvar(MDOmodel *model, int dim, int numobjnz, int *objind, double *objval, const char *varname)¶
Add a new psd variable to model.
- Parameters
model (MDOmodel*) – [in] The model pointer.
dim (int) – [in] The dimension of new psd variable.
numobjnz (int) – [in] The number of non-zero entries of all non-zero matrices. For objective non-zero coefficients associated with variable, each coefficient is a matrix.
objind (int*) – [in] The indices for objective non-zero entriesmatrix elements associated with new psd variable.
objval (double*) – [in] The values for objective matrix elements associated with new psd variable.
varname (const char*) – [in] Variable name. Can be NULL.
- Returns
A response code that specifies the status of the function.
-
int MDOaddqpterms(MDOmodel *model, int numqnz, int *qrow, int *qcol, double *qval)¶
Add new quadratic objective terms to current objective function. Note that adding a term with variable i and j is equivalent adding a term with variable j and i.
- Parameters
model (MDOmodel*) – [in] The model pointer.
numqnz (int) – [in] The total number of non-zeros associated with new quadratic terms.
qrow (int*) – [in] The first variable indices associated with quadratic terms.
qcol (int*) – [in] The second variable indices associated with quadratic terms.
qval (double*) – [in] The non-zero values associated with quadratic terms.
- Returns
A response code that specifies the status of the function.
-
int MDOaddrangeconstr(MDOmodel *model, int numnz, int *cind, double *cval, double lower, double upper, const char *constrname)¶
Add a new range constraint (has both LHS and RHS) to model.
- Parameters
model (MDOmodel*) – [in] The model pointer.
numnz (int) – [in] The number of non-zeros associated with the new constraint.
cind (int*) – [in] The variable indices for non-zeros associated with the new constraint.
cval (double*) – [in] The values for non-zeros associated with the new constraint.
lower (double) – [in] Left-hand-side value for the new constraint. Default value is -MDO_INFINITY if it is NULL.
upper (double) – [in] Right-hand-side value for the new constraint. Default value is MDO_INFINITY if it is NULL.
constrname (const char*) – [in] Constraint name for new constraint. Can be NULL.
- Returns
A response code that specifies the status of the function.
-
int MDOaddrangeconstrs(MDOmodel *model, int numconstrs, int numnz, int *cbeg, int *cind, double *cval, double *lower, double *upper, const char **constrnames)¶
Add a batch of range constraints to model.
- Parameters
model (MDOmodel*) – [in] The model pointer.
numconstrs (int) – [in] The number of new constraints should be added.
numnz (int) – [in] The total number of non-zeros associated with new constraints.
cbeg (int*) – [in] Constraint matrix non-zero values are passed into this function in Compressed Sparse Row (CSR) format. Each constraint in the constraint matrix is represented as a list of index-value pairs, where each index entry provides the variable index for a non-zero coefficient, and each value entry provides the corresponding non-zero value. Each constraint in the model has a cbeg and clen value, indicating the start position of the non-zeros for that constraint in the cind and cval arrays, and cbeg[i + 1] - cbeg[i] is the number of non-zero values for i-th constraint. It should contain at least numconstrs elements. Can be NULL if numconstrs is zero. For example, if vbeg[3] = 10 and cbeg[4] = 12 , that would indicate that constraint 3 has 2 (12 - 10) non-zero values associated to it. Their variable indices can be found in cind[10] and cind[11] , and the values for those non-zeros can be found in cval[10] and cval[11].
cind (int*) – [in] Variable indices associated with non-zero values.
cval (double*) – [in] Non-zero values associated with constraint matrix.
lower (double*) – [in] The left-hand-side values for new range constraints.
upper (double*) – [in] The right-hand-side values for new range constraints.
constrnames (const char**) – [in] Constraint names for new range constraints. Can be NULL.
- Returns
A response code that specifies the status of the function.
-
int MDOaddrangepsdconstr(MDOmodel *model, int numnz, int numpsdvars, int numpsdnz, int *cind, double *cval, int *psdvarind, int *mbgn, int *indices, double *values, double lower, double upper, const char *constrname)¶
Add a new range psd constraint (has both LHS and RHS) to model.
- Parameters
model (MDOmodel*) – [in] The model pointer.
numnz (int) – [in] Number of non-zeros entries of psd constraint’s linear part.
numpsdvars (int) – [in] Number of psd variables associated.
numpsdnz (int) – [in] The total number of nonzero entries in all nonzero matrices in the psd constraint’s psd part.
cind (int*) – [in] Variable indices for non-zeros for linear part in the new psd constraint.
cval (double*) – [in] Non-zero values for linear part in the new psd constraint.
psdvarind (int*) – [in] Psd variable indices in the psd constraint’s psd part.
mbgn (int*) – [in] The beginning indices for first non-zero entry in each non-zero matrix.
indices (int*) – [in] The indices for non-zero entries of all non-zero matrices.
values (double*) – [in] The values for non-zero entries of all non-zero matrices.
lower (double) – [in] Left-hand-side value for the new constraint. Default value is -MDO_INFINITY if it is NULL.
upper (double) – [in] Right-hand-side value for the new constraint. Default value is MDO_INFINITY if it is NULL.
constrname (const char*) – [in] The psd constraint name. Can be NULL.
- Returns
A response code that specifies the status of the function.
-
int MDOaddsos(MDOmodel *model, int numsos, int nummerbers, int *types, int *beg, int *ind, double *weight)¶
Add a new Special Ordered Set (SOS) constraint to model.
- Parameters
model (MDOmodel*) – [in] The model object.
numsos (int) – [in] The number of SOS constraints to be added.
nummerbers (int) – [in] The total number of variables associated with new constraints.
types (int*) –
[in] The SOS type for each new SOS constraint. Valid types include:
1 for SOS_TYPE1
2 for SOS_TYPE2
beg (int*) – [in] The list beginning indices for each SOS constraint.
ind (int*) – [in] The variable indices associated with new SOS constraints.
weight (double*) – [in] Weights for each participating variable.
- Returns
A response code that specifies the status of the function.
-
int MDOaddgenconstrIndicator(MDOmodel *model, const char *name, int binvar, int binval, int nvars, const int *vars, const double *vals, char sense, double rhs)¶
Add a new indicator constraint to model.
- Parameters
model (MDOmodel*) – [in] The model pointer.
name (const char*) – [in] The name of new indicator constraint.
binvar (int) – [in] The binary variable index.
binval (int) – [in] The binary value when linear constraint take effect.
nvars (int) – [in] The number of variables in linear constraint.
vars (const int*) – [in] Variable indices associated with linear constraint.
vals (const double*) – [in] Variable coefficients associated with linear constraint.
sense (char) – [in] The sense of linear constraint.
rhs (double) – [in] The right-hand-side value of linear constraint.
- Returns
A response code that specifies the status of the function.
-
int MDOaddvar(MDOmodel *model, int numnz, int *vind, double *vval, double obj, double lb, double ub, char vtype, const char *varname)¶
Add a new variable to model.
- Parameters
model (MDOmodel*) – [in] The model pointer.
numnz (int) – [in] The number of non-zeros associated with new variable in constraint matrix.
vind (int*) – [in] Constraint indices associated with non-zeros for new variable.
vval (double*) – [in] The values associated with non-zeros for the new variable.
obj (double) – [in] Objective coefficient for the new variable.
lb (double) – [in] Lower bound for the new variable. Default value is 0 if it is NULL.
ub (double) – [in] Upper bound for the new variable. Default value is MDO_INFINITY if it is NULL.
vtype (char) –
[in] Variable type for the new variable. Variable types include:
MDO_CONTINUOUS(‘C’) for continuous variable,
MDO_BINARY(‘B’) for binary variable,
MDO_INTEGER(‘I’) for integral variable,
MDO_SEMICONT(‘S’) for semi-continuous variable,
MDO_SEMIINT(‘N’) for semi-integral variable.
varname (const char*) – [in] Variable name. Can be NULL.
- Returns
A response code that specifies the status of the function.
-
int MDOaddvars(MDOmodel *model, int numvars, int numnz, int *vbeg, int *vind, double *vval, double *obj, double *lb, double *ub, char *vtype, const char **varnames)¶
Add a batch of variables to model.
- Parameters
model (MDOmodel*) – [in] The model pointer.
numvars (int) – [in] The number of new variables.
numnz (int) – [in] The total number of non-zeros in constraint matrix for the new variables.
vbeg (int*) – [in] Constraint matrix non-zero values are passed into this function in Compressed Sparse Column (CSC) format. Each column in the constraint matrix is represented as a list of index-value pairs, where each index entry provides the constraint index for a non-zero coefficient, and each value entry provides the corresponding non-zero value. Each variable in the model has a vbeg and vlen value, indicating the start position of the non-zeros for that variable in the vind and vval arrays, and the number of non-zero values for that variable, respectively. It should contain at least numvars elements. Can be NULL if numvars is zero. For example, if vbeg[3] = 10 and vlen[3] = 2, that would indicate that variable 3 has two non-zero values associated to it. Their constraint indices can be found in vind[10] and vind[11] , and the numerical values for those non-zeros can be found in vval[10] and vval[11].
vind (int*) – [in] Index of constraint associated to non-zero values. Can be NULL if numconstrs is zero.
vval (double*) – [in] Values associated with constraint matrix non-zeros. Can be NULL if numconstrs is zero.
obj (double*) – [in] The objective coefficients of new variables, it should contain at least numvars elements. Can be NULL if numvars is zero.
lb (double*) – [in] Lower bound for each new variable. Can be NULL if numvars is zero.
ub (double*) – [in] Upper bound for each new variable. Can be NULL if numvars is zero.
vtype (char*) –
[in] Variable type for each new variable. Can be NULL in wich case variables will be considered CONTINUOUS. Variable types include:
MDO_CONTINUOUS(‘C’) for continuous variable,
MDO_BINARY(‘B’) for binary variable,
MDO_INTEGER(‘I’) for integral variable,
MDO_SEMICONT(‘S’) for semi-continuous variable,
MDO_SEMIINT(‘N’) for semi-integral variable.
varnames (const char**) – [in] Variable name for each new variable. Can be NULL.
- Returns
A response code that specifies the status of the function.
-
int MDOchgcoeffs(MDOmodel *model, int numchgs, int *cind, int *vind, double *val)¶
Change coefficients in constraint matrix.
- Parameters
model (MDOmodel*) – [in] The model pointer.
numchgs (int) – [in] The number of coefficients to be changed.
cind (int*) – [in] The constraint indices in constraint matrix.
vind (int*) – [in] The variable indices in constraint matrix.
val (double*) – [in] The new values of coefficients indicated by cind and vind .
- Returns
A response code that specifies the status of the function.
-
int MDOcomputeIIS(MDOmodel *model)¶
Compute an IIS(Irreducible Inconsistent Subsystem). IIS is a subset of variable bounds and constraint bounds, this subset satisfies:
The subproblem corresponding to the subset is still infeasible.
After delete any bound in this subset, the subproblem becomes feasible.
Check IIS related attributes for variable and constraint for more details.
- Parameters
model (MDOmodel*) – [in] The model to compute IIS.
- Returns
A response code that specifies the status of the function.
Note
The cardinality of the subsystem is supposed to be small. Note that the problem is supposed to be infeasible.
-
MDOmodel *MDOcopymodel(MDOmodel *model)¶
Create a (deep) copy from an existing model.
- Parameters
model (MDOmodel*) – [in] The existing model.
- Returns
The location in which the newly created model should be placed.
-
int MDOdelconstrs(MDOmodel *model, int numdel, int *ind)¶
Delete constraints from model.
- Parameters
model (MDOmodel*) – [in] The model pointer.
numdel (int) – [in] The number of constraints should be deleted.
ind (int*) – [in] Constraint indices to be deleted.
- Returns
A response code that specifies the status of the function.
Note
This function call triggers a rebuilding of internal data structure, so batch delete constraints as many as possible for better performance.
-
int MDOdelqconstrs(MDOmodel *model, int numdel, int *ind)¶
Delete quadratic constraints from model.
- Parameters
model (MDOmodel*) – [in] The model pointer.
numdel (int) – [in] The number of quadratic constraints should be deleted.
ind (int*) – [in] Quadratic constraint indices to be deleted.
- Returns
A response code that specifies the status of the function.
Note
This function call triggers a rebuilding of internal data structure, so batch delete quadratic constraints as many as possible for better performance.
-
int MDOdelq(MDOmodel *model)¶
Delete all quadratic objective terms from model.
- Parameters
model (MDOmodel*) – [in] The model pointer.
- Returns
A response code that specifies the status of the function.
-
int MDOdelsos(MDOmodel *model, int len, int *ind)¶
Delete SOS constraints from model.
- Parameters
model (MDOmodel*) – [in] The model object.
len (int) – [in] The number of SOS constraints to be deleted.
ind (int*) – [in] The indices of SOS constraints to be deleted.
- Returns
A response code that specifies the status of the function.
-
int MDOdelgenconstrs(MDOmodel *model, int numdel, int *ind)¶
Delete general constraints from model.
- Parameters
model (MDOmodel*) – [in] The model pointer.
numdel (int) – [in] The number of general constraints to be deleted.
ind (int*) – [in] General constraint indices to be deleted.
- Returns
A response code that specifies the status of the function.
Note
This function call triggers a rebuilding of internal data structure, so batch delete constraints as many as possible for better performance.
-
int MDOdelvars(MDOmodel *model, int numdel, int *ind)¶
Delete variables from model by variable indices.
- Parameters
model (MDOmodel*) – [in] The model pointer.
numdel (int) – [in] The number of variables to be deleted.
ind (int*) – [in] Variable indices.
- Returns
A response code that specifies the status of the function.
Note
This function call triggers a rebuilding of internal data structure, so batch delete variables as many as possible for better performance.
-
int MDOfreemodel(MDOmodel *model)¶
Free an existing model and release all its associated resources.
- Parameters
model (MDOmodel*) – [in] The model to be freed.
- Returns
A response code that specifies the status of the function.
-
int MDOgetcoeff(MDOmodel *model, int constrind, int varind, double *valP)¶
Retrieve a single constraint matrix coefficient.
- Parameters
model (MDOmodel*) – [in] The model pointer.
constrind (int) – [in] The constraint index.
varind (int) – [in] The variable index.
valP (double*) – [out] The place to hold coefficient value.
- Returns
A response code that specifies the status of the function.
-
int MDOgetconstrbyname(MDOmodel *model, const char *name, int *constrnumP)¶
Retrieve a single linear constraint by its name. Note that if multiple linear constraints have the same name, this function choose one randomly.
- Parameters
model (MDOmodel*) – [in] The model pointer.
name (const char*) – [in] The constraint name.
constrnumP (int*) – [out] The place to hold the named constraint index. -1 if no such name found.
- Returns
A response code that specifies the status of the function.
-
int MDOgetqconstrbyname(MDOmodel *model, const char *qcname, int *constrnumP)¶
Retrieve a single quadratic constraint by its name. Note that if multiple quadratic constraints have the same name, this function choose one randomly.
- Parameters
model (MDOmodel*) – [in] The model pointer.
qcname (const char*) – [in] The quadratic constraint name.
constrnumP (int*) – [out] The place to hold the named quadratic constraint index. -1 if no such name found.
- Returns
A response code that specifies the status of the function.
-
int MDOgetconstrcoeff(MDOmodel *model, int rind, int cind, double *coeff)¶
Get coefficient value associated with specified constraint and variable.
- Parameters
model (MDOmodel*) – [in] The model pointer.
rind (int) – [in] Constraint index.
cind (int) – [in] Variable index.
coeff (double*) – [out] The place to hold result coefficient value.
- Returns
A response code that specifies the status of the function.
-
int MDOgetconstrs(MDOmodel *model, int *numnzP, int *cbeg, int *cind, double *cval, int start, int len)¶
Get a batch of constraints by index range.
- Parameters
model (MDOmodel*) – [in] The model pointer.
numnzP (int*) – [out] The total number of non-zeros Retrieved.
cbeg (int*) –
[out] Constraint matrix non-zero values are returned in Compressed Sparse Row (CSR) format.
Each constraint in the constraint matrix is represented as a list of index-value pairs, where each index entry provides the variable index for a non-zero coefficient, and each value entry provides the corresponding non-zero value.
Each constraint has an associated cbeg value, indicating the start position of the non-zeros for that constraint in the cind and cval arrays.
This pointer should have at least len elements space, where cbeg[i] will be the start index of the asssociated non-zeros in cind for i-th constraint, and cbeg[i + 1] - cbeg[i] will be the number of non-zeros for i-th constraint.
cind (int*) – [out] Place to hold constraint non-zero indices as result.
cval (double*) – [out] Place to hold constraint non-zero values as result.
start (int) – [in] The start constraint index to Retrieve.
len (int) – [in] The number of constraints to Retrieve.
- Returns
A response code that specifies the status of the function.
-
int MDOgetqconstr(MDOmodel *model, int qconstr, int *numlnz, int *lind, double *lval, int *numqnz, int *qrow, int *qcol, double *qval)¶
Retrieve a quadratic constraint by its index. Typically, this function should be called twice. The first call with numlnz and numqnz (pass NULL for other arguments) to get the numbers of linear and quadratic terms, then space can be allocated to make the second call.
- Parameters
model (MDOmodel*) – [in] The model pointer.
qconstr (int) – [in] The quadratic constraint index to be retrieved.
numlnz (int*) – [out] The place to hold the number of linear terms in this constraint.
lind (int*) – [out] The place to hold variable list of linear terms. Can be NULL.
lval (double*) – [out] The place to hold coefficients of linear terms. Can be NULL.
numqnz (int*) – [out] The place to hold number of quadratic terms.
qrow (int*) – [out] The place to hold the first variable list of quadratic terms. Can be NULL.
qcol (int*) – [out] The place to hold the second variable list of quadratic terms. Can be NULL.
qval (double*) – [out] The place to hold the quadratic coefficients. Can be NULL.
- Returns
A response code that specifies the status of the function.
-
int MDOgetpsdconstr(MDOmodel *model, int rind, int *numnzs, int *numpsdvars, int *nummatnz, int *cind, double *cval, int *psdvarind, int *mbgn, int *mind, double *mval)¶
Retrieve a single psd constraint matrix coefficient. The coefficient itself is also a matrix.
- Parameters
model (MDOmodel*) – [in] The model pointer.
rind (int) – [in] The constraint index.
numnzs (int*) – [out] The number of non-zeros in linear part.
numpsdvars (int*) – [out] The number of associated psd variables.
nummatnz (int*) – [out] The number of non-zeros entries in the matrix.
cind (int*) – [out] The variable indices in constraint’s linear part
cval (double*) – [out] The variable coefficients in constraint’s linear part
psdvarind (int*) – [out] The indices for psd variables. Can be NULL.
mbgn (int*) – [out] The beginning index of each matrix. Can be NULL.
mind (int*) – [out] The place to hold indices for matrix elements. Can be NULL.
mval (double*) – [out] The place to hold values for matrix elements. Can be NULL.
- Returns
A response code that specifies the status of the function.
-
int MDOgetq(MDOmodel *model, int *numqnzP, int *qrow, int *qcol, double *qval)¶
Retrieve all quadratic objective terms from model.
- Parameters
model (MDOmodel*) – [in] The model pointer.
numqnzP (int*) – [out] The Place to hold number of quadratic non-zeros.
qrow (int*) – [out] The place to hold the first variable indices. It should have at least numqnzP elements space.
qcol (int*) – [out] The place to hold the second variable indices. It should have at least numqnzP elements space.
qval (double*) – [out] The place to hold the non-zero values of quadratic objective terms. It should have at least numqnzP elements space.
- Returns
A response code that specifies the status of the function.
-
int MDOgetsos(MDOmodel *model, int *nummembers, int *sostype, int *beg, int *ind, double *weight, int start, int len)¶
Retrieve the variables and weights of SOS constraints.
- Parameters
model (MDOmodel*) – [in] The model object.
nummembers (int*) – [out] The number of participating variables for each SOS constraint.
sostype (int*) – [out] The place to hold the types of requested SOS constraints.
beg (int*) – [out] The place to hold the list of beginning indices of each SOS constraint.
ind (int*) – [out] The place to hold the variable indices associated with SOS constraints.
weight (double*) – [out] The place to hold the variable weights associated with SOS constraints.
start (int) – [in] The start SOS constraint index to be requested.
len (int) – [in] The number of SOS constraints to be requested.
- Returns
A response code that specifies the status of the function.
-
int MDOgetgenconstrIndicator(MDOmodel *model, int genconstr, int *binvarP, int *binvalP, int *nvarsP, int *vars, double *vals, char *sense, double *rhs)¶
Retrieve an indicator constraint by its index.
- Parameters
model (MDOmodel*) – [in] The model pointer.
genconstr (int) – [in] The index of indicator constraint to retrieve.
binvarP (int*) – [out] The place to hold binary variable index.
binvalP (int*) – [out] The place to hold binary value when linear constraint take effect.
nvarsP (int*) – [out] The place to hold the number of variables in linear constraint.
vars (int*) – [out] The place to hold the variable indices associated with linear constraint.
vals (double*) – [out] The place to hold the variable coefficients associated with linear constraint.
sense (char*) – [out] The place to hold the sense of linear constraint.
rhs (double*) – [out] The place to hold the right-hand-side value of linear constraint.
- Returns
A response code that specifies the status of the function.
-
int MDOgetvarbyname(MDOmodel *model, const char *name, int *varnumP)¶
Retrieve a variable by its name. If multiple variables have the same name, this function chooses one randomly.
- Parameters
model (MDOmodel*) – [in] The model pointer.
name (const char*) – [in] The variable name.
varnumP (int*) – [out] The place to hold variable index.
- Returns
A response code that specifies the status of the function.
-
int MDOgetvars(MDOmodel *model, int *numnzP, int *vbeg, int *vind, double *vval, int start, int len)¶
Retrieve non-zeros for a range of variables from the constraint matrix.
- Parameters
model (MDOmodel*) – [in] The model pointer.
numnzP (int*) – [out] The number of non-zeros associated with variables.
vbeg (int*) –
[out] Constraint matrix non-zero values are returned in Compressed Sparse Column (CSC) format by this function. Each column in the constraint matrix is represented as a list of index-value pairs, where each index entry provides the constraint index for a non-zero coefficient, and each value entry provides the corresponding non-zero value.
Each variable has an associated vbeg value, indicating the start position of the non-zeros for that constraint in the vind and vval arrays. This pointer should have at least len elements space, where vbeg[i] will be the start index of the asssociated non-zeros in vind for i-th variable, and vbeg[i + 1] - vbeg[i] will be the number of non-zeros for i-th variable.
vind (int*) – [out] Place to hold constraint indices associated with non-zero values.
vval (double*) – [out] Place to hold values associated with constraint matrix non-zeros.
start (int) – [in] The start index of variable to Retrieve non-zeros from.
len (int) – [in] The number of variables to Retrieve non-zeros from.
- Returns
A response code that specifies the status of the function.
-
int MDOloadmodel(MDOenv *env, MDOmodel **modelP, const char *Pname, int numvars, int numconstrs, int objsense, double objcon, double *obj, char *sense, double *rhs, int *vbeg, int *vlen, int *vind, double *vval, double *lb, double *ub, char *vtype, const char **varnames, const char **constrnames)¶
Create a new optimization model from an environment, and initialize the newly created model with provided arguments. The model is then ready for optimization or modification.
- Parameters
env (MDOenv*) – [in] The environment pointer.
modelP (MDOmodel**) – [out] The location in which the pointer to the newly created model should be placed.
Pname (const char*) – [in] The problem name, can be NULL or empty string.
numvars (int) – [in] The number of variables to be added to the newly created model.
numconstrs (int) – [in] The number of constraints to be added to the newly created model.
objsense (int) –
[in] The objective sense of new problem.
MDO_MINIMIZE(1) for minimization (default)
and, MDO_MAXIMIZE(-1) for maximization.
objcon (double) – [in] The objective constant of new problem.
obj (double*) – [in] The objective coefficients of new variables, it should contain at least numvars elements. Can be NULL if numvars is zero.
sense (char*) –
[in] The sense of the new constraints. it should contain at least numconstrs elements. Can be NULL if numconstrs is zero. Valid sense types include:
MDO_EQUAL(‘=’) for equal,
MDO_LESS_EQUAL(‘<’) for less-than-or-equal,
MDO_GREATER_EQUAL(‘>’) for greater-than-or-equal.
rhs (double*) – [in] The right-hand-side values of the new constraints. it should contain at least numconstrs elements. Can be NULL if numconstrs is zero.
vbeg (int*) –
[in] Constraint matrix non-zero values are passed into this function in Compressed Sparse Column (CSC) format. Each column in the constraint matrix is represented as a list of index-value pairs, where each index entry provides the constraint index for a non-zero coefficient, and each value entry provides the corresponding non-zero value. Each variable in the model has a vbeg and vlen value, indicating the start position of the non-zeros for that variable in the vind and vval arrays, and the number of non-zero values for that variable, respectively. It should contain at least numvars elements. Can be NULL if numvars is zero.
For example, if vbeg[3] = 10 and vlen[3] = 2 , that would indicate that variable 3 has two non-zero values associated to it. Their constraint indices can be found in vind[10] and vind[11] , and the numerical values for those non-zeros can be found in vval[10] and vval[11].
vlen (int*) – [in] Number of constraint matrix non-zero values associated to each variable. It should contain at least numvars elements. Can be NULL if numvars is zero.
vind (int*) – [in] Index of constraint associated to non-zero values. Can be NULL if numconstrs is zero.
vval (double*) – [in] Values associated with constraint matrix non-zeros. Can be NULL if numconstrs is zero.
lb (double*) – [in] Lower bound for each new variable. Can be NULL if numvars is zero.
ub (double*) – [in] Upper bound for each new variable. Can be NULL if numvars is zero.
vtype (char*) –
[in] Variable type for each new variable. Can be NULL in which case variables will be considered CONTINUOUS. Variable types include:
MDO_CONTINUOUS(‘C’) for continuous variable,
MDO_BINARY(‘B’) for binary variable,
MDO_INTEGER(‘I’) for integral variable,
MDO_SEMICONT(‘S’) for semi-continuous variable,
MDO_SEMIINT(‘N’) for semi-integral variable.
varnames (const char**) – [in] Variable name for each new variable. Can be NULL.
constrnames (const char**) – [in] Constraint name for each new constraint. Can be NULL.
- Returns
A response code that specifies the status of the function.
-
int MDOnewmodel(MDOenv *env, MDOmodel **modelP, const char *Pname, int numvars, double *obj, double *lb, double *ub, char *vtype, const char **varnames)¶
Create a new optimization model from an environment, and initialize the newly created model with provided variables. The model is then ready for modification, but not for optimization as it has no constraint.
- Parameters
env (MDOenv*) – [in] The environment pointer.
modelP (MDOmodel**) – [out] The location in which the pointer to the newly created model should be placed.
Pname (const char*) – [in] The problem name, can be NULL or empty string.
numvars (int) – [in] The number of variables to be added to the newly created model.
obj (double*) – [in] The objective coefficients of new variables, it should contain at least numvars elements. Can be NULL if numvars is zero.
lb (double*) – [in] Lower bound for each new variable. Can be NULL if numvars is zero.
ub (double*) – [in] Upper bound for each new variable. Can be NULL if numvars is zero.
vtype (char*) –
[in] Variable type for each new variable. Can be NULL in wich case variables will be considered CONTINUOUS. Variable types include:
MDO_CONTINUOUS(‘C’) for continuous variable,
MDO_BINARY(‘B’) for binary variable,
MDO_INTEGER(‘I’) for integral variable,
MDO_SEMICONT(‘S’) for semi-continuous variable,
MDO_SEMIINT(‘N’) for semi-integral variable.
varnames (const char**) – [in] Variable name for each new variable. Can be NULL.
- Returns
A response code that specifies the status of the function.
-
int MDOoptimize(MDOmodel *model)¶
Optimize a model.
- Parameters
model (MDOmodel*) – [in] The model to optimize.
- Returns
A response code that specifies the status of the function.
-
int MDOread(MDOmodel *model, const char *filename)¶
Load data to an existing model from file.
- Parameters
model (MDOmodel*) – [in] The existing model pointer.
filename (const char*) – [in] The path to the file where data stored. Note that file format and its compression type (optionally) is encoded in the file name suffix. Valid suffix is .prm for parameter loading, and .mst for MIP starts loading, optionally followed by its compression type .gz or .bz2.
- Returns
A response code that specifies the status of the function.
-
int MDOreadmodel(MDOenv *env, const char *filename, MDOmodel **modelP)¶
Load a model from file.
- Parameters
env (MDOenv*) – [in] The environment pointer.
filename (const char*) – [in] The path to the file where the model stored. Note that file format and its compression type (optionally) is encoded in the file name suffix. Valid suffixes are: .lp, .mps, .qps and .dat-s, optionally followed by its compression type .gz or .bz2.
modelP (MDOmodel**) – [out] The place to hold the newly loaded model.
- Returns
A response code that specifies the status of the function.
-
int MDOreset(MDOmodel *model, int clearall)¶
Reset the model to an unsolved state, discarding any previously computed solution.
- Parameters
model (MDOmodel*) – [in] The model to reset.
clearall (int) – [in] Whether to clear all information more than solution. 1 for yes, and 0 to indicate clear only solution.
- Returns
A response code that specifies the status of the function.
-
int MDOsetconstrcoeff(MDOmodel *model, int rind, int cind, double coeff)¶
Set coefficient value associated with specified constraint and variable.
- Parameters
model (MDOmodel*) – [in] The model pointer.
rind (int) – [in] Constraint index.
cind (int) – [in] Variable index.
coeff (double) – [in] New coefficient value.
- Returns
A response code that specifies the status of the function.
-
int MDOwrite(MDOmodel *model, const char *filename)¶
Serialize model data to file. Include model itself or other settings.
- Parameters
model (MDOmodel*) – [in] The mode pointer.
filename (const char*) – [in] The path to file where data serialized. Note that data type and its compression type (optionally) is encoded in the file name suffix. Valid suffixes are .lp, .mps and .qps for model itself, .sol, .bas, .prm and .mst for solution data, basis data, parameter settings and MIP starts. optionally followed by its compression type .gz or .bz2.
- Returns
A response code that specifies the status of the function.
-
int MDOaddconstr(MDOmodel *model, int numnz, int *cind, double *cval, char sense, double rhs, const char *constrname)¶