Movatterモバイル変換


[0]ホーム

URL:


ContentsMenuExpandLight modeDark modeAuto light/dark mode
Gurobi Optimizer Reference Manual
Light LogoDark Logo

Concepts

Features

Reference

Gurobi
Back to top

R API - Common Arguments#

Most common arguments in the Gurobi R interface areRlist variables, each containing multiplenamedcomponents.Several of these named components are optional. Note that you refer to anamed component of a list variable by adding a dollar sign to the end ofthe variable name, followed by the name of the named component. Forexample,model$A refers to named componentA ofvariablemodel.

The model argument#

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

Models can be built in a number of ways. You can populate theappropriate named components of themodel list using standardR routines. You can also read a model from a file, usinggurobi_read. A few API functions(gurobi_feasrelax andgurobi_relax) also returnmodels.

Note that all matrix named components within themodel variable canbe dense or sparse. Sparse matrices should be built using eithersparseMatrix from theMatrix package, orsimple_triplet_matrix from theslam package.

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

Commonly used named components#

A

The linear constraint matrix.

obj (optional)

The linear objective vector (thec vector in theproblem statement). When present, you must specifyone value for each column ofA. When absent, each variable has adefault objective coefficient of 0.

sense (optional)

The senses of the linear constraints. Allowed values are=,<, or>. You must specify one value for each row ofA, ora 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 (\(b\) intheproblem statement). You must specify one valuefor each row ofA. When absent, the right-hand side vectordefaults to the zero vector.

lb (optional)

The lower bound vector. When present, you must specify one value foreach column ofA. When absent, each variable has a default lowerbound of 0.

ub (optional)

The upper bound vector. When present, you must specify one value foreach column ofA. When absent, the variables have infinite upperbounds.

vtype (optional)

The variable types. This vector is used to capture variableintegrality constraints. Allowed values areC (continuous),B(binary),I (integer),S (semi-continuous), orN(semi-integer). Binary variables must be either 0 or 1. Integervariables can take any integer value between the specified lower andupper bounds. Semi-continuous variables can take any value betweenthe specified lower and upper bounds, or a value of zero.Semi-integer variables can take any integer value between thespecified lower and upper bounds, or a value of zero. When present,you must specify one value for each column ofA, or a singlevalue to specify that all variables have the same type. When absent,each variable is treated as being continuous. Refer to thevariable section of the referencemanual for more information on variable types.

modelsense (optional)

The optimization sense. Allowed values aremin (minimize) ormax (maximize). When absent, the default optimization sense isminimization.

modelname (optional)

The name of the model. The name appears in the Gurobi log, and whenwriting a model to a file.

objcon (optional)

The constant offset in the objective function (\(\mathrm{alpha}\)in theproblem statement).

varnames (optional)

The variable names vector. A character vector. When present, eachelement of this vector defines the name of a variable. You mustspecify a name for each column ofA.

constrnames (optional)

The constraint names vector. A character vector. When present, eachelement of the vector defines the name of a constraint. You mustspecify a name for each row ofA.

Quadratic objective and constraint named components#

Q (optional)

The quadratic objective matrix. When present,Q must be a squarematrix whose row and column counts are equal to the number of columnsinA.

quadcon (optional)

The quadratic constraints. A list of lists. When present, eachelement inquadcon defines a single quadratic constraint:\(x^TQc\, x + q^Tx \le \mathrm{beta}\).

TheQc matrix must be a square matrix whose row and column countsare equal to the number of columns ofA. It is stored inmodel$quadcon[[i]]$Qc.

The optionalq vector defines the linear terms in the constraint.It can be a dense vector specifying a value for each column ofAor a sparse vector (should be built usingsparseVector from theMatrix package). It is stored inmodel$quadcon[[i]]$q.

The scalarbeta is stored inmodel$quadcon[[i]]$rhs. It defines theright-hand side value for the constraint.

The optionalsense string defines the sense of the quadraticconstraint. Allowed values are<,= or>. If not present,the default sense is<. It is stored inmodel$quadcon[[i]]$sense.

The optionalname string defines the name of the quadraticconstraint. It is stored inmodel$quadcon[[i]]$name.

SOS constraint named components#

sos (optional)

The Special Ordered Set (SOS) constraints. A list of lists. Whenpresent, each entry insos defines a single SOS constraint. A SOSconstraint can be of type 1 or 2. The type of SOS constraint\(i\) is specified viamodel$sos[[i]]$type. A type 1 SOSconstraint is a set of variables where at most one variable in theset may take a value other than zero. A type 2 SOS constraint is anordered set of variables where at most two variables in the set maytake non-zero values. If two take non-zeros values, they must becontiguous in the ordered set. The members of an SOS constraint arespecified by placing their indices in vectormodel$sos[[i]]$index. Weights associatedwith SOS members are provided in vectormodel$sos[[i]]$weight. Please refer toSOS Constraints section in thereference manual for details on SOS constraints.

Multi-objective named components#

multiobj (optional)

Multi-objective specification for the model. A list of lists. Whenpresent, each entry inmultiobj defines a single objective of amulti-objective problem. Please refer to theMultiple Objectives section in thereference manual for more details on multi-objective optimization.Each objective\(i\) may have the following named components:

objn

Specified viamodel$multiobj[[i]]$objn. This is thei-th objective vector.

objcon (optional)

Specified viamodel$multiobj[[i]]$objcon. Ifprovided, this is thei-th objective constant. The default valueis 0.

priority (optional)

Specified viamodel$multiobj[[i]]$priority. Ifprovided, this value is thehierarchical priority for thisobjective. The default value is 0.

weight (optional)

Specified viamodel$multiobj[[i]]$weight. Ifprovided, this value is the multiplier used when aggregatingobjectives. The default value is 1.0.

reltol (optional)

Specified viamodel$multiobj[[i]]$reltol. Ifprovided, this value specifies the relative objective degradationwhen doing hierarchical multi-objective optimization. The defaultvalue is 0.

abstol (optional)

Specified viamodel$multiobj[[i]]$abstol. Ifprovided, this value specifies the absolute objective degradationwhen doing hierarchical multi-objective optimization. The defaultvalue is 0.

name (optional)

Specified viamodel$multiobj[[i]]$name. If provided,this string specifies the name of thei-th objective function.

Note that when multiple objectives are present, theresult$objval named component that is returned inthe result of an optimization call will be a vector of the samelength asmodel$multiobj.

A multi-objective model can’t have other objectives. Thus, combiningmodel$multiobj with any ofmodel$obj,model$objcon,model$pwlobj, ormodel$Q is an error.

Computing an IIS#

When computing an Irreducible Inconsistent Subsystem (IIS) for aninfeasible model, additional model attributes for variable bounds,linear constraints, quadratic constraints and general constraints may beset in order to indicate whether the corresponding entity should beexplicitly included or excluded from the IIS:

iislbforce (optional)

list of length equal to the number of variables. The value ofmodel$iislbforce[[i]] specifies the IIS forceattribute for the lower bound of the\(i\)-th variable.

iisubforce (optional)

list of length equal to the number of variables. The value ofmodel$iisubforce[[i]] specifies the IIS forceattribute for the upper bound of the\(i\)-th variable.

iisconstrforce (optional)

list of length equal to the number of constraints. The value ofmodel$iisconstrforce[[i]] specifies the IIS forceattribute for the\(i\)-th constraint.

iisqconstrforce (optional)

list of length equal to the number of quadratic constraints. Thevalue ofmodel$iisqconstrforce[[i]] specifies the IISforce attribute for the\(i\)-th quadratic constraint.

iisgenconstrforce (optional)

list of length equal to the number of general constraints. The valueofmodel$iisgenconstrforce[[i]] specifies the IISforce attribute for the\(i\)-th general constraint.

Possible values for all five attribute of listsfrom above are:\(-1\) to let the algorithm decide,\(0\) to exclude thecorresponding entity from the IIS, and\(1\) to always include thecorresponding entity in the IIS.

Note that setting this attribute to 0 may make the resulting subsystemfeasible (or consistent), which would then make it impossible toconstruct an IIS. Trying anyway will result in aIIS_NOT_INFEASIBLE error. Similarly, settingthis attribute to 1 may result in an IIS that is not irreducible. Moreprecisely, the system would only be irreducible with respect to themodel elements that have force values of -1 or 0.

General constraint named components#

The list of lists described below are used to addgeneral constraintsto a model. Please refer to theGeneral Constraints section inthe reference manual for additional details on general constraints.

genconmax (optional)

A list of lists. When present, each entry ingenconmax defines aMAX general constraint of the form

\[x[\mathrm{resvar}] = \max\left\{\mathrm{con},x[j]:j\in\mathrm{vars}\right\}\]

Each entry may have the following named components:

resvar

Specified viamodel$genconmax[[i]]$resvar.Index of the variable in the left-hand side of the constraint.

vars

Specified viamodel$genconmax[[i]]$vars, it isa vector of indices of variables in the right-hand side of theconstraint.

con (optional)

Specified viamodel$genconmax[[i]]$con. Whenpresent, specifies the constant on the left-hand side. Defaultvalue is\(-\infty\).

name (optional)

Specified viamodel$genconmax[[i]]$name. Whenpresent, specifies the name of the\(i\)-th MAX generalconstraint.

genconmin (optional)

A list of lists. When present, each entry ingenconmax defines aMIN general constraint of the form

\[x[\mathrm{resvar}] = \min\left\{\mathrm{con},x[j]:j\in\mathrm{vars}\right\}\]

Each entry may have the following named components:

resvar

Specified viamodel$genconmin[[i]]$resvar.Index of the variable in the left-hand side of the constraint.

vars

Specified viamodel$genconmin[[i]]$vars, it isa vector of indices of variables in the right-hand side of theconstraint.

con (optional)

Specified viamodel$genconmin[[i]]$con. Whenpresent, specifies the constant on the left-hand side. Defaultvalue is\(\infty\).

name (optional)

Specified viamodel$genconmin[[i]]$name. Whenpresent, specifies the name of the\(i\)-th MIN generalconstraint.

genconabs (optional)

A list of lists. When present, each entry ingenconmax defines anABS general constraint of the form

\[x[\mathrm{resvar}] = \vert x[\mathrm{argvar}]\vert\]

Each entry may have the following named components:

resvar

Specified viamodel$genconabs[[i]]$resvar.Index of the variable in the left-hand side of the constraint.

argvar

Specified viamodel$genconabs[[i]]$argvar. Index ofthe variable in the right-hand side of the constraint.

name (optional)

Specified viamodel$genconabs[[i]]$name. Whenpresent, specifies the name of the\(i\)-th ABS generalconstraint.

genconand (optional)

A list of lists. When present, each entry ingenconand defines anAND general constraint of the form

\[x[\mathrm{resvar}] = \mathrm{and}\{x[i]:i\in\mathrm{vars}\}\]

Each entry may have the following named components:

resvar

Specified viamodel$genconand[[i]]$resvar.Index of the variable in the left-hand side of the constraint.

vars

Specified viamodel$genconand[[i]]$vars, it isa vector of indices of variables in the right-hand side of theconstraint.

name (optional)

Specified viamodel$genconand[[i]]$name. Whenpresent, specifies the name of the\(i\)-th AND generalconstraint.

genconor (optional)

A list of lists. When present, each entry ingenconor defines anOR general constraint of the form

\[x[\mathrm{resvar}] = \mathrm{or}\{x[i]:i\in\mathrm{vars}\}\]

Each entry may have the following named components:

resvar

Specified viamodel$genconor[[i]]$resvar.Index of the variable in the left-hand side of the constraint.

vars

Specified viamodel$genconor[[i]]$vars, it isa vector of indices of variables in the right-hand side of theconstraint.

name (optional)

Specified viamodel$genconor[[i]]$name. Whenpresent, specifies the name of the\(i\)-th OR generalconstraint.

genconnorm (optional)

A list of lists. When present, each entry ingenconnorm defines aNORM general constraint of the form

\[x[\mathrm{resvar}] = \mathrm{norm}(x[i]:i\in\mathrm{vars}, \mathrm{which})\]

Each entry may have the following named components:

resvar

Specified viamodel$genconnorm[[i]]$resvar.Index of the variable in the left-hand side of the constraint.

vars

Specified viamodel$genconnorm[[i]]$vars, itis a vector of indices of variables in the right-hand side of theconstraint.

which

Specified viamodel$genconnorm[[i]]$which. Specifieswhich p-norm to use. Possible values are 0, 1, 2 and\(\infty\).

name (optional)

Specified viamodel$genconnorm[[i]]$name. Whenpresent, specifies the name of the\(i\)-th NORM generalconstraint.

genconind (optional)

A list of lists. When present, each entry ingenconind defines anINDICATOR general constraint of the form

\[x[\mathrm{binvar}] = \mathrm{binval}\Rightarrow\sum\left( x[j]\cdot\mathrm{a}[j]\right) \ \mathrm{sense} \ \mathrm{rhs}\]

This constraint states that when the binary variable\(x[\mathrm{binvar}]\) takes the valuebinval then the linearconstraint\(\sum\left(x[\mathrm{vars}[j]]\cdot\mathrm{val}[j]\right) \ \mathrm{sense} \ \mathrm{rhs}\)must hold. Note thatsense is one of=,<, or> forequality (\(=\)), less than or equal (\(\leq\)) or greaterthan or equal (\(\geq\)) constraints. Each entry may have thefollowing named components:

binvar

Specified viamodel$genconind[[i]]$binvar.Index of the implicating binary variable.

binval

Specified viamodel$genconind[[i]]$binval.Value for the binary variable that forces the following linearconstraint to be satisfied. It can be either 0 or 1.

a

Specified viamodel$genconind[[i]]$a.Vector of coefficients of variables participating in the impliedlinear constraint. You can specify a value fora for eachcolumn ofA (dense vector) or pass a sparse vector (should bebuilt usingsparseVector from theMatrix package).

sense

Specified viamodel$genconind[[i]]$sense.Sense of the implied linear constraint. Must be one of=,<, or>.

rhs

Specified viamodel$genconind[[i]]$rhs.Right-hand side value of the implied linear constraint.

name (optional)

Specified viamodel$genconind[[i]]$name. Whenpresent, specifies the name of the\(i\)-th INDICATOR generalconstraint.

genconpwl (optional)

A list of lists. When present, each entry ingenconpwl defines apiecewise-linear constraint of the form

\[x[\mathrm{yvar}] = f(x[\mathrm{xvar}])\]

The breakpoints for\(f\) are provided as arguments. Refer to thedescription ofpiecewise-linear objectives fordetails of how piecewise-linear functions are defined

Each entry may have the following named components:

xvar

Specified viamodel$genconpwl[[i]]$xvar. Indexof the variable in the right-hand side of the constraint.

yvar

Specified viamodel$genconpwl[[i]]$yvar. Indexof the variable in the left-hand side of the constraint.

xpts

Specified viamodel$genconpwl[[i]]$xpts.Specifies the\(x\) values for the points that define thepiecewise-linear function. Must be in non-decreasing order.

ypts

Specified viamodel$genconpwl[[i]]$ypts.Specifies the\(y\) values for the points that define thepiecewise-linear function.

name (optional)

Specified viamodel$genconpwl[[i]]$name. Whenpresent, specifies the name of the\(i\)-thpiecewise-linear general constraint.

genconpoly (optional)

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

A list of lists. When present, each entry ingenconpoly defines apolynomial function constraint of the form

\[x[\mathrm{yvar}] = p_0 x[\mathrm{xvar}]^d + p_1 x[\mathrm{xvar}]^{d-1} + ... + p_{d-1} x[\mathrm{xvar}] + p_{d}\]

A piecewise-linear approximation of the functionis added to the model. The details of the approximation are controlledusing the following four attributes (or using the parameters with thesame names):FuncPieces,FuncPieceError,FuncPieceLength, andFuncPieceRatio.Alternatively, the function can be treated as a nonlinear constraint bysetting the attributeFuncNonlinear. For details, consult theGeneral Constraintdiscussion.

Each entry may have the following named components:

xvar

Specified viamodel$genconpoly[[i]]$xvar.Index of the variable in the right-hand side of the constraint.

yvar

Specified viamodel$genconpoly[[i]]$yvar.Index of the variable in the left-hand side of the constraint.

p

Specified viamodel$genconpoly[[i]]$p.Specifies the coefficients for the polynomial function (startingwith the coefficient for the highest power). If\(x^d\) is thehighest power term, a dense vector of length\(d+1\) isreturned.

name (optional)

Specified viamodel$genconpoly[[i]]$name. Whenpresent, specifies the name of the\(i\)-thpolynomial function constraint.

funcpieces (optional)

Specified viamodel$genconpoly[[i]]$funcpieces.When present, specifies theFuncPieces attribute of the\(i\)-th polynomial function constraint.

funcpiecelength (optional)

Specified viamodel$genconpoly[[i]]$funcpiecelength.When present, specifies theFuncPieceLength attributeof the\(i\)-th polynomial function constraint.

funcpieceerror (optional)

Specified viamodel$genconpoly[[i]]$funcpieceerror.When present, specifies theFuncPieceError attribute ofthe\(i\)-th polynomial function constraint.

funcpieceratio (optional)

Specified viamodel$genconpoly[[i]]$funcpieceratio.When present, specifies theFuncPieceRatio attribute ofthe\(i\)-th polynomial function constraint.

funcnonlinear (optional)

Specified viamodel$genconpoly[[i]]$funcnonlinear.When present, specifies theFuncNonlinear attribute ofthe\(i\)-th polynomial function constraint.

genconexp (optional)

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

A list of lists. When present, each entry ingenconexp definesthe natural exponential function constraint of the form

\[x[\mathrm{yvar}] = \mathrm{exp}(x[\mathrm{xvar}])\]

A piecewise-linear approximation of the functionis added to the model. The details of the approximation are controlledusing the following four attributes (or using the parameters with thesame names):FuncPieces,FuncPieceError,FuncPieceLength, andFuncPieceRatio.Alternatively, the function can be treated as a nonlinear constraint bysetting the attributeFuncNonlinear. For details, consult theGeneral Constraintdiscussion.

Each entry may have the following named components:

xvar

Specified viamodel$genconexp[[i]]$xvar. Indexof the variable in the right-hand side of the constraint.

yvar

Specified viamodel$genconexp[[i]]$yvar. Indexof the variable in the left-hand side of the constraint.

name (optional)

Specified viamodel$genconexp[[i]]$name. Whenpresent, specifies the name of the\(i\)-th naturalexponential function constraint.

funcpieces (optional)

Specified viamodel$genconexp[[i]]$funcpieces.When present, specifies theFuncPieces attribute of the\(i\)-th natural exponential function constraint.

funcpiecelength (optional)

Specified viamodel$genconexp[[i]]$funcpiecelength.When present, specifies theFuncPieceLength attributeof the\(i\)-th natural exponential function constraint.

funcpieceerror (optional)

Specified viamodel$genconexp[[i]]$funcpieceerror.When present, specifies theFuncPieceError attribute ofthe\(i\)-th natural exponential function constraint.

funcpieceratio (optional)

Specified viamodel$genconexp[[i]]$funcpieceratio.When present, specifies theFuncPieceRatio attribute ofthe\(i\)-th natural exponential function constraint.

funcnonlinear (optional)

Specified viamodel$genconexp[[i]]$funcnonlinear.When present, specifies theFuncNonlinear attribute ofthe\(i\)-th natural exponential function constraint.

genconexpa (optional)

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

A list of lists. When present, each entry ingenconexpa definesan exponential function constraint of the form

\[x[\mathrm{yvar}] = \mathrm{a}^{x[\mathrm{xvar}]}\]

A piecewise-linear approximation of the functionis added to the model. The details of the approximation are controlledusing the following four attributes (or using the parameters with thesame names):FuncPieces,FuncPieceError,FuncPieceLength, andFuncPieceRatio.Alternatively, the function can be treated as a nonlinear constraint bysetting the attributeFuncNonlinear. For details, consult theGeneral Constraintdiscussion.

Each entry may have the following named components:

xvar

Specified viamodel$genconexpa[[i]]$xvar.Index of the variable in the right-hand side of the constraint.

yvar

Specified viamodel$genconexpa[[i]]$yvar.Index of the variable in the left-hand side of the constraint.

a

Specified viamodel$genconexpa[[i]]$a.Specifies the base of the exponential function\(a > 0\).

name (optional)

Specified viamodel$genconexpa[[i]]$name. Whenpresent, specifies the name of the\(i\)-thexponential function constraint.

funcpieces (optional)

Specified viamodel$genconexpa[[i]]$funcpieces.When present, specifies theFuncPieces attribute of the\(i\)-th exponential function constraint.

funcpiecelength (optional)

Specified viamodel$genconexpa[[i]]$funcpiecelength.When present, specifies theFuncPieceLength attributeof the\(i\)-th exponential function constraint.

funcpieceerror (optional)

Specified viamodel$genconexpa[[i]]$funcpieceerror.When present, specifies theFuncPieceError attribute ofthe\(i\)-th exponential function constraint.

funcpieceratio (optional)

Specified viamodel$genconexpa[[i]]$funcpieceratio.When present, specifies theFuncPieceRatio attribute ofthe\(i\)-th exponential function constraint.

funcnonlinear (optional)

Specified viamodel$genconexpa[[i]]$funcnonlinear.When present, specifies theFuncNonlinear attribute ofthe\(i\)-th exponential function constraint.

genconlog (optional)

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

A list of lists. When present, each entry ingenconlog definesthe natural logarithmic function constraint of the form

\[x[\mathrm{yvar}] = \mathrm{log}(x[\mathrm{xvar}])\]

A piecewise-linear approximation of the functionis added to the model. The details of the approximation are controlledusing the following four attributes (or using the parameters with thesame names):FuncPieces,FuncPieceError,FuncPieceLength, andFuncPieceRatio.Alternatively, the function can be treated as a nonlinear constraint bysetting the attributeFuncNonlinear. For details, consult theGeneral Constraintdiscussion.

Each entry may have the following named components:

xvar

Specified viamodel$genconlog[[i]]$xvar. Indexof the variable in the right-hand side of the constraint.

yvar

Specified viamodel$genconlog[[i]]$yvar. Indexof the variable in the left-hand side of the constraint.

name (optional)

Specified viamodel$genconlog[[i]]$name. Whenpresent, specifies the name of the\(i\)-th naturallogarithmic function constraint.

funcpieces (optional)

Specified viamodel$genconlog[[i]]$funcpieces.When present, specifies theFuncPieces attribute of the\(i\)-th natural logarithmic function constraint.

funcpiecelength (optional)

Specified viamodel$genconlog[[i]]$funcpiecelength.When present, specifies theFuncPieceLength attributeof the\(i\)-th natural logarithmic function constraint.

funcpieceerror (optional)

Specified viamodel$genconlog[[i]]$funcpieceerror.When present, specifies theFuncPieceError attribute ofthe\(i\)-th natural logarithmic function constraint.

funcpieceratio (optional)

Specified viamodel$genconlog[[i]]$funcpieceratio.When present, specifies theFuncPieceRatio attribute ofthe\(i\)-th natural logarithmic function constraint.

funcnonlinear (optional)

Specified viamodel$genconlog[[i]]$funcnonlinear.When present, specifies theFuncNonlinear attribute ofthe\(i\)-th natural logarithmic function constraint.

genconloga (optional)

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

A list of lists. When present, each entry ingenconloga defines alogarithmic function constraint of the form

\[x[\mathrm{yvar}] = \mathrm{log}(x[\mathrm{xvar}])\setminus\mathrm{log}(a)\]

A piecewise-linear approximation of the functionis added to the model. The details of the approximation are controlledusing the following four attributes (or using the parameters with thesame names):FuncPieces,FuncPieceError,FuncPieceLength, andFuncPieceRatio.Alternatively, the function can be treated as a nonlinear constraint bysetting the attributeFuncNonlinear. For details, consult theGeneral Constraintdiscussion.

Each entry may have the following named components:

xvar

Specified viamodel$genconloga[[i]]$xvar.Index of the variable in the right-hand side of the constraint.

yvar

Specified viamodel$genconloga[[i]]$yvar.Index of the variable in the left-hand side of the constraint.

a

Specified viamodel$genconloga[[i]]$a.Specifies the base of the logarithmic function\(a > 0\).

name (optional)

Specified viamodel$genconloga[[i]]$name. Whenpresent, specifies the name of the\(i\)-thlogarithmic function constraint.

funcpieces (optional)

Specified viamodel$genconloga[[i]]$funcpieces.When present, specifies theFuncPieces attribute of the\(i\)-th logarithmic function constraint.

funcpiecelength (optional)

Specified viamodel$genconloga[[i]]$funcpiecelength.When present, specifies theFuncPieceLength attributeof the\(i\)-th logarithmic function constraint.

funcpieceerror (optional)

Specified viamodel$genconloga[[i]]$funcpieceerror.When present, specifies theFuncPieceError attribute ofthe\(i\)-th logarithmic function constraint.

funcpieceratio (optional)

Specified viamodel$genconloga[[i]]$funcpieceratio.When present, specifies theFuncPieceRatio attribute ofthe\(i\)-th logarithmic function constraint.

funcnonlinear (optional)

Specified viamodel$genconloga[[i]]$funcnonlinear.When present, specifies theFuncNonlinear attribute ofthe\(i\)-th logarithmic function constraint.

genconlogistic (optional)

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

A list of lists. When present, each entry ingenconlog definesthe logistic function constraint of the form

\[x[\mathrm{yvar}] = 1 / (1 + \mathrm{exp}(-x[\mathrm{xvar}]))\]

A piecewise-linear approximation of the functionis added to the model. The details of the approximation are controlledusing the following four attributes (or using the parameters with thesame names):FuncPieces,FuncPieceError,FuncPieceLength, andFuncPieceRatio.Alternatively, the function can be treated as a nonlinear constraint bysetting the attributeFuncNonlinear. For details, consult theGeneral Constraintdiscussion.

Each entry may have the following named components:

xvar

Specified viamodel$genconlogistic[[i]]$xvar.Index of the variable in the right-hand side of the constraint.

yvar

Specified viamodel$genconlogistic[[i]]$yvar.Index of the variable in the left-hand side of the constraint.

name (optional)

Specified viamodel$genconlogistic[[i]]$name.When present, specifies the name of the\(i\)-thlogistic function constraint.

funcpieces (optional)

Specified viamodel$genconlogistic[[i]]$funcpieces.When present, specifies theFuncPieces attribute of the\(i\)-th logistic function constraint.

funcpiecelength (optional)

Specified viamodel$genconlogistic[[i]]$funcpiecelength.When present, specifies theFuncPieceLength attributeof the\(i\)-th logistic function constraint.

funcpieceerror (optional)

Specified viamodel$genconlogistic[[i]]$funcpieceerror.When present, specifies theFuncPieceError attribute ofthe\(i\)-th logistic function constraint.

funcpieceratio (optional)

Specified viamodel$genconlogistic[[i]]$funcpieceratio.When present, specifies theFuncPieceRatio attribute ofthe\(i\)-th logistic function constraint.

funcnonlinear (optional)

Specified viamodel$genconlogistic[[i]]$funcnonlinear.When present, specifies theFuncNonlinear attribute ofthe\(i\)-th logistic function constraint.

genconpow (optional)

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

A list of lists. When present, each entry ingenconpow defines apower function constraint of the form

\[x[\mathrm{yvar}] = x[\mathrm{xvar}]^\mathrm{a}\]

A piecewise-linear approximation of the functionis added to the model. The details of the approximation are controlledusing the following four attributes (or using the parameters with thesame names):FuncPieces,FuncPieceError,FuncPieceLength, andFuncPieceRatio.Alternatively, the function can be treated as a nonlinear constraint bysetting the attributeFuncNonlinear. For details, consult theGeneral Constraintdiscussion.

Each entry may have the following named components:

xvar

Specified viamodel$genconpow[[i]]$xvar. Indexof the variable in the right-hand side of the constraint.

yvar

Specified viamodel$genconpow[[i]]$yvar. Indexof the variable in the left-hand side of the constraint.

a

Specified viamodel$genconpow[[i]]$a.Specifies the exponent of the power function.

name (optional)

Specified viamodel$genconpow[[i]]$name. Whenpresent, specifies the name of the\(i\)-th power functionconstraint.

funcpieces (optional)

Specified viamodel$genconpow[[i]]$funcpieces.When present, specifies theFuncPieces attribute of the\(i\)-th power function constraint.

funcpiecelength (optional)

Specified viamodel$genconpow[[i]]$funcpiecelength.When present, specifies theFuncPieceLength attributeof the\(i\)-th power function constraint.

funcpieceerror (optional)

Specified viamodel$genconpow[[i]]$funcpieceerror.When present, specifies theFuncPieceError attribute ofthe\(i\)-th power function constraint.

funcpieceratio (optional)

Specified viamodel$genconpow[[i]]$funcpieceratio.When present, specifies theFuncPieceRatio attribute ofthe\(i\)-th power function constraint.

funcnonlinear (optional)

Specified viamodel$genconpow[[i]]$funcnonlinear.When present, specifies theFuncNonlinear attribute ofthe\(i\)-th power function constraint.

genconsin (optional)

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

A list of lists. When present, each entry ingenconsin definesthe sine function constraint of the form

\[x[\mathrm{yvar}] = \mathrm{sin}(x[\mathrm{xvar}])\]

A piecewise-linear approximation of the functionis added to the model. The details of the approximation are controlledusing the following four attributes (or using the parameters with thesame names):FuncPieces,FuncPieceError,FuncPieceLength, andFuncPieceRatio.Alternatively, the function can be treated as a nonlinear constraint bysetting the attributeFuncNonlinear. For details, consult theGeneral Constraintdiscussion.

Each entry may have the following named components:

xvar

Specified viamodel$genconsin[[i]]$xvar. Indexof the variable in the right-hand side of the constraint.

yvar

Specified viamodel$genconsin[[i]]$yvar. Indexof the variable in the left-hand side of the constraint.

name (optional)

Specified viamodel$genconsin[[i]]$name. Whenpresent, specifies the name of the\(i\)-th sine functionconstraint.

funcpieces (optional)

Specified viamodel$genconsin[[i]]$funcpieces.When present, specifies theFuncPieces attribute of the\(i\)-th sine function constraint.

funcpiecelength (optional)

Specified viamodel$genconsin[[i]]$funcpiecelength.When present, specifies theFuncPieceLength attributeof the\(i\)-th sine function constraint.

funcpieceerror (optional)

Specified viamodel$genconsin[[i]]$funcpieceerror.When present, specifies theFuncPieceError attribute ofthe\(i\)-th sine function constraint.

funcpieceratio (optional)

Specified viamodel$genconsin[[i]]$funcpieceratio.When present, specifies theFuncPieceRatio attribute ofthe\(i\)-th sine function constraint.

funcnonlinear (optional)

Specified viamodel$genconsin[[i]]$funcnonlinear.When present, specifies theFuncNonlinear attribute ofthe\(i\)-th sine function constraint.

genconcos (optional)

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

A list of lists. When present, each entry ingenconcos definesthe cosine function constraint of the form

\[x[\mathrm{yvar}] = \mathrm{cos}(x[\mathrm{xvar}])\]

A piecewise-linear approximation of the functionis added to the model. The details of the approximation are controlledusing the following four attributes (or using the parameters with thesame names):FuncPieces,FuncPieceError,FuncPieceLength, andFuncPieceRatio.Alternatively, the function can be treated as a nonlinear constraint bysetting the attributeFuncNonlinear. For details, consult theGeneral Constraintdiscussion.

Each entry may have the following named components:

xvar

Specified viamodel$genconcos[[i]]$xvar. Indexof the variable in the right-hand side of the constraint.

yvar

Specified viamodel$genconcos[[i]]$yvar. Indexof the variable in the left-hand side of the constraint.

name (optional)

Specified viamodel$genconcos[[i]]$name. Whenpresent, specifies the name of the\(i\)-th cosine functionconstraint.

funcpieces (optional)

Specified viamodel$genconcos[[i]]$funcpieces.When present, specifies theFuncPieces attribute of the\(i\)-th cosine function constraint.

funcpiecelength (optional)

Specified viamodel$genconcos[[i]]$funcpiecelength.When present, specifies theFuncPieceLength attributeof the\(i\)-th cosine function constraint.

funcpieceerror (optional)

Specified viamodel$genconcos[[i]]$funcpieceerror.When present, specifies theFuncPieceError attribute ofthe\(i\)-th cosine function constraint.

funcpieceratio (optional)

Specified viamodel$genconcos[[i]]$funcpieceratio.When present, specifies theFuncPieceRatio attribute ofthe\(i\)-th cosine function constraint.

funcnonlinear (optional)

Specified viamodel$genconcos[[i]]$funcnonlinear.When present, specifies theFuncNonlinear attribute ofthe\(i\)-th cosine function constraint.

gencontan (optional)

Deprecated since version 13.0:Usingfunction constraints is deprecated since version 13.0.Please usenonlinear constraints instead.

A list of lists. When present, each entry ingencontan definesthe tangent function constraint of the form

\[x[\mathrm{yvar}] = \mathrm{tan}(x[\mathrm{xvar}])\]

A piecewise-linear approximation of the functionis added to the model. The details of the approximation are controlledusing the following four attributes (or using the parameters with thesame names):FuncPieces,FuncPieceError,FuncPieceLength, andFuncPieceRatio.Alternatively, the function can be treated as a nonlinear constraint bysetting the attributeFuncNonlinear. For details, consult theGeneral Constraintdiscussion.

Each entry may have the following named components:

xvar

Specified viamodel$gencontan[[i]]$xvar. Indexof the variable in the right-hand side of the constraint.

yvar

Specified viamodel$gencontan[[i]]$yvar. Indexof the variable in the left-hand side of the constraint.

name (optional)

Specified viamodel$gencontan[[i]]$name. Whenpresent, specifies the name of the\(i\)-th tangent functionconstraint.

funcpieces (optional)

Specified viamodel$gencontan[[i]]$funcpieces.When present, specifies theFuncPieces attribute of the\(i\)-th tangent function constraint.

funcpiecelength (optional)

Specified viamodel$gencontan[[i]]$funcpiecelength.When present, specifies theFuncPieceLength attributeof the\(i\)-th tangent function constraint.

funcpieceerror (optional)

Specified viamodel$gencontan[[i]]$funcpieceerror.When present, specifies theFuncPieceError attribute ofthe\(i\)-th tangent function constraint.

funcpieceratio (optional)

Specified viamodel$gencontan[[i]]$funcpieceratio.When present, specifies theFuncPieceRatio attribute ofthe\(i\)-th tangent function constraint.

funcnonlinear (optional)

Specified viamodel$gencontan[[i]]$funcnonlinear.When present, specifies theFuncNonlinear attribute ofthe\(i\)-th tangent function constraint.

Advanced named components#

pwlobj (optional)

The piecewise-linear objective functions. A list of lists. Whenpresent, each entry inpwlobj defines a piecewise-linearobjective function for a single variable. The index of the variablewhose objective function is being defined is stored inmodel$pwlobj[[i]]$var. The\(x\)values for the points that define the piecewise-linear function arestored inmodel$pwlobj[[i]]$x. The values in the\(x\) vector must be in non-decreasing order. The\(y\)values for the points that define the piecewise-linear function arestored inmodel$pwlobj[[i]]$y.

vbasis (optional)

The variable basis status vector. Used to provide an advancedstarting point for the simplex algorithm. You would generally neverconcern yourself with the contents of this vector, but would insteadsimply pass it from the result of a previous optimization run to theinput of a subsequent run. When present, you must specify one valuefor each column ofA.

cbasis (optional)

The constraint basis status vector. Used to provide an advancedstarting point for the simplex algorithm. Consult thevbasisdescription for details. When present, you must specify one value foreach row ofA.

varhintval (optional)

A set of user hints. If you know that a variable is likely to take aparticular value in high quality solutions of a MIP model, you canprovide that value as a hint. You can also (optionally) provideinformation about your level of confidence in a hint with thevarhintpri named component. If present, you must specify onevalue for each column ofA. Use a value ofNA for variableswhere no such hint is known. For more details, please refer to theAttribute section in the reference manual.

varhintpri (optional)

Priorities on user hints. After providing variable hints through thevarhintval list, you can optionally also provide hint prioritiesto give an indication of your level of confidence in your hints. Ifpresent, you must specify a value for each column ofA. For moredetails, please refer to theAttribute section in the reference manual.

branchpriority (optional)

Variable branching priority. If present, the value of this attributeis used as the primary criteria for selecting a fractional variablefor branching during the MIP search. Variables with larger valuesalways take priority over those with smaller values. Ties are brokenusing the standard branch variable selection criteria. If present,you must specify one value for each column ofA.

pstart (optional)

The current simplex start vector. If you setpstart values forevery variable in the model anddstart values for everyconstraint, then simplex will use those values to compute a warmstart basis. For more details, please refer to theAttribute section in the reference manual.

dstart (optional)

The current simplex start vector. If you setdstart values forevery linear constraint in the model andpstart values for everyvariable, then simplex will use those values to compute a warm startbasis. For more details, please refer to theAttribute section in the reference manual.

lazy (optional)

Determines whether a linear constraint is treated as alazyconstraint. If present, you must specify one value for each row ofA. For more details, please refer to theAttribute section in the reference manual.

start (optional)

The MIP start vector. The MIP solver will attempt to build an initialsolution from this vector. When present, you must specify a startvalue for each variable. Note that you can set the start value for avariable toNA, which instructs the MIP solver to try to fill ina value for that variable.

partition (optional)

The MIP variable partition number, which is used by the MIP solutionimprovement heuristic. If present, you must specify one value foreach variable ofA. For more details, please refer to theAttribute section in the reference manual.

If any of the mandatory components listed above are missing, thegurobi() function will return an error.

Below is an example that demonstrates the construction of a simpleoptimization 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 buildA as a sparse matrix, using eithersparseMatrixorsimple_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 valuefor most of the array-valued components. The specified value will beexpanded to an array of the appropriate size, with each component of thearray equal to the scalar (e.g.,model$obj<-1 would beequivalent tomodel$obj<-c(1,1,1) in the example).

The params argument#

As mentioned previously, the Gurobi Optimizer provides a set ofparameters that allow you to control many of the details of theoptimization process. Factors like feasibility and optimalitytolerances, choices of algorithms, strategies for exploring the MIPsearch tree, etc., can be controlled by modifying Gurobi parametersbefore beginning the optimization.

Parameter changes are specified using alist variable havingmultiplenamedcomponents, which is passed as an argument to theappropriate Gurobi function (e.g.,gurobi). The name of eachnamed component must be the name of a Gurobi parameter, and theassociated value should be the desired value of that parameter. You canfind a complete list of the available Gurobi parameters in thereference manual.

To create a list that would set the GurobiMethod parameter to 2 and theResultFile parameter tomodel.mps,you would do the following:

paramsparams$Method<-2params$ResultFile<-'model.mps'

We should say a bit more about theResultFile parameter.If this parameter is set, the optimization model that is eventuallypassed to Gurobi will also be output to the specified file. The filenamesuffix should be one of.mps,.rew,.lp,.rlp,.dua,.dlp,.ilp, or.opb, to indicate the desired fileformat (see thefile format section in thereference manual for details on Gurobi file formats).

The params struct can also be used to set license specific parameters,that define the computational environment to be used. We will discussthe two most common use cases next, and refer again to the collection ofall available parameters in thereference manual.

Using a Compute Server License#

Gurobi Compute Server allows you to offload optimization jobs to aremote server. Servers are organized into clusters. By providing thename of any node within the cluster, your job will automatically be sentto the least heavily loaded node in the cluster. If all nodes are atcapacity, your job will be placed in a queue, and will proceed oncecapacity becomes available. You can find additional information aboutGurobi Compute Server in theGurobi Remote Services Reference Manual.The most commonly used parameters are the following.

ComputeServer

A Compute Server. You can refer to the server using its name or itsIP address. If you are using a non-default port, the server nameshould be followed by the port number (e.g.,server1:61000).

ServerPassword (optional)

User password on the Compute Server cluster. Obtain this from yourCompute Server administrator.

CSPriority (optional)

The priority of the job. Priorities must be between -100 and 100,with a default value of 0 (by convention). Higher priority jobs arechosen from the server job queue before lower priority jobs. A jobwith priority 100 runs immediately, bypassing the job queue andignoring the job limit on the server. You should exercise cautionwith priority 100 jobs, since they can severely overload a server,which can cause jobs to fail, and in extreme cases can cause theserver to crash.

CSRouter (optional)

The router for the Compute Server cluster. A router can be used toimprove the robustness of a Compute Server deployment. You can referto the router using either its name or its IP address. A typicalRemote Services deployment won’t use a router, so you typically won’tneed to set this.

CSTLSinsecure (optional)

Indicates whether to use insecure mode in the TLS (Transport LayerSecurity). Leave this at its default value of 0 unless your serveradministrator tells you otherwise.

Here is an example of how to use aparams argument to connect to aCompute Server:

paramsparams$ComputeServer<-'server1.mycompany.com:61000'params$CSPriority<-5

Using a Gurobi Instant Cloud License#

Gurobi Instant Cloud allows you to offload optimization jobs to a GurobiCompute Server on the cloud. If an appropriate machine is alreadyrunning, the job will run on that machine. It will automatically launcha new machine otherwise. Note that launching a new machine can take afew minutes. You can find additional information about the GurobiInstant Cloud service in thereference manual. Themost commonly used parameters are the following.

CloudAccessID

The access ID for your Gurobi Instant Cloud license. This can beretrieved from the Gurobi Instant Cloud website. When used incombination with yourCloudSecretKey, this allows you to launchInstant Cloud instances and submit jobs to them.

CloudSecretKey

The secret key for your Gurobi Instant Cloud license. This can beretrieved from the Gurobi Instant Cloud website. When used incombination with yourCloudAccessID, this allows you to launchInstant Cloud instances and submit jobs to them. Note that you shouldkeep your secret key private.

CloudPool (optional)

The machine pool. Machine pools allow you to create fixedconfigurations on the Instant Cloud website (capturing things liketype of machine, geographic region, etc.), and then launch and sharemachines from client programs without having to restate configurationinformation each time you launch a machine. If not provided, your jobwill be launched in the default pool associated with your cloudlicense.

CSPriority (optional)

The priority of the job. Priorities must be between -100 and 100,with a default value of 0 (by convention). Higher priority jobs arechosen from the server job queue before lower priority jobs. A jobwith priority 100 runs immediately, bypassing the job queue andignoring the job limit on the server. You should exercise cautionwith priority 100 jobs, since they can severely overload a server,which can cause jobs to fail, and in extreme cases can cause theserver to crash.

Here is an example of how to use aparams argument to launch a GurobiInstant Cloud instance:

paramsparams$CloudAccessID<-'3d1ecef9-dfad-eff4-b3fa'params$CloudSecretKey<-'ae6L23alJe3+fas'

Help and Feedback

On this page

[8]ページ先頭

©2009-2025 Movatter.jp