I’m encountering a problem with an optimization model in Julia where I need to enforce a specific condition using indicator variables. The goal is to ensure that for each time period ( t ) (from 2 to T), either ( y_{i,t} ) is positive and ( z_{i,t} ) is zero, or the other way around. Despite several attempts, I’m not achieving the expected behavior.
My initial approach was to use the constraint @constraint(model,[i=1:n,t=2:T],z[i,t]*y[i,t] == 0)
to prevent both ( y ) and ( z ) from being positive at the same time ( t ). However, this did not work as planned, as I still observe cases where both ( y ) and ( z ) are positive simultaneously.
To address this, I introduced binary variables ( b_t[t] ) and added constraints like @constraint(model, [i=1:n, t=2:T], y[i,t] <= 1 - b_t[t])
and @constraint(model, [i=1:n, t=2:T], z[i,t] <= b_t[t])
. Unfortunately, this approach leads to the model running indefinitely without finding a solution.
Here’s the relevant portion of my Julia code:
model = Model()
@variables(model, begin
0 <= x[i=1:n,t=2:T] <= 1
0 <= y[i=1:n, t=2:T] <= 1
0 <= z[i=1:n,t=2:T] <= 1
w[t=2:T], Bin
end)
# Active when w[t] == 1
@constraint(model, [t=2:T], w[t] => {sum(CF[i,t] * x[i,t] for i in 1:n) - L[t] == -sum(PBid[i,t] * y[i,t] for i in 1:n)})
# Active when w[t] == 0
@constraint(model, [t=2:T], !w[t] => {sum(CF[i,t] * x[i,t] for i in 1:n) - L[t] == -sum(PAsk[i,t] * z[i,t] for i in 1:n)})
I’m seeking advice on what might be causing these issues or how to implement these constraints correctly in Julia. Any insights or suggestions would be greatly appreciated, as I’m currently unable to progress with this model.