Search code examples
javaintellij-ideacplexwebsphere

Can't import model from MPS file to IloCplex - IBM ILOG CPLEX - Java - Intellij


I'm currently developing a project in java using the Ilog Cplex libraries, I'm using the Intellij-Idea IDE. I'm having troubles importing a model from MPS file, this is the piece of code that gives me problems

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

It fires this exception:

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)

I tried running it in unit tests using junit4, junit.runners.Parameterized, and in a simple class from its main method. Same result in each case. I've also tried to set the full path to the file and it gives the same result. I know that the file I used is ok, I'm able to read it using the cplex terminal commands, I also tried other files.

The code that uses the Ilog's libraries can compile, I'm not sure if it can run though since I'm not able to import a model I can't try to solve one.

I'm using windows, launching the IDE as admin sorts no effects, and the file is not blocked from reading (nor writing).

I'm following the documentation from 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)

In the official support pages, I found this about the error: http://www-eio.upc.es/lceio/manuals/cplex-11/html/refcallablelibrary/html/macros/CPXERR_FAIL_OPEN_READ.html

But I can't find anything useful.

Also, the IBM forum is currently closed and no one seems to have had this kind of problem :(

Does anyone know what could be the trouble? What can I do? Do you know of any other alternative?

Thanks to anyone that will stop by!!


Solution

  • Following @rkersh answer i did this:

    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;
    

    This makes sure that the absolute path is correct and now iloCplexInstance.importModel(fileName); accepts it fine