I am trying to solve a MINLP problem using gekko. My code is the following:
m = GEKKO(remote = False)
m.options.SOLVER = 3
m.solver_options = ['minlp_maximum_iterations 500', \
# minlp iterations with integer solution
'minlp_max_iter_with_int_sol 10', \
# treat minlp as nlp
'minlp_as_nlp 0', \
# nlp sub-problem max iterations
'nlp_maximum_iterations 50', \
# 1 = depth first, 2 = breadth first
'minlp_branch_method 1', \
# maximum deviation from whole number
'minlp_integer_tol 0.05', \
# covergence tolerance
'minlp_gap_tol 0.01']
rows = nb_phases + 3*b_max*(nb_phases+1)
x = np.empty(rows,dtype=object)
for i in range(3*nb_phases*b_max+nb_phases+1):
x[i] = m.Var(value = xinit[i], lb = LB[i], ub = UB[i], integer = False)
for i in range(3*nb_phases*b_max+nb_phases+1, (3*nb_phases+3)*b_max+nb_phases):
x[i] = m.Var(value = xinit[i], lb = LB[i], ub = UB[i], integer = True)
# Constraints
m.axb(A,B,x,etype = '<=',sparse=False)
m.axb(A_eq,B_eq,x,etype = '=',sparse=False)
# Objective Function
f = objective_fun(x, t, ob, jofbuses, q, qc, s, oa, k, l, T, G_next, C, Y, G_previous)
m.Obj(f)
#Solver
m.solve(disp = False)
I get the following exception:
Exception message: Read option: "minlp_maximum_iterations". It is not a valid option. Check the list of available options.
And I get the same exception for all the other options.
I tried changing the solver to m.options.solver = 1 but then I get the error:
Error: Exception: Acess Violation Traceback: not available, compile with -ftrace=frame or -ftrace=full Error: 'results.json' not found.
The 'objective_fun' function I call in the code above is the following:
def objective_fun(x, t, ob, jofbuses, q, qc, s, oa, k, l, T, G_next, C, Y, G_previous):
nb_phases = len(G_next)
b_max = len(t)
no_lanegroups = len(q)
obj = 0
G = x[0:nb_phases]
for j in range(no_lanegroups):
delay_a = 0.5*q[j]/(1-q[j]/s[j]) * (pow((sum(G_previous[l[j]:nb_phases]) + sum(G[0:k[j]-1]) + sum(Y[l[j]-1:nb_phases]) + sum(Y[0:k[j]-1])),2) + pow(sum(G[l[j]:nb_phases]) + sum(G_next[0:k[j]-1]) + sum(Y[l[j]-1:nb_phases]) + sum(Y[0:k[j]-1]),2))
obj = obj + oa*delay_a
for b in range(b_max):
delay_b1 = x[(3*nb_phases+1)*b_max + nb_phases + b]*(q[jofbuses[b]-1]/s[jofbuses[b]-1] * (t[b] - (T-1)*C + sum(G_previous[l[jofbuses[b]-1]:nb_phases]) + sum(Y[l[jofbuses[b]-1] -1:nb_phases])) + (T-1)*C - t[b] + sum(Y[0:k[jofbuses[b]-1]-1]))
delay_b2 = x[(3*nb_phases+2)*b_max + nb_phases + b-1]*(q[jofbuses[b]-1]/s[jofbuses[b]-1] * (t[b] - (T-1)*C - sum(Y[0:l[jofbuses[b]-1]-1])) + T*C + sum(G_next[0:k[jofbuses[b]-1]-1]) + sum(Y[0:k[jofbuses[b]-1]-1]) - t[b])
delay_b3 = sum(x[nb_phases*b_max + nb_phases*b:nb_phases*b_max + nb_phases*b+k[jofbuses[b]-1]-1]) - q[jofbuses[b]-1]/s[jofbuses[b]-1]*sum(x[2*nb_phases*b_max + nb_phases*b:2*nb_phases*b_max + nb_phases*b +l[jofbuses[b]-1]])
delay_b = delay_b1+delay_b2 +delay_b3
obj = obj + delay_b*ob[b]
return obj
Furthermore, if I don't specify the options, I can run the code and find a successful solution. However some elements of the x array should be integers but the solution I get doesn't respect this condition.
Can you help me figure out how to solve these issues? Thanks a lot !
The option minlp_maximum_iterations
is not one of the available options for the IPOPT solver. You correctly discovered that switching to m.options.SOLVER=1
(APOPT solver) resolves this error.
The solver is not finding a solution. I recommend an initialization strategy to first solve with IPOPT without the options. Next, solve again with the APOPT options to see if the IPOPT non-integer solution helps as a starting point to find the optimal integer solution.