Removed "using namespace std" statements from header files in EO -- "std::" identifier were added where necessary.

This commit is contained in:
okoenig 2003-02-27 19:28:07 +00:00
commit 86fa476c67
263 changed files with 2009 additions and 1976 deletions

View file

@ -37,7 +37,6 @@
#include <eoInit.h>
using namespace gp_parse_tree;
using namespace std;
/**
\defgroup ParseTree
@ -93,7 +92,7 @@ public :
/**
* To read me from a stream
* @param is The istream
* @param is The std::istream
*/
eoParseTree(std::istream& is) : EO<FType>(), parse_tree<Node>()
@ -102,11 +101,11 @@ public :
}
/// My class name
string className(void) const { return "eoParseTree"; }
std::string className(void) const { return "eoParseTree"; }
/**
* To print me on a stream
* @param os The ostream
* @param os The std::ostream
*/
void printOn(std::ostream& os) const
{
@ -120,7 +119,7 @@ public :
/**
* To read me from a stream
* @param is The istream
* @param is The std::istream
*/
void readFrom(std::istream& is)
{
@ -132,7 +131,7 @@ public :
is >> sz;
vector<Node> v(sz);
std::vector<Node> v(sz);
unsigned i;
@ -158,7 +157,7 @@ public :
fitness(fit);
std::copy(istream_iterator<Node>(is), istream_iterator<Node>(), back_inserter(*this));
std::copy(std::istream_iterator<Node>(is), std::istream_iterator<Node>(), back_inserter(*this));
*/
}
};

View file

@ -35,7 +35,6 @@
#include <eoPop.h>
using namespace gp_parse_tree;
using namespace std;
/** eoParseTreeDepthInit : the initializer class for eoParseTree
\class eoParseTreeDepthInit eoParseTreeDepthInit.h gp/eoParseTreeDepthInit.h
@ -51,7 +50,7 @@ class eoParseTreeDepthInit : public eoInit< eoParseTree<FType, Node> >
protected:
// a binary predicate for sorting
// hopefully this will work with M$VC++ 6.0
struct lt_arity:public binary_function<Node,Node,bool>
struct lt_arity:public std::binary_function<Node,Node,bool>
{
bool operator()(const Node &_node1, const Node &_node2) { return (_node1.arity() < _node2.arity());};
};
@ -63,13 +62,13 @@ class eoParseTreeDepthInit : public eoInit< eoParseTree<FType, Node> >
/**
* Constructor
* @parm _max_depth The maximum depth of a tree
* @param _initializor A vector containing the possible nodes
* @param _initializor A std::vector containing the possible nodes
* @param _grow False results in a full tree, True result is a randomly grown tree
* @param _ramped_half_and_half True results in Ramped Half and Half Initialization
*/
eoParseTreeDepthInit(
unsigned _max_depth,
const vector<Node>& _initializor,
const std::vector<Node>& _initializor,
bool _grow = true,
bool _ramped_half_and_half = false)
:
@ -82,21 +81,21 @@ class eoParseTreeDepthInit : public eoInit< eoParseTree<FType, Node> >
{
if(initializor.empty())
{
throw logic_error("eoParseTreeDepthInit: uhm, wouldn't you rather give a non-empty set of Nodes?");
throw std::logic_error("eoParseTreeDepthInit: uhm, wouldn't you rather give a non-empty set of Nodes?");
}
// lets sort the initializor vector according to arity (so we can be sure the terminals are in front)
// lets sort the initializor std::vector according to arity (so we can be sure the terminals are in front)
// we use stable_sort so that if element i was in front of element j and they have the same arity i remains in front of j
stable_sort(initializor.begin(), initializor.end(), lt_arity());
}
/// My class name
virtual string className() const { return "eoParseTreeDepthInit"; };
virtual std::string className() const { return "eoParseTreeDepthInit"; };
/**initialize a tree
* @param _tree : the tree to be initialized
*/
void operator()(EoType& _tree)
{
list<Node> sequence;
std::list<Node> sequence;
generate(sequence, current_depth);
parse_tree<Node> tmp(sequence.begin(), sequence.end());
@ -117,11 +116,11 @@ class eoParseTreeDepthInit : public eoInit< eoParseTree<FType, Node> >
}
private :
void generate(list<Node>& sequence, int the_max, int last_terminal = -1)
void generate(std::list<Node>& sequence, int the_max, int last_terminal = -1)
{
if (last_terminal == -1)
{ // check where the last terminal in the sequence resides
typename vector<Node>::iterator it;
typename std::vector<Node>::iterator it;
for (it = initializor.begin(); it != initializor.end(); ++it)
{
if (it->arity() > 0)
@ -133,12 +132,12 @@ class eoParseTreeDepthInit : public eoInit< eoParseTree<FType, Node> >
if (the_max == 1)
{ // generate terminals only
typename vector<Node>::iterator it = initializor.begin() + rng.random(last_terminal);
typename std::vector<Node>::iterator it = initializor.begin() + rng.random(last_terminal);
sequence.push_front(*it);
return;
}
typename vector<Node>::iterator what_it;
typename std::vector<Node>::iterator what_it;
if (grow)
{
@ -171,12 +170,12 @@ class eoParseTreeDepthInit : public eoInit< eoParseTree<FType, Node> >
* @param pop the population to be created
* @param population_size the size of the population to be created
* @param init_max_depth the initial maximum tree depth
* @param initializor A vector containing the possible nodes
* @param initializor A std::vector containing the possible nodes
\ingroup ParseTree
*/
template <class FType, class Node>
void eoInitRampedHalfAndHalf(eoPop< eoParseTree<FType,Node> > &pop, unsigned int population_size, unsigned int init_max_depth, vector<Node> &initializor)
void eoInitRampedHalfAndHalf(eoPop< eoParseTree<FType,Node> > &pop, unsigned int population_size, unsigned int init_max_depth, std::vector<Node> &initializor)
{
typedef eoParseTree<FType,Node> EoType;
typedef eoPop< EoType > Pop;
@ -185,10 +184,10 @@ void eoInitRampedHalfAndHalf(eoPop< eoParseTree<FType,Node> > &pop, unsigned in
unsigned int part_pop_size = population_size / (2*M);
unsigned int m=0;
cerr << "EO WARNING: Ramped Half and Half Initialization is now supported by eoParseTreeDepthInit." << endl;
cerr << " This function is now obsolete and might be removed in the future so you should"<< endl;
cerr << " update your code to use: " << endl << endl;
cerr << " eoParseTreeDepthInit( _max_depth, _initializer, bool _grow, bool _ramped_half_and_half)" << endl << endl;
std::cerr << "EO WARNING: Ramped Half and Half Initialization is now supported by eoParseTreeDepthInit." << std::endl;
std::cerr << " This function is now obsolete and might be removed in the future so you should"<< std::endl;
std::cerr << " update your code to use: " << std::endl << std::endl;
std::cerr << " eoParseTreeDepthInit( _max_depth, _initializer, bool _grow, bool _ramped_half_and_half)" << std::endl << std::endl;
pop.clear();

View file

@ -51,7 +51,7 @@ public:
: eoQuadOp<EoType>(), max_length(_max_length) {};
/// the ckassname
virtual string className() const { return "eoSubtreeXOver"; };
virtual std::string className() const { return "eoSubtreeXOver"; };
/// Dtor
virtual ~eoSubtreeXOver () {};
@ -99,7 +99,7 @@ public:
{};
/// the class name
virtual string className() const { return "eoBranchMutation"; };
virtual std::string className() const { return "eoBranchMutation"; };
/// Dtor
virtual ~eoBranchMutation() {};
@ -152,14 +152,14 @@ public:
/**
* Constructor
* @param _initializor The vector of Nodes given to the eoGpDepthInitializer
* @param _initializor The std::vector of Nodes given to the eoGpDepthInitializer
*/
eoPointMutation( vector<Node>& _initializor)
eoPointMutation( std::vector<Node>& _initializor)
: eoMonOp<EoType>(), initializor(_initializor)
{};
/// the class name
virtual string className() const { return "eoPointMutation"; };
virtual std::string className() const { return "eoPointMutation"; };
/// Dtor
virtual ~eoPointMutation() {};
@ -191,7 +191,7 @@ public:
}
private :
vector<Node>& initializor;
std::vector<Node>& initializor;
};
@ -217,7 +217,7 @@ public:
{};
/// The class name
virtual string className() const { return "eoExpansionMutation"; };
virtual std::string className() const { return "eoExpansionMutation"; };
/// Dtor
virtual ~eoExpansionMutation() {};
@ -284,7 +284,7 @@ public:
{};
/// The class name
virtual string className() const { return "eoCollapseSubtreeMutation"; };
virtual std::string className() const { return "eoCollapseSubtreeMutation"; };
/// Dtor
virtual ~eoCollapseSubtreeMutation() {};
@ -347,7 +347,7 @@ public:
{};
/// The class name
virtual string className() const { return "eoHoistMutation"; };
virtual std::string className() const { return "eoHoistMutation"; };
/// Dtor
virtual ~eoHoistMutation() {};

View file

@ -34,7 +34,6 @@
using namespace gp_parse_tree;
using namespace std;
#define TERMINAL 0
@ -68,12 +67,12 @@ class eoStParseTreeDepthInit : public eoInit< eoParseTree<FType, Node> >
/**
* Constructor
* @parm _max_depth The maximum depth of a tree
* @param _initializor A vector containing the possible nodes
* @param _initializor A std::vector containing the possible nodes
* @param _grow False results in a full tree, True result is a randomly grown tree
*/
eoStParseTreeDepthInit(
unsigned _max_depth,
const vector<Node>& _node,
const std::vector<Node>& _node,
const int& _return_type,
bool _grow = true)
:
@ -84,48 +83,48 @@ class eoStParseTreeDepthInit : public eoInit< eoParseTree<FType, Node> >
{
if(_node.empty())
{
throw logic_error("eoStParseTreeDepthInit: uhm, wouldn't you rather give a non-empty set of Nodes?");
throw std::logic_error("eoStParseTreeDepthInit: uhm, wouldn't you rather give a non-empty set of Nodes?");
}
unsigned int i=0;
int arity=0;
int type=0;
vector<Node> node_vector;
std::vector<Node> node_std::vector;
for(i=0; i < _node.size(); i++)
{
arity = _node[i].arity();
type = _node[i].type();
if(arity==0)
{
node_vector = node[type][TERMINAL];
node_vector.push_back(_node[i]);
node[type][TERMINAL]= node_vector;
node_std::vector = node[type][TERMINAL];
node_std::vector.push_back(_node[i]);
node[type][TERMINAL]= node_std::vector;
}
else
//if (arity != 0) // non-terminal
{
node_vector = node[type][NONTERMINAL];
node_vector.push_back(_node[i]);
node[type][NONTERMINAL] = node_vector;
node_std::vector = node[type][NONTERMINAL];
node_std::vector.push_back(_node[i]);
node[type][NONTERMINAL] = node_std::vector;
}
node_vector = node[type][ALL];
node_vector.push_back(_node[i]);
node[type][ALL] = node_vector;
node_std::vector = node[type][ALL];
node_std::vector.push_back(_node[i]);
node[type][ALL] = node_std::vector;
}
}
/// My class name
virtual string className() const { return "eoStParseTreeDepthInit"; };
virtual std::string className() const { return "eoStParseTreeDepthInit"; };
/**initialize a tree
* @param _tree : the tree to be initialized
*/
void operator()(EoType& _tree)
{
list<Node> sequence;
std::list<Node> sequence;
bool good_tree = false;
do
{
@ -137,7 +136,7 @@ class eoStParseTreeDepthInit : public eoInit< eoParseTree<FType, Node> >
_tree.swap(tmp);
}
private :
bool generate(list<Node>& sequence, int the_max, int request_type)
bool generate(std::list<Node>& sequence, int the_max, int request_type)
{
int selected=0;
@ -182,7 +181,7 @@ class eoStParseTreeDepthInit : public eoInit< eoParseTree<FType, Node> >
unsigned max_depth;
map < int, map < int, vector<Node> > > node;
map < int, map < int, std::vector<Node> > > node;
int return_type;
bool grow;

View file

@ -37,7 +37,7 @@
// a help function
template <class EOT>
void get_possible_nodes(const EOT &_eo, vector<int> &possible_nodes, const int type)
void get_possible_nodes(const EOT &_eo, std::vector<int> &possible_nodes, const int type)
{
int n=0;
possible_nodes.clear();
@ -65,7 +65,7 @@ public:
: eoQuadOp<EoType>(), max_length(_max_length) {};
/// the ckassname
virtual string className() const { return "eoStSubtreeXOver"; };
virtual std::string className() const { return "eoStSubtreeXOver"; };
/// Dtor
virtual ~eoStSubtreeXOver () {};
@ -78,7 +78,7 @@ public:
bool operator()(EoType & _eo1, EoType & _eo2 )
{
int i = 0;
vector<int> nodes;
std::vector<int> nodes;
int n = 0;
int type = 0;
int j = 0;
@ -142,7 +142,7 @@ public:
{};
/// the class name
virtual string className() const { return "eoStBranchMutation"; };
virtual std::string className() const { return "eoStBranchMutation"; };
/// Dtor
virtual ~eoStBranchMutation() {};
@ -154,7 +154,7 @@ public:
bool operator()(EoType& _eo1 )
{
int i = rng.random(_eo1.size());
vector<int> nodes;
std::vector<int> nodes;
int type = _eo1[i]->type();
int j=0;
int n=0;
@ -200,29 +200,29 @@ public:
/**
* Constructor
* @param _initializor The vector of Nodes given to the eoGpDepthInitializer
* @param _initializor The std::vector of Nodes given to the eoGpDepthInitializer
*/
eoStPointMutation( vector<Node>& _node)
eoStPointMutation( std::vector<Node>& _node)
: eoMonOp<EoType>()
{
unsigned int i=0;
int arity=0;
int type=0;
vector<Node> node_vector;
std::vector<Node> node_std::vector;
for(i=0; i < _node.size(); i++)
{
arity = _node[i].arity();
type = _node[i].type();
node_vector = node[type][arity];
node_vector.push_back(_node[i]);
node[type][arity]= node_vector;
node_std::vector = node[type][arity];
node_std::vector.push_back(_node[i]);
node[type][arity]= node_std::vector;
};
};
/// the class name
virtual string className() const { return "eoStPointMutation"; };
virtual std::string className() const { return "eoStPointMutation"; };
/// Dtor
virtual ~eoStPointMutation() {};
@ -246,7 +246,7 @@ public:
private :
map < int, map < int, vector<Node> > > node;
map < int, map < int, std::vector<Node> > > node;
};
@ -270,7 +270,7 @@ public:
{};
/// the class name
virtual string className() const { return "eoStHoistMutation"; };
virtual std::string className() const { return "eoStHoistMutation"; };
/// Dtor
virtual ~eoStHoistMutation() {};
@ -282,7 +282,7 @@ public:
bool operator()(EoType& _eo1 )
{
vector<int> nodes;
std::vector<int> nodes;
// get the type of the current tree
int type = _eo1[ _eo1.size() - 1 ]->type();

View file

@ -53,7 +53,7 @@
RetVal Node::operator()(RetVal, subtree<... , It values)
where It is whatever type you desire (most of the time
this will be a vector containing the values of your
this will be a std::vector containing the values of your
variables);
3) parse_tree::apply(RetVal, It values, It2 moreValues)
@ -129,22 +129,22 @@
tree[2] points at the root node4
Embedded iterators are implemented to iterate over nodes rather
than subtrees. So an easy way to copy your tree to a vector is:
than subtrees. So an easy way to copy your tree to a std::vector is:
vector<Node> vec(tree.size());
std::vector<Node> vec(tree.size());
copy(tree.ebegin(), tree.eend(), vec.begin());
You can also copy it to an ostream_iterator with this
You can also copy it to an std::ostream_iterator with this
technique, given that your Node implements an appropriate
operator<<. Reinitializing a tree with the vector is also
operator<<. Reinitializing a tree with the std::vector is also
simple:
tree.clear();
copy(vec.begin(), vec.end(), back_inserter(tree));
or from an istream:
or from an std::istream:
copy(istream_iterator<T>(my_stream), istream_iterator<T>(), back_inserter(tree));
copy(std::istream_iterator<T>(my_stream), std::istream_iterator<T>(), back_inserter(tree));
Note that the back_inserter must be used as there is no
resize member in the parse_tree. back_inserter will use
@ -972,7 +972,7 @@ void swap(gp_parse_tree::parse_tree<T>& a, gp_parse_tree::parse_tree<T>& b)
}
template<class T> inline
void iter_swap(vector<gp_parse_tree::parse_tree<T> >::iterator a, vector<gp_parse_tree::parse_tree<T> > b)
void iter_swap(std::vector<gp_parse_tree::parse_tree<T> >::iterator a, std::vector<gp_parse_tree::parse_tree<T> > b)
{
a->swap(*b);
}*/