コード例 #1
0
 def match_by_pivot(P, excluded_nodes=set({})):
     pivot_neighbors = graph.neighbors(P.id)
     for A_id in random.sample(pivot_neighbors, len(pivot_neighbors)):
         if A_id not in excluded_nodes:
             for B_id in random.sample(pivot_neighbors, len(pivot_neighbors)):
                 if B_id not in excluded_nodes | set({A_id}):
                     # if not relax and A_id in graph.neighbors(B_id):
                     #     continue
                     edge_PA = graph.edges[random.sample(graph.edges_between(P.id, A_id), 1)[0]]
                     edge_PB = graph.edges[random.sample(graph.edges_between(P.id, B_id), 1)[0]]
                     return g.OrderedEdgeNodeSet([graph.nodes[A_id], P, graph.nodes[B_id]],
                                                  [edge_PA, edge_PB])
コード例 #2
0
    def match(cls, graph, P, pivot_edge, excluded_nodes=set({}), excluded_edges=set({}), **params):    
        """
        Returns an ordered edge node set that follows A-P or P-A.
        """
        # Hardcode the match check
        pivot_neighbors = graph.neighbors(P.id)

        for A_id in random.sample(pivot_neighbors, len(pivot_neighbors)):
            if A_id not in excluded_nodes and A_id != P.id:
                edge = graph.edges[random.sample(graph.edges_between(P.id, A_id), 1)[0]]
                return g.OrderedEdgeNodeSet([P, graph.nodes[A_id]], [edge])
        return None
コード例 #3
0
        def match_by_pivot(P, excluded_nodes=set({})):
            pivot_neighbors = graph.neighbors(P.id)

            #A
            for A_id in random.sample(pivot_neighbors, len(pivot_neighbors)):
                if A_id not in excluded_nodes:
                    #B
                    for B_id in random.sample(pivot_neighbors, len(pivot_neighbors)):
                        if B_id not in excluded_nodes | set({A_id}):
                            #C
                            for C_id in random.sample(pivot_neighbors, len(pivot_neighbors)):
                                if C_id not in excluded_nodes | set({A_id, B_id}):
                                    #D
                                    for D_id in random.sample(pivot_neighbors, len(pivot_neighbors)):
                                        if D_id not in excluded_nodes | set({A_id, B_id, C_id}):
                                            edge_PA = graph.edges[random.sample(graph.edges_between(P.id, A_id), 1)[0]]
                                            edge_PB = graph.edges[random.sample(graph.edges_between(P.id, B_id), 1)[0]]
                                            edge_PC = graph.edges[random.sample(graph.edges_between(P.id, C_id), 1)[0]]
                                            edge_PD = graph.edges[random.sample(graph.edges_between(P.id, D_id), 1)[0]]
                                            return g.OrderedEdgeNodeSet([graph.nodes[A_id], graph.nodes[B_id], P, graph.nodes[C_id], graph.nodes[D_id]],
                                                                        [edge_PA, edge_PB, edge_PC, edge_PD])
コード例 #4
0
 def match(cls, graph, pivot, pivot_edge, excluded_nodes=set({}), excluded_edges=set({}), **params):
     if pivot is not None and pivot.id not in excluded_nodes:
         return g.OrderedEdgeNodeSet([pivot], [])
コード例 #5
0
 def match(cls, graph, pivot, pivot_edge, excluded_nodes=set({}), excluded_edges=set({}), **params):
     # Hardcode the match check
     if pivot.id not in excluded_nodes:
         return g.OrderedEdgeNodeSet([pivot], [])