luca giovanni voglino
luca giovanni voglino

Reputation: 29

How to read an lp file with CPLEX?

I am new to using CPLEX. I have an lp file and should solve it. How do I implement it in CPLEX? Thanks.

Upvotes: 1

Views: 3285

Answers (2)

TimChippingtonDerrick
TimChippingtonDerrick

Reputation: 2072

If you want to avoid having to do any programming at all, just use the CPLEX commandline tool. This is cplex.exe on windows, e.g. in

C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\bin\x64_win64.

You will find something similar on other systems like Linux or MacOS. This lets you read, solve and write out your solution using the commands 'read', 'opt' and 'write' like this:

C:\Users\Tim>cplex

Welcome to IBM(R) ILOG(R) CPLEX(R) Interactive Optimizer 12.9.0.0
...

CPLEX> read "location.lp"
Problem location.lp' read.
Read time = 0.05 sec. (0.00 ticks)
CPLEX> opt
Tried aggregator 1 time.

...

MIP - Integer optimal solution:  Objective =  4.9900000000e+02
Solution time =    0.19 sec.  Iterations = 124  Nodes = 0
Deterministic time = 7.91 ticks  (42.08 ticks/sec)

CPLEX> write location.sol
Incumbent solution written to file 'location.sol'.
CPLEX> quit

The cplex commandline tool is very useful tool when you get to know it.

Upvotes: 4

Alex Fleischer
Alex Fleischer

Reputation: 10062

if I use the zoo example with bus.lp

\ENCODING=ISO-8859-1
\Problem name: broken

Minimize
 obj: 500 nbBus40 + 400 nbBus30
Subject To
 ctAllKidsNeedToGo: 40 nbBus40 + 30 nbBus30 >= 300

Bounds
      nbBus40 >= 0
      nbBus30 >= 0
Generals
 nbBus40  nbBus30 
End

then in OPL

main
{
  cplex.importModel("bus.lp");
  cplex.solve();
  writeln(cplex.getObjValue());
}

gives

3800

Upvotes: 1

Related Questions