I am recently learning Python Gekko and I am very very new to linear programming, so excuse my ignorance in certain topics.
I have a variable which should have a value of either 0 or should be greater than 20.
I later learnt that this is called a semi-continuous variable. My questions are as below
You can use the if3()
function to enforce that constraint. That function uses a binary variable for the switch condition so it transforms the problem from a linear programming (LP) problem to a mixed integer linear programming (MILP) problem.
from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
m = GEKKO()
p = m.Param(np.linspace(0,50))
y = m.if3(p-20,0,p)
m.options.IMODE=2
m.solve()
# plot solution
plt.plot(p.value,'r-',lw=3)
plt.plot(y.value,'b.-')
plt.show()