Reputation: 21
I am trying to implement a unit commitment problem with cvxpy with a rampup cost. However I am struggling to identify the ramp-ups. (when variable switch from 0 to any positive value) In other terms, I have a variable g, positive and I want to determine when g is 0, or when g>0. I know it's often easier with some tolerance, that's not really an issue for me.
Below is some code to put this in context :
import cvxpy as cp
n=50
g=cp.Variable(n)
ispos=cp.Variable(n,boolean=True)
I would need a constraint that looks like this :
I tried to work around something like below, but I cannot get a syntax CVXPY is happy with.
constraints=[ispos == (g>=0)]
I get the following error
Exception: Cannot evaluate the truth value of a constraint or chain constraints, e.g., 1 >= x >= 0.
Also tried with this :
constraints+=[ off[t]+(1 if g[t]<=0 else 0)== 1 for t in range (n)]
But I get the following error:
Exception: Cannot evaluate the truth value of a constraint or chain constraints, e.g., 1 >= x >= 0.
Upvotes: 1
Views: 1640
Reputation: 16782
You want:
ipsos[t] = 0 ==> g[t] >= 0
ipsos[t] = 1 ==> g[t] <= -0.001
This can be modeled as:
g[t] >= L[t]*ipsos[t]
g[t] <= -0.001*ipsos[t]+U[t]*(1-ipsos[t])
g[t] ∈ [L[t],U[t]]
I assume here that the lowerbound L[t]
is a negative number. In practice, I would drop this -0.001 thing and just do:
g[t] >= L[t]*ipsos[t]
g[t] <= U[t]*(1-ipsos[t])
g[t] ∈ [L[t],U[t]]
Upvotes: 0