-1

I'm trying to make a optimization problem that include product of a binary and a continuous variable in the objective, someone have an example or maybe how to fix it..


Touf = gp.Model('Time of Use FL')

# Creacion de Estados ON y OFF Carga
a = {}
for j in range (1,Ncargas+1):
    for k in range(1,dia+1):
        a[j,k] = Touf.addVar(vtype=GRB.BINARY, name="a(%s,%s)" % (j,k))

b = {}
for k in range(1,dia+1):
    b[k] = Touf.addVar(lb=0.0, ub=0.5,vtype=GRB.CONTINUOUS)

bdiss = {}
for k in range(1,dia+1):
    bdiss[k] = Touf.addVar(lb=0.0, ub=0.5,vtype=GRB.CONTINUOUS)

St= {}
for k in range(1,dia+1):
    St[k] = Touf.addVar(lb=0.0, ub=0.5,vtype=GRB.CONTINUOUS)

beff = 0.9


Touf.setObjective((gp.quicksum(a[j,k]*Costo[k]*(Potencia[j-1]+b[k]-bdiss[k]) for j in range(1,Ncargas) for k in range(1,dia))), GRB.MINIMIZE)

Touf.addConstr(gp.quicksum(a[j,k]*Potencia[j-1] for j in range(1,Ncargas) for k in range(1,dia)) <= MD.item(0))

for i in range(1,Ncargas+1):
    Touf.addConstr(gp.quicksum(a[i,j] for j in range(Sj.item(i-1),Fj.item(i-1)+1)) == lj[i-1])

Touf.addConstrs(St[i]==St[i-1]+beff*b[i]-1/beff*bdiss[i] for i in range(1,dia))


# Solve
Touf.optimize()

Sergio
  • 1
  • 2

1 Answers1

0

There are different ways to handle a product z = y*x where y is a continuous variable and x a binary variable.

  1. Use a standard linearization (link). This requires good bounds on y (that seems ok in your model).

  2. Use indicator constraints (link):

    x = 0 ==> z = 0
    x = 1 ==> z = y
    
  3. Gurobi can handle convex and non-convex quadratic terms directly. You may need to use the nonconvex option (link).

Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39