0

I have a VRP code in AMPL and want to write it in GUROBI-C#. Here is the constraint in AMPL:

subject to cons2{j in customer}: sum{i in nodes: i<>j} x[i,j] = 1;

and here is my code in C#, but it is still not working:

//constraint 2
for (int j = 1; j < DC1; j++)
{
   GRBLinExpr sumI = 0.0;
   for (int i = 0; i < DC1; i++)
   if (i != j)
   {
      sumI += x[i, j];
   }
   model.AddConstr(sumI, GRB.EQUAL, 1.0, "C1.2");
}

I have not see example when i<>j is used in C#, if anyone knows please help. Thank you

croxy
  • 4,082
  • 9
  • 28
  • 46
  • The C# equivalent for operator "<>" is operator "!=" Thats reason why you wont find any example of i<>j – Erik Šťastný Jan 17 '17 at 12:50
  • @ErikŠťastný this is the reference with Phyton, but I cannot do it in C# `for j in clients: model.addConstr(quicksum( x[i,j] for i in sites if i != j ) == 1)` – Arlita Nurmaya Asri Jan 17 '17 at 12:57
  • Probably i wont help you, i have no idea what are clients,sites or what quicksum do. BUT, C# has foreach loop which you can use i think and another thing. Do you use Visual Studio? If yes it has excelent debugger you can see all variables at runtime and step by step search where the problem happened – Erik Šťastný Jan 17 '17 at 13:22
  • it is already solved by myself. It is correct to replace i <> j becomes i !=j. thank you – Arlita Nurmaya Asri Jan 19 '17 at 08:48

0 Answers0