I'm solving an integer nonlinear programming problem with python gekko, where there're 1446 integer variable, 31 constraints of the linear combinations of there variables, and 1 nonlinear objective to maximize.
The program takes a long time and I'm wondering if it can speed up, as well as how to tune a better m.solver_options.
Here're the codes.(I only leave some comments about the variables because their computation relies on some outer data files.)
m = GEKKO()
m.options.SOLVER = 1 # APOPT is an MINLP solver
# optional solver settings with APOPT
m.solver_options = ['minlp_maximum_iterations 500',
'minlp_as_nlp 0',
'minlp_branch_method 1',
'minlp_integer_tol 0',
'nlp_maximum_iterations 50',
]
# Constraint: sum of all weights <= 1
# e.g. weights = [0.04 * int_v1, 0.05 * int_v2, ..., 0.03 * int_v1446]
m.Equation(m.sum(weights) <= 1)
# Constraint: sum of weights on each cluster has an upper bound
# e.g. weights_per_cluster = {'1': [int_v2, int_v5, int_v8], '2': [int_v1, int_v4, int_v6], ..., '30': [int_v9, int_v12]}
for cluster in clusters:
m.Equation(m.sum(weights_per_cluster[cluster]) <= 0.1)
mu_sig_raw = np.array(mu_sig_raw).transpose() # real value, shape (106, 1446)
mu = np.mean(mu_sig_raw, axis=0) # real value, shape (1446, 1)
sigma = np.cov(np.transpose(mu_sig_raw)) # real value, shape (1446, 1446)
k = len(mu)
# Objective: profit-rate mean-variance model
m.Maximize(
(m.sum([mu[i] * weights[i] for i in range(k)]) - 0.03)
/
m.sqrt(m.sum([
m.sum([sigma[i, j] * weights[i] * weights[j] for j in range(k)])
for i in range(k)
]))
)
m.solve(disp=True)