-1

I need the Syntax to create a sum in a Gurobi-constraint in c++:

EXAMPLE: I have the variables: x[i][j]

and the constraint: sum over all i's from x[i][j] <= 1 for all j's

in Gurobi Python it is: for i in [list of i's]: model.addConstr(x[i,j] <= 0 for j in [list of j's])

How is the Syntax for this in c++?

Thanks in advance! Best regards, David Franck

DvdFrcK
  • 33
  • 5
  • Welcome to Stack Overflow. Please read [the help pages](http://stackoverflow.com/help), take the SO [tour], read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Lastly please learn how to [edit] your questions to improve them, for example by including a [mcve] of *your own* attempt together with a description of the problems you have with it. – Some programmer dude Jan 14 '21 at 09:56
  • And finally a tip about your problem in doing translations: Don't! Don't try to translate a solution in one programming language directly into another. Instead start *fresh* and try to write brand new implementation of the generic algorithm. – Some programmer dude Jan 14 '21 at 09:58

1 Answers1

0

I found it out:

     for (j = 0; j < n; j++) 
     {
         GRBLinExpr expr = 0;
         for (i = 0; i < n; i++)
            expr += vars[i][j];
         model.addConstr(expr <= 1, [name of constrain]);
     }
DvdFrcK
  • 33
  • 5