0
我是CPLEX Python API的新手。我希望通過以.mod和.dat文件作爲輸入,在python中解決我已經在CPLEX OPL IDE中完成的線性編程問題。我想在Python中使用它,因爲我希望不斷改變我的輸入。我的問題的mod文件在下面給出。有人可以幫助我如何使用這個python API。使用CPLEX python API進行連續輸入的線性編程
int n = ...;
int m = ...;
int c = ...;
int s = ...;
range v = 1..n;
range p = 1..m;
int c_req[v] = ...;
int s_req[v] = ...;
int trust[v][v] = ...;
// decision variables
dvar boolean assign[p][v];
// expressions
dexpr int used[pi in p] = max(vi in v) assign[pi][v]; // used[i] = 1 iff pi is used
dexpr int totalUsed = sum(pi in p) used[pi];
execute {
cplex.tilim = 60; // Time limit 60 seconds
}
// model
minimize totalUsed;
subject to {
forall(pi in p)
c_cap:
sum(vi in v) c_req[vi] * assign[pi][vi] <= c;
forall(pi in p)
s_cap:
sum(vi in v) s_req[vi] * assign[pi][vi] <= s;
forall(vi in v)
v_all:
sum(pi in p) assign[pi][vi] == 1;
forall(pi in p, v1 in v, v2 in v) if (v1 < v2) if (trust[v1][v2] == 0)
trust_constraint:
assign[p][v1] + assign[p][v2] <= 1;
}
如果生成diet.dat,請確保該文件句柄是同步,然後關閉。 – PerlDev