0

我使用 OPL 在 IBM Optimization Studio 中实现了一个 LP 问题来创建模型。在验证模型后,我想将其放入 Java 中,以便为模拟目的编写参数脚本。我找到了使用以下代码在 Java 中使用我的 OLP 模型的最快方法:

IloOplFactory.setDebugMode(false);
IloOplFactory oplF = new IloOplFactory();
IloOplErrorHandler errHandler = oplF.createOplErrorHandler(System.out);
IloOplModelSource modelSource = oplF.createOplModelSource("myModel.mod");
IloCplex cplex = null;
cplex = oplF.createCplex();
IloOplSettings settings = oplF.createOplSettings(errHandler);
IloOplModelDefinition def = oplF.createOplModelDefinition(modelSource, settings);
IloOplModel opl = oplF.createOplModel(def, cplex);

String inDataFile = "myData.dat";
IloOplDataSource dataSource = oplF.createOplDataSource(inDataFile);
opl.addDataSource(dataSource);

opl.generate();
opl.convertAllIntVars(); // converts integer bounds into LP compatible format
if (cplex.solve()) {
        double obj = opl.getCplex().getObjValue();
        System.out.println("OBJECTIVE: " + obj);
}

现在的问题是,如果我在 IBM Optimization Studio 和 Java 中运行“myModel.mod”和“myData.dat”,我会得到非常不同的客观结果。

在 IBM 优化工作室中:

solution (optimal) with objective 125

在 Java 中:

Parallel mode: deterministic, using up to 4 threads for concurrent optimization.
Tried aggregator 1 time.
LP Presolve eliminated 0 rows and 1 columns.
Reduced LP has 5280 rows, 5325 columns, and 25525 nonzeros.
Presolve time = 0.01 sec. (3.77 ticks)

Iteration log . . .
Iteration:     1   Dual objective     =             0.000000
Iteration:   345   Dual objective     =            90.297455
Iteration:   568   Dual objective     =           117.206047
Perturbation started.
Iteration:   707   Dual objective     =           117.206047
Removing perturbation.
Reinitializing dual norms . . .

Dual simplex solved model.

OBJECTIVE: 117.20608137232513

我查看了数据集和我的模型,甚至不可能达到小于 125 的目标(我使用极值来确保我的目标变量之一是 125,因此低于该值的任何东西都不可能)。

有谁知道为什么这些结果不同?与 IBM 相比,Java 的设置是否可能有所不同?我是否可以将我的 IBM 优化工作室设置导入 Java 来进行测试?

谢谢!

编辑:这里是 IBM Optimization studio 日志,我忘了包括那些。它确实显示了更多关于整数被截断的信息,但这是我对这两个程序的第一次体验,所以有人可以帮我找出问题所在或这一切意味着什么吗?

Found incumbent of value 125.000000 after 0.00 sec. (0.53 ticks)
Tried aggregator 1 time.
MIP Presolve eliminated 5027 rows and 4764 columns.
MIP Presolve modified 1191 coefficients.
Reduced MIP has 253 rows, 562 columns, and 1958 nonzeros.
Reduced MIP has 562 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.02 sec. (8.46 ticks)
Probing fixed 8 vars, tightened 0 bounds.
Probing time = 0.00 sec. (2.86 ticks)
Tried aggregator 1 time.
MIP Presolve eliminated 158 rows and 306 columns.
MIP Presolve modified 293 coefficients.
Reduced MIP has 95 rows, 256 columns, and 632 nonzeros.
Reduced MIP has 256 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.02 sec. (1.73 ticks)
Probing fixed 6 vars, tightened 0 bounds.
Probing time = 0.00 sec. (0.12 ticks)
Tried aggregator 1 time.
MIP Presolve eliminated 29 rows and 30 columns.
MIP Presolve modified 2 coefficients.
Reduced MIP has 66 rows, 226 columns, and 522 nonzeros.
Reduced MIP has 226 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (0.42 ticks)
Probing time = 0.00 sec. (0.07 ticks)
Clique table members: 34.
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: deterministic, using up to 4 threads.
Root relaxation solution time = 0.00 sec. (0.36 ticks)

    Nodes                                         Cuts/
   Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap

*     0+    0                          125.0000      123.0000             1.60%
      0     0      123.8469     4      125.0000      123.8469       62    0.92%
      0     0        cutoff            125.0000                     81    0.00%
Elapsed time = 0.09 sec. (17.09 ticks, tree = 0.00 MB, solutions = 1)

Zero-half cuts applied:  1
Gomory fractional cuts applied:  1

Root node processing (before b&c):
  Real time             =    0.09 sec. (17.22 ticks)
Parallel b&c, 4 threads:
  Real time             =    0.00 sec. (0.00 ticks)
  Sync time (average)   =    0.00 sec.
  Wait time (average)   =    0.00 sec.
                      ------------
Total (root+branch&cut) =    0.09 sec. (17.22 ticks)

编辑 2:我发现我的矩阵 0..1 中的整数值没有被四舍五入为 0 或 1,而是被计为 0.932...如何强制 Java cplex 舍入我的整数?

已解决:它是“opl.convertAllIntVars();” 它将所有内容都转换为双打。我从示例代码中取出并删除了它,现在一切正常。

4

1 回答 1

0

您的模型在某些方面会有所不同。我怀疑可能处理整数变量的方式 - 值 125 是一个整数,而 117.2 显然不是整数,日志显示它正在作为一个直接的 LP 解决。

查看两个模型解决方案中变量的值,找出值不同的地方。希望这两种解决方案中的许多变量值都是相似的,这应该有助于缩小搜索范围。

尝试将您的模型导出为 LP 文件或两者中的类似文件,然后比较生成的模型。也许在 CPLEX 命令行求解器中求解两个导出的模型,并比较日志和结果。

尝试从另一个模型中的一个解决方案中修复一些值并重新解决。

此外,为我们提供更多来自 OPL 模型的日志输出。

于 2015-04-09T06:06:50.343 回答