I'm trying to solve an optimization problem using scipy. There's a huge database that I re-arranged in order to use some of the rows as parameters in the optimization problem. Then I take the sum of each entry and multiply by x variables in order to create constraints that must be greater than "arb" (which is just a new single variable). When I try to solve it I get TypeError: constraint1() missing 2 required positional arguments: 'x' and 'row1'.
path = r'mypath/*.csv'
#Extract data
all_rec = iglob(path, recursive=True)
df = (pd.read_csv(f, usecols=[4]) for f in all_rec)
list = pd.concat(df, axis=1, ignore_index=True)
#Extract arrays
t=0
row1 = list.iloc[t+5] - list.iloc[t]
row2 = list.iloc[t+10] - list.iloc[t]
row3 = list.iloc[t+15] - list.iloc[t]
row4 = list.iloc[t+20] - list.iloc[t]
#LP Problem
def objective(arb, sign=-1.0):
return sign*arb
def constraint1(arb,x,row1):
for i in range(len(list.columns)):
sum_cons1 = sum(row1[i]*x[i]) - arb
return sum_cons1
def constraint2(arb,x,row2):
for i in range(len(list.columns)):
sum_cons2 = sum(row2[i]*x[i]) - arb
return sum_cons2
def constraint3(arb,x,row3):
for i in range(len(list.columns)):
sum_cons3 = sum(row3[i]*x[i]) - arb
return sum_cons3
def constraint4(arb,x,row4):
for i in range(len(list.columns)):
sum_cons4 = sum(row4[i]*x[i]) - arb
return sum_cons4
con1 = {'type': 'ineq', 'fun': constraint1}
con2 = {'type': 'ineq', 'fun': constraint2}
con3 = {'type': 'ineq', 'fun': constraint3}
con4 = {'type': 'ineq', 'fun': constraint4}
cons = ([con1,con2,con3,con4])
solution = minimize(objective,x0=2500.0,method='SLSQP',constraints=cons)
print(solution)