Merge branch 'master' of ssh://eodev.git.sourceforge.net/gitroot/eodev/eodev
This commit is contained in:
commit
47cdcb8052
6 changed files with 52 additions and 22 deletions
|
|
@ -29,7 +29,6 @@ Authors:
|
||||||
#define _edoRepairerDispatcher_h
|
#define _edoRepairerDispatcher_h
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "edoRepairer.h"
|
#include "edoRepairer.h"
|
||||||
|
|
@ -52,28 +51,28 @@ template < typename EOT >
|
||||||
class edoRepairerDispatcher
|
class edoRepairerDispatcher
|
||||||
: public edoRepairer<EOT>,
|
: public edoRepairer<EOT>,
|
||||||
std::vector<
|
std::vector<
|
||||||
std::pair< std::set< unsigned int >, edoRepairer< EOT >* >
|
std::pair< std::vector< unsigned int >, edoRepairer< EOT >* >
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Empty constructor
|
//! Empty constructor
|
||||||
edoRepairerDispatcher() :
|
edoRepairerDispatcher() :
|
||||||
std::vector<
|
std::vector<
|
||||||
std::pair< std::set< unsigned int >, edoRepairer< EOT >* >
|
std::pair< std::vector< unsigned int >, edoRepairer< EOT >* >
|
||||||
>()
|
>()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//! Constructor with a single index set and repairer operator
|
//! Constructor with a single index set and repairer operator
|
||||||
edoRepairerDispatcher( std::set<unsigned int> idx, edoRepairer<EOT>* op ) :
|
edoRepairerDispatcher( std::vector<unsigned int> idx, edoRepairer<EOT>* op ) :
|
||||||
std::vector<
|
std::vector<
|
||||||
std::pair< std::set< unsigned int >, edoRepairer< EOT >* >
|
std::pair< std::vector< unsigned int >, edoRepairer< EOT >* >
|
||||||
>()
|
>()
|
||||||
{
|
{
|
||||||
this->add( idx, op );
|
this->add( idx, op );
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Add more indexes set and their corresponding repairer operator address to the list
|
//! Add more indexes set and their corresponding repairer operator address to the list
|
||||||
void add( std::set<unsigned int> idx, edoRepairer<EOT>* op )
|
void add( std::vector<unsigned int> idx, edoRepairer<EOT>* op )
|
||||||
{
|
{
|
||||||
assert( idx.size() > 0 );
|
assert( idx.size() > 0 );
|
||||||
assert( op != NULL );
|
assert( op != NULL );
|
||||||
|
|
@ -90,7 +89,7 @@ public:
|
||||||
EOT partsol;
|
EOT partsol;
|
||||||
|
|
||||||
// j is an iterator that points on an uint
|
// j is an iterator that points on an uint
|
||||||
for( std::set< unsigned int >::iterator j = ipair->first.begin(); j != ipair->first.end(); ++j ) {
|
for( std::vector< unsigned int >::iterator j = ipair->first.begin(); j != ipair->first.end(); ++j ) {
|
||||||
partsol.push_back( sol.at(*j) );
|
partsol.push_back( sol.at(*j) );
|
||||||
} // for j
|
} // for j
|
||||||
|
|
||||||
|
|
@ -101,9 +100,9 @@ public:
|
||||||
(*(ipair->second))( partsol );
|
(*(ipair->second))( partsol );
|
||||||
|
|
||||||
{ // copy back the repaired partial solution to sol
|
{ // copy back the repaired partial solution to sol
|
||||||
// browse partsol with uint k, and the idx set with an iterator (std::set is an associative tab)
|
// browse partsol with uint k, and the idx set with an iterator (std::vector is an associative tab)
|
||||||
unsigned int k=0;
|
unsigned int k=0;
|
||||||
for( std::set< unsigned int >::iterator j = ipair->first.begin(); j != ipair->first.end(); ++j ) {
|
for( std::vector< unsigned int >::iterator j = ipair->first.begin(); j != ipair->first.end(); ++j ) {
|
||||||
sol[ *j ] = partsol[ k ];
|
sol[ *j ] = partsol[ k ];
|
||||||
k++;
|
k++;
|
||||||
} // for j
|
} // for j
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,12 @@ Authors:
|
||||||
* edoSamplerUniform
|
* edoSamplerUniform
|
||||||
* This class uses the Uniform distribution parameters (bounds) to return
|
* This class uses the Uniform distribution parameters (bounds) to return
|
||||||
* a random position used for population sampling.
|
* a random position used for population sampling.
|
||||||
|
*
|
||||||
|
* Returns a random number in [min,max[ for each variable defined by the given
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* Note: if the distribution given at call defines a min==max for one of the
|
||||||
|
* variable, the result will be the same number.
|
||||||
*/
|
*/
|
||||||
template < typename EOT, class D = edoUniform<EOT> >
|
template < typename EOT, class D = edoUniform<EOT> >
|
||||||
class edoSamplerUniform : public edoSampler< D >
|
class edoSamplerUniform : public edoSampler< D >
|
||||||
|
|
@ -62,6 +68,9 @@ public:
|
||||||
double min = distrib.min()[i];
|
double min = distrib.min()[i];
|
||||||
double max = distrib.max()[i];
|
double max = distrib.max()[i];
|
||||||
double random = rng.uniform(min, max);
|
double random = rng.uniform(min, max);
|
||||||
|
|
||||||
|
assert( ( min == random && random == max ) || ( min <= random && random < max) ); // random in [ min, max [
|
||||||
|
|
||||||
solution.push_back(random);
|
solution.push_back(random);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,13 +43,13 @@ int main(void)
|
||||||
edoRepairer<EOT>* rep1 = new edoRepairerFloor<EOT>();
|
edoRepairer<EOT>* rep1 = new edoRepairerFloor<EOT>();
|
||||||
edoRepairer<EOT>* rep2 = new edoRepairerCeil<EOT>();
|
edoRepairer<EOT>* rep2 = new edoRepairerCeil<EOT>();
|
||||||
|
|
||||||
std::set<unsigned int> indexes1;
|
std::vector<unsigned int> indexes1;
|
||||||
indexes1.insert(0);
|
indexes1.push_back(0);
|
||||||
indexes1.insert(2);
|
indexes1.push_back(2);
|
||||||
|
|
||||||
std::set<unsigned int> indexes2;
|
std::vector<unsigned int> indexes2;
|
||||||
indexes2.insert(1);
|
indexes2.push_back(1);
|
||||||
indexes2.insert(3);
|
indexes2.push_back(3);
|
||||||
|
|
||||||
edoRepairerDispatcher<EOT> repare( indexes1, rep1 );
|
edoRepairerDispatcher<EOT> repare( indexes1, rep1 );
|
||||||
repare.add( indexes2, rep2 );
|
repare.add( indexes2, rep2 );
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,13 @@ Authors:
|
||||||
Johann Dréo <johann.dreo@thalesgroup.com>
|
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef __unix__
|
||||||
|
#warning "Warning: class 'eoEvalUserTimeThrowException' is only available under UNIX systems (defining 'rusage' in 'sys/resource.h'), contributions for other systems are welcomed."
|
||||||
|
#else
|
||||||
|
|
||||||
|
#ifndef __EOEVALUSERTIMETHROWEXCEPTION_H__
|
||||||
|
#define __EOEVALUSERTIMETHROWEXCEPTION_H__
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
|
|
||||||
|
|
@ -60,3 +67,6 @@ protected:
|
||||||
const long _max;
|
const long _max;
|
||||||
struct rusage _usage;
|
struct rusage _usage;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif // __EOEVALUSERTIMETHROWEXCEPTION_H__
|
||||||
|
#endif // __UNIX__
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,16 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* eoScalarFitness<ScalarType, Compare = less<ScalarType> >:
|
|
||||||
* Wraps a scalar fitness values such as a double or int, with the option of
|
* Wraps a scalar fitness values such as a double or int, with the option of
|
||||||
* maximizing (using less<ScalarType>) or minimizing (using greater<ScalarType>)
|
* maximizing (using less<ScalarType>) or minimizing (using greater<ScalarType>)
|
||||||
|
*
|
||||||
* It overrides operator<() to use the Compare template argument
|
* It overrides operator<() to use the Compare template argument. Thus, if you
|
||||||
|
* need to compare if an indiv1 is "better" than an indiv2, you can use:
|
||||||
|
* if( indiv1 > indiv2 ) {
|
||||||
|
* // indiv1 is better
|
||||||
|
* } else {
|
||||||
|
* // indiv2 is better
|
||||||
|
* }
|
||||||
*
|
*
|
||||||
* Suitable constructors and assignments and casts are defined to work
|
* Suitable constructors and assignments and casts are defined to work
|
||||||
* with this quantity as if it were a ScalarType.
|
* with this quantity as if it were a ScalarType.
|
||||||
|
|
@ -57,6 +62,13 @@ class eoScalarFitness
|
||||||
eoScalarFitness& operator=(const ScalarType& v)
|
eoScalarFitness& operator=(const ScalarType& v)
|
||||||
{ value = v; return *this; }
|
{ value = v; return *this; }
|
||||||
|
|
||||||
|
/** Conversion operator: it permits to use a fitness instance as its scalar
|
||||||
|
* type, if needed. For example, this is possible:
|
||||||
|
* eoScalarFitness<double,std::less<double> > fit;
|
||||||
|
* double val = 1.0;
|
||||||
|
* fit = val;
|
||||||
|
* val = fit;
|
||||||
|
*/
|
||||||
operator ScalarType(void) const { return value; }
|
operator ScalarType(void) const { return value; }
|
||||||
|
|
||||||
/// Comparison, using less by default
|
/// Comparison, using less by default
|
||||||
|
|
@ -83,13 +95,13 @@ class eoScalarFitness
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Typedefs for fitness comparison, Maximizing Fitness compares with less,
|
Typedefs for fitness comparison, Maximizing Fitness compares with less,
|
||||||
and minimizing fitness compares with greater. This because we want ordinary
|
and minimizing fitness compares with greater. This because we want ordinary
|
||||||
fitness values (doubles) to be equivalent with Maximizing Fitness, and
|
fitness values (doubles) to be equivalent with Maximizing Fitness, and
|
||||||
comparing with less is the default behaviour.
|
comparing with less is the default behaviour.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(__CUDACC__)
|
#if defined(__CUDACC__)
|
||||||
typedef eoScalarFitness<float, std::less<float> > eoMaximizingFitness;
|
typedef eoScalarFitness<float, std::less<float> > eoMaximizingFitness;
|
||||||
typedef eoScalarFitness<float, std::greater<float> > eoMinimizingFitness;
|
typedef eoScalarFitness<float, std::greater<float> > eoMinimizingFitness;
|
||||||
|
|
|
||||||
|
|
@ -289,7 +289,7 @@ void eoParser::printOn(ostream& os) const
|
||||||
string str = "--" + param->longName() + "=" + param->getValue();
|
string str = "--" + param->longName() + "=" + param->getValue();
|
||||||
|
|
||||||
os.setf(ios_base::left, ios_base::adjustfield);
|
os.setf(ios_base::left, ios_base::adjustfield);
|
||||||
os << setw(40) << str;
|
os << setfill(' ') << setw(40) << str;
|
||||||
|
|
||||||
os << setw(0) << " # ";
|
os << setw(0) << " # ";
|
||||||
if (param->shortName())
|
if (param->shortName())
|
||||||
|
|
|
||||||
Reference in a new issue