Log Tool Configuration - GII/JEAF GitHub Wiki
The log tools allow the user to record information about the evolutionary process. The user cannot use any log but several log tools are implemented in the current version of the framework. The user can implement more or extend the existing ones following some conventions that will be explained in the following sections.
### How to create new log toolsThe log tools are subclasses of the abstract class LogTool. The next figure shows the class diagram of the logtool package. The log tools implement the observer pattern, so the LogTool class implements the Observer interface (currently, the only class observed is the EvolutionaryAlgorithm class).
logtoolclassdiagram.png
To create a new log tool, the user should implement a new subclass of the LogTool class. If this new subclass has specific parameters, these should be declared and, moreover, the user should override the method configure(Configuration conf) of the Configuration interface in order to allow the factory to configure this log tool. If the user overrides the method configure, the first call should be to the superclass configure method (i.e., super.configure(conf)), like in the following example:
public void configure(Configuration conf) {
super.configure(conf);
if (conf.containsKey("Value") {
this.value = conf.getDouble("Value");
} else {
ConfWarning w = new ConfWarning("Value",this.value);
w.warn();
}
}
The other method that the user should implement is the update method of the Observer interface. The first call of this method should be again a call to the superclass update method. This call is mandatory and necessary to create the log file the first time that the method is called. Here we show an example of an update method.
@Override
public void update(Observable o, Object arg) {
EvolutionaryAlgorithm algorithm = (EvolutionaryAlgorithm) o;
BestIndividualSpecification bestSpec = new BestIndividualSpecification();
Individual best;
super.update(o, arg);
if (algorithm.getState() == EvolutionaryAlgorithm.REPLACE_STATE && arg == null) {
best = (Individual) IndividualsProductTrader.get(bestSpec,
algorithm.getPopulation().getIndividuals(), 1, algorithm.getComparator()).get(0);
if (print && algorithm.getComparator().compare(best, this.to_compare) <= -1) {
int index_of_best = algorithm.getPopulation().getIndividuals().indexOf(best);
super.getLog().println(algorithm.getFEs() - algorithm.getPopulation().getSize() + index_of_best);
print = false;
}
}
if (algorithm.getState() == EvolutionaryAlgorithm.FINAL_STATE) {
print = true;
}
}
As it was explained in the configuration section, a log tool is configured by indicating three parameters (Class , Folder and Name). Only the Class tag is mandatory as well as other parameters that are specific for each log tool class.
<Log>
<Class></Class>
<Folder></Folder>
<Name></Name>
<!-- Other specific configuration parameters -->
</Log>
Both, Folder and Name tags are string variables that could include regular expressions, which are replaced with their specific values during the execution of the algorithm. Here, we present a list of regular expressions that could be used in the pattern:
- ID: is the identifier name of the log tool.
- ALG: is the identifier of the evolutionary algorithm.
- OF: this expression will be replaced with the name of the objective function that is being solved. If the problem is multiobjective, this expression will be replaced with the name of the first function.
- POP: it will be replaced with the population size.
- DIM: this expression will be replaced with the dimension of the problem (i.e., the chromosome size).
- ND: it will be replaced with the node number (range) of the node where the algorithm is executed. So, every node will record the information in a different log file. When the algorithm is executed in non-distributed environments, ND will be replaced by 0.
- USR: it will be replaced with a text provided by the user as an algorithm attribute. This attribute could be changed with the method setUserTag(String tag) of the EvolutionaryAlgorithm class.
-
TS: this expression will be replaced with a timestamp like "YYYYMMDDHHmmSS", where:
- YYYY: is the current year with four numbers.
- MM: is the current month with two numbers.
- DD: is the current day with two numbers.
- HH: is the current hour in 24 hours format.
- mm: are the current minutes.
- SS: are the current seconds.
For example, a configuration like the following will create a BestMeanLogTool log file in a folder with the name /home/pilar/pruebas/SphereObjective if the user is solving the objective function SphereObjective, with the name bestmean_50_10_20080929183755.txt, with a population size of 50, with a chromosome size of 10 and when the user executes the algorithm on 29th September 2008, at 18:37:55.
<Log>
<Class>es.udc.gii.common.eaf.log.BestMeanLogTool</Class>
<Folder>/home/pilar/pruebas/OF/</Folder>
<Name>ID_POP_DIM_TS.txt</Name>
</Log>
As we said before, the Folder and Class tags are not mandatory. If one of them does not appear in the configuration file, its default values are:
- Folder: working_directory/OF
- Name: ALG_POP_TS.txt (monoprocessor environment) or ALG_POP_TS_ND.txt (distributed environment).
A list of the implemented log tool, and explanation of their behavior and configuration examples are showed in the javadoc section.