Adjust code to perform to C++ standard according to gcc-3.4
interpretation... (Have not compiled/checked/changed paradisEO.) That is, the current code compiles with gcc-3.4 and the checks (besides t-MGE1bit) all pass.
This commit is contained in:
parent
faaadf7599
commit
85a326c5e4
35 changed files with 1057 additions and 864 deletions
|
|
@ -11,16 +11,16 @@
|
|||
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
|
||||
|
|
@ -43,33 +43,33 @@
|
|||
class eoScalarFitnessAssembledTraits{
|
||||
|
||||
public:
|
||||
|
||||
|
||||
typedef std::vector<std::string>::size_type size_type;
|
||||
|
||||
static void setDescription( size_type _idx, std::string _descr ) {
|
||||
static void setDescription( size_type _idx, std::string _descr ) {
|
||||
if ( _idx < TermDescriptions.size() )
|
||||
TermDescriptions[_idx] = _descr;
|
||||
TermDescriptions[_idx] = _descr;
|
||||
else{
|
||||
TermDescriptions.resize(_idx, "Unnamed variable" );
|
||||
TermDescriptions[_idx] = _descr;
|
||||
}
|
||||
}
|
||||
|
||||
static std::string getDescription( size_type _idx) {
|
||||
static std::string getDescription( size_type _idx) {
|
||||
if ( _idx < TermDescriptions.size() )
|
||||
return TermDescriptions[_idx ];
|
||||
return TermDescriptions[_idx ];
|
||||
else
|
||||
return "Unnamed Variable";
|
||||
}
|
||||
|
||||
static void resize( size_type _n, const std::string& _descr) {
|
||||
TermDescriptions.resize(_n, _descr);
|
||||
|
||||
static void resize( size_type _n, const std::string& _descr) {
|
||||
TermDescriptions.resize(_n, _descr);
|
||||
}
|
||||
|
||||
|
||||
static size_type size() { return TermDescriptions.size(); }
|
||||
|
||||
static std::vector<std::string> getDescriptionVector() { return TermDescriptions; }
|
||||
|
||||
|
||||
private:
|
||||
static std::vector<std::string> TermDescriptions;
|
||||
};
|
||||
|
|
@ -80,7 +80,7 @@ private:
|
|||
maximizing (using less<ScalarType>) or minimizing (using greater<ScalarType>).
|
||||
- Stores all kinda different values met during fitness assembly, to be defined in eoEvalFunc.
|
||||
- It overrides operator<() to use the Compare template argument.
|
||||
- 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.
|
||||
- Global fitness value is stored as first element in the vector
|
||||
*/
|
||||
|
|
@ -88,26 +88,32 @@ template <class ScalarType, class Compare, class FitnessTraits >
|
|||
class eoScalarFitnessAssembled : public std::vector<ScalarType> {
|
||||
|
||||
public:
|
||||
|
||||
using std::vector< ScalarType >::empty;
|
||||
using std::vector< ScalarType >::front;
|
||||
using std::vector< ScalarType >::size;
|
||||
|
||||
|
||||
typedef typename std::vector<ScalarType> baseVector;
|
||||
typedef typename baseVector::size_type size_type;
|
||||
|
||||
// Basic constructors and assignments
|
||||
eoScalarFitnessAssembled()
|
||||
eoScalarFitnessAssembled()
|
||||
: baseVector( FitnessTraits::size() ),
|
||||
feasible(true), failed(false), msg("")
|
||||
{}
|
||||
|
||||
eoScalarFitnessAssembled( size_type _n,
|
||||
eoScalarFitnessAssembled( size_type _n,
|
||||
const ScalarType& _val,
|
||||
const std::string& _descr="Unnamed variable" )
|
||||
: baseVector(_n, _val),
|
||||
feasible(true), failed(false), msg("")
|
||||
{
|
||||
{
|
||||
if ( _n > FitnessTraits::size() )
|
||||
FitnessTraits::resize(_n, _descr);
|
||||
}
|
||||
|
||||
eoScalarFitnessAssembled( const eoScalarFitnessAssembled& other)
|
||||
|
||||
eoScalarFitnessAssembled( const eoScalarFitnessAssembled& other)
|
||||
: baseVector( other ),
|
||||
feasible(other.feasible),
|
||||
failed(other.failed),
|
||||
|
|
@ -121,27 +127,26 @@ public:
|
|||
msg = other.msg;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// Constructors and assignments to work with scalar type
|
||||
eoScalarFitnessAssembled( const ScalarType& v )
|
||||
eoScalarFitnessAssembled( const ScalarType& v )
|
||||
: baseVector( 1, v ),
|
||||
feasible(true), failed(false), msg("")
|
||||
{}
|
||||
|
||||
|
||||
eoScalarFitnessAssembled& operator=( const ScalarType& v ) {
|
||||
|
||||
if ( empty() )
|
||||
push_back( v );
|
||||
else
|
||||
front() = v;
|
||||
|
||||
return *this;
|
||||
|
||||
if( empty() )
|
||||
push_back( v );
|
||||
else
|
||||
front() = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//! Overload push_back()
|
||||
void push_back(const ScalarType& _val ){
|
||||
baseVector::push_back( _val );
|
||||
if ( size() > FitnessTraits::size() )
|
||||
if ( size() > FitnessTraits::size() )
|
||||
FitnessTraits::setDescription( size()-1, "Unnamed variable");
|
||||
}
|
||||
|
||||
|
|
@ -156,46 +161,46 @@ public:
|
|||
baseVector::resize(_n, _val);
|
||||
FitnessTraits::resize(_n, _descr);
|
||||
}
|
||||
|
||||
|
||||
//! Set description
|
||||
void setDescription( size_type _idx, std::string _descr ) {
|
||||
void setDescription( size_type _idx, std::string _descr ) {
|
||||
FitnessTraits::setDescription( _idx, _descr );
|
||||
}
|
||||
|
||||
|
||||
//! Get description
|
||||
std::string getDescription( size_type _idx ){ return FitnessTraits::getDescription( _idx ); }
|
||||
|
||||
//! Get vector with descriptions
|
||||
std::vector<std::string> getDescriptionVector() { return FitnessTraits::getDescriptionVector(); }
|
||||
|
||||
|
||||
//! Feasibility boolean
|
||||
/**
|
||||
* Can be specified anywhere in fitness evaluation
|
||||
* Can be specified anywhere in fitness evaluation
|
||||
* as an indicator if the individual is in some feasible range.
|
||||
*/
|
||||
bool feasible;
|
||||
|
||||
|
||||
//! Failed boolean
|
||||
/**
|
||||
* Can be specified anywhere in fitness evaluation
|
||||
* as an indicator if the evaluation of the individual failed
|
||||
*/
|
||||
bool failed;
|
||||
|
||||
|
||||
//! Message
|
||||
/**
|
||||
/**
|
||||
* Can be specified anywhere in fitness evaluation.
|
||||
* Typically used to store some sort of error messages, if evaluation of individual failed.
|
||||
*/
|
||||
std::string msg;
|
||||
|
||||
|
||||
|
||||
// Scalar type access
|
||||
operator ScalarType(void) const {
|
||||
operator ScalarType(void) const {
|
||||
if ( empty() )
|
||||
return 0.0;
|
||||
else
|
||||
return front();
|
||||
return front();
|
||||
}
|
||||
|
||||
//! Print term values and descriptions
|
||||
|
|
@ -205,11 +210,11 @@ public:
|
|||
}
|
||||
|
||||
// Comparison, using less by default
|
||||
bool operator<(const eoScalarFitnessAssembled& other) const{
|
||||
bool operator<(const eoScalarFitnessAssembled& other) const{
|
||||
if ( empty() || other.empty() )
|
||||
return false;
|
||||
else
|
||||
return Compare()( front() , other.front() );
|
||||
return Compare()( front() , other.front() );
|
||||
}
|
||||
|
||||
// implementation of the other operators
|
||||
|
|
@ -237,10 +242,10 @@ std::ostream& operator<<(std::ostream& os, const eoScalarFitnessAssembled<F, Cmp
|
|||
{
|
||||
for (unsigned i=0; i < f.size(); ++i)
|
||||
os << f[i] << " ";
|
||||
|
||||
|
||||
os << f.feasible << " ";
|
||||
os << f.failed << " ";
|
||||
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
|
@ -252,10 +257,10 @@ std::istream& operator>>(std::istream& is, eoScalarFitnessAssembled<F, Cmp, Fitn
|
|||
is >> value;
|
||||
f[i] = value;
|
||||
}
|
||||
|
||||
|
||||
is >> f.feasible;
|
||||
is >> f.failed;
|
||||
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue