簡體   English   中英

如何使用 CPLEX 讀取 lp 文件?

[英]How to read an lp file with CPLEX?

我是使用 CPLEX 的新手。 我有一個 lp 文件,應該解決它。 如何在 CPLEX 中實現它? 謝謝。

如果您想完全避免進行任何編程,只需使用 CPLEX 命令行工具。 這是Windows上的cplex.exe ,例如在

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

你會在 Linux 或 MacOS 等其他系統上找到類似的東西。 這使您可以使用“讀取”、“選擇”和“寫入”命令來讀取、求解和寫出您的解決方案,如下所示:

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

當您了解 cplex 命令行工具時,它是非常有用的工具。

如果我使用帶有 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

然后在OPL

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

3800

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM