def moran_sexual(network):
    """The generalized sexual Moran process.

    Ateach time step, and individual is chosen for replication and another
    individual is chosen to die. The replication replaces the one who dies.
    For this process to work you need to add a new agent before calling step.
    """
    if not network.transmissions():
        replacer = random.choice(network.nodes(type=Source))
        replacer.transmit()
    else:
        from operator import attrgetter
        agents = network.nodes(type=Agent)
        baby = max(agents, key=attrgetter('creation_time'))
        agents = [a for a in agents if a.id != baby.id]
        replacer = random.choice(agents)
        replaced = random.choice(
            replacer.neighbors(direction="to", type=Agent))

        # Give the baby the same outgoing connections as the replaced.
        for node in replaced.neighbors(direction="to"):
            baby.connect(direction="to", whom=node)

        # Give the baby the same incoming connections as the replaced.
        for node in replaced.neighbors(direction="from"):
            node.connect(direction="to", whom=baby)

        # Kill the replaced agent.
        replaced.fail()

        # Endow the baby with the ome of the replacer.
        replacer.transmit(to_whom=baby)