IndexError:索引2超出轴0的大小为2(列表调度)

时间:2017-09-14 12:01:48

标签: python-2.7 indexoutofboundsexception scheduling

我在尝试安排以下操作时遇到问题。 for循环中似乎有错误。特别是在这一部分:m=2 # machines n= 4 # number of jobs p= np.array([1,2,3,4]) # processing times iTimemax = np.sum(p) # Initialisation iTime = 0 k= 0 iRow = 0 # the iRowth job of the machine mM=np.zeros((n,m)) for i in range (iTimemax): for j in range (m): if np.sum(mM[:,j]) <= iTime: mM[iRow,j] = p[k] k = k + 1 # next job to be assigned iRow = iRow + 1 iTime = iTime +1 。 但我不明白出了什么问题。

git fetch    # get all new upstream commits

# bring master up to date
git checkout master
git merge    # equivalent to `git merge origin/master`

# bring newbranch up to date
git checkout newbranch
git merge master

1 个答案:

答案 0 :(得分:0)

p数组的长度为4,每次进入if条件时都会递增k。您需要在if条件中添加一个检查或在外循环中重置k。

例如:

import numpy as np
m=2  # machines
n= 4  # number of jobs
p= np.array([1,2,3,4])  # processing times
iTimemax = np.sum(p)

# Initialisation
iTime = 0
k= 0
iRow = 0  # the iRowth job of the machine
mM=np.zeros((n,m))
for i in range (iTimemax):
    for j in range (m):
        if np.sum(mM[:,j])  <= iTime and k < len(p):
            mM[iRow,j] = p[k]
            k = k + 1  # next job to be assigned
    iRow = iRow + 1
    iTime = iTime +1