DisabledWhale
DisabledWhale

Reputation: 861

Julia (JuMP): Indicator constraints with multiple conditional values (is a boolean expression possible?)

I want to implement a constraint depending on the change of values in my binary decision variable, x, over "time".

I am trying to implement a minimum operating time constraint for a unit commitment optimization problem for power systems. x is representing the unit activation where 0 and 1 show that a power unit, n, at a certain time, t, respectively is shut off or turned on.

For this, indicator constraints seem to be a promising solution and with the inspiration of a similar problem the implementation seemed quite straightforward.

So, since boolean operators are introduced (! and ¬), I prematurely wanted to express the change in a boolean way:

@constraint(m, xx1[n=1:N,t=2:T], (!x[n,t-1] && x[n,t]) => {next(t, 1) + next(t, 2) == 2})

Saying: if unit was deactivated before but now is on, then demand the unit to be active for the next 2 times.

Where next(t, i) = x[((t - 1 + i) % T) + 1].

I got the following error:

LoadError: MethodError: no method matching !(::VariableRef)
Closest candidates are:
  !(!Matched::Missing) at missing.jl:100
  !(!Matched::Bool) at bool.jl:33
  !(!Matched::Function) at operators.jl:896

I checked that the indicator constraint is working properly with a single term only.

Question: Is this possible or is there another obvious solution?

Troubleshooting and workarounds: I have tried the following (please correct me if my diagnosis is wrong):

You can get the working code from github.

Upvotes: 1

Views: 826

Answers (1)

DisabledWhale
DisabledWhale

Reputation: 861

The trick is to find constraint(s) that have an equivalent truth-table:

# Like
(!x[1] && x[2]) => {z == 1}

# Is equivalent to:
z >= -x[1] + x[2]

# Proof
-x[1] + x[2] = sum <= z
--------------------------
 - 0  +  0   =  0  <= 0
 - 1  +  0   =  -1 <= 0 
 - 0  +  1   =  1  <= 1
 - 1  +  1   =  0  <= 0

I was recommended MOSEK Modeling Cookbook to help working out the correct formulation of constraints.

See eventually the thread here from where I got the answer for further details.

Upvotes: 2

Related Questions