I've been trying to learn how to use Gekko and am currently trying to model optimal battery charge/discharge based in input/output prices (taking inspiration from here and here.
Below is my following code.
from gekko import Gekko
import numpy as np
m = Gekko()
electricity_price_in = np.random.uniform(low=0.1, high=1, size=50)
electrictiy_price_out = np.random.uniform(low=0.3, high=3, size=50)
E_battery = m.Var(lb=0, ub=366.2, value=0) #energy in battery at time t, battery size 366 MWh
Pc = m.Var(lb=0, ub=50) #charge power, 50 MW max
Pd = m.Var(lb=0, ub=36.6) #discharge power, max 36 MW
E_price_in = m.Param(electricity_price_in)
E_price_out = m.Param(electrictiy_price_out)
m.time = np.linspace(0,49, 50)
Revenue = m.Intermediate(Pd*E_price_out)
Cost = m.Intermediate(Pc*E_price_in)
m.Equation(E_battery.dt() == Pc-Pd)
m.Equation(E_battery >= 0)
m.Maximize(Revenue - Cost)
m.options.IMODE = 6
m.solve()
This appears to work ok. However, I get very different results if I include the following code:
isCharging = m.if3(-Pc,1,0)
isDischarging = m.if3(-Pd,1,0)
What I believe I am doing is creating two variables. As they are not constraint equations and are not included in the objective function, I would have expected the inclusion of this to make no changes to my results, however my code gives very different results (all variables turn into a list of zeroes).
Why would adding these two variables change my results?