Saving model in file with high float precision

354 views
Skip to first unread message

paul-emile Morgades

unread,
Sep 21, 2022, 3:34:26 AM9/21/22
to or-tools-discuss

Hello,

My team and I are willing to model LP problem using OR-Tools and then solving them by sending the LP in a file to CPlex or Gurobi. We do not want to directly link CPlex or Gurobi to Or-tools as a third party solver.

For this purpose we have used the .mps file format. Nevertheless, the float number precision seems to only be of 5 numbers. This is not enough for our usecases.

Is there a better suited file format handled by Or-tools? Like the .nl file format?
Is there a way to increase the .mps file format’s precision?

We use Or-Tools via Java.

Here is the way get the .mps:


String solverName = "SCIP";

Loader.loadNativeLibraries();
MPSolver solver = MPSolver.createSolver(solverName);

double infinity = Double.POSITIVE_INFINITY;
MPVariable x = solver.makeIntVar(0.0, infinity, "x");


MPConstraint c0 = solver.makeConstraint(-infinity, 17.5, "c0");
c0.setCoefficient(x, 1);

MPConstraint c1 = solver.makeConstraint(-infinity, 3.5, "c1");
c1.setCoefficient(x, 1.12345678912345);

MPObjective objective = solver.objective();
objective.setCoefficient(x, 1);
objective.setMaximization();

final MPSolver.ResultStatus resultStatus = solver.solve();
String mps_text = solver.exportModelAsMpsFormat();
System.out.println("MPS: " + mps_text);

Here is the output:

MPS: * Generated by MPModelProtoExporter

*   Name             :

*   Format           : Free

*   Constraints      : 2

*   Variables        : 1

*     Binary         : 0

*     Integer        : 1

*     Continuous     : 0

NAME         

OBJSENSE

  MAX

ROWS

 N  COST

 L  c0

 L  c1

COLUMNS

  INTSTART  'MARKER'                            'INTORG'

    x       COST          1  c0            1

    x       c1      1.12346

  INTEND    'MARKER'                            'INTEND'

RHS

    RHS     c0      17.5123  c1          3.5

BOUNDS

 LI BOUND   x             0

ENDATA


Thank you.

Laurent Perron

unread,
Sep 21, 2022, 4:49:53 AM9/21/22
to or-tools-discuss
why don't you solve directly with gurobi ?

Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/d8d66ca6-bb4b-4f67-9b20-7bb7115009a7n%40googlegroups.com.

Laurent Perron

unread,
Sep 21, 2022, 4:53:25 AM9/21/22
to or-tools-discuss
Alternatively, if you want to stay in or-tools world, you can export the protobuf and reload it.

And no, we do not support any other format.

PR are welcome :-)

Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00


paul-emile Morgades

unread,
Sep 21, 2022, 5:50:12 AM9/21/22
to or-tools-discuss
We have hard time linking Or-Tools to the third party solvers on windows, that's why we are considering linking them using files.

Thank you for your answer :).


Laurent Perron

unread,
Sep 21, 2022, 7:07:08 AM9/21/22
to or-tools-discuss
gurobi is preloaded. It just needs to find the dll.

Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00


Le mer. 21 sept. 2022 à 11:50, paul-emile Morgades <pio7...@gmail.com> a écrit :
We have hard time linking Or-Tools to the third party solvers on windows, that's why we are considering linking them using files.

Thank you for your answer :).


--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.

Andreas Beham

unread,
Sep 21, 2022, 8:29:17 AM9/21/22
to or-tools-discuss
Hmm strange. As Laurent said Gurobi is already in, SCIP is in, CBC is in. I linked or-tools against CPLEX 22.1 in a build I did around July, but for dotnet. This wasn't working in April or so, because it couldn't link some function that was used (IIRC), but somebody fixed this. I used the cmake-based build and the description here: https://github.com/google/or-tools/blob/stable/cmake/README.md
The only file that I had to change was cmake\FindCPLEX.cmake where I changed the name of the .lib file to cplex2210.lib.

Best!

paul-emile Morgades

unread,
Sep 22, 2022, 3:13:49 AM9/22/22
to or-tools-discuss
Thank you for your insights!
I have tried this with CPLEX 12.6 but I get this error:
java.lang.UnsatisfiedLinkError: C:\Users\morgpa00\AppData\Local\Temp\ortools-java5986568736092578411\ortools-win32-x86-64\jniortools.dll: Can't find dependent libraries

Laurent Perron

unread,
Sep 22, 2022, 4:56:16 AM9/22/22
to or-tools-discuss
It seems the cplex dll is not on the path.

Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00


--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
Message has been deleted

Vincent ANGILELLA

unread,
Sep 23, 2022, 9:18:30 AM9/23/22
to or-tools-discuss

Hello everyone, 

pio7...'s next desk neighbor here. 

We tried to recompile or-tools with cplex with 2 different versions, cplex 12.6 and cplex, 22.10, each time with the corresponding dll's on the path variable, and FindCPLEX.cmake configured properly to find cplex.lib. 

The build succeeds, but we always have similar linking errors. 

Is there something specific we should know about adding the dlls on the path ? Should it have a special name, a cplex_home variable, be in the cplex root folder, ... ?

A remark : We had to change the arborescence of our cplex installations each time so that or-tools finds the .h files. The build for or-tools systematically looks for them in ${CPLEX_ROOT}/cplex/include, we didn't have exactly that. It may be a related problem.  

Thanks in advance

Laurent Perron

unread,
Sep 23, 2022, 11:02:40 AM9/23/22
to or-tools-discuss
It has to be on the windows part.
Add the directory with the dll to the PATH variable.

Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00


Vincent ANGILELLA

unread,
Sep 26, 2022, 3:38:52 AM9/26/22
to or-tools-discuss

Hello, 

It is on the path variable. 
Since it builds, it is probably on windows part indeed. Maybe the following error message rings a bell ?
WARNING: Logging before InitGoogleLogging() is written to STDERR
W0922 11:40:41.159670 15184 linear_solver.cc:625] Support for CPLEX not linked in, or the license was not found.
Could not create solver CPLEX

We can use the cplex.jar, so it probably isn't a license issue. 

Thanks in advance

Andreas Beham

unread,
Sep 26, 2022, 4:03:44 AM9/26/22
to or-tools-discuss
Maybe go back, scan the build log and check that everything did work correctly with respect to CPLEX during compile and linking. You should see USE_CPLEX=on, otherwise the build doesn't include CPLEX.
There are some options that you need to supply as noted here: https://github.com/google/or-tools/blob/stable/cmake/README.md#enabling-cplex-support
Check on the next chapter "CMake Options" also on how these options are enabled during build.
Reply all
Reply to author
Forward
0 new messages