Home > other >  The object is not iterable 'int' excuse me, where I went wrong?
The object is not iterable 'int' excuse me, where I went wrong?

Time:09-16

I want to use parallel computing all_fitness, serial works, but when parallel error is as follows:
Traceback (the most recent call last) :
The File "C: \ Users \ lq \ AppData \ Local \ designed \ Python \ Python36 \ lib \ multiprocessing \ pool py", line 119, the worker in
Result=(True, func (* args, * * KWDS))
File "C: \ Users \ lq \ AppData \ Local \ designed \ Python \ Python36 \ lib \ multiprocessing \ pool py", line 44, in mapstar
Return the list (map (* args))
The File "C: \ Users \ lq \ AppData \ Local \ designed \ Python \ Python36 \ lib \ defs py", line 8, in all_fitness
AllF [I]=([once function1 (P [I]), function2ce (P [I]) [0], function3 (P) [I]])
The File "C: \ Users \ lq \ AppData \ Local \ designed \ Python \ Python36 \ lib \ defs py", line 13, once function1 in
Return the sum (y)
TypeError: 'int' object is not iterable
"" "

The above exception was The direct cause of The following exception:

Traceback (the most recent call last) :
The File "& lt; Stdin>" , line 2, the in & lt; module>
The File "C: \ Users \ lq \ AppData \ Local \ designed \ Python \ Python36 \ lib \ multiprocessing \ pool py", line 266, in the map
Return the self. _map_async (func, iterable, mapstar, chunksize). The get ()
The File "C: \ Users \ lq \ AppData \ Local \ designed \ Python \ Python36 \ lib \ multiprocessing \ pool py", line 644, in the get
Raise the self. _value
TypeError: 'int' object is not iterable

Problem as follows:

Def all_fitness (P) :
AllF=[[] for I in range (len (P))]
For I in range (len (P)) :
AllF [I]=([once function1 (P [I]), function2ce (P [I]) [0], function3 (P) [I]])
Return allF


Def once function1 (y) :
Return the sum (y)

# Second function to optimize
Def function2ce (y) :
Rr=[0 for a in range (N)] # Rr as 01 variables,
Ere=[0 for a in range (N)]
Z=[[0 for a in range (M)] for a in range (N)] # 01 variables,
Ece=[0 for a in range (N)]
Z=[[] for I in range (N)]
D=[]
Ce=0
Md=35
For trip in range (N) :
If the tag] [trip - 1!=tag [trip] : re=md
Tre=Max (re, 0) # more than the actual electric
If tre<=0.3 * md: Rr [trip]=1
Ere [trip]=tre
For I in range (M) :
Z [trip] [I]=y Rr [trip] [I] * * D [trip] [I]
If the sum (Z] [trip - 1)!=0:
In the range for v (len] [trip - 1) (Z) :
If Z [trip - 1] [v]==1: Z] [trip - 1. Append (v)
D=kidis. Cell (trip - 1, choice (z] [trip - 1)). The value
Ejk=md - Ere [trip] + d * Qa
Re=tre + Ece] [trip - 1-2 * d * Qa - DJK [trip] * Qa
If d<=Ere [trip]/Qa:
Cijk=2 Qa * * A * d
The else:
Cijk=A * (Ere [trip] + d * Qa) + B * Qb * (d - Ere [trip]/Qa)
The else:
Ejk=0
Re=tre - DJK [trip] * Qa
Cijk=0
Ece [trip]=Ejk
Ce +=A * (Ere [trip - 1) + Ece] [trip - 1 - Ere [trip]) + B * Qb/Qa * (Ere [trip] - re) + Cijk
Return the ce, Z, Ece, Z

# Third function to optimize
The from datetime import datetime
The from XLRD import xldate_as_tuple
The from datetime import datetime, timedelta
Def function3 (y) :
The SPD=[[] for I in range (M)]
Lt=[[] for I in range (N)]
Dt=[[] for I in range (N)]
PD=[[] for I in range (M)]
Ece=[[] for I in range (M)] # ece
T=[[] for I in range (M)]
Q=[[] for I in range (M)]
Z3=function2ce (y) [1]
Z3=function2ce (y) [3]
Ece3=function2ce (y) [2]
NPD=0
For trip in range (N) :
Dt [trip]=datetime (* xldate_as_tuple (at [trip], 0))
If len (z3 [trip])!=0:
PD [z3 [trip] [0]]. Append (dt) [trip]
NPD +=1
Ece [z3 [trip] [0]]. Append (Ece3 [trip])
For I in range (M) :
T [I]=[0 for I in range (len (PD) [I])]
Q [I]=[0 for I in range (len (PD) [I])]
For I in range (M) :
The SPD [I]=sorted (PD) [I]
In the range for r (len (PD) [I]) :
For x in the range (len (lt) [I]) :
If the SPD [I] [r] If q [I] [r] & gt; [I] [r]=s: T=t0 * (0.5 + math.h floor ((q [I] [r] - s)/s))
Lt [I]. Append (SPD [I] [r] + timedelta (hours [I] [r])=T + timedelta (hours=ece [I] [r]/r))
Return the sum (the sum (T))/nPD # hours



If __name__=="__main__ ':
With the Pool (5) the as p:
F=p. ap (defs all_fitness, pos)



Code where I went wrong? Puzzled me for a long time, if someone can help answer really thank you very much!!!!!!

CodePudding user response:

What a mess.
What the hell is the pos at the far right after the last, which step assignment?

CodePudding user response:

The program with blocks of code enclosed please,,,
  • Related