After carefully debugging, I come up with a solution to this issue. It seems
the class member may behave differently from normal functions. The following
example works in small-scale networks.
#!/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(self.g.vertex_index[v])
else:
self.Gateway.append(self.g.vertex_index[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 = v, target = x),self.Cloudlet)
n = Network()
n.test()
Are there any suggestions for this phenomenon?
Best,
Percy
--
Sent from:
http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
_______________________________________________
graph-tool mailing list
[email protected]
https://lists.skewed.de/mailman/listinfo/graph-tool