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


Python networkx.NodeNotFound方法代码示例

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


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

示例1: compute_BEST_DES

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NodeNotFound [as 别名]
def compute_BEST_DES(self, node_src, alloc_DES, sim, DES_dst,message):
        try:

            bestLong = float('inf')
            minPath = []
            bestDES = []
            #print len(DES_dst)
            for dev in DES_dst:
                #print "DES :",dev
                node_dst = alloc_DES[dev]
                path = list(nx.shortest_path(sim.topology.G, source=node_src, target=node_dst))
                long = len(path)

                if  long < bestLong:
                    bestLong = long
                    minPath = path
                    bestDES = dev

            #print bestDES,minPath
            return minPath, bestDES

        except (nx.NetworkXNoPath, nx.NodeNotFound) as e:
            self.logger.warning("There is no path between two nodes: %s - %s " % (node_src, node_dst))
            # print "Simulation ends?"
            return [], None 
开发者ID:acsicuib,项目名称:YAFS,代码行数:27,代码来源:selection_multipleDeploys.py

示例2: compute_DSAR

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NodeNotFound [as 别名]
def compute_DSAR(self, node_src, alloc_DES, sim, DES_dst,message):
        try:
            bestSpeed = float('inf')
            minPath = []
            bestDES = []
            # print "LEN %i" %len(DES_dst)
            for dev in DES_dst:
                #print "DES :",dev
                node_dst = alloc_DES[dev]
                path = list(nx.shortest_path(sim.topology.G, source=node_src, target=node_dst))
                speed = 0
                for i in range(len(path) - 1):
                    link = (path[i], path[i + 1])
                    #print " LINK : ",link
                    #print " BYTES :", message.bytes
                    speed += sim.topology.G.edges[link][Topology.LINK_PR] + (message.bytes/sim.topology.G.edges[link][Topology.LINK_BW])
                    #print " Spped :" , speed
                    #print sim.topology.G.edges[link][Topology.LINK_BW]

                att_node = sim.topology.get_nodes_att()[path[-1]]


                time_service = message.inst / float(att_node["IPT"])
                # print "Tims serviice %s" %time_service
                speed += time_service  # HW - computation of last node
                #print "SPEED: ",speed
                if  speed < bestSpeed:
                    bestSpeed = speed
                    minPath = path
                    bestDES = dev

            # print "DES %s   PATH %s" %(bestDES,minPath)
            return minPath, bestDES

        except (nx.NetworkXNoPath, nx.NodeNotFound) as e:
            self.logger.warning("There is no path between two nodes: %s - %s " % (node_src, node_dst))
            print "Simulation ends?"
            return [], None 
开发者ID:acsicuib,项目名称:YAFS,代码行数:40,代码来源:selection_multipleDeploys.py

示例3: compute_DSAR

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NodeNotFound [as 别名]
def compute_DSAR(self, node_src, alloc_DES, sim, DES_dst,message):
        try:
            bestSpeed = float('inf')
            minPath = []
            bestDES = []
            #print len(DES_dst)
            for dev in DES_dst:
                #print "DES :",dev
                node_dst = alloc_DES[dev]
                path = list(nx.shortest_path(sim.topology.G, source=node_src, target=node_dst))
                speed = 0
                for i in range(len(path) - 1):
                    link = (path[i], path[i + 1])
                   # print "LINK : ",link
                   # print " BYTES :", message.bytes
                    speed += sim.topology.G.edges[link][Topology.LINK_PR] + (message.bytes/sim.topology.G.edges[link][Topology.LINK_BW])
                    #print sim.topology.G.edges[link][Topology.LINK_BW]

                att_node = sim.topology.get_nodes_att()[path[-1]]

                time_service = message.inst / float(att_node["IPT"])
                speed += time_service  # HW - computation of last node
                #print "SPEED: ",speed
                if  speed < bestSpeed:
                    bestSpeed = speed
                    minPath = path
                    bestDES = dev

            #print bestDES,minPath
            return minPath, bestDES

        except (nx.NetworkXNoPath, nx.NodeNotFound) as e:
            self.logger.warning("There is no path between two nodes: %s - %s " % (node_src, node_dst))
            # print "Simulation ends?"
            return [], None 
开发者ID:acsicuib,项目名称:YAFS,代码行数:37,代码来源:selection_multipleDeploys.py

示例4: compute_most_near

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NodeNotFound [as 别名]
def compute_most_near(self,node_src,alloc_DES,sim,DES_dst):
        """
        This functions caches the minimun path among client-devices and fog-devices-Module Calculator and it chooses the best calculator process deployed in that node
        """
        #By Placement policy we know that:
        try:
            minLenPath = float('inf')
            minPath = []
            bestDES = []
            for dev in DES_dst:
                node_dst = alloc_DES[dev]
                path = list(nx.shortest_path(sim.topology.G, source=node_src, target=node_dst))
                if len(path)<minLenPath:
                    minLenPath = len(path)
                    minPath = path
                    bestDES = dev

            return minPath,bestDES
        except nx.NetworkXNoPath as e:
            self.logger.warning("There is no path between two nodes: %s - %s " % (node_src, node_dst))
            print "Simulation ends?. Time:", sim.env.now
            # sim.stop = True ## You can stop all DES process
            return [], None

        except nx.NodeNotFound as e:
            self.logger.warning("Node not found: %s - %s "%(node_src,node_dst))
            print "Simulation ends?. Time:",sim.env.now
            # sim.stop = True ## You can stop all DES process
            return [],None 
开发者ID:acsicuib,项目名称:YAFS,代码行数:31,代码来源:selection_multipleDeploys.py

示例5: astar_path_length

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NodeNotFound [as 别名]
def astar_path_length(G, source, target, heuristic=None, weight='weight'):
    """Returns the length of the shortest path between source and target using
    the A* ("A-star") algorithm.

    Parameters
    ----------
    G : NetworkX graph

    source : node
       Starting node for path

    target : node
       Ending node for path

    heuristic : function
       A function to evaluate the estimate of the distance
       from the a node to the target.  The function takes
       two nodes arguments and must return a number.

    Raises
    ------
    NetworkXNoPath
        If no path exists between source and target.

    See Also
    --------
    astar_path

    """
    if source not in G or target not in G:
        msg = 'Either source {} or target {} is not in G'
        raise nx.NodeNotFound(msg.format(source, target))

    path = astar_path(G, source, target, heuristic, weight)
    return sum(G[u][v].get(weight, 1) for u, v in zip(path[:-1], path[1:])) 
开发者ID:holzschu,项目名称:Carnets,代码行数:37,代码来源:astar.py

示例6: test_absent_source

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NodeNotFound [as 别名]
def test_absent_source(self):
        # the check is in _dijkstra_multisource, but this will provide
        # regression testing against later changes to any of the "client"
        # Dijkstra or Bellman-Ford functions
        G = nx.path_graph(2)
        for fn in (nx.dijkstra_path,
                   nx.dijkstra_path_length,
                   nx.single_source_dijkstra_path,
                   nx.single_source_dijkstra_path_length,
                   nx.single_source_dijkstra,
                   nx.dijkstra_predecessor_and_distance,):
            assert_raises(nx.NodeNotFound, fn, G, 3, 0) 
开发者ID:holzschu,项目名称:Carnets,代码行数:14,代码来源:test_weighted.py

示例7: test_absent_source_bellman_ford

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NodeNotFound [as 别名]
def test_absent_source_bellman_ford(self):
        # the check is in _bellman_ford; this provides regression testing
        # against later changes to "client" Bellman-Ford functions
        G = nx.path_graph(2)
        for fn in (nx.bellman_ford_predecessor_and_distance,
                   nx.bellman_ford_path,
                   nx.bellman_ford_path_length,
                   nx.single_source_bellman_ford_path,
                   nx.single_source_bellman_ford_path_length,
                   nx.single_source_bellman_ford,):
            assert_raises(nx.NodeNotFound, fn, G, 3, 0) 
开发者ID:holzschu,项目名称:Carnets,代码行数:13,代码来源:test_weighted.py

示例8: test_shortest_path

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NodeNotFound [as 别名]
def test_shortest_path(self):
        assert_equal(nx.shortest_path(self.cycle, 0, 3), [0, 1, 2, 3])
        assert_equal(nx.shortest_path(self.cycle, 0, 4), [0, 6, 5, 4])
        validate_grid_path(4, 4, 1, 12, nx.shortest_path(self.grid, 1, 12))
        assert_equal(nx.shortest_path(self.directed_cycle, 0, 3), [0, 1, 2, 3])
        # now with weights
        assert_equal(nx.shortest_path(self.cycle, 0, 3, weight='weight'),
                     [0, 1, 2, 3])
        assert_equal(nx.shortest_path(self.cycle, 0, 4, weight='weight'),
                     [0, 6, 5, 4])
        validate_grid_path(4, 4, 1, 12, nx.shortest_path(self.grid, 1, 12,
                                                         weight='weight'))
        assert_equal(nx.shortest_path(self.directed_cycle, 0, 3,
                                      weight='weight'),
                     [0, 1, 2, 3])
        # weights and method specified
        assert_equal(nx.shortest_path(self.directed_cycle, 0, 3,
                                      weight='weight', method='dijkstra'),
                     [0, 1, 2, 3])
        assert_equal(nx.shortest_path(self.directed_cycle, 0, 3,
                                      weight='weight', method='bellman-ford'),
                     [0, 1, 2, 3])
        # when Dijkstra's will probably (depending on precise implementation)
        # incorrectly return [0, 1, 3] instead
        assert_equal(nx.shortest_path(self.neg_weights, 0, 3, weight='weight',
                                      method='bellman-ford'),
                     [0, 2, 3])
        # confirm bad method rejection
        assert_raises(ValueError, nx.shortest_path, self.cycle, method='SPAM')
        # confirm absent source rejection
        assert_raises(nx.NodeNotFound, nx.shortest_path, self.cycle, 8) 
开发者ID:holzschu,项目名称:Carnets,代码行数:33,代码来源:test_generic.py

示例9: test_shortest_path_length

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NodeNotFound [as 别名]
def test_shortest_path_length(self):
        assert_equal(nx.shortest_path_length(self.cycle, 0, 3), 3)
        assert_equal(nx.shortest_path_length(self.grid, 1, 12), 5)
        assert_equal(nx.shortest_path_length(self.directed_cycle, 0, 4), 4)
        # now with weights
        assert_equal(nx.shortest_path_length(self.cycle, 0, 3,
                                             weight='weight'),
                     3)
        assert_equal(nx.shortest_path_length(self.grid, 1, 12,
                                             weight='weight'),
                     5)
        assert_equal(nx.shortest_path_length(self.directed_cycle, 0, 4,
                                             weight='weight'),
                     4)
        # weights and method specified
        assert_equal(nx.shortest_path_length(self.cycle, 0, 3, weight='weight',
                                             method='dijkstra'),
                     3)
        assert_equal(nx.shortest_path_length(self.cycle, 0, 3, weight='weight',
                                             method='bellman-ford'),
                     3)
        # confirm bad method rejection
        assert_raises(ValueError,
                      nx.shortest_path_length,
                      self.cycle,
                      method='SPAM')
        # confirm absent source rejection
        assert_raises(nx.NodeNotFound, nx.shortest_path_length, self.cycle, 8) 
开发者ID:holzschu,项目名称:Carnets,代码行数:30,代码来源:test_generic.py

示例10: test_tree_all_pairs_lowest_common_ancestor5

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NodeNotFound [as 别名]
def test_tree_all_pairs_lowest_common_ancestor5(self):
        """Handles invalid input correctly."""
        empty_digraph = tree_all_pairs_lca(nx.DiGraph())
        assert_raises(nx.NetworkXPointlessConcept, list, empty_digraph)

        bad_pairs_digraph = tree_all_pairs_lca(self.DG, pairs=[(-1, -2)])
        assert_raises(nx.NodeNotFound, list, bad_pairs_digraph) 
开发者ID:holzschu,项目名称:Carnets,代码行数:9,代码来源:test_lowest_common_ancestors.py

示例11: test_tree_all_pairs_lowest_common_ancestor11

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NodeNotFound [as 别名]
def test_tree_all_pairs_lowest_common_ancestor11(self):
        """Test that None as a node in the graph raises an error."""
        G = nx.DiGraph([(None, 3)])
        assert_raises(nx.NetworkXError, list, tree_all_pairs_lca(G))
        assert_raises(nx.NodeNotFound, list,
                      tree_all_pairs_lca(self.DG, pairs=G.edges())) 
开发者ID:holzschu,项目名称:Carnets,代码行数:8,代码来源:test_lowest_common_ancestors.py

示例12: test_all_pairs_lowest_common_ancestor5

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NodeNotFound [as 别名]
def test_all_pairs_lowest_common_ancestor5(self):
        """Test that pairs not in the graph raises error."""
        assert_raises(nx.NodeNotFound, all_pairs_lca, self.DG, [(-1, -1)]) 
开发者ID:holzschu,项目名称:Carnets,代码行数:5,代码来源:test_lowest_common_ancestors.py

示例13: test_all_pairs_lowest_common_ancestor10

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NodeNotFound [as 别名]
def test_all_pairs_lowest_common_ancestor10(self):
        """Test that it bails on None as a node."""
        G = nx.DiGraph([(None, 3)])
        assert_raises(nx.NetworkXError, all_pairs_lca, G)
        assert_raises(nx.NodeNotFound, all_pairs_lca,
                      self.DG, pairs=G.edges()) 
开发者ID:holzschu,项目名称:Carnets,代码行数:8,代码来源:test_lowest_common_ancestors.py

示例14: astar_path_length

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NodeNotFound [as 别名]
def astar_path_length(G, source, target, heuristic=None, weight='weight'):
    """Return the length of the shortest path between source and target using
    the A* ("A-star") algorithm.

    Parameters
    ----------
    G : NetworkX graph

    source : node
       Starting node for path

    target : node
       Ending node for path

    heuristic : function
       A function to evaluate the estimate of the distance
       from the a node to the target.  The function takes
       two nodes arguments and must return a number.

    Raises
    ------
    NetworkXNoPath
        If no path exists between source and target.

    See Also
    --------
    astar_path

    """
    if source not in G or target not in G:
        msg = 'Either source {} or target {} is not in G'
        raise nx.NodeNotFound(msg.format(source, target))

    path = astar_path(G, source, target, heuristic, weight)
    return sum(G[u][v].get(weight, 1) for u, v in zip(path[:-1], path[1:])) 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:37,代码来源:astar.py

示例15: test_single_node_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NodeNotFound [as 别名]
def test_single_node_graph(self):
        G = nx.DiGraph()
        G.add_node(0)
        assert_equal(nx.single_source_bellman_ford_path(G, 0), {0: [0]})
        assert_equal(nx.single_source_bellman_ford_path_length(G, 0), {0: 0})
        assert_equal(nx.single_source_bellman_ford(G, 0), ({0: 0}, {0: [0]}))
        assert_equal(nx.bellman_ford_predecessor_and_distance(G, 0), ({0: [None]}, {0: 0}))
        assert_equal(nx.goldberg_radzik(G, 0), ({0: None}, {0: 0}))
        assert_raises(nx.NodeNotFound, nx.bellman_ford_predecessor_and_distance, G, 1)
        assert_raises(nx.NodeNotFound, nx.goldberg_radzik, G, 1) 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:12,代码来源:test_weighted.py


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