Код: Выделить всё
from scipy import optimize
from math import log
bounds = ((0, 1), (0, 1), (0, 1), (0, 1))
def finite_resources(x):
return x[0] + x[2] - 1
cons = ({'type': 'eq', 'fun': finite_resources})
def global_satisfaction(x):
return -(log(1+x[0])/(1+x[1]*10000) + log(1+x[2])/(1+x[3]*10000))
results = dict()
print(optimize.shgo(global_satisfaction, bounds, constraints=cons))
Код: Выделить всё
message: Optimization terminated successfully.
success: True
fun: -1.3862943611198906
funl: [-1.386e+00]
x: [ 1.000e+00 0.000e+00 1.000e+00 0.000e+00]
xl: [[ 1.000e+00 0.000e+00 1.000e+00 0.000e+00]]
nit: 1
nfev: 18
nlfev: 5
nljev: 1
nlhev: 0
Я не решаюсь сообщить о проблеме на Github scipy.
Подробнее здесь: https://stackoverflow.com/questions/792 ... constraint
Мобильная версия