Back
/*
 * (C) 2003-2009 Spolecne s.r.o.
 * Author: Tomas Straka
 * www.spoledge.com
 *
 * Written permission must be obtained in advance from Spolecne s.r.o for any form of
 * reproduction, use or distribution.
 */
package ants.models.thrakia;

import java.util.HashMap;
import java.util.Set;
import ants.models.thrakia.ZygothicGraph.Mediator;

/**
 * Mediator Law says: Neuron can catch mediators only if it has correspondent receptors.
 * The amount of cought mediators depends on number of receptors and is the only information
 * to set the internal state of the neuron.
 */
public class MediatorLaw
{
    /**
     * Stablity of the cumulative state.
     * Implementation of "short time memory".
     */
    private static final int trashHold = 3;

    /**
     * The logic, which determines how many and what mediators were cought by a synapse.
     */
    public static HashMap<Mediator, Integer> wasCought(Set<Mediator> firedMediators,
                                                       HashMap<Mediator, Integer> receptors) {
        HashMap<Mediator, Integer> result = new HashMap<Mediator, Integer>();
        
        forMediator m : firedMediators ) {
            ifreceptors.containsKey) ) result.putm, receptors.get) );
        }
        
        return result;
    }
    
    /**
     * The logic, which determines the <i>Cumulative State</i>. The information what
     * time period is taken in consideration is in Neuron itself. Since it is the period
     * between two consecutive strikes, it is easier this way.
     */
    public static Mediator getCumulativeStateMediator lastCumulativeState,
                                               HashMap<Mediator, Integer> hasBeenCought ) {

        int maxSoFar;
        Mediator medSoFar = lastCumulativeState;
        
        iflastCumulativeState == null ) {     // at the beginning of the simulation
            maxSoFar = -trashHold;              // anything is bigger
        else {
            Integer coughtCurrent = hasBeenCought.getlastCumulativeState );
            ifcoughtCurrent == null maxSoFar = trashHold;
            else maxSoFar = trashHold + coughtCurrent.intValue();
        }

        forMediator m : hasBeenCought.keySet() ) {
            int i = hasBeenCought.get).intValue();
            ifi > maxSoFar ) {
                maxSoFar = i;
                medSoFar = m;
            }
        }
        
        return medSoFar;
    }
}
Back