The following MINLP problem returns Warning: no more possible trial points and no integer solution
. I believe this is wrong since at the very least b = [[1,0,0,1,0,0,1], [1,0,0,1,0,1,0]]
is a feasible point.
When switching to m.options.SOLVER=3
, I do get a reasonable non-integer solution. When I test the exact same script with a simpler objective function i.e., m.Obj(-sig[0][0])
, with m.options.SOLVER=1
Gekko finds an integer solution.
from gekko import GEKKO
import numpy as np
import pandas as pd
info_df = pd.DataFrame({'pos': ['qb', 'qb', 'rb', 'rb', 'wr', 'wr', 'wr'], 'cost': [30, 40, 15, 20, 20, 20, 30]})
budget = 80
mu_post = np.array([15, 16, 8, 9, 10, 14, 15])
n = mu_post.shape[0]
sigma_post = np.identity(n)
for i in range(n):
sigma_post[i][i] = i+1
def get_football_position_range(pos, df):
return (df[df['pos'] == pos].index[0], df[df['pos'] == pos].index[-1])
qb_index_range = get_football_position_range('qb', info_df)
rb_index_range = get_football_position_range('rb', info_df)
wr_index_range = get_football_position_range('wr', info_df)
# Number of lineups
N = 2
pi = 3.14159
eps = 1.0E-6
def normal_cdf(x, m):
return 1/(1+m.exp(-1.65451*x))
def normal_pdf(x, m):
return (1/((2*pi)**(.5)))*m.exp((x**2)/2)
def theta(s, m):
return m.sqrt(s[0][0]+s[1][1] - 2*s[0][1])
#################################################
#Integer Optimization Program
m = GEKKO(remote=False)
b = m.Array(m.Var,(N,n), lb=0, ub=1, integer=True, value = 1e-3)
# CONSTRAINT: Each Lineup must be less than budget
z = np.array([None for i in range(N)])
for i in range(N):
z[i] = m.Intermediate(sum(b[i, :]*list(info_df['cost'])))
m.Equations([z[i] <= budget for i in range(N)])
# CONSTRAINT: Each Lineup has one QB
z_1 = np.array([None]*N)
for i in range(N):
z_1[i] = m.Intermediate(sum(b[i, qb_index_range[0]: qb_index_range[1]+1]))
m.Equations([z_1[i] == 1 for i in range(N)])
# CONSTRAINT: Each Lineup has one RB
z_2 = np.array([None for i in range(N)])
for i in range(N):
z_2[i] = m.Intermediate(sum(b[i, rb_index_range[0]: rb_index_range[1]+1]))
m.Equations([z_2[i] == 1 for i in range(N)])
# CONSTRAINT: Each Lineup has one WR
z_3 = np.array([None for i in range(N)])
for i in range(N):
z_3[i] = m.Intermediate(sum(b[i, wr_index_range[0]: wr_index_range[1]+1]))
m.Equations([z_3[i] == 1 for i in range(N)])
# OBJECTIVE: Maximize
mu = b@mu_post
sig = b@sigma_post@b.T
inter = m.if3(theta(sig, m)-eps, .5*mu[0]+.5*mu[1],
(mu[0]*normal_cdf((mu[0]-mu[1])/theta(sig, m), m) + \
mu[1]*normal_cdf((mu[1]-mu[0])/theta(sig, m), m) + \
theta(sig, m)*normal_pdf((mu[0]-mu[1])/theta(sig, m), m)))
m.Obj(-inter)
m.options.SOLVER = 1
m.solve(debug=0, disp=True)
Note this is a follow up question to Gekko returning incorrect successful solution which was not completely specified.