def dfunc(pos, t): ''' in a in-progress graph dfunc is used to dynamically compute a distance equivalent to parameter 't' at position 'pos' estimated given k nearest sampled points ''' [dist, idx] = posvtree.query(pos, k=123) v = [posv['v'][i] for i in idx] v = np.median(v) return v * t posv = {'pos': list(EV.apply(mid, axis=1)), 'v': list(EV.apply(speed, axis=1))} posvtree = spatial.cKDTree(posv['pos']) g = mlaterationgraph(dfunc=dfunc) for i, v in V.iterrows(): g.add_position(v.numr_cell, [v.lon, v.lat]) if (i % 1000 == 0): print 'load positions to graph : ', i, '/', len(V) for i, e in E.iterrows(): g.add_edge(e.numr_cell, e.nnumr_cell, e.dt) if (i % 1000 == 0): print 'load edges to graph : ', i, '/', len(E) g.step = 100 g.solve(complete=True) with open(tsv('ngaude_cell_graph_computing_vertex'), 'a') as f:
def dfunc(pos,t): ''' in a in-progress graph dfunc is used to dynamically compute a distance equivalent to parameter 't' at position 'pos' estimated given k nearest sampled points ''' [dist,idx] = posvtree.query(pos, k = 123) v = [posv['v'][i] for i in idx] v = np.median(v) return v*t posv = { 'pos' : list(EV.apply(mid, axis = 1)), 'v' : list(EV.apply(speed, axis = 1)) } posvtree = spatial.cKDTree(posv['pos']) g = mlaterationgraph(dfunc = dfunc) for i,v in V.iterrows(): g.add_position(v.numr_cell, [v.lon,v.lat]) if (i%1000 == 0): print 'load positions to graph : ',i,'/',len(V) for i,e in E.iterrows(): g.add_edge(e.numr_cell, e.nnumr_cell, e.dt) if (i%1000 == 0): print 'load edges to graph : ',i,'/',len(E) g.step = 100 g.solve(complete=True) with open(tsv('ngaude_cell_graph_computing_vertex'), 'a') as f:
# -*- coding: utf-8 -*- """ Created on Thu Dec 18 21:04:43 2014 @author: ngaude """ from mlateration import mlaterationgraph import math import random import matplotlib.pyplot as plt random.seed(123456) g = mlaterationgraph() for i in range(40): while True: x = random.randint(1, 10) y = random.randint(1, 10) u = (x, y) if not u in g.pos: break g.add_position(u, [x, y]) for i in range(500): noise = 0.005 while True: xy = [random.randint(1, 10) for i in range(4)] d = math.sqrt(math.pow(xy[0] - xy[2], 2) + math.pow(xy[1] - xy[3], 2)) d = d * (1.0 + random.uniform(-noise, noise))
Created on Thu Dec 18 21:04:43 2014 @author: ngaude """ from mlateration import mlaterationgraph import math import random import matplotlib.pyplot as plt random.seed(123456) g = mlaterationgraph() for i in range(40): while True: x = random.randint(1, 10) y = random.randint(1, 10) u = (x, y) if not u in g.pos: break g.add_position(u, [x, y]) for i in range(500): noise = 0.005 while True: xy = [random.randint(1, 10) for i in range(4)] d = math.sqrt(math.pow(xy[0] - xy[2], 2) + math.pow(xy[1] - xy[3], 2)) d = d * (1.0 + random.uniform(-noise, noise))