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 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 OutputDBCInteger maxCollectedAmount ) {
        hasBeenCought = new HashMap<Mediator, Integer>();
        this.maxCollectedAmount = maxCollectedAmount;
    }

    /**
     * Accept transmited Mediators.
     */
    public void acceptHashMap<Mediator, Integer> transmited ) {

        // store the transmited mediators
        forMediator m : transmited.keySet() ) {
            int newValue = transmited.get(m).intValue();
            ifhasBeenCought.containsKey) )
                newValue += hasBeenCought.get(m).intValue();
            hasBeenCought.putm, new IntegernewValue ) );
        }
    }
    
    /**
     * Compute the most present mediator.
     */
    public void compute() {
        amount = 0.0;
        ifhasBeenCought.size() == return;  // mediator is not set
            
        forMediator m : hasBeenCought.keySet() ) {
            double curAmount = hasBeenCought.get).doubleValue();
            ifcurAmount > amount ) {
                amount = curAmount;
                mediator = m;
            }
        }
        amount /= maxCollectedAmount.doubleValue();
        ifamount > 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() {
        ifamount == 0.0 return null;
        else return Odour.getCorrespondentOdourmediator );
    }
}
Back