New style for MOEO
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@788 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
7161febf9c
commit
39709d3d12
103 changed files with 2607 additions and 2521 deletions
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoArchiveObjectiveVectorSavingUpdater.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -51,8 +51,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoArchiveObjectiveVectorSavingUpdater : public eoUpdater
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
|
|
@ -62,46 +62,47 @@ public:
|
|||
* @param _id own ID
|
||||
*/
|
||||
moeoArchiveObjectiveVectorSavingUpdater (moeoArchive<MOEOT> & _arch, const std::string & _filename, bool _count = false, int _id = -1) :
|
||||
arch(_arch), filename(_filename), count(_count), counter(0), id(_id)
|
||||
arch(_arch), filename(_filename), count(_count), counter(0), id(_id)
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* Saves the fitness of the archive's members into the file
|
||||
*/
|
||||
void operator()() {
|
||||
char buff[MAX_BUFFER_SIZE];
|
||||
if (count)
|
||||
void operator()()
|
||||
{
|
||||
char buff[MAX_BUFFER_SIZE];
|
||||
if (count)
|
||||
{
|
||||
if (id == -1)
|
||||
if (id == -1)
|
||||
{
|
||||
sprintf (buff, "%s.%u", filename.c_str(), counter ++);
|
||||
sprintf (buff, "%s.%u", filename.c_str(), counter ++);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
sprintf (buff, "%s.%u.%u", filename.c_str(), id, counter ++);
|
||||
sprintf (buff, "%s.%u.%u", filename.c_str(), id, counter ++);
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
if (id == -1)
|
||||
if (id == -1)
|
||||
{
|
||||
sprintf (buff, "%s", filename.c_str());
|
||||
sprintf (buff, "%s", filename.c_str());
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
sprintf (buff, "%s.%u", filename.c_str(), id);
|
||||
sprintf (buff, "%s.%u", filename.c_str(), id);
|
||||
}
|
||||
counter ++;
|
||||
counter ++;
|
||||
}
|
||||
std::ofstream f(buff);
|
||||
for (unsigned int i = 0; i < arch.size (); i++)
|
||||
f << arch[i].objectiveVector() << std::endl;
|
||||
f.close ();
|
||||
std::ofstream f(buff);
|
||||
for (unsigned int i = 0; i < arch.size (); i++)
|
||||
f << arch[i].objectiveVector() << std::endl;
|
||||
f.close ();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** local archive */
|
||||
moeoArchive<MOEOT> & arch;
|
||||
|
|
@ -114,6 +115,6 @@ private:
|
|||
/** own ID */
|
||||
int id;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOARCHIVEOBJECTIVEVECTORSAVINGUPDATER_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoArchiveUpdater.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -47,8 +47,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoArchiveUpdater : public eoUpdater
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
|
|
@ -62,18 +62,19 @@ public:
|
|||
/**
|
||||
* Updates the archive with newly found non-dominated solutions contained in the main population
|
||||
*/
|
||||
void operator()() {
|
||||
arch.update(pop);
|
||||
void operator()()
|
||||
{
|
||||
arch.update(pop);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** the archive of non-dominated solutions */
|
||||
moeoArchive < MOEOT > & arch;
|
||||
/** the main population */
|
||||
const eoPop < MOEOT > & pop;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOARCHIVEUPDATER_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoBinaryMetricSavingUpdater.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -51,8 +51,8 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoBinaryMetricSavingUpdater : public eoUpdater
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/** The objective vector type of a solution */
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -65,37 +65,41 @@ public:
|
|||
* @param _filename the target filename
|
||||
*/
|
||||
moeoBinaryMetricSavingUpdater (moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > & _metric, const eoPop < MOEOT > & _pop, std::string _filename) :
|
||||
metric(_metric), pop(_pop), filename(_filename), counter(1)
|
||||
metric(_metric), pop(_pop), filename(_filename), counter(1)
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* Saves the metric's value for the current generation
|
||||
*/
|
||||
void operator()() {
|
||||
if (pop.size()) {
|
||||
if (firstGen) {
|
||||
firstGen = false;
|
||||
void operator()()
|
||||
{
|
||||
if (pop.size())
|
||||
{
|
||||
if (firstGen)
|
||||
{
|
||||
firstGen = false;
|
||||
}
|
||||
else {
|
||||
// creation of the two Pareto sets
|
||||
std::vector < ObjectiveVector > from;
|
||||
std::vector < ObjectiveVector > to;
|
||||
for (unsigned int i=0; i<pop.size(); i++)
|
||||
from.push_back(pop[i].objectiveVector());
|
||||
for (unsigned int i=0 ; i<oldPop.size(); i++)
|
||||
to.push_back(oldPop[i].objectiveVector());
|
||||
// writing the result into the file
|
||||
std::ofstream f (filename.c_str(), std::ios::app);
|
||||
f << counter++ << ' ' << metric(from,to) << std::endl;
|
||||
f.close();
|
||||
else
|
||||
{
|
||||
// creation of the two Pareto sets
|
||||
std::vector < ObjectiveVector > from;
|
||||
std::vector < ObjectiveVector > to;
|
||||
for (unsigned int i=0; i<pop.size(); i++)
|
||||
from.push_back(pop[i].objectiveVector());
|
||||
for (unsigned int i=0 ; i<oldPop.size(); i++)
|
||||
to.push_back(oldPop[i].objectiveVector());
|
||||
// writing the result into the file
|
||||
std::ofstream f (filename.c_str(), std::ios::app);
|
||||
f << counter++ << ' ' << metric(from,to) << std::endl;
|
||||
f.close();
|
||||
}
|
||||
oldPop = pop;
|
||||
oldPop = pop;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/** binary metric comparing two Pareto sets */
|
||||
moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > & metric;
|
||||
|
|
@ -110,6 +114,6 @@ private:
|
|||
/** counter */
|
||||
unsigned int counter;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOBINARYMETRICSAVINGUPDATER_H_*/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <moeoConvertPopToObjectiveVectors.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -46,8 +46,8 @@
|
|||
*/
|
||||
template < class MOEOT, class ObjectiveVector = typename MOEOT::ObjectiveVector >
|
||||
class moeoConvertPopToObjectiveVectors : public eoUF < const eoPop < MOEOT >, const std::vector < ObjectiveVector > >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Returns a vector of the objective vectors from the population _pop
|
||||
|
|
@ -55,15 +55,15 @@ public:
|
|||
*/
|
||||
const std::vector < ObjectiveVector > operator()(const eoPop < MOEOT > _pop)
|
||||
{
|
||||
std::vector < ObjectiveVector > result;
|
||||
result.resize(_pop.size());
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
std::vector < ObjectiveVector > result;
|
||||
result.resize(_pop.size());
|
||||
for (unsigned int i=0; i<_pop.size(); i++)
|
||||
{
|
||||
result.push_back(_pop[i].objectiveVector());
|
||||
result.push_back(_pop[i].objectiveVector());
|
||||
}
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*MOEOPOPTOOBJECTIVEVECTORS_H_*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue