2013年9月20日 星期五

Parameter file for ECJ

The following is an example of parameter file for running ECJ.

#No. of breeding threads, in general, it is set it to match the

#no. of cores or
#processors running on the computer
breedthreads = 1

#No. of evaluation threads

evalthreads = 1

#Setting the seed to ensure ECJ to produce the exact same 

#results.
seed.0 = 4357

# This setup the evolution state, which is created by ec.Evolve 

# for performing evolutionary process.
# However, prior to create the ec.EvolutionState, ec.Evolve will 
# create the following objects beforehand.
# i . Parameter Database, which holds all parameters 
# that ec.EvolutionState uses to build and process
# ii. Output, e.g. out.stat
# iii. Checkpointing Facility
# iv. No. of Threads, and random number generators, 
# one per thread
# v. No. of Jobs
state = ec.simple.SimpleEvolutionState

# Load class for population holding the individuals in the evolutionary process pop = ec.Population

# Load class for Initializer to create the initial population

# ec.simple.SimpleInitializer is the only known class
init = ec.simple.SimpleInitializer

# Finisher for clean up job at the very end of the run

ec.simple.SimpleFinisher is the only known class
finish = ec.simple.SimpleFinisher

# Breeder for creating new population based on existing 

# population using mutation and/or crossover
# There are four types of breeder in ECJ including:
DEBreederMuCommaLambdaBreederPSOBreederSimpleBreeder
breed = ec.simple.SimpleBreeder

# For assigning qualifier to each member of the Population

# There are four types of evaluator in ECJ including:
CompetitiveEvaluatorMultiPopCoevolutionaryEvaluator,
SimpleEvaluator
eval = ec.simple.SimpleEvaluator

# For statistics generation

ChartableStatisticsRandomRestartsSimpleShortStatistics,
SimpleStatisticsTarpeianStatistics
stat = ec.simple.SimpleStatistics

# For importing / exporting individuals from/to the population

InterPopulationExchangeIslandExchangeSimpleExchanger
exch = ec.simple.SimpleExchanger

# Parameters for the EvolutionState

generations = 1000

# whether or not to quit ECJ when it finds an ideal individual. 

# otherwise, it will continue until it runs out of generation.
quit-on-run-complete = false

# checkpointing is a facility to save state of process to a file

checkpoint = false
checkpoint-prefix = ec
# modulo tells by how many generation it will create one 
# checkpoint file
checkpoint-modulo = 1

# Output file

stat.file = $out.stat

# No. of population pop.subpops = 1

# Class of the population subpop.0, which is a repository of 
# individuals
pop.subpop.0 = ec.Subpopulation

# Size of the subpop.0 pop.subpop.0.size = 50

# This tells ECJ not to regenerate individual if it is 
# duplicate. 
pop.subpop.0.duplicate-retries = 0
# Species of the individual 
pop.subpop.0.species = ec.vector.BitVectorSpecies

# Define the fitness model and ec.simple.SimpleFitness defines 

# fitness values from 0.0 inclusive to infinity exclusive, 
# where 0.0 is the worst fitness
# Further, it can define an ideal fitness to any value 
# other than 0.
# There are three types of fitness in 
# ECJ KozaFitnessMultiObjectiveFitnessSimpleFitness 
pop.subpop.0.species.fitness = ec.simple.SimpleFitness

# Define representation

# The type of individual in the species
pop.subpop.0.species.ind = ec.vector.BitVectorIndividual

# Parameters of the species 

pop.subpop.0.species.genome-size = 200
pop.subpop.0.species.crossover-type = one
pop.subpop.0.species.crossover-prob = 0.3
pop.subpop.0.species.mutation-prob = 0.01

# Define pipeline for creating new individuals

# Top node is a vector mutation pipe 
pop.subpop.0.species.pipe = ec.vector.breed.VectorMutationPipeline
# Lower node is a vector crossover pipe
pop.subpop.0.species.pipe.source.0 = ec.vector.breed.VectorCrossoverPipeline
# Define two sources of individual for the crossover using tournament selection
pop.subpop.0.species.pipe.source.0.source.0 = ec.select.TournamentSelection
pop.subpop.0.species.pipe.source.0.source.1 = same

# set tournament size to 2 for all tournament cases

select.tournament.size = 2

# set the fitness function
eval.problem = ec.app.tutorial1.MaxOnes

2013年8月26日 星期一

Modify the fitness equation of Tutorial 1 of ECJ

Okay, this time I switch to ECJ, which is a comprehensive library for evolutionary computation as I have surfed the web again for an easier platform than those C++ libraries.  I've tried the Tutorial 1 that is simple and easy to follow. As you may know, evolutionary process relies on a fitness equation to find optimal value.

In tutorial 1, the optimal solution is defined as the maximum  number of "1s" or "trues" in a chromosome / genome. To do this, it defines the  fitness value using the following codes in the MaxOnes.java file.
int sum=0; for(int x=0; xsum += (ind2.genome[x] ? 1 : 0);
The best genome will be 11111 when the size of genome is 5. Alternatively, I want the best genome be 10101. To do this, I replace the above code with the followings:
int sum=0; 
 for(int x=0; x
 if ((ind2.genome[x]==true) && ((x+1)%2!=0)) sum++;
else if ((ind2.genome[x]==true) && ((x+1)%2!=0)) sum++;
This increases the fitness value by 1 if the gene value is true at odd position or if the gene value is false at even position. The result is an alternating 1s and 0s string. Next, I will try to understand the entire evolutionary process in ECJ and how to define a representation and evolving operators.



2013年8月13日 星期二

Compiling Evolving Objects on Windows 7

Recently, I am studying the use of genetic algorithm for my research studies. After a quick search for C++ API on the Internet, I can identify GALib and Evolving Objects (EO), which seems to be a good start to study how it works.

Setting up the GALib is simple that requires downloading the code and add it to a IDE. And I can run the code without much problem. GALib is also well-documented. However, it does not support Estimation of Distribution Algorithm (EDA) which EO does. For EO, it takes me two days to figure out how to compile and run the build-in examples. Simply because I don't know CMake and EO requires it for building the program, while I cannot find any useful information on the Internet for setting up the EO on Windows platform. That's why I write this blog to record the procedure to setting up EO on Windows.

I am using Windows 7 Home and NetBeans 7.3.1 (on Java SE 1.6). To start, I have installed the following compiler and Make Tool.
  • Cygwin 4.7.3 (includes gcc, g++ and GNU assembler, GNU Make and GNU Debugger)
  • CMake Tool 2.8.4


The following is step-by-step procedure and I also recommend to read the FAQ in the EO website before start.

1. Use the GIT tools in NetBeans to clone the code using the following link.
git://eodev.git.sourceforge.net/gitroot/eodev/eodev


2. Select EO1.3.1 only from the list of remote branches. Click Next and enter d:\ as parent directory and specify "eodev" as clone name. Then, click Finish and wait until the source code populated in the d:\eodev directory.

3. After completion of the cloning, Netbeans will ask for creating a new project. Then, choose create C/C++ project using existing sources, specify folder containing the sources, tool collection and configuration model you prefer. Choose custom mode and click Next.


4. Then you will see the following build tools configuration.The CMakeLists.txt is important that tells how to generate the Makefile for later compiling. Just leave all the items unchanged and click Next. 


5. Specify the working directory and build/clean command, then click Next.


6. Specify the source directory and click Next


7. Specify automatic configuration for the code assistance settings


8. Finally, specify the project name and click Finish.


9. A new project is added to the projects explorer and Netbeans will try to build the software. However, it will return the following error messages telling it cannot identify the C and C++ compilers. As you may see all the backslashes are missing in the location name.


10. To build the code, it requires two files:CMakeLists.txt and Makefiles. CMakeLists.txt is located under the EO directory, i.e. d:\eodev\eo. Try to modify the following lines in the file and save it.
  • Uncomment the following line

#cmake_minimum_required(VERSION 2.8)

  • Add the following lines under ADD_SUBDIRECTORY(tutorial) so that all the lesson codes are included during the build:

ADD_SUBDIRECTORY(tutorial/lesson1)
ADD_SUBDIRECTORY(tutorial/lesson2)
ADD_SUBDIRECTORY(tutorial/lesson3)
ADD_SUBDIRECTORY(tutorial/lesson4)
ADD_SUBDIRECTORY(tutorial/lesson5)
ADD_SUBDIRECTORY(tutorial/lession6)

11. Start the CMake GUI, specify d:/eodev/eo as the location of source code and location to build the binaries. Clear the cache by clicking File>Delete Cache.

12. Click "Configure" and a window will be displayed asking for generator, select "Unix Makefiles" and select "Specify Native Compilers". Enter C:/cygwin/bin/g++.exe for C++ and C:/cygwin/bin/gcc.exe for C.


13. Click Advanced to see all the variables. In particular, specify the followings

CMAKE_BUILD_TYPE = debug
CMAKE_CXX_COMPILER = C:/cygwin/bin/g++.exe
CMAKE_CXX_COMPILER_WITH_PATH = C:/cygwin/bin/g++.exe
CMAKE_C_COMPILER = C:/cygwin/bin/gcc.exe
CMAKE_C_COMPILER_WITH_PATH = C:/cygwin/bin/gcc.exe
CMAKE_RC_COMPILER= c:/cygwin/bin/windres.exe
CMAKE_RC_COMPILER_ENV_VAR = c:/cygwin/bin/windres.exe
CMAKE_CXX_FLAGS =
CMAKE_CXX_FLAGS_RELWITHDEBINFO= -O2 -g
CMAKE_CXX_FLAGS_RELEASE=-O2
CMAKE_CXX_FLAGS_DEBUG=-O0 -g

Then click "Configure". If everything okay, "Configuring done" will be displayed. Further click "Generate" to create the makefile.

14. Back to Netbeans, click "Clean and Build" to start the building process.

15. During the building process, the following errors are encountered.

D:/eodev/eo/tutorial/Lesson2/FirstBitEA.cpp:128:40: error: no matching function for call to ‘eoPropCombinedQuadOp >::add(eoNPtsBitXover >&, const double&, bool)’
D:/eodev/eo/tutorial/Lesson2/FirstBitEA.cpp:128:40: note: candidate is:
In file included from D:/eodev/eo/src/eo:63:0,
                 from D:/eodev/eo/tutorial/Lesson2/FirstBitEA.cpp:18:
D:/eodev/eo/src/eoProportionalCombinedOp.h:202:16: note: void eoPropCombinedQuadOp::add(eoQuadOp&, double) [with EOT = eoBit]

D:/eodev/eo/src/eoProportionalCombinedOp.h:202:16: note:   candidate expects 2 arguments, 3 provided

This refers to line 128 of FirstBitEA.cpp that the eoPropCombinedQuadOp.add function accepts two arguments only, but 3 are found. Just remove the third argument. Similar error can be found in FirstRealEA.cpp line 125 and other files.

16. This completes the settings and you can start to explore the example codes.