Ok, updated the Makefile.am again to use the

make check

Command I picked up in the automake documentation (RTFM, you know)

Tagged a lot of header functions in the GnuPlot files with 'inline',
so they can be used from more than one sourcefile.

Ok, now the interesting news. Started a new library libga (not to be confused
with Matthew's GaLib). Here I suggest we put a fairly complete and configurable
genetic algorithm. Just to see how far we can stretch ourselves and also to have
a GA-componenent that can be used in other applications without having to rebuild
the entire thing. test/t-eoGA.cpp tests this library
This commit is contained in:
maartenkeijzer 2001-02-12 13:58:51 +00:00
commit dea8a51f7e
12 changed files with 260 additions and 81 deletions

View file

@ -5,7 +5,7 @@
###############################################################################
INCLUDES = -I$(top_builddir)/src
CPPFLAGS = -O2
CPPFLAGS = -O2 -Wall
lib_LIBRARIES = libeoutils.a
libeoutils_a_SOURCES = eoParser.cpp eoRNG.cpp eoState.cpp eoUpdater.cpp eoFileMonitor.cpp eoStdoutMonitor.cpp

View file

@ -78,7 +78,7 @@ class eoGnuplot
}
protected:
protected:
void initGnuPlot(std::string _title, std::string _extra);
// the private data
bool firstTime; // the stats might be unknown in Ctor
@ -86,12 +86,12 @@ protected:
private:
};
// the following should be placed in a separate eoGnuplot.cpp
// the following should be placed in a separate eoGnuplot.cpp
static unsigned numWindow=0;
////////////////////////////////////////////////////////////
void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
inline void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
/////////////////////////////////////////////////////////
{
char snum[255];
@ -103,7 +103,7 @@ void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
args[1] = strdup( "-geometry" );
args[2] = strdup( os.str() );
args[3] = strdup( "-title" );
args[4] = strdup( _title.c_str() );
args[4] = strdup( _title.c_str() );
args[5] = 0;
gpCom = PipeComOpenArgv( "gnuplot", args );
if( ! gpCom )
@ -115,21 +115,21 @@ void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
}
}
// the following should be placed in a separate file pipecom.c
// together with the corresponding pipecom.h
// but first their MSC equivalent must be written and tested
// but first their MSC equivalent must be written and tested
// or some #idef instructions put with clear message at compile time
// that this is for Unix only ???
/* ----------------------------------------------------------------------
* Where........: CMAP - Polytechnique
* Where........: CMAP - Polytechnique
* File.........: pipecom.c
* Author.......: Bertrand Lamy (Equipe genetique)
* Created......: Mon Mar 13 13:50:11 1995
* Description..: Communication par pipe bidirectionnel avec un autre process
*
* Ident........: $Id: eoGnuplot.h,v 1.2 2001-02-01 05:17:16 evomarc Exp $
*
* Ident........: $Id: eoGnuplot.h,v 1.3 2001-02-12 13:58:51 maartenkeijzer Exp $
* ----------------------------------------------------------------------
*/
@ -142,7 +142,7 @@ void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
// #include "pipecom.h"
int Check( PCom *com )
inline int Check( PCom *com )
{
if( ! com ) {
fprintf( stderr, "PipeCom: Null pointer.\n" );
@ -158,16 +158,16 @@ int Check( PCom *com )
}
PCom * PipeComOpen( char *prog )
inline PCom * PipeComOpen( char *prog )
{
char *args[2];
args[0] = prog;
args[1] = NULL;
return PipeComOpenArgv( prog, args );
return PipeComOpenArgv( prog, args );
}
PCom * PipeComOpenArgv( char *prog, char *argv[] )
inline PCom * PipeComOpenArgv( char *prog, char *argv[] )
{
int toFils[2];
int toPere[2];
@ -188,7 +188,7 @@ PCom * PipeComOpenArgv( char *prog, char *argv[] )
perror("PipeComOpen: fork failed" );
return ret;
break;
case 0:
/* --- Here's the son --- */
/* --- replace old stdin --- */
@ -197,7 +197,7 @@ PCom * PipeComOpenArgv( char *prog, char *argv[] )
exit( -1 );
/* --- AVOIR: kill my father --- */
}
if( dup2( toPere[1], fileno(stdout) ) < 0 ) {
if( dup2( toPere[1], fileno(stdout) ) < 0 ) {
perror( "PipeComOpen(son): could not connect" );
exit( -1 );
}
@ -211,7 +211,7 @@ PCom * PipeComOpenArgv( char *prog, char *argv[] )
ret = (PCom *) malloc( sizeof(PCom) );
if( ! ret )
return NULL;
ret->fWrit = (FILE *)fdopen( toFils[1], "w" );
ret->fRead = (FILE *)fdopen( toPere[0], "r" );
ret->pid = sonPid;
@ -220,7 +220,7 @@ PCom * PipeComOpenArgv( char *prog, char *argv[] )
}
int PipeComSend( PCom *to, const char *line )
inline int PipeComSend( PCom *to, const char *line )
{
int nb = 0;
if( ! Check(to ) )
@ -231,10 +231,10 @@ int PipeComSend( PCom *to, const char *line )
}
int PipeComSendn( PCom *to, const char *data, int n )
inline int PipeComSendn( PCom *to, const char *data, int n )
{
int nb = 0;
if( ! Check(to) )
if( ! Check(to) )
return nb;
nb = fwrite( data, 1, n, to->fWrit );
@ -243,9 +243,9 @@ int PipeComSendn( PCom *to, const char *data, int n )
}
int PipeComReceive( PCom *from, char *data, int max )
inline int PipeComReceive( PCom *from, char *data, int max )
{
if( ! Check(from) )
if( ! Check(from) )
return 0;
if( ! data ) {
fprintf( stderr, "PipeComReceive: Invalid data pointer\n" );
@ -259,7 +259,7 @@ int PipeComReceive( PCom *from, char *data, int max )
int PipeComClose( PCom *to )
inline int PipeComClose( PCom *to )
{
if( ! Check(to) )
return 0;
@ -271,7 +271,7 @@ int PipeComClose( PCom *to )
int PipeComWaitFor( PCom *from, char *what )
inline int PipeComWaitFor( PCom *from, char *what )
{
char buffer[256];
do {

View file

@ -48,34 +48,34 @@ This class plots through gnuplot the eoStat given as argument
/** eoGnuplot1DMonitor plots stats through gnuplot
* assumes that the same file is appened every so and so,
* assumes that the same file is appened every so and so,
* and replots it everytime
*/
class eoGnuplot1DMonitor: public eoFileMonitor, public eoGnuplot
{
public:
// Ctor
eoGnuplot1DMonitor(std::string _filename, bool _top=false) :
eoFileMonitor(_filename, " "),
eoGnuplot1DMonitor(std::string _filename, bool _top=false) :
eoFileMonitor(_filename, " "),
eoGnuplot(_filename,(_top?"":"set key bottom"))
{}
// Dtor
virtual ~eoGnuplot1DMonitor(){}
virtual eoMonitor& operator() (void) ;
virtual void FirstPlot();
virtual void FirstPlot();
/// Class name.
virtual string className() const { return "eoGnuplot1DMonitor"; }
private:
private:
};
// the following should be placed in a separate eoGnuplot1DMonitor.cpp
// the following should be placed in a separate eoGnuplot1DMonitor.cpp
// then the inline specifier should dissappear
////////////////////////////////////////////////////////////
eoMonitor& eoGnuplot1DMonitor::operator() (void)
inline eoMonitor& eoGnuplot1DMonitor::operator() (void)
/////////////////////////////////////////////////////////
{
// update file using the eoFileMonitor
@ -98,10 +98,10 @@ eoMonitor& eoGnuplot1DMonitor::operator() (void)
}
////////////////////////////////////////////////////////////
void eoGnuplot1DMonitor::FirstPlot()
inline void eoGnuplot1DMonitor::FirstPlot()
////////////////////////////////////////////////////////
{
if (vec.size() < 2)
if (vec.size() < 2)
{
throw runtime_error("Must have some stats to plot!\n");
}
@ -118,5 +118,5 @@ void eoGnuplot1DMonitor::FirstPlot()
os << '\0';
PipeComSend( gpCom, buff );
}
#endif _eoGnuplot1DMonitor_H

View file

@ -81,7 +81,7 @@ private:
// the following should be placed in a separate eoGnuplot1DMonitor.cpp
////////////////////////////////////////////////////////////
eoMonitor& eoGnuplot1DSnapshot::operator() (void)
inline eoMonitor& eoGnuplot1DSnapshot::operator() (void)
/////////////////////////////////////////////////////////
{
// update file using the eoFileMonitor

View file

@ -3,7 +3,7 @@
//-----------------------------------------------------------------------------
// eoState.h
// (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000
/*
/*
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
@ -32,6 +32,8 @@
#include <map>
#include <vector>
#include <eoFunctorStore.h>
class eoObject;
class eoPersistent;
@ -40,7 +42,7 @@ class eoPersistent;
* then in turn implement the persistence framework through members load
* and save, that will call readFrom and printOn for the registrated objects.
*/
class eoState
class eoState
{
public :
@ -54,7 +56,7 @@ public :
void registerObject(eoPersistent& registrant);
/**
* Copies the object (MUST be derived from eoPersistent)
* Copies the object (MUST be derived from eoPersistent)
* and returns a reference to the owned object.
* Note: it does not register the object, this must be done afterwards!
*/
@ -65,7 +67,13 @@ public :
ownedObjects.push_back(new T(persistent));
return static_cast<T&>(*ownedObjects.back());
}
void storeFunctor(eoFunctorBase* _functor)
{
// add it to the functorStore, fo
functorStore.add(_functor);
}
/**
* Loading error thrown when nothing seems to work.
*/
@ -82,21 +90,21 @@ public :
* @param _filename the name of the file to load from
*/
void load(const std::string& _filename);
/**
* Reads the file specified
*
* @param is the stream to load from
*/
void load(std::istream& is);
/**
* Saves the state in file specified
*
* @param _filename the name of the file to save into
*/
void save(const std::string& _filename) const;
/**
* Saves the state in file specified
*
@ -109,13 +117,15 @@ private :
// first is Persistent, second is the raw data associated with it.
typedef std::map<std::string, eoPersistent*> ObjectMap;
ObjectMap objectMap;
std::vector<ObjectMap::iterator> creationOrder;
std::vector<eoPersistent*> ownedObjects;
// And a functor store to boot
eoFunctorStore functorStore;
// private copy and assignment as eoState is supposed to be unique
eoState(const eoState&);
eoState& operator=(const eoState&);