2017-09-14 8 views
0

J'ai un problème en essayant de planifier ce qui suit. Il semble y avoir une erreur dans la boucle for. En particulier dans cette partie: mM[iRow,j] = p[k]. Mais je ne comprends pas ce qui ne va pas.IndexError: l'index 2 est hors limites pour l'axe 0 avec la taille 2 (List Scheduling)

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 

Répondre

0

La longueur de votre tableau de p est 4 et que vous incrémente k chaque fois qu'il est dans la condition if. Vous devez ajouter une vérification dans votre condition if ou réinitialiser k dans la boucle externe.

Par exemple:

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