/*
* (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>();
for( Mediator m : firedMediators ) {
if( receptors.containsKey( m ) ) result.put( m, receptors.get( m ) );
}
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 getCumulativeState( Mediator lastCumulativeState,
HashMap<Mediator, Integer> hasBeenCought ) {
int maxSoFar;
Mediator medSoFar = lastCumulativeState;
if( lastCumulativeState == null ) { // at the beginning of the simulation
maxSoFar = -trashHold; // anything is bigger
} else {
Integer coughtCurrent = hasBeenCought.get( lastCumulativeState );
if( coughtCurrent == null ) maxSoFar = trashHold;
else maxSoFar = trashHold + coughtCurrent.intValue();
}
for( Mediator m : hasBeenCought.keySet() ) {
int i = hasBeenCought.get( m ).intValue();
if( i > maxSoFar ) {
maxSoFar = i;
medSoFar = m;
}
}
return medSoFar;
}
}
|