我想添加额外的变量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);