* whitespace cleanup
This commit is contained in:
parent
56c6edab04
commit
70e60a50d2
195 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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
#include <eoInit.h>
|
||||
#include <eoCounter.h>
|
||||
|
||||
|
|
@ -13,7 +12,7 @@ class Tester : public eoInit<int>
|
|||
public :
|
||||
void operator()(int& i)
|
||||
{
|
||||
i=1;
|
||||
i=1;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ int main(int argc, char* argv[])
|
|||
///// FIRST, problem or representation dependent stuff
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
// The evaluation fn - encapsulated into an eval counter for output
|
||||
// The evaluation fn - encapsulated into an eval counter for output
|
||||
eoEvalFuncPtr<EOT, double> mainEval( binary_value<EOT> );
|
||||
eoEvalFuncCounter<EOT> eval(mainEval);
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: mkeijzer@dhi.dk
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -38,10 +38,10 @@ struct Dummy : public EO<double>
|
|||
Dummy(std::string _s="") : s(_s) {}
|
||||
|
||||
void printOn(std::ostream & _os) const
|
||||
{
|
||||
EO<double>::printOn(_os);
|
||||
_os << " - " << s ;
|
||||
}
|
||||
{
|
||||
EO<double>::printOn(_os);
|
||||
_os << " - " << s ;
|
||||
}
|
||||
|
||||
std::string s;
|
||||
};
|
||||
|
|
@ -179,9 +179,9 @@ void init(eoPop<Dummy> & _pop, unsigned _pSize)
|
|||
for (unsigned i=0; i<_pSize; i++)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << i;
|
||||
_pop[i] = Dummy(os.str());
|
||||
_pop[i].fitness(i);
|
||||
os << i;
|
||||
_pop[i] = Dummy(os.str());
|
||||
_pop[i].fitness(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -190,7 +190,7 @@ int the_main(int argc, char **argv)
|
|||
{
|
||||
eoParser parser(argc, argv);
|
||||
eoValueParam<unsigned int> parentSizeParam(
|
||||
parser.createParam(unsigned(10), "parentSize", "Parent size",'P'));
|
||||
parser.createParam(unsigned(10), "parentSize", "Parent size",'P'));
|
||||
pSize = parentSizeParam.value(); // global variable
|
||||
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
|
|
@ -201,8 +201,8 @@ int the_main(int argc, char **argv)
|
|||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(std::cout);
|
||||
exit(1);
|
||||
parser.printHelp(std::cout);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
////////////////////////////////// define operators
|
||||
|
|
@ -379,11 +379,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 <eo>
|
||||
#include <es.h>
|
||||
#include <utils/eoStat.h>
|
||||
|
|
@ -39,7 +38,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());
|
||||
|
|
@ -54,7 +53,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
|
||||
|
|
@ -63,7 +62,6 @@ int main()
|
|||
pop = eoPop<realVec>( 1000000, init_N );
|
||||
double iqr = test(pop, 1.09);
|
||||
if( iqr < 1.08 || iqr > 1.11 ) {
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@ bool check_permutation(const Chrom & _chrom)
|
|||
std::cout << " Error: Wrong permutation !" << std::endl;
|
||||
std::string s;
|
||||
s.append( " Wrong permutation in t-eoInitPermutation");
|
||||
throw std::runtime_error( s );
|
||||
throw std::runtime_error( s );
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
int main()
|
||||
|
|
@ -44,13 +44,13 @@ int main()
|
|||
|
||||
// a chromosome randomizer
|
||||
eoInitPermutation <Chrom> random(CHROM_SIZE);
|
||||
|
||||
// the population:
|
||||
|
||||
// the population:
|
||||
eoPop<Chrom> pop;
|
||||
|
||||
|
||||
// Evaluation
|
||||
eoEvalFuncPtr<Chrom> eval( real_value );
|
||||
|
||||
|
||||
for (i = 0; i < POP_SIZE; ++i)
|
||||
{
|
||||
Chrom chrom(CHROM_SIZE);
|
||||
|
|
@ -61,7 +61,7 @@ int main()
|
|||
check_permutation(chrom);
|
||||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,13 +38,13 @@ int main()
|
|||
|
||||
// a chromosome randomizer
|
||||
eoInitPermutation <Chrom> random(CHROM_SIZE);
|
||||
|
||||
// the population:
|
||||
|
||||
// the population:
|
||||
eoPop<Chrom> pop;
|
||||
|
||||
|
||||
// Evaluation
|
||||
//eoEvalFuncPtr<Chrom> eval( real_value );
|
||||
|
||||
|
||||
for (i = 0; i < POP_SIZE; ++i)
|
||||
{
|
||||
Chrom chrom(CHROM_SIZE);
|
||||
|
|
@ -52,18 +52,18 @@ int main()
|
|||
//eval(chrom);
|
||||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
|
||||
// a shift mutation
|
||||
eoOrderXover<Chrom> cross;
|
||||
|
||||
|
||||
for (i = 0; i < POP_SIZE; ++i)
|
||||
std::cout << " Initial chromosome n<>" << i << " : " << pop[i] << "..." << std::endl;
|
||||
|
||||
cross(pop[0],pop[1]);
|
||||
cross(pop[1],pop[2]);
|
||||
|
||||
|
||||
for (i = 0; i < POP_SIZE; ++i) {
|
||||
std::cout << " Initial chromosome n<>" << i << " becomes : " << pop[i] << " after orderXover" << std::endl;
|
||||
std::cout << " Initial chromosome n<>" << i << " becomes : " << pop[i] << " after orderXover" << std::endl;
|
||||
check_permutation(pop[i]);
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -98,14 +98,14 @@ int main(int argc, char* argv[])
|
|||
|
||||
// now create the snapshot monitor
|
||||
eoValueParam<bool>& plotDistribParam = parser.getORcreateParam(false, "plotDistrib",
|
||||
"Plot Distribution", '\0',
|
||||
"Output - Graphical");
|
||||
"Plot Distribution", '\0',
|
||||
"Output - Graphical");
|
||||
if (plotDistribParam.value())
|
||||
{
|
||||
#ifdef HAVE_GNUPLOT
|
||||
unsigned frequency=1; // frequency of plots updates
|
||||
eoGnuplot1DSnapshot *distribSnapshot = new eoGnuplot1DSnapshot(ptDirNameParam->value(),
|
||||
frequency, "distrib");
|
||||
frequency, "distrib");
|
||||
state.storeFunctor(distribSnapshot);
|
||||
// add the distribution (it is an eoValueParam<vector<double> >)
|
||||
distribSnapshot->add(distrib);
|
||||
|
|
@ -117,7 +117,7 @@ int main(int argc, char* argv[])
|
|||
// the algorithm: EDA
|
||||
// don't know where else to put the population size!
|
||||
unsigned popSize = parser.getORcreateParam(unsigned(100), "popSize",
|
||||
"Population Size", 'P', "Algorithm").value();
|
||||
"Population Size", 'P', "Algorithm").value();
|
||||
eoSimpleEDA<Indi> eda(update, eval, popSize, checkpoint);
|
||||
|
||||
///// End of construction of the algorith
|
||||
|
|
|
|||
|
|
@ -24,21 +24,21 @@ int main()
|
|||
double sigma(5.);
|
||||
double sum(0.);
|
||||
for(size_t i=0; i<num; ++i)
|
||||
sum += abs(rng.normal(sigma));
|
||||
sum += abs(rng.normal(sigma));
|
||||
sum /= double(num);
|
||||
if(sum > sigma / 0.68) {
|
||||
cerr << "Normal distribution seems out of bounds; "
|
||||
<< "rerun to make sure it wasn't a statistical outlier" << endl;
|
||||
return -1;
|
||||
cerr << "Normal distribution seems out of bounds; "
|
||||
<< "rerun to make sure it wasn't a statistical outlier" << endl;
|
||||
return -1;
|
||||
}
|
||||
sum = 0.;
|
||||
for(size_t i=0; i<num; ++i)
|
||||
sum += abs(rng.normal(mean, sigma) - mean);
|
||||
sum += abs(rng.normal(mean, sigma) - mean);
|
||||
sum /= double(num);
|
||||
if(sum > sigma / 0.68) {
|
||||
cerr << "Normal distribution seems out of bounds; "
|
||||
<< "rerun to make sure it wasn't a statistical outlier" << endl;
|
||||
return -1;
|
||||
cerr << "Normal distribution seems out of bounds; "
|
||||
<< "rerun to make sure it wasn't a statistical outlier" << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ int main(int argc, char* argv[])
|
|||
///// FIRST, problem or representation dependent stuff
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
// The evaluation fn - encapsulated into an eval counter for output
|
||||
eoEvalFuncPtr<EOT, double, const std::vector<double>&>
|
||||
mainEval( real_value );
|
||||
// The evaluation fn - encapsulated into an eval counter for output
|
||||
eoEvalFuncPtr<EOT, double, const std::vector<double>&>
|
||||
mainEval( real_value );
|
||||
eoEvalFuncCounter<EOT> eval(mainEval);
|
||||
|
||||
// the genotype - through a genotype initializer
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@
|
|||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <stdexcept> // runtime_error
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// tt.cpp:
|
||||
// tt.cpp:
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ public :
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
int the_main(int argc, char **argv)
|
||||
{
|
||||
{
|
||||
eoParser parser(argc, argv);
|
||||
eoValueParam<unsigned int> parentSizeParam(10, "parentSize", "Parent size",'P');
|
||||
parser.processParam( parentSizeParam );
|
||||
|
|
@ -73,13 +73,13 @@ int the_main(int argc, char **argv)
|
|||
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(std::cout);
|
||||
exit(1);
|
||||
parser.printHelp(std::cout);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
unsigned i;
|
||||
|
||||
std::cout << "Testing the replacements\nParents SIze = " << pSize
|
||||
std::cout << "Testing the replacements\nParents SIze = " << pSize
|
||||
<< " and offspring size = " << oSize << std::endl;
|
||||
|
||||
rng.reseed(42);
|
||||
|
|
@ -213,11 +213,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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,15 +19,15 @@ double f (const Indi & _indi)
|
|||
int main_function(int argc, char **argv)
|
||||
{
|
||||
//Parameters
|
||||
const unsigned int VEC_SIZE = 2;
|
||||
const unsigned int POP_SIZE = 10;
|
||||
const unsigned int NEIGHBORHOOD_SIZE= 3;
|
||||
const unsigned int VEC_SIZE = 2;
|
||||
const unsigned int POP_SIZE = 10;
|
||||
const unsigned int NEIGHBORHOOD_SIZE= 3;
|
||||
|
||||
rng.reseed (33);
|
||||
eoEvalFuncPtr<Indi, double, const Indi& > plainEval(f);
|
||||
eoEvalFuncCounter < Indi > eval (plainEval);
|
||||
eoUniformGenerator < double >uGen (0., 5.);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
eoUniformGenerator < double >sGen (-1., 1.);
|
||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||
eoFirstIsBestInit < Indi > localInit;
|
||||
|
|
@ -57,11 +57,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-eoRingTopology" << std::endl;
|
||||
std::cout << "Exception: " << e.what() << " in t-eoRingTopology" << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
#include <eoPop.h>
|
||||
#include <EO.h>
|
||||
#include <eoProportionalSelect.h>
|
||||
|
|
@ -29,22 +28,22 @@ int test_select()
|
|||
}
|
||||
|
||||
Select select;
|
||||
|
||||
|
||||
unsigned ndraws = 10000;
|
||||
|
||||
|
||||
for (unsigned i = 0; i < ndraws; ++i)
|
||||
{
|
||||
const TestEO& eo = select(pop);
|
||||
|
||||
|
||||
counts[eo.index]++;
|
||||
}
|
||||
|
||||
cout << "Threshold = " << 1./sqrt(double(ndraws)) << endl;
|
||||
|
||||
|
||||
for (unsigned i = 0; i < 4; ++i)
|
||||
{
|
||||
cout << counts[i]/ndraws << ' ';
|
||||
|
||||
|
||||
double c = counts[i]/ndraws;
|
||||
|
||||
if (fabs(c - probs[i]) > 1./sqrt((double)ndraws)) {
|
||||
|
|
@ -52,7 +51,7 @@ int test_select()
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cout << endl;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -62,7 +61,6 @@ int main()
|
|||
rng.reseed(44);
|
||||
|
||||
if (test_select<eoProportionalSelect<TestEO> >()) return 1;
|
||||
|
||||
|
||||
return test_select<eoStochasticUniversalSelect<TestEO> >();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
|
@ -29,5 +28,3 @@ int main() {
|
|||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -121,8 +121,8 @@ eoValueParam<unsigned> tournamentSizeParam = parser.createParam(unsigned(2), "to
|
|||
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(std::cout);
|
||||
exit(0);
|
||||
parser.printHelp(std::cout);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// hard-coded directory name ...
|
||||
|
|
@ -155,7 +155,7 @@ eoValueParam<unsigned> tournamentSizeParam = parser.createParam(unsigned(2), "to
|
|||
|
||||
// random seed
|
||||
eoValueParam<uint32_t>& seedParam = parser.createParam(uint32_t(0), "seed",
|
||||
"Random number seed", 'S');
|
||||
"Random number seed", 'S');
|
||||
if (seedParam.value() == 0)
|
||||
seedParam.value() = time(0);
|
||||
rng.reseed(seedParam.value());
|
||||
|
|
@ -212,11 +212,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;
|
||||
return 1;
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -230,11 +230,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;
|
||||
return 1;
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,13 +47,13 @@ int main()
|
|||
|
||||
// a chromosome randomizer
|
||||
eoInitPermutation <Chrom> random(CHROM_SIZE);
|
||||
|
||||
// the population:
|
||||
|
||||
// the population:
|
||||
eoPop<Chrom> pop;
|
||||
|
||||
|
||||
// Evaluation
|
||||
eoEvalFuncPtr<Chrom> eval( real_value );
|
||||
|
||||
|
||||
for (i = 0; i < POP_SIZE; ++i)
|
||||
{
|
||||
Chrom chrom(CHROM_SIZE);
|
||||
|
|
@ -61,10 +61,10 @@ int main()
|
|||
eval(chrom);
|
||||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
|
||||
// a shift mutation
|
||||
eoShiftMutation <Chrom> shift;
|
||||
|
||||
|
||||
for (i = 0; i < POP_SIZE; ++i)
|
||||
{
|
||||
std::cout << " Initial chromosome n°" << i << " : " << pop[i] << "..." << std::endl;
|
||||
|
|
@ -72,7 +72,7 @@ int main()
|
|||
std::cout << " ... becomes : " << pop[i] << " after shift mutation" << std::endl;
|
||||
check_permutation(pop[i]);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -89,22 +89,22 @@ 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());
|
||||
}
|
||||
|
||||
// run the algorithm
|
||||
|
|
@ -112,13 +112,13 @@ 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);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 100; ++i)
|
||||
rng.rand();
|
||||
rng.rand();
|
||||
|
||||
std::cout << "a random number is " << rng.random(1024) << std::endl;;
|
||||
|
||||
|
|
@ -129,11 +129,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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,13 +48,13 @@ int main()
|
|||
|
||||
// a chromosome randomizer
|
||||
eoInitPermutation <Chrom> random(CHROM_SIZE);
|
||||
|
||||
// the population:
|
||||
|
||||
// the population:
|
||||
eoPop<Chrom> pop;
|
||||
|
||||
|
||||
// Evaluation
|
||||
eoEvalFuncPtr<Chrom> eval( real_value );
|
||||
|
||||
|
||||
for (i = 0; i < POP_SIZE; ++i)
|
||||
{
|
||||
Chrom chrom(CHROM_SIZE);
|
||||
|
|
@ -62,11 +62,11 @@ int main()
|
|||
eval(chrom);
|
||||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// a swap mutation
|
||||
eoSwapMutation <Chrom> swap;
|
||||
|
||||
|
||||
for (i = 0; i < POP_SIZE; ++i)
|
||||
{
|
||||
std::cout << " Initial chromosome n°" << i << " : " << pop[i] << "..." << std::endl;
|
||||
|
|
@ -74,7 +74,7 @@ int main()
|
|||
std::cout << " ... becomes : " << pop[i] << " after swap mutation" << std::endl;
|
||||
check_permutation(pop[i]);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,57 +23,57 @@ public :
|
|||
// arity function, need this function!
|
||||
int arity() const { return op == X? 0 : 2; }
|
||||
|
||||
void randomize() {}
|
||||
void randomize() {}
|
||||
|
||||
// evaluation function, single case, using first argument to give value of variable
|
||||
template <class Children>
|
||||
void operator()(double& result, Children args, double var) const
|
||||
{
|
||||
double r1(0.), r2(0.);
|
||||
if (arity() == 2)
|
||||
{
|
||||
args[0].apply(r1, var);
|
||||
args[1].apply(r2, var);
|
||||
}
|
||||
switch (op)
|
||||
{
|
||||
case Plus : result = r1 + r2; break;
|
||||
case Min : result = r1 - r2; break;
|
||||
case Mult : result = r1 * r2; break;
|
||||
case PDiv : {
|
||||
if (r2 == 0.0)
|
||||
// protection a la Koza, realistic implementations
|
||||
// should maybe throw an exception
|
||||
result = 1.0;
|
||||
else
|
||||
result = r1 / r2;
|
||||
break;
|
||||
}
|
||||
case X : result = var; break;
|
||||
}
|
||||
double r1(0.), r2(0.);
|
||||
if (arity() == 2)
|
||||
{
|
||||
args[0].apply(r1, var);
|
||||
args[1].apply(r2, var);
|
||||
}
|
||||
switch (op)
|
||||
{
|
||||
case Plus : result = r1 + r2; break;
|
||||
case Min : result = r1 - r2; break;
|
||||
case Mult : result = r1 * r2; break;
|
||||
case PDiv : {
|
||||
if (r2 == 0.0)
|
||||
// protection a la Koza, realistic implementations
|
||||
// should maybe throw an exception
|
||||
result = 1.0;
|
||||
else
|
||||
result = r1 / r2;
|
||||
break;
|
||||
}
|
||||
case X : result = var; break;
|
||||
}
|
||||
}
|
||||
|
||||
/// 'Pretty' print to ostream function
|
||||
template <class Children>
|
||||
void operator()(string& result, Children args) const
|
||||
void operator()(string& result, Children args) const
|
||||
{
|
||||
static const string lb = "(";
|
||||
static const string rb = ")";
|
||||
char opStr[4] = " ";
|
||||
opStr[1] = op;
|
||||
static const string lb = "(";
|
||||
static const string rb = ")";
|
||||
char opStr[4] = " ";
|
||||
opStr[1] = op;
|
||||
|
||||
if (arity() == 0)
|
||||
{
|
||||
result = "x";
|
||||
return;
|
||||
}
|
||||
// else
|
||||
string r1;
|
||||
args[0].apply(r1);
|
||||
result = lb + r1;
|
||||
result += opStr;
|
||||
args[1].apply(r1);
|
||||
result += r1 + rb;
|
||||
result = "x";
|
||||
return;
|
||||
}
|
||||
// else
|
||||
string r1;
|
||||
args[0].apply(r1);
|
||||
result = lb + r1;
|
||||
result += opStr;
|
||||
args[1].apply(r1);
|
||||
result += r1 + rb;
|
||||
}
|
||||
|
||||
Operator getOp() const { return op; }
|
||||
|
|
@ -99,7 +99,7 @@ static SymregNode init_sequence[5] = {SymregNode::X, SymregNode::Plus, SymregNod
|
|||
// template <>
|
||||
// bool lt_arity(const SymregNode &node1, const SymregNode &node2)
|
||||
// {
|
||||
// return (node1.arity() < node2.arity());
|
||||
// return (node1.arity() < node2.arity());
|
||||
// }
|
||||
// #endif
|
||||
|
||||
|
|
@ -166,16 +166,16 @@ public :
|
|||
vector<double> outputs;
|
||||
outputs.resize(inputs.size());
|
||||
|
||||
double fitness = 0.0;
|
||||
double fitness = 0.0;
|
||||
|
||||
for (unsigned i = 0; i < inputs.size(); ++i)
|
||||
{
|
||||
{
|
||||
_eo.apply(outputs[i], inputs[i]);
|
||||
fitness += (outputs[i] - target[i]) * (outputs[i] - target[i]);
|
||||
}
|
||||
fitness += (outputs[i] - target[i]) * (outputs[i] - target[i]);
|
||||
}
|
||||
|
||||
fitness /= (double) target.size();
|
||||
fitness = sqrt(fitness);
|
||||
fitness /= (double) target.size();
|
||||
fitness = sqrt(fitness);
|
||||
|
||||
if (fitness > 1e+20)
|
||||
fitness = 1e+20;
|
||||
|
|
@ -197,11 +197,11 @@ void print_best(eoPop<EOT>& pop)
|
|||
|
||||
for (unsigned i = 1; i < pop.size(); ++i)
|
||||
{
|
||||
if (best < pop[i].fitness())
|
||||
{
|
||||
best = pop[i].fitness();
|
||||
index = i;
|
||||
}
|
||||
if (best < pop[i].fitness())
|
||||
{
|
||||
best = pop[i].fitness();
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "\t";
|
||||
|
|
|
|||
|
|
@ -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,32 +71,32 @@ int main()
|
|||
// Terminators
|
||||
eoGenContinue <Particle> genCont1 (50);
|
||||
eoGenContinue <Particle> genCont2 (50);
|
||||
|
||||
|
||||
// PS flight
|
||||
eoSyncEasyPSO<Particle> pso1(genCont1, eval, velocity, flight);
|
||||
|
||||
eoSyncEasyPSO<Particle> pso2(init,genCont2, eval, velocity, flight);
|
||||
|
||||
|
||||
// flight
|
||||
try
|
||||
{
|
||||
pso1(pop);
|
||||
std::cout << "FINAL POPULATION AFTER SYNC PSO n°1:" << std::endl;
|
||||
pso1(pop);
|
||||
std::cout << "FINAL POPULATION AFTER SYNC 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 SYNC PSO n°2:" << std::endl;
|
||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||
|
||||
pso2(pop);
|
||||
std::cout << "FINAL POPULATION AFTER SYNC 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,13 +48,13 @@ int main()
|
|||
|
||||
// a chromosome randomizer
|
||||
eoInitPermutation <Chrom> random(CHROM_SIZE);
|
||||
|
||||
// the population:
|
||||
|
||||
// the population:
|
||||
eoPop<Chrom> pop;
|
||||
|
||||
|
||||
// Evaluation
|
||||
eoEvalFuncPtr<Chrom> eval( real_value );
|
||||
|
||||
|
||||
for (i = 0; i < POP_SIZE; ++i)
|
||||
{
|
||||
Chrom chrom(CHROM_SIZE);
|
||||
|
|
@ -62,10 +62,10 @@ int main()
|
|||
eval(chrom);
|
||||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
|
||||
// a twoOpt mutation
|
||||
eoTwoOptMutation <Chrom> twoOpt;
|
||||
|
||||
|
||||
for (i = 0; i < POP_SIZE; ++i)
|
||||
{
|
||||
std::cout << " Initial chromosome n°" << i << " : " << pop[i] << "..." << std::endl;
|
||||
|
|
@ -73,7 +73,7 @@ int main()
|
|||
std::cout << " ... becomes : " << pop[i] << " after twoOpt mutation" << std::endl;
|
||||
check_permutation(pop[i]);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ main() {
|
|||
for ( unsigned i = 0; i < 100; i ++) {
|
||||
std::cout << u1() << "\t" << u2() << "\t" << u3() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -67,11 +67,10 @@ int main()
|
|||
|
||||
// Chrom Transmision
|
||||
std::cout << "Chrom transmission--------" << std::endl;
|
||||
VirusTransmission<float> vt;
|
||||
VirusTransmission<float> vt;
|
||||
vt( chrom2, chrom );
|
||||
std::cout << chrom2 << std::endl;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -208,11 +208,11 @@ int main()
|
|||
|
||||
try
|
||||
{
|
||||
main_function();
|
||||
main_function();
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cout << "Exception: " << e.what() << '\n';
|
||||
std::cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ int test_fitness(Fitness a, Fitness b)
|
|||
{
|
||||
// srand(time(0));
|
||||
|
||||
// Fitness a = aval; //static_cast<double>(rand()) / RAND_MAX;
|
||||
// Fitness a = aval; //static_cast<double>(rand()) / RAND_MAX;
|
||||
// Fitness b = bval; //static_cast<double>(rand()) / RAND_MAX;
|
||||
|
||||
std::cout.precision(2);
|
||||
|
||||
|
||||
unsigned repeat = 2;
|
||||
while (repeat--)
|
||||
{
|
||||
|
|
@ -32,25 +32,25 @@ int test_fitness(Fitness a, Fitness b)
|
|||
std::cout << a << " < " << b << " is true" << std::endl;
|
||||
else
|
||||
std::cout << a << " < " << b << " is false" <<std::endl;
|
||||
|
||||
|
||||
std::cout << "testing > ";
|
||||
if (a > b)
|
||||
std::cout << a << " > " << b << " is true" << std::endl;
|
||||
else
|
||||
std::cout << a << " > " << b << " is false" <<std::endl;
|
||||
|
||||
|
||||
std::cout << "testing == ";
|
||||
if (a == b)
|
||||
std::cout << a << " == " << b << " is true" << std::endl;
|
||||
else
|
||||
std::cout << a << " == " << b << " is false" <<std::endl;
|
||||
|
||||
|
||||
std::cout << "testing != ";
|
||||
if (a != b)
|
||||
std::cout << a << " != " << b << " is true" << std::endl;
|
||||
else
|
||||
std::cout << a << " != " << b << " is false" <<std::endl;
|
||||
|
||||
|
||||
a = b;
|
||||
}
|
||||
return 1;
|
||||
|
|
@ -73,18 +73,17 @@ int main()
|
|||
|
||||
std::cout << "Testing maximizing fitness with 1 and 2" << std::endl;
|
||||
std::cout << "------------------------------------------------------" << std::endl;
|
||||
|
||||
|
||||
eoMaximizingFitness a1 = 1;
|
||||
eoMaximizingFitness b1 = 2;
|
||||
|
||||
test_fitness(a1,b1);
|
||||
|
||||
|
||||
std::cout << "Testing maximizing fitness with 2 and 1" << std::endl;
|
||||
std::cout << "------------------------------------------------------" << std::endl;
|
||||
|
||||
|
||||
test_fitness(b1,a1);
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -27,10 +27,10 @@ import optparse, logging, sys, os
|
|||
from datetime import datetime
|
||||
|
||||
LEVELS = {'debug': logging.DEBUG,
|
||||
'info': logging.INFO,
|
||||
'warning': logging.WARNING,
|
||||
'error': logging.ERROR,
|
||||
'critical': logging.CRITICAL}
|
||||
'info': logging.INFO,
|
||||
'warning': logging.WARNING,
|
||||
'error': logging.ERROR,
|
||||
'critical': logging.CRITICAL}
|
||||
|
||||
LOG_DEFAULT_FILENAME='notitle.log'
|
||||
|
||||
|
|
@ -68,10 +68,10 @@ def parser(parser=optparse.OptionParser()):
|
|||
|
||||
def logger(level_name, filename=LOG_DEFAULT_FILENAME):
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG,
|
||||
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
|
||||
filename=filename, filemode='a'
|
||||
)
|
||||
level=logging.DEBUG,
|
||||
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
|
||||
filename=filename, filemode='a'
|
||||
)
|
||||
|
||||
console = logging.StreamHandler()
|
||||
console.setLevel(LEVELS.get(level_name, logging.NOTSET))
|
||||
|
|
@ -85,45 +85,45 @@ if not options.onlyexecute:
|
|||
|
||||
def get_boxplot_data( filename ):
|
||||
try:
|
||||
f = open( filename )
|
||||
return [ [ float(value) for value in line.split() ] for line in f.readlines() ]
|
||||
f = open( filename )
|
||||
return [ [ float(value) for value in line.split() ] for line in f.readlines() ]
|
||||
except:
|
||||
raise ValueError('got an issue during the reading of file %s' % filename)
|
||||
raise ValueError('got an issue during the reading of file %s' % filename)
|
||||
|
||||
def do_measure( name, p, ps, P, d, ds, D, r=options.nRun, s=options.seed, v='logging' ):
|
||||
OPENMP_EXEC_FORMAT='./test/t-openmp -p=%d --popStep=%d -P=%d -d=%d --dimStep=%d -D=%d -r=%d --seed=%d -v=%s -H=%s -C=%d -V=%d'
|
||||
|
||||
pwd = options.topic + name + '_'
|
||||
cmd = OPENMP_EXEC_FORMAT % (p, ps, P, d, ds, D, r, s, v, pwd,
|
||||
0 if options.onlyVarTime else 1,
|
||||
0 if options.onlyConstTime else 1)
|
||||
0 if options.onlyVarTime else 1,
|
||||
0 if options.onlyConstTime else 1)
|
||||
logging.info( cmd )
|
||||
if not options.onlyprint:
|
||||
os.system( cmd )
|
||||
os.system( cmd )
|
||||
|
||||
if not options.onlyexecute:
|
||||
def generate( filenames ):
|
||||
for cur in filenames:
|
||||
filename = RESULT_FILE_FORMAT % (pwd, cur, p, ps, P, d, ds, D, r, s)
|
||||
pylab.boxplot( get_boxplot_data( filename ) )
|
||||
nonzero = lambda x: x if x > 0 else 1
|
||||
iters = ( nonzero( P - p ) / ps ) * ( nonzero( D - d ) / ds )
|
||||
pylab.xlabel('%d iterations from %d,%d to %d,%d' % ( iters, p, d, P, D) )
|
||||
pylab.ylabel('%s - %s' % (cur, name))
|
||||
pylab.savefig( filename + '.pdf', format='pdf' )
|
||||
pylab.savefig( filename + '.png', format='png' )
|
||||
pylab.cla()
|
||||
pylab.clf()
|
||||
def generate( filenames ):
|
||||
for cur in filenames:
|
||||
filename = RESULT_FILE_FORMAT % (pwd, cur, p, ps, P, d, ds, D, r, s)
|
||||
pylab.boxplot( get_boxplot_data( filename ) )
|
||||
nonzero = lambda x: x if x > 0 else 1
|
||||
iters = ( nonzero( P - p ) / ps ) * ( nonzero( D - d ) / ds )
|
||||
pylab.xlabel('%d iterations from %d,%d to %d,%d' % ( iters, p, d, P, D) )
|
||||
pylab.ylabel('%s - %s' % (cur, name))
|
||||
pylab.savefig( filename + '.pdf', format='pdf' )
|
||||
pylab.savefig( filename + '.png', format='png' )
|
||||
pylab.cla()
|
||||
pylab.clf()
|
||||
|
||||
if not options.onlyVarTime:
|
||||
generate( ['speedup', 'efficiency', 'dynamicity'] )
|
||||
if not options.onlyConstTime:
|
||||
generate( ['variable_speedup', 'variable_efficiency', 'variable_dynamicity'] )
|
||||
if not options.onlyVarTime:
|
||||
generate( ['speedup', 'efficiency', 'dynamicity'] )
|
||||
if not options.onlyConstTime:
|
||||
generate( ['variable_speedup', 'variable_efficiency', 'variable_dynamicity'] )
|
||||
|
||||
def main():
|
||||
if not options.onlyprint:
|
||||
logging.info('creates first the new topic repository %s', options.topic)
|
||||
os.mkdir( options.topic )
|
||||
logging.info('creates first the new topic repository %s', options.topic)
|
||||
os.mkdir( options.topic )
|
||||
|
||||
logging.info('do all tests with r = %d and a common seed value = %d' % (options.nRun, options.seed))
|
||||
|
||||
|
|
@ -133,24 +133,24 @@ def main():
|
|||
F = options.fixedBound
|
||||
|
||||
if options.measure is None or 1 in options.measure:
|
||||
logging.info('(1) measure for all combinaisons of P n D')
|
||||
do_measure( '1', 1*n, 10*n, 101*n, 1*n, 10*n, 101*n )
|
||||
logging.info('(1) measure for all combinaisons of P n D')
|
||||
do_measure( '1', 1*n, 10*n, 101*n, 1*n, 10*n, 101*n )
|
||||
|
||||
if options.measure is None or 2 in options.measure:
|
||||
logging.info('(2) measure for P \in [%d, %d[ with D fixed to %d' % (1*n, 101*n, F))
|
||||
do_measure( '2', 1*n, 1*n, 101*n, F, 1, F )
|
||||
logging.info('(2) measure for P \in [%d, %d[ with D fixed to %d' % (1*n, 101*n, F))
|
||||
do_measure( '2', 1*n, 1*n, 101*n, F, 1, F )
|
||||
|
||||
if options.measure is None or 3 in options.measure:
|
||||
logging.info('(3) measure for P \in [%d, %d[ with ps = %d and D fixed to %d' % (1*n, 1001*n, 10*n, F))
|
||||
do_measure( '3', 1*n, 10*n, 1001*n, F, 1, F )
|
||||
logging.info('(3) measure for P \in [%d, %d[ with ps = %d and D fixed to %d' % (1*n, 1001*n, 10*n, F))
|
||||
do_measure( '3', 1*n, 10*n, 1001*n, F, 1, F )
|
||||
|
||||
if options.measure is None or 4 in options.measure:
|
||||
logging.info('(4) measure for D \in [%d, %d[ with P fixed to %d' % (1*n, 101*n, F))
|
||||
do_measure( '4', F, 1, F, 1*n, 1*n, 101*n )
|
||||
logging.info('(4) measure for D \in [%d, %d[ with P fixed to %d' % (1*n, 101*n, F))
|
||||
do_measure( '4', F, 1, F, 1*n, 1*n, 101*n )
|
||||
|
||||
if options.measure is None or 5 in options.measure:
|
||||
logging.info('(5) measure for D \in [%d, %d[ with ds = %d and P fixed to %d' % (1*n, 1001*n, 10*n, F))
|
||||
do_measure( '5', F, 1, F, 1*n, 10*n, 1001*n )
|
||||
logging.info('(5) measure for D \in [%d, %d[ with ds = %d and P fixed to %d' % (1*n, 1001*n, 10*n, F))
|
||||
do_measure( '5', F, 1, F, 1*n, 10*n, 1001*n )
|
||||
|
||||
# when executed, just run main():
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// t-selectOne.cpp
|
||||
// This program test the breeder object
|
||||
// (c) GeNeura Team, 1998
|
||||
/*
|
||||
// (c) GeNeura Team, 1998
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
|
||||
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ main()
|
|||
unsigned i;
|
||||
|
||||
eoBinRandom<Chrom> random;
|
||||
eoPop<Chrom> pop;
|
||||
eoPop<Chrom> pop;
|
||||
|
||||
// Create the population
|
||||
for (i = 0; i < POP_SIZE; ++i) {
|
||||
|
|
@ -61,7 +61,7 @@ main()
|
|||
BinaryValue()(chrom);
|
||||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
|
||||
// print population
|
||||
std::cout << "population:" << std::endl;
|
||||
for (i = 0; i < pop.size(); ++i)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue