net.sourceforge.jabm.init
Class RandomVariateInitialiser

java.lang.Object
  extended by net.sourceforge.jabm.init.SpringSimulationFactory
      extended by net.sourceforge.jabm.init.RandomVariateInitialiser
All Implemented Interfaces:
SimulationFactory, org.springframework.beans.factory.InitializingBean

public class RandomVariateInitialiser
extends SpringSimulationFactory
implements org.springframework.beans.factory.InitializingBean

A simulation factory which initialises the values of pre-specified Spring bean properties by drawing randomly from the specified probability distribution. The bean properties are designated as random variates by creating a configuration file which specifies the mapping between each variate and its corresponding distribution.

Currently the following distributions are supported.

N Normal distribution
U Uniform distribution

The parameters of the distribution are specified in brackets after the abbreviation. For example the following configuration:

agent.epsilon = U(0.2, 0.5)
agent.wealth = N(200.0, 10.0)

specifies that the agent's epsilon parameter is uniformly distributed between 0.2 and 0.5 and the agent's wealth is normally distributed with mean 200 and standard deviation 10.

See Also:
Properties, AbstractDistribution
 

Field Summary
protected  java.lang.String configFileName
           
protected  java.lang.Object configFileNamePrefix
           
protected  EventScheduler eventScheduler
           
protected  java.util.HashMap<java.lang.String,java.lang.String> expressionBindings
           
protected  cern.jet.random.engine.RandomEngine prng
           
 
Constructor Summary
RandomVariateInitialiser()
           
 
Method Summary
 void afterPropertiesSet()
           
 java.lang.Number evaluate(java.lang.String expression, java.util.Properties variateBindings)
           
protected  void fireEvent(java.lang.String variableName, java.lang.Number value)
           
 java.lang.String getConfigFileName()
           
 java.lang.Object getConfigFileNamePrefix()
           
 EventScheduler getEventScheduler()
           
 cern.jet.random.engine.RandomEngine getPrng()
           
 Simulation initialise(SimulationController simulationController)
           
 bsh.Interpreter initialiseBeanShell(java.util.Properties variateBindings)
           
 void parseConfigFile()
           
 void setConfigFileName(java.lang.String configFileName)
          The name of the configuration file which specifies which bean properties are to be treated as random variates and their corresponding distribution.
 void setConfigFileNamePrefix(java.lang.Object configFileNamePrefix)
           
 void setEventScheduler(EventScheduler eventScheduler)
          If this property is set then the initialiser will fire a RandomVariateInitialisedEvent each time a random variate is initialised.
 void setPrng(cern.jet.random.engine.RandomEngine prng)
          The pseudo-random number generator to be used for drawing all variates drawn by this initialiser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configFileNamePrefix

protected java.lang.Object configFileNamePrefix

configFileName

protected java.lang.String configFileName

prng

protected cern.jet.random.engine.RandomEngine prng

expressionBindings

protected java.util.HashMap<java.lang.String,java.lang.String> expressionBindings

eventScheduler

protected EventScheduler eventScheduler
Constructor Detail

RandomVariateInitialiser

public RandomVariateInitialiser()
Method Detail

initialise

public Simulation initialise(SimulationController simulationController)
Specified by:
initialise in interface SimulationFactory
Overrides:
initialise in class SpringSimulationFactory

parseConfigFile

public void parseConfigFile()
                     throws java.io.FileNotFoundException,
                            java.io.IOException
Throws:
java.io.FileNotFoundException
java.io.IOException

evaluate

public java.lang.Number evaluate(java.lang.String expression,
                                 java.util.Properties variateBindings)

initialiseBeanShell

public bsh.Interpreter initialiseBeanShell(java.util.Properties variateBindings)
                                    throws bsh.EvalError
Throws:
bsh.EvalError

fireEvent

protected void fireEvent(java.lang.String variableName,
                         java.lang.Number value)

getConfigFileName

public java.lang.String getConfigFileName()

setConfigFileName

public void setConfigFileName(java.lang.String configFileName)
The name of the configuration file which specifies which bean properties are to be treated as random variates and their corresponding distribution. This file is in the standard format for a Properties file.

Parameters:
configFileName -
See Also:
Properties

getPrng

public cern.jet.random.engine.RandomEngine getPrng()

setPrng

public void setPrng(cern.jet.random.engine.RandomEngine prng)
The pseudo-random number generator to be used for drawing all variates drawn by this initialiser.

Parameters:
prng -

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
java.lang.Exception

getEventScheduler

public EventScheduler getEventScheduler()

setEventScheduler

public void setEventScheduler(EventScheduler eventScheduler)
If this property is set then the initialiser will fire a RandomVariateInitialisedEvent each time a random variate is initialised.

Parameters:
eventScheduler - The scheduler used to manage the event queue.
See Also:
RandomVariateInitialisedEvent, EventScheduler

getConfigFileNamePrefix

public java.lang.Object getConfigFileNamePrefix()

setConfigFileNamePrefix

public void setConfigFileNamePrefix(java.lang.Object configFileNamePrefix)