R API概述

R API概述

本节文档了Gurobi R接口。对于那些不熟悉R的人来说,它是统计计算的自由语言。请访问R网站for more information. This manual begins with a quick overview of the methods provided by our R API. It then continues with acomprehensive presentation所有可用的方法,他们的参数和返回值。

If you are new to the Gurobi Optimizer, we suggest that you start with the快速入门指南或者示例之旅。这些文件提供了如何使用此处描述的方法的具体示例。

A quick note for new users: the convention in math programming is that variables are non-negative unless specified otherwise. You'll need to explicitly set lower bounds if you want variables to be able to take negative values.

楷模

我们的Gurobi R接口使您可以表达以下表格的问题:

minimize <span>$</span>x^TQx + c^Tx + \mathrm{alpha}<span>$</span>
subject to <span>$</span>Ax = b<span>$</span> (线性约束)
<span> $ </ span> \ ell \ le x \ le u <span> $ </ span> (bound constraints)
some<span>$</span>x_j<span>$</span>integral (完整性约束)
<span> $ </ span> x ^ tqc x + q ^ tx \ le \ mathrm {beta} <span> $ </ span> (quadratic constraints)
some<span>$</span>x_i<span>$</span>in SOS (special ordered set constraints)
min,max,abs,或... (一般约束)



模型存储为listvariables, each consisting of multiple命名组件。The named components capture the different model components listed above. Many of these model components are optional. For example, integrality constraints may be omitted.

可以从文件加载优化模型(使用gurobi_read.函数),或者可以通过填充模型变量的适当命名组件(使用标准R构造)来构建。我们将讨论如何在模型中表示的细节模型论点部分。

我们经常参考class优化模型。具有线性目标函数,线性约束和连续变量的模型是一个Linear Program (LP)。如果目标是二次,则该模型是一个二次程序(QP)。If any of the constraints are quadratic, the model is a二次约束程​​序(QCP)。We'll sometimes also discuss a special case of QCP, the二阶锥计划(SOCP)。If the model contains any integer variables, semi-continuous variables, semi-integer variables, Special Ordered Set (SOS) constraints, or general constraints, the model is aMixed Integer Program (MIP)。We'll also sometimes discuss special cases of MIP, including混合整数线性规划(MILP),Mixed Integer Quadratic Programs (MIQP),混合整数二次约束程​​序(MIQCP), 和Mixed Integer Second-Order Cone Programs (MISOCP)。The Gurobi Optimizer handles all of these model classes.

Solving a Model

Once you have built a model, you can callGurobi.计算解决方案。默认,Gurobi.will use the并发优化器要解决LP模型,屏障算法解决QP和QCP型号,以及分支算法解决混合整数型号。解决方案作为a返回list多变的。我们将讨论如何在我们讨论的情况下代表优化结果的详细信息Gurobi.function.

以下是R API中可能的命令序列的一个简单示例:
模型<- gurobi_read('examples/data/stein9.mps')
结果< - gurobi(型号)

Multiple Solutions and Multiple Objectives

默认情况下,Gurobi Optimizer假定您的目标是找到一个具有单个目标函数的模型的证明最佳解决方案。Gurobi提供了允许您放宽其中任何一个假设的功能。您应该参考该部分解决方案池有关如何要求多个解决方案的信息,或部分Multiple Objectives有关如何指定多个目标函数并控制它们之间的权衡的信息。

Infeasible Models

You have a few options if a model is found to be infeasible. You can try to diagnose the cause of the infeasibility, attempt to repair the infeasibility, or both. To obtain information that can be useful for diagnosing the cause of an infeasibility, callGurobi._iisto compute an Irreducible Inconsistent Subsystem (IIS). This method can be used for both continuous and MIP models, but you should be aware that the MIP version can be quite expensive. We will discuss the details of how IIS results are represented in theGurobi._iis功能文档。manbet体育手机客户端

To attempt to repair an infeasibility, callgurobi_feasrelax.to compute a feasibility relaxation for the model. This relaxation allows you to find a solution that minimizes the magnitude of the constraint violation.

Managing Parameters

Gurobi Optimizer提供了一组参数,允许您控制优化过程的许多细节。可以通过修改Gurobi参数在开始优化之前来控制可行性和最优性公差等因素,算法,探索MIP搜索树等的策略。

每个Gurobi参数都有一个默认值。所需的参数更改通过了list多变的。The name of each named component within this list must be the name of a Gurobi parameter, and the associated value should be the desired value of that parameter. You can find a complete list of the available Gurobi parameters这里。We will provide additional details on changing parameter settings in the参数论点部分。

监测进展

可以通过Gurobi Logging监控优化的进度。默认情况下,Gurobi将向屏幕发送输出。一些简单的控件可用于修改默认日志记录行为。如果您想将输出直接输出到文件以及屏幕,请设置logfile.parameter to the name of your desired log file. The frequency of logging output can be controlled with theDisplayInterval参数,可以完全关闭OutputFlagparameter. A detailed description of the Gurobi log file can be found in theLogging部分。

Error Handling

If unsuccessful, the methods of the Gurobi R interface will return an error code and an error message. A list of possible error codes can be found in the错误代码部分。

环境

默认情况下,各种Gurobi函数将查找有效的许可证文件并创建本地Gurobi环境。只要相应的R API函数正在运行,此环境存在,并且在完成后释放。

Another option is to provide an optionalenvargument (also through alist). This argument allows you to solve the given problem on a Gurobi Compute Server or using the Gurobi Instant Cloud. We will discuss this topic further in theenv论点部分。

Gurobi will check the current working directory for a file namedGurobi.。env, 和it will attempt to read parameter settings from this file if it exists. The file should be inPRM格式(简要介绍,每行应包含参数名称,然后包含该参数的所需值)。