I'm solving a non-linear optimization problem with Gekko in a loop and want to use the prior solution to initialize the next solution. I've created a simplified the problem with the code below to show the issue.
from gekko import GEKKO
m = GEKKO() # Initialize gekko
# Initialize variables
x1 = m.Var(value=1,lb=1,ub=5)
x2 = m.Var(value=5,lb=1,ub=5)
# Equations
m.Equation(x1==x2*2)
m.Equation(x1**2+x2**2==10)
m.Obj(x1*x2) # Objective
m.options.solver=1
m.solve(disp=False) # Solve
print('Iterations: ' + str(m.options.iterations))
print(x1.value[0], x2.value[0])
print('Objective: ' + str(m.options.objfcnval))
m.solve(disp=False) # Solve again
print('Iterations: ' + str(m.options.iterations))
print(x1.value[0], x2.value[0])
print('Objective: ' + str(m.options.objfcnval))
The console prints:
Iterations: 5
2.8284271334 1.4142135667
Objective: 4.0000000245
Iterations: 5
2.8284271334 1.4142135667
Objective: 4.0000000245
The values of x1 and x2 return to the initial guesses of 1 and 5 before the "Solve again" attempt. I tried x1.value = x1.value but this returns RecursionError: maximum recursion depth exceeded. What is the right way to initialize values from a prior solution in Gekko?