Why Gekko can't find a solution given variables initial values

Viewed 159

I have an optimization problem that I'm trying to solve using Gekko. When I'm setting initial values for the variables, with values of a possible solution, which satisfied the constrains, Gekko can't find a solution. How can I find the root cause?

I'm getting this error:

Error: Exception: Access Violation
At line 1341 of file MUMPS/src/dmumps_part2.F
Traceback: not available, compile with -ftrace=frame or -ftrace=full

Error: 'results.json' not found. Check above for additional error details
did not managed to solve
((1)*((d_t200_3_1-d_t100_3_1)))

Here is the optimization model I'm running

m = GEKKO(remote=False)
m.options.MAX_ITER=1000
m.options.IMODE=3 

d_t200_3_0 = m.Var(540, name='d_t200_3_0')
d_t200_3_2 = m.Var(180, name='d_t200_3_2')
d_t200_3_1 = m.Var(360, name='d_t200_3_1')
d_t100_3_0 = m.Var(60, name='d_t100_3_0')
d_t100_3_2 = m.Var(20, name='d_t100_3_2')
d_t100_3_1 = m.Var(40, name='d_t100_3_1')
m.Equation(m.abs2(d_t100_3_0) >= 0.0)
m.Equation(200 > m.abs2(d_t100_3_0))
m.Equation(m.abs2(d_t100_3_2) >= 0.0)
m.Equation(200 > m.abs2(d_t100_3_2))
m.Equation(m.abs2(d_t100_3_1) >= 0.0)
m.Equation(200 > m.abs2(d_t100_3_1))
m.Equation(m.abs2(-1.0*m.abs2(d_t100_3_0) - -1.0*m.abs2(d_t100_3_2)) >= 0.0)
m.Equation(200 > m.abs2(-1.0*m.abs2(d_t100_3_0) - -1.0*m.abs2(d_t100_3_2)))
m.Equation(m.abs2(-1.0*m.abs2(d_t100_3_0) - -1.0*m.abs2(d_t100_3_1)) >= 0.0)
m.Equation(200 > m.abs2(-1.0*m.abs2(d_t100_3_0) - -1.0*m.abs2(d_t100_3_1)))
m.Equation(m.abs2(-1.0*m.abs2(d_t100_3_2) - -1.0*m.abs2(d_t100_3_1)) >= 0.0)
m.Equation(200 > m.abs2(-1.0*m.abs2(d_t100_3_2) - -1.0*m.abs2(d_t100_3_1)))
m.Equation(m.abs2(d_t200_3_0) >= 200.0)
m.Equation(600 > m.abs2(d_t200_3_0))
m.Equation(m.abs2(d_t200_3_2) >= 0.0)
m.Equation(200 > m.abs2(d_t200_3_2))
m.Equation(m.abs2(d_t200_3_1) >= 200.0)
m.Equation(400 > m.abs2(d_t200_3_1))
m.Equation(m.abs2(-1.0*m.abs2(d_t200_3_0) - -1.0*m.abs2(d_t200_3_2)) >= 200.0)
m.Equation(400 > m.abs2(-1.0*m.abs2(d_t200_3_0) - -1.0*m.abs2(d_t200_3_2)))
m.Equation(m.abs2(-1.0*m.abs2(d_t200_3_0) - -1.0*m.abs2(d_t200_3_1)) >= 0.0)
m.Equation(200 > m.abs2(-1.0*m.abs2(d_t200_3_0) - -1.0*m.abs2(d_t200_3_1)))
m.Equation(m.abs2(-1.0*m.abs2(d_t200_3_2) - -1.0*m.abs2(d_t200_3_1)) >= 0.0)
m.Equation(200 > m.abs2(-1.0*m.abs2(d_t200_3_2) - -1.0*m.abs2(d_t200_3_1)))

m.Obj(d_t200_3_2 - d_t100_3_2)
m.solve(debug =1, disp=True)

When solving this without initials values, I get a solution, but there is sometimes inconsistency, i.e. different solution for the same problem. Any hint why this could happen? I thought that there is some random initiation and the seed is changing, but according to the documentation the initial default values are 0.

Thanks!

Just to update that I didn't found the problem yet, but if looking on a subset of the optimization variables and corresponding constrains, I do able to get the optimization results. here is the subset:

d_t200_1_0 = m.Var(180, name='d_t200_1_0')
d_t200_1_2 = m.Var(180, name='d_t200_1_2')
d_t100_1_0 = m.Var(20, name='d_t100_1_0')
d_t100_1_2 = m.Var(20, name='d_t100_1_2')
m.Equation(m.abs2(d_t100_1_0) >= 0.0)
m.Equation(200 > m.abs2(d_t100_1_0))
m.Equation(m.abs2(d_t100_1_2) >= 0.0)
m.Equation(200 > m.abs2(d_t100_1_2))
m.Equation(m.abs2(-1.0*m.abs2(d_t100_1_0) - 1.0*m.abs2(d_t100_1_2)) >= 0.0)
m.Equation(200 > m.abs2(-1.0*m.abs2(d_t100_1_0) - 1.0*m.abs2(d_t100_1_2)))
m.Equation(m.abs2(d_t200_1_0) >= 0.0)
m.Equation(200 > m.abs2(d_t200_1_0))
m.Equation(m.abs2(d_t200_1_2) >= 0.0)
m.Equation(200 > m.abs2(d_t200_1_2))
m.Equation(m.abs2(-1.0*m.abs2(d_t200_1_0) - 1.0*m.abs2(d_t200_1_2)) >= 200.0)
m.Equation(400 > m.abs2(-1.0*m.abs2(d_t200_1_0) - 1.0*m.abs2(d_t200_1_2)))

1 Answers

Switching over to abs3() helps to solve the problem. Also, some of the equations are not needed because they are always satisfied.

from gekko import GEKKO
m = GEKKO(remote=False)
m.options.MAX_ITER=1000
m.options.IMODE=3 

d_t200_3_0 = m.Var(540, name='d_t200_3_0')
d_t200_3_2 = m.Var(180, name='d_t200_3_2')
d_t200_3_1 = m.Var(360, name='d_t200_3_1')
d_t100_3_0 = m.Var(60, name='d_t100_3_0')
d_t100_3_2 = m.Var(20, name='d_t100_3_2')
d_t100_3_1 = m.Var(40, name='d_t100_3_1')

# these equations are not needed
# all values will satisfy the equation
#m.Equation(m.abs3(d_t100_3_0) >= 0.0)
#m.Equation(m.abs3(d_t100_3_2) >= 0.0)
#m.Equation(m.abs3(d_t100_3_1) >= 0.0)
#m.Equation(m.abs3(d_t200_3_2) >= 0.0)

# reform to eliminate absolute value with simple inequalities
#m.Equation(200 > m.abs3(d_t100_3_0))
#m.Equation(200 > m.abs3(d_t100_3_2))
#m.Equation(200 > m.abs3(d_t100_3_1))
#m.Equation(200 > m.abs3(d_t200_3_2))
#m.Equation(600 > m.abs3(d_t200_3_0))
#m.Equation(400 > m.abs3(d_t200_3_1))
v = [d_t100_3_0,d_t100_3_2,d_t100_3_1,d_t200_3_2,d_t200_3_0,d_t200_3_1]
b = [200,200,200,200,600,400]
for i,vi in enumerate(v):
    vi.LOWER = -b[i]
    vi.UPPER =  b[i]

m.Equation(m.abs3(d_t200_3_0) >= 200.0)
m.Equation(m.abs3(d_t200_3_1) >= 200.0)
m.Equation(m.abs3(-1.0*m.abs3(d_t100_3_0) - -1.0*m.abs3(d_t100_3_2)) >= 0.0)
m.Equation(200 > m.abs3(-1.0*m.abs3(d_t100_3_0) - -1.0*m.abs3(d_t100_3_2)))
m.Equation(m.abs3(-1.0*m.abs3(d_t100_3_0) - -1.0*m.abs3(d_t100_3_1)) >= 0.0)
m.Equation(200 > m.abs3(-1.0*m.abs3(d_t100_3_0) - -1.0*m.abs3(d_t100_3_1)))
m.Equation(m.abs3(-1.0*m.abs3(d_t100_3_2) - -1.0*m.abs3(d_t100_3_1)) >= 0.0)
m.Equation(200 > m.abs3(-1.0*m.abs3(d_t100_3_2) - -1.0*m.abs3(d_t100_3_1)))
m.Equation(m.abs3(-1.0*m.abs3(d_t200_3_0) - -1.0*m.abs3(d_t200_3_2)) >= 200.0)
m.Equation(400 > m.abs3(-1.0*m.abs3(d_t200_3_0) - -1.0*m.abs3(d_t200_3_2)))
m.Equation(m.abs3(-1.0*m.abs3(d_t200_3_0) - -1.0*m.abs3(d_t200_3_1)) >= 0.0)
m.Equation(200 > m.abs3(-1.0*m.abs3(d_t200_3_0) - -1.0*m.abs3(d_t200_3_1)))
m.Equation(m.abs3(-1.0*m.abs3(d_t200_3_2) - -1.0*m.abs3(d_t200_3_1)) >= 0.0)
m.Equation(200 > m.abs3(-1.0*m.abs3(d_t200_3_2) - -1.0*m.abs3(d_t200_3_1)))

m.Minimize(d_t200_3_2 - d_t100_3_2)
m.solve(disp=True)

This gives a successful solution.

 --------- APM Model Size ------------
 Each time step contains
   Objects      :  0
   Constants    :  0
   Variables    :  172
   Intermediates:  0
   Connections  :  0
   Equations    :  129
   Residuals    :  129
 
 Number of state variables:    172
 Number of total equations: -  128
 Number of slack variables: -  90
 ---------------------------------------
 Degrees of freedom       :    -46
 
 * Warning: DOF <= 0
 ----------------------------------------------
 Steady State Optimization with APOPT Solver
 ----------------------------------------------
Iter:     1 I:  0 Tm:      0.02 NLPi:    8 Dpth:    0 Lvs:    3 Obj: -2.00E+02 Gap:       NaN
--Integer Solution:  -2.00E+02 Lowest Leaf:  -2.00E+02 Gap:   0.00E+00
Iter:     2 I:  0 Tm:      0.02 NLPi:    1 Dpth:    1 Lvs:    3 Obj: -2.00E+02 Gap:  0.00E+00
 Successful solution
 
 ---------------------------------------------------
 Solver         :  APOPT (v1.0)
 Solution time  :  0.0469 sec
 Objective      :  -200.0000000002
 Successful solution
 ---------------------------------------------------
Related