2

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

  1. Is it possible to convert the above condition into a linear equation
  2. By any chance does Gekko support the semi-continuous variables as I could not find anything about it in the documentation.

1 Answer 1

1

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.

result

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.