I would like to solve an optimization problem with Gekko. The non-linear constraints are generated in a function and passed on as a vector. Since there are vectors, I use m.Equations and m.Array. To make it as simple as possible, I have simplified my problem so that the code remains short and simple. I think my mistake is in how I use m.Equations. The error message is:
Exception: @error: Equation Definition An equation without equality (=) or inequality (>,<) false STOPPING...
This is my code:
import numpy as np
from gekko import GEKKO
def powerf(x):
U = np.array([[x[2]], [x[3] * m.exp(x[4] * 1j)]])
G = np.array([[x[0] + x[1] * 1j], [0]])
L = np.array([[0],[1]])
y = np.array([[-18.8301*1j, 18.8566*1j], [18.8566*1j, -18.8301*1j]])
I = np.matmul(y, U)
Iconj = np.real(I) - np.imag(I) * 1j
S = np.matmul(np.diagflat(Iconj), U)
P = np.real(S) - np.real(G) + np.real(L)
Q = np.imag(S) - np.imag(G) + np.imag(L)
return np.concatenate((P,Q)).reshape(4,)
m = GEKKO()
x = m.Array(m.Var,5)
ig = [0, 0, 1, 1, 0]
lb = [0, -2, 0.95, 0.95, -np.pi]
ub = [5, 2, 1.10, 1.10, np.pi]
for i in range(len(x)):
x[i].value = ig[i]
x[i].lower = lb[i]
x[i].upper = ub[i]
m.Equations([powerf(x) == np.zeros(4,)])
m.Obj(x[0])
m.solve()