pythongurobi

Gurobi: unsupported operand type(s) for -: 'int' and 'tupledict'


I have this constraint with big-M parameter and an auxiliary binary variable w:

for i in customers:
    for j in customers:
        if i != j:
            mdl.addConstr(y[j] +  z[j] <= y[i] + z[i] - df.demand[j]*(x1[i,j] + x2[i,j])
                          + 100000 * (1 - w), name= 'C8')

When I run the code, I got the following error:

TypeError: unsupported operand type(s) for -: 'int' and 'tupledict'

w is defined as follows:

w = mdl.addVars(0,1,vtype=GRB.BINARY, name='w')

I couldn't figure out what is the problem? Is it a problem in defining w? Thank you


Solution

  • w is tupledict as it was defined using mdl.addVars.

    As w is a single variable you need to define it using mdl.addVar instead:

    w = mdl.addVar(0,1,vtype=GRB.BINARY, name='w')