git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@36 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
d9acd984f9
commit
c7d3cc755c
154 changed files with 13175 additions and 0 deletions
73
trunk/paradiseo-moeo/src/moeoArchiveFitnessSavingUpdater.h
Normal file
73
trunk/paradiseo-moeo/src/moeoArchiveFitnessSavingUpdater.h
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// moeoArchiveFitnessSavingUpdater.h
|
||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
||||
/*
|
||||
This library...
|
||||
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEOARCHIVEFITNESSSAVINGUPDATER_H_
|
||||
#define MOEOARCHIVEFITNESSSAVINGUPDATER_H_
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <eoPop.h>
|
||||
#include <utils/eoUpdater.h>
|
||||
#include <moeoArchive.h>
|
||||
|
||||
#define MAX_BUFFER_SIZE 1000
|
||||
|
||||
/**
|
||||
* This class allows to save the fitnesses of solutions contained in an archive into a file at each generation.
|
||||
*/
|
||||
template < class EOT > class moeoArchiveFitnessSavingUpdater:public eoUpdater
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
* @param _arch local archive
|
||||
* @param _filename target filename
|
||||
* @param _id own ID
|
||||
*/
|
||||
moeoArchiveFitnessSavingUpdater (moeoArchive < EOT > &_arch, const std::string & _filename = "Res/Arch", int _id = -1):arch (_arch), filename (_filename), id (_id),
|
||||
counter
|
||||
(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the fitness of the archive's members into the file
|
||||
*/
|
||||
void operator () ()
|
||||
{
|
||||
char buff[MAX_BUFFER_SIZE];
|
||||
if (id == -1)
|
||||
sprintf (buff, "%s.%u", filename.c_str (), counter++);
|
||||
else
|
||||
sprintf (buff, "%s.%u.%u", filename.c_str (), id, counter++);
|
||||
std::ofstream f (buff);
|
||||
for (unsigned i = 0; i < arch.size (); i++)
|
||||
f << arch[i].fitness () << std::endl;
|
||||
f.close ();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/** local archive */
|
||||
moeoArchive < EOT > &arch;
|
||||
/** target filename */
|
||||
std::string filename;
|
||||
/** own ID */
|
||||
int id;
|
||||
/** counter */
|
||||
unsigned counter;
|
||||
|
||||
};
|
||||
|
||||
#endif /*MOEOARCHIVEFITNESSSAVINGUPDATER_H_ */
|
||||
Loading…
Add table
Add a link
Reference in a new issue