我使用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 Optimization Studio中:
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,所以任何低于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();“,它将所有内容转换为doubles。我从示例代码中提取并删除了它,现在一切正常。
发布于 2015-04-09 14:06:50
你的模型在某些方面会有所不同。我怀疑整数变量可能被处理的方式-值125是一个相当舍入的数字,而117.2显然不是整数,日志显示它是作为一个直接的LP来解决的。
查看两个模型的解决方案中变量的值,找出值的不同之处。希望两个解决方案中的许多变量值都是相似的,这将有助于缩小搜索范围。
尝试将模型导出为LP文件或两者中的类似文件,并比较生成的模型。也许可以在CPLEX命令行求解器中求解两个导出的模型,并比较日志和结果。
尝试在另一个模型中修复一个解决方案中的一些值,然后重新求解。
另外,给我们提供更多来自OPL模型的日志输出。
https://stackoverflow.com/questions/29516645
复制相似问题