我目前正在使用 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
库的代码可以编译,但我不确定它是否可以运行,因为我无法导入模型,我无法尝试解决一个模型.
我使用的是 Windows,以管理员身份启动 IDE 没有任何效果,并且文件不会被阻止读取(或写入)。
在官方支持页面中,我发现了有关错误的信息:http://www-eio.upc.es/lceio/manuals/cplex-11/html/refcallablelibrary/html/macros/CPXERR_FAIL_OPEN_READ.html
但是我找不到任何有用的东西。
另外,IBM 论坛目前已关闭,似乎没有人遇到过此类问题:(
有谁知道可能出什么问题吗?我能做些什么?你知道还有其他选择吗?
感谢任何来访的人!!
最佳答案
异常消息显示:
ilog.cplex.CpxException: CPLEX Error 1423: Could not open file 'models\20_70_45_05_100.mps' for reading.
尝试使用绝对路径,例如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);
关于java - 无法将模型从 MPS 文件导入到 IloCplex - IBM ILOG CPLEX - Java - Intellij,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60681862/