First of all I need to use map function in python and not comprehensions to implement multiprocessing.
My initial version of a list comprehension is as follows
t3List = [x for x in rowCost if ( cost[t1][t2]+cost[rowCost.index(x)][tour[ tour.index(rowCost.index(x)) - 1 ] ]-cost[t2][rowCost.index(x)]-cost[t1][tour[ tour.index(rowCost.index(x)) - 1 ] ]>0 and rowCost.index(x) !=t1 and rowCost.index(x) != t2 and rowCost.index(x) != tour[ tour.index(t2)+1] and x<cost[t1][t2] ) ]
For more understanding t1
and t2
are just vertices. eg values of t1
,t2
are 34,21 respectively.
rowcost
is a list which contains distances from one vertex to every other vertex.
tour
is just some order of vertices in which I have to travel ( basically I m solving tsp )
Here all variables are local. cost
is like just a symmetric cost matrix of all vertices.
For huge number of vertices this list is taking 0.5 to 1 sec to compute. So I planned to implement multiprocessing after seeing this
I understood that map function takes first argument as a function.
But to implement above comprehension this function has to have multiple parameters as all the variables are local.
How to solve this problem? Any help hugely appreciated.