How to compute the IIS form for the model shown below
using JuMP, Gurobi
include("Data.jl")
UnitCommitment_dt = UC_dt
function DUC_Clearing(UnitCommitment_dt)
# Indices
ngen = length(UC_dt.Gen_Constraints[:,1])
periods = length(UC_dt.Forecast[1,:])
# Sets
J = collect(1:ngen)
T = collect(1:periods)
zT = collect(1:periods+1)
# Parameters
# Generator Parameters
cแต = UC_dt.Gen_Constraints[:,1]
c = UC_dt.Gen_Constraints[:,2]
Pฬฒ = UC_dt.Gen_Constraints[:,3]
Pฬ
= UC_dt.Gen_Constraints[:,4]
Sแต = UC_dt.Gen_Constraints[:,5]
Sแดฐ = UC_dt.Gen_Constraints[:,6]
Rแต = UC_dt.Gen_Constraints[:,7]
Rแดฐ = UC_dt.Gen_Constraints[:,8]
Tแต = UC_dt.Gen_Constraints[:,9]
Tแดฐ = UC_dt.Gen_Constraints[:,10]
# Initial Init_Conditions
๐ฃโ = UC_dt.Init_Conditions[:,1]
๐โ = UC_dt.Init_Conditions[:,2]
U = UC_dt.Init_Conditions[:,3]
D = UC_dt.Init_Conditions[:,4]
L = min.(periods*ones(Real, 3), U)
F = min.(periods*ones(Real, 3), D)
๐งโโโ = [0; 0 ;0]
# Forecast
๐ท = UC_dt.Forecast[1,:]
๐
= UC_dt.Forecast[2,:]
# Model
DUC = Model(Gurobi.Optimizer)
set_attribute(DUC, "OutputFlag", 1)
set_attribute(DUC, "FeasibilityTol", 1e-8)
set_attribute(DUC, "MIPGap", 1e-8)
set_attribute(DUC, "MIPGapAbs", 0)
# Variables
@variables(DUC, begin
๐[J,T] # pโฑผ(t): Active/real power produced by unit j in time period t (MW)
๐ฬ
[J,T] # ฬ
pโฑผ(t): Maximum available power in time period t from unit j (MW).
๐ฃ[J,T], Bin # vโฑผ(t): On/off status in time period t of the unit j (1 if ON and 0 otherwise)
๐ฆ[J,T], Bin # yโฑผ(t): Startup status in time period t of the unit j
๐ง[J,zT], Bin # zโฑผ(t): Shutdown status in the time period t of the unit j
end)
@constraint(DUC, pow_balance[t=T], sum(๐[j,t] for j in J) == ๐ท[t])
@constraint(DUC, reserve[t=T], sum(๐ฬ
[j,t] for j in J) โฅ ๐ท[t]+๐
[t])
for t in T, j in J
if t!=1
@constraint(DUC, ๐ฃ[j,t-1]-๐ฃ[j,t]+๐ฆ[j,t]-๐ง[j,t]==0)
else
@constraint(DUC, ๐ฃโ[j]-๐ฃ[j,t]+๐ฆ[j,t]-๐ง[j,t]==0)
end
end
for t in T, j in J
if t!=1
@constraint(DUC, ๐[j,t]-๐[j,t-1] โค Rแต[j]*๐ฃ[j,t-1]+Sแต[j]*๐ฆ[j,t])
else
@constraint(DUC, ๐[j,t]-๐โ[j] โค Rแต[j]*๐ฃโ[j]+Sแต[j]*๐ฆ[j,t])
end
end
for t in T, j in J
if t!=1
@constraint(DUC, ๐[j,t-1]-๐[j,t] โค Rแดฐ[j]*๐ฃ[j,t]+Sแดฐ[j]*๐ง[j,t])
else
@constraint(DUC, ๐โ[j]-๐[j,t] โค Rแดฐ[j]*๐ฃ[j,t]+Sแดฐ[j]*๐ง[j,t])
end
end
@constraint(DUC, [j=J,t=T], Pฬฒ[j]*๐ฃ[j,t] โค ๐[j,t])
@constraint(DUC, [j=J,t=T], ๐[j,t] โค ๐ฬ
[j,t])
@constraint(DUC, [j=J,t=T], ๐ฬ
[j,t] โค Pฬ
[j]*๐ฃ[j,t])
for t in T, j in J
if t!=1
@constraint(DUC, ๐ฬ
[j,t] โค ๐[j,t-1] + Rแต[j]*๐ฃ[j,t-1]+Sแต[j]*๐ฆ[j,t])
else
@constraint(DUC, ๐ฬ
[j,t] โค ๐โ[j] + Rแต[j]*๐ฃโ[j]+Sแต[j]*๐ฆ[j,t])
end
end
for t in T, j in J
#if t!=length(UC_dt.Forecast[1,:])
@constraint(DUC, ๐ฬ
[j,t] โค Pฬ
[j]*(๐ฃ[j,t]-๐ง[j,t+1]) + Sแดฐ[j]*๐ง[j,t+1])
#=
else
#@constraint(DUC, ๐ฬ
[j,t] โค Pฬ
[j]*(๐ฃ[j,t]-๐ง[j,1]) + Sแดฐ[j]*๐ง[j,1])
@constraint(DUC, ๐ฬ
[j,t] โค Pฬ
[j]*(๐ฃ[j,t]-๐ง[j,t+1]) + Sแดฐ[j]*๐ง[j,t+1])
end
=#
end
#constraint(DUC, ๐ฃ[3,1]==1)
for j in J
for t in L[j]+1:periods
k=t-Tแต[j]+1
ku = collect(k:t)
println(k)
println(ku)
if kโฅ1
@constraint(DUC, sum(๐ฆ[j,kuu] for kuu in ku) โค ๐ฃ[j,t])
end
end
end
for j in J
for t in F[j]+1:periods
k=t-Tแดฐ[j]+1
kd = collect(k:t)
if kโฅ1
@constraint(DUC, ๐ฃ[j,t] + sum(๐ง[j,kdd] for kdd in kd) โค 1)
end
end
end
for j in J
@assert(L[j]*F[j]==0)
for t in 1:L[j]
@constraint(DUC,๐ฃ[j,t]==1)
#@constraint(DUC,๐ฆ[j,t]==0)
#@constraint(DUC,๐ง[j,t]==0)
end
for t in 1:F[j]
@constraint(DUC,๐ฃ[j,t]==0)
#@constraint(DUC,๐ฆ[j,t]==0)
#@constraint(DUC,๐ง[j,t]==0)
end
end
@expressions(DUC, begin
gen_cost, sum(sum(c[j]*๐[j,t] for j in J) for t in T)
startup_cost, sum(sum(cแต[j]*๐ฆ[j,t] for j in J) for t in T)
end)
@objective(DUC, Min, gen_cost + startup_cost)
optimize!(DUC)
println(DUC)
println(value.(๐))
#println(dual.(pow_balance)) # can not find dual for MILP
println(dual_status(DUC))
# Finding dual for the linear version of the problem by fixing the discrete variables
undo = fix_discrete_variables(DUC)
println(" Here is the LP version of the model")
#println(DUC)
optimize!(DUC)
dual_status(DUC)
println(dual.(pow_balance))
println(dual.(reserve))
println(value.(๐ฬ
))
println(value.(๐))
#println(value.(๐ง))
end
@time DUC_Clearing(UnitCommitment_dt)