モデルを作成するために OPL を使用して、IBM Optimization Studio で LP 問題を実装しました。モデルを検証した後、シミュレーション用のパラメーターをスクリプト化するために、モデルを Java に入れたいと考えました。次のコードを使用して、Java で OLP モデルを使用する最も簡単な方法を見つけました。
IloOplFactory.setDebugMode(false);
IloOplFactory oplF = new IloOplFactory();
IloOplErrorHandler errHandler = oplF.createOplErrorHandler(System.out);
IloOplModelSource modelSource = oplF.createOplModelSource("myModel.mod");
IloCplex cplex = null;
cplex = oplF.createCplex();
IloOplSettings settings = oplF.createOplSettings(errHandler);
IloOplModelDefinition def = oplF.createOplModelDefinition(modelSource, settings);
IloOplModel opl = oplF.createOplModel(def, cplex);
String inDataFile = "myData.dat";
IloOplDataSource dataSource = oplF.createOplDataSource(inDataFile);
opl.addDataSource(dataSource);
opl.generate();
opl.convertAllIntVars(); // converts integer bounds into LP compatible format
if (cplex.solve()) {
double obj = opl.getCplex().getObjValue();
System.out.println("OBJECTIVE: " + obj);
}
問題は、IBM Optimization Studio と Java の両方で「myModel.mod」と「myData.dat」を実行すると、非常に異なる客観的な結果が得られることです。
IBM Optimization Studio で:
solution (optimal) with objective 125
Java の場合:
Parallel mode: deterministic, using up to 4 threads for concurrent optimization.
Tried aggregator 1 time.
LP Presolve eliminated 0 rows and 1 columns.
Reduced LP has 5280 rows, 5325 columns, and 25525 nonzeros.
Presolve time = 0.01 sec. (3.77 ticks)
Iteration log . . .
Iteration: 1 Dual objective = 0.000000
Iteration: 345 Dual objective = 90.297455
Iteration: 568 Dual objective = 117.206047
Perturbation started.
Iteration: 707 Dual objective = 117.206047
Removing perturbation.
Reinitializing dual norms . . .
Dual simplex solved model.
OBJECTIVE: 117.20608137232513
データセットとモデルを調べたところ、125 未満の目標は不可能です (目標変数の 1 つが 125 であることを確認するために極端な値を使用したため、それ以下は不可能です)。
これらの結果が異なる理由を知っている人はいますか? それはおそらく、IBM と比較して Java の設定にあるものでしょうか? IBM Optimization Studio の設定を Java にインポートして、これをテストすることはできますか?
ありがとうございました!
編集: ここに IBM Optimization Studio のログがありますが、それらを含めるのを忘れていました。切り捨てられた整数に関するより多くの情報が表示されますが、これは両方のプログラムでの最初の経験なので、誰かが問題の場所またはこれが何を意味するのかを特定するのを手伝ってくれませんか?
Found incumbent of value 125.000000 after 0.00 sec. (0.53 ticks)
Tried aggregator 1 time.
MIP Presolve eliminated 5027 rows and 4764 columns.
MIP Presolve modified 1191 coefficients.
Reduced MIP has 253 rows, 562 columns, and 1958 nonzeros.
Reduced MIP has 562 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.02 sec. (8.46 ticks)
Probing fixed 8 vars, tightened 0 bounds.
Probing time = 0.00 sec. (2.86 ticks)
Tried aggregator 1 time.
MIP Presolve eliminated 158 rows and 306 columns.
MIP Presolve modified 293 coefficients.
Reduced MIP has 95 rows, 256 columns, and 632 nonzeros.
Reduced MIP has 256 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.02 sec. (1.73 ticks)
Probing fixed 6 vars, tightened 0 bounds.
Probing time = 0.00 sec. (0.12 ticks)
Tried aggregator 1 time.
MIP Presolve eliminated 29 rows and 30 columns.
MIP Presolve modified 2 coefficients.
Reduced MIP has 66 rows, 226 columns, and 522 nonzeros.
Reduced MIP has 226 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (0.42 ticks)
Probing time = 0.00 sec. (0.07 ticks)
Clique table members: 34.
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: deterministic, using up to 4 threads.
Root relaxation solution time = 0.00 sec. (0.36 ticks)
Nodes Cuts/
Node Left Objective IInf Best Integer Best Bound ItCnt Gap
* 0+ 0 125.0000 123.0000 1.60%
0 0 123.8469 4 125.0000 123.8469 62 0.92%
0 0 cutoff 125.0000 81 0.00%
Elapsed time = 0.09 sec. (17.09 ticks, tree = 0.00 MB, solutions = 1)
Zero-half cuts applied: 1
Gomory fractional cuts applied: 1
Root node processing (before b&c):
Real time = 0.09 sec. (17.22 ticks)
Parallel b&c, 4 threads:
Real time = 0.00 sec. (0.00 ticks)
Sync time (average) = 0.00 sec.
Wait time (average) = 0.00 sec.
------------
Total (root+branch&cut) = 0.09 sec. (17.22 ticks)
編集 2: マトリックス 0..1 の整数値が 0 または 1 に丸められていないことがわかりましたが、代わりに 0.932 としてカウントされています... Java cplex に整数を強制的に丸めるにはどうすればよいですか?
解決済み:「opl.convertAllIntVars();」でした すべてをdoubleに変換しました。これをサンプル コードから取り出して削除したところ、すべて正常に動作するようになりました。