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


Python networkx.NetworkXNoPath方法代码示例

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


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

示例1: compute_BEST_DES

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoPath [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: get_path_iter

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoPath [as 别名]
def get_path_iter(graph, source, target, path_length, loop):
    """Return a generator of paths with path_length cutoff from source to
    target."""
    path_iter = nx.all_simple_paths(graph, source, target, path_length)
    try:
        for p in path_iter:
            path = deepcopy(p)
            # Remove common target from a path.
            path.remove(target)
            if loop:
                path.append(path[0])
            # A path should contain at least one edge
            if len(path) < 2:
                continue
            yield path
    except nx.NetworkXNoPath:
        pass 
开发者ID:sorgerlab,项目名称:indra,代码行数:19,代码来源:pathfinding.py

示例3: has_path

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoPath [as 别名]
def has_path(G, source, target):
    """Return True if G has a path from source to target, False otherwise.

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

    source : node
       Starting node for path

    target : node
       Ending node for path
    """
    try:
        sp = nx.shortest_path(G,source, target)
    except nx.NetworkXNoPath:
        return False
    return True 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:20,代码来源:generic.py

示例4: has_path

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoPath [as 别名]
def has_path(G, source, target):
    """Returns *True* if *G* has a path from *source* to *target*.

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

    source : node
       Starting node for path

    target : node
       Ending node for path
    """
    try:
        nx.shortest_path(G, source, target)
    except nx.NetworkXNoPath:
        return False
    return True 
开发者ID:holzschu,项目名称:Carnets,代码行数:20,代码来源:generic.py

示例5: test_bidirectional_shortest_path_restricted_directed_cycle

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoPath [as 别名]
def test_bidirectional_shortest_path_restricted_directed_cycle():
    directed_cycle = nx.cycle_graph(7, create_using=nx.DiGraph())
    length, path = _bidirectional_shortest_path(directed_cycle, 0, 3)
    assert_equal(path, [0, 1, 2, 3])
    assert_raises(
        nx.NetworkXNoPath,
        _bidirectional_shortest_path,
        directed_cycle,
        0, 3,
        ignore_nodes=[1],
    )
    length, path = _bidirectional_shortest_path(directed_cycle, 0, 3,
                                                ignore_edges=[(2, 1)])
    assert_equal(path, [0, 1, 2, 3])
    assert_raises(
        nx.NetworkXNoPath,
        _bidirectional_shortest_path,
        directed_cycle,
        0, 3,
        ignore_edges=[(1, 2)],
    ) 
开发者ID:holzschu,项目名称:Carnets,代码行数:23,代码来源:test_simple_paths.py

示例6: has_path

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoPath [as 别名]
def has_path(G, source, target):
    """Return *True* if *G* has a path from *source* to *target*.

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

    source : node
       Starting node for path

    target : node
       Ending node for path
    """
    try:
        sp = nx.shortest_path(G, source, target)
    except nx.NetworkXNoPath:
        return False
    return True 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:20,代码来源:generic.py

示例7: plot_path

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoPath [as 别名]
def plot_path(self, frm_node, to_node, levels=1, add_to_exsting=False):
        """Plot shortest path between two nodes"""
        try:
            path = nx.shortest_path(self.dataG, frm_node, to_node)
        except nx.NetworkXNoPath as e:
            tkm.showerror("No path", str(e))
            return
        except nx.NetworkXError as e:
            tkm.showerror("Node not in graph", str(e))
            return

        graph = self.dataG.subgraph(self._neighbors(path,levels=levels))

        if add_to_exsting:
            self._plot_additional(graph.nodes())
        else:
            self.clear()
            self._plot_graph(graph)

        # Mark the path
        if levels > 0 or add_to_exsting:
            for u, v in zip(path[:-1], path[1:]):
                u_disp = self._find_disp_node(u)
                v_disp = self._find_disp_node(v)
                for key, value in self.dispG.edge[u_disp][v_disp].items():
                    self.mark_edge(u_disp, v_disp, key) 
开发者ID:jsexauer,项目名称:networkx_viewer,代码行数:28,代码来源:graph_canvas.py

示例8: _check_rule_typing

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoPath [as 别名]
def _check_rule_typing(hierarchy, rule_id, graph_id, lhs_mapping, rhs_mapping):
    all_paths = dict(nx.all_pairs_shortest_path(hierarchy))

    paths_from_target = {}
    for s in hierarchy.nodes():
        if s == graph_id:
            for key in all_paths[graph_id].keys():
                paths_from_target[key] = all_paths[graph_id][key]

    for t in paths_from_target.keys():
        if t != graph_id:
            new_lhs_h = compose(
                lhs_mapping,
                hierarchy.compose_path_typing(paths_from_target[t]))
            new_rhs_h = compose(
                rhs_mapping,
                hierarchy.compose_path_typing(paths_from_target[t]))
            try:
                # find homomorphisms from s to t via other paths
                s_t_paths = nx.all_shortest_paths(hierarchy, rule_id, t)
                for path in s_t_paths:
                    lhs_h, rhs_h = hierarchy.compose_path_typing(path)
                    if lhs_h != new_lhs_h:
                        raise HierarchyError(
                            "Invalid lhs typing: homomorphism does not "
                            "commute with an existing "
                            "path from '%s' to '%s'!" % (s, t)
                        )
                    if rhs_h != new_rhs_h:
                        raise HierarchyError(
                            "Invalid rhs typing: homomorphism does not "
                            "commute with an existing " +
                            "path from '%s' to '%s'!" % (s, t)
                        )
            except(nx.NetworkXNoPath):
                pass
    return 
开发者ID:Kappa-Dev,项目名称:ReGraph,代码行数:39,代码来源:type_checking.py

示例9: _check_instance

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoPath [as 别名]
def _check_instance(hierarchy, graph_id, pattern, instance, pattern_typing):
    # Check that the homomorphism is valid
    try:
        check_homomorphism(
            pattern,
            hierarchy.get_graph(graph_id),
            instance,
            total=True
        )
    except InvalidHomomorphism as e:
        raise RewritingError(
            "Homomorphism from the pattern to the instance subgraph "
            "is not valid, got: '{}'".format(e))

    # Check that it is a mono
    if not is_monic(instance):
        raise RewritingError(
            "Homomorphism from the pattern to the instance subgraph "
            "is not injective")

    # Check that instance typing and lhs typing coincide
    for node in pattern.nodes():
        if pattern_typing:
            for typing_graph, typing in pattern_typing.items():
                try:
                    instance_typing = hierarchy.compose_path_typing(
                        nx.shortest_path(hierarchy, graph_id, typing_graph))
                    if node in pattern_typing.keys() and\
                       instance[node] in instance_typing.keys():
                        if typing[node] != instance_typing[instance[node]]:
                            raise RewritingError(
                                "Typing of the instance of LHS does not " +
                                " coincide with typing of LHS!")
                except NetworkXNoPath:
                    raise RewritingError(
                        "Graph '%s' is not typed by '%s' specified "
                        "as a typing graph of the lhs of the rule." %
                        (graph_id, typing_graph)) 
开发者ID:Kappa-Dev,项目名称:ReGraph,代码行数:40,代码来源:type_checking.py

示例10: _check_rule_typing

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoPath [as 别名]
def _check_rule_typing(self, rule_id, graph_id, lhs_mapping, rhs_mapping):
        all_paths = dict(nx.all_pairs_shortest_path(self._graph))

        paths_from_target = {}
        for s in self.nodes():
            if s == graph_id:
                for key in all_paths[graph_id].keys():
                    paths_from_target[key] = all_paths[graph_id][key]

        for t in paths_from_target.keys():
            if t != graph_id:
                new_lhs_h = compose(
                    lhs_mapping,
                    self.compose_path_typing(paths_from_target[t]))
                new_rhs_h = compose(
                    rhs_mapping,
                    self.compose_path_typing(paths_from_target[t]))
                try:
                    # find homomorphisms from s to t via other paths
                    s_t_paths = nx.all_shortest_paths(self._graph, rule_id, t)
                    for path in s_t_paths:
                        lhs_h, _, rhs_h = self.compose_path_typing(path)
                        if lhs_h != new_lhs_h:
                            raise HierarchyError(
                                "Invalid lhs typing: homomorphism does not "
                                "commute with an existing "
                                "path from '{}' to '{}'!".format(s, t)
                            )
                        if rhs_h != new_rhs_h:
                            raise HierarchyError(
                                "Invalid rhs typing: homomorphism does not "
                                "commute with an existing " +
                                "path from '{}' to '{}'!".format(s, t)
                            )
                except(nx.NetworkXNoPath):
                    pass
        return 
开发者ID:Kappa-Dev,项目名称:ReGraph,代码行数:39,代码来源:hierarchies.py

示例11: _makeEdgePaths

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import NetworkXNoPath [as 别名]
def _makeEdgePaths(self):
        """Make edgePaths dict. (Also removes used edges from _graph.)"""

        # sort edges by Y values. the idea is that the straight flow's edges
        # will be handled first and will get nicer edges, though we probably
        # won't be doing exactly the right thing here.
        self.edgeLayoutInfos.sort(
            key=lambda eli: (eli.y1, eli.y2 >= eli.y1, abs(eli.y2 - eli.y1)))

        edgePaths = {}
        for eli in self.edgeLayoutInfos:
            try:
                path = self._choosePath(eli.p1, eli.p2)

                # don't use these edges for any other paths
                for p1, p2 in zip(path, path[1:]):
                    self._graph.remove_edge(p1, p2)
            except networkx.NetworkXNoPath:
                # TODO: try again with more rect outlines
                print('no path! between', p1, p2, file=sys.stderr)
                # create direct edge for debugging
                path = [p1, p2]

            # Force vertical beginning and end of edges.
            # TODO: it'd be nicer to include these edges in the graph
            path.insert(0, eli.p0)
            path.append(eli.p3)

            edgePaths[eli.b1Addr, eli.b2Addr] = path

        return edgePaths 
开发者ID:sapir,项目名称:sonare,代码行数:33,代码来源:graph.py

示例12: compute_DSAR

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

示例13: compute_DSAR

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

示例14: compute_DSAR

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

示例15: compute_most_near

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


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