Corrected the outState.regiserObject(parser) ommission (see SecondBitEA.html)
This commit is contained in:
parent
b225f093e6
commit
41a85aaa7d
1 changed files with 33 additions and 35 deletions
|
|
@ -47,15 +47,13 @@ istrstream</font></tt>
|
||||||
<br><b><tt><font color="#993300">#include <fstream></font></tt></b>
|
<br><b><tt><font color="#993300">#include <fstream></font></tt></b>
|
||||||
<br><tt><font color="#993300">// the general include for eo</font></tt>
|
<br><tt><font color="#993300">// the general include for eo</font></tt>
|
||||||
<br><b><tt><font color="#993300">#include <eo></font></tt></b>
|
<br><b><tt><font color="#993300">#include <eo></font></tt></b>
|
||||||
<br><tt><font color="#993300">// specific includes</font></tt>
|
|
||||||
<br><b><tt><font color="#993300">#include "eoSGATransform.h"</font></tt></b>
|
|
||||||
<br><b><tt><font color="#993300">#include "eoPropCombinedOp.h"</font></tt></b></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<a NAME="evalfunc"></a>
|
<a NAME="evalfunc"></a>
|
||||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||||
<tr>
|
<tr>
|
||||||
<td><b><tt><font color="#CC0000">#include "binary_value.h"</font></tt></b></td>
|
<td><tt><font color="#CC0000">// a simple fitness function that computes the number of ones of a bitstring</font></tt><br>
|
||||||
|
<b><tt><font color="#CC0000">#include "binary_value.h"</font></tt></b></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<a NAME="representation"></a>
|
<a NAME="representation"></a>
|
||||||
|
|
@ -76,14 +74,14 @@ parameters as constants, read them:</font></tt>
|
||||||
or -o=value)</font></tt>
|
or -o=value)</font></tt>
|
||||||
<br><tt><font color="#3366FF">//
|
<br><tt><font color="#3366FF">//
|
||||||
or in a parameter file (same syntax, order independent, </font></tt>
|
or in a parameter file (same syntax, order independent, </font></tt>
|
||||||
<br><tt><font color="#3366FF">//
|
<br><tt><font color="#3366FF">//
|
||||||
# = usual comment character </font></tt>
|
# = usual comment character </font></tt>
|
||||||
<br><tt><font color="#3366FF">//
|
<br><tt><font color="#3366FF">//
|
||||||
or in the environment (TODO)</font></tt>
|
or in the environment (TODO)</font></tt>
|
||||||
<br><tt><font color="#3366FF">// note that the parameters are passed by
|
<br><tt><font color="#3366FF">// note that the parameters are passed by
|
||||||
reference so they can be updated</font></tt>
|
reference so they can be updated</font></tt>
|
||||||
<br><b><tt><font color="#3366FF">void read_param(int argc, char *argv[], </font></tt></b>
|
<br><a NAME="seed_passing"></a><b><tt><font color="#3366FF">void read_param(eoParser & _parser, </font></tt></b>
|
||||||
<br><a NAME="seed_passing"></a><b><tt><font color="#660000">uint32 &
|
<br><b><tt><font color="#660000">uint32 &
|
||||||
_seed</font><font color="#3366FF">,</font></tt></b>
|
_seed</font><font color="#3366FF">,</font></tt></b>
|
||||||
<br><b><tt><font color="#999900">unsigned int & _vecSize</font><font color="#3366FF">,</font></tt></b>
|
<br><b><tt><font color="#999900">unsigned int & _vecSize</font><font color="#3366FF">,</font></tt></b>
|
||||||
<br><b><tt><font color="#009900">unsigned int & _popSize,</font></tt></b>
|
<br><b><tt><font color="#009900">unsigned int & _popSize,</font></tt></b>
|
||||||
|
|
@ -102,104 +100,100 @@ _seed</font><font color="#3366FF">,</font></tt></b>
|
||||||
<br><b><tt><font color="#CC33CC">double & _oneBitRate</font></tt></b>
|
<br><b><tt><font color="#CC33CC">double & _oneBitRate</font></tt></b>
|
||||||
<br><b><tt><font color="#3366FF">)</font></tt></b>
|
<br><b><tt><font color="#3366FF">)</font></tt></b>
|
||||||
<br><b><tt><font color="#3366FF">{ </font></tt></b>
|
<br><b><tt><font color="#3366FF">{ </font></tt></b>
|
||||||
<br><a NAME="parser_declare"></a><tt><font color="#3366FF">// define a
|
|
||||||
parser from the command-line arguments</font></tt>
|
|
||||||
<br><b><tt><font color="#3366FF"> eoParser parser(argc,
|
|
||||||
argv);</font></tt></b>
|
|
||||||
<br><tt><font color="#3366FF"><b> </b>// For each
|
<br><tt><font color="#3366FF"><b> </b>// For each
|
||||||
parameter, define Parameters directly in the parser, </font></tt>
|
parameter, define Parameters directly in the parser, </font></tt>
|
||||||
<br><tt><font color="#3366FF"><b> </b>// and assign
|
<br><tt><font color="#3366FF"><b> </b>// and assign
|
||||||
the value to the variable</font></tt>
|
the value to the variable</font></tt>
|
||||||
<br><a NAME="random"></a><a NAME="_seed_declare"></a><b><tt><font color="#3366FF">
|
<br><a NAME="random"></a><a NAME="_seed_declare"></a><b><tt><font color="#3366FF">
|
||||||
</font><font color="#660000">eoValueParam<uint32>& seedParam = parser.createParam<uint32>(time(0),
|
</font><font color="#660000">eoValueParam<uint32>& seedParam = _parser.createParam<uint32>(time(0),
|
||||||
"seed", "Random number seed", 'S');</font></tt></b>
|
"seed", "Random number seed", 'S');</font></tt></b>
|
||||||
<br><a NAME="seed_assign"></a><b><tt><font color="#660000">
|
<br><a NAME="seed_assign"></a><b><tt><font color="#660000">
|
||||||
_seed = seedParam.value();</font></tt></b>
|
_seed = seedParam.value();</font></tt></b>
|
||||||
<p><b><tt><font color="#3366FF"> </font><font color="#999900">eoValueParam<unsigned
|
<p><b><tt><font color="#3366FF"> </font><font color="#999900">eoValueParam<unsigned
|
||||||
int>& vecSizeParam = parser.createParam<unsigned int>(8, "vecSize",
|
int>& vecSizeParam = _parser.createParam<unsigned int>(8, "vecSize",
|
||||||
"Genotype size",'V', "Representation");</font></tt></b>
|
"Genotype size",'V', "Representation");</font></tt></b>
|
||||||
<br><b><tt><font color="#999900"> _vecSize = vecSizeParam.value();</font></tt></b>
|
<br><b><tt><font color="#999900"> _vecSize = vecSizeParam.value();</font></tt></b>
|
||||||
<p><b><tt><font color="#3366FF"> </font><font color="#009900">eoValueParam<unsigned
|
<p><b><tt><font color="#3366FF"> </font><font color="#009900">eoValueParam<unsigned
|
||||||
int>& popSizeParam = parser.createParam<unsigned int>(10, "popSize",
|
int>& popSizeParam = _parser.createParam<unsigned int>(10, "popSize",
|
||||||
"Population size",'P', "Evolution");</font></tt></b>
|
"Population size",'P', "Evolution");</font></tt></b>
|
||||||
<br><b><tt><font color="#009900"> _popSize = popSizeParam.value();</font></tt></b>
|
<br><b><tt><font color="#009900"> _popSize = popSizeParam.value();</font></tt></b>
|
||||||
<br><b><tt><font color="#009900"> eoValueParam<unsigned
|
<br><b><tt><font color="#009900"> eoValueParam<unsigned
|
||||||
int>& tSizeParam = parser.createParam<unsigned int>(10, "tSize",
|
int>& tSizeParam = _parser.createParam<unsigned int>(10, "tSize",
|
||||||
"Tournament size",'T', "Evolution");</font></tt></b>
|
"Tournament size",'T', "Evolution");</font></tt></b>
|
||||||
<br><b><tt><font color="#009900"> _tSize = tSizeParam.value();</font></tt></b>
|
<br><b><tt><font color="#009900"> _tSize = tSizeParam.value();</font></tt></b>
|
||||||
<br><a NAME="_load_name"></a>
|
<br><a NAME="_load_name"></a>
|
||||||
<br><b><tt><font color="#3366FF"> eoValueParam<string>&
|
<br><b><tt><font color="#3366FF"> eoValueParam<string>&
|
||||||
load_nameParam = parser.createParam<string>("", "Load","A save file
|
load_nameParam = _parser.createParam<string>("", "Load","A save file
|
||||||
to restart from",'L', "Persistence");</font></tt></b>
|
to restart from",'L', "Persistence");</font></tt></b>
|
||||||
<br><b><tt><font color="#3366FF"> _load_name =
|
<br><b><tt><font color="#3366FF"> _load_name =
|
||||||
load_nameParam.value();</font></tt></b>
|
load_nameParam.value();</font></tt></b>
|
||||||
<p><b><tt><font color="#3366FF"> eoValueParam<unsigned
|
<p><b><tt><font color="#3366FF"> eoValueParam<unsigned
|
||||||
int>& maxGenParam = parser.createParam<unsigned int>(100, "maxGen",
|
int>& maxGenParam = _parser.createParam<unsigned int>(100, "maxGen",
|
||||||
"Maximum number of generations",'G', "Stopping criterion");</font></tt></b>
|
"Maximum number of generations",'G', "Stopping criterion");</font></tt></b>
|
||||||
<br><b><tt><font color="#3366FF"> _maxGen = maxGenParam.value();</font></tt></b>
|
<br><b><tt><font color="#3366FF"> _maxGen = maxGenParam.value();</font></tt></b>
|
||||||
<br><b><tt><font color="#3366FF"> eoValueParam<unsigned
|
<br><b><tt><font color="#3366FF"> eoValueParam<unsigned
|
||||||
int>& minGenParam = parser.createParam<unsigned int>(100, "minGen",
|
int>& minGenParam = _parser.createParam<unsigned int>(100, "minGen",
|
||||||
"Minimum number of generations",'g', "Stopping criterion");</font></tt></b>
|
"Minimum number of generations",'g', "Stopping criterion");</font></tt></b>
|
||||||
<br><b><tt><font color="#3366FF"> _minGen = minGenParam.value();</font></tt></b>
|
<br><b><tt><font color="#3366FF"> _minGen = minGenParam.value();</font></tt></b>
|
||||||
<br><b><tt><font color="#3366FF"> eoValueParam<unsigned
|
<br><b><tt><font color="#3366FF"> eoValueParam<unsigned
|
||||||
int>& steadyGenParam = parser.createParam<unsigned int>(100, "steadyGen",
|
int>& steadyGenParam = _parser.createParam<unsigned int>(100, "steadyGen",
|
||||||
"Number of generations with no improvement",'s', "Stopping criterion");</font></tt></b>
|
"Number of generations with no improvement",'s', "Stopping criterion");</font></tt></b>
|
||||||
<br><b><tt><font color="#3366FF"> _steadyGen =
|
<br><b><tt><font color="#3366FF"> _steadyGen =
|
||||||
steadyGenParam.value();</font></tt></b>
|
steadyGenParam.value();</font></tt></b>
|
||||||
<p><b><tt><font color="#CC33CC"> eoValueParam<double>&
|
<p><b><tt><font color="#CC33CC"> eoValueParam<double>&
|
||||||
pCrossParam = parser.createParam<double>(0.6, "pCross", "Probability
|
pCrossParam = _parser.createParam<double>(0.6, "pCross", "Probability
|
||||||
of Crossover", 'C', "Genetic Operators"); </font></tt></b>
|
of Crossover", 'C', "Genetic Operators"); </font></tt></b>
|
||||||
<br><b><tt><font color="#CC33CC"> _pCross = pCrossParam.value();</font></tt></b>
|
<br><b><tt><font color="#CC33CC"> _pCross = pCrossParam.value();</font></tt></b>
|
||||||
<br><b><tt><font color="#CC33CC"> eoValueParam<double>&
|
<br><b><tt><font color="#CC33CC"> eoValueParam<double>&
|
||||||
pMutParam = parser.createParam<double>(0.1, "pMut", "Probability of
|
pMutParam = _parser.createParam<double>(0.1, "pMut", "Probability of
|
||||||
Mutation", 'M', "Genetic Operators");</font></tt></b>
|
Mutation", 'M', "Genetic Operators");</font></tt></b>
|
||||||
<br><b><tt><font color="#CC33CC"> _pMut = pMutParam.value();</font></tt></b>
|
<br><b><tt><font color="#CC33CC"> _pMut = pMutParam.value();</font></tt></b>
|
||||||
<br><b><tt><font color="#CC33CC"> eoValueParam<double>&
|
<br><b><tt><font color="#CC33CC"> eoValueParam<double>&
|
||||||
onePointRateParam = parser.createParam<double>(1, "onePointRate", "Relative
|
onePointRateParam = _parser.createParam<double>(1, "onePointRate", "Relative
|
||||||
rate for one point crossover", '1', "Genetic Operators");</font></tt></b>
|
rate for one point crossover", '1', "Genetic Operators");</font></tt></b>
|
||||||
<br><b><tt><font color="#CC33CC"> _onePointRate
|
<br><b><tt><font color="#CC33CC"> _onePointRate
|
||||||
= onePointRateParam.value();</font></tt></b>
|
= onePointRateParam.value();</font></tt></b>
|
||||||
<br><b><tt><font color="#CC33CC"> eoValueParam<double>&
|
<br><b><tt><font color="#CC33CC"> eoValueParam<double>&
|
||||||
twoPointsRateParam = parser.createParam<double>(1, "twoPointRate", "Relative
|
twoPointsRateParam = _parser.createParam<double>(1, "twoPointRate", "Relative
|
||||||
rate for two point crossover", '2', "Genetic Operators");</font></tt></b>
|
rate for two point crossover", '2', "Genetic Operators");</font></tt></b>
|
||||||
<br><b><tt><font color="#CC33CC"> _twoPointsRate
|
<br><b><tt><font color="#CC33CC"> _twoPointsRate
|
||||||
= twoPointsRateParam.value();</font></tt></b>
|
= twoPointsRateParam.value();</font></tt></b>
|
||||||
<br><b><tt><font color="#CC33CC"> eoValueParam<double>&
|
<br><b><tt><font color="#CC33CC"> eoValueParam<double>&
|
||||||
uRateParam = parser.createParam<double>(2, "uRate", "Relative rate for
|
uRateParam = _parser.createParam<double>(2, "uRate", "Relative rate for
|
||||||
uniform crossover", 'U', "Genetic Operators");</font></tt></b>
|
uniform crossover", 'U', "Genetic Operators");</font></tt></b>
|
||||||
<br><b><tt><font color="#CC33CC"> _uRate =
|
<br><b><tt><font color="#CC33CC"> _uRate =
|
||||||
uRateParam.value();</font></tt></b>
|
uRateParam.value();</font></tt></b>
|
||||||
<br><b><tt><font color="#CC33CC"> eoValueParam<double>&
|
<br><b><tt><font color="#CC33CC"> eoValueParam<double>&
|
||||||
pMutPerBitParam = parser.createParam<double>(0.01, "pMutPerBit", "Probability
|
pMutPerBitParam = _parser.createParam<double>(0.01, "pMutPerBit", "Probability
|
||||||
of flipping 1 bit in bit-flip mutation", 'b', "Genetic Operators");</font></tt></b>
|
of flipping 1 bit in bit-flip mutation", 'b', "Genetic Operators");</font></tt></b>
|
||||||
<br><b><tt><font color="#CC33CC"> _pMutPerBit =
|
<br><b><tt><font color="#CC33CC"> _pMutPerBit =
|
||||||
pMutPerBitParam.value();</font></tt></b>
|
pMutPerBitParam.value();</font></tt></b>
|
||||||
<br><b><tt><font color="#CC33CC"> eoValueParam<double>&
|
<br><b><tt><font color="#CC33CC"> eoValueParam<double>&
|
||||||
bitFlipRateParam = parser.createParam<double>(0.01, "bitFlipRate", "Relative
|
bitFlipRateParam = _parser.createParam<double>(0.01, "bitFlipRate", "Relative
|
||||||
rate for bit-flip mutation", 'B', "Genetic Operators");</font></tt></b>
|
rate for bit-flip mutation", 'B', "Genetic Operators");</font></tt></b>
|
||||||
<br><b><tt><font color="#CC33CC"> _bitFlipRate
|
<br><b><tt><font color="#CC33CC"> _bitFlipRate
|
||||||
= bitFlipRateParam.value();</font></tt></b>
|
= bitFlipRateParam.value();</font></tt></b>
|
||||||
<br><b><tt><font color="#CC33CC"> eoValueParam<double>&
|
<br><b><tt><font color="#CC33CC"> eoValueParam<double>&
|
||||||
oneBitRateParam = parser.createParam<double>(0.01, "oneBitRate", "Relative
|
oneBitRateParam = _parser.createParam<double>(0.01, "oneBitRate", "Relative
|
||||||
rate for deterministic bit-flip mutation", 'D', "Genetic Operators");</font></tt></b>
|
rate for deterministic bit-flip mutation", 'D', "Genetic Operators");</font></tt></b>
|
||||||
<br><b><tt><font color="#CC33CC">
|
<br><b><tt><font color="#CC33CC">
|
||||||
_oneBitRate = oneBitRateParam.value();</font></tt></b>
|
_oneBitRate = oneBitRateParam.value();</font></tt></b>
|
||||||
<p><tt><font color="#3366FF"><b> </b>// the name
|
<p><tt><font color="#3366FF"><b> </b>// the name
|
||||||
of the "status" file where all actual parameter values will be saved</font></tt>
|
of the "status" file where all actual parameter values will be saved</font></tt>
|
||||||
<br><b><tt><font color="#3366FF"> string str_status
|
<br><b><tt><font color="#3366FF"> string str_status
|
||||||
= parser.ProgramName() + ".status";</font></tt></b>
|
= _parser.ProgramName() + ".status";</font></tt></b>
|
||||||
<br><b><tt><font color="#3366FF"> eoValueParam<string>&
|
<br><b><tt><font color="#3366FF"> eoValueParam<string>&
|
||||||
status_nameParam = parser.createParam<string>(str_status.c_str(), "status","Status
|
status_nameParam = _parser.createParam<string>(str_status.c_str(), "status","Status
|
||||||
file",'S', "Persistence");</font></tt></b>
|
file",'S', "Persistence");</font></tt></b>
|
||||||
<br><tt><font color="#3366FF"><b> </b>// do the following AFTER
|
<br><tt><font color="#3366FF"><b> </b>// do the following AFTER
|
||||||
ALL PARAMETERS HAVE BEEN PROCESSED</font></tt>
|
ALL PARAMETERS HAVE BEEN PROCESSED</font></tt>
|
||||||
<br><tt><font color="#3366FF"><b> </b>// i.e. in case you need
|
<br><tt><font color="#3366FF"><b> </b>// i.e. in case you need
|
||||||
parameters somewhere else, postpone these</font></tt>
|
parameters somewhere else, postpone these</font></tt>
|
||||||
<br><b><tt><font color="#3366FF"> if (parser.userNeedsHelp())</font></tt></b>
|
<br><b><tt><font color="#3366FF"> if (_parser.userNeedsHelp())</font></tt></b>
|
||||||
<br><b><tt><font color="#3366FF">
|
<br><b><tt><font color="#3366FF">
|
||||||
{</font></tt></b>
|
{</font></tt></b>
|
||||||
<br><b><tt><font color="#3366FF">
|
<br><b><tt><font color="#3366FF">
|
||||||
parser.printHelp(cout);</font></tt></b>
|
_parser.printHelp(cout);</font></tt></b>
|
||||||
<br><b><tt><font color="#3366FF">
|
<br><b><tt><font color="#3366FF">
|
||||||
exit(1);</font></tt></b>
|
exit(1);</font></tt></b>
|
||||||
<br><b><tt><font color="#3366FF">
|
<br><b><tt><font color="#3366FF">
|
||||||
|
|
@ -209,7 +203,7 @@ exit(1);</font></tt></b>
|
||||||
<br><b><tt><font color="#3366FF">
|
<br><b><tt><font color="#3366FF">
|
||||||
{</font></tt></b>
|
{</font></tt></b>
|
||||||
<br><b><tt><font color="#3366FF">ofstream os(status_nameParam.value().c_str());</font></tt></b>
|
<br><b><tt><font color="#3366FF">ofstream os(status_nameParam.value().c_str());</font></tt></b>
|
||||||
<br><tt><font color="#3366FF"><b>os << parser; </b>// and you can
|
<br><tt><font color="#3366FF"><b>os << _parser; </b>// and you can
|
||||||
use that file as parameter file</font></tt>
|
use that file as parameter file</font></tt>
|
||||||
<br><b><tt><font color="#3366FF">
|
<br><b><tt><font color="#3366FF">
|
||||||
}</font></tt></b>
|
}</font></tt></b>
|
||||||
|
|
@ -254,6 +248,10 @@ parameters for mutations;</font></tt>
|
||||||
<br><b><tt><font color="#CC33CC"> double pMutPerBit;</font></tt></b>
|
<br><b><tt><font color="#CC33CC"> double pMutPerBit;</font></tt></b>
|
||||||
<br><b><tt><font color="#CC33CC"> double bitFlipRate;</font></tt></b>
|
<br><b><tt><font color="#CC33CC"> double bitFlipRate;</font></tt></b>
|
||||||
<br><b><tt><font color="#CC33CC"> double oneBitRate;</font></tt></b>
|
<br><b><tt><font color="#CC33CC"> double oneBitRate;</font></tt></b>
|
||||||
|
<br><a NAME="parser_declare"></a><tt><font color="#3366FF"><b> </b>// define a
|
||||||
|
parser from the command-line arguments</font></tt>
|
||||||
|
<br><b><tt><font color="#3366FF"> eoParser parser(argc,
|
||||||
|
argv);</font></tt></b>
|
||||||
<br><tt><font color="#3366FF"><b> </b>// Now read the parameters
|
<br><tt><font color="#3366FF"><b> </b>// Now read the parameters
|
||||||
of the program</font></tt>
|
of the program</font></tt>
|
||||||
<br><b><tt><font color="#3366FF"> read_param(argc,
|
<br><b><tt><font color="#3366FF"> read_param(argc,
|
||||||
|
|
@ -521,10 +519,10 @@ of item the eoCheckpoint can handle: state savers:</font></tt>
|
||||||
<br><a NAME="outstate_declare"></a><b><tt><font color="#3366FF">
|
<br><a NAME="outstate_declare"></a><b><tt><font color="#3366FF">
|
||||||
eoState outState;</font></tt></b>
|
eoState outState;</font></tt></b>
|
||||||
<br><tt><font color="#3366FF"><b> </b>// Register
|
<br><tt><font color="#3366FF"><b> </b>// Register
|
||||||
the algorithm into the state (so it has something to save!!)</font></tt>
|
the algorithm into the state</font></tt>
|
||||||
<br><a NAME="outstate_register"></a><b><tt><font color="#3366FF">
|
<br><a NAME="outstate_register"></a><b><tt><font color="#3366FF"> outState.registerObject(parser);</font></tt></b>
|
||||||
outState.registerObject(rng);</font></tt></b>
|
|
||||||
<br><b><tt><font color="#3366FF"> outState.registerObject(pop);</font></tt></b>
|
<br><b><tt><font color="#3366FF"> outState.registerObject(pop);</font></tt></b>
|
||||||
|
<br><b><tt><font color="#3366FF"> outState.registerObject(rng);</font></tt></b>
|
||||||
<br><tt><font color="#3366FF"><b> </b>// and feed
|
<br><tt><font color="#3366FF"><b> </b>// and feed
|
||||||
the state to state savers</font></tt>
|
the state to state savers</font></tt>
|
||||||
<br><a NAME="statesaver_declare"></a><tt><font color="#3366FF"><b>
|
<br><a NAME="statesaver_declare"></a><tt><font color="#3366FF"><b>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue