0

目的関数の最大値を計算する予定です。私のコーディングは次のとおりです。

import numpy as np
from scipy.optimize import minimize

# this is my objective function
def objective(x,sign=-1.0):
    x1=x[0]
    x2=x[1]
    x3=x[2]
    x4=x[3]
    x5=x[4]
    x6=x[5]
    return sign*(sum(x1+x2+x3+x4+x5+x6)) # to get maximum by using '-1' sign

def constraint1(x):
    return 5900-(x[0]+x[1]+0.949*x[2]+0.933*x[3]+0.824*x[4]+0.519*x[5])
def constraint2(x):
    return 6000-(x[2]+x[3]+0.922*x[4]+0.619*x[5])
def constraint3(x):
    return 6450-(x[3]+0.969*x[4]+0.777*x[5])

b1=(0,600)
b2=(0,475)
b3=(0,450)
b4=(0,500)
b5=(0,825)
b6=(0,6800)
bnds=(b1,b2,b3,b4,b5,b6)
cons=[constraint1,constraint2,constraint3]

solution=minimize(objective,x0=None,method='Nelder-Mead', tol=1e-6,
              bounds=bnds,constraints=cons)

しかし、私はエラーが発生しました:

Traceback (most recent call last):
IndexError: index 1 is out of bounds for axis 0 with size 1

私は何をすべきか??? どうもありがとう。

4

1 に答える 1