def test_typical(self):

        # every node in a complete graph is simplicial
        G = nx.complete_graph(100)
        for v in G:
            self.assertTrue(dnx.is_simplicial(G, v))

        # if we remove one edge then every node except the
        # two should be almost simplicial
        u = 0
        w = 1
        G.remove_edge(u, w)
        for v in G:
            if v not in (u, w):
                self.assertFalse(dnx.is_simplicial(G, v))
                self.assertTrue(dnx.is_almost_simplicial(G, v))
            else:
                self.assertTrue(dnx.is_simplicial(G, v))
Exemplo n.º 2
0
def markov_add_remove_simplicial_vertex(g, num_steps):
    for _ in range(num_steps):
        simplicial_vertices = filter(lambda v: dnx.is_simplicial(g, v),
                                     g.nodes)
        v = random.choice(g.nodes)
        # remove an edge
        c = set(g.neighbors(v))
        common_neighbors = reduce(and_, [set(g.neighbors(u)) for u in c])
        common_neighbors = filter(lambda u: u != v, common_neighbors)
        u = random.choice(common_neighbors)
        g.add_edge(u, v)