Clean up configure/build-process.

- assume C++ standard-conforming environment
- add a user-option for gnuplot-support
- separate gnuplot-code into declaration and implementation,
  so we can define at EO-build-time whether to use it or not.

Adopt code and Makefiles to above changes.

Some minor fixes.
This commit is contained in:
kuepper 2005-10-02 21:42:08 +00:00
commit 47af7cfe5a
22 changed files with 603 additions and 537 deletions

View file

@ -14,7 +14,7 @@ SUBDIRS = src doc contrib win $(SUBDIRS_APP) $(SUBDIRS_TUT) test
# Directory for documents
DOCDIR = ~/public_html/eodocs
#Directory for indices -- not useful for the user
# Directory for indices -- not useful for the user
IDXDIR = ~/index

View file

@ -2,7 +2,8 @@
#
# Compile applications unless user requests not to do it.
AC_DEFUN([AC_APPLICATIONS],[dnl
AC_ARG_ENABLE([applications],[ --enable-applications build applications (default=yes)],
AC_ARG_ENABLE([applications],
AC_HELP_STRING([--enable-applications], [build applications (default=yes)]),
[ case "${enableval}" in
yes) applications=true ;;
no) applications=false ;;
@ -18,11 +19,34 @@ AC_DEFUN([AC_APPLICATIONS],[dnl
# AC_GNUPLOT()
#
# Compile applications unless user requests not to do it.
AC_DEFUN([AC_GNUPLOT], [dnl
AC_ARG_ENABLE([gnuplot],
AC_HELP_STRING([--enable-gnuplot], [use gnuplot for graphical display (default=yes)]),
[ac_cv_use_gnuplot=$enableval],
[ac_cv_use_gnuplot=yes])
AC_CACHE_CHECK([use gnuplot for graphical display],
[ac_cv_use_gnuplot],
[ac_cv_use_gnuplot=no])
if test "$ac_cv_use_gnuplot" = "yes"; then
AC_ARG_VAR([GNUPLOT], [gnuplot used for graphical display])
AC_CHECK_PROG([GNUPLOT], [gnuplot], [true])
AC_DEFINE([HAVE_GNUPLOT], [1], [gnuplot graphical display])
else
AC_DEFINE([NO_GNUPLOT], [1], [no gnuplot graphical display])
fi
])
# AC_TUTORIAL()
#
# Compile tutorial unless user requests not to do it.
AC_DEFUN([AC_TUTORIAL],[dnl
AC_ARG_ENABLE([tutorial],[ --enable-tutorial build tutorial (default=yes)],
AC_ARG_ENABLE([tutorial],
AC_HELP_STRING([--enable-tutoria], [build tutorial (default=yes)]),
[ case "${enableval}" in
yes) tutorial=true ;;
no) tutorial=false ;;
@ -35,46 +59,3 @@ AC_DEFUN([AC_TUTORIAL],[dnl
AM_CONDITIONAL([USE_TUTORIAL], false)
fi
])
dnl Available from the GNU Autoconf Macro Archive at:
dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_namespaces.html
dnl
AC_DEFUN([AC_CXX_NAMESPACES],
[AC_CACHE_CHECK(whether the compiler implements namespaces,
ac_cv_cxx_namespaces,
[AC_LANG_SAVE
AC_LANG_CPLUSPLUS
AC_TRY_COMPILE([namespace Outer { namespace Inner { int i = 0; }}],
[using namespace Outer::Inner; return i;],
ac_cv_cxx_namespaces=yes, ac_cv_cxx_namespaces=no)
AC_LANG_RESTORE
])
if test "$ac_cv_cxx_namespaces" = yes; then
AC_DEFINE(HAVE_NAMESPACES,,[define if the compiler implements namespaces])
fi
])
dnl Available from the GNU Autoconf Macro Archive at:
dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_have_numeric_limits.html
dnl
AC_DEFUN([AC_CXX_HAVE_NUMERIC_LIMITS],
[AC_CACHE_CHECK(whether the compiler has numeric_limits<T>,
ac_cv_cxx_have_numeric_limits,
[AC_REQUIRE([AC_CXX_NAMESPACES])
AC_LANG_SAVE
AC_LANG_CPLUSPLUS
AC_TRY_COMPILE([#include <limits>
#ifdef HAVE_NAMESPACES
using namespace std;
#endif],[double e = numeric_limits<double>::epsilon(); return 0;],
ac_cv_cxx_have_numeric_limits=yes, ac_cv_cxx_have_numeric_limits=no)
AC_LANG_RESTORE
])
if test "$ac_cv_cxx_have_numeric_limits" = yes; then
AC_DEFINE(HAVE_NUMERIC_LIMITS,,[define if the compiler has numeric_limits<T>])
fi
])

View file

@ -5,42 +5,30 @@
#ifndef mlp_h
#define mlp_h
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_NUMERIC_LIMITS
#include <numeric>
#define MLP_MAXFLOAT std::numeric_limits<double>::max()
#define MLP_MINFLOAT std::numeric_limits<double>::min()
#elif defined HAVE_VALUES_H
#include <values.h>
#define MLP_MAXFLOAT MAXFLOAT
#define MLP_MINFLOAT MINFLOAT
#else
#error numerical limits not available
#endif
#include <math.h> // exp
#include <stdexcept> // invalid_argument
#include <iostream> // istream ostream
#include <algorithm> // generate
#include <vector> // vector
#include <utils/eoRNG.h> // eoRng
#include <utils/rnd_generators.h> // normal_geneurator
#include <vecop.h> // *
#include <utility>
#include <cmath> // exp
#include <iostream>
#include <iterator>
#include <numeric>
#include <stdexcept> // invalid_argument
#include <utility>
#include <vector>
#include <utils/eoRNG.h> // eoRng
#include <utils/rnd_generators.h> // normal_generator
#include <vecop.h> // *
using namespace std;
namespace mlp
{
typedef double real;
typedef std::vector<real> vector;
using namespace std;
typedef double real;
typedef std::vector<real> vector;
}
namespace std {
ostream& operator<<(ostream& os, const mlp::vector& v)
{
@ -60,13 +48,15 @@ namespace std {
namespace mlp
{
using namespace std;
//---------------------------------------------------------------------------
// useful typedefs
//---------------------------------------------------------------------------
const real max_real = MLP_MAXFLOAT;
const real min_real = MLP_MINFLOAT;
const real max_real = std::numeric_limits<real>::max();
const real min_real = std::numeric_limits<real>::min();
//---------------------------------------------------------------------------
@ -459,12 +449,9 @@ namespace mlp {
#undef MLP_MAXFLOAT
#undef MLP_MINFLOAT
#endif // mlp_h
// Local Variables:
// mode:C++
// c-file-style: "Stroustrup"

View file

@ -11,5 +11,5 @@ LIBEO = $(top_builddir)/src/libeo.a
LIBEOUTILS = $(top_builddir)/src/utils/libeoutils.a
AM_CXXFLAGS = -I$(top_srcdir)/src
DEPS = $(LIBEOUTILS) $(LIBEO)
LIBS = $(LIBEOUTILS) $(LIBEO)
DEPS = $(LIBEO) $(LIBEOUTILS)
LIBS = $(LIBEO) $(LIBEOUTILS)

View file

@ -10,5 +10,5 @@ LIBEO = $(top_builddir)/src/libeo.a
LIBEOUTILS = $(top_builddir)/src/utils/libeoutils.a
AM_CXXFLAGS = -I$(top_srcdir)/src
DEPS = $(LIBEOUTILS) $(LIBEO)
LIBS = $(LIBEOUTILS) $(LIBEO)
DEPS = $(LIBEO) $(LIBEOUTILS)
LIBS = $(LIBEO) $(LIBEOUTILS)

View file

@ -11,7 +11,7 @@
#include <eoVector.h> // eoVectorLength
#include <eoOp.h> // eoMonOp eoQuadraticOp
#include <eoInit.h> // eoInit
#include <utils/rnd_generators.h> // uniform_generator
#include "utils/rnd_generators.h" // uniform_generator
//-----------------------------------------------------------------------------
// phenotype
@ -50,7 +50,7 @@ phenotype eoChromEvaluator(const Chrom& chrom)
++black;
tmp[i] = -1;
}
// look for whites
for (unsigned i = 0; i < chrom.size(); ++i)
for (unsigned j = 0; j < tmp.size(); ++j)
@ -75,7 +75,7 @@ unsigned num_colors;
void init_eoChromEvaluator(const unsigned& c, const unsigned& l, std::string s)
{
num_colors = c;
// check consistency between parameters
if (s != default_solution)
{
@ -85,14 +85,14 @@ void init_eoChromEvaluator(const unsigned& c, const unsigned& l, std::string s)
std::cerr << "solution length != length" << std::endl;
exit(EXIT_FAILURE);
}
// check number of colors
if (c != default_colors && c < *max_element(s.begin(), s.end()) - '0')
if ((c != default_colors) && (c < unsigned(*max_element(s.begin(), s.end()) - '0')))
{
std::cerr << "too high color number found!" << std::endl;
exit(EXIT_FAILURE);
}
}
}
else
if (l != default_length || c != default_colors )
// generate a random solution
@ -102,7 +102,7 @@ void init_eoChromEvaluator(const unsigned& c, const unsigned& l, std::string s)
s.resize(l);
generate(s.begin(), s.end(), color);
}
// put the solution parameter on the solution chromosome
if (num_colors <= 10)
{

View file

@ -1,7 +1,6 @@
#!/bin/sh
DIE=0
PROG=eo
(autoconf --version) < /dev/null > /dev/null 2>&1 ||
@ -11,13 +10,6 @@ PROG=eo
DIE=1
}
#(libtool --version) < /dev/null > /dev/null 2>&1 ||
#{
# echo
# echo "You must have libtool installed to compile $PROG."
# DIE=1
#}
(automake --version) < /dev/null > /dev/null 2>&1 ||
{
echo
@ -37,7 +29,7 @@ automake -a -c
autoconf
# we want doc to be recompiled - and it keeps saying it's up to date!!!
touch doc/eo.cfg
# touch doc/eo.cfg
echo
echo "Now run 'configure' and 'make' to build $PROG."

View file

@ -16,10 +16,6 @@ dnl automake initialization
AM_INIT_AUTOMAKE([gnu dist-bzip2 dist-zip])
AM_CONFIG_HEADER(config.h)
dnl user-switches
AC_APPLICATIONS
AC_TUTORIAL
dnl Checks for programs.
AC_PROG_CC
AC_PROG_CXX
@ -27,33 +23,32 @@ AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_ARG_VAR([DOXYGEN], [doxygen - automatic documentation generator])
AC_PATH_PROG([AR], [ar], [false], [$PATH:/usr/ccs/bin]) # solaris-x86 needs extra path
AC_ARG_VAR([DOXYGEN], [automatic documentation generation])
AC_CHECK_PROGS([DOXYGEN], [doxygen], [true])
AC_ARG_VAR([AR], [ar - archiver for static libraries])
# solaris-x86 hides ar at "/usr/ccs/bin/ar"
AC_CHECK_PROGS([AR], [ar /usr/ccs/bin/ar], [false])
dnl Checks for compiler characteristics.
AC_CXX_NAMESPACES
AC_TYPE_SIZE_T
dnl Checks for header files.
AC_LANG(C++)
AC_HEADER_STDC
AC_CHECK_HEADERS(limits.h)
AC_CHECK_HEADERS(limits, [], AC_MSG_ERROR([Need limits C++ include.]))
AC_CHECK_HEADERS(sstream, [], AC_MSG_ERROR([Need sstream C++ include.]))
AC_CHECK_HEADERS(stdint.h, [], AC_MSG_WARN([Need C99 standard header.]))
AC_CXX_HAVE_NUMERIC_LIMITS
dnl Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_SIZEOF(unsigned long)
AC_CHECK_TYPES(uint32_t, [], AC_MSG_WARN([Need uint32_t from C99 standard.]))
AC_TYPE_SIZE_T
dnl Checks for libraries.
dnl Checks for library functions.
AC_CHECK_LIB(m, cos)
dnl user-switches
AC_APPLICATIONS
AC_GNUPLOT
AC_TUTORIAL
dnl create makefiles
AC_OUTPUT(Makefile \
app/Makefile \

View file

@ -67,27 +67,32 @@
<h2>Platforms</h2>
</td>
<td bgcolor="#ffcc99">
<p>EO should work on Windows and any Un*x-like operating system with
a standard-conforming C++ development system.
<p>
EO should work on Windows and any Un*x-like operating system with
a standard-conforming C++ development system.
</p>
<p>Recent versions of EO have been tested on the following
platforms:
<p>
Recent versions of EO have been tested on the following platforms:
<ul>
<li>Linux-x86 with GCC 3.x and 4.x</li>
<li>Linux-x86_64 with GCC 3.x</li>
<li>Darwin-powerpc (Macintosh) with GCC 3.3</li>
<li>Linux x86 with GCC 3.x and 4.x</li>
<li>Linux x86_64 with GCC 3.x</li>
<li>MacOS X/Darwin PowerPC with GCC 3.3</li>
<li>Solaris SPARC with GCC 3.3.2</li>
<li>Solaris x86 with GCC 3.3.2 (t-MGE1bit fails)</li>
<li>CygWin (Windows XP) with GCC 3.3.1 (cygming special).
<li>Win95/NT with VC++ 5.0 and Borland Builder. Makefiles and
projects files are provided.</li>
</ul>
If you have tested EO on a system not listed here, please
<a href="mailto:eodev-main@lists.sourceforge.net?subject=test-report">let us know</a>.
<a href="mailto:eodev-main@lists.sourceforge.net?subject=test-report">let
us know</a>.
</p>
<p>If you are working on a system with an older C++ compiler there
is a good chance that eo-0.9.3zz works. It is tested on Linux with
gcc-2.9x and several systems (IRIX, Solaris) with egcs.
<p>
If you are working on a system with an older C++ compiler there is
a good chance that eo-0.9.3zz works. It is tested on Linux with
gcc-2.9x and several systems (IRIX, Solaris) with egcs.
</p>
</td>
</tr>

View file

@ -113,5 +113,3 @@ pkginclude_HEADERS = eo \
ga.h
AM_CXXFLAGS = -I$(top_srcdir)/src
AM_LIBS = -Lutils -leoutil

View file

@ -3,15 +3,19 @@
lib_LIBRARIES = libeoutils.a
libeoutils_a_SOURCES = eoData.cpp \
eoFileMonitor.cpp \
eoGnuplot.cpp \
eoGnuplot1DMonitor.cpp \
eoGnuplot1DSnapshot.cpp \
eoIntBounds.cpp \
eoParser.cpp \
eoRealBounds.cpp \
eoRNG.cpp \
eoState.cpp \
eoUpdater.cpp \
eoFileMonitor.cpp \
eoStdoutMonitor.cpp \
eoRealBounds.cpp \
eoIntBounds.cpp \
make_help.cpp
eoUpdater.cpp \
make_help.cpp \
pipecom.cpp
utilsincludedir = $(pkgincludedir)/utils
@ -50,5 +54,4 @@ utilsinclude_HEADERS = checkpointing \
rnd_generators.h \
selectors.h
AM_CXXFLAGS = -I$(top_srcdir)/src
AM_CXXFLAGS = -I$(top_srcdir)/src -DGNUPLOT_PROGRAM=\"@GNUPLOT@\"

View file

@ -3,7 +3,7 @@
//-----------------------------------------------------------------------------
// eoFileMonitor.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
@ -21,33 +21,32 @@
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
Marc.Schoenauer@polytechnique.fr
mkeijzer@dhi.dk
CVS Info: $Date: 2004-09-21 19:49:48 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/utils/eoFileMonitor.h,v 1.13 2004-09-21 19:49:48 maartenkeijzer Exp $ $Author: maartenkeijzer $
*/
//-----------------------------------------------------------------------------
/** Modified the default behavior, so that it erases existing files.
Can be modified in the ctor.
MS 25/11/00
*/
#ifndef _eoFileMonitor_h
#define _eoFileMonitor_h
#ifndef EO_eoFileMonitor_h
#define EO_eoFileMonitor_h
#include <string>
#include <fstream>
#include <stdexcept>
#include <utils/eoMonitor.h>
#include <eoObject.h>
#include "utils/eoMonitor.h"
#include "eoObject.h"
/**
Prints statistics to file
/** Prints statistics to file
Modified the default behavior, so that it erases existing files. Can
be modified in the ctor.
@version MS 25/11/00
*/
class eoFileMonitor : public eoMonitor
{
public :
eoFileMonitor(std::string _filename, std::string _delim = " ", bool _keep = false, bool _header=false)
: filename(_filename), delim(_delim), keep(_keep), header(_header), firstcall(true)
eoFileMonitor(std::string _filename, std::string _delim = " ", bool _keep = false, bool _header=false)
: filename(_filename), delim(_delim), keep(_keep), header(_header), firstcall(true)
{
if (! _keep) {
std::ofstream os(filename.c_str());
@ -57,23 +56,23 @@ public :
}
}
}
virtual eoMonitor& operator()(void);
virtual eoMonitor& operator()(std::ostream& os);
void printHeader(void);
virtual void printHeader(std::ostream& os);
virtual std::string getFileName() { return filename;}
private :
std::string filename;
std::string delim;
bool keep; // should we append or create a new file
bool header; // printing header at begin of file?
bool firstcall;
};
#endif

View file

@ -0,0 +1,93 @@
//-----------------------------------------------------------------------------
// (c) Marc Schoenauer, 2001
// Copyright (C) 2005 Jochen Küpper
/*
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: Marc.Schoenauer@polytechnique.fr
*/
//-----------------------------------------------------------------------------
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <sstream>
#include <stdexcept>
#include "eoGnuplot.h"
unsigned eoGnuplot::numWindow=0;
eoGnuplot::eoGnuplot(std::string _title, std::string _extra)
: firstTime(true)
{
initGnuPlot(_title, _extra);
}
eoGnuplot::~eoGnuplot()
{
if( gpCom ) {
PipeComSend( gpCom, "quit\n" );
PipeComClose( gpCom );
gpCom =NULL;
}
}
void eoGnuplot::gnuplotCommand(const char *_command)
{
if(gpCom) {
PipeComSend( gpCom, _command );
PipeComSend( gpCom, "\n" );
}
}
void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
{
std::ostringstream os;
os << "250x150-0+" << numWindow*170;
numWindow++;
char *args[6];
args[0] = strdup( GNUPLOT_PROGRAM );
args[1] = strdup( "-geometry" );
args[2] = strdup( os.str().c_str());
args[3] = strdup( "-title" );
args[4] = strdup( _title.c_str() );
args[5] = 0;
gpCom = PipeComOpenArgv( GNUPLOT_PROGRAM, args );
if(! gpCom )
throw std::runtime_error("Cannot spawn gnuplot\n");
else {
PipeComSend( gpCom, "set grid\n" );
PipeComSend( gpCom, _extra.c_str() );
PipeComSend( gpCom, "\n" );
}
}
// Local Variables:
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -1,5 +1,3 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// eoGnuplot1DMonitor.h
// (c) Marc Schoenauer, 2001
@ -21,275 +19,81 @@
Contact: Marc.Schoenauer@polytechnique.fr
*/
//-----------------------------------------------------------------------------
#ifndef NO_GNUPLOT
#ifndef _eoGnuplot_H
#define _eoGnuplot_H
#ifndef EO_eoGnuplot_H
#define EO_eoGnuplot_H
#include <string>
/**
@author Marc Schoenauer 2001
@version 0.0
#include "pipecom.h"
This class is the abstract class that will be used by further gnuplot calls
to plots what is already written by some eoMonitor into a file
/** Base class for calls to gnuplot
This class is the abstract class that will be used by further gnuplot
calls to plots what is already written by some eoMonitor into a file
@author Marc Schoenauer
@version 0.0 (2001)
*/
//-----------------------------------------------------------------------------
#include <fstream>
#include <utils/pipecom.h>
/** eoGnuplot: base class that will be used to call gnuplot
*/
class eoGnuplot
{
public:
// Ctor
eoGnuplot(std::string _title, std::string _extra = std::string("")) :
firstTime(true)
{
// opens pipe with Gnuplot
initGnuPlot(_title, _extra);
}
public:
// Dtor
virtual ~eoGnuplot() {
// close - the gnuplot windows if pipe was correctly opened
if( gpCom ) {
PipeComSend( gpCom, "quit\n" ); // Ferme gnuplot
PipeComClose( gpCom );
gpCom =NULL;
}
}
/** Open pipe to Gnuplot.
/// Class name.
virtual std::string className() const { return "eoGnuplot"; }
@param _title Title for gnuplot window.
@param _extra Extra parameters to gnuplot.
*/
eoGnuplot(std::string _title, std::string _extra = std::string(""));
/** send a command to gnuplot directly
*/
void gnuplotCommand(std::string _command)
{
if( gpCom ) {
PipeComSend( gpCom, _command.c_str() );
PipeComSend( gpCom, "\n" );
}
}
/** Destructor
/** send a command to gnuplot directly
*/
void gnuplotCommand(char * _command)
{
if( gpCom ) {
PipeComSend( gpCom, _command );
PipeComSend( gpCom, "\n" );
}
}
Close the gnuplot windows if pipe was correctly opened
*/
virtual ~eoGnuplot();
/** Class name */
virtual std::string className() const
{ return "eoGnuplot"; }
/** Send command to gnuplot */
void gnuplotCommand(const char * _command);
/** Send command to gnuplot
@overload
*/
void gnuplotCommand(std::string _command)
{ gnuplotCommand(_command.c_str()); }
protected:
void initGnuPlot(std::string _title, std::string _extra);
// the private data
bool firstTime; // the stats might be unknown in Ctor
PCom *gpCom; // Communication with gnuplot OK
private:
/** Initialize gnuplot
@param _title Title for gnuplot window.
@param _extra Extra parameters to gnuplot.
*/
void initGnuPlot(std::string _title, std::string _extra);
/** The stats might be unknown in Ctor */
bool firstTime;
/** Communication with gnuplot OK */
PCom *gpCom;
/** Internal counter for gnuplot windows */
static unsigned numWindow;
};
// the following should be placed in a separate eoGnuplot.cpp
static unsigned numWindow=0;
////////////////////////////////////////////////////////////
inline void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
/////////////////////////////////////////////////////////
{
std::ostringstream os;
os << "250x150-0+" << numWindow*170;
numWindow++;
char *args[6];
args[0] = strdup( "gnuplot" );
args[1] = strdup( "-geometry" );
args[2] = strdup( os.str().c_str());
args[3] = strdup( "-title" );
args[4] = strdup( _title.c_str() );
args[5] = 0;
gpCom = PipeComOpenArgv( "gnuplot", args );
if( ! gpCom )
throw std::runtime_error("Impossible to spawn gnuplot\n");
else {
PipeComSend( gpCom, "set grid\n" );
PipeComSend( gpCom, _extra.c_str() );
PipeComSend( gpCom, "\n" );
}
}
// 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
// or some #idef instructions put with clear message at compile time
// that this is for Unix only ???
/* ----------------------------------------------------------------------
* 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.13 2005-09-28 21:49:26 kuepper Exp $
* ----------------------------------------------------------------------
*/
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
// #include "pipecom.h"
inline int Check( PCom *com )
{
if( ! com ) {
fprintf( stderr, "PipeCom: Null pointer.\n" );
fflush( stderr );
return 0;
}
if( kill( com->pid, 0 ) != 0 ) {
fprintf( stderr, "PipeCom: process doesn't exists.\n" );
fflush( stderr );
return 0;
}
return 1;
}
inline PCom * PipeComOpen( char *prog )
{
char *args[2];
args[0] = prog;
args[1] = NULL;
return PipeComOpenArgv( prog, args );
}
inline PCom * PipeComOpenArgv( char *prog, char *argv[] )
{
int toFils[2];
int toPere[2];
int sonPid;
PCom * ret = NULL;
if( pipe( toFils ) < 0 ) {
perror( "PipeComOpen: Creating pipes" );
return ret;
}
if( pipe( toPere ) < 0 ) {
perror( "PipeComOpen: Creating pipes" );
return ret;
}
switch( (sonPid = vfork()) ) {
case -1:
perror("PipeComOpen: fork failed" );
return ret;
break;
case 0:
/* --- Here's the son --- */
/* --- replace old stdin --- */
if( dup2( toFils[0], fileno(stdin) ) < 0 ) {
perror( "PipeComOpen(son): could not connect" );
exit( -1 );
/* --- AVOIR: kill my father --- */
}
if( dup2( toPere[1], fileno(stdout) ) < 0 ) {
perror( "PipeComOpen(son): could not connect" );
exit( -1 );
}
if( execvp( prog, argv ) < 0 ) {
perror( prog );
perror( "PipeComOpen: can't exec" );
exit(1);
}
break;
default:
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;
}
return ret;
}
inline int PipeComSend( PCom *to, const char *line )
{
int nb = 0;
if( ! Check(to ) )
return nb;
nb = fprintf( to->fWrit, line );
fflush( to->fWrit );
return nb;
}
inline int PipeComSendn( PCom *to, const char *data, int n )
{
int nb = 0;
if( ! Check(to) )
return nb;
nb = fwrite( data, 1, n, to->fWrit );
fflush( to->fWrit );
return nb;
}
inline int PipeComReceive( PCom *from, char *data, int max )
{
if( ! Check(from) )
return 0;
if( ! data ) {
fprintf( stderr, "PipeComReceive: Invalid data pointer\n" );
fflush( stderr );
return 0;
}
if( fgets( data, max, from->fRead ) )
return strlen(data);
return 0;
}
#endif // EO_eoGnuplot_H
inline int PipeComClose( PCom *to )
{
if( ! Check(to) )
return 0;
fclose( to->fRead );
fclose( to->fWrit );
free( to );
return 1;
}
inline int PipeComWaitFor( PCom *from, char *what )
{
char buffer[256];
do {
if( ! PipeComReceive( from, buffer, 256 ) )
return 0;
} while( strcmp( buffer, what ) );
return 1;
}
#endif
#endif
// Local Variables:
// c-file-style: "Stroustrup"
// comment-column: 35
// fill-column: 80
// mode: C++
// End:

View file

@ -0,0 +1,82 @@
//-----------------------------------------------------------------------------
// eoGnuplot1DMonitor.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
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
Marc.Schoenauer@polytechnique.fr
mkeijzer@dhi.dk
*/
//-----------------------------------------------------------------------------
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <sstream>
#include "eoGnuplot1DMonitor.h"
#include "eoParam.h"
eoMonitor& eoGnuplot1DMonitor::operator() (void)
{
// update file using the eoFileMonitor
eoFileMonitor::operator()();
// sends plot order to gnuplot
// assumes successive plots will have same nb of columns!!!
if (firstTime)
{
FirstPlot();
firstTime = false;
}
else
{
if( gpCom ) {
PipeComSend( gpCom, "replot\n" );
}
}
return *this;
}
void eoGnuplot1DMonitor::FirstPlot()
{
if (vec.size() < 2)
{
throw std::runtime_error("Must have some stats to plot!\n");
}
std::ostringstream os;
os << "plot";
for (unsigned i=1; i<vec.size(); i++) {
os << " '" << getFileName().c_str() <<
"' using 1:" << i+1 << " title '" << (vec[i])->longName() << "' with lines" ;
if (i<vec.size()-1)
os << ", ";
}
os << '\n';
PipeComSend( gpCom, os.str().c_str());
}
// Local Variables:
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -23,100 +23,51 @@
mkeijzer@dhi.dk
*/
//-----------------------------------------------------------------------------
#ifndef NO_GNUPLOT
#ifndef _eoGnuplot1DMonitor_H
#define _eoGnuplot1DMonitor_H
#ifndef EO_eoGnuplot1DMonitor_H
#define EO_eoGnuplot1DMonitor_H
#include <fstream>
#include <string>
#include <utils/eoMonitor.h>
#include <utils/eoGnuplot.h>
#include <eoObject.h>
#include "eoObject.h"
#include "utils/eoFileMonitor.h"
#include "utils/eoGnuplot.h"
#include "utils/pipecom.h"
/**
@author Marc Schoenauer 2000
@version 0.0
/** Plot eoStat
@author Marc Schoenauer
@version 0.0 (2000)
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, and replots it
everytime
*/
//-----------------------------------------------------------------------------
#include <fstream>
#include <utils/pipecom.h>
/** eoGnuplot1DMonitor plots stats through gnuplot
* assumes that the same file is appened every so and so,
* and replots it everytime
*/
class eoGnuplot1DMonitor: public eoFileMonitor, public eoGnuplot
class eoGnuplot1DMonitor : public eoFileMonitor, public eoGnuplot
{
public:
// Ctor
eoGnuplot1DMonitor(std::string _filename, bool _top=false) :
eoFileMonitor(_filename, " "),
eoGnuplot(_filename,(_top?"":"set key bottom"))
{}
public:
using eoMonitor::vec;
// Dtor
virtual ~eoGnuplot1DMonitor(){}
/** Constructor */
eoGnuplot1DMonitor(std::string _filename, bool _top=false) :
eoFileMonitor(_filename, " "),
eoGnuplot(_filename,(_top?"":"set key bottom"))
{}
virtual eoMonitor& operator() (void) ;
virtual void FirstPlot();
/** Destructor */
virtual ~eoGnuplot1DMonitor(){}
/// Class name.
virtual std::string className() const { return "eoGnuplot1DMonitor"; }
virtual eoMonitor& operator()();
private:
virtual void FirstPlot();
/** Class name */
virtual std::string className() const
{ return "eoGnuplot1DMonitor"; }
};
// the following should be placed in a separate eoGnuplot1DMonitor.cpp
// then the inline specifier should dissappear
////////////////////////////////////////////////////////////
inline eoMonitor& eoGnuplot1DMonitor::operator() (void)
/////////////////////////////////////////////////////////
{
// update file using the eoFileMonitor
eoFileMonitor::operator()();
// sends plot order to gnuplot
// assumes successive plots will have same nb of columns!!!
if (firstTime)
{
FirstPlot();
firstTime = false;
}
else
{
if( gpCom ) {
PipeComSend( gpCom, "replot\n" );
}
}
return *this;
}
////////////////////////////////////////////////////////////
inline void eoGnuplot1DMonitor::FirstPlot()
////////////////////////////////////////////////////////
{
if (vec.size() < 2)
{
throw std::runtime_error("Must have some stats to plot!\n");
}
std::ostringstream os;
os << "plot";
for (unsigned i=1; i<vec.size(); i++) {
os << " '" << getFileName().c_str() <<
"' using 1:" << i+1 << " title '" << vec[i]->longName() << "' with lines" ;
if (i<vec.size()-1)
os << ", ";
}
os << '\n';
PipeComSend( gpCom, os.str().c_str());
}
#endif
#endif

View file

@ -0,0 +1,30 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "eoGnuplot1DSnapshot.h"
inline eoMonitor& eoGnuplot1DSnapshot::operator() (void)
{
// update file using the eoFileMonitor method
eoFileSnapshot::operator()();
// sends plot order to gnuplot
//std::string buff; // need local memory
std::ostringstream os;
os << "set title 'Gen. " << getCounter() << "'; plot '"
// mk: had to use getFilename().c_str(), because it seems the string(stream) lib is screwed in gcc3.2
<< getFileName().c_str() << "' notitle with points ps " << pointSize;
os << std::endl;
PipeComSend( gpCom, os.str().c_str());
return (*this);
}
// Local Variables:
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -23,36 +23,30 @@
mkeijzer@dhi.dk
*/
//-----------------------------------------------------------------------------
#ifndef NO_GNUPLOT
#ifndef _eoGnuplot1DSnapshot_H
#define _eoGnuplot1DSnapshot_H
#ifndef EO_eoGnuplot1DSnapshot_H
#define EO_eoGnuplot1DSnapshot_H
#include <fstream>
#include <sstream>
#include <string>
#include <eoObject.h>
#include "eoRealVectorBounds.h"
#include <utils/pipecom.h>
#include <utils/eoFileSnapshot.h>
#include <utils/eoGnuplot.h>
#include <eoObject.h>
/**
/** Plot stats through gnuplot
@author Marc Schoenauer 2000
@version 0.0
This class plots through gnuplot the eoStat given as argument
*/
//-----------------------------------------------------------------------------
#include <fstream>
#include "eoRealVectorBounds.h"
#include <utils/pipecom.h>
/** eoGnuplot1DSnapshot plots stats through gnuplot
* assumes that the same file is re-written every so and so,
* and plots it from scratch everytime it's called
Assumes that the same file is re-written every so and so, and plots it
from scratch everytime it's called
*/
class eoGnuplot1DSnapshot: public eoFileSnapshot, public eoGnuplot
{
@ -118,25 +112,5 @@ private:
};
// the following should be placed in a separate eoGnuplot1DMonitor.cpp
////////////////////////////////////////////////////////////
inline eoMonitor& eoGnuplot1DSnapshot::operator() (void)
/////////////////////////////////////////////////////////
{
// update file using the eoFileMonitor method
eoFileSnapshot::operator()();
// sends plot order to gnuplot
//std::string buff; // need local memory
std::ostringstream os;
os << "set title 'Gen. " << getCounter() << "'; plot '"
// mk: had to use getFilename().c_str(), because it seems the string(stream) lib is screwed in gcc3.2
<< getFileName().c_str() << "' notitle with points ps " << pointSize;
os << std::endl;
PipeComSend( gpCom, os.str().c_str());
return (*this);
}
#endif
#endif

173
eo/src/utils/pipecom.cpp Normal file
View file

@ -0,0 +1,173 @@
/* ----------------------------------------------------------------------
* 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
* ----------------------------------------------------------------------
*/
// MSC equivalent must be written and tested or some #idef instructions added
// with a clear message at compile time that this is for Unix only ???
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <cstdlib>
#include <cstring>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include "pipecom.h"
int Check( PCom *com )
{
if( ! com ) {
fprintf( stderr, "PipeCom: Null pointer.\n" );
fflush( stderr );
return 0;
}
if( kill( com->pid, 0 ) != 0 ) {
fprintf( stderr, "PipeCom: process doesn't exists.\n" );
fflush( stderr );
return 0;
}
return 1;
}
PCom * PipeComOpen( char *prog )
{
char *args[2];
args[0] = prog;
args[1] = NULL;
return PipeComOpenArgv( prog, args );
}
PCom * PipeComOpenArgv( char *prog, char *argv[] )
{
int toFils[2];
int toPere[2];
int sonPid;
PCom * ret = NULL;
if( pipe( toFils ) < 0 ) {
perror( "PipeComOpen: Creating pipes" );
return ret;
}
if( pipe( toPere ) < 0 ) {
perror( "PipeComOpen: Creating pipes" );
return ret;
}
switch( (sonPid = vfork()) ) {
case -1:
perror("PipeComOpen: fork failed" );
return ret;
break;
case 0:
/* --- Here's the son --- */
/* --- replace old stdin --- */
if( dup2( toFils[0], fileno(stdin) ) < 0 ) {
perror( "PipeComOpen(son): could not connect" );
exit( -1 );
/* --- AVOIR: kill my father --- */
}
if( dup2( toPere[1], fileno(stdout) ) < 0 ) {
perror( "PipeComOpen(son): could not connect" );
exit( -1 );
}
if( execvp( prog, argv ) < 0 ) {
perror( prog );
perror( "PipeComOpen: can't exec" );
exit(1);
}
break;
default:
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;
}
return ret;
}
int PipeComSend( PCom *to, const char *line )
{
int nb = 0;
if( ! Check(to ) )
return nb;
nb = fprintf( to->fWrit, line );
fflush( to->fWrit );
return nb;
}
int PipeComSendn( PCom *to, const char *data, int n )
{
int nb = 0;
if( ! Check(to) )
return nb;
nb = fwrite( data, 1, n, to->fWrit );
fflush( to->fWrit );
return nb;
}
int PipeComReceive( PCom *from, char *data, int max )
{
if( ! Check(from) )
return 0;
if( ! data ) {
fprintf( stderr, "PipeComReceive: Invalid data pointer\n" );
fflush( stderr );
return 0;
}
if( fgets( data, max, from->fRead ) )
return strlen(data);
return 0;
}
int PipeComClose( PCom *to )
{
if( ! Check(to) )
return 0;
fclose( to->fRead );
fclose( to->fWrit );
free( to );
return 1;
}
int PipeComWaitFor( PCom *from, char *what )
{
char buffer[256];
do {
if( ! PipeComReceive( from, buffer, 256 ) )
return 0;
} while( strcmp( buffer, what ) );
return 1;
}
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -1,48 +1,47 @@
/* ----------------------------------------------------------------------
* Where........: CMAP - Polytechnique
* Where........: CMAP - Polytechnique
* File.........: pipecom.h
* Author.......: Bertrand Lamy (EEAAX)
* Created......: Thu Mar 9 17:21:15 1995
* Description..: Pipe communication with a process
*
* Ident........: $Id: pipecom.h,v 1.3 2001-10-08 09:13:16 evomarc Exp $
* ----------------------------------------------------------------------
*/
#ifndef PIPECOM_H
#define PIPECOM_H
// This file cannot be used from C any more due to some const additions.
// However, if you remove the const, it should work in C as well.
// this file cannot be used from C or C++ any more due to some const additions
// however, if you remove the const, it should work in C also
#ifdef __cplusplus
extern "C" {
#endif
#ifndef EO_PIPECOM_H
#define EO_PIPECOM_H
#include <stdio.h>
typedef struct PipeCommunication {
typedef struct PipeCommunication {
FILE *fWrit;
FILE *fRead;
int pid;
} PCom;
PCom *PipeComOpen( char *prog );
PCom *PipeComOpenArgv( char *prog, char *argv[] );
extern PCom *PipeComOpen( char *prog );
extern PCom *PipeComOpenArgv( char *prog, char *argv[] );
int PipeComSend( PCom *to, const char *line );
int PipeComSendn( PCom *to, const char *data, int n );
extern int PipeComSend( PCom *to, const char *line );
extern int PipeComSendn( PCom *to, const char *data, int n );
int PipeComReceive( PCom *from, char *data, int max );
extern int PipeComReceive( PCom *from, char *data, int max );
int PipeComClose( PCom *to );
extern int PipeComClose( PCom *to );
extern int PipeComWaitFor( PCom *from, char *what );
int PipeComWaitFor( PCom *from, char *what );
#ifdef __cplusplus
} /* ferme extern "C" */
#endif
#endif // EO_PIPECOM_H
#endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -17,7 +17,7 @@ extra_DIST = Makefile.simple
LDADD = -L$(top_builddir)/src -L$(top_builddir)/src/ga -L$(top_builddir)/src/utils
LIBS = -lga -leoutils -leo
LIBS = -lga -leo -leoutils
INCLUDES = -I$(top_srcdir)/src

View file

@ -17,6 +17,6 @@ extra_DIST = Makefile.simple
LDADD = -L$(top_builddir)/src -L$(top_builddir)/src/ga -L$(top_builddir)/src/utils
LIBS = -lga -leoutils -leo
LIBS = -lga -leo -leoutils
INCLUDES = -I$(top_srcdir)/src