/*
* (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;
/**
* The neurons are connected by <i>Synapses</i>. Each synapse holds a set of <i>Mediators</i>.
*/
public class Synapse
{
/**
* The container for receptors
*/
private HashMap<Mediator, Integer> receptors;
/**
* The target (<i>neuron</i> or output DBC) which will accept fired <i>Mediators</i>.
*/
private AcceptMediators target;
/**
* Create an empty </i>synapse</i>. The target in parameter is a neuron or output DBC,
* which will accept the mediators.
*/
private Synapse(AcceptMediators target) {
receptors = new HashMap<Mediator, Integer>();
this.target = target;
}
/**
* Create a synapse and preset receptors on one mediator. The target in parameter
* is a neuron or output DBC, which will accept the mediators.
*/
public Synapse(AcceptMediators target, Mediator m, Integer numOfReceptors) {
this( target );
receptors.put(m, numOfReceptors);
}
/**
* Create a synapse and preset receptors on an array of mediators. The target in parameter
* is a neuron or output DBC, which will accept the mediators.
*/
public Synapse(AcceptMediators target, Mediator [] m, Integer [] numOfReceptors) {
this( target );
if(m.length != numOfReceptors.length)
throw new RuntimeException("The length of arrays defining type and number of receptors must be the same.");
for(int i = 0; i < m.length; i++) {
receptors.put(m[i], numOfReceptors[i]);
}
}
/**
* Transmit the fired Mediators. In the "The introduction to the neural networks" the logic
* belongs to the Fire Law, in the web site and on seminars it belongs more to the "Mediator Law".
* since it is just metter of decision, for the moment it is included in the Mediator Law.
*/
public void transmit( Set<Mediator> firedMediators ) {
HashMap<Mediator, Integer> transmission = MediatorLaw.wasCought(firedMediators, receptors);
target.accept(transmission);
}
}
|