/*
* (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 ants.models.thrakia.ZygothicGraph.Mediator;
/**
* The representation of output DBC - Usualy a leg. The results are withdrawn by the ant itself.
*/
public class OutputDBC implements AcceptMediators {
/**
* The recently cought mediators
*/
private HashMap<Mediator, Integer> hasBeenCought;
/**
* The maximum amount of one Mediator collected
*/
private Integer maxCollectedAmount;
/**
* The last computed amount.
*/
private double amount;
/**
* The last computed winning mediator.
*/
private Mediator mediator;
/**
* Create an output DBC. The maximal
* possible amount of Mediators collected is: numberOfConnectedNeurons
* x maxNumberOfReceptors per Mediator and Synapse x maxFrequency
* ( dTime from ThrakianAnt / tm from FireLaw ). So it is quite unpredictable
* at the time of model creation. Thats why it is passed in the constructor.
*/
public OutputDBC( Integer maxCollectedAmount ) {
hasBeenCought = new HashMap<Mediator, Integer>();
this.maxCollectedAmount = maxCollectedAmount;
}
/**
* Accept transmited Mediators.
*/
public void accept( HashMap<Mediator, Integer> transmited ) {
// store the transmited mediators
for( Mediator m : transmited.keySet() ) {
int newValue = transmited.get(m).intValue();
if( hasBeenCought.containsKey( m ) )
newValue += hasBeenCought.get(m).intValue();
hasBeenCought.put( m, new Integer( newValue ) );
}
}
/**
* Compute the most present mediator.
*/
public void compute() {
amount = 0.0;
if( hasBeenCought.size() == 0 ) return; // mediator is not set
for( Mediator m : hasBeenCought.keySet() ) {
double curAmount = hasBeenCought.get( m ).doubleValue();
if( curAmount > amount ) {
amount = curAmount;
mediator = m;
}
}
amount /= maxCollectedAmount.doubleValue();
if( amount > 1.0 ) amount = 1.0;
}
/**
* Clean the buffered data;
*/
public void clean() {
hasBeenCought = new HashMap<Mediator, Integer>();
}
/**
* Get amount of most present mediator. Range 0..1. Call compute
* beforehand.
*/
public double getAmount() {
return amount;
}
/**
* Get odour to the most present mediator. Call compute
* beforehand. Can return null if the Odour cannot be produced.
*/
public Odour getOdour() {
if( amount == 0.0 ) return null;
else return Odour.getCorrespondentOdour( mediator );
}
}
|