예제 #1
0
    for v in G.nodes():
        if G.node[v]['state'] != 'V':
            for u in G.nodes():
                if G.node[u]['state'] != 'V':
                    G.node[u]['state'] = 'S'
            G.node[v]['state'] = 'I'
            onum = Poly(0, x)
            oden = Poly(1, x)

            stepdown(Poly(1, x), Poly(1, x))

            a = onum.mul(soden)
            b = sonum.mul(oden)
            c = a.add(b)
            d = oden.mul(soden)
            a = d.gcd(c)
            sonum, no = c.div(a)
            soden, no = d.div(a)

            print '(' + str(sonum.as_expr()) + ')/(' + str(
                soden.as_expr()) + ')'
            print '-------------'

    a = soden.mul_ground(G.number_of_nodes())
    b = sonum.gcd(a)
    c, no = sonum.div(b)
    d, no = a.div(b)
    print s.strip() + ', (' + str(c.as_expr()) + ')/(' + str(d.as_expr()) + ')'

#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #
예제 #2
0
        G0.add_edge(argv[2 + 2 * i], argv[3 + 2 * i])

    for v in G0.nodes():
        G0.node[v]['state'] = 'S'

    s = ''
    for i in range(2 + 2 * nl, len(argv)):
        me = argv[i]
        s += me + ' '
        if me not in G0.nodes():
            print me, 'not in G'
            exit()
        G0.node[me]['state'] = 'I'

    #G = nx.convert_node_labels_to_integers(G0,label_attribute='id')
    G = deepcopy(G0)

    onum = Poly(0, x)
    oden = Poly(1, x)
    stepdown(Poly(1, x), Poly(1, x))

    a = onum.gcd(oden)
    onum, no = onum.div(a)
    oden, no = oden.div(a)

    # the output format is: [active nodes (separated by blanks)], [solution polynomial]
    print s.strip() + ', (' + str(onum.as_expr()) + ')/(' + str(
        oden.as_expr()) + ')'

#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #
예제 #3
0
    G = nx.convert_node_labels_to_integers(G0, label_attribute='id')

    stnum = Poly(0, x)
    stden = Poly(1, x)
    for v in G.nodes():
        for u in G.nodes():
            if G.node[u]['state'] != 'SENTI':
                G.node[u]['state'] = 'S'
        if G.node[v]['state'] != 'SENTI':
            G.node[v]['state'] = 'I'
        tnum = Poly(0, x)
        tden = Poly(1, x)

        stepdown(Poly(1, x), Poly(1, x), Poly(0, x), Poly(1, x))

        a = tnum.mul(stden)
        b = stnum.mul(tden)
        a = a.add(b)
        b = tden.mul(stden)
        c = a.gcd(b)
        stnum, no = a.div(c)
        stden, no = b.div(c)

    a = stden.mul_ground(G.number_of_nodes())
    b = stnum.gcd(a)
    c, no = stnum.div(b)
    d, no = a.div(b)
    print s.strip() + ', (' + str(c.as_expr()) + ')/(' + str(d.as_expr()) + ')'

#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #