* whitespace cleanup

This commit is contained in:
Caner Candan 2011-05-05 17:15:10 +02:00
commit 70e60a50d2
195 changed files with 1763 additions and 1873 deletions

View file

@ -18,8 +18,8 @@ LINK_DIRECTORIES(${EO_BINARY_DIR}/lib)
SET (GPSYMREG_SOURCES main.cpp)
# no matter what is the OS, hopefully
ADD_EXECUTABLE(gpsymreg ${GPSYMREG_SOURCES})
ADD_EXECUTABLE(gpsymreg ${GPSYMREG_SOURCES})
ADD_DEPENDENCIES(gpsymreg eo eoutils)
######################################################################################
@ -36,4 +36,3 @@ SET_TARGET_PROPERTIES(gpsymreg PROPERTIES VERSION "${GPSYMREG_VERSION}")
TARGET_LINK_LIBRARIES(gpsymreg eo eoutils)
######################################################################################

View file

@ -14,7 +14,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
jeggermo@liacs.nl
jeggermo@liacs.nl
*/
#ifndef _FITNESS_FUNCTION_H
@ -225,4 +225,3 @@ class RegFitness: public eoEvalFunc< eoParseTree<FitnessType, Node> >
};
#endif

View file

@ -30,7 +30,7 @@
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
jeggermo@liacs.nl
jeggermo@liacs.nl
*/
@ -146,25 +146,25 @@ int main(int argc, char *argv[])
// the parameters are passed on as well
RegFitness eval(generationCounter, initSequence, parameter);
RegFitness eval(generationCounter, initSequence, parameter);
// Depth Initializor, set for Ramped Half and Half Initialization
eoParseTreeDepthInit<FitnessType, Node> initializer(parameter.InitMaxDepth, initSequence, true, true);
eoParseTreeDepthInit<FitnessType, Node> initializer(parameter.InitMaxDepth, initSequence, true, true);
// create the initial population
Pop pop(parameter.population_size, initializer);
Pop pop(parameter.population_size, initializer);
// and evaluate the individuals
apply<EoType>(eval, pop);
apply<EoType>(eval, pop);
@ -335,10 +335,3 @@ int main(int argc, char *argv[])
}

View file

@ -3,18 +3,18 @@
it under the terms of the GNU 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 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
jeggermo@liacs.nl
jeggermo@liacs.nl
*/
#ifndef _NODE_H
@ -33,13 +33,13 @@ using namespace std;
/* A new Operation and Node class for even more flexibility.
Improvements over the t-eoSymreg code are:
* No hardcoded functions or operators. The Operation and Node class below
allow you to specify your own unary and binary functions as well as
binary operators (like +,-,*,/). Moreover you can detemine if you want
to allow primitve subroutines with either one or two arguments.
If a Node has a subroutine Operation it will take evaluate the first
If a Node has a subroutine Operation it will take evaluate the first
(and possible second) child branch and use them as input variables for
the remaining second (or third) child branch.
*/
@ -47,20 +47,20 @@ using namespace std;
typedef enum {Variable, UFunction, BFunction, BOperator, Const} Type;
typedef double (*BinaryFunction)(const double,const double);
typedef double (*BinaryFunction)(const double,const double);
typedef double (*UnaryFunction)(const double);
struct Operation
{
public:
typedef unsigned int VariableID;
typedef string Label;
// if your compiler allows you to have nameless unions you can make this a
// union by removing the //'s below
//union
//{
UnaryFunction uFunction;
@ -68,34 +68,34 @@ struct Operation
VariableID id;
double constant;
//};
Label label;
Type type;
// the default constructor results in a constant with value 0
Operation() : constant(0), label("0"), type(Const){};
// two possible constructors for Unary Functions
Operation(UnaryFunction _uf, Label _label): uFunction(_uf), label(_label), type(UFunction) {};
Operation(Label _label, UnaryFunction _uf): uFunction(_uf), label(_label), type(UFunction) {};
// Watch out there are two constructors using pointers two binary functions:
// Binary Function (printed as label(subtree0,subtree1) (e.g. pow(x,y))
// Binary Operator (printed as (subtree0 label subtree1) (e.g. x^y)
// The difference is purely cosmetic.
// If you specify the label before the function pointer -> Binary Function
Operation(Label _label, BinaryFunction _bf): bFunction(_bf), label(_label), type(BFunction) {};
// If you specify the function pointer before the label -> Binary Operator
Operation(BinaryFunction _bf, Label _label): bFunction(_bf), label(_label), type(BOperator) {};
// A constructor for variables
Operation(VariableID _id, Label _label): id(_id), label(_label), type(Variable) {};
// A constructor for constants
Operation(double _constant, Label _label): constant(_constant), label(_label), type(Const) {};
Operation(const Operation &_op)
{
switch(_op.type)
@ -110,7 +110,7 @@ struct Operation
label = _op.label;
};
virtual ~Operation(){};
};
@ -118,14 +118,14 @@ class Node
{
private:
Operation op;
public:
Node(void): op(Operation()){};
Node(Operation &_op) : op(_op){};
virtual ~Node(void) {}
int arity(void) const
int arity(void) const
{
switch(op.type)
{
@ -134,53 +134,53 @@ class Node
case BFunction: return 2;
case BOperator: return 2;
case Const: return 0;
}
return 0;
}
return 0;
}
void randomize(void) {}
template<class Children>
void operator()(double& result, Children args, vector<double> &var) const
{
double result0;
double result1;
switch(op.type)
{
case Variable: result = var[op.id%var.size()]; //%var.size() used in the case of Subroutines and as a security measure
break;
case UFunction: args[0].apply(result0, var);
result = op.uFunction(result0);
result = op.uFunction(result0);
break;
case BFunction:
case BFunction:
case BOperator: args[0].apply(result0, var);
args[1].apply(result1, var);
args[1].apply(result1, var);
result = op.bFunction(result0,result1);
break;
case Const: result = op.constant;
break;
break;
}
}
template<class Children>
void operator()(string& result, Children args) const
{
string subtree0;
string subtree1;
string subtree2;
switch(op.type)
{
case Variable:
case Variable:
case Const: result += op.label;
break;
case UFunction: result += op.label;
result += "(";
args[0].apply(subtree0);
@ -195,7 +195,7 @@ class Node
args[1].apply(subtree1);
result += subtree1;
result += ")";
break;
break;
case BOperator: result += "(";
args[0].apply(subtree0);
result += subtree0;
@ -204,16 +204,16 @@ class Node
result += subtree1;
result += ")";
break;
default: result += "ERROR in Node::operator(string,...) \n"; break;
default: result += "ERROR in Node::operator(string,...) \n"; break;
}
}
Operation getOp(void) const {return op;}
};
@ -230,7 +230,7 @@ class Node
std::ostream& operator<<(std::ostream& os, const Node& eot)
{
Operation op(eot.getOp());
os << (eot.getOp()).label;
return os;
}

View file

@ -3,18 +3,18 @@
it under the terms of the GNU 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 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
jeggermo@liacs.nl
jeggermo@liacs.nl
*/
#ifndef _PARAMETERS_FUNCTION_H
@ -28,7 +28,7 @@ using namespace std;
struct Parameters{
unsigned int nGenerations; // -G
unsigned population_size; // -P
unsigned population_size; // -P
unsigned offspring_size; // -O
unsigned int MaxSize; // -S
unsigned int InitMaxDepth; // -D
@ -41,72 +41,72 @@ struct Parameters{
Parameters(int argc, char **argv)
{
eoParser parser(argc,argv);
// generations
eoValueParam<unsigned int> paramGenerations(1, "generations", "Generations", 'G', false);
parser.processParam( paramGenerations );
nGenerations = paramGenerations.value();
cerr << "nGenerations= " << nGenerations << endl;
// populationsize
eoValueParam<unsigned int> paramPopulationSize(10, "populationsize", "PopulationSize", 'P', false);
parser.processParam( paramPopulationSize );
population_size = paramPopulationSize.value();
cerr << "population_size= " << population_size << endl;
// offspringsize
eoValueParam<unsigned int> paramOffspringSize(population_size, "offspringsize", "OffspringSize", 'O', false);
parser.processParam( paramOffspringSize );
offspring_size = paramOffspringSize.value();
cerr << "offspring_size= " << offspring_size << endl;
// maxsize
eoValueParam<unsigned int> paramMaxSize(15, "maxsize", "MaxSize", 'S', false);
parser.processParam( paramMaxSize );
MaxSize = paramMaxSize.value();
cerr << "MaxSize= " << MaxSize << endl;
// initialmaxdepth
eoValueParam<unsigned int> paramInitialMaxDepth(4, "initialmaxdepth", "InitialMaxDepth", 'D', false);
parser.processParam( paramInitialMaxDepth );
InitMaxDepth = paramInitialMaxDepth.value();
cerr << "InitMaxDepth= " << InitMaxDepth << endl;
// randomseed
eoValueParam<unsigned int> paramRandomSeed(1, "randomseed", "Random Seed", 'R', false);
parser.processParam( paramRandomSeed );
randomseed = paramRandomSeed.value();
cerr << "randomseed= " << randomseed << endl;
// crossover-rate
eoValueParam<double> paramXover(0.75, "crossoverrate", "crossover rate", 'x', false);
parser.processParam(paramXover );
xover_rate = paramXover.value();
cerr << "xover_rate= " << xover_rate << endl;
//mutation-rate
eoValueParam<double> paramMutation(0.25, "mutationrate", "mutation rate", 'm', false);
parser.processParam(paramMutation );
mutation_rate = paramMutation.value();
cerr << "mutation_rate= " << mutation_rate << endl;
//tournament size
eoValueParam<unsigned int > paramTournamentSize(5, "tournamentsize", "tournament size", 't', false);
parser.processParam(paramTournamentSize );
tournamentsize = paramTournamentSize.value();
cerr << "Tournament Size= " << tournamentsize << endl;
if (parser.userNeedsHelp())
{
parser.printHelp(cout);
exit(1);
parser.printHelp(cout);
exit(1);
}
};
~Parameters(){};
};
};
#endif