使用C#在Gurobi中向变量添加其他描述

时间:2017-03-25 12:41:29

标签: c# gurobi ampl

我想添加额外的变量despription而不是将其作为约束。我已经在AMPL中做过这样的事情:

var z {p in route} = sum{n in nodes}s[p,n];

到目前为止,我已经使用C#在Gurobi中编写代码,但它不起作用。它说:“Cannot implicitly convert type 'Gurobi.GRBLinExpr' to 'Gurobi.GRBVar'

GRBVar[] z = new GRBVar[P];     //variable of route
GRBVar[] y = new GRBVar[M];     //variable of depot
GRBVar[,] s = new GRBVar[P,N];     //auxilary variable

for (int p = 0; p < P; p++)
 for (int n = 0; n < N; n++)
 s[p, n] = master.AddVar(0.0, 1.0, 0.0, GRB.CONTINUOUS, "s" + p + "," + n);

for (int p = 0; p < P; p++)
{
GRBLinExpr sumS = 0.0;
for (int n = 0; n < N; n++)
{
sumS += s[p, n];
}
z[p] = sumS;
};

 for (int m = 0; m < M; m++)
 y[m]=master.AddVar(0.0, 1.0, 0.0, GRB.CONTINUOUS, "y" + m);

0 个答案:

没有答案