I am writing a very simple optimization model in Gurobipy but am struggling with the binary variable constraints.
I have 5 materials in 3 groups. The decision variables are whether or not to use one of the materials and are binary. Each decision variable has a cost coefficient and I am minimizing total cost in the objective. The first group has 3 of the materials and the latter 2 groups have just one material in each.
I would like to write a constraint so that the sum of the decision variables in group 1 == 1 and so on... meaning you can only pick one material from each group.
The constraints would look something like this:
x[0] + x[3] + x[4] == 1
x[1] == 1
x[2] == 1
Is there a way to iterate through a list of components by group and to match those against the variable names?
Thank you!