當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。