Moved out of the 'obsolete' directory a couple of honest classes, which didn't harm anybody; activated also in Makefile.am the program that tested them

This commit is contained in:
jmerelo 2001-02-13 22:35:07 +00:00
commit 0dd3e27e4e
6 changed files with 388 additions and 366 deletions

View file

@ -1,350 +1,350 @@
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(disable:4786) #pragma warning(disable:4786)
#endif #endif
#include <stdexcept> #include <stdexcept>
#include <algorithm> #include <algorithm>
#include <fstream> #include <fstream>
#include <iomanip> #include <iomanip>
#include <utils/compatibility.h> #include <utils/compatibility.h>
#include <utils/eoParser.h> #include <utils/eoParser.h>
using namespace std; using namespace std;
void eoWarning(std::string str) void eoWarning(std::string str)
{ {
cout << str << '\n'; cout << str << '\n';
} }
std::ostream& printSectionHeader(std::ostream& os, std::string section) std::ostream& printSectionHeader(std::ostream& os, std::string section)
{ {
if (section == "") if (section == "")
section = "General"; section = "General";
os << '\n' << setw(10) << "###### " << setw(20) << section << setw(10) << " ######\n"; os << '\n' << setw(10) << "###### " << setw(20) << section << setw(10) << " ######\n";
return os; return os;
} }
eoParameterLoader::~eoParameterLoader() eoParameterLoader::~eoParameterLoader()
{ {
for (unsigned i = 0; i < ownedParams.size(); ++i) for (unsigned i = 0; i < ownedParams.size(); ++i)
{ {
delete ownedParams[i]; delete ownedParams[i];
} }
} }
eoParser::eoParser ( int _argc, char **_argv , string _programDescription, string _lFileParamName, char _shortHand) : eoParser::eoParser ( unsigned _argc, char **_argv , string _programDescription, string _lFileParamName, char _shortHand) :
programName( _argv[0]), programName( _argv[0]),
programDescription( _programDescription), programDescription( _programDescription),
needHelp(false, "help", "Prints this message", 'h') needHelp(false, "help", "Prints this message", 'h')
{ {
// need to process the param file first // need to process the param file first
// if we want command-line to have highest priority // if we want command-line to have highest priority
unsigned i; unsigned i;
for (i = 1; i < _argc; ++i) for (i = 1; i < _argc; ++i)
{ {
if (_argv[i][0] == '@') if (_argv[i][0] == '@')
{ // read response file { // read response file
char *pts = _argv[i]+1; // yes a char*, sorry :-) char *pts = _argv[i]+1; // yes a char*, sorry :-)
ifstream ifs (pts); ifstream ifs (pts);
ifs.peek(); // check if it exists ifs.peek(); // check if it exists
if (!ifs) if (!ifs)
{ {
string msg = (string)("Could not open response file: ") + pts; string msg = (string)("Could not open response file: ") + pts;
throw runtime_error(msg); throw runtime_error(msg);
} }
// read - will be overwritten by command-line // read - will be overwritten by command-line
readFrom(ifs); readFrom(ifs);
break; // stop reading command line args for '@' break; // stop reading command line args for '@'
} }
} }
// now read arguments on command-line // now read arguments on command-line
strstream stream; strstream stream;
for (i = 1; i < _argc; ++i) for (i = 1; i < _argc; ++i)
{ {
stream << _argv[i] << '\n'; stream << _argv[i] << '\n';
} }
readFrom(stream); readFrom(stream);
processParam(needHelp); processParam(needHelp);
} }
void eoParser::processParam(eoParam& param, std::string section) void eoParser::processParam(eoParam& param, std::string section)
{ {
doRegisterParam(param); // plainly register it doRegisterParam(param); // plainly register it
params.insert(make_pair(section, &param)); params.insert(make_pair(section, &param));
} }
void eoParser::doRegisterParam(eoParam& param) const void eoParser::doRegisterParam(eoParam& param) const
{ {
if (param.required() && !isItThere(param)) if (param.required() && !isItThere(param))
{ {
string msg = "Required parameter: " + param.longName() + " missing"; string msg = "Required parameter: " + param.longName() + " missing";
messages.push_back(msg); messages.push_back(msg);
} }
pair<bool, string> value = getValue(param); pair<bool, string> value = getValue(param);
if (value.first) if (value.first)
{ {
param.setValue(value.second); param.setValue(value.second);
} }
} }
pair<bool, string> eoParser::getValue(eoParam& _param) const pair<bool, string> eoParser::getValue(eoParam& _param) const
{ {
pair<bool, string> result(false, ""); pair<bool, string> result(false, "");
if (_param.shortName() != 0) if (_param.shortName() != 0)
{ {
map<char, string>::const_iterator it = shortNameMap.find(_param.shortName()); map<char, string>::const_iterator it = shortNameMap.find(_param.shortName());
if (it != shortNameMap.end()) if (it != shortNameMap.end())
{ {
result.second = it->second; result.second = it->second;
result.first = true; result.first = true;
return result; return result;
} }
} }
map<string, string>::const_iterator it = longNameMap.find(_param.longName()); map<string, string>::const_iterator it = longNameMap.find(_param.longName());
if (it != longNameMap.end()) if (it != longNameMap.end())
{ {
result.second = it->second; result.second = it->second;
result.first = true; result.first = true;
return result; return result;
} }
// else (TODO: check environment, just long names) // else (TODO: check environment, just long names)
return result; return result;
} }
void eoParser::updateParameters() const void eoParser::updateParameters() const
{ {
typedef MultiMapType::const_iterator It; typedef MultiMapType::const_iterator It;
for (It p = params.begin(); p != params.end(); ++p) for (It p = params.begin(); p != params.end(); ++p)
{ {
doRegisterParam(*p->second); doRegisterParam(*p->second);
} }
} }
void eoParser::readFrom(istream& is) void eoParser::readFrom(istream& is)
{ {
string str; string str;
while (is >> str) while (is >> str)
{ {
if (str[0] == '#') if (str[0] == '#')
{ // skip the rest of the line { // skip the rest of the line
string tempStr; string tempStr;
getline(is, tempStr); getline(is, tempStr);
} }
if (str[0] == '-') if (str[0] == '-')
{ {
if (str.size() < 2) if (str.size() < 2)
{ {
eoWarning("Missing parameter"); eoWarning("Missing parameter");
needHelp.value() = true; needHelp.value() = true;
return; return;
} }
if (str[1] == '-') // two consecutive dashes if (str[1] == '-') // two consecutive dashes
{ {
string::iterator equalLocation = find(str.begin() + 2, str.end(), '='); string::iterator equalLocation = find(str.begin() + 2, str.end(), '=');
string value; string value;
if (equalLocation == str.end()) if (equalLocation == str.end())
{ // TODO: it should be the next string { // TODO: it should be the next string
value = ""; value = "";
} }
else else
{ {
value = string(equalLocation + 1, str.end()); value = string(equalLocation + 1, str.end());
} }
string name(str.begin() + 2, equalLocation); string name(str.begin() + 2, equalLocation);
longNameMap[name] = value; longNameMap[name] = value;
} }
else // it should be a char else // it should be a char
{ {
string value = "1"; // flags do not need a special string value = "1"; // flags do not need a special
if (str.size() >= 2) if (str.size() >= 2)
{ {
if (str[2] == '=') if (str[2] == '=')
{ {
if (str.size() >= 3) if (str.size() >= 3)
value = string(str.begin() + 3, str.end()); value = string(str.begin() + 3, str.end());
} }
else else
{ {
value = string(str.begin() + 2, str.end()); value = string(str.begin() + 2, str.end());
} }
} }
shortNameMap[str[1]] = value; shortNameMap[str[1]] = value;
} }
} }
} }
updateParameters(); updateParameters();
} }
void eoParser::printOn(ostream& os) const void eoParser::printOn(ostream& os) const
{ {
typedef MultiMapType::const_iterator It; typedef MultiMapType::const_iterator It;
It p = params.begin(); It p = params.begin();
std::string section = p->first; std::string section = p->first;
printSectionHeader(os, section); printSectionHeader(os, section);
//print every param with its value //print every param with its value
for (; p != params.end(); ++p) for (; p != params.end(); ++p)
{ {
std::string newSection = p->first; std::string newSection = p->first;
if (newSection != section) if (newSection != section)
{ {
section = newSection; section = newSection;
printSectionHeader(os, section); printSectionHeader(os, section);
} }
eoParam* param = p->second; eoParam* param = p->second;
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 << setw(40) << str;
os << setw(0) << " # "; os << setw(0) << " # ";
if (param->shortName()) if (param->shortName())
os << '-' << param->shortName() << " : "; os << '-' << param->shortName() << " : ";
os << param->description(); os << param->description();
if (param->required()) if (param->required())
{ {
os << " REQUIRED "; os << " REQUIRED ";
} }
os << '\n'; os << '\n';
} }
} }
void eoParser::printHelp(ostream& os) void eoParser::printHelp(ostream& os)
{ {
if (needHelp.value() == false && !messages.empty()) if (needHelp.value() == false && !messages.empty())
{ {
std::copy(messages.begin(), messages.end(), ostream_iterator<string>(os, "\n")); std::copy(messages.begin(), messages.end(), ostream_iterator<string>(os, "\n"));
messages.clear(); messages.clear();
return; return;
} }
// print program name and description // print program name and description
os << this->programName <<": "<< programDescription << "\n\n"; os << this->programName <<": "<< programDescription << "\n\n";
// print the usage when calling the program from the command line // print the usage when calling the program from the command line
os << "Usage: "<< programName<<" [Options]\n"; os << "Usage: "<< programName<<" [Options]\n";
// only short usage! // only short usage!
os << "Options of the form \"-f[=Value]\" or \"--Name[=value]\"" << endl; os << "Options of the form \"-f[=Value]\" or \"--Name[=value]\"" << endl;
os << "Where:"<<endl; os << "Where:"<<endl;
typedef MultiMapType::const_iterator It; typedef MultiMapType::const_iterator It;
It p = params.begin(); It p = params.begin();
std::string section = p->first; std::string section = p->first;
printSectionHeader(os, section); printSectionHeader(os, section);
//print every param with its value //print every param with its value
for (; p != params.end(); ++p) for (; p != params.end(); ++p)
{ {
std::string newSection = p->first; std::string newSection = p->first;
if (newSection != section) if (newSection != section)
{ {
section = newSection; section = newSection;
printSectionHeader(os, section); printSectionHeader(os, section);
} }
if (p->second->shortName()) if (p->second->shortName())
os << "-" << p->second->shortName() << ", "; os << "-" << p->second->shortName() << ", ";
os << "--" <<p->second->longName() <<":\t" os << "--" <<p->second->longName() <<":\t"
<< p->second->description() ; << p->second->description() ;
os << "\n" << setw(20) << ( (p->second->required())?"Required":"Optional" ); os << "\n" << setw(20) << ( (p->second->required())?"Required":"Optional" );
os <<". By default: "<<p->second->defValue() << '\n'; os <<". By default: "<<p->second->defValue() << '\n';
} // for p } // for p
os << "\n@param_file \t defines a file where the parameters are stored\n"; os << "\n@param_file \t defines a file where the parameters are stored\n";
os << '\n'; os << '\n';
} }
bool eoParser::userNeedsHelp(void) bool eoParser::userNeedsHelp(void)
{ {
/* /*
check whether there are long or short names entered check whether there are long or short names entered
without a corresponding parameter without a corresponding parameter
*/ */
for (LongNameMapType::const_iterator lIt = longNameMap.begin(); lIt != longNameMap.end(); ++lIt) for (LongNameMapType::const_iterator lIt = longNameMap.begin(); lIt != longNameMap.end(); ++lIt)
{ {
string entry = lIt->first; string entry = lIt->first;
MultiMapType::const_iterator it; MultiMapType::const_iterator it;
for (it = params.begin(); it != params.end(); ++it) for (it = params.begin(); it != params.end(); ++it)
{ {
if (entry == it->second->longName()) if (entry == it->second->longName())
{ {
break; break;
} }
} }
if (it == params.end()) if (it == params.end())
{ {
string msg = "Unknown parameter: --" + entry + " entered, type -h or --help to see available parameters"; string msg = "Unknown parameter: --" + entry + " entered, type -h or --help to see available parameters";
messages.push_back(msg); messages.push_back(msg);
} }
} }
for (ShortNameMapType::const_iterator sIt = shortNameMap.begin(); sIt != shortNameMap.end(); ++sIt) for (ShortNameMapType::const_iterator sIt = shortNameMap.begin(); sIt != shortNameMap.end(); ++sIt)
{ {
char entry = sIt->first; char entry = sIt->first;
MultiMapType::const_iterator it; MultiMapType::const_iterator it;
for (it = params.begin(); it != params.end(); ++it) for (it = params.begin(); it != params.end(); ++it)
{ {
if (entry == it->second->shortName()) if (entry == it->second->shortName())
{ {
break; break;
} }
} }
if (it == params.end()) if (it == params.end())
{ {
string entryString(1, entry); string entryString(1, entry);
string msg = "Unknown parameter: -" + entryString + " entered, type -h or --help to see available parameters"; string msg = "Unknown parameter: -" + entryString + " entered, type -h or --help to see available parameters";
messages.push_back(msg); messages.push_back(msg);
} }
} }
return needHelp.value() || !messages.empty(); return needHelp.value() || !messages.empty();
} }

View file

@ -23,7 +23,9 @@
mkeijzer@dhi.dk mkeijzer@dhi.dk
*/ */
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/**
CVS Info: $Date: 2001-02-13 22:35:07 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/utils/eoParser.h,v 1.7 2001-02-13 22:35:07 jmerelo Exp $ $Author: jmerelo $ $Log$
*/
#ifndef eoParser_h #ifndef eoParser_h
#define eoParser_h #define eoParser_h
@ -111,7 +113,7 @@ public:
* @param _lFileParamName Name of the parameter specifying the configuration file (--param-file) * @param _lFileParamName Name of the parameter specifying the configuration file (--param-file)
* @param _shortHand Single charachter shorthand for specifying the configuration file * @param _shortHand Single charachter shorthand for specifying the configuration file
*/ */
eoParser ( int _argc, char **_argv , string _programDescription = "", eoParser ( unsigned _argc, char **_argv , string _programDescription = "",
string _lFileParamName = "param-file", char _shortHand = 'p'); string _lFileParamName = "param-file", char _shortHand = 'p');
/** /**

View file

@ -21,7 +21,9 @@
Contact: todos@geneura.ugr.es, http://geneura.ugr.es Contact: todos@geneura.ugr.es, http://geneura.ugr.es
*/ */
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/**
CVS Info: $Date: 2001-02-13 22:35:07 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/utils/Attic/eoRnd.h,v 1.1 2001-02-13 22:35:07 jmerelo Exp $ $Author: jmerelo $ $Log$
*/
#ifndef _EORND_H #ifndef _EORND_H
#define _EORND_H #define _EORND_H

View file

@ -21,6 +21,11 @@
Contact: todos@geneura.ugr.es, http://geneura.ugr.es Contact: todos@geneura.ugr.es, http://geneura.ugr.es
*/ */
/**
CVS Info: $Date: 2001-02-13 22:35:07 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/utils/Attic/eoUniform.h,v 1.1 2001-02-13 22:35:07 jmerelo Exp $ $Author: jmerelo $ $Log$
*/
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#ifndef _EOUNIFORM_H #ifndef _EOUNIFORM_H
@ -28,14 +33,19 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include <eoRnd.h> #include <utils/eoRnd.h>
#include <utils/eoRNG.h> #include <utils/eoRNG.h>
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Class eoUniform // Class eoUniform
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/// Generates uniform random number over the interval [min, max) /** Generates uniform random number over the interval [min, max)
Uses the global variable rng
*/
using eo::rng;
template<class T> template<class T>
class eoUniform: public eoRnd<T> class eoUniform: public eoRnd<T>
{ {

View file

@ -13,7 +13,8 @@ LDADDS = $(top_builddir)/src/libeo.a $(top_builddir)/src/utils/libeoutils.a
CXXFLAGS = -g CXXFLAGS = -g
############################################################################### ###############################################################################
check_PROGRAMS = t-eofitness t-eobin t-eoStateAndParser t-eoCheckpointing t-eoExternalEO t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA check_PROGRAMS = t-eofitness t-eoRandom t-eobin t-eoStateAndParser t-eoCheckpointing \
t-eoExternalEO t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA
TESTS=run_tests TESTS=run_tests
# removing temporarily t-eoESFull # removing temporarily t-eoESFull
#noinst_PROGRAMS = t-eofitness t-eobin t-eoStateAndParser t-eoCheckpointing t-eoExternalEO t-eoESFull t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA #noinst_PROGRAMS = t-eofitness t-eobin t-eoStateAndParser t-eoCheckpointing t-eoExternalEO t-eoESFull t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA
@ -24,6 +25,11 @@ TESTS=run_tests
#t_eoESFull_DEPENDENCIES = $(DEPS) #t_eoESFull_DEPENDENCIES = $(DEPS)
#t_eoESFull_LDFLAGS = -lm #t_eoESFull_LDFLAGS = -lm
#t_eoESFull_LDADD = $(LDADDS) #t_eoESFull_LDADD = $(LDADDS)
###############################################################################
t_eoRandom_SOURCES = t-eoRandom.cpp
t_eoRandom_DEPENDENCIES = $(DEPS)
t_eoRandom_LDADD = $(LDADDS)
############################################################################### ###############################################################################

View file

@ -23,27 +23,29 @@
*/ */
/**
CVS Info: $Date: 2001-02-13 22:35:07 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/test/t-eoRandom.cpp,v 1.5 2001-02-13 22:35:07 jmerelo Exp $ $Author: jmerelo $ $Log$
*/
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include <iostream> // cout #include <iostream> // cout
#include <strstream> // ostrstream, istrstream #include <strstream> // ostrstream, istrstream
#include <eoUniform.h> // eoBin #include <utils/eoUniform.h> // eoBin
#include <eoNormal.h> //#include <eoNormal.h>
#include <eoNegExp.h> //#include <eoNegExp.h>
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
main() { main() {
eoNormal<float> n1(-2.5,3.5); eoUniform<float> u1(-2.5,3.5);
eoNormal<double> n2(0.003, 0.0005 ); eoUniform<double> u2(0.003, 0.0005 );
eoNormal<unsigned long> n3( 10000000U, 10000U); eoUniform<unsigned long> u3( 10000000U, 10000U);
eoNegExp<float> e1(3.5); /* eoNegExp<float> e1(3.5);
eoNegExp<double> e2(0.003 ); eoNegExp<double> e2(0.003 );
eoNegExp<long> e3( 10000U); eoNegExp<long> e3( 10000U);
cout << "n1\t\tn2\t\tn3\t\te1\t\te2\t\te3" << endl; cout << "n1\t\tn2\t\tn3\t\te1\t\te2\t\te3" << endl; */
for ( unsigned i = 0; i < 100; i ++) { for ( unsigned i = 0; i < 100; i ++) {
cout << n1() << "\t" << n2() << "\t" << n3() << "\t" << cout << u1() << "\t" << u2() << "\t" << u3() << endl;
e1() << "\t" << e2() << "\t" << e3() << endl;
} }
return 0; // to avoid VC++ complaints return 0; // to avoid VC++ complaints