Grasshopper Scripts for Network Connectivity

Feb, 2017

Network Connectivity is a method that use Graph Theory to solve spatial problems. I developed a series of Grasshopper tools to calculate Network Connectivity Measures. These measures can be used to find closest routes, most central nodes, most connected routes, least cost path, etc. Since all tools were written as Python language, they are highly customizable and can extend to many other usages. import rhinoscriptsyntax as rs
import ghpythonlib.components as gh

for l in nt_lines:
#get the start and end point index from nt_pts
st=rs.CurveStartPoint(l)
st_index= rs.PointArrayClosestPoint(nt_pts,st)
ed=rs.CurveEndPoint(l)
ed_index=rs.PointArrayClosestPoint(nt_pts,ed)
#add edge based on start/end pts
#build a library, with a road as key; the start and end index are the values.
nt_lib[l]=[st_index,ed_index]
#nt_line[(st_index,ed_index)]=l
#G[st_index][ed_index]['weight'] = rs.CurveLength(l)

def get_weight(nt_l):
length=rs.CurveLength(nt_l)
return length

c= list(nt_lib[nt_lines])
for i in nt_lines:
indexs=list(nt_lib[i])
st_ind=indexs
#print indexs
#print rs.CurveLength(i)
ed_ind=indexs
#print ed_ind
G[st_ind][ed_ind]['weight'] = get_weight(i)

# convert the input vertex indices and convert them to topology indices
from_v = start_end
to_v = start_end

def get_shortest_path(from_v,to_v):
topology_list = nx.shortest_path(G, from_v, to_v, True)
print topology_list
p_list=[]
for i in range(1,len(topology_list)):
try:
except:
pass
return p_list

a=get_shortest_path(from_v,to_v)

import itertools as it
vet_combinations= list(it.combinations(multi_pts,2))

path_list=[]
for i in vet_combinations:
from_i = i
to_i = i
path_list.append(get_shortest_path(from_i,to_i))

b=path_list
print b