import numpy as np
from scipy.optimize import minimize, Bounds
def func(x):
return np.sum(np.sqrt(x))
def con(x):
return 1000 - np.sum(x * np.arange(1, 101))
con1 = {'type': 'ineq', 'fun': lambda x: 10 - x[0]}
con2 = {'type': 'ineq', 'fun': lambda x: 20 - x[0] - 2 * x[1]}
con3 = {'type': 'ineq', 'fun': lambda x: 30 - x[0] - 2 * x[1] - 3 * x[2]}
con4 = {'type': 'ineq', 'fun': lambda x: 40 - x[0] - 2 * x[1] - 3 * x[2] - 4 * x[3]}
con5 = {'type': 'ineq', 'fun': con}
cons = [con1, con2, con3, con4, con5]
bounds = Bounds([0] * 100, np.inf * 100)
x0 = np.zeros(100)
res = minimize(func, x0, constraints=cons, bounds=bounds)
print(res.x)
print(res.fun)