当前位置: 首页>>代码示例>>Python>>正文


Python Graph.create_graph_from_list方法代码示例

本文整理汇总了Python中Graph.create_graph_from_list方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.create_graph_from_list方法的具体用法?Python Graph.create_graph_from_list怎么用?Python Graph.create_graph_from_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Graph的用法示例。


在下文中一共展示了Graph.create_graph_from_list方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: los_angeles

# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import create_graph_from_list [as 别名]
def los_angeles(parameters=None, delaytype='None', noise=0.0, path=None):
    """Generate small map of L.A. with 122 links and 44 modes
    """

    if not path:
        path = 'los_angeles_data_2.mat'
    data = sio.loadmat(path)

        
    links = data['links']
    ODs1, ODs2, ODs3, ODs4 = data['ODs1'], data['ODs2'], data['ODs3'], data['ODs4']
    if noise>0.0:
        ODs1 = [(o, d, normal(f, noise*f)) for o,d,f in ODs1]
        ODs2 = [(o, d, normal(f, noise*f)) for o,d,f in ODs2]
        ODs3 = [(o, d, normal(f, noise*f)) for o,d,f in ODs3]
        ODs4 = [(o, d, normal(f, noise*f)) for o,d,f in ODs4]
        links = [(s, t, r, normal(d, noise*d), c) for s,t,r,d,c in links]
      
    nodes = data['nodes']
    tmp = links
    links = []
    
    if delaytype=='Polynomial':
        theta = parameters
        degree = len(theta)
        for startnode, endnode, route, ffdelay, slope in tmp:            #print startnode, endnode, route, ffdelay, slope
            coef = [ffdelay*a*b for a,b in zip(theta, np.power(slope, range(1,degree+1)))]
            links.append((startnode, endnode, route, ffdelay, (ffdelay, slope, coef)))
    if delaytype=='Hyperbolic':
        a,b = parameters
        for startnode, endnode, route, ffdelay, slope in tmp:
            k1, k2 = a*ffdelay/slope, b/slope
            links.append((startnode, endnode, route, ffdelay, (ffdelay, slope, k1, k2)))
    if delaytype=='None':
        for startnode, endnode, route, ffdelay, slope in tmp: links.append((startnode, endnode, route, ffdelay, None))
           
    g1 = g.create_graph_from_list(nodes, links, delaytype, ODs1, 'Map of L.A.')
    g2 = g.create_graph_from_list(nodes, links, delaytype, ODs2, 'Map of L.A.')
    g3 = g.create_graph_from_list(nodes, links, delaytype, ODs3, 'Map of L.A.')
    g4 = g.create_graph_from_list(nodes, links, delaytype, ODs4, 'Map of L.A.')
    return g1, g2, g3, g4
开发者ID:cedavidyang,项目名称:bridge_ranking,代码行数:43,代码来源:generate_graph.py

示例2: los_angeles_2

# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import create_graph_from_list [as 别名]
def los_angeles_2(parameters=None, delaytype='None'):
    """Generate larger map of L.A. with 664 links and 194 nodes
    """
    nodes = np.genfromtxt('LA_medium_data/nodes_LA_toy.csv', delimiter = ',', skip_header = 1)
    nodes = nodes[:,1:3]
    links = np.genfromtxt('LA_medium_data/links_qgis_cap.csv', delimiter = ',', skip_header = 1)
    tmp = links
    links = []
    speed_limit_freeway = 33.33 #unit: m/s
    dict_cap2speed ={600:12.5, 1000:16.67, 2000:16.67, 4000:16.67, 5000:16.67, 1500:16.67, 3000:22.22, 6000:22.22, 9000:22.22, 4500:22.22, 7500:22.22, 10500:22.22}
    
    if delaytype=='None':
        for startnode, endnode, category in tmp:
            arc = distance_on_unit_sphere(nodes[startnode-1][2], nodes[startnode-1][1], nodes[endnode-1][2], nodes[endnode-1][1])
            if category == 1: ffdelay = arc/speed_limit_freeway
            if category == 2: ffdelay = arc/16.67
            if category !=0: links.append((startnode, endnode, 1, ffdelay, None))
            
    if delaytype=='Polynomial':
        theta = parameters
        degree = len(theta)
        for startnode, endnode, category, cap in tmp:
            arc = distance_on_unit_sphere(nodes[startnode-1][1], nodes[startnode-1][0], nodes[endnode-1][1], nodes[endnode-1][0])
            if category == 1: ffdelay, slope = arc/speed_limit_freeway, 1/cap
            if category == 2: 
                if dict_cap2speed.has_key(cap):           
                    ffdelay, slope = arc/dict_cap2speed[cap], 1/cap
                else : ffdelay, slope = arc/16.67, 1/cap
            coef = [ffdelay*a*b for a,b in zip(theta, np.power(slope, range(1,degree+1)))]
            links.append((startnode, endnode, 1, ffdelay, (ffdelay, slope, coef)))
    
    dest1 = 50
    dest2 = 100
    ODs=[]
    
    #ODs+=create_linear_ODs(34.044801, -117.831116, 33.955998, -118.309021, 10, 10, nodes, 6000.0)
    #ODs+=create_linear_ODs(34.162493, -118.301468, 34.106226, -117.903214, 2, 20, nodes, 6000.0)    
    #ODs+=create_linear_ODs(34.044801, -117.831116, 33.955998, -118.309021, 2, 30, nodes, 6000.0)
    #ODs+=create_linear_ODs(34.162493, -118.301468, 34.106226, -117.903214, 2, 40, nodes, 6000.0)    
    #ODs+=create_linear_ODs(34.044801, -117.831116, 33.955998, -118.309021, 2, 50, nodes, 6000.0)
    #ODs+=create_linear_ODs(34.162493, -118.301468, 34.106226, -117.903214, 2, 60, nodes, 6000.0)    
    #ODs+=create_linear_ODs(34.044801, -117.831116, 33.955998, -118.309021, 2, 70, nodes, 6000.0)
    #ODs+=create_linear_ODs(34.162493, -118.301468, 34.106226, -117.903214, 2, 80, nodes, 6000.0)        
        
    #ODs = [[  57. ,   50.  ,   4. ],[  20. ,  162.   , 56.4]]
    ODs = Create_ODs_nodes_unique(nodes)
    ODs = ODs[1:5]
    print ODs
    return g.create_graph_from_list(nodes, links, delaytype, ODs, 'Larger map of L.A.')
开发者ID:cedavidyang,项目名称:bridge_ranking,代码行数:51,代码来源:generate_graph.py

示例3: test_LA

# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import create_graph_from_list [as 别名]
def test_LA(datapath='', parameters=None, delaytype='None'):
    nodes = np.genfromtxt(datapath+'Data/Network/CSV/test_LA/test_nodes.csv', delimiter = ',', skip_header = 1)
    nodes = nodes[:,1:3]
    #link_data = np.genfromtxt('Data/Network/CSV/test_LA/test_links.csv', delimiter = ',', skip_header = 1)
    link_data = np.genfromtxt(datapath+'Data/Network/CSV/test_LA/test_links_C.csv', delimiter = ',', skip_header=1)

    if delaytype=='None':
        links = []
        speed_limit_freeway = 30.00 #unit: m/s
        dict_cap2speed ={600:12.5, 1000:16.67, 2000:16.67, 4000:16.67, 5000:16.67, 1500:16.67, 3000:22.22, 6000:22.22, 9000:22.22, 4500:22.22, 7500:22.22, 10500:22.22}
        for startnode, endnode, category in link_data:
            arc = distance_on_unit_sphere(nodes[startnode-1][2], nodes[startnode-1][1], nodes[endnode-1][2], nodes[endnode-1][1])
            if category == 1: ffdelay = arc/speed_limit_freeway
            if category == 2: ffdelay = arc/16.67
            if category !=0: links.append((startnode, endnode, 1, ffdelay, None))

    if delaytype=='Polynomial':
        #theta = parameters
        #degree = len(theta)
        #for startnode, endnode, category, cap in tmp:
            #arc = distance_on_unit_sphere(nodes[startnode-1][1], nodes[startnode-1][0], nodes[endnode-1][1], nodes[endnode-1][0])
            #if category == 1: ffdelay, slope = arc/speed_limit_freeway, 1./cap
            #if category == 2:
                #if dict_cap2speed.has_key(cap):
                    #ffdelay, slope = arc/dict_cap2speed[cap], 1./cap
                #else : ffdelay, slope = arc/16.67, 1./cap
            #coef = [ffdelay*a*b for a,b in zip(theta, np.power(slope, range(1,degree+1)))]
            #links.append((startnode, endnode, 1, ffdelay, (ffdelay, slope, coef)))
        theta = parameters
        degree = len(theta)
        links=[]
        for link_entry in link_data:
            startnode = int(link_entry[1])
            endnode = int(link_entry[2])
            length = link_entry[3]
            cap = link_entry[5]
            freespeed = link_entry[6]
            ff_d=length/freespeed
            #change a capacity (slop=1) to simulate an accident
            #slope= 2000 / cap
            slope= 1. / cap
            coef = [ff_d*a*b for a,b in zip(theta, np.power(slope, range(1,degree+1)))]
            links.append((startnode, endnode, 1, ff_d, (ff_d, slope, coef), cap, length,freespeed))

    ODs = Create_ODs_nodes_unique(nodes, datapath)
    #ODs = ODs[1:5]
    #print ODs

    return g.create_graph_from_list(nodes, links, delaytype, ODs, 'test L.A.')
开发者ID:cedavidyang,项目名称:bridge_ranking,代码行数:51,代码来源:generate_graph.py

示例4: LA_county

# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import create_graph_from_list [as 别名]
def LA_county(datapath='', parameters=None, delaytype='None', cur_gis=None):
    nodes = np.genfromtxt(datapath+'Data/Network/CSV/LA_county/nodes.csv', delimiter = ',', skip_header = 1)
    nodes = nodes[:,:2]
    link_data = np.genfromtxt('Data/Network/CSV/LA_county/links.csv', delimiter = ',', skip_header = 1)
    link_data = np.hstack((link_data[:,[-1]], link_data[:,:-1]))

    if delaytype=='None':
        links = []
        speed_limit_freeway = 30.00 #unit: m/s
        dict_cap2speed ={600:12.5, 1000:16.67, 2000:16.67, 4000:16.67, 5000:16.67, 1500:16.67, 3000:22.22, 6000:22.22, 9000:22.22, 4500:22.22, 7500:22.22, 10500:22.22}
        for startnode, endnode, category in link_data:
            arc = distance_on_unit_sphere(nodes[startnode-1][2], nodes[startnode-1][1], nodes[endnode-1][2], nodes[endnode-1][1])
            if category == 1: ffdelay = arc/speed_limit_freeway
            if category == 2: ffdelay = arc/16.67
            if category !=0: links.append((startnode, endnode, 1, ffdelay, None))

    if delaytype=='Polynomial':
        theta = parameters
        degree = len(theta)
        links=[]
        for link_entry in link_data:
            startnode = int(link_entry[1])
            endnode = int(link_entry[2])
            length = link_entry[3]
            cap = link_entry[5]
            freespeed = link_entry[6]
            ff_d=length/freespeed
            #change a capacity (slop=1) to simulate an accident
            #slope= 2000 / cap
            slope= 1. / cap
            coef = [ff_d*a*b for a,b in zip(theta, np.power(slope, range(1,degree+1)))]
            links.append((startnode, endnode, 1, ff_d, (ff_d, slope, coef), cap, length,freespeed))

    ODs = Create_ODs_nodes_unique(nodes, datapath, cur_gis)
    #ODs = ODs[ODs[:,-1]>np.sum(ODs[:,-1])/1000.,:]

    return g.create_graph_from_list(nodes, links, delaytype, ODs, 'LA county')
开发者ID:cedavidyang,项目名称:bridge_ranking,代码行数:39,代码来源:generate_graph.py


注:本文中的Graph.create_graph_from_list方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。