See the Introduction in the configuration.html.
The configuration file will start thus:
<?xml version="1.0" encoding="ISO-8859-1" ?> <configuration>
The definition of writer may be left out altogether if using ConsoleWriter because that is the default for the BeanPot. The writer is simply a logger of last resort and also a output generator for census beans, etc.
<writer class="com.rubecula.beanpot.ConsoleWriter"> </writer>
If you want to be able to monitor your beans via a JMX agent and the Jconsole application, you will need to include the following bean definition. You will also have to ensure that the beans you want to monitor are MBeans. Without going into too much detail here, the easiest way to accomplish that is to define an interface called xxxMBean where xxx represents the name of one of the classes or interfaces in the bean's class hierarchy.
<MBeanPot></MBeanPot>
Now comes the beans tag:
<beans>
Following this point is a list of the beans used for the Peppered Moth applet. Note that order is important. In particular, if bean A is referenced as a constructor argument by bean B, then bean A's definition must precede B's definition. However, if bean A is referenced only by a property, or as a member of bean A, then the order is immaterial.
Note also that while in general the beans can have any names that you like, there are some beans which are expected to have specific names. In particular, the Applet. The complete list can be found in the Beans interface, which should be consulted before any names are changed.
First come a couple of optional beans, the phenotype and fitness caches. If you don't specify them here, those caches will still exist (using the standard classes) but in that case you won't be able to register them as MBeans (unless you do it yourself) because the BeanPot won't know about them, as they will be implicitly constructed by the "Realm" bean. Other reasons to specify them here as beans are of course if you want to provide your own caching mechanisms and/or if you want to turn caching off as shown (caching can be a source of hard-to-diagnose problems).
<bean id="PhenotypeCache" class="com.rubecula.darwin.domain.helper.PhenotypeCache"> </bean> <bean id="FitnessCache" class="com.rubecula.darwin.domain.helper.FitnessCache"> <property name="active"> <value>false</value> </property> </bean>
The following bean, Realm, is required for all Darwin evolutions. You may of course implement your own concrete class and reference it here. All that is required is that it implements the Realm interface. The concrete implementation referenced here is the standard implementation of Realm.
The realm indirectly "hosts" all of the environments and populations of organisms. It is one of the three top-level cooperating classes that make up a Darwin application, the others being the "Evolution" bean and either the "Applet" (or "_Applet_") or the console for an application.
If you have specified the fitness and/or phenotype caches above (actually they always go together in practice), then you will need to reference them here as constructor args (as shown). Otherwise, you do not need to specify any constructor args. For details of the constructor arguments and properties, see the API for Realm_Wallacian.
<bean id="Realm" class="com.rubecula.darwin.domain.world.Realm_Wallacian"> <constructor-arg> <ref bean="PhenotypeCache" /> </constructor-arg> <constructor-arg> <ref bean="FitnessCache" /> </constructor-arg> </bean>
The peppered moth applet uses a particular implementation of Census which understands about and reports on wing colors. The standard census taker is com.rubecula.darwin.domain.helper.Census_Standard. For details of the constructor arguments and properties, see the API for Census_WingColor.
<bean id="CensusTaker" class="com.rubecula.darwin.examples.pepperedmoth.Census_WingColor"> <constructor-arg> <ref bean="_Writer_" /> </constructor-arg> </bean>
The peppered moth applet uses a particular implementation of Registry which reports on births and their wing colors. The standard registry (which does nothing for births, deaths, or marriages) is com.rubecula.darwin.domain.world.Registry_None. For details of the constructor arguments and properties, see the API for Registry_PepperedMoth.
<bean id="Registry" class="com.rubecula.darwin.examples.pepperedmoth.Registry_PepperedMoth"> <constructor-arg> <ref bean="_Writer_" /> </constructor-arg> </bean>
For information on the random number generator bean, see configuration.html. For details of the constructor arguments and properties, see the API for Random_Standard.
<bean id="Random" class="com.rubecula.util.random.Random_Standard"> <property name="seed"> <value>0</value> </property> </bean>
The following bean, the "Evolution" bean is one of the three fundamental components of a Darwin application -- it is what drives the evolutionary process. For details of the constructor arguments and properties, see the API for Evolution_Calendar, which is a concrete implementation of com.rubecula.darwin.evolution.Evolution which is based on calendar time (in seconds), starting from now. Thus it is suitable for an evolution that runs in real time. If you need an evolution that, for example, simulates the Jurassic period, then you need to define your own implementation of Evolution.
<bean id="Evolution" class="com.rubecula.darwin.evolution.Evolution_Calendar"> <constructor-arg class="Boolean"> <value>false</value> </constructor-arg> <property name="ui"> <value>!Applet</value> </property> <property name="evolvables" keyClass="com.rubecula.darwin.foundation.Evolvable" valueClass="Integer"> <map> <entry key="!Darwin" value="1" /> </map> </property> </bean>
The following bean is the first of a set of evaluators. These
evaluators can be any concrete implementation of
com.rubecula.jexpression.Evaluator. Such an evaluator is able to
evaluate an mathematical expression containing variables, constants,
functions, etc. Evaluators support one of two notations: algebraic and
RPN. The best evaluator available, we believe, is JEP. It requires a license
which we cannot provide. If you do have a license and want to use it,
the class that you need here is:
com.rubecula.jexpression.jep.Evaluator_JEP. There are a few other
evaluators supported by the Jexpression package, including Evaluator_RPN
and Evaluator_RPN_Mutable. Please see the Jexpression
documentation for more details.
Note that if the evaluator class implements
com.rubecula.jexpression.EvaluatorMutable, the expression terms
specified here will be overwritten by the function which utilizes this
evaluator. Thus, it is only necessary to specify the expression terms
here if the evaluator is immutable. The constructor arg below therefore
is more of an exemplar than something that is required in this context.
Finally, don't be tempted to use one evaluator for several different
functions. They should not be shared unless they are immutable, and even
then problems will arise if you instead use a mutable evaluator and
change the expression.
This EvaluatorFitness bean will be used by the Fitness bean (see below). In the Peppered Moth applet, you can change the expression evaluated for fitness by going to the options panel and editing the fitness function. For details of the constructor arguments and properties, see the API for Evaluator_RPN_Mutable.
<bean id="EvaluatorFitness" class="com.rubecula.jexpression.rpn.Evaluator_RPN_Mutable"> <constructor-arg class="com.rubecula.jexpression.Term[]"> <list valueClass="com.rubecula.jexpression.Term"> <value>e</value> <value>$shapeFactor / $value $target - + 2</value> <value>pow</value> <value>*</value> <value>pow</value> <value>$shapeFactor / *</value> </list> </constructor-arg> </bean>
This EvaluatorDesirable bean will be used (indirectly) by the MateChoice bean (see below). In the Peppered Moth applet, you can change the expression evaluated for desirability by going to the options panel and editing the Desirability function.
<bean id="EvaluatorDesirable" class="com.rubecula.jexpression.rpn.Evaluator_RPN_Mutable"> </bean>
This EvaluatorChoosy bean will be used (indirectly) by the MateChoice bean (see below). In the Peppered Moth applet, you can change the expression evaluated for choosiness by going to the options panel and editing the Choosiness function.
<bean id="EvaluatorChoosy" class="com.rubecula.jexpression.rpn.Evaluator_RPN"> <constructor-arg class="CharSequence[]"> <list valueClass="CharSequence"> <value>E $random 3.8 * ^</value> </list> </constructor-arg> </bean>
The MateChoice bean determines for the Peppered Moth system how mates are chosen. For details on the constructor args and properties, see the API documentation for MateChoice_PepperedMoth. The MateChoice class has several different constructors, the primary one taking Random, Function_Desirable, Function_Choosy, and Attraction as arguments. The constructor used here is one that constructs its own functions for desirability and choosiness (passing them the two given bean references for evaluators), and an Attraction_Uniform object for sexual attraction.
<bean id="MateChoice" class="com.rubecula.darwin.examples.pepperedmoth.MateChoice_PepperedMoth"> <constructor-arg> <ref bean="Random" /> </constructor-arg> <constructor-arg> <ref bean="EvaluatorDesirable" /> </constructor-arg> <constructor-arg> <ref bean="EvaluatorChoosy" /> </constructor-arg> </bean>
The following set of beans is only required if you are configuring an applet, that is to say you are using the Swing foundation classes to provide your user interface. If you were using a different user interface, you would be required to put some similar types of beans here instead. For details on the constructor args and properties, see the API documentation for Painter_PepperedMoth.
The first bean to define is the applet. This is an externally imposed bean and therefore takes the type "external". An external bean must be introduced into the bean container using the method BeanContainer.imposeBean(String,Object), providing the key (id) that the bean will be referenced by and the bean itself. This imposition must occur before the bean container is configured. In the case of an applet, the calls to the bean container, including the invocation of imposeBean, are found in the init() method.
Note the member construct in this bean definition. We are stipulating that the applet should be added as a member of type "listener" to the Evolution bean. In practice, the bean pot invokes the method addListener on the Evolution bean, passing in the applet as its parameter.
For details of the applet class used here, see the API documentation for Applet_PepperedMoth.
<bean id="Applet" type="external" class="com.rubecula.darwin.examples.pepperedmoth.Applet_PepperedMoth"> <member membership="listener">!Evolution</member> <property name="controlPanel"> <value>!ControlPanel</value> </property> <property name="optionsPanel"> <value>!OptionsPanel</value> </property> <property name="censusTaker"> <value>!CensusTaker</value> </property> <property name="painter"> <value>!Painter</value> </property> <property name="visualizerTabs"> <value>!VisualizationTabs</value> </property> <property name="visualizationFactory"> <value>!VisualizationFactory</value> </property> </bean>
The next bean to define is the painter bean, the bean that knows how to depict the current state of the evolution. The peppered moth painter knows how to show moths as circles of varying size and color. The single constructor argument specifies the title to be used at the top of the painted image.
<bean id="Painter" class="com.rubecula.darwin.examples.pepperedmoth.Painter_PepperedMoth"> <constructor-arg> <value>Moths</value> </constructor-arg> </bean>
The control panel bean is the bean that lays out and responds to the control panel, in this applet, the area at the bottom of the applet image. It includes, buttons for start/stop/next for the evolution process, as well as sliders for the soot density and the generation rate. The first constructor argument specifies the bean which listens to changes in the control panel artifacts, typically the applet itself (take care to use the name defined right at the top of this file for the applet name, which defaults to "_Applet_", but which in this case is defined as "Applet"). The second argument specifies whether or not evolution should start running (or start paused as in this case). Note that you specify the class of this argument as the class Boolean, even though the constructor takes a primitive argument of boolean. For details on the constructor args and properties, see the API documentation for ControlPanel_PepperedMoth.
<bean id="ControlPanel" class="com.rubecula.darwin.examples.pepperedmoth.ControlPanel_PepperedMoth"> <constructor-arg> <ref bean="Applet" /> </constructor-arg> <constructor-arg class="Boolean"> <value>false</value> </constructor-arg> </bean>
The options controller bean is responsible for interacting with the options panel (see OptionsPanel bean). It implements the setProperty and setState methods of the ControlAction interface. The constructor argument is the "interacter", which paints and responds to control actions, and is typically the applet itself. For details on the constructor args and properties, see the API documentation for OptionsController_PepperedMoth.
<bean id="OptionsController" class="com.rubecula.darwin.examples.pepperedmoth.OptionsController_PepperedMoth"> <constructor-arg> <ref bean="Applet" /> </constructor-arg> </bean>
The options panel works in conjunction with the options controller (which must be passed in as the constructor argument) and is responsible for the look of the options tab of the peppered moth applet. For details on the constructor args and properties, see the API documentation for OptionsPanel_Standard.
<bean id="OptionsPanel" class="com.rubecula.darwin.visualization.swing.OptionsPanel_Standard"> <constructor-arg> <ref bean="OptionsController" /> </constructor-arg> </bean>
The visualizer is more or less synonymous with the main panel of the applet. The visualizer tabs are therefore the three tabs that show the options panel, the control population and the experimental population. The first constructor argument is the painter bean defined above. The tabs property is a map of tab contents. Two of the three tabs are added programmatically by the applet. The other tab, viz. the options panel, is added here by setting the "tabs" map. For details on the constructor args and properties, see the API documentation for VisualizerTabs.
Note that it is not (currenly) possible to specify the tabs by using the member construct in, for example, the OptionsPanel bean definition because the method which adds a tab to the Visualization tab takes four parameters rather than just two.
<bean id="VisualizationTabs" class="com.rubecula.darwin.visualization.swing.VisualizerTabs"> <constructor-arg> <ref bean="Painter" /> </constructor-arg> <property name="tabs"> <map> <entry key="options" value="!OptionsPanel" /> </map> </property> </bean>
<bean id="VisualizationFactory" class="com.rubecula.darwin.examples.pepperedmoth.VisualizationFactory_PepperedMoth"> <constructor-arg> <ref bean="Random" /> </constructor-arg> </bean>
<bean id="VisualizableListener" class="com.rubecula.darwin.examples.pepperedmoth.Visualization_PepperedMoth"> <constructor-arg> <ref bean="VisualizationFactory" /> </constructor-arg> <constructor-arg class="Boolean"> <value>false</value> </constructor-arg> <member membership="visualizableListener">!Evolution</member> <property name="visualizerTabs"> <value>!VisualizationTabs</value> </property> </bean>
The Mortality bean determines for the which organisms live and which die. For details on the constructor args and properties, see the API documentation for Mortality_Reaper. The constructor used here is takes the Random bean, and two other values TODO as constructor arguments.
<bean id="Mortality" class="com.rubecula.darwin.domain.genetics.Mortality_Reaper"> <constructor-arg> <ref bean="Random" /> </constructor-arg> <constructor-arg class="Double"> <value>0.15</value> </constructor-arg> <property name="bias"> <value>0.75</value> </property> </bean>
<bean id="Fecundity" class="com.rubecula.darwin.domain.genetics.Fecundity_Saturated"> <property name="saturationThresholds" valueClass="Double"> <list> <value>1.5</value> <value>0.8</value> <value>0.4</value> <value>0.2</value> <value>0.1</value> </list> </property> </bean>
<bean id="Meiosis" class="com.rubecula.darwin.domain.genetics.Meiosis_Locus"> <constructor-arg> <ref bean="Random" /> </constructor-arg> </bean>
<bean id="Randomizer" class="com.rubecula.util.random.Randomizer"> <constructor-arg> <ref bean="Random" /> </constructor-arg> <property name="odds"> <value>100</value> </property> </bean>
<bean id="Mutator" class="com.rubecula.darwin.examples.pepperedmoth.Mutator_PepperedMoth"> <constructor-arg> <ref bean="Randomizer" /> </constructor-arg> <constructor-arg> <value>100</value> <!-- should be redundant --> </constructor-arg> </bean>
<bean id="Melanism" class="com.rubecula.darwin.examples.pepperedmoth.Allele_PepperedMoth"> <constructor-arg> <value>Melanism</value> </constructor-arg> <constructor-arg class="Boolean"> <value>true</value> </constructor-arg> </bean>
<bean id="NonMelanism" class="com.rubecula.darwin.examples.pepperedmoth.Allele_PepperedMoth"> <constructor-arg> <value>NonMelanism</value> </constructor-arg> <constructor-arg class="Boolean"> <value>false</value> </constructor-arg> </bean>
<bean id="Locus" class="com.rubecula.darwin.domain.genetics.Locus_Triversian"> <constructor-arg> <ref bean="Random" /> </constructor-arg> <constructor-arg> <value>Wing Color</value> </constructor-arg> <member membership="locus">!ChromosomeNoSex</member> <property name="alleles" keyClass="com.rubecula.darwin.domain.helper.Allele" valueClass="Integer"> <map> <entry key="!Melanism" value="1" /> <entry key="!NonMelanism" value="4" /> </map> </property> </bean>
<bean id="Typica" class="com.rubecula.darwin.examples.pepperedmoth.Variant_WingColor"> <constructor-arg class="com.rubecula.darwin.examples.pepperedmoth.WingColor"> <value>Typica</value> </constructor-arg> <member membership="variant">!Character</member> </bean>
<bean id="Carbonaria" class="com.rubecula.darwin.examples.pepperedmoth.Variant_WingColor"> <constructor-arg class="com.rubecula.darwin.examples.pepperedmoth.WingColor"> <value>Carbonaria</value> </constructor-arg> <member membership="variant">!Character</member> </bean>
<bean id="Character" class="com.rubecula.darwin.domain.environment.Pharacter_Fisherian"> <constructor-arg> <value>Wing Color</value> </constructor-arg> <member membership="character">!Phenome</member> </bean>
<bean id="Fitness" class="com.rubecula.darwin.examples.pepperedmoth.FitnessEngine_PepperedMoth"> <constructor-arg> <ref bean="EvaluatorFitness" /> </constructor-arg> <constructor-arg> <ref bean="Realm" /> </constructor-arg> </bean>
<bean id="Phenome" class="com.rubecula.darwin.domain.environment.Phenome_Standard"> <constructor-arg> <ref bean="Fitness" /> </constructor-arg> <property name="characters" valueClass="com.rubecula.darwin.domain.helper.Pharacter"> <list> <value>!Character</value> </list> </property> </bean>
<bean id="Expresser" class="com.rubecula.darwin.domain.world.Expresser_Mendelian"> <constructor-arg> <ref bean="Character" /> </constructor-arg> <constructor-arg> <value>Melanism</value> </constructor-arg> <constructor-arg> <value>Carbonaria</value> </constructor-arg> </bean>
<bean id="ChromosomeNoSex" class="com.rubecula.darwin.domain.genetics.Chromosome_NoSex"> <constructor-arg> <value>No Sex Chromosome</value> </constructor-arg> <member membership="chromosome">!Genomic</member> </bean>
<bean id="Genomic" class="com.rubecula.darwin.domain.world.Genomic_Sexual"> <constructor-arg> <value>Peppered Moth Genomic</value> </constructor-arg> <constructor-arg> <ref bean="Meiosis" /> </constructor-arg> <constructor-arg> <ref bean="Mutator" /> </constructor-arg> <constructor-arg> <ref bean="Random" /> </constructor-arg> <property name="expressers" keyClass="com.rubecula.darwin.domain.helper.Locus" valueClass="com.rubecula.darwin.domain.helper.Expresser"> <map> <entry key="!Locus" value="!Expresser" /> </map> </property> </bean>
<bean id="Darwin" class="com.rubecula.darwin.domain.world.Taxon_Darwinian"> <constructor-arg> <value>Peppered Moth System</value> </constructor-arg> <constructor-arg> <ref bean="Realm" /> </constructor-arg> <constructor-arg> <ref bean="Genomic" /> </constructor-arg> <constructor-arg> <ref bean="Phenome" /> </constructor-arg> <constructor-arg> <ref bean="CensusTaker" /> </constructor-arg> <constructor-arg> <ref bean="Mortality" /> </constructor-arg> <constructor-arg> <ref bean="MateChoice" /> </constructor-arg> <constructor-arg> <ref bean="Fecundity" /> </constructor-arg> <property name="registry" valueClass="com.rubecula.darwin.domain.helper.Registry"> <value>!Registry</value> </property> <property name="seedPopulation"> <value>10</value> </property> </bean>
<bean id="EcoFactorControlSoot" class="com.rubecula.darwin.examples.pepperedmoth.EcoFactor_SootDensity"> <constructor-arg class="Double"> <value>5</value> </constructor-arg> <member membership="factor">!EnvironmentControl</member> </bean>
<bean id="EcoFactorExpSoot" class="com.rubecula.darwin.examples.pepperedmoth.EcoFactor_SootDensity"> <constructor-arg class="Double"> <value>3</value> </constructor-arg> <member membership="factor">!EnvironmentExp</member> </bean>
<bean id="EnvironmentControl" class="com.rubecula.darwin.examples.pepperedmoth.Environment_PepperedMoth"> <constructor-arg> <value>control environment</value> </constructor-arg> <constructor-arg> <ref bean="Realm" /> </constructor-arg> </bean>
<bean id="EnvironmentExp" class="com.rubecula.darwin.examples.pepperedmoth.Environment_PepperedMoth"> <constructor-arg> <value>experimental environment</value> </constructor-arg> <constructor-arg> <ref bean="Realm" /> </constructor-arg> </bean>
Note that in the definitions of the populations (following), we do not use the member tag, but instead add the populations in the definition of Darwin. This appears to be a sequencing issue.
<bean id="PopulationControl" class="com.rubecula.darwin.domain.world.Population_Malthusian"> <constructor-arg> <value>0</value> </constructor-arg> <constructor-arg> <value>control population</value> </constructor-arg> <constructor-arg> <ref bean="EnvironmentControl" /> </constructor-arg> <constructor-arg> <ref bean="Random" /> </constructor-arg> <member membership="population">!Darwin</member> <property name="isolated"> <value>true</value> </property> </bean>
Please see configuration.html for more on populations and colonies. This section has not been updated to show the definition of colonies.
<bean id="PopulationExp" class="com.rubecula.darwin.domain.world.Population_Malthusian"> <constructor-arg> <value>1</value> </constructor-arg> <constructor-arg> <value>experimental population</value> </constructor-arg> <constructor-arg> <ref bean="EnvironmentExp" /> </constructor-arg> <constructor-arg> <ref bean="Random" /> </constructor-arg> <member membership="population">!Darwin</member> <property name="isolated"> <value>false</value> </property> </bean>
The following two beans define the background colors we use for the visual environments which the moths inhabit. In this case, the grey value is a number between 0 (pure white) and 1 (pure black) and represents the soot density of the tree bark.
Note the keyed member construct in this bean definition. We are stipulating that the soot color bean (SootMediumGrey or SootLightGrey) should be added as a keyed (or named) attribute of the appropriate visualization model bean. In practice, the bean pot invokes the method putAttribute on the VisualizationModelControl (or VisualizationModelExp) bean, passing in "background color" as its first parameter and the soot color bean as its second parameter.
<bean id="SootMediumGrey" class="com.rubecula.darwin.examples.pepperedmoth.SootColor"> <constructor-arg class="Float"> <value>5</value> </constructor-arg> <constructor-arg class="Float"> <value>10</value> </constructor-arg> <member key="backgroundColor" membership="attribute">!VisualizationModelControl</member> </bean> <bean id="SootLightGrey" class="com.rubecula.darwin.examples.pepperedmoth.SootColor"> <constructor-arg class="Float"> <value>3</value> </constructor-arg> <constructor-arg class="Float"> <value>10</value> </constructor-arg> <member key="backgroundColor" membership="attribute">!VisualizationModelExp</member> </bean>
<bean id="VisualizationModelControl" class="com.rubecula.darwin.visualization.VisualizationModel_Standard"> <constructor-arg> <ref bean="PopulationControl" /> </constructor-arg> <member membership="visualizationModel">!Applet</member> </bean>
<bean id="VisualizationModelExp" class="com.rubecula.darwin.visualization.VisualizationModel_Standard"> <constructor-arg> <ref bean="PopulationExp" /> </constructor-arg> <member membership="visualizationModel">!Applet</member> </bean>
<bean id="EnvironmentListener" class="com.rubecula.darwin.examples.pepperedmoth.EnvironmentListener_PepperedMoth"> <constructor-arg> <ref bean="VisualizationModelExp" /> </constructor-arg> </bean>
Closing tags...
</beans> </configuration>