I a trying to minimize and maximize a random 'test function' using gekko which is connected to A. A consists of 4 parameters between the range (0-100) and sum of A < 100.However I keep getting weird results,because the minimum of the test function is supposed to be 2500 and the max 10000. My code is below.Can anyone tell me where the problem is? Thanks in advance
import numpy as np
from gekko import GEKKO
def test_function(x):
return np.dot(x, x)
A = m.Array(m.Var, (4))
# initial guess
ig = [1, 5, 5, 1]
# lower bounds
i = 0
for Ai in A:
Ai.value = ig[i]
Ai.lower = 0
Ai.upper = 100
i += 1
m.Equation(np.sum(A) < 100)
m.Obj(test_function(A))
m.solve()
print(test_function(A))
print (A)
results
Solver : IPOPT (v3.12)
Solution time : 1.379999999971915E-002 sec
Objective : 4.141037033873033E-007
Successful solution
---------------------------------------------------
(((((v1)*(v1))+((v2)*(v2)))+((v3)*(v3)))+((v4)*(v4)))
[[0.00042734466188] [0.00015629584657] [0.00015629584657]
[0.00042734466188]]
Process finished with exit code 0