Пример #1
0
def network_cycle(network, curstate):
    """A Python version of what the C++ cycle does."""
    nextstate = Channels(network.factory.world)
    for g in network.genes:
        for m in g.modules:
            a, b = m.channels
            if operand.calculate(m.op, curstate.test(a), curstate.test(b)):
                nextstate.set(g.pub)
                break
    return nextstate
Пример #2
0
def compute_cis_mod_function(mod):
    wrld = mod.gene.network.factory.world
    unique = list(set(mod.channels))

    # Remove the fixed channels
    if 0 in unique:
        unique.remove(0)
    if 1 in unique:
        unique.remove(1)

    # Build a list of True stats
    is_true = []

    # What if there's nothing here...?
    if not unique:
        st = Channels(wrld)

        # Set our fixed channel
        st.set(1)
        act = mod.is_active(st)
        if act:
            return True
        return False

    # Generate all possible states for this many channels
    all_states = [_ for _ in itertools.product([0, 1], repeat=len(unique))]
    for state in all_states:
        channel_state = Channels(wrld)
        channel_state.set(1)
        for i, channel in enumerate(state):
            if channel:
                channel_state.set(unique[i])

        # Now, ASK the module whether this state turns it on...
        act = mod.is_active(channel_state)
        if act:
            is_true.append(state)

    # NOTE: We need to append _, as sympy barfs on 'E1' for
    # some bizarre reason...
    names = ['_' + wrld.name_for_channel(u) for u in unique]
    sop = SOPform(names, is_true)

    return sop