# The model argument

Filter Content By
Version
Languages

### The model argument

Model variables store optimization problems (as described in the problem statement).

Models can be built in a number of ways. You can populate the appropriate named components of the model list using standard R routines. You can also read a model from a file, using gurobi_read. A few API functions ( gurobi_feasrelax and gurobi_relax) also return models.

Note that all matrix named components within the model variable can be dense or sparse. Sparse matrices should be built using either sparseMatrix from the Matrix package, or simple_triplet_matrix from the slam package.

The following is an enumeration of all of the named components of the model argument that Gurobi will take into account when optimizing the model:

Commonly used named components:

A
The linear constraint matrix.

obj (optional)
The linear objective vector (the c vector in the problem statement). When present, you must specify one value for each column of A. When absent, each variable has a default objective coefficient of 0.

sense (optional)
The senses of the linear constraints. Allowed values are '=', '<', or '>'. You must specify one value for each row of A, or a single value to specify that all constraints have the same sense. When absent, all senses default to '<'.

rhs (optional)
The right-hand side vector for the linear constraints ( in the problem statement). You must specify one value for each row of A. When absent, the right-hand side vector defaults to the zero vector.

lb (optional)
The lower bound vector. When present, you must specify one value for each column of A. When absent, each variable has a default lower bound of 0.

ub (optional)
The upper bound vector. When present, you must specify one value for each column of A. When absent, the variables have infinite upper bounds.

vtype (optional)
The variable types. This vector is used to capture variable integrality constraints. Allowed values are 'C' (continuous), 'B' (binary), 'I' (integer), 'S' (semi-continuous), or 'N' (semi-integer). Binary variables must be either 0 or 1. Integer variables can take any integer value between the specified lower and upper bounds. Semi-continuous variables can take any value between the specified lower and upper bounds, or a value of zero. Semi-integer variables can take any integer value between the specified lower and upper bounds, or a value of zero. When present, you must specify one value for each column of A, or a single value to specify that all variables have the same type. When absent, each variable is treated as being continuous. Refer to this section for more information on variable types.

modelsense (optional)
The optimization sense. Allowed values are 'min' (minimize) or 'max' (maximize). When absent, the default optimization sense is minimization.

modelname (optional)
The name of the model. The name appears in the Gurobi log, and when writing a model to a file.

objcon (optional)
The constant offset in the objective function ( in the problem statement).

varnames (optional)
The variable names vector. A character vector. When present, each element of this vector defines the name of a variable. You must specify a name for each column of A.

constrnames (optional)
The constraint names vector. A character vector. When present, each element of the vector defines the name of a constraint. You must specify a name for each row of A.

Quadratic objective and constraint named components:

Q (optional)
The quadratic objective matrix. When present, Q must be a square matrix whose row and column counts are equal to the number of columns in A.

The quadratic constraints. A list of lists. When present, each element in quadcon defines a single quadratic constraint: .

The Qc matrix must be a square matrix whose row and column counts are equal to the number of columns of A. It is stored in model$quadcon[[i]]$Qc.

The optional q vector defines the linear terms in the constraint. It can be a dense vector specifying a value for each column of A or a sparse vector (should be built using sparseVector from the Matrix package). It is stored in model$quadcon[[i]]$q.

The scalar beta is stored in model$quadcon[[i]]$rhs. It defines the right-hand side value for the constraint.

The optional sense string defines the sense of the quadratic constraint. Allowed values are '<', '=' or '>'. If not present, the default sense is '<'. It is stored in model$quadcon[[i]]$sense.

The optional name string defines the name of the quadratic constraint. It is stored in model$quadcon[[i]]$name.

SOS constraint named components:

sos (optional)
The Special Ordered Set (SOS) constraints. A list of lists. When present, each entry in sos defines a single SOS constraint. A SOS constraint can be of type 1 or 2. The type of SOS constraint is specified via model$sos[[i]]$type. 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. The members of an SOS constraint are specified by placing their indices in vector model$sos[[i]]$index. Weights associated with SOS members are provided in vector model$sos[[i]]$weight. Please refer to this section for details on SOS constraints.

Multi-objective named components:

multiobj (optional)
Multi-objective specification for the model. A list of lists. When present, each entry in multiobj defines a single objective of a multi-objective problem. Please refer to the Multiple Objectives section for more details on multi-objective optimization. Each objective may have the following named components:
objn
Specified via model$multiobj[[i]]$objn. This is the i-th objective vector.

objcon (optional)
Specified via model$multiobj[[i]]$objcon. If provided, this is the i-th objective constant. The default value is 0.

priority (optional)
Specified via model$multiobj[[i]]$priority. If provided, this value is the hierarchical priority for this objective. The default value is 0.

weight (optional)
Specified via model$multiobj[[i]]$weight. If provided, this value is the multiplier used when aggregating objectives. The default value is 1.0.

reltol (optional)
Specified via model$multiobj[[i]]$reltol. If provided, this value specifies the relative objective degradation when doing hierarchical multi-objective optimization. The default value is 0.

abstol (optional)
Specified via model$multiobj[[i]]$abstol. If provided, this value specifies the absolute objective degradation when doing hierarchical multi-objective optimization. The default value is 0.

name (optional)
Specified via model$multiobj[[i]]$name. If provided, this string specifies the name of the i-th objective function.

Note that when multiple objectives are present, the result$objval named component that is returned in the result of an optimization call will be a vector of the same length as model$multiobj.

A multi-objective model can't have other objectives. Thus, combining model$multiobj with any of model$obj, model$objcon, model$pwlobj, or model$Q is an error. General constraint named components: The list of lists described below are used to add general constraints to a model. Mathematical programming has traditionally defined a set of fundamental constraint types: variable bound constraints, linear constraints, quadratic constraints, integrality constraints, and SOS constraints. These are typically treated directly by the underlying solver (although not always), and are fundamental to the overall algorithm. Gurobi accepts a number of additional constraint types, which we collectively refer to as general (function) constraints. These are typically not treated directly by the solver. Rather, they are transformed by presolve into constraints (and variables) chosen from among the fundamental types listed above. In some cases, the resulting constraint or constraints are mathematically equivalent to the original; in others, they are approximations. If such constraints appear in your model, but if you prefer to reformulate them yourself using fundamental constraint types instead, you can certainly do so. However, note that Gurobi can sometimes exploit information contained in the other constraints in the model to build a more efficient formulation than what you might create. The additional constraint types that fall under this general constraint umbrella are: • MAX (genconmax): set a decision variable equal to the maximum value from among a set of decision variables • MIN (genconmin): set a decision variable equal to the minimum value from among a set of decision variables • ABS (genconabs): set a decision variable equal to the absolute value of some other decision variable • AND (genconand): set a binary variable equal to one if and only if all of a set of binary decision variables are equal to one • OR (genconor): set a binary variable equal to one if and only if at least one variable out of a set of binary decision variables is equal to one • INDICATOR (genconind): whenever a given binary variable takes a certain value, then the given linear constraint must be satisfied • Piecewise-linear constraints (genconpwl): set a variable equal to the piecewise-linear function defined by a set of points using some other variable • Polynomial (genconpoly): set a variable equal to the polynomial function defined by some other variable • Natural exponential (genconexp): set a variable equal to the natural exponential function by some other variable • Exponential (genconexpa): set a variable equal to the exponential function by some other variable • Natural logarithm (genconlog): set a variable equal to the natural logarithmic function by some other variable • Logarithm (genconloga): set a variable equal to the logarithmic function by some other variable • Power (genconpow): set a variable equal to the power function by some other variable • SIN (genconsin): set a variable equal to the sine function by some other variable • COS (genconcos): set a variable equal to the cosine function by some other variable • TAN (gencontan): set a variable equal to the tangent function by some other variable Please refer to this section for additional details on general constraints. genconmax (optional) A list of lists. When present, each entry in genconmax defines a MAX general constraint of the form Each entry may have the following named components: resvar Specified via model$genconmax[[i]]$resvar. Index of the variable in the left-hand side of the constraint. vars Specified via model$genconmax[[i]]$vars, it is a vector of indices of variables in the right-hand side of the constraint. con (optional) Specified via model$genconmax[[i]]$con. When present, specifies the constant on the left-hand side. Default value is . name (optional) Specified via model$genconmax[[i]]$name. When present, specifies the name of the -th MAX general constraint. genconmin (optional) A list of lists. When present, each entry in genconmax defines a MIN general constraint of the form Each entry may have the following named components: resvar Specified via model$genconmin[[i]]$resvar. Index of the variable in the left-hand side of the constraint. vars Specified via model$genconmin[[i]]$vars, it is a vector of indices of variables in the right-hand side of the constraint. con (optional) Specified via model$genconmin[[i]]$con. When present, specifies the constant on the left-hand side. Default value is . name (optional) Specified via model$genconmin[[i]]$name. When present, specifies the name of the -th MIN general constraint. genconabs (optional) A list of lists. When present, each entry in genconmax defines an ABS general constraint of the form Each entry may have the following named components: resvar Specified via model$genconabs[[i]]$resvar. Index of the variable in the left-hand side of the constraint. argvar Specified via model$genconabs[[i]]$argvar. Index of the variable in the right-hand side of the constraint. name (optional) Specified via model$genconabs[[i]]$name. When present, specifies the name of the -th ABS general constraint. genconand (optional) A list of lists. When present, each entry in genconand defines an AND general constraint of the form Each entry may have the following named components: resvar Specified via model$genconand[[i]]$resvar. Index of the variable in the left-hand side of the constraint. vars Specified via model$genconand[[i]]$vars, it is a vector of indices of variables in the right-hand side of the constraint. name (optional) Specified via model$genconand[[i]]$name. When present, specifies the name of the -th AND general constraint. genconor (optional) A list of lists. When present, each entry in genconor defines an OR general constraint of the form Each entry may have the following named components: resvar Specified via model$genconor[[i]]$resvar. Index of the variable in the left-hand side of the constraint. vars Specified via model$genconor[[i]]$vars, it is a vector of indices of variables in the right-hand side of the constraint. name (optional) Specified via model$genconor[[i]]$name. When present, specifies the name of the -th OR general constraint. genconind (optional) A list of lists. When present, each entry in genconind defines an INDICATOR general constraint of the form This constraint states that when the binary variable takes the value binval then the linear constraint must hold. Note that sense is one of '=', '<', or '>' for equality (), less than or equal () or greater than or equal () constraints. Each entry may have the following named components: binvar Specified via model$genconind[[i]]$binvar. Index of the implicating binary variable. binval Specified via model$genconind[[i]]$binval. Value for the binary variable that forces the following linear constraint to be satisfied. It can be either 0 or 1. a Specified via 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 (should be built using sparseVector from the Matrix package). sense Specified via model$genconind[[i]]$sense. Sense of the implied linear constraint. Must be one of '=', '<', or '>'. rhs Specified via model$genconind[[i]]$rhs. Right-hand side value of the implied linear constraint. name (optional) Specified via model$genconind[[i]]$name. When present, specifies the name of the -th INDICATOR general constraint. genconpwl (optional) A list of lists. When present, each entry in genconpwl defines a piecewise-linear constraint of the form The breakpoints for are provided as arguments. Refer to the description of piecewise-linear objectives for details of how piecewise-linear functions are defined Each entry may have the following named components: xvar Specified via model$genconpwl[[i]]$xvar. Index of the variable in the right-hand side of the constraint. yvar Specified via model$genconpwl[[i]]$yvar. Index of the variable in the left-hand side of the constraint. xpts Specified via model$genconpwl[[i]]$xpts. Specifies the values for the points that define the piecewise-linear function. Must be in non-decreasing order. ypts Specified via model$genconpwl[[i]]$ypts. Specifies the values for the points that define the piecewise-linear function. name (optional) Specified via model$genconpwl[[i]]$name. When present, specifies the name of the -th piecewise-linear general constraint. genconpoly (optional) A list of lists. When present, each entry in genconpoly defines a polynomial function constraint of the form A piecewise-linear approximation of the function is added to the model. The details of the approximation are controlled using the following four attributes (or using the parameters with the same names): FuncPieces, FuncPieceError, FuncPiecesLength, and FuncPieceRatio. For details, consult the General Constraint discussion. Each entry may have the following named components: xvar Specified via model$genconpoly[[i]]$xvar. Index of the variable in the right-hand side of the constraint. yvar Specified via model$genconpoly[[i]]$yvar. Index of the variable in the left-hand side of the constraint. p Specified via model$genconpoly[[i]]$p. Specifies the coefficients for the polynomial function (starting with the coefficient for the highest power). If is the highest power term, a dense vector of length is returned. name (optional) Specified via model$genconpoly[[i]]$name. When present, specifies the name of the -th polynomial function constraint. funcpieces (optional) Specified via model$genconpoly[[i]]$funcpieces. When present, specifies the FuncPieces attribute of the -th polynomial function constraint. funcpiecelength (optional) Specified via model$genconpoly[[i]]$funcpiecelength. When present, specifies the FuncPieceLength attribute of the -th polynomial function constraint. funcpieceerror (optional) Specified via model$genconpoly[[i]]$funcpieceerror. When present, specifies the FuncPieceError attribute of the -th polynomial function constraint. funcpieceratio (optional) Specified via model$genconpoly[[i]]$funcpieceratio. When present, specifies the FuncPieceRatio attribute of the -th polynomial function constraint. genconexp (optional) A list of lists. When present, each entry in genconexp defines the natural exponential function constraint of the form A piecewise-linear approximation of the function is added to the model. The details of the approximation are controlled using the following four attributes (or using the parameters with the same names): FuncPieces, FuncPieceError, FuncPiecesLength, and FuncPieceRatio. For details, consult the General Constraint discussion. Each entry may have the following named components: xvar Specified via model$genconexp[[i]]$xvar. Index of the variable in the right-hand side of the constraint. yvar Specified via model$genconexp[[i]]$yvar. Index of the variable in the left-hand side of the constraint. name (optional) Specified via model$genconexp[[i]]$name. When present, specifies the name of the -th natural exponential function constraint. funcpieces (optional) Specified via model$genconexp[[i]]$funcpieces. When present, specifies the FuncPieces attribute of the -th natural exponential function constraint. funcpiecelength (optional) Specified via model$genconexp[[i]]$funcpiecelength. When present, specifies the FuncPieceLength attribute of the -th natural exponential function constraint. funcpieceerror (optional) Specified via model$genconexp[[i]]$funcpieceerror. When present, specifies the FuncPieceError attribute of the -th natural exponential function constraint. funcpieceratio (optional) Specified via model$genconexp[[i]]$funcpieceratio. When present, specifies the FuncPieceRatio attribute of the -th natural exponential function constraint. genconexpa (optional) A list of lists. When present, each entry in genconexpa defines an exponential function constraint of the form A piecewise-linear approximation of the function is added to the model. The details of the approximation are controlled using the following four attributes (or using the parameters with the same names): FuncPieces, FuncPieceError, FuncPiecesLength, and FuncPieceRatio. For details, consult the General Constraint discussion. Each entry may have the following named components: xvar Specified via model$genconexpa[[i]]$xvar. Index of the variable in the right-hand side of the constraint. yvar Specified via model$genconexpa[[i]]$yvar. Index of the variable in the left-hand side of the constraint. a Specified via model$genconexpa[[i]]$a. Specifies the base of the exponential function . name (optional) Specified via model$genconexpa[[i]]$name. When present, specifies the name of the -th exponential function constraint. funcpieces (optional) Specified via model$genconexpa[[i]]$funcpieces. When present, specifies the FuncPieces attribute of the -th exponential function constraint. funcpiecelength (optional) Specified via model$genconexpa[[i]]$funcpiecelength. When present, specifies the FuncPieceLength attribute of the -th exponential function constraint. funcpieceerror (optional) Specified via model$genconexpa[[i]]$funcpieceerror. When present, specifies the FuncPieceError attribute of the -th exponential function constraint. funcpieceratio (optional) Specified via model$genconexpa[[i]]$funcpieceratio. When present, specifies the FuncPieceRatio attribute of the -th exponential function constraint. genconlog (optional) A list of lists. When present, each entry in genconlog defines the natural logarithmic function constraint of the form A piecewise-linear approximation of the function is added to the model. The details of the approximation are controlled using the following four attributes (or using the parameters with the same names): FuncPieces, FuncPieceError, FuncPiecesLength, and FuncPieceRatio. For details, consult the General Constraint discussion. Each entry may have the following named components: xvar Specified via model$genconlog[[i]]$xvar. Index of the variable in the right-hand side of the constraint. yvar Specified via model$genconlog[[i]]$yvar. Index of the variable in the left-hand side of the constraint. name (optional) Specified via model$genconlog[[i]]$name. When present, specifies the name of the -th natural logarithmic function constraint. funcpieces (optional) Specified via model$genconlog[[i]]$funcpieces. When present, specifies the FuncPieces attribute of the -th natural logarithmic function constraint. funcpiecelength (optional) Specified via model$genconlog[[i]]$funcpiecelength. When present, specifies the FuncPieceLength attribute of the -th natural logarithmic function constraint. funcpieceerror (optional) Specified via model$genconlog[[i]]$funcpieceerror. When present, specifies the FuncPieceError attribute of the -th natural logarithmic function constraint. funcpieceratio (optional) Specified via model$genconlog[[i]]$funcpieceratio. When present, specifies the FuncPieceRatio attribute of the -th natural logarithmic function constraint. genconloga (optional) A list of lists. When present, each entry in genconloga defines a logarithmic function constraint of the form A piecewise-linear approximation of the function is added to the model. The details of the approximation are controlled using the following four attributes (or using the parameters with the same names): FuncPieces, FuncPieceError, FuncPiecesLength, and FuncPieceRatio. For details, consult the General Constraint discussion. Each entry may have the following named components: xvar Specified via model$genconloga[[i]]$xvar. Index of the variable in the right-hand side of the constraint. yvar Specified via model$genconloga[[i]]$yvar. Index of the variable in the left-hand side of the constraint. a Specified via model$genconloga[[i]]$a. Specifies the base of the logarithmic function . name (optional) Specified via model$genconloga[[i]]$name. When present, specifies the name of the -th logarithmic function constraint. funcpieces (optional) Specified via model$genconloga[[i]]$funcpieces. When present, specifies the FuncPieces attribute of the -th logarithmic function constraint. funcpiecelength (optional) Specified via model$genconloga[[i]]$funcpiecelength. When present, specifies the FuncPieceLength attribute of the -th logarithmic function constraint. funcpieceerror (optional) Specified via model$genconloga[[i]]$funcpieceerror. When present, specifies the FuncPieceError attribute of the -th logarithmic function constraint. funcpieceratio (optional) Specified via model$genconloga[[i]]$funcpieceratio. When present, specifies the FuncPieceRatio attribute of the -th logarithmic function constraint. genconpow (optional) A list of lists. When present, each entry in genconpow defines a power function constraint of the form A piecewise-linear approximation of the function is added to the model. The details of the approximation are controlled using the following four attributes (or using the parameters with the same names): FuncPieces, FuncPieceError, FuncPiecesLength, and FuncPieceRatio. For details, consult the General Constraint discussion. Each entry may have the following named components: xvar Specified via model$genconpow[[i]]$xvar. Index of the variable in the right-hand side of the constraint. yvar Specified via model$genconpow[[i]]$yvar. Index of the variable in the left-hand side of the constraint. a Specified via model$genconpow[[i]]$a. Specifies the exponent of the power function. name (optional) Specified via model$genconpow[[i]]$name. When present, specifies the name of the -th power function constraint. funcpieces (optional) Specified via model$genconpow[[i]]$funcpieces. When present, specifies the FuncPieces attribute of the -th power function constraint. funcpiecelength (optional) Specified via model$genconpow[[i]]$funcpiecelength. When present, specifies the FuncPieceLength attribute of the -th power function constraint. funcpieceerror (optional) Specified via model$genconpow[[i]]$funcpieceerror. When present, specifies the FuncPieceError attribute of the -th power function constraint. funcpieceratio (optional) Specified via model$genconpow[[i]]$funcpieceratio. When present, specifies the FuncPieceRatio attribute of the -th power function constraint. genconsin (optional) A list of lists. When present, each entry in genconsin defines the sine function constraint of the form A piecewise-linear approximation of the function is added to the model. The details of the approximation are controlled using the following four attributes (or using the parameters with the same names): FuncPieces, FuncPieceError, FuncPiecesLength, and FuncPieceRatio. For details, consult the General Constraint discussion. Each entry may have the following named components: xvar Specified via model$genconsin[[i]]$xvar. Index of the variable in the right-hand side of the constraint. yvar Specified via model$genconsin[[i]]$yvar. Index of the variable in the left-hand side of the constraint. name (optional) Specified via model$genconsin[[i]]$name. When present, specifies the name of the -th sine function constraint. funcpieces (optional) Specified via model$genconsin[[i]]$funcpieces. When present, specifies the FuncPieces attribute of the -th sine function constraint. funcpiecelength (optional) Specified via model$genconsin[[i]]$funcpiecelength. When present, specifies the FuncPieceLength attribute of the -th sine function constraint. funcpieceerror (optional) Specified via model$genconsin[[i]]$funcpieceerror. When present, specifies the FuncPieceError attribute of the -th sine function constraint. funcpieceratio (optional) Specified via model$genconsin[[i]]$funcpieceratio. When present, specifies the FuncPieceRatio attribute of the -th sine function constraint. genconcos (optional) A list of lists. When present, each entry in genconcos defines the cosine function constraint of the form A piecewise-linear approximation of the function is added to the model. The details of the approximation are controlled using the following four attributes (or using the parameters with the same names): FuncPieces, FuncPieceError, FuncPiecesLength, and FuncPieceRatio. For details, consult the General Constraint discussion. Each entry may have the following named components: xvar Specified via model$genconcos[[i]]$xvar. Index of the variable in the right-hand side of the constraint. yvar Specified via model$genconcos[[i]]$yvar. Index of the variable in the left-hand side of the constraint. name (optional) Specified via model$genconcos[[i]]$name. When present, specifies the name of the -th cosine function constraint. funcpieces (optional) Specified via model$genconcos[[i]]$funcpieces. When present, specifies the FuncPieces attribute of the -th cosine function constraint. funcpiecelength (optional) Specified via model$genconcos[[i]]$funcpiecelength. When present, specifies the FuncPieceLength attribute of the -th cosine function constraint. funcpieceerror (optional) Specified via model$genconcos[[i]]$funcpieceerror. When present, specifies the FuncPieceError attribute of the -th cosine function constraint. funcpieceratio (optional) Specified via model$genconcos[[i]]$funcpieceratio. When present, specifies the FuncPieceRatio attribute of the -th cosine function constraint. gencontan (optional) A list of lists. When present, each entry in gencontan defines the tangent function constraint of the form A piecewise-linear approximation of the function is added to the model. The details of the approximation are controlled using the following four attributes (or using the parameters with the same names): FuncPieces, FuncPieceError, FuncPiecesLength, and FuncPieceRatio. For details, consult the General Constraint discussion. Each entry may have the following named components: xvar Specified via model$gencontan[[i]]$xvar. Index of the variable in the right-hand side of the constraint. yvar Specified via model$gencontan[[i]]$yvar. Index of the variable in the left-hand side of the constraint. name (optional) Specified via model$gencontancos[[i]]$name. When present, specifies the name of the -th tangent function constraint. funcpieces (optional) Specified via model$gencontan[[i]]$funcpieces. When present, specifies the FuncPieces attribute of the -th tangent function constraint. funcpiecelength (optional) Specified via model$gencontan[[i]]$funcpiecelength. When present, specifies the FuncPieceLength attribute of the -th tangent function constraint. funcpieceerror (optional) Specified via model$gencontan[[i]]$funcpieceerror. When present, specifies the FuncPieceError attribute of the -th tangent function constraint. funcpieceratio (optional) Specified via model$gencontan[[i]]$funcpieceratio. When present, specifies the FuncPieceRatio attribute of the -th tangent function constraint. Advanced named components: pwlobj (optional) The piecewise-linear objective functions. A list of lists. When present, each entry in pwlobj defines a piecewise-linear objective function for a single variable. The index of the variable whose objective function is being defined is stored in model$pwlobj[[i]]$var. The values for the points that define the piecewise-linear function are stored in model$pwlobj[[i]]$x. The values in the vector must be in non-decreasing order. The values for the points that define the piecewise-linear function are stored in model$pwlobj[[i]]$y. vbasis (optional) The variable basis status vector. Used to provide an advanced starting point for the simplex algorithm. You would generally never concern yourself with the contents of this vector, but would instead simply pass it from the result of a previous optimization run to the input of a subsequent run. When present, you must specify one value for each column of A. cbasis (optional) The constraint basis status vector. Used to provide an advanced starting point for the simplex algorithm. Consult the vbasis description for details. When present, you must specify one value for each row of A. varhintval (optional) A set of user hints. If you know that a variable is likely to take a particular value in high quality solutions of a MIP model, you can provide that value as a hint. You can also (optionally) provide information about your level of confidence in a hint with the varhintpri named component. If present, you must specify one value for each column of A. Use a value of NA for variables where no such hint is known. For more details, please refer to the VarHitVal attribute documentation. varhintpri (optional) Priorities on user hints. After providing variable hints through the varhintval list, you can optionally also provide hint priorities to give an indication of your level of confidence in your hints. If present, you must specify a value for each column of A. For more details, please refer to the VarHintPri attribute documentation. branchpriority (optional) Variable branching priority. If present, the value of this attribute is used as the primary criteria for selecting a fractional variable for branching during the MIP search. Variables with larger values always take priority over those with smaller values. Ties are broken using the standard branch variable selection criteria. If present, you must specify one value for each column of A. pstart (optional) The current simplex start vector. If you set pstart values for every variable in the model and dstart values for every constraint, then simplex will use those values to compute a warm start basis. For more details, please refer to the PStart attribute documentation. dstart (optional) The current simplex start vector. If you set dstart values for every linear constraint in the model and pstart values for every variable, then simplex will use those values to compute a warm start basis. For more details, please refer to the DStart attribute documentation. lazy (optional) Determines whether a linear constraint is treated as a lazy constraint. If present, you must specify one value for each row of A. For more details, please refer to the Lazy attribute documentation. start (optional) The MIP start vector. The MIP solver will attempt to build an initial solution from this vector. When present, you must specify a start value for each variable. Note that you can set the start value for a variable to NA, which instructs the MIP solver to try to fill in a value for that variable. partition (optional) The MIP variable partition number, which is used by the MIP solution improvement heuristic. If present, you must specify one value for each variable of A. For more details, please refer to the Partition attribute documentation. If any of the mandatory components listed above are missing, the gurobi() function will return an error. Below is an example that demonstrates the construction of a simple optimization model: model <- list() model$A <- matrix(c(1,2,3,1,1,0), nrow=2, byrow=T)
model$obj <- c(1,1,1) model$modelsense <- 'max'
model$rhs <- c(4,1) model$sense <- c('<', '>')

You can also build A as a sparse matrix, using either sparseMatrix or simple_triplet_matrix:

model$A <- spMatrix(2, 3, c(1, 1, 1, 2, 2), c(1, 2, 3, 1, 2), c(1, 2, 3, 1, 1)) model$A <- simple_triplet_matrix(c(1, 1, 1, 2, 2), c(1, 2, 3, 1, 2), c(1, 2, 3, 1, 1))

Note that the Gurobi R interface allows you to specify a scalar value for most of the array-valued components. The specified value will be expanded to an array of the appropriate size, with each component of the array equal to the scalar (e.g., model$obj <- 1 would be equivalent to model$obj <- c(1,1,1) in the example).