I am trying to model a pumped hydro electric problem using GEKKO and python, and I am running into some errors trying to avoid charging and discharging at the same time. The idea is using price as input to Pump/Release water and obtain the highest possible benefit, having a maximum storage of 4 hours of water release. My problem is that I can't seem to work out binary variables for the problem to work:
import numpy as np
from gekko import GEKKO
horas = 4
año = 2018
Eff = 0.75
PMD_calculo = np.array([1,1.5,3,0.5,0.2])
#PMD_calculo = np.array(PMD_año[año]['Precio'])
Num_horas = len(PMD_calculo)
m = GEKKO(remote=False)
m.options.SOLVER = 1
m.solver_options = ['minlp_integer_tol 0.0']
#variables
Carga = m.Var(Num_horas, lb=0, ub=horas) # Storage (from 0 to 4 hours of energy)
Tur = m.Array(m.Var, Num_horas, lb=0, ub=1) # Generation
Bom = m.Array(m.Var, Num_horas, lb=0, ub=1/Eff) # Pumping
T = m.Array(m.Var, Num_horas, lb=0, ub=1, integer = True)
B = m.Array(m.Var, Num_horas, lb=0, ub=1, integer = True)
m.Equation(Carga[i] <= Bom[i-1]*B[i-1] - Tur[i-1]*T[i-1] for i in range(1,len(PMD_calculo) ))# charge / discharge
m.Equation(B[i]+T[i] <= 1 for i in range(len(PMD_calculo))) # Avoid charge and discharge
m.Maximize(Tur*T*PMD_calculo - Bom*PMD_calculo*B)
m.solve()
With this I get the following error:
----------------------------------------------------------------
APMonitor, Version 1.0.0
APMonitor Optimization Suite
----------------------------------------------------------------
@error: Inequality Definition
invalid inequalities: z > x < y
<generatorobject<genexpr>at0x000001b29a296eb0>
STOPPING . . .
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-45-26c2eb591bd7> in <module>
21 m.Maximize(Tur*T*PMD_calculo - Bom*PMD_calculo*B)
22
---> 23 m.solve()
C:\ProgramData\Anaconda3\lib\site-packages\gekko\gekko.py in solve(self, disp, debug, GUI, **kwargs)
2138 print("Error:", errs)
2139 if (debug >= 1) and record_error:
-> 2140 raise Exception(apm_error)
2141
2142 else: #solve on APM server
Exception: @error: Inequality Definition
invalid inequalities: z > x < y
<generatorobject<genexpr>at0x000001b29a296eb0>
STOPPING . . .
I THINK that i am getting the correct output when not using binary variables (charge-discharge either cancel each other out in the same hour or in multiple hours) but it still makes the process hard to process
