0

I am trying to include a python "max" command inside a quicksum command using gurobi with python. There is obviously an error with doing so, under LinExpr limitations as it is not accepted.

shutdowncost = quicksum(quicksum(shutdown_cost[i] * max((v[hour -1, i] - v[hour, i]),0) for i in num_gen) for hour in hour_range)

V is a binary variable in the model, while the remainder are fixed variables. The issue is around shutdowncost being negative in the scenario where v[hour - 1, i] is 0, and v[hour, i] is 1.

Is there another command that can be used to replace the max command inside the quicksum?

tm553
  • 97
  • 4
  • 15
  • is this operation allowed : `list.sort(reverse=True)[0]` ? – PRMoureu Jun 27 '17 at 17:27
  • Why do you use `gurobi`? What about solving in pure Python (with `numpy` for example)? – a_guest Jun 27 '17 at 18:32
  • Using gurobi for the optimisation toolbox. Thanks for the comments - I was able to remedy the issue by introducing new variables for the shutdowncost and constrain it to be equal to this command. – tm553 Jun 27 '17 at 22:57

1 Answers1

0

Here is a paper that talks about startup and shutdown constraints: MIPFormulation. They use the notation:

  • u[t] 1 for online, 0 for offline, binary (state)
  • v[t] 1 for turned on that time period, binary (turn_on)
  • w[t] 1 for turned off that period, binary (turn_off)

These gurobi binary variables are defined with the constraints:

  • u[t] - u[t-1] == v[t] - w[t]
  • v[t] + w[t] <= 1

Then your shutdowncost can be defined:

  • shutdowncost = quicksum([shutdown_cost[i] * w[hour, i] for i in num_gen for hour in hour_range])

(No need for 2 quicksums!) This shutdowncost can then be used in your objective function or another constraint. And it is easier to see what is happening.

Rich L
  • 369
  • 3
  • 12