How can I set a Binary MV variable on GEKKO?

Viewed 160

I am performing an optimization on GEKKO and I need one of the variable (specifically an MV variable) to be binary. I have tried this:

pheat=m.MV(value=0,lb=0,ub=1,integer=True)

but in the result the variable still has a continuos value between 0 and 1.

Here is the full code for reference.

from gekko import GEKKO

tf=23 #hours
dis=24 #point in time discretization
o=np.ones(dis)
#initialize model
m=GEKKO()
m.time=np.linspace(0,tf,dis)
#MV variables
pheat=m.MV(value=0,lb=0,ub=1,integer=True)
pheat.STATUS = 1
# Load in data
buy = m.Param(SpotPrices[:dis,country]/10000)    # (c/Wh)
ppv = m.Param(P_AC[:dis,country])                # (W)
qint=m.Param(Q_internal[:dis,country])           # (W)
qwall=m.Param(Qradiation_w[:dis,country])
temp=m.Param(Temperature_data[:dis,country])
walle=m.Param(H_wall_e[:dis,country]*Area_walls)
vent=m.Param(Coeffvent[:dis])
window=m.Param(Area_window*H_window[:dis,country]*1.17)
occ=m.Param(occupancy_profile[:dis])
#Constant values
walli=m.Const(Coeffwall)
bridge=m.Const(0.75*18)
croom=m.Const(2.923E6)
cwall=m.Const(1.055E8)
# Variables
T_int=m.Var(value=20,ub=26)
T_wa=m.Var(value=19)
#equations
m.Equation(T_int.dt() == (walli*(T_wa-T_int)+window*(temp-T_int)+bridge*(temp-T_int)+vent*(temp-T_int)+qint+pheat*1000)*3600/croom )
m.Equation(T_wa.dt() == (walli*(T_int-T_wa)+walle*(temp-T_wa)+qwall)*3600/cwall )       
y = m.if2(occ-1,18,20)
m.Equation(T_int>=y)
m.Obj((pheat*1000-ppv)*buy) # minimize cost

m.options.IMODE = 6  # optimal control
m.solve() # Solve

Thanks for the help!

1 Answers
Related