8.8.2. model¶
- class model¶
An optimization model
Properties
The linear constraint matrix
The quadratic objective matrix
Constraint names vector
Indicator constraint
It can be LHS or sense
Name of model
Sense of the model
Linear objective vector
Constant offset in the objective function
Psd constraints
Psd variables
Quadratic constraints
RHS (Right Hand Side) of linear constraints
Special Ordered Set (SOS) constraints
Variable names vector
Types of Variables
- A¶
The linear constraint matrix. Optional attribute, if it exists, must be a MATLAB sparse matrix. Each column in the matrix represents a variable, and each row represents a linear constraint.
- Q¶
The quadratic objective matrix. Optional attribute, if it exists, must be a MATLAB sparse matrix. Q must be a square matrix whose row and column counts are equal to the number of columns in A. In Q, the meanings of Q[i][j] and Q[j][i] are identical. For the objective expression x^2 + xy + y^2, the matrix Q values [1, 0.5; 0.5, 1;] and [1 1; 0 1;] are equivalent. It must be a MATLAB sparse matrix.
- constrnames¶
Constraint names vector. Optional attribute, if it exists, it must be a cell array composed of char arrays. When present, each element of this vector defines the name of a constraint. Its length should be the same as the number of rows in the linear constraint matrix A.
- genconind¶
Indicator constraint. Optional attribute, if it exists, it must be an array of structures, with each structure representing an instruction constraint. The structure needs to include the following attributes.
model.genconind(i).binvar
Index of the implicating binary variable. It should be an integer of type double between 1 and the number of model variables. The default value is 0.
model.genconind(i).binval
Value for the binary variable that forces the following linear constraint to be satisfied. It must be either 0 or 1. Default is empty.
model.genconind(i).a
Vector of coefficients of variables participating in the implied linear constraint. You can specify a value for a for each column of A (dense vector) or pass a sparse vector (sparse n-by-1 matrix).The default value is 0.
genconind(i).rhs
Right-hand side value of the implied linear constraint. The type must be double. The default value is 0.
model.genconind(i).sense
Sense of the implied linear constraint. It should be ‘<’,’>’ or ‘=’. The default value is ‘<’.
model.genconind(i).name
Name of the implied linear constraint. Optional attribute, if it exists, it must be a char array. Default is empty.
- lhsorsense¶
It can be LHS or sense. When the provided type is a double array, the value is represented as LHS of linear constraints. Its length should be the same as the number of rows in the linear constraint matrix A. When the provided type is a char array, the value is represented as sense of linear constraints and the characters can be ‘<’, ‘>’, or ‘=’. Also, it can be a single character specify that all constraints have the same sense. The default value is ‘<’.
- modelname¶
Name of model. Optional attribute, if it exists, must be a MATLAB sparse matrix.
- modelsense¶
Sense of the model. Optional attribute, if it exists, must be a MATLAB sparse matrix. It allows for value ‘max’ or ‘min’. When absent, the default value is minimization.
- obj¶
Linear objective vector. It must be provided and must be a array. Its length should be the same as the number of columns in the linear constraint matrix A.
- objcon¶
Constant offset in the objective function. Optional attribute, if it exists, its type must be double. When absent, the default value is 0.
- psdcon¶
Psd constraints. Optional attribute, if it exists, its type must be an array of structures. Each element in psdcon defines a single psd constraint. In addition, quadcon can include the following attributes:
model.psdcon(i).psdmats
Psd constraint matrix. It must be a one-dimensional cell array, containing several MATLAB sparse matrices, and each matrix must be symmetric.
model.psdcon(i).indices
Indices of the corresponding PSD variables for the PSD constraint matrix. Its type must be a one-dimensional array, and its length must be the same as the number of matrices in psdmats. The index in the array represents the corresponding PSD constraint matrix, while the values in the array represent the PSD variables associated with that constraint matrix. The values in the array must not greater than the number of PSD variables, and the size of the corresponding PSD constraint matrix must be the same as that of the objective matrix for PSD variables.
model.psdcon(i).linearterm
The linear part in psdcon. Optional attribute, if it exists, it must be an array or an n*1 sparse vector. Its length should be the same as the number of columns in the constraint matrix.
model.psdcon(i).name
Name of the psd constraint. Optional attribute, if it exists, it must be a char array.
model.psdcon(i).lhsorsense
It can be LHS or sense. When the provided type is a double, the value is represented as LHS of psd constraints. When the provided type is a character, the value is represented as sense of psd constraints and the character can be ‘<’, ‘>’, or ‘=’. The default value is ‘<’.
model.psdcon(i).rhs
Right-hand side value of the psd constraint. The type must be double. The default value is 0.
- psdvar¶
Psd variables. Optional attribute, if it exists, its type must be an array of structures. Each element in padvar defines a single psd variables. In addition, psdvar can include the following attributes:
model.psdvar(i).obj
The objective matrix of the PSD variable. It must be a MATLAB sparse matrix and is required to be a real symmetric matrix.
model.psdvar(i).name
Name of the psd variable. Optional attribute, if it exists, it must be a char array.
- quadcon¶
Quadratic constraints. Optional attribute, if it exists, its type must be an array of structures. Each element in quadcon defines a single quadratic constraint. There are two input methods for the quadcon matrix, corresponding to MATLAB sparse and coo sparse respectively. For each element in quadcon, you can choose either method to input the quadcon matrix.
matlab sparse
Use model.quadcon(i).Qc to input quadcon matrix. Qc should be matlab sparse. It must be a square matrix whose row and column counts are equal to the number of columns in A.
coo sparse
The row indices and column indices of the nonzero values in the Quadcon Matrix are passed in via model.quadcon(i).Qrow and model.quadcon(i).Qcol, respectively. The nonzero values themselves are passed in via model.quadcon(i).Qval. All of them should be array with the same length.
In addition, quadcon can also include the following attributes:
model.quadcon(i).q
The linear part in Quadcon. Optional attribute, if it exists, it must be an array or an n*1 sparse vector. Its length should be the same as the number of columns in the constraint matrix.
model.quadcon(i).rhs
Right-hand side value of the implied quadratic constraint. The type must be double. The default value is 0.
model.quadcon(i).lhrorsense
It can be LHS or sense. When the provided type is a double, the value is represented as LHS of quadratic constraints. When the provided type is a character, the value is represented as sense of quadratic constraints and the character can be ‘<’, ‘>’, or ‘=’. The default value is ‘<’.
model.quadcon(i).name
Name of the implied quadratic constraint. Optional attribute, if it exists, it must be a char array.
- rhs¶
RHS (Right Hand Side) of linear constraints. It must be provided and must be a array. Its length should be the same as the number of rows in the linear constraint matrix A. When absent, all values in RHS default to 0.
- sos¶
Special Ordered Set (SOS) constraints. It is an array of structures. When present, each entry in sos defines a single SOS constraint. The structure needs to include the following attributes.
model.sos(i).type
The type of sos constraint. It can be either 1 or 2. A type 1 SOS constraint is a set of variables where at most one variable in the set may take a value other than zero. A type 2 SOS constraint is an ordered set of variables where at most two variables in the set may take non-zero values. If two take non-zeros values, they must be contiguous in the ordered set.
model.sos(i).index
The members of an SOS constraint are specified by placing their indices. It must be an array.
model.sos(i).weight
SOS members’ weight. It must be an array.
- varnames¶
Variable names vector. Optional attribute, if it exists, it must be a cell array composed of char arrays. When present, each element of this vector defines the name of a constraint. Its length should be the same as the number of cols in the linear constraint matrix A.
- vtype¶
Types of Variables. Optional attribute, if it exists, each value in the char array represents the type of the variable at the corresponding position. The values can be ‘C’ (continuous), ‘B’ (binary), ‘I’ (integer), ‘S’ (semi-continuous), or ‘N’ (semi-integer). Continuous indicates a real number variable, Binary indicates a binary variable which can only take values 0 or 1, Integer indicates an integer variable, Semi-continuous can take real number values within the lower and upper bounds or 0, and Semi-integer can take integer values within the lower and upper bounds or 0. When absent, the types of variable are default to ‘C’.