# Building the model

Filter Content By
Version
Languages

## Building the model

The example begins by building an optimization model. The data associated with an optimization model must be stored in a MATLAB struct. Fields in this struct contain the different parts of the model. The most fundamental fields are: The constraint matrix (A), the objective vector (obj), the right-hand side vector (rhs), and the constraint sense vector (sense). Among these, only the constraint matrix is mandatory, and default values are substituted for all other model fields in case they are missing.

The example uses the built-in sparse function to build the constraint matrix A. The Gurobi MATLAB interface only accepts sparse matrices as input. If you have a dense matrix, use sparse to convert it to a sparse matrix before passing it to our interface.

In addition to the fields discussed above, this example sets two more fields: modelsense and vtype. The former is used to indicate the sense of the objective function. The default is minimization, so we've set the field equal to 'max' to indicate that we would like to maximize the specified objective. The vtype field is used to indicate the types of the variables in the model. In our example, all variables are binary ('B'). Note that our interface allows you to specify a scalar value for the sense and vtype arguments. The Gurobi interface will expand that scalar to a constant array of the appropriate length. In this example, the scalar value 'B' will be expanded to an array of length 3, containing one 'B' value for each column of A.