I am using the SLSQP algorithm for an minimization problem.
Here is my code:
import pandas as pd
import numpy as np
from scipy.optimize import minimize, Bounds
df = pd.DataFrame(np.random.rand(750,5),columns=['pred','var1','start'])
def obj(x,df=df):
return -(x*df['pred']).sum()
def c1(x,df=df):
return abs((x*df['var1']).sum())-0.05
def c2(x):
return sum(x)
def c3(x):
return 2-sum(abs(x))
sol = minimize(
fun=er,
x0=df['start'],
method='SLSQP',
bounds=Bounds(-1, 3),
constraints=[{'type': 'ineq', 'fun': c1},{'type': 'eq', 'fun': c2},{'type': 'eq', 'fun': c3}],
options={'maxiter': 1000})
I don't think that this can be rewritten as an LP because c3 has an absolute value function.
Open to any other ideas.