* whitespace cleanup
This commit is contained in:
parent
56c6edab04
commit
70e60a50d2
47 changed files with 1763 additions and 1873 deletions
|
|
@ -14,12 +14,12 @@
|
|||
|
||||
* test/t-eoSymreg.cpp (SymregNode::operator()): Initialize r1 and r2 to
|
||||
avoid compiler warnings.
|
||||
|
||||
|
||||
|
||||
|
||||
2006-07-02 Thomas Legrand <thomas.legrand@inria.fr>
|
||||
|
||||
* test/t-eoEasyPSO.cpp: added PSO test
|
||||
|
||||
|
||||
* test/Makefile.am: added PSO test
|
||||
|
||||
|
||||
|
|
@ -28,9 +28,9 @@
|
|||
* test/t-eoSyncEasyPSO.cpp: added synchronous PSO test
|
||||
* test/t-eoEasyPSO.cpp: customized PSO test (initialization)
|
||||
* test/Makefile.am: added synchronous PSO test
|
||||
|
||||
|
||||
* Local Variables:
|
||||
* coding: iso-8859-1
|
||||
* mode: flyspell
|
||||
* fill-column: 80
|
||||
* End:
|
||||
* End:
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
CVS Info: $Date: 2001-06-21 12:03:17 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/test/RoyalRoad.h,v 1.3 2001-06-21 12:03:17 jmerelo Exp $ $Author: jmerelo $
|
||||
*/
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ class RoyalRoad: public eoEvalFunc<EOT> {
|
|||
_eo.fitness( fitness );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
unsigned div;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
/** Just the simple function that takes binary value of a chromosome and sets
|
||||
the fitnes.
|
||||
@param _chrom A binary chromosome
|
||||
@param _chrom A binary chromosome
|
||||
*/
|
||||
|
||||
template <class Chrom> double binary_value(const Chrom& _chrom)
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@ import sys
|
|||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 2:
|
||||
print 'Usage: boxplot.py [Results files, ...]'
|
||||
sys.exit()
|
||||
print 'Usage: boxplot.py [Results files, ...]'
|
||||
sys.exit()
|
||||
|
||||
for i in range(1, len(sys.argv)):
|
||||
pylab.boxplot( [ [ float(value) for value in line.split() ] for line in open( sys.argv[i] ).readlines() ] )
|
||||
pylab.boxplot( [ [ float(value) for value in line.split() ] for line in open( sys.argv[i] ).readlines() ] )
|
||||
|
||||
pylab.xlabel('iterations')
|
||||
pylab.show()
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ struct fitness_traits< pair<Performance, Worth> >
|
|||
|
||||
/* end fitness_traits.h */
|
||||
|
||||
/* EO.h
|
||||
/* EO.h
|
||||
|
||||
The Fitness template argument is there for backward compatibility reasons
|
||||
|
||||
|
|
@ -236,7 +236,7 @@ public :
|
|||
{
|
||||
if (!fitness_traits::needs_mapping)
|
||||
{
|
||||
throw runtime_error("eoPop: no scaling needed, yet a scaling function is defined");
|
||||
throw runtime_error("eoPop: no scaling needed, yet a scaling function is defined");
|
||||
}
|
||||
|
||||
(*p2w)(*this);
|
||||
|
|
@ -429,5 +429,3 @@ int main()
|
|||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
/** Just a simple function that takes an eoEsBase<double> and sets the fitnes
|
||||
to sphere
|
||||
/** Just a simple function that takes an eoEsBase<double> and sets the fitnes
|
||||
to sphere
|
||||
@param _ind vector<double>
|
||||
*/
|
||||
|
||||
|
|
@ -14,6 +14,3 @@ double real_value(const std::vector<double>& _ind)
|
|||
sum += _ind[i] * _ind[i];
|
||||
return sum/_ind.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
echo "Testing -h"
|
||||
./t-eoCheckpointing -h
|
||||
./t-eoCheckpointing -h
|
||||
|
||||
echo "Finished"
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@ int main()
|
|||
|
||||
// EO objects can be printed with stream operators
|
||||
std::cout << "chrom1 = " << chrom1 << std::endl
|
||||
<< "chrom2 = " << chrom2 << std::endl;
|
||||
|
||||
<< "chrom2 = " << chrom2 << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,14 +37,14 @@ main()
|
|||
C c1( 5,6,1 );
|
||||
cout << "Default constructor with values: " << endl
|
||||
<< c1 << endl;
|
||||
|
||||
|
||||
}
|
||||
{
|
||||
eoUniform<T> aleat( 1,10 );
|
||||
C c1( 5,6, aleat );
|
||||
cout << "Random constructor: " << endl
|
||||
<< c1 << endl;
|
||||
|
||||
|
||||
}
|
||||
{
|
||||
C c1( 3,4,1 ), c2( c1 );
|
||||
|
|
@ -111,12 +111,12 @@ main()
|
|||
cout << "Number of Columns: " << endl
|
||||
<< c1.numOfCols() << endl;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
cout << "Class Name: " << endl
|
||||
<< c1.className() << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
cout << "-----------------------------------------------------" << endl
|
||||
<< "Catching exceptions: " << endl
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
#include <eoScalarFitness.h>
|
||||
|
|
@ -123,6 +122,3 @@ int main(int argc, char* argv[]) {
|
|||
cout << "Fitness achieved = " << pop[0].fitness() << endl;
|
||||
cout << "Function evaluations = " << evals.value() << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
// to avoid long name warnings
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4786)
|
||||
|
|
@ -113,38 +112,38 @@ int the_main(int argc, char **argv)
|
|||
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(std::cout);
|
||||
return 0;
|
||||
parser.printHelp(std::cout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Either load or initialize
|
||||
if (load_name.value() != "")
|
||||
{
|
||||
state.load(load_name.value()); // load the rest
|
||||
state.load(load_name.value()); // load the rest
|
||||
}
|
||||
else
|
||||
{
|
||||
// else
|
||||
// else
|
||||
|
||||
// initialize rng and population
|
||||
// initialize rng and population
|
||||
|
||||
rng.reseed(seed.value());
|
||||
rng.reseed(seed.value());
|
||||
|
||||
pop.resize(2);
|
||||
pop.resize(2);
|
||||
|
||||
pop[0].fitness(1);
|
||||
pop[1].fitness(2);
|
||||
pop[0].fitness(1);
|
||||
pop[1].fitness(2);
|
||||
}
|
||||
|
||||
while(checkpoint(pop))
|
||||
{
|
||||
pop[0].fitness(pop[0].fitness() + 1);
|
||||
pop[0].fitness(pop[0].fitness() + 1);
|
||||
|
||||
time_t now = time(0);
|
||||
time_t now = time(0);
|
||||
|
||||
while (time(0) == now) {} // wait a second to test timed saver
|
||||
while (time(0) == now) {} // wait a second to test timed saver
|
||||
|
||||
std::cout << "gen " << generationCounter.value() << std::endl;
|
||||
std::cout << "gen " << generationCounter.value() << std::endl;
|
||||
}
|
||||
|
||||
// run the algorithm
|
||||
|
|
@ -152,9 +151,9 @@ int the_main(int argc, char **argv)
|
|||
// Save when needed
|
||||
if (save_name.value() != "")
|
||||
{
|
||||
std::string file_name = save_name.value();
|
||||
save_name.value() = ""; // so that it does not appear in the parser section of the state file
|
||||
state.save(file_name);
|
||||
std::string file_name = save_name.value();
|
||||
save_name.value() = ""; // so that it does not appear in the parser section of the state file
|
||||
state.save(file_name);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
|
@ -164,11 +163,11 @@ int main(int argc, char **argv)
|
|||
{
|
||||
try
|
||||
{
|
||||
the_main(argc, argv);
|
||||
the_main(argc, argv);
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
#include <utility>
|
||||
|
||||
#include <eo>
|
||||
|
|
@ -13,16 +12,16 @@ class DualSphere : public eoEvalFunc<EOT>
|
|||
public:
|
||||
virtual void operator()( EOT & x )
|
||||
{
|
||||
if( x.invalid() ) { return; }
|
||||
if( x.invalid() ) { return; }
|
||||
|
||||
double sum = 0;
|
||||
int sign = 1;
|
||||
for( unsigned int i=0, s=x.size(); i<s; ++i ) {
|
||||
sum += x[i] * x[i];
|
||||
sign *= x[i]<0 ? -1 : 1;
|
||||
}
|
||||
double sum = 0;
|
||||
int sign = 1;
|
||||
for( unsigned int i=0, s=x.size(); i<s; ++i ) {
|
||||
sum += x[i] * x[i];
|
||||
sign *= x[i]<0 ? -1 : 1;
|
||||
}
|
||||
|
||||
x.fitness( std::make_pair( sum, sign>0 ? true : false ) );
|
||||
x.fitness( std::make_pair( sum, sign>0 ? true : false ) );
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -60,7 +59,7 @@ int main()
|
|||
pop.push_back( sol4 );
|
||||
// on the sphere function everyone has the same fitness of 1
|
||||
if( test(pop, 0) != 0 ) {
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pop.erase(pop.begin(),pop.end());
|
||||
|
|
@ -75,7 +74,7 @@ int main()
|
|||
pop.push_back( sol3 );
|
||||
pop.push_back( sol4 );
|
||||
if( test(pop, 1) != 1 ) {
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// test on a random normal distribution
|
||||
|
|
@ -84,7 +83,6 @@ int main()
|
|||
pop = eoPop<DualVector>( 1000000, init_N );
|
||||
double iqr = test(pop, 1.09);
|
||||
if( iqr < 1.08 || iqr > 1.11 ) {
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,34 +37,34 @@ int main_function(int argc, char *argv[])
|
|||
eoParser parser(argc, argv); // for user-parameter reading
|
||||
eoState state; // keeps all things allocated
|
||||
eoValueParam<bool>& simpleParam = parser.getORcreateParam(true, "Isotropic",
|
||||
"Isotropic self-adaptive mutation",
|
||||
'i', "ES mutation");
|
||||
"Isotropic self-adaptive mutation",
|
||||
'i', "ES mutation");
|
||||
eoValueParam<bool>& stdevsParam = parser.getORcreateParam(false, "Stdev",
|
||||
"One self-adaptive stDev per variable",
|
||||
's', "ES mutation");
|
||||
"One self-adaptive stDev per variable",
|
||||
's', "ES mutation");
|
||||
eoValueParam<bool>& corrParam = parser.getORcreateParam(false, "Correl",
|
||||
"Use correlated mutations",
|
||||
'c', "ES mutation");
|
||||
"Use correlated mutations",
|
||||
'c', "ES mutation");
|
||||
// Run the appropriate algorithm
|
||||
if (simpleParam.value() == false)
|
||||
{
|
||||
std::cout << "Using eoReal" << std::endl;
|
||||
runAlgorithm(eoReal<FitT>(), parser, state);
|
||||
std::cout << "Using eoReal" << std::endl;
|
||||
runAlgorithm(eoReal<FitT>(), parser, state);
|
||||
}
|
||||
else if (stdevsParam.value() == false)
|
||||
{
|
||||
std::cout << "Using eoEsSimple" << std::endl;
|
||||
runAlgorithm(eoEsSimple<FitT>(), parser, state);
|
||||
std::cout << "Using eoEsSimple" << std::endl;
|
||||
runAlgorithm(eoEsSimple<FitT>(), parser, state);
|
||||
}
|
||||
else if (corrParam.value() == false)
|
||||
{
|
||||
std::cout << "Using eoEsStdev" << std::endl;
|
||||
runAlgorithm(eoEsStdev<FitT>(), parser, state);
|
||||
std::cout << "Using eoEsStdev" << std::endl;
|
||||
runAlgorithm(eoEsStdev<FitT>(), parser, state);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Using eoEsFull" << std::endl;
|
||||
runAlgorithm(eoEsFull<FitT>(), parser, state);
|
||||
std::cout << "Using eoEsFull" << std::endl;
|
||||
runAlgorithm(eoEsFull<FitT>(), parser, state);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -83,11 +83,11 @@ int main(int argc, char **argv)
|
|||
#endif
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cout << "Exception: " << e.what() << '\n';
|
||||
std::cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ int main_function(int argc, char *argv[])
|
|||
|
||||
// Define Parameters and load them
|
||||
eoValueParam<uint32_t>& seed = parser.createParam(static_cast<uint32_t>(time(0)),
|
||||
"seed", "Random number seed");
|
||||
"seed", "Random number seed");
|
||||
eoValueParam<string>& load_name = parser.createParam(string(), "Load","Load a state file",'L');
|
||||
eoValueParam<string>& save_name = parser.createParam(string(), "Save","Saves a state file",'S');
|
||||
eoValueParam<bool>& stdevs = parser.createParam(false, "Stdev", "Use adaptive mutation rates", 's');
|
||||
|
|
@ -62,23 +62,23 @@ int main_function(int argc, char *argv[])
|
|||
// Run the appropriate algorithm
|
||||
if (stdevs.value() == false && corr.value() == false)
|
||||
{
|
||||
runAlgorithm(eoEsSimple<FitT>() ,parser, state, bounds, load_name);
|
||||
runAlgorithm(eoEsSimple<FitT>() ,parser, state, bounds, load_name);
|
||||
}
|
||||
else if (corr.value() == true)
|
||||
{
|
||||
runAlgorithm(eoEsFull<FitT>(),parser, state, bounds, load_name);
|
||||
runAlgorithm(eoEsFull<FitT>(),parser, state, bounds, load_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
runAlgorithm(eoEsStdev<FitT>(), parser, state, bounds, load_name);
|
||||
runAlgorithm(eoEsStdev<FitT>(), parser, state, bounds, load_name);
|
||||
}
|
||||
|
||||
// and save
|
||||
if (!save_name.value().empty())
|
||||
{
|
||||
string file_name = save_name.value();
|
||||
save_name.value() = ""; // so that it does not appear in the parser section of the state file
|
||||
state.save(file_name);
|
||||
string file_name = save_name.value();
|
||||
save_name.value() = ""; // so that it does not appear in the parser section of the state file
|
||||
state.save(file_name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -98,11 +98,11 @@ int main(int argc, char **argv)
|
|||
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cout << "Exception: " << e.what() << '\n';
|
||||
std::cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
|
@ -120,7 +120,7 @@ void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoRealVectorBounds& _
|
|||
|
||||
if (lambda_rate.value() < 1.0f)
|
||||
{
|
||||
throw logic_error("lambda_rate must be larger than 1 in a comma strategy");
|
||||
throw logic_error("lambda_rate must be larger than 1 in a comma strategy");
|
||||
}
|
||||
|
||||
// Initialization
|
||||
|
|
@ -137,8 +137,8 @@ void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoRealVectorBounds& _
|
|||
}
|
||||
else
|
||||
{
|
||||
// evaluate initial population
|
||||
apply<EOT>(eval, pop);
|
||||
// evaluate initial population
|
||||
apply<EOT>(eval, pop);
|
||||
}
|
||||
|
||||
// Ok, time to set up the algorithm
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@ main()
|
|||
|
||||
// a chromosome randomizer
|
||||
eoBinRandom<Chrom> random;
|
||||
// the populations:
|
||||
eoPop<Chrom> pop;
|
||||
// the populations:
|
||||
eoPop<Chrom> pop;
|
||||
|
||||
// Evaluation
|
||||
eoEvalFuncPtr<Chrom> eval( binary_value );
|
||||
|
||||
|
||||
for (i = 0; i < POP_SIZE; ++i)
|
||||
{
|
||||
Chrom chrom(CHROM_SIZE);
|
||||
|
|
@ -29,12 +29,12 @@ main()
|
|||
eval(chrom);
|
||||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
|
||||
std::cout << "population:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
|
||||
|
||||
// selection
|
||||
eoLottery<Chrom> lottery;
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ main()
|
|||
eoBreeder<Chrom> breeder( propSel );
|
||||
propSel.addOp(bitflip, 0.25);
|
||||
propSel.addOp(xover, 0.75);
|
||||
|
||||
|
||||
// replacement
|
||||
eoInclusion<Chrom> inclusion;
|
||||
|
||||
|
|
@ -65,11 +65,10 @@ main()
|
|||
std::cout << "exception: " << e.what() << std::endl;;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
std::cout << "pop" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ double real_value (const Particle & _particle)
|
|||
{
|
||||
double sum = 0;
|
||||
for (unsigned i = 0; i < _particle.size ()-1; i++)
|
||||
sum += pow(_particle[i],2);
|
||||
sum += pow(_particle[i],2);
|
||||
return (sum);
|
||||
}
|
||||
|
||||
|
|
@ -50,15 +50,15 @@ int main()
|
|||
|
||||
// perform position initialization
|
||||
pop.append (POP_SIZE, random);
|
||||
|
||||
|
||||
// topology
|
||||
eoLinearTopology<Particle> topology(NEIGHBORHOOD_SIZE);
|
||||
|
||||
// the full initializer
|
||||
eoInitializer <Particle> init(eval,veloRandom,localInit,topology,pop);
|
||||
init();
|
||||
|
||||
|
||||
|
||||
|
||||
// bounds
|
||||
eoRealVectorBounds bnds(VEC_SIZE,-1.5,1.5);
|
||||
|
||||
|
|
@ -71,33 +71,32 @@ int main()
|
|||
// Terminators
|
||||
eoGenContinue <Particle> genCont1 (50);
|
||||
eoGenContinue <Particle> genCont2 (50);
|
||||
|
||||
|
||||
// PS flight
|
||||
eoEasyPSO<Particle> pso1(genCont1, eval, velocity, flight);
|
||||
|
||||
eoEasyPSO<Particle> pso2(init,genCont2, eval, velocity, flight);
|
||||
|
||||
|
||||
// flight
|
||||
try
|
||||
{
|
||||
pso1(pop);
|
||||
std::cout << "FINAL POPULATION AFTER PSO n°1:" << std::endl;
|
||||
pso1(pop);
|
||||
std::cout << "FINAL POPULATION AFTER PSO n°1:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
pso2(pop);
|
||||
std::cout << "FINAL POPULATION AFTER PSO n°2:" << std::endl;
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
pso2(pop);
|
||||
std::cout << "FINAL POPULATION AFTER PSO n°2:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cout << "exception: " << e.what() << std::endl;;
|
||||
exit(EXIT_FAILURE);
|
||||
std::cout << "exception: " << e.what() << std::endl;;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,11 +66,11 @@ int main(int argc, char **argv)
|
|||
{
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cout << "Exception: " << e.what() << " in t-eoExtendedVelocity" << std::endl;
|
||||
std::cout << "Exception: " << e.what() << " in t-eoExtendedVelocity" << std::endl;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <stdexcept> // runtime_error
|
||||
|
||||
#include <eoEvalFuncPtr.h>
|
||||
#include <other/external_eo>
|
||||
|
|
@ -61,9 +61,9 @@ bool UserDefMutate(UserDefStruct& a)
|
|||
a = RandomStruct(); // just for testing
|
||||
|
||||
if (rng.flip(0.1f))
|
||||
a.d = UserDefStruct::test;
|
||||
a.d = UserDefStruct::test;
|
||||
else
|
||||
a.d = UserDefStruct::another;
|
||||
a.d = UserDefStruct::another;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -72,13 +72,13 @@ bool UserDefBinCrossover(UserDefStruct& a, const UserDefStruct& b)
|
|||
std::cout << "UserDefBinCrossover\n";
|
||||
|
||||
if (rng.flip(0.5))
|
||||
a.a = b.a;
|
||||
a.a = b.a;
|
||||
if (rng.flip(0.5))
|
||||
a.b = b.b;
|
||||
a.b = b.b;
|
||||
if (rng.flip(0.5))
|
||||
a.c = b.c;
|
||||
a.c = b.c;
|
||||
if (rng.flip(0.5))
|
||||
a.d = b.d;
|
||||
a.d = b.d;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -86,13 +86,13 @@ bool UserDefQuadCrossover(UserDefStruct& a, UserDefStruct& b)
|
|||
{
|
||||
std::cout << "UserDefQuadCrossover\n";
|
||||
if (rng.flip(0.5))
|
||||
swap(a.a, b.a);
|
||||
swap(a.a, b.a);
|
||||
if (rng.flip(0.5))
|
||||
swap(a.b, b.b);
|
||||
swap(a.b, b.b);
|
||||
if (rng.flip(0.5))
|
||||
swap(a.c, b.c);
|
||||
swap(a.c, b.c);
|
||||
if (rng.flip(0.5))
|
||||
swap(a.d, b.d);
|
||||
swap(a.d, b.d);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// t-eoFitnessAssembled.cpp
|
||||
// Marc Wintermantel & Oliver Koenig
|
||||
|
|
@ -11,19 +11,19 @@
|
|||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@inria.fr
|
||||
mak@dhi.dk
|
||||
Marc.Schoenauer@inria.fr
|
||||
mak@dhi.dk
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
#include <iostream>
|
||||
|
|
@ -32,7 +32,7 @@
|
|||
#include "eoScalarFitnessAssembled.h"
|
||||
|
||||
void test_eoScalarFitnessAssembledClass(){
|
||||
|
||||
|
||||
// Create instances
|
||||
eoAssembledMinimizingFitness A,B,C(5, 1.3, "C value");
|
||||
|
||||
|
|
@ -53,9 +53,9 @@ void test_eoScalarFitnessAssembledClass(){
|
|||
std::cout << "C= " << C << std::endl;
|
||||
std::cout << "Printing values and descriptions: " << std::endl;
|
||||
std::cout << "A: "; A.printAll( std::cout ); std::cout << std::endl;
|
||||
std::cout << "B: "; B.printAll( std::cout ); std::cout << std::endl;
|
||||
std::cout << "B: "; B.printAll( std::cout ); std::cout << std::endl;
|
||||
std::cout << "C: "; C.printAll( std::cout ); std::cout << std::endl;
|
||||
|
||||
|
||||
A.resize(8, 100.3, "A resized");
|
||||
std::cout << "Resized A: "; A.printAll( std::cout ); std::cout << std::endl;
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ void test_eoScalarFitnessAssembledClass(){
|
|||
F=A;
|
||||
G= 7.5;
|
||||
std::cout << "F = A : " << F << "\t G = 7.5 : " << G << std::endl;
|
||||
|
||||
|
||||
// Comparing...
|
||||
std::cout << "A<B: " << (A<B) << std::endl;
|
||||
std::cout << "A>B: " << (A>B) << std::endl;
|
||||
|
|
@ -80,15 +80,15 @@ void test_eoScalarFitnessAssembledClass(){
|
|||
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
std::cout << "-----------------------------------" << std::endl;
|
||||
std::cout << "START t-eoFitnessAssembled" << std::endl;
|
||||
|
||||
try{
|
||||
// Test the fitness class itself
|
||||
test_eoScalarFitnessAssembledClass();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch(std::exception& e){
|
||||
|
|
@ -102,4 +102,3 @@ int main(){
|
|||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// t-eoFitnessAssembledEA.cpp
|
||||
// Marc Wintermantel & Oliver Koenig
|
||||
|
|
@ -11,19 +11,19 @@
|
|||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@inria.fr
|
||||
mak@dhi.dk
|
||||
Marc.Schoenauer@inria.fr
|
||||
mak@dhi.dk
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
|
@ -41,7 +41,7 @@
|
|||
#include <es/eoReal.h> // Definition of representation
|
||||
#include <es/eoRealInitBounded.h> // Uniformly initializes real vector in bounds
|
||||
#include <es/make_genotype_real.h> // Initialization of a genotype
|
||||
#include <eoEvalFunc.h> // Base class for fitness evaluation
|
||||
#include <eoEvalFunc.h> // Base class for fitness evaluation
|
||||
#include <es/make_op_real.h> // Variation operators using standard Real operators
|
||||
#include <eoScalarFitnessAssembled.h> // The fitness class
|
||||
typedef eoReal<eoAssembledMinimizingFitness> Indi;
|
||||
|
|
@ -51,7 +51,7 @@ typedef eoReal<eoAssembledMinimizingFitness> Indi;
|
|||
#include <do/make_continue.h> // The stopping criterion
|
||||
#include <do/make_checkpoint_assembled.h> // Outputs (stats, population dumps, ...)
|
||||
#include <do/make_algo_scalar.h> // Evolution engine (selection and replacement)
|
||||
#include <do/make_run.h> // simple call to the algo.stays there for consistency reasons
|
||||
#include <do/make_run.h> // simple call to the algo.stays there for consistency reasons
|
||||
|
||||
// Define a fitness class
|
||||
template <class EOT>
|
||||
|
|
@ -59,9 +59,9 @@ class eoAssembledEvalFunc : public eoEvalFunc<EOT>{
|
|||
public:
|
||||
// Constructor defining number and descriptions of fitness terms
|
||||
eoAssembledEvalFunc() {
|
||||
|
||||
|
||||
// Define a temporary fitness object to have access to its static traits
|
||||
typename EOT::Fitness tmpfit(3, 0.0);
|
||||
typename EOT::Fitness tmpfit(3, 0.0);
|
||||
tmpfit.setDescription(0,"Fitness");
|
||||
tmpfit.setDescription(1,"Some Value");
|
||||
tmpfit.setDescription(2,"Other Value");
|
||||
|
|
@ -70,27 +70,27 @@ public:
|
|||
|
||||
void operator()(EOT& _eo){
|
||||
|
||||
// Define temporary fitness object
|
||||
// Define temporary fitness object
|
||||
// (automatically gets initialized with size given in constructor)
|
||||
typename EOT::Fitness tmpfit;
|
||||
|
||||
|
||||
// Eval some dummy fitness
|
||||
double sum1=0.0, sum2=0.0;
|
||||
for (unsigned i=0; i < _eo.size(); ++i){
|
||||
sum1 += _eo[i]*_eo[i];
|
||||
sum2 += fabs(_eo[i]) + fabs(_eo[i]);
|
||||
}
|
||||
|
||||
|
||||
// Store some fitness terms
|
||||
tmpfit[1]= sum1;
|
||||
tmpfit[2]= sum2;
|
||||
|
||||
|
||||
// Store the fitness
|
||||
tmpfit = (sum1 + sum2)/_eo.size();
|
||||
|
||||
// Pass it
|
||||
_eo.fitness( tmpfit );
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -99,14 +99,14 @@ void make_help(eoParser & _parser);
|
|||
|
||||
// now use all of the above, + representation dependent things
|
||||
int main(int argc, char* argv[]){
|
||||
|
||||
|
||||
std::cout << "-----------------------------------" << std::endl;
|
||||
std::cout << "START t-eoFitnessAssembledEA" << std::endl;
|
||||
|
||||
try{
|
||||
|
||||
// Parser & State
|
||||
eoParser parser(argc, argv); // for user-parameter reading
|
||||
eoParser parser(argc, argv); // for user-parameter reading
|
||||
eoState state; // keeps all things allocated
|
||||
|
||||
////
|
||||
|
|
@ -120,7 +120,7 @@ int main(int argc, char* argv[]){
|
|||
|
||||
// The genotype
|
||||
eoRealInitBounded<Indi>& init = do_make_genotype(parser, state, Indi() );
|
||||
|
||||
|
||||
// The variation operators
|
||||
eoGenOp<Indi>& op = do_make_op(parser, state, init);
|
||||
|
||||
|
|
@ -158,7 +158,7 @@ int main(int argc, char* argv[]){
|
|||
std::cout << "Final Population\n";
|
||||
pop.sortedPrintOn(std::cout);
|
||||
std::cout << std::endl;
|
||||
|
||||
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue