Am o problemă atunci când încerc să programez următoarele. Se pare că există o eroare în bucla for. În special în această parte: mM[iRow,j] = p[k]
.dar nu înțeleg ce este în neregulă.
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
1 răspunsuri
Lungimea matricei tale p este 4 și incrementezi k de fiecare dată când ajunge în condiția if. Trebuie fie să adăugați o verificare în condiția if, fie să resetați k în bucla exterioară.
De exemplu:
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