Try our new documentation site (beta).

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 (<span>$</span>b<span>$</span> 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 the variable section of the reference manual 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 ( <span>$</span>\mathrm{alpha}<span>$</span> 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.

quadcon (optional)
The quadratic constraints. A list of lists. When present, each element in quadcon defines a single quadratic constraint: <span>$</span>x^TQc\, x + q^Tx \le \mathrm{beta}<span>$</span>.

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 <span>$</span>i<span>$</span> 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 SOS Constraints section in the reference manual 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 in the reference manual for more details on multi-objective optimization. Each objective <span>$</span>i<span>$</span> 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.

Computing an IIS

When computing an Irreducible Inconsistent Subsytem (IIS) for an infeasible model, additional model attributes for variable bounds, linear constraints, quadratic constraints and general constraints may be set in order to indicate whether a corresponing entity should explicitly included or excluded from the IIS:

iislbforce (optional)
list of length equal to the number of variables. The value of model$iislbforce[[i]] specifies the IIS force attribute for the lower bound of the <span>$</span>i<span>$</span>-th variable.

iisubforce (optional)
list of length equal to the number of variables. The value of model$iisubforce[[i]] specifies the IIS force attribute for the upper bound of the <span>$</span>i<span>$</span>-th variable.

iisconstrforce (optional)
list of length equal to the number of constraints. The value of model$iisconstrforce[[i]] specifies the IIS force attribute for the <span>$</span>i<span>$</span>-th constraint.

iisqconstrforce (optional)
list of length equal to the number of quadratic constraints. The value of model$iisqconstrforce[[i]] specifies the IIS force attribute for the <span>$</span>i<span>$</span>-th quadratic constraint.

iisgenconstrforce (optional)
list of length equal to the number of general constraints. The value of model$iisgenconstrforce[[i]] specifies the IIS force attribute for the <span>$</span>i<span>$</span>-th general constraint.

Possible values for all five attribute of listsfrom above are: <span>$</span>-1<span>$</span> to let the algorithm decide, <span>$</span>0<span>$</span> to exclude the corresponding entity from the IIS, and <span>$</span>1<span>$</span> to always include the corresponding entity in the IIS.

Note that setting this attribute to 0 may make the resulting subsystem feasible (or consistent), which would then make it impossible to construct an IIS. Trying anyway will result in a GRB_ERROR_IIS_NOT_INFEASIBLE error. Similarly, setting this attribute to 1 may result in an IIS that is not irreducible. More precisely, the system would only be irreducible with respect to the model elements that have force values of -1 or 0.

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
  • NORM (genconnorm): set a decision variable equal to the p-norm of a vector of decision variables
  • 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 General Constraints section in the reference manual 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
<span>$</span>x[\mathrm{resvar}] = \max\left\{\mathrm{con},x[j]:j\in\mathrm{vars}\right\}<span>$</span>
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 <span>$</span>-\infty<span>$</span>.
name (optional)
Specified via model$genconmax[[i]]$name. When present, specifies the name of the <span>$</span>i<span>$</span>-th MAX general constraint.

genconmin (optional)
A list of lists. When present, each entry in genconmax defines a MIN general constraint of the form
<span>$</span>x[\mathrm{resvar}] = \min\left\{\mathrm{con},x[j]:j\in\mathrm{vars}\right\}<span>$</span>
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 <span>$</span>\infty<span>$</span>.
name (optional)
Specified via model$genconmin[[i]]$name. When present, specifies the name of the <span>$</span>i<span>$</span>-th MIN general constraint.

genconabs (optional)
A list of lists. When present, each entry in genconmax defines an ABS general constraint of the form
<span>$</span>x[\mathrm{resvar}] = \vert x[\mathrm{argvar}]\vert<span>$</span>
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 <span>$</span>i<span>$</span>-th ABS general constraint.

genconand (optional)
A list of lists. When present, each entry in genconand defines an AND general constraint of the form
<span>$</span>x[\mathrm{resvar}] = \mathrm{and}\{x[i]:i\in\mathrm{vars}\}<span>$</span>
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 <span>$</span>i<span>$</span>-th AND general constraint.

genconor (optional)
A list of lists. When present, each entry in genconor defines an OR general constraint of the form
<span>$</span>x[\mathrm{resvar}] = \mathrm{or}\{x[i]:i\in\mathrm{vars}\}<span>$</span>
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 <span>$</span>i<span>$</span>-th OR general constraint.

genconnorm (optional)
A list of lists. When present, each entry in genconnorm defines a NORM general constraint of the form
<span>$</span>x[\mathrm{resvar}] = \mathrm{norm}(x[i]:i\in\mathrm{vars}, \mathrm{which})<span>$</span>
Each entry may have the following named components:
resvar
Specified via model$genconnorm[[i]]$resvar. Index of the variable in the left-hand side of the constraint.
vars
Specified via model$genconnorm[[i]]$vars, it is a vector of indices of variables in the right-hand side of the constraint.
which
Specified via model$genconnorm[[i]]$which. Specifies which p-norm to use. Possible values are 0, 1, 2 and <span>$</span>\infty<span>$</span>.
name (optional)
Specified via model$genconnorm[[i]]$name. When present, specifies the name of the <span>$</span>i<span>$</span>-th NORM general constraint.

genconind (optional)
A list of lists. When present, each entry in genconind defines an INDICATOR general constraint of the form
<span>$</span>x[\mathrm{binvar}] = \mathrm{binval}\Rightarrow\sum\left( x\MRalternative{(j)}{...
...\cdot\mathrm{a}\MRalternative{(j)}{[[j]]}\right) \ \mathrm{sense}\ \mathrm{rhs}<span>$</span>
This constraint states that when the binary variable <span>$</span>x[\mathrm{binvar}]<span>$</span> takes the value binval then the linear constraint <span>$</span>\sum\left(x[\mathrm{vars}\MRalternative{(j)}{[[j]]}]\cdot\mathrm{val}\MRalternative{(j)}{[[j]]}\right)\ \mathrm{sense}\ \mathrm{rhs}<span>$</span> must hold. Note that sense is one of =, <, or > for equality (<span>$</span>=<span>$</span>), less than or equal (<span>$</span>\leq<span>$</span>) or greater than or equal (<span>$</span>\geq<span>$</span>) 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 <span>$</span>i<span>$</span>-th INDICATOR general constraint.

genconpwl (optional)
A list of lists. When present, each entry in genconpwl defines a piecewise-linear constraint of the form
<span>$</span>x[\mathrm{yvar}] = f(x[\mathrm{xvar}])<span>$</span>
The breakpoints for <span>$</span>f<span>$</span> 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 <span>$</span>x<span>$</span> 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 <span>$</span>y<span>$</span> 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 <span>$</span>i<span>$</span>-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
<span>$</span>x[\mathrm{yvar}] = p_0 x[\mathrm{xvar}]^d + p_1 x[\mathrm{xvar}]^{d-1} + ... + p_{d-1} x[\mathrm{xvar}] + p_{d}<span>$</span>
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 <span>$</span>x^d<span>$</span> is the highest power term, a dense vector of length <span>$</span>d+1<span>$</span> is returned.
name (optional)
Specified via model$genconpoly[[i]]$name. When present, specifies the name of the <span>$</span>i<span>$</span>-th polynomial function constraint.
funcpieces (optional)
Specified via model$genconpoly[[i]]$funcpieces. When present, specifies the FuncPieces attribute of the <span>$</span>i<span>$</span>-th polynomial function constraint.
funcpiecelength (optional)
Specified via model$genconpoly[[i]]$funcpiecelength. When present, specifies the FuncPieceLength attribute of the <span>$</span>i<span>$</span>-th polynomial function constraint.
funcpieceerror (optional)
Specified via model$genconpoly[[i]]$funcpieceerror. When present, specifies the FuncPieceError attribute of the <span>$</span>i<span>$</span>-th polynomial function constraint.
funcpieceratio (optional)
Specified via model$genconpoly[[i]]$funcpieceratio. When present, specifies the FuncPieceRatio attribute of the <span>$</span>i<span>$</span>-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
<span>$</span>x[\mathrm{yvar}] = \mathrm{exp}(x[\mathrm{xvar}])<span>$</span>
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 <span>$</span>i<span>$</span>-th natural exponential function constraint.
funcpieces (optional)
Specified via model$genconexp[[i]]$funcpieces. When present, specifies the FuncPieces attribute of the <span>$</span>i<span>$</span>-th natural exponential function constraint.
funcpiecelength (optional)
Specified via model$genconexp[[i]]$funcpiecelength. When present, specifies the FuncPieceLength attribute of the <span>$</span>i<span>$</span>-th natural exponential function constraint.
funcpieceerror (optional)
Specified via model$genconexp[[i]]$funcpieceerror. When present, specifies the FuncPieceError attribute of the <span>$</span>i<span>$</span>-th natural exponential function constraint.
funcpieceratio (optional)
Specified via model$genconexp[[i]]$funcpieceratio. When present, specifies the FuncPieceRatio attribute of the <span>$</span>i<span>$</span>-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
<span>$</span>x[\mathrm{yvar}] = \mathrm{a}^{x[\mathrm{xvar}]}<span>$</span>
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 <span>$</span>a > 0<span>$</span>.
name (optional)
Specified via model$genconexpa[[i]]$name. When present, specifies the name of the <span>$</span>i<span>$</span>-th exponential function constraint.
funcpieces (optional)
Specified via model$genconexpa[[i]]$funcpieces. When present, specifies the FuncPieces attribute of the <span>$</span>i<span>$</span>-th exponential function constraint.
funcpiecelength (optional)
Specified via model$genconexpa[[i]]$funcpiecelength. When present, specifies the FuncPieceLength attribute of the <span>$</span>i<span>$</span>-th exponential function constraint.
funcpieceerror (optional)
Specified via model$genconexpa[[i]]$funcpieceerror. When present, specifies the FuncPieceError attribute of the <span>$</span>i<span>$</span>-th exponential function constraint.
funcpieceratio (optional)
Specified via model$genconexpa[[i]]$funcpieceratio. When present, specifies the FuncPieceRatio attribute of the <span>$</span>i<span>$</span>-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
<span>$</span>x[\mathrm{yvar}] = \mathrm{log}(x[\mathrm{xvar}])<span>$</span>
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 <span>$</span>i<span>$</span>-th natural logarithmic function constraint.
funcpieces (optional)
Specified via model$genconlog[[i]]$funcpieces. When present, specifies the FuncPieces attribute of the <span>$</span>i<span>$</span>-th natural logarithmic function constraint.
funcpiecelength (optional)
Specified via model$genconlog[[i]]$funcpiecelength. When present, specifies the FuncPieceLength attribute of the <span>$</span>i<span>$</span>-th natural logarithmic function constraint.
funcpieceerror (optional)
Specified via model$genconlog[[i]]$funcpieceerror. When present, specifies the FuncPieceError attribute of the <span>$</span>i<span>$</span>-th natural logarithmic function constraint.
funcpieceratio (optional)
Specified via model$genconlog[[i]]$funcpieceratio. When present, specifies the FuncPieceRatio attribute of the <span>$</span>i<span>$</span>-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
<span>$</span>x[\mathrm{yvar}] = \mathrm{log}(x[\mathrm{xvar}])\setminus\mathrm{log}(a)<span>$</span>
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 <span>$</span>a > 0<span>$</span>.
name (optional)
Specified via model$genconloga[[i]]$name. When present, specifies the name of the <span>$</span>i<span>$</span>-th logarithmic function constraint.
funcpieces (optional)
Specified via model$genconloga[[i]]$funcpieces. When present, specifies the FuncPieces attribute of the <span>$</span>i<span>$</span>-th logarithmic function constraint.
funcpiecelength (optional)
Specified via model$genconloga[[i]]$funcpiecelength. When present, specifies the FuncPieceLength attribute of the <span>$</span>i<span>$</span>-th logarithmic function constraint.
funcpieceerror (optional)
Specified via model$genconloga[[i]]$funcpieceerror. When present, specifies the FuncPieceError attribute of the <span>$</span>i<span>$</span>-th logarithmic function constraint.
funcpieceratio (optional)
Specified via model$genconloga[[i]]$funcpieceratio. When present, specifies the FuncPieceRatio attribute of the <span>$</span>i<span>$</span>-th logarithmic function constraint.

genconpow (optional)
A list of lists. When present, each entry in genconpow defines a power function constraint of the form
<span>$</span>x[\mathrm{yvar}] = x[\mathrm{xvar}]^\mathrm{a}<span>$</span>
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 <span>$</span>i<span>$</span>-th power function constraint.
funcpieces (optional)
Specified via model$genconpow[[i]]$funcpieces. When present, specifies the FuncPieces attribute of the <span>$</span>i<span>$</span>-th power function constraint.
funcpiecelength (optional)
Specified via model$genconpow[[i]]$funcpiecelength. When present, specifies the FuncPieceLength attribute of the <span>$</span>i<span>$</span>-th power function constraint.
funcpieceerror (optional)
Specified via model$genconpow[[i]]$funcpieceerror. When present, specifies the FuncPieceError attribute of the <span>$</span>i<span>$</span>-th power function constraint.
funcpieceratio (optional)
Specified via model$genconpow[[i]]$funcpieceratio. When present, specifies the FuncPieceRatio attribute of the <span>$</span>i<span>$</span>-th power function constraint.

genconsin (optional)
A list of lists. When present, each entry in genconsin defines the sine function constraint of the form
<span>$</span>x[\mathrm{yvar}] = \mathrm{sin}(x[\mathrm{xvar}])<span>$</span>
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 <span>$</span>i<span>$</span>-th sine function constraint.
funcpieces (optional)
Specified via model$genconsin[[i]]$funcpieces. When present, specifies the FuncPieces attribute of the <span>$</span>i<span>$</span>-th sine function constraint.
funcpiecelength (optional)
Specified via model$genconsin[[i]]$funcpiecelength. When present, specifies the FuncPieceLength attribute of the <span>$</span>i<span>$</span>-th sine function constraint.
funcpieceerror (optional)
Specified via model$genconsin[[i]]$funcpieceerror. When present, specifies the FuncPieceError attribute of the <span>$</span>i<span>$</span>-th sine function constraint.
funcpieceratio (optional)
Specified via model$genconsin[[i]]$funcpieceratio. When present, specifies the FuncPieceRatio attribute of the <span>$</span>i<span>$</span>-th sine function constraint.

genconcos (optional)
A list of lists. When present, each entry in genconcos defines the cosine function constraint of the form
<span>$</span>x[\mathrm{yvar}] = \mathrm{cos}(x[\mathrm{xvar}])<span>$</span>
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 <span>$</span>i<span>$</span>-th cosine function constraint.
funcpieces (optional)
Specified via model$genconcos[[i]]$funcpieces. When present, specifies the FuncPieces attribute of the <span>$</span>i<span>$</span>-th cosine function constraint.
funcpiecelength (optional)
Specified via model$genconcos[[i]]$funcpiecelength. When present, specifies the FuncPieceLength attribute of the <span>$</span>i<span>$</span>-th cosine function constraint.
funcpieceerror (optional)
Specified via model$genconcos[[i]]$funcpieceerror. When present, specifies the FuncPieceError attribute of the <span>$</span>i<span>$</span>-th cosine function constraint.
funcpieceratio (optional)
Specified via model$genconcos[[i]]$funcpieceratio. When present, specifies the FuncPieceRatio attribute of the <span>$</span>i<span>$</span>-th cosine function constraint.

gencontan (optional)
A list of lists. When present, each entry in gencontan defines the tangent function constraint of the form
<span>$</span>x[\mathrm{yvar}] = \mathrm{tan}(x[\mathrm{xvar}])<span>$</span>
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$gencontan[[i]]$name. When present, specifies the name of the <span>$</span>i<span>$</span>-th tangent function constraint.
funcpieces (optional)
Specified via model$gencontan[[i]]$funcpieces. When present, specifies the FuncPieces attribute of the <span>$</span>i<span>$</span>-th tangent function constraint.
funcpiecelength (optional)
Specified via model$gencontan[[i]]$funcpiecelength. When present, specifies the FuncPieceLength attribute of the <span>$</span>i<span>$</span>-th tangent function constraint.
funcpieceerror (optional)
Specified via model$gencontan[[i]]$funcpieceerror. When present, specifies the FuncPieceError attribute of the <span>$</span>i<span>$</span>-th tangent function constraint.
funcpieceratio (optional)
Specified via model$gencontan[[i]]$funcpieceratio. When present, specifies the FuncPieceRatio attribute of the <span>$</span>i<span>$</span>-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 <span>$</span>x<span>$</span> values for the points that define the piecewise-linear function are stored in
model$pwlobj[[i]]$x. The values in the <span>$</span>x<span>$</span> vector must be in non-decreasing order. The <span>$</span>y<span>$</span> 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 Attribute section in the reference manual.

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 Attribute section in the reference manual.

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 Attribute section in the reference manual.

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 Attribute section in the reference manual.

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 Attribute section in the reference manual.

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 Attribute section in the reference manual.

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).

Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.

Search

Gurobi Optimization