How to write sum starting from 5
AnsweredI have data on the number of nurses 21, but the used in the equation starts from nurse 5, with n = 1,2,3,...,N and the sequence 1,2,3,4 is the senior nurse (T). If i=N-T then written in programming?
T = np.loadtxt("Kepala jaga.txt")
###
D = hari.shape[0] #Jumlah Hari
print('D:',D)
N = perawat.shape[0] #Jumlah perawat
print('N:',N)
S = shift.shape[0] #Shift
print('S:',S)
# Membuat Model
m = gp.Model("BnB")
# Variabel Keputusan
x = m.addVars(N,D,S, vtype=GRB.BINARY, name="x")
# Fungsi Tujuan
m.setObjective((sum(sum(x[n,d,1]))**2/17-((sum(sum(x[n,d,1])))/17)**2 for i in range(N) for d in range (D)) + (sum(sum(x[n,d,2]))**2/17-((sum(sum(x[n,d,2])))/17)**2 for n in range(N-T) for d in range (D)) + (sum(sum(x[n,d,3]))**2/17-((sum(sum(x[n,d,3])))/17)**2 for n in range(N-T) for d in range (D)) + (sum(sum(x[n,d,4]))**2/17-((sum(sum(x[n,d,4])))/17)**2 for n in range(N-T) for d in range (D)) , GRB.MINIMIZE)
because the results after running is
File d:\pemograman\untitled7.py:38
m.setObjective((sum(sum(x[n,d,1]))**2/17-((sum(sum(x[n,d,1])))/17)**2 for i in range(N) for d in range (D)) + (sum(sum(x[n,d,2]))**2/17-((sum(sum(x[n,d,2])))/17)**2 for n in range(N-T) for d in range (D)) + (sum(sum(x[n,d,3]))**2/17-((sum(sum(x[n,d,3])))/17)**2 for n in range(N-T) for d in range (D)) + (sum(sum(x[n,d,4]))**2/17-((sum(sum(x[n,d,4])))/17)**2 for n in range(N-T) for d in range (D)) , GRB.MINIMIZE)
TypeError: 'numpy.float64' object cannot be interpreted as an integer
0
-
Hi Laynufar,
To get a more accurate answer, we recommend that you provide the smallest example that can reproduce the error by itself.
Please see: Tutorial: Preparing a Minimal Reproducible ExampleThe following is a response based on my guess, and these are matters related to Python, not Gurobi:
- "TypeError: 'numpy.float64' object cannot be interpreted as an integer":
Your code contains numpy.float64 (possibly T). - Writing sum starting from 5:
You can use range(5,N).
Regards,
Ryuta1 - "TypeError: 'numpy.float64' object cannot be interpreted as an integer":
Please sign in to leave a comment.
Comments
1 comment