MingyuSang
MingyuSang

Reputation: 11

Gurubi python constraint using quicksum

I have an optimization problem using Python and Gurobi. In my problem formulation there is the following constraint:

enter image description here

Here, w_it is a decision variable and G_it is a parameter expressed using a dictionary. For example,

Git = {( 't1', 1): 4, ( 't1', 2): 3, ....}

The right side of the constraint is the sum of G_i1, G_i2, ... G_it

con3 = m.addConstrs(wit[i,t] <= gp.quicksum(Git[i,t]) for i in NC for t in time_shifts)

Upvotes: 1

Views: 1472

Answers (1)

Greg Glockner
Greg Glockner

Reputation: 5653

There are several issues:

  1. I suggest you use variables w and G, not wit and Git.
  2. The convention is for decision variables w[i,t] >= 0, so there is no need to write this constraint explicitly.
  3. It looks like there is some confusion between t and tau. I'll try to make this clear.

What you need looks like this:

con3 = m.addConstrs(w[i,t] <= gp.quicksum(G[i,tau] for tau in range(1,t+1))
                                          for i in NC
                                          for t in time_shifts)

You may need to adjust the range depending on whether time_shifts counts from 0 or from 1.

Upvotes: 0

Related Questions