Example #1
0
    def test_weights_thresholds(self):
        wseq=[3,4,3,3,5,6,5,4,5,6]
        cs=nxt.weights_to_creation_sequence(wseq,threshold=10)
        wseq=nxt.creation_sequence_to_weights(cs)
        cs2=nxt.weights_to_creation_sequence(wseq)
        assert_equal(cs, cs2)
        
        wseq=nxt.creation_sequence_to_weights(nxt.uncompact([3,1,2,3,3,2,3]))
        assert_equal(wseq,
                     [s*0.125 for s in [4,4,4,3,5,5,2,2,2,6,6,6,1,1,7,7,7]])

        wseq=nxt.creation_sequence_to_weights([3,1,2,3,3,2,3])
        assert_equal(wseq,
                     [s*0.125 for s in [4,4,4,3,5,5,2,2,2,6,6,6,1,1,7,7,7]])

        wseq=nxt.creation_sequence_to_weights(list(enumerate('ddidiiidididi')))
        assert_equal(wseq,
                     [s*0.1 for s in [5,5,4,6,3,3,3,7,2,8,1,9,0]])

        wseq=nxt.creation_sequence_to_weights('ddidiiidididi')
        assert_equal(wseq,
                     [s*0.1 for s in [5,5,4,6,3,3,3,7,2,8,1,9,0]])

        wseq=nxt.creation_sequence_to_weights('ddidiiidididid')
        ws=[s/float(12) for s in [6,6,5,7,4,4,4,8,3,9,2,10,1,11]]
        assert_true(sum([abs(c-d) for c,d in zip(wseq,ws)]) < 1e-14)
Example #2
0
    def test_weights_thresholds(self):
        wseq=[3,4,3,3,5,6,5,4,5,6]
        cs=nxt.weights_to_creation_sequence(wseq,threshold=10)
        wseq=nxt.creation_sequence_to_weights(cs)
        cs2=nxt.weights_to_creation_sequence(wseq)
        assert_equal(cs, cs2)
        
        wseq=nxt.creation_sequence_to_weights(nxt.uncompact([3,1,2,3,3,2,3]))
        assert_equal(wseq,
                     [s*0.125 for s in [4,4,4,3,5,5,2,2,2,6,6,6,1,1,7,7,7]])

        wseq=nxt.creation_sequence_to_weights([3,1,2,3,3,2,3])
        assert_equal(wseq,
                     [s*0.125 for s in [4,4,4,3,5,5,2,2,2,6,6,6,1,1,7,7,7]])

        wseq=nxt.creation_sequence_to_weights(list(enumerate('ddidiiidididi')))
        assert_equal(wseq,
                     [s*0.1 for s in [5,5,4,6,3,3,3,7,2,8,1,9,0]])

        wseq=nxt.creation_sequence_to_weights('ddidiiidididi')
        assert_equal(wseq,
                     [s*0.1 for s in [5,5,4,6,3,3,3,7,2,8,1,9,0]])

        wseq=nxt.creation_sequence_to_weights('ddidiiidididid')
        ws=[s/float(12) for s in [6,6,5,7,4,4,4,8,3,9,2,10,1,11]]
        assert_true(sum([abs(c-d) for c,d in zip(wseq,ws)]) < 1e-14)
Example #3
0
    def test_creation_sequences(self):
        deg=[3,2,2,1]
        G=nx.generators.havel_hakimi_graph(deg)
        cs0=nxt.creation_sequence(deg)
        H0=nxt.threshold_graph(cs0)
        assert_equal(''.join(cs0), 'ddid')

        cs1=nxt.creation_sequence(deg, with_labels=True)
        H1=nxt.threshold_graph(cs1)
        assert_equal(cs1, [(1, 'd'), (2, 'd'), (3, 'i'), (0, 'd')])

        cs2=nxt.creation_sequence(deg, compact=True)
        H2=nxt.threshold_graph(cs2)
        assert_equal(cs2, [2, 1, 1])
        assert_equal(''.join(nxt.uncompact(cs2)), 'ddid')
        assert_true(graph_could_be_isomorphic(H0,G))
        assert_true(graph_could_be_isomorphic(H0,H1))
        assert_true(graph_could_be_isomorphic(H0,H2))
Example #4
0
    def test_creation_sequences(self):
        deg=[3,2,2,1]
        G=nx.generators.havel_hakimi_graph(deg)
        cs0=nxt.creation_sequence(deg)
        H0=nxt.threshold_graph(cs0)
        assert_equal(''.join(cs0), 'ddid')

        cs1=nxt.creation_sequence(deg, with_labels=True)
        H1=nxt.threshold_graph(cs1)
        assert_equal(cs1, [(1, 'd'), (2, 'd'), (3, 'i'), (0, 'd')])

        cs2=nxt.creation_sequence(deg, compact=True)
        H2=nxt.threshold_graph(cs2)
        assert_equal(cs2, [2, 1, 1])
        assert_equal(''.join(nxt.uncompact(cs2)), 'ddid')
        assert_true(graph_could_be_isomorphic(H0,G))
        assert_true(graph_could_be_isomorphic(H0,H1))
        assert_true(graph_could_be_isomorphic(H0,H2))