Multistart: added possibility to reinit population on each MultiStartJob, or use the same pop.
This commit is contained in:
parent
355541ae88
commit
74bdb0fa91
1 changed files with 20 additions and 7 deletions
|
|
@ -113,10 +113,10 @@ struct SerializableBasicType : public eoserial::Persistent
|
||||||
template< class EOT, class FitT >
|
template< class EOT, class FitT >
|
||||||
struct MultiStartData
|
struct MultiStartData
|
||||||
{
|
{
|
||||||
MultiStartData( mpi::communicator& _comm, eoAlgo<EOT>& _algo, const eoPop< EOT >& _originalPop, int _masterRank )
|
MultiStartData( mpi::communicator& _comm, eoAlgo<EOT>& _algo, int _masterRank, eoInit<EOT>* _init = 0 )
|
||||||
:
|
:
|
||||||
runs( 0 ), firstIndividual( true ), bestFitness(), pop(),
|
runs( 0 ), firstIndividual( true ), bestFitness(), pop(),
|
||||||
comm( _comm ), algo( _algo ), originalPop( _originalPop ), masterRank( _masterRank )
|
comm( _comm ), algo( _algo ), masterRank( _masterRank ), init( _init )
|
||||||
{
|
{
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
@ -131,7 +131,7 @@ struct MultiStartData
|
||||||
// static parameters
|
// static parameters
|
||||||
mpi::communicator& comm;
|
mpi::communicator& comm;
|
||||||
eoAlgo<EOT>& algo;
|
eoAlgo<EOT>& algo;
|
||||||
const eoPop< EOT >& originalPop;
|
eoInit<EOT>* init;
|
||||||
int masterRank;
|
int masterRank;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -205,8 +205,10 @@ class MultiStartStore : public JobStore< MultiStartData< EOT, FitT > >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MultiStartStore( eoAlgo<EOT> & algo, const eoPop< EOT >& pop, int masterRank )
|
MultiStartStore( eoAlgo<EOT> & algo, int masterRank, const eoPop< EOT > & pop, eoInit<EOT>* init = 0 )
|
||||||
: _data( Node::comm(), algo, pop, masterRank )
|
: _data( Node::comm(), algo, masterRank, init ),
|
||||||
|
_pop( pop ),
|
||||||
|
_firstPopInit( true )
|
||||||
{
|
{
|
||||||
this->_iff = new IsFinishedMultiStart< EOT, FitT >;
|
this->_iff = new IsFinishedMultiStart< EOT, FitT >;
|
||||||
this->_iff->needDelete(true);
|
this->_iff->needDelete(true);
|
||||||
|
|
@ -221,7 +223,16 @@ class MultiStartStore : public JobStore< MultiStartData< EOT, FitT > >
|
||||||
void init( int runs )
|
void init( int runs )
|
||||||
{
|
{
|
||||||
_data.runs = runs;
|
_data.runs = runs;
|
||||||
_data.pop = _data.originalPop; // FIXME ?
|
|
||||||
|
if( _data.init )
|
||||||
|
{
|
||||||
|
_data.pop = eoPop<EOT>( _pop.size(), *_data.init );
|
||||||
|
} else if( _firstPopInit )
|
||||||
|
{
|
||||||
|
_data.pop = _pop;
|
||||||
|
}
|
||||||
|
_firstPopInit = false;
|
||||||
|
|
||||||
_data.firstIndividual = true;
|
_data.firstIndividual = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -232,6 +243,8 @@ class MultiStartStore : public JobStore< MultiStartData< EOT, FitT > >
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MultiStartData< EOT, FitT > _data;
|
MultiStartData< EOT, FitT > _data;
|
||||||
|
const eoPop< EOT >& _pop;
|
||||||
|
bool _firstPopInit;
|
||||||
};
|
};
|
||||||
|
|
||||||
template< class EOT, class FitT >
|
template< class EOT, class FitT >
|
||||||
|
|
@ -347,7 +360,7 @@ int main(int argc, char **argv)
|
||||||
// eoEasyPSO<Particle> pso2(init,genCont2, eval, velocity, flight);
|
// eoEasyPSO<Particle> pso2(init,genCont2, eval, velocity, flight);
|
||||||
|
|
||||||
DynamicAssignmentAlgorithm assignmentAlgo;
|
DynamicAssignmentAlgorithm assignmentAlgo;
|
||||||
MultiStartStore< Particle, ParticleFitness > store( pso1, pop, DEFAULT_MASTER );
|
MultiStartStore< Particle, ParticleFitness > store( pso1, DEFAULT_MASTER, pop );
|
||||||
|
|
||||||
MultiStart< Particle, ParticleFitness > msjob( assignmentAlgo, DEFAULT_MASTER, store, 5 );
|
MultiStart< Particle, ParticleFitness > msjob( assignmentAlgo, DEFAULT_MASTER, store, 5 );
|
||||||
msjob.run();
|
msjob.run();
|
||||||
|
|
|
||||||
Reference in a new issue