Hello, Tiago
Thanks for the advice. I follow your instruction converting the iterative
object into a python list as shown in global function
'find_multi_path(g,source,target)'. Then, everything works fine as the
following.
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 9 09:47:40 2018
"""
import multiprocess as mp
import graph_tool.all as gt
import numpy as np
g = gt.price_network(20, m = 2, directed = False)
valid_paths = g.new_vertex_property("object")
g.vertex_properties["valid_paths"] = valid_paths
def find_multi_path(g,source,target):
res = []
#distance =
gt.shortest_distance(g=graph,source=g.vertex(source_index),target=g.vertex(dest_index),weights=delay)
#paths = gt.all_paths(self.g,source=source_index,target=dest_index,
cutoff = 5)
#growth with the O(V!)
paths = gt.all_shortest_paths(g,source = source, target = target)
for p in paths:
res.append(p)
return res
Cloudlet = []
Gateway = []
for v in g.vertices():
if np.random.rand() > 0.5:
Cloudlet.append(v)
else:
Gateway.append(v)
pool = mp.Pool(processes=4)
for v in Gateway:
valid_paths[v] = pool.map(lambda x: find_multi_path(g = g, source =
g.vertex_index[v], target = x),[g.vertex_index[c] for c in Cloudlet])
*Nevertheless, the unpickled problem still exists as if I encapsulate the
graph object into a class.* The following is an example.
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 9 09:47:40 2018
"""
import multiprocess as mp
import graph_tool.all as gt
import numpy as np
def find_multi_path(g,source,target):
res = []
#distance =
gt.shortest_distance(g=graph,source=g.vertex(source_index),target=g.vertex(dest_index),weights=delay)
#paths = gt.all_paths(self.g,source=source_index,target=dest_index,
cutoff = 5)
#growth with the O(V!)
paths = gt.all_shortest_paths(g,source = source, target = target)
for p in paths:
res.append(p)
return res
class Network:
def __init__(self):
self.g = gt.price_network(20, m = 2, directed = False)
self.Cloudlet = []
self.Gateway = []
self.valid_paths = self.g.new_vertex_property("object")
self.g.vertex_properties["valid_paths"] = self.valid_paths
def test(self):
for v in self.g.vertices():
if np.random.rand() > 0.5:
self.Cloudlet.append(v)
else:
self.Gateway.append(v)
pool = mp.Pool(processes=4)
for v in self.Gateway:
self.valid_paths[v] = pool.map(lambda x: find_multi_path(g =
self.g, source = self.g.vertex_index[v], target = x),[self.g.vertex_index[c]
for c in self.Cloudlet])
n = Network()
n.test()
The Python compiler again says
RuntimeError: Pickling of "graph_tool.libgraph_tool_core.Vertex" instances
is not enabled (http://www.boost.org/libs/python/doc/v2/pickle.html)
Wish you all the best,
Percy