0

我目前正在使用这些Ilog Cplex库在 java 中开发一个项目,我正在使用 Intellij-Idea IDE。我在从MPS文件中导入模型时遇到问题,这是给我带来问题的一段代码

IloCplex iloCplexInstance = new IloCplex();
iloCplexInstance.importModel(fileName);

它触发此异常:

ilog.cplex.CpxException: CPLEX Error  1423: Could not open file 'models\20_70_45_05_100.mps' for reading.

at ilog.cplex.CplexI.CALL(CplexI.java:5204)
at ilog.cplex.CplexI._readModel(CplexI.java:5584)
at ilog.cplex.CplexI.importModel(CplexI.java:1032)
at ilog.cplex.IloCplex.importModel(IloCplex.java:902)
at heuristics.ziround.LPUtils.fromMPS(LPUtils.java:34)
at heuristics.test.LPUtilsTestCompile.main(LPUtilsTestCompile.java:13)

我尝试在单元测试中使用junit4,junit.runners.Parameterized和在其主要方法中的一个简单类中运行它。每种情况下的结果相同。我也尝试设置文件的完整路径,它给出了相同的结果。我知道我使用的文件没问题,我可以使用 cplex 终端命令读取它,我也尝试了其他文件。

使用Ilog's 库的代码可以编译,但我不确定它是否可以运行,因为我无法导入我无法尝试解决的模型。

我正在使用 Windows,以管理员身份启动 IDE 没有任何影响,并且文件未被阻止读取(或写入)。

我正在关注 IBM 的文档: https ://www.ibm.com/support/knowledgecenter/SSSA5P_12.7.0/ilog.odms.cplex.help/refjavacplex/html/ilog/cplex/IloCplex.html#importModel(java .lang.String)

在官方支持页面中,我发现了这个错误:http ://www-eio.upc.es/lceio/manuals/cplex-11/html/refcallablelibrary/html/macros/CPXERR_FAIL_OPEN_READ.html

但我找不到任何有用的东西。

此外,IBM 论坛目前已关闭,似乎没有人遇到过这种问题 :(

有谁知道可能是什么问题?我能做些什么?你知道还有其他选择吗?

感谢任何会停下来的人!

4

2 回答 2

1

异常消息说:

ilog.cplex.CpxException:CPLEX 错误 1423:无法打开文件 “models\20_70_45_05_100.mps”进行读取。

尝试使用绝对路径,例如c:\path\to\your\models\20_70_45_05_100.mps.

您还可以向程序中添加代码以确保路径存在。就像是:

import java.nio.file.Files;
...
IloCplex iloCplexInstance = new IloCplex();
if (!Files.exists(fileName))
    throw new AssertionError("path does not exist: " + fileName);
iloCplexInstance.importModel(fileName);
于 2020-03-14T16:49:07.123 回答
0

@rkersh回答之后,我这样做了:

String modelsPath = "absolute\\folder\\path";

Collection<Object[]> models = new ArrayList<>();
File folder = new File(modelsPath);
for (final File fileEntry : Objects.requireNonNull(folder.listFiles())) {
    if (fileEntry.isFile())
        models.add(new String[]{fileEntry.getAbsolutePath()});
}
return models;

这确保绝对路径是正确的,现在iloCplexInstance.importModel(fileName);可以接受它

于 2020-03-16T11:32:23.997 回答