some reviews
This commit is contained in:
parent
729fa74b42
commit
96f618f88f
6 changed files with 508 additions and 554 deletions
52
eo/src/EO.h
52
eo/src/EO.h
|
|
@ -28,17 +28,18 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <stdexcept> // runtime_error
|
#include <stdexcept> // runtime_error
|
||||||
#include <eoObject.h>
|
#include <eoObject.h> //
|
||||||
#include <eoPersistent.h>
|
#include <eoPersistent.h> //
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/** EO is a base class for evolvable objects, that is, the subjects of evolution.
|
/** EO is a base class for evolvable objects, that is, the subjects of
|
||||||
EOs have only got a fitness, which at the same time needs to be only an object with the
|
evolution. EOs have only got a fitness, which at the same time needs to be
|
||||||
operation less than (<) defined. Fitness says how good is the object; evolution or change
|
only an object with the operation less than (<) defined. Fitness says how
|
||||||
of these objects is left to the genetic operators. A fitness less than another means a
|
good is the object; evolution or change of these objects is left to the
|
||||||
worse fitness, in whatever the context; thus, fitness is always maximized; although
|
genetic operators. A fitness less than another means a worse fitness, in
|
||||||
it can be minimized with a proper definition of the < operator.\\
|
whatever the context; thus, fitness is always maximized; although it can
|
||||||
The fitness object must have, besides an void ctor, a copy ctor.
|
be minimized with a proper definition of the < operator. The fitness
|
||||||
|
object must have, besides an void ctor, a copy ctor.
|
||||||
*/
|
*/
|
||||||
template<class F> class EO: public eoObject, public eoPersistent
|
template<class F> class EO: public eoObject, public eoPersistent
|
||||||
{
|
{
|
||||||
|
|
@ -46,31 +47,24 @@ public:
|
||||||
typedef F Fitness;
|
typedef F Fitness;
|
||||||
|
|
||||||
/** Default constructor.
|
/** Default constructor.
|
||||||
Fitness must have a ctor which takes 0 as a value; we can not use void ctors here
|
Fitness must have a ctor which takes 0 as a value; we can not use void
|
||||||
since default types like float have no void initializer. VC++ allows it, but gcc does not
|
ctors here since default types like float have no void initializer.
|
||||||
|
VC++ allows it, but gcc does not
|
||||||
*/
|
*/
|
||||||
EO(): repFitness(0), invalidFitness(true) {}
|
EO(): repFitness(0), invalidFitness(true) {}
|
||||||
|
|
||||||
/** Ctor from stream.
|
/** Ctor from stream.
|
||||||
Fitness must have defined the lecture from an istream.
|
Fitness must have defined the lecture from an istream.
|
||||||
*/
|
*/
|
||||||
EO( istream& _is ) {
|
EO( istream& _is ) { readFrom(_is); }
|
||||||
_is >> repFitness;
|
|
||||||
invalidFitness = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Copy ctor
|
|
||||||
EO( const EO& _eo ): repFitness( _eo.repFitness ), invalidFitness( _eo.invalidFitness ) {};
|
|
||||||
|
|
||||||
/// Virtual dtor
|
/// Virtual dtor
|
||||||
virtual ~EO() {};
|
virtual ~EO() {};
|
||||||
|
|
||||||
/// Return fitness value.
|
/// Return fitness value.
|
||||||
Fitness fitness() const
|
Fitness fitness() const {
|
||||||
{
|
|
||||||
if (invalid())
|
if (invalid())
|
||||||
//throw runtime_error("invalid fitness");
|
throw runtime_error("invalid fitness");
|
||||||
cout << "invalid fitness" << endl;
|
|
||||||
return repFitness;
|
return repFitness;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,23 +96,26 @@ public:
|
||||||
/** Return the class id.
|
/** Return the class id.
|
||||||
* @return the class name as a string
|
* @return the class name as a string
|
||||||
*/
|
*/
|
||||||
virtual string className() const { return "EO"; };
|
virtual string className() const { return "EO"; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read object.\\
|
* Read object.\\
|
||||||
* Calls base class, just in case that one had something to do. The read and print
|
* Calls base class, just in case that one had something to do.
|
||||||
* methods should be compatible and have the same format. In principle, format is
|
* The read and print methods should be compatible and have the same format.
|
||||||
* "plain": they just print a number
|
* In principle, format is "plain": they just print a number
|
||||||
* @param _is a istream.
|
* @param _is a istream.
|
||||||
* @throw runtime_exception If a valid object can't be read.
|
* @throw runtime_exception If a valid object can't be read.
|
||||||
*/
|
*/
|
||||||
virtual void readFrom(istream& _is) {
|
virtual void readFrom(istream& _is) {
|
||||||
_is >> repFitness;
|
_is >> repFitness;
|
||||||
|
if (is)
|
||||||
invalidFitness = false;
|
invalidFitness = false;
|
||||||
|
else
|
||||||
|
throw runtime_error("EO(istream&): can't read valid eo from istream");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write object. It's called printOn since it prints the object _on_ a stream.
|
* Write object. Called printOn since it prints the object _on_ a stream.
|
||||||
* @param _os A ostream.
|
* @param _os A ostream.
|
||||||
*/
|
*/
|
||||||
virtual void printOn(ostream& _os) const {
|
virtual void printOn(ostream& _os) const {
|
||||||
|
|
@ -135,3 +132,4 @@ private:
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#endif EO_H
|
#endif EO_H
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// UException.h
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifndef _UEXCEPTION_H
|
|
||||||
#define _UEXCEPTION_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#if defined (__BCPLUSPLUS__)
|
|
||||||
#include <stdexcept>
|
|
||||||
#else
|
|
||||||
#include <exception>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Class UException
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//@{
|
|
||||||
/**
|
|
||||||
* This class manages exceptions. It´s barely an extension of the standard exception,
|
|
||||||
* but it can be initialized with an STL string. Called UException (utils-exception)+
|
|
||||||
* to avoid conflicts with other classes.
|
|
||||||
*/
|
|
||||||
class UException: public exception {
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
UException( const string& _msg ): msg( _msg ) { };
|
|
||||||
|
|
||||||
///
|
|
||||||
virtual const char* what() const { return msg.c_str(); };
|
|
||||||
|
|
||||||
private:
|
|
||||||
string msg;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//@}
|
|
||||||
#endif
|
|
||||||
|
|
@ -34,10 +34,9 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
/** @name eo1d class
|
/** @name eo1d class
|
||||||
* Randomly accesible evolvable object with one dimension, with
|
* Randomly accesible evolvable object with one dimension, with variable
|
||||||
variable length.
|
* length. Use this if you want to evolve "linear" things, like bitstrings,
|
||||||
* Use this if you want to evolve "linear" things, like bitstrings, or
|
* or floating-point arrays. If you don't, subclass directly from EO
|
||||||
floating-point arrays. If you don't, subclass directly from EO
|
|
||||||
* @see EO
|
* @see EO
|
||||||
* @author GeNeura
|
* @author GeNeura
|
||||||
* @version 0.2
|
* @version 0.2
|
||||||
|
|
|
||||||
|
|
@ -331,3 +331,4 @@ ostream& operator<<( ostream& _os, const eo2dVector<T,fitnessT>& _eo) {
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,23 @@
|
||||||
//-----------------------------------------------------------------------------
|
/*
|
||||||
// eoBin.h
|
eoBin.h
|
||||||
//-----------------------------------------------------------------------------
|
(c) GeNeura Team 1998
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef eoBin_h
|
#ifndef eoBin_h
|
||||||
#define eoBin_h
|
#define eoBin_h
|
||||||
|
|
|
||||||
|
|
@ -40,28 +40,8 @@
|
||||||
#include <strstream>
|
#include <strstream>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
// include for exceptions
|
||||||
// Class UExceptions - probably useless ???
|
include <stdecept> // logic_error
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* This class manages exceptions. It´s barely an extension of the standard except
|
|
||||||
ion,
|
|
||||||
* but it can be initialized with an STL string. Called UException (utils-except
|
|
||||||
ion)+
|
|
||||||
* to avoid conflicts with other classes.
|
|
||||||
*/
|
|
||||||
class UException: public exception {
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
UException( const string& _msg ): msg( _msg ) { };
|
|
||||||
|
|
||||||
///
|
|
||||||
virtual const char* what() const { return msg.c_str(); };
|
|
||||||
|
|
||||||
private:
|
|
||||||
string msg;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Class Param
|
// Class Param
|
||||||
|
|
@ -747,20 +727,20 @@ public:
|
||||||
/**
|
/**
|
||||||
* This class managges unknown argument exceptions.
|
* This class managges unknown argument exceptions.
|
||||||
*/
|
*/
|
||||||
class UnknownArg : public UException {
|
class UnknownArg : public logic_error {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param _arg string to be shown when the exception occurs
|
* @param _arg string to be shown when the exception occurs
|
||||||
*/
|
*/
|
||||||
UnknownArg( const string& _arg): UException( "Invalid argument: "+_arg ) { };
|
UnknownArg( const string& _arg): logic_error( "Invalid argument: "+_arg ) { };
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class managges bad param types.
|
* This class managges bad param types.
|
||||||
*/
|
*/
|
||||||
class BadType : public UException {
|
class BadType : public logic_error {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -769,39 +749,39 @@ public:
|
||||||
* @param _value The value of the param
|
* @param _value The value of the param
|
||||||
*/
|
*/
|
||||||
BadType(const string& _param, const string& _value, const string& _correctType)
|
BadType(const string& _param, const string& _value, const string& _correctType)
|
||||||
: UException("The value '" + _value + "' assigned to the argument " + _param + " isn't a correct "+_correctType) { };
|
: logic_error("The value '" + _value + "' assigned to the argument " + _param + " isn't a correct "+_correctType) { };
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class managges exceptions produced when there isn't a value for a parameter.
|
* This class managges exceptions produced when there isn't a value for a parameter.
|
||||||
*/
|
*/
|
||||||
class MissingVal : public UException {
|
class MissingVal : public logic_error {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param _param The param
|
* @param _param The param
|
||||||
*/
|
*/
|
||||||
MissingVal(const string& _param) : UException("Missing value for parameter " + _param) {};
|
MissingVal(const string& _param) : logic_error("Missing value for parameter " + _param) {};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class managges exceptions produced when the user forgot a required parameter.
|
* This class managges exceptions produced when the user forgot a required parameter.
|
||||||
*/
|
*/
|
||||||
class MissingReqParam : public UException {
|
class MissingReqParam : public logic_error {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param _shortName The param's short name
|
* @param _shortName The param's short name
|
||||||
*/
|
*/
|
||||||
MissingReqParam(const string& _shortName) : UException("Missing required parameter " + _shortName) {};
|
MissingReqParam(const string& _shortName) : logic_error("Missing required parameter " + _shortName) {};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class managges exceptions du to < without a > in array value
|
* This class managges exceptions du to < without a > in array value
|
||||||
*/
|
*/
|
||||||
class BadArrayParam : public UException {
|
class BadArrayParam : public logic_error {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -810,7 +790,7 @@ public:
|
||||||
* @param _first_word The first word read after the "<"
|
* @param _first_word The first word read after the "<"
|
||||||
*/
|
*/
|
||||||
BadArrayParam(const string& _param, const string &_first_word) :
|
BadArrayParam(const string& _param, const string &_first_word) :
|
||||||
UException("Array parameter " + _param + ": No matching > (" + _first_word
|
logic_error("Array parameter " + _param + ": No matching > (" + _first_word
|
||||||
+ "... )") {};
|
+ "... )") {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue