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


Python Network.add_edge方法代码示例

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


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

示例1: graph_network

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import add_edge [as 别名]
def graph_network():
  network = Network()
  data = json.load(open("graph.data.json"))

  node_by_id = {}
  for point_id, point in data["nodes"].items():
    node = network.add_node( *point )
    node_by_id[point_id] = node

  edge_by_id = {}
  for edge_id, edge_pair in data["edges"].items():
    node = network.add_node( *point )
    n1, n2 = [node_by_id[str(n)] for n in edge_pair]
    network.add_edge( n1, n2, (255,random.randint(0,255),random.randint(0,255)))
    edge_by_id[edge_id] = (n1, n2)

  r = {
    "network": network,
    "nodes": node_by_id,
    "edges": edge_by_id
  }
  return r
开发者ID:annthurium,项目名称:modeling,代码行数:24,代码来源:networkx_graph.py

示例2: Network

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import add_edge [as 别名]
from emulator import *
from network import Network
from time import sleep

# make a network and draw it
network = Network()
n1 = network.add_node( 20, 20, 20 )
n2 = network.add_node( 25, 40, 0 )
network.add_edge( n1, n2, (255,0,0) )
display = Emulator(network, False)

# wait a bit, modify the network some way, and pass the updated network into the
# visualizer. eventually we will want to pass in the update data in some better/different
# format (e.g. as a serial stream of RGB values that are mapped onto the network
# structure already within the visualizer) rather than re-drawing the whole network every time.
sleep(1)
n3 = network.add_node( 5, 0, 40 )
network.add_edge( n1, n3, (0,255,0) )
display.update(network)

external_run(display.queue, display.network)
开发者ID:mens-amplio,项目名称:pyprocessing-test,代码行数:23,代码来源:test.py

示例3: resize_array

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import add_edge [as 别名]
    edge = ( n1, n2 )
    resize_array(lights_array, index)
    lights_array[index] = edge
    network.add_edge( n1, n2, (255, 0, 0) )
    network.add_edge( below, n1, (255, 255, 255) )
    child_lights = draw_tree(children, n2, lights_array)
    lights_tree.append( (edge, rod, child_lights) )
  return lights_tree, lights_array

lights_tree, lights_array = draw_tree(data_tree, origin)

def select_light(ls, numbers):
  index = numbers[0]
  if len(ls) <= index:
    return None
  if len(numbers) > 1:
    return select_light(ls[index][2], numbers[1:])
  else:
    return ls[index][0]

light_number = select_light(data_tree, [1,1])
light = lights_array[light_number]
if light:
  network.add_edge(light[0], light[1], (0,100,255) )

print("ok")

# single-threaded, for now.
display = Emulator(network, False)
external_run(display.queue, display.network)
开发者ID:mens-amplio,项目名称:pyprocessing-test,代码行数:32,代码来源:draw_long_cylinders.py

示例4: Network

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import add_edge [as 别名]
from emulator import *
from network import Network
from time import sleep
import math
import multiprocessing
import random
import time

# make a network and draw it
network = Network()

f = open("../modeling/graph.data.py")
data = eval(f.read())

node_by_id = {}

for point_id, point in data["nodes"].items():
  node = network.add_node( *point )
  node_by_id[point_id] = node

edge_by_id = {}

for edge_id, edge_pair in data["edges"].items():
  node = network.add_node( *point )
  n1, n2 = edge_pair
  network.add_edge( node_by_id[n1], node_by_id[n2], (255,random.randint(0,255),random.randint(0,255)))

# single-threaded, for now.
display = Emulator(network, False)
external_run(display.queue, display.network)
开发者ID:mens-amplio,项目名称:pyprocessing-test,代码行数:32,代码来源:draw_long_cylinders_graph.py


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