Added bounds to FitnessStat and Gnuplot monitor

This commit is contained in:
evomarc 2002-08-23 15:41:00 +00:00
commit 18cd20da78
3 changed files with 60 additions and 6 deletions

View file

@ -77,6 +77,16 @@ class eoGnuplot
}
}
/** send a command to gnuplot directly
*/
void gnuplotCommand(char * _command)
{
if( gpCom ) {
PipeComSend( gpCom, _command );
PipeComSend( gpCom, "\n" );
}
}
protected:
void initGnuPlot(std::string _title, std::string _extra);
@ -129,7 +139,7 @@ inline void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
* Created......: Mon Mar 13 13:50:11 1995
* Description..: Communication par pipe bidirectionnel avec un autre process
*
* Ident........: $Id: eoGnuplot.h,v 1.4 2001-09-08 05:59:17 evomarc Exp $
* Ident........: $Id: eoGnuplot.h,v 1.5 2002-08-23 15:40:59 evomarc Exp $
* ----------------------------------------------------------------------
*/

View file

@ -28,6 +28,7 @@
#define _eoGnuplot1DSnapshot_H
#include <string>
#include <sstream>
#include <utils/eoFileSnapshot.h>
#include <utils/eoGnuplot.h>
@ -43,6 +44,7 @@ This class plots through gnuplot the eoStat given as argument
//-----------------------------------------------------------------------------
#include <fstream>
#include "eoRealVectorBounds.h"
#include <utils/pipecom.h>
@ -62,6 +64,16 @@ class eoGnuplot1DSnapshot: public eoFileSnapshot, public eoGnuplot
pointSize(5)
{}
// Ctor
eoGnuplot1DSnapshot(std::string _dirname, eoRealVectorBounds & _bounds,
unsigned _frequency = 1,
std::string _filename = "gen", std::string _delim = " ") :
eoFileSnapshot(_dirname, _frequency, _filename, _delim),
eoGnuplot(_filename,"set data style points"),
pointSize(5)
{
handleBounds(_bounds);
}
// Ctor
eoGnuplot1DSnapshot(eoFileSnapshot & _fSnapshot) :
eoFileSnapshot(_fSnapshot),
@ -69,6 +81,15 @@ class eoGnuplot1DSnapshot: public eoFileSnapshot, public eoGnuplot
pointSize(5)
{}
// Ctor with range
eoGnuplot1DSnapshot(eoFileSnapshot & _fSnapshot, eoRealVectorBounds & _bounds) :
eoFileSnapshot(_fSnapshot),
eoGnuplot(_fSnapshot.baseFileName(),"set data style points"),
pointSize(5)
{
handleBounds(_bounds);
}
// Dtor
virtual ~eoGnuplot1DSnapshot(){}
@ -77,6 +98,19 @@ class eoGnuplot1DSnapshot: public eoFileSnapshot, public eoGnuplot
/// Class name.
virtual string className() const { return "eoGnuplot1DSnapshot"; }
virtual void handleBounds(eoRealVectorBounds & _bounds)
{
ostringstream os;
os << "set autoscale\nset yrange [" ;
if (_bounds.isMinBounded(0))
os << _bounds.minimum(0);
os << ":" ;
if (_bounds.isMaxBounded(0))
os << _bounds.maximum(0);
os << "]\n";
gnuplotCommand(os.str());
}
unsigned pointSize;
private:

View file

@ -27,6 +27,7 @@
#ifndef _eoScalarFitnessStat_h
#define _eoScalarFitnessStat_h
#include <utils/eoRealVectorBounds.h>
#include <utils/eoStat.h>
/**
@ -36,15 +37,24 @@ template <class EOT, class FitT = typename EOT::Fitness>
class eoScalarFitnessStat : public eoSortedStat<EOT, vector<double> >
{
public :
eoScalarFitnessStat(std::string _description = "FitnessES") :
eoSortedStat<EOT, vector<double> >(vector<double>(0), _description) {}
virtual void operator()(const vector<const EOT*>& _popPters)
eoScalarFitnessStat(std::string _description = "FitnessES",
eoRealVectorBounds & _bounds = eoDummyVectorNoBounds) :
eoSortedStat<EOT, vector<double> >(vector<double>(0), _description) ,
range(*_bounds[0])
{}
virtual void operator()(const vector<const EOT*>& _popPters)
{
value().resize(_popPters.size());
for (unsigned i=0; i<_popPters.size(); i++)
value()[i] = _popPters[i]->fitness();
{
value()[i] = _popPters[i]->fitness();
range.truncate(value()[i]);
}
}
private :
eoRealBounds & range;
};
#endif