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


Python Network.add_node方法代码示例

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


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

示例1: test_basic

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import add_node [as 别名]
 def test_basic(self):
     node = Node('one')
     nw = Network([node])
     self.assertEqual(nw.find_node('one'), node)
     node = Node(('two', 2))
     nw.add_node(node)
     self.assertEqual(nw.find_node(('two', 2)), node)
     three = Node('three')
     arc = Arc(three, 1)
     nw.find_node('one').add_arc(arc)
     self.assertEqual(nw.find_node('three'), three)
开发者ID:sh4rkfin,项目名称:misc,代码行数:13,代码来源:network_test.py

示例2: graph_network

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import add_node [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

示例3: create_non_zero_flow_network

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import add_node [as 别名]
 def create_non_zero_flow_network(self, color):
     if not self.is_colored_vbmap_problem():
         raise ValueError("VbMapProblem instance is not a colored map problem")
     network = Network()
     za = self.get_active_vbucket_moves()[color]
     for i, a in enumerate(self.prev_avb()[color]):
         if a > 0:
             node = Node(("prev_avb", i), a)
             network.add_node(node)
             for j, x in enumerate(za[i]):
                 if x > 0:
                     to_node = network.find_or_create_node(('avb', j))
                     node.add_arc(Arc(to_node, x))
     avb = self.get_colored_avb()[color]
     # print "avb: ", avb
     x = self.get_colored_replication_map()[color]
     # for i in range(len(x)):
     #     print "x[{0}]: ".format(i), x[i]
     for i, a in enumerate(avb):
         if a > 0:
             node = network.find_or_create_node(("avb", i))
             for j, y in enumerate(x[i]):
                 if y > 0:
                     to_node = network.find_or_create_node(('rvb', j))
                     node.add_arc(Arc(to_node, y))
     zr = self.get_replica_vbucket_moves()[color]
     for i, a in enumerate(self.prev_rvb()[color]):
         if a > 0:
             node = network.find_or_create_node(("prev_rvb", i))
             node.set_source(-a)
             for j in range(len(zr)):
                 y = zr[j][i]
                 if y > 0:
                     from_node = network.find_node(('rvb', j))
                     from_node.add_arc(Arc(node, y))
     return network
开发者ID:sh4rkfin,项目名称:misc,代码行数:38,代码来源:vbmap.py

示例4: Network

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import add_node [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

示例5: Network

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import add_node [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/tree.data.py")
data_tree = eval(f.read())

origin = network.add_node( 0, 0, 0 )

def resize_array(ary, index):
  while len(ary) < index + 1:
    ary.append(None)

def draw_tree(tree, below, lights_array = []):
  lights_tree = []
  for (index,rod,children) in tree:
    ((x1,y1,z1),(x2,y2,z2)) = rod
    n1 = network.add_node( x1, y1, z1 )
    n2 = network.add_node( x2, y2, z2 )
    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) )
开发者ID:mens-amplio,项目名称:pyprocessing-test,代码行数:33,代码来源:draw_long_cylinders.py

示例6: Network

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import add_node [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

示例7: main

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import add_node [as 别名]
def main(args):
    config.SHOULD_LOG = args.log
    topo = topology.parse_topology(args.topo)

    print "\n"
    print "########################################"
    print "#        SIMULATION PARAMETERS.        #"
    print "########################################"
    pprint(args.__dict__)
    print "\n"
    print "########################################"
    print "#              TOPOLOGY.               #"
    print "########################################"
    pprint(topo)
    print "\n"
    print "########################################"
    print "#            SIMULATION LOG.           #"
    print "########################################"

    # Set up nodes in the network.
    nodes = {}
    network = Network(delay=args.delay, loss=args.loss)
    for addr, outgoing_links in topo:
        node = Node.create(addr)
        nodes[addr] = node
        network.add_node(node, outgoing_links)

    # Start the network.
    network.start()

    # Run protocol.
    APP_CLS = PROTOCOLS[args.protocol]
    for addr, node in nodes.iteritems():
        node.start_application(APP_CLS(addr))

    if args.protocol == 'pong':
        for addr in args.seed:
            nodes[addr].get_application(APP_CLS.ADDRESS).send_ping()
            nodes[addr].get_application(APP_CLS.ADDRESS).send_time_set()

    if args.protocol == 'make':
        assert args.target
        for addr in args.seed:
            nodes[addr].get_application(APP_CLS.ADDRESS).set_mode(app.pong.Mode.MAKE)
            nodes[addr].get_application(APP_CLS.ADDRESS).send_make_flood(args.target)

    if args.protocol == 'toporeq':
        for addr in args.seed:
            nodes[addr].get_application(APP_CLS.ADDRESS).send_topo_req()

    if args.protocol == 'topoflood':
        for addr in args.seed:
            nodes[addr].get_application(APP_CLS.ADDRESS).send_topo_flood()

    if args.protocol == 'deluge' or args.protocol == 'rateless':
        for addr, node in nodes.iteritems():
            application = node.get_application(APP_CLS.ADDRESS)
            application.stop_protocol()
            application.protocol.K = args.k
            application.protocol.T_MIN = args.tmin
            application.protocol.T_MAX = args.tmax
            application.protocol.FRAME_DELAY = args.framedelay
            application.protocol.T_R = args.t_r
            application.protocol.T_TX = args.t_tx
            application.protocol.W = args.w
            application.protocol.RX_MAX = args.rx_max
            if args.protocol == 'deluge':
                assert args.dpagesize % args.dpacketsize == 0
                application.protocol.PAGE_SIZE = args.dpagesize
                application.protocol.PACKET_SIZE = args.dpacketsize
                application.protocol.PACKETS_PER_PAGE = args.dpagesize / args.dpacketsize
            elif args.protocol == 'rateless':
                assert args.rpagesize % args.rpacketsize == 0
                application.protocol.PAGE_SIZE = args.rpagesize
                application.protocol.PACKET_SIZE = args.rpacketsize
                application.protocol.PACKETS_PER_PAGE = args.rpagesize / args.rpacketsize
                application.protocol.PDU_CLS.DATA_FORMAT = "II" + ("B" * application.protocol.PACKETS_PER_PAGE) + \
                    ("B" * application.protocol.PACKET_SIZE)
                # TODO: Cleaner way to do this.
                app.protocol.rateless_deluge.ROWS_REQUIRED = args.rpagesize / args.rpacketsize
            application.start_protocol()

        # Read file and seed in the network.
        data = args.file.read()
        args.file.close()
        for addr in args.seed:
            nodes[addr].get_application(APP_CLS.ADDRESS).disseminate(data)

    # Don't terminate.
    while True:
        time.sleep(100)
开发者ID:ymichael,项目名称:xbns,代码行数:93,代码来源:main.py


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