Category : minimize

So this is my code. I am trying to minimize an objective function. I have two variables and three constraints. The second constraint is creating an infeasibility problem: import sys import pandas as pd !pip install -i https://pypi.gurobi.com/ gurobipy from gurobipy import * def a(): model = Model() return model def readFile(): f = pd.ExcelFile("y.xlsx") ..

Read more

When I use fmin_l_bfgs_b method, the code terminated after iteration=1. Sometimes I got a Warning: Warning: more than 10 function and gradient evaluations in the last line search. Termination may possibly be caused by a bad search direction. Sometimes, the code run until itration=100 as long as I set iprint=101 in fmin_l_bfgs_b. but more frequently ..

Read more

hi im trying to minimize a simple 3 variable function with some range costraints in the x variables .. but im getting ‘Inequality constraints incompatible – any idea ? thanks !! from scipy.optimize import minimize def f(x): return (int(558*x[0]*x[1]*x[2])-(x[2]*(558-int(558*x[0])))-(x[2]*558)) x0 = [0.4, 1.0, 2.0] #real data Ranges #x[0] 0..1 #x[1] 1..3 #x[2] 5..50 cons=( {‘type’: ..

Read more

I have a equity portfolio optimization (scipy optimizer > minimize) and want to set a constraint that restricts the number of stocks (nosec = 50) in the portfolio. I tried the following constraint: constr_nosec = {‘type’: ‘eq’, ‘fun’: lambda weights: (nosec – sum(1 for x in weights if x > 0.0000001))} Unfortunately, the optimization does ..

Read more