Structural deformable models
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
Searcher Class Reference

#include <Searcher.h>

Collaboration diagram for Searcher:
Collaboration graph
[legend]

Public Member Functions

 Searcher ()
 
 Searcher (const Searcher &rhs)
 
 ~Searcher ()
 
Searcheroperator= (const Searcher &rhs)
 
bool step (float dt)
 
void evolve ()
 
void startSearch (bool dostart=true)
 
bool searchDone () const
 
template<class Iter >
unsigned int getWinners (Iter iter) const
 
std::map< dword, Winner > & getWinList ()
 
const std::map< dword, Winner > & getWinList () const
 
float getBestQOF () const
 
float getLeastQOF () const
 
float relativeQOF (float qof) const
 
const WinnergetWinner (dword id) const
 
void setExpectationMap (const ExpectationMap &em)
 
ExpectationMapgetExpectationMap ()
 
const ExpectationMapgetExpectationMap () const
 
void clear ()
 
void draw () const
 
bool triggerTest (int mx, int my, int what)
 
 operator bool () const
 
const ModelgetRepresentative () const
 
void reattachSensors ()
 
float getGeneration (const Model *model) const
 
void setShapeWeight (float shapeweight)
 
float getShapeWeight () const
 

Protected Types

enum  { MODE_PAUSE, MODE_RUN, MODE_DONE }
 

Protected Member Functions

std::map< dword, Winner > & updateWinList ()
 
int getBindex (int bx, int by, bool &culled=*((bool *) NULL)) const
 
int getBindex (const PropVec &prop, bool &culled=*((bool *) NULL)) const
 
int getBindex (const Model &model, bool &culled=*((bool *) NULL)) const
 
void getQualityRange (float &lqof, float &hqof, float shapeweight=-1) const
 
void findWinners ()
 
bool buildBins (float bindist=0.f)
 
int buildClusters ()
 
void selectWinners ()
 
void cleanFlags ()
 
std::list< Model * >::iterator & remove (std::list< Model * >::iterator &mi)
 
int add (Model *m)
 
Modelmutate (Model &model, float rate=1) const
 
int distribute (int n=-1, float qth=0, bool count=false)
 

Protected Attributes

Model m_Representative
 
PropVec m_AvgWinner
 
PropVec m_StdWinner
 
PropVec m_MinModel
 
PropVec m_MaxModel
 
ExpectationMap m_EMap
 
std::list< Model * > m_Population
 
int m_NPop
 
std::vector< MBin > m_Bins
 
int m_BinsX
 
int m_BinsY
 
float m_BinDist
 
std::list< MBin > m_Clusters
 
int m_NClusters
 
MBin * m_CurCluster
 
float m_Time
 
Point m_PosMax
 
Point m_PosMin
 
Point m_PosRange
 
enum Searcher:: { ... }  SMode
 
dword m_Mode
 
float m_EvolveT
 
float m_MutateRate
 
std::map< dword, Winnerm_Winners
 
dword m_NextWinID
 
float m_ShapeWeight
 

Detailed Description

Engine performing genetic search to determine a set of local winners.

Definition at line 16 of file Searcher.h.

Member Enumeration Documentation

anonymous enum
protected
Enumerator
MODE_PAUSE 
MODE_RUN 
MODE_DONE 

Definition at line 79 of file Searcher.h.

Constructor & Destructor Documentation

Searcher::Searcher ( )

Definition at line 76 of file Searcher.cpp.

References getSearchPara(), m_EvolveT, m_MutateRate, SearcherParams::m_MutateRate, m_ShapeWeight, and SearcherParams::m_ShapeWeight.

76  : m_NPop(0), m_Time(0), m_Mode(MODE_PAUSE),
79 {
80  m_EvolveT = 0.0f;
83 }
dword m_Mode
Definition: Searcher.h:80
float m_ShapeWeight
influence of shape deformation on QOF
Definition: Searcher.h:185
dword m_NextWinID
Definition: Searcher.h:84
float m_MutateRate
initial mutation rate
Definition: Searcher.h:173
float m_ShapeWeight
Definition: Searcher.h:85
float m_Time
Definition: Searcher.h:77
SearcherParams & getSearchPara()
Definition: Searcher.h:194
#define SRCH_SHAPEWEIGHT
Definition: Searcher.cpp:36
float m_EvolveT
Definition: Searcher.h:81
int m_NPop
Definition: Searcher.h:70
float m_MutateRate
Definition: Searcher.h:82
Searcher::Searcher ( const Searcher rhs)

Definition at line 85 of file Searcher.cpp.

References operator=().

86 {
87  operator=(rhs);
88 }
Searcher & operator=(const Searcher &rhs)
Definition: Searcher.cpp:95
Searcher::~Searcher ( )

Definition at line 90 of file Searcher.cpp.

References clear().

91 {
92  clear();
93 }
void clear()
Definition: Searcher.cpp:126

Member Function Documentation

int Searcher::add ( Model m)
protected

Definition at line 143 of file Searcher.cpp.

References Model::getFlags(), m_NPop, m_Population, m_Time, Model::m_TimeStamp, Model::setID(), Model::setInstCount(), and Winner::WID_EMPTY.

Referenced by distribute(), evolve(), and getShapeWeight().

143  {
144  m->m_TimeStamp = m_Time;
145  m->getFlags() = 0;
147  m->setInstCount(1);
148  m_Population.push_back(m);
149  return ++m_NPop;
150 }
void setID(dword id)
Definition: Model.h:84
float m_Time
Definition: Searcher.h:77
dword & getFlags()
Definition: Model.h:196
std::list< Model * > m_Population
Definition: Searcher.h:69
int m_NPop
Definition: Searcher.h:70
void setInstCount(dword ic)
Definition: Model.h:223
float m_TimeStamp
time stamps (see. TTimeStamp)
Definition: Model.h:259
bool Searcher::buildBins ( float  bindist = 0.f)
protected

Definition at line 361 of file Searcher.cpp.

References getBindex(), Model::getNNodes(), Model::getProperties(), getPropScale(), ExpectationMap::getRepresentative(), getSearchPara(), m_AvgWinner, m_BinDist, m_Bins, m_BinsX, m_BinsY, m_EMap, m_MaxModel, m_MinModel, m_Population, m_PosRange, SearcherParams::m_RelBinDist, m_Representative, m_ShapeWeight, m_StdWinner, MAXRAD, Model::ST_MEMBER, Point2D::sum(), Point2D::x, and Point2D::y.

Referenced by buildClusters(), and getShapeWeight().

362 {
363  if(m_EMap.getRepresentative().getNNodes() == 0) return false;
364  else if(m_Representative.getNNodes() == 0) {
367  m_StdWinner = 0.f;
369  }
370 //destroy bins
371  m_BinsX = m_BinsY = 0;
372  m_Bins.clear();
373 //initialize bins
374  float radius = getPropScale(m_MinModel);
375  //m_Representative.getStdRadius();
376  if(m_Population.empty() || m_PosRange.sum()==0 || radius<0.001)
377  return false;
378 
379  m_BinDist = bindist != 0.f ? bindist : radius*getSearchPara().m_RelBinDist;
380  m_BinsX = (int)(m_PosRange.x/m_BinDist)+1;
381  m_BinsY = (int)(m_PosRange.y/m_BinDist)+1;
382  m_Bins.resize(m_BinsX*m_BinsY);
383 // cout << m_PosRange << endl;
384 // TRACE("created " << m_BinsX << " in X and " << m_BinsY
385 // << " in Y direction.");
386 //fill bins
387  for(list<Model*>::iterator model = m_Population.begin();
388  model != m_Population.end(); model++)
389  {
390  (*model)->setOldState();
391  (*model)->unsetFlags(Model::ST_MEMBER);
392  (*model)->setShapeWeight(m_ShapeWeight);
393  Point c = (*model)->getCenter();
394  int bx = (int)(c.x/m_BinDist);
395  int by = (int)(c.y/m_BinDist);
396 #define MAXRAD 0
397 #if (MAXRAD>0)
398  for(int px=bx-MAXRAD; px<=bx+MAXRAD; px++) {
399  if(px>=0 && px<=m_BinsX) {
400  for(int py=by-MAXRAD; py<=by+MAXRAD; py++) {
401  bool culled;
402  int index = getBindex(px,py,culled);
403  if(!culled)
404  m_Bins[index].push_back(*model);
405  }
406  }
407  }
408 #else
409  bool culled;
410  int index = getBindex(bx,by,culled);
411  //if(!culled)
412  m_Bins[index].push_back(*model);
413 #endif
414 #undef MAXRAD
415  }
416  return true;
417 }
float m_RelBinDist
distance of bins relative to representative radius
Definition: Searcher.h:170
std::vector< MBin > m_Bins
Definition: Searcher.h:71
const PropVec & getProperties() const
Definition: Model.cpp:1263
PropVec m_MaxModel
Definition: Searcher.h:67
float y
Definition: Point.h:224
PropVec m_MinModel
Definition: Searcher.h:67
float m_BinDist
Definition: Searcher.h:73
float getPropScale(const PropVec &prop)
Definition: PropVec.h:19
Point m_PosRange
Definition: Searcher.h:78
int m_BinsX
Definition: Searcher.h:72
float m_ShapeWeight
Definition: Searcher.h:85
PropVec m_StdWinner
Definition: Searcher.h:66
int getNNodes() const
Definition: Model.h:77
float sum() const
returns 1-norm
Definition: Point.h:160
int getBindex(int bx, int by, bool &culled=*((bool *) NULL)) const
Definition: Searcher.h:104
SearcherParams & getSearchPara()
Definition: Searcher.h:194
std::list< Model * > m_Population
Definition: Searcher.h:69
Model m_Representative
Definition: Searcher.h:65
Model & getRepresentative()
Definition: ExpMap.h:156
ExpectationMap m_EMap
Definition: Searcher.h:68
int m_BinsY
Definition: Searcher.h:72
Definition: Point.h:16
PropVec m_AvgWinner
Definition: Searcher.h:66
float x
Definition: Point.h:224
#define MAXRAD
int Searcher::buildClusters ( )
protected

Definition at line 419 of file Searcher.cpp.

References buildBins(), Model::DIST_CPOINTS, getBindex(), Model::getDataScale(), getPropDir(), getPropPos(), getPropScale(), getSearchPara(), m_BinDist, m_Bins, m_BinsX, SearcherParams::m_ClusterDDir, SearcherParams::m_ClusterDPos, SearcherParams::m_ClusterDScale, SearcherParams::m_ClusterMeltDist, m_Clusters, SearcherParams::m_ClusterTH, m_CurCluster, m_NClusters, SearcherParams::m_NClusters, M_PI, m_Population, m_Representative, mapAnglePI(), Model::ST_MEMBER, Point2D::x, and Point2D::y.

Referenced by evolve(), and getShapeWeight().

420 {
421  m_Clusters.clear();
422  m_NClusters = 0;
423  if(!buildBins()) return 0;
424  list<Model*>::iterator model = m_Population.begin();
425  float cqth = (*model)->getQualityOfFit()*getSearchPara().m_ClusterTH;
426  float m_MergeDistMM = getSearchPara().m_ClusterMeltDist;
427  float m_MergeDist;
429  m_MergeDist = m_Representative.getDataScale()*m_MergeDistMM;
430  else m_MergeDist = m_MergeDistMM*100;
431  int nmelt = 0, nmerge = 0;
432  int maxclusters = (int)getSearchPara().m_NClusters;
433  if(maxclusters == 0) maxclusters = numeric_limits<int>::max();
434  while(model != m_Population.end()
435  && (*model)->getQualityOfFit()>cqth
436  && m_NClusters < maxclusters)
437  {
438  if(!(*model)->hasFlags(Model::ST_MEMBER)) {
439 //create new cluster from model
440  m_Clusters.push_back(MBin());
441  m_CurCluster = &m_Clusters.back();
442  m_CurCluster->push_back(*model);
443  (*model)->setFlags(Model::ST_MEMBER);
444  PropVec cprop = (*model)->getPropertiesMM();
445  float mdrot = M_PI*getSearchPara().m_ClusterDDir;
446  float mdscale = getSearchPara().m_ClusterDScale;
447  float mdpos = getPropScale(cprop)*getSearchPara().m_ClusterDPos;
448  m_NClusters++;
449 //scan bins for other cluster members
450  Point c = (*model)->getCenter();
451  int bx = (int)(c.x/m_BinDist);
452  int by = (int)(c.y/m_BinDist);
453  int binradius = (int)ceil(mdpos/m_BinDist);
454  for(int px=bx-binradius; px<=bx+binradius; px++) {
455  if(px>=0 && px<=m_BinsX) {
456  for(int py=by-binradius; py<=by+binradius; py++) {
457  bool culled;
458  int index = getBindex(px,py,culled);
459  if(!culled) {
460  MBin::iterator be = m_Bins[index].begin();
461  while(be != m_Bins[index].end()) {
462  MBin::iterator nextbe = be;
463  nextbe++;
464  if(!(*be)->hasFlags(Model::ST_MEMBER)) {
465  PropVec prop = (*be)->getPropertiesMM();
466  //PropVec pdiff = getPropTF(cprop, prop);
467  float dpos = (getPropPos(cprop)-
468  getPropPos(prop)).norm();
469  float drot = mapAnglePI(getPropDir(cprop)-
470  getPropDir(prop));
471  drot = fabs(drot);
472  float dscale = getPropScale(prop)/
473  getPropScale(cprop);
474  if(dscale>1) dscale = 1-1/dscale;
475  else dscale = 1-dscale;
476  if(dpos < mdpos && drot < mdrot &&
477  dscale < mdscale) {
478  if(dpos < m_MergeDistMM &&
479  (*model)->distance(
480  **be,Model::DIST_CPOINTS)
481  < m_MergeDist)
482  {
483  //too close --> melt
484  (*model)->mergeModel(**be);
485  nmelt++;
486  } else {
487  m_CurCluster->push_back(*be);
488  nmerge++;
489  }
490  (*be)->setFlags(Model::ST_MEMBER);
491  m_Bins[index].erase(be);
492  }
493  } else m_Bins[index].erase(be);
494  be = nextbe;
495  }
496  }
497  }
498  }
499  }
500 // DUMP(cprop);
501 // DUMP((*model)->getQualityOfFit());
502 // DUMP(m_CurCluster->size());
503  }
504  model++;
505  }
506 // DUMP(nmelt);
507 // DUMP(m_MergeDist);
508 // DUMP(nmerge);
509 // DUMP(m_NClusters);
510  return m_NClusters;
511 }
float m_ClusterMeltDist
maximum Hausdorff distance in mm for melting two shapes
Definition: Searcher.h:169
std::vector< MBin > m_Bins
Definition: Searcher.h:71
bool buildBins(float bindist=0.f)
Definition: Searcher.cpp:361
float y
Definition: Point.h:224
Point2D getPropPos(const PropVec &prop)
Definition: PropVec.h:13
float m_BinDist
Definition: Searcher.h:73
float getPropScale(const PropVec &prop)
Definition: PropVec.h:19
int m_BinsX
Definition: Searcher.h:72
float m_ClusterDScale
maximum relative difference in scale to cluster representative
Definition: Searcher.h:167
float m_ClusterTH
least quality of cluster relative to the best
Definition: Searcher.h:165
dword m_NClusters
number of clusters (winners) determined at each cycle
Definition: Searcher.h:164
float getPropDir(const PropVec &prop)
Definition: PropVec.h:25
int getBindex(int bx, int by, bool &culled=*((bool *) NULL)) const
Definition: Searcher.h:104
#define M_PI
Definition: mathutil.h:9
SearcherParams & getSearchPara()
Definition: Searcher.h:194
std::list< Model * > m_Population
Definition: Searcher.h:69
MBin * m_CurCluster
Definition: Searcher.h:76
Model m_Representative
Definition: Searcher.h:65
int m_NClusters
Definition: Searcher.h:75
std::list< MBin > m_Clusters
Definition: Searcher.h:74
float m_ClusterDDir
maximum difference in direction in $$
Definition: Searcher.h:168
float m_ClusterDPos
maximum distance of shapes in a cluster (relative to shape radius)
Definition: Searcher.h:166
Definition: Point.h:16
float mapAnglePI(float a)
Definition: mathutil.h:107
float x
Definition: Point.h:224
dword getDataScale() const
Definition: Model.h:204
void Searcher::cleanFlags ( )
protected

Definition at line 546 of file Searcher.cpp.

References VVector< T, D >::clampLB(), VVector< T, D >::clampUB(), DUMP, Model::getProperties(), Model::getQualityOfFit(), m_AvgWinner, m_MaxModel, m_MinModel, m_Population, m_Representative, m_StdWinner, m_Time, Model::m_TimeStamp, VVector< T, D >::sqrtEach(), Model::ST_DEL, Model::ST_LOOSER, Model::ST_MEMBER, Model::ST_NODEL, Model::ST_OLDSTATE, and Model::ST_WINNER.

Referenced by evolve(), and getShapeWeight().

547 {
548 //remove loosers -- no, just set flags properly
549  int killcount = 0;
550  int wincount = 0;
551  int mergekill=0;
552  int lowkill=0;
553  Model *prep = *m_Population.begin();
554  m_AvgWinner = 0.f;
555  m_StdWinner = 0.f;
556  m_MinModel = m_MaxModel = prep->getProperties();
557  list<Model*>::iterator model = m_Population.begin();
558  while(model != m_Population.end())
559  {
560  list<Model*>::iterator nm = model; nm++;
561  if((*model)->hasFlags(Model::ST_NODEL)) {
562  (*model)->setFlags(Model::ST_WINNER|Model::ST_MEMBER);
563  (*model)->unsetFlags(Model::ST_LOOSER|Model::ST_OLDSTATE
564  |Model::ST_DEL);
565  }
566  if(!(*model)->hasFlags(Model::ST_MEMBER)) {
567  remove(model);
568  lowkill++;
569  } else if((*model)->hasFlags(Model::ST_DEL)) {
570  //(*model)->unsetFlags(Model::ST_DEL);
571  remove(model);
572  mergekill++;
573  } else {
574  m_MinModel.clampUB((*model)->getProperties());
575  m_MaxModel.clampLB((*model)->getProperties());
576  if((*model)->isOldState()) {
577  (*model)->unsetFlags(Model::ST_WINNER|Model::ST_LOOSER
579  //(*model)->m_TimeStamp[Model::TS_WIN] = 0.0;
580  } else if((*model)->isWinner()) {
581  if(prep->getQualityOfFit() < (*model)->getQualityOfFit())
582  prep = *model;
583  PropVec winprop = (*model)->getProperties();
584  m_AvgWinner += winprop;
585  m_StdWinner += (winprop *= winprop);
586  wincount++;
587  } else { //if((*model)->isLooser()) {
588  if(!(*model)->isLooser())
589  (*model)->setLooser(true, m_Time);
590  //(*model)->m_TimeStamp[Model::TS_WIN] = 0.0;
591  killcount++;
592  }
593  }
594  model = nm;
595  }
596  m_Representative = *prep;
597  if(!wincount) {
599  m_StdWinner = 0.f;
600  } else {
601  m_AvgWinner /= (float)(wincount);
602  m_StdWinner /= (float)(wincount);
603  DUMP(m_AvgWinner);
604  DUMP(m_StdWinner);
607  }
608  DUMP(mergekill);
609  DUMP(lowkill);
610  cout << "representative age: "
611  << m_Time-m_Representative.m_TimeStamp << " s" //[Model::TS_WIN]
612  << " (search time "<<m_Time<<" s)"<<endl;
613  cout << killcount<<" loosers and " << wincount << " winners."<<endl;
614 }
#define DUMP(expr)
Definition: common.h:16
float getQualityOfFit() const
Definition: Model.cpp:1204
const PropVec & getProperties() const
Definition: Model.cpp:1263
PropVec m_MaxModel
Definition: Searcher.h:67
PropVec m_MinModel
Definition: Searcher.h:67
float m_Time
Definition: Searcher.h:77
PropVec m_StdWinner
Definition: Searcher.h:66
VT & clampUB(const VT &ub)
Definition: VVector.h:247
Definition: Model.h:33
VT & sqrtEach()
Definition: VVector.h:215
std::list< Model * > m_Population
Definition: Searcher.h:69
VT & clampLB(const VT &lb)
Definition: VVector.h:241
Model m_Representative
Definition: Searcher.h:65
PropVec m_AvgWinner
Definition: Searcher.h:66
float m_TimeStamp
time stamps (see. TTimeStamp)
Definition: Model.h:259
void Searcher::clear ( )

Definition at line 126 of file Searcher.cpp.

References Model::clear(), ExpectationMap::clear(), m_Bins, m_BinsX, m_BinsY, m_EMap, m_EvolveT, m_NPop, m_Population, m_Representative, m_Time, and m_Winners.

Referenced by getExpectationMap(), operator=(), startSearch(), triggerTest(), and ~Searcher().

126  {
127  m_BinsX = m_BinsY = 0;
128  m_Bins.clear();
129  for(list<Model*>::iterator gi=m_Population.begin();
130  gi != m_Population.end(); gi++)
131  {
132  delete *gi;
133  }
134  m_Population.clear();
136  m_EMap.clear();
137  m_Winners.clear();
138  m_NPop=0;
139  m_Time=0;
140  m_EvolveT=0;
141 }
std::vector< MBin > m_Bins
Definition: Searcher.h:71
void clear(bool oldonly=false)
Definition: ExpMap.cpp:141
int m_BinsX
Definition: Searcher.h:72
float m_Time
Definition: Searcher.h:77
std::map< dword, Winner > m_Winners
Definition: Searcher.h:83
std::list< Model * > m_Population
Definition: Searcher.h:69
Model m_Representative
Definition: Searcher.h:65
ExpectationMap m_EMap
Definition: Searcher.h:68
int m_BinsY
Definition: Searcher.h:72
float m_EvolveT
Definition: Searcher.h:81
int m_NPop
Definition: Searcher.h:70
void clear()
remove and destroy all geometry information (nodes and edges)
Definition: Model.cpp:95
int Searcher::distribute ( int  n = -1,
float  qth = 0,
bool  count = false 
)
protected

Definition at line 627 of file Searcher.cpp.

References add(), ExpectationMap::generateInstance(), Model::getNNodes(), Model::getProperties(), Model::getQualityOfFit(), ExpectationMap::getRepresentative(), m_AvgWinner, m_EMap, m_Representative, and m_StdWinner.

Referenced by getShapeWeight().

629 {
630  //this function is unused
631  if(m_EMap.getRepresentative().getNNodes() == 0) return -1;
632  else if(m_Representative.getNNodes() == 0) {
635  m_StdWinner = 0.f;
636  }
637  for(int i=0; i<n; i++) {
638  Model *newmod = m_EMap.generateInstance();
639  if(newmod->getQualityOfFit() < qth) {
640  delete newmod;
641  } else {
642  //newmod->m_TimeStamp = m_Time; //[Model::TS_CREATE]
643  add(newmod);
644  }
645  }
646  return n;
647 }
float getQualityOfFit() const
Definition: Model.cpp:1204
const PropVec & getProperties() const
Definition: Model.cpp:1263
Model * generateInstance() const
Definition: ExpMap.cpp:184
PropVec m_StdWinner
Definition: Searcher.h:66
int getNNodes() const
Definition: Model.h:77
Definition: Model.h:33
Model m_Representative
Definition: Searcher.h:65
Model & getRepresentative()
Definition: ExpMap.h:156
ExpectationMap m_EMap
Definition: Searcher.h:68
int add(Model *m)
Definition: Searcher.cpp:143
PropVec m_AvgWinner
Definition: Searcher.h:66
void Searcher::draw ( ) const

Definition at line 687 of file Searcher.cpp.

References Model::draw(), m_Population, m_Representative, and m_Winners.

Referenced by Brain::drawAllModels(), and getExpectationMap().

688 {
689  glLineWidth(1.0f);
690  for(list<Model*>::const_iterator m = m_Population.begin();
691  m!=m_Population.end(); m++)
692  {
693  if((*m)->isWinner()) {
694  glColor4f(0.1,0.9,0.0,0.7);
695  } else if((*m)->isLooser()) {
696  glColor4f(0.0,0.0,1.0,0.3);
697  } else {
698  glColor4f(0.9,0.9,0.0,0.3);
699  }
700  (*m)->draw();
701  }
702  glLineWidth(3.0f);
703  glColor4f(0.1,0.9,0.0,1.0);
704  for(list<Model*>::const_iterator m = m_Population.begin();
705  m!=m_Population.end(); m++)
706  {
707  if((*m)->isWinner())// && (m_Time-(*m)->m_TimeStamp[Model::TS_WIN])>6)
708  (*m)->draw();
709  }
710  if(!m_Winners.empty()) {
711  glLineWidth(3.0f);
712  glColor4f(1.0f, 0.0f, 0.5f,1.0f);
714  glLineWidth(1.0f);
715  }
716 }
std::map< dword, Winner > m_Winners
Definition: Searcher.h:83
std::list< Model * > m_Population
Definition: Searcher.h:69
Model m_Representative
Definition: Searcher.h:65
void draw(bool drawPoints=false) const
Draw using OpenGL.
Definition: Model.cpp:542
void Searcher::evolve ( )

Definition at line 163 of file Searcher.cpp.

References add(), buildClusters(), cleanFlags(), DUMP, ExpectationMap::generateInstance(), Model::getName(), Model::getQualityOfFit(), getQualityRange(), getSearchPara(), m_EMap, SearcherParams::m_EvolveCycle, EMDistribution::m_Integral, SearcherParams::m_MaxPop, m_Mode, m_MutateRate, SearcherParams::m_MutateSpawns, SearcherParams::m_MutateTHRed, m_NextWinID, m_NPop, SearcherParams::m_NSpawns, SearcherParams::m_NSpawnsTHRed, m_Population, m_Representative, m_Time, Winner::m_WinnerID, m_Winners, MODE_DONE, MODE_PAUSE, mutate(), NULL, ExpectationMap::ratePropVec(), selectWinners(), and Model::ST_NODEL.

Referenced by Brain::evolve().

164 {
165  if(m_Mode == MODE_PAUSE) return;
166 //create, mutate, and remove
167  int extrakill=0;
168  float lqof,hqof;
169  getQualityRange(lqof,hqof);
170  double slowlive=0.0;
171  if(m_NPop) {
172  for(list<Model*>::const_iterator m = m_Population.begin();
173  m!=m_Population.end(); m++)
174  {
175  //if((*m)->m_TimeStamp-m_Time > 4&&(*m)->getLiveliness()>slowlive)
176  slowlive += (*m)->getLiveliness();
177  }
178  slowlive /= m_NPop;
179  slowlive *= 0.5;
180  DUMP(slowlive);
181  }
182 
183  //findWinners();
184  if(buildClusters()) {
185  selectWinners();
186  cleanFlags();
187  }
188  //float kill_quality_th = hqof*0.7;
189  list<Model*>::iterator m=m_Population.begin();
190  dword rank = 0;
191  bool pastlast=false;
192  int lamekill=0;
193  m_Winners.clear();
194  Model* lastmodel = !m_Population.empty() ? m_Population.back():NULL;
195  while(m != m_Population.end() && !pastlast)
196  {
197  if(*m == lastmodel) pastlast=true;
198  list<Model*>::iterator nm = m; nm++;
199  //float relq = (hqof-lqof)*kill_quality_th+lqof;
200  //(hqof!=0.0) ? ((*m)->getQualityOfFit()-lqof)/hqof :1;
201  //if(relq > (*m)->getQualityOfFit() && m_NPop>1) {
202  if(rank > getSearchPara().m_MaxPop) {
203  if(m_NPop>1) { remove(m); extrakill++; }
204  } else if((*m)->isWinner()) {
205  PropVec propvec((*m)->getProperties());
206  if(!(*m)->getID()) (*m)->setID(m_NextWinID++);
207  Winner winner(*m);
208  float rating = m_EMap.ratePropVec(propvec, &winner);
209  if(rating < getSearchPara().m_RatingTH &&
210  !(*m)->hasFlags(Model::ST_NODEL)) {
211 // cout << "removing invalid winner " << endl;
212 // DUMP(rating);
213 // DUMP(propvec);
214 // DUMP(propvec.clamp(m_EMap.m_LB, m_EMap.m_UB));
215 // DUMP((*m)->getName());
216  remove(m);
217  m_NextWinID--;
218  } else
219  {
220  m_Winners[winner.m_WinnerID] = winner;
221 // m_Winners.insert(pair<dword,Winner>(winner.m_WinnerID,
222 // winner));
223 //mutate winners
224  float threduce = getSearchPara().m_MutateTHRed;
225  float qth = (*m)->getQualityOfFit()*threduce;
226  int cs=0;
227  int misses=0;
228  const int nspawns = getSearchPara().m_MutateSpawns;
229  while(cs<nspawns) {
230  Model *newmod = &mutate(*(new Model(**m)),m_MutateRate
231  *exp((m_Time/getSearchPara().m_MutateHL)
232  *(-M_LN2)));
233  if(newmod->getQualityOfFit() < qth) {
234  delete newmod;
235  misses++;
236  if(misses%nspawns==0) qth*=threduce;
237  } else {
238  add(newmod);
239  cs++;
240  }
241  }
242  if(misses>nspawns) DUMP(misses)<<" for mutation"<<endl;
243  //nm = m; nm++; // ensure validity of iterator (?)
244  }
245  } else if((*m)->getLiveliness()<slowlive) {
246  remove(m);
247  lamekill++;
248  } else if(m_NPop>1 && (*m)->isLooser() &&
249  (m_Time-(*m)->m_TimeStamp>getSearchPara().m_EvolveCycle*10))
250  {
251  remove(m);
252  }
253  m = nm;
254  rank++;
255  }
256 // DUMP(extrakill);
257 // DUMP(lamekill);
258 //Spawn new instances
259  int cs = 0;
260  float threduce = getSearchPara().m_NSpawnsTHRed;
261  float qth = hqof*threduce; //DEBUG
262  int misses = 0;
263  const int nspawns = m_EMap && m_EMap.m_Integral > 0.00001f
264  ? getSearchPara().m_NSpawns : 0;
265  while(cs<nspawns) {
266  Model *newmod = m_EMap.generateInstance();
267  if(newmod->getQualityOfFit() < qth) {
268  delete newmod;
269  misses++;
270  if(misses%nspawns==0) qth*=threduce;
271  } else {
272  //qth = newmod->getQualityOfFit();
273  //newmod->m_TimeStamp = m_Time; //[Model::TS_CREATE]
274  add(newmod);
275  cs++;
276  }
277  }
278  //if(misses>20) DUMP(misses) << " for distribution" << endl;
280  if(m_NPop > 0 && //(int)m_Winners.size() &&
281  m_EMap.m_Integral < 0.0001f)
282  {
283  m_Mode = MODE_DONE;
284  } else cout << m_Representative.getName() << " searching, integral = "
285  << m_EMap.m_Integral << endl;
286 }
dword m_MutateSpawns
number of spawns when mutating a shape
Definition: Searcher.h:177
float m_Integral
Definition: ExpMap.h:67
dword m_Mode
Definition: Searcher.h:80
#define NULL
Definition: simpletypes.h:9
#define DUMP(expr)
Definition: common.h:16
float getQualityOfFit() const
Definition: Model.cpp:1204
dword m_NextWinID
Definition: Searcher.h:84
Model * generateInstance() const
Definition: ExpMap.cpp:184
void getQualityRange(float &lqof, float &hqof, float shapeweight=-1) const
Definition: Searcher.cpp:649
float ratePropVec(const PropVec &prop, Winner *winner=NULL) const
Definition: ExpMap.cpp:107
dword m_NSpawns
number of new spawned shapes at each cycle
Definition: Searcher.h:161
float m_NSpawnsTHRed
threshold reduction factor for new spawns
Definition: Searcher.h:162
float m_Time
Definition: Searcher.h:77
float m_MutateTHRed
threshold reduction factor for mutated spawns
Definition: Searcher.h:175
std::map< dword, Winner > m_Winners
Definition: Searcher.h:83
Definition: ExpMap.h:10
Definition: Model.h:33
float m_EvolveCycle
time in seconds for one evolution cycle
Definition: Searcher.h:172
SearcherParams & getSearchPara()
Definition: Searcher.h:194
std::list< Model * > m_Population
Definition: Searcher.h:69
unsigned long dword
Definition: simpletypes.h:6
void selectWinners()
Definition: Searcher.cpp:513
Model m_Representative
Definition: Searcher.h:65
int buildClusters()
Definition: Searcher.cpp:419
ExpectationMap m_EMap
Definition: Searcher.h:68
int add(Model *m)
Definition: Searcher.cpp:143
int m_NPop
Definition: Searcher.h:70
void cleanFlags()
Definition: Searcher.cpp:546
dword m_MaxPop
maximum population count
Definition: Searcher.h:163
const std::string & getName() const
Definition: Model.h:81
float m_MutateRate
Definition: Searcher.h:82
Model & mutate(Model &model, float rate=1) const
Definition: Searcher.cpp:307
void Searcher::findWinners ( )
protected

Referenced by getShapeWeight().

float Searcher::getBestQOF ( ) const
inline

Definition at line 129 of file Searcher.h.

References m_Population.

Referenced by getWinList(), and relativeQOF().

130 {
131  return m_Population.empty()? 1.f
132  :(*m_Population.begin())->getQualityOfFit();
133 }
std::list< Model * > m_Population
Definition: Searcher.h:69
int Searcher::getBindex ( int  bx,
int  by,
bool &  culled = *((bool*)NULL) 
) const
inlineprotected

Definition at line 104 of file Searcher.h.

References m_BinsX, m_BinsY, and NULL.

Referenced by buildBins(), buildClusters(), getBindex(), and getShapeWeight().

105 {
106  bool tb;
107  bool &cf = &culled != NULL ? culled : tb; // redirect to temporary bool?
108  cf = false;
109  if(bx<0) { bx=0; cf = true; }
110  else if(bx>=m_BinsX) { bx=m_BinsX-1; cf = true; }
111  if(by<0) { by=0; cf = true; }
112  else if(by>=m_BinsY) { by=m_BinsY-1; cf = true; }
113  return by*m_BinsX+bx;
114 }
#define NULL
Definition: simpletypes.h:9
int m_BinsX
Definition: Searcher.h:72
int m_BinsY
Definition: Searcher.h:72
int Searcher::getBindex ( const PropVec prop,
bool &  culled = *((bool*)NULL) 
) const
inlineprotected

Definition at line 116 of file Searcher.h.

References getBindex().

117 {
118  return getBindex((int)prop[0], (int)prop[1], culled);
119 }
int getBindex(int bx, int by, bool &culled=*((bool *) NULL)) const
Definition: Searcher.h:104
int Searcher::getBindex ( const Model model,
bool &  culled = *((bool*)NULL) 
) const
inlineprotected

Definition at line 121 of file Searcher.h.

References getBindex(), Model::getCenter(), and setPropPos().

122 {
123  //PropVec prop=model.getProperties();
124  PropVec prop(0.);
125  setPropPos(prop, model.getCenter());
126  return getBindex(prop, culled);
127 }
const Point getCenter() const
Definition: Model.cpp:852
PropVec & setPropPos(PropVec &prop, const Point2D &p)
Definition: PropVec.h:16
int getBindex(int bx, int by, bool &culled=*((bool *) NULL)) const
Definition: Searcher.h:104
ExpectationMap& Searcher::getExpectationMap ( )
inline

Definition at line 37 of file Searcher.h.

References m_EMap.

Referenced by MStructure::rebuildExpMap(), and Brain::setupSearch().

37 { return m_EMap; }
ExpectationMap m_EMap
Definition: Searcher.h:68
const ExpectationMap& Searcher::getExpectationMap ( ) const
inline

Definition at line 38 of file Searcher.h.

References clear(), draw(), m_EMap, and triggerTest().

38 { return m_EMap; }
ExpectationMap m_EMap
Definition: Searcher.h:68
float Searcher::getGeneration ( const Model model) const

Definition at line 303 of file Searcher.cpp.

References getSearchPara(), SearcherParams::m_EvolveCycle, m_Time, and Model::m_TimeStamp.

Referenced by MStructure::addExpectation(), and getRepresentative().

303  {
304  return (m_Time - model->m_TimeStamp) / getSearchPara().m_EvolveCycle;
305 }
float m_Time
Definition: Searcher.h:77
float m_EvolveCycle
time in seconds for one evolution cycle
Definition: Searcher.h:172
SearcherParams & getSearchPara()
Definition: Searcher.h:194
float m_TimeStamp
time stamps (see. TTimeStamp)
Definition: Model.h:259
float Searcher::getLeastQOF ( ) const
inline

Definition at line 135 of file Searcher.h.

References m_Population.

Referenced by getWinList(), and relativeQOF().

136 {
137  return m_Population.empty()? 0.f
138  :(*m_Population.rbegin())->getQualityOfFit();
139 }
std::list< Model * > m_Population
Definition: Searcher.h:69
void Searcher::getQualityRange ( float &  lqof,
float &  hqof,
float  shapeweight = -1 
) const
protected

Definition at line 649 of file Searcher.cpp.

References m_Population, and setShapeWeight().

Referenced by evolve(), getShapeWeight(), and triggerTest().

651 {
652  if(m_Population.empty()) {
653  lqof = hqof = 0;
654  return;
655  }
656  bool cw = (shapeweight!=-1);
657  if(cw) (*m_Population.begin())->setShapeWeight(shapeweight);
658  lqof=hqof=(*m_Population.begin())->getQualityOfFit();
659  for(list<Model*>::const_iterator m = m_Population.begin();
660  m!=m_Population.end(); m++)
661  {
662  if(cw) (*m)->setShapeWeight(shapeweight);
663  if((*m)->getQualityOfFit()>hqof) hqof=(*m)->getQualityOfFit();
664  if((*m)->getQualityOfFit()<lqof) lqof=(*m)->getQualityOfFit();
665  }
666 }
void setShapeWeight(float shapeweight)
Definition: Searcher.h:46
std::list< Model * > m_Population
Definition: Searcher.h:69
const Model& Searcher::getRepresentative ( ) const
inline

Definition at line 43 of file Searcher.h.

References getGeneration(), m_Representative, and reattachSensors().

Referenced by Brain::triggerTest().

43 { return m_Representative; }
Model m_Representative
Definition: Searcher.h:65
float Searcher::getShapeWeight ( ) const
inline
std::map<dword,Winner>& Searcher::getWinList ( )
inline

Definition at line 30 of file Searcher.h.

References m_Winners.

Referenced by MStructure::addExpectation(), StructTable::findBestConnection(), and MStructure::verifyWinnerRating().

30 { return m_Winners; }
std::map< dword, Winner > m_Winners
Definition: Searcher.h:83
const std::map<dword,Winner>& Searcher::getWinList ( ) const
inline

Definition at line 31 of file Searcher.h.

References getBestQOF(), getLeastQOF(), getWinner(), m_Winners, relativeQOF(), and setExpectationMap().

31 { return m_Winners; }
std::map< dword, Winner > m_Winners
Definition: Searcher.h:83
const Winner * Searcher::getWinner ( dword  id) const

Definition at line 668 of file Searcher.cpp.

References m_Winners, and NULL.

Referenced by getWinList(), MStructure::getWinner(), and MStructure::verifyWinnerRating().

669 {
670  map<dword,Winner>::const_iterator wi = m_Winners.find(id);
671  if(wi == m_Winners.end()) return NULL;
672  else return &wi->second;
673 }
#define NULL
Definition: simpletypes.h:9
std::map< dword, Winner > m_Winners
Definition: Searcher.h:83
template<class Iter >
unsigned int Searcher::getWinners ( Iter  iter) const
inline

Definition at line 90 of file Searcher.h.

References m_Population.

Referenced by searchDone(), and Brain::triggerTest().

91 {
92  unsigned int nwin=0;
93  for(std::list<Model*>::const_iterator wi=m_Population.begin();
94  wi != m_Population.end(); wi++)
95  {
96  if((*wi)->isWinner()) {
97  *iter++ = *wi;
98  nwin++;
99  }
100  }
101  return nwin;
102 }
std::list< Model * > m_Population
Definition: Searcher.h:69
Model & Searcher::mutate ( Model model,
float  rate = 1 
) const
protected

Definition at line 307 of file Searcher.cpp.

References Model::adaptProperties(), Model::adaptProportion(), Model::addNoise(), frand, FRAND1, Model::getProperties(), getSearchPara(), Model::getStdRadius(), M_PI, Model::push(), Model::pushRotate(), setPropDir(), and setPropPos().

Referenced by evolve(), and getShapeWeight().

308 {
309 #define _PROP_MUTATION_
310 #ifdef _PROP_MUTATION_
311  PropVec prop = model.getProperties();
312  PropVec mutation(0.f);
313  bool same=true;
314  while(same) {
315  if(FRAND1 < getSearchPara().m_MutatePDir){
316  setPropDir(mutation,frand(2*M_PI));
317  same = false;
318  }
319  if(FRAND1 < getSearchPara().m_MutatePPos) {
320  Point pos(0,0);
321  float radius = model.getStdRadius();//*rate;
322  pos += Point2D(radius-frand(2*radius), radius-frand(2*radius));
323  setPropPos(mutation,pos);
324  same = false;
325  }
326  if(FRAND1 < getSearchPara().m_MutatePNoise) {
327  model.addNoise(getSearchPara().m_MutateNoiseRate*rate);
328  same = false;
329  }
330  if(FRAND1 < getSearchPara().m_MutatePProp) {
331  model.adaptProportion(getSearchPara().m_MutatePropRate);
332  same = false;
333  }
334  }
335  model.adaptProperties(prop+(mutation*rate));
336 #else
337  float radius=model.getStdRadius();
338  model.push(Point2D(-radius+frand(2*radius),
339  -radius+frand(2*radius)));
340  model.pushRotate((*m)->getCenter(), -2+frand(4));
341  model.addNoise(0.1);
342 #endif
343  return model;
344 }
#define frand(max)
Definition: mathutil.h:48
const PropVec & getProperties() const
Definition: Model.cpp:1263
float getStdRadius(const Point &center) const
Returns mean squared distance from centroid.
Definition: Model.cpp:1018
void pushRotate(const Point &c, float angle)
Definition: Model.cpp:954
void adaptProportion(float ratio)
overall rest lengths sum is adapted to overall edge lengths by ratio
Definition: Model.cpp:1164
#define FRAND1
Definition: mathutil.h:49
PropVec & setPropDir(PropVec &prop, float dir)
Definition: PropVec.h:28
PropVec & setPropPos(PropVec &prop, const Point2D &p)
Definition: PropVec.h:16
#define M_PI
Definition: mathutil.h:9
SearcherParams & getSearchPara()
Definition: Searcher.h:194
void adaptProperties(const PropVec &prop)
Definition: Model.cpp:1249
Definition: Point.h:16
void addNoise(float r)
Definition: Model.cpp:901
void push(const Point &t)
Definition: Model.cpp:931
Searcher::operator bool ( ) const
inline

Definition at line 42 of file Searcher.h.

References m_EMap.

42 { return (bool)m_EMap; }
ExpectationMap m_EMap
Definition: Searcher.h:68
Searcher & Searcher::operator= ( const Searcher rhs)

Definition at line 95 of file Searcher.cpp.

References clear(), m_AvgWinner, m_BinDist, m_Bins, m_BinsX, m_BinsY, m_EMap, m_EvolveT, m_Mode, m_MutateRate, m_NextWinID, m_NPop, m_Population, m_PosMax, m_PosMin, m_PosRange, m_Representative, m_ShapeWeight, m_StdWinner, m_Time, m_Winners, and updateWinList().

Referenced by Searcher().

96 {
97  if(&rhs == this) return *this;
98  clear();
100  m_AvgWinner = rhs.m_AvgWinner;
101  m_StdWinner = rhs.m_StdWinner;
102  m_EMap = rhs.m_EMap;
103  for(list<Model*>::const_iterator gi=rhs.m_Population.begin();
104  gi != rhs.m_Population.end(); gi++)
105  {
106  m_Population.push_back(new Model(**gi));
107  }
108  m_NPop = rhs.m_NPop;
109  m_Bins = rhs.m_Bins;
110  m_BinsX, m_BinsY = rhs.m_BinsX;
111  m_BinDist = rhs.m_BinDist;
112  m_Time = rhs.m_Time;
113  m_PosMax = rhs.m_PosMax;
114  m_PosMin = rhs.m_PosMin;
115  m_PosRange = rhs.m_PosRange;
116  m_Mode = rhs.m_Mode;
117  m_EvolveT = rhs.m_EvolveT;
119  m_NextWinID = rhs.m_NextWinID;
122  updateWinList();
123  return *this;
124 }
dword m_Mode
Definition: Searcher.h:80
std::vector< MBin > m_Bins
Definition: Searcher.h:71
dword m_NextWinID
Definition: Searcher.h:84
Point m_PosMax
Definition: Searcher.h:78
float m_BinDist
Definition: Searcher.h:73
Point m_PosRange
Definition: Searcher.h:78
int m_BinsX
Definition: Searcher.h:72
float m_ShapeWeight
Definition: Searcher.h:85
float m_Time
Definition: Searcher.h:77
PropVec m_StdWinner
Definition: Searcher.h:66
void clear()
Definition: Searcher.cpp:126
std::map< dword, Winner > m_Winners
Definition: Searcher.h:83
Definition: Model.h:33
std::list< Model * > m_Population
Definition: Searcher.h:69
Point m_PosMin
Definition: Searcher.h:78
Model m_Representative
Definition: Searcher.h:65
ExpectationMap m_EMap
Definition: Searcher.h:68
int m_BinsY
Definition: Searcher.h:72
float m_EvolveT
Definition: Searcher.h:81
int m_NPop
Definition: Searcher.h:70
PropVec m_AvgWinner
Definition: Searcher.h:66
float m_MutateRate
Definition: Searcher.h:82
std::map< dword, Winner > & updateWinList()
Definition: Searcher.cpp:675
void Searcher::reattachSensors ( )

Definition at line 616 of file Searcher.cpp.

References ExpectationMap::getRepresentative(), m_EMap, m_Population, m_Representative, and Model::reattachSensors().

Referenced by getRepresentative().

617 {
620  for(list<Model*>::iterator model = m_Population.begin();
621  model != m_Population.end(); model++)
622  {
623  (*model)->reattachSensors();
624  }
625 }
void reattachSensors()
get sensors from sensor collection
Definition: Model.cpp:616
std::list< Model * > m_Population
Definition: Searcher.h:69
Model m_Representative
Definition: Searcher.h:65
Model & getRepresentative()
Definition: ExpMap.h:156
ExpectationMap m_EMap
Definition: Searcher.h:68
float Searcher::relativeQOF ( float  qof) const
inline

Definition at line 141 of file Searcher.h.

References getBestQOF(), and getLeastQOF().

Referenced by getWinList().

142 {
143  const float mq = getBestQOF(), lq = getLeastQOF();
144  float range = mq-lq; if(range <= 0.f) range = 1.f;
145  return (qof-lq)/range;
146 }
float getBestQOF() const
Definition: Searcher.h:129
float getLeastQOF() const
Definition: Searcher.h:135
list< Model * >::iterator & Searcher::remove ( std::list< Model * >::iterator &  mi)
protected

Definition at line 152 of file Searcher.cpp.

References m_NPop, m_Population, and Model::ST_NODEL.

153 {
154  if(!(*mi)->hasFlags(Model::ST_NODEL)) {
155  list<Model*>::iterator ci = mi++;
156  delete *ci;
157  m_Population.erase(ci);
158  m_NPop--;
159  }
160  return mi;
161 }
std::list< Model * > m_Population
Definition: Searcher.h:69
int m_NPop
Definition: Searcher.h:70
bool Searcher::searchDone ( ) const
inline

Definition at line 28 of file Searcher.h.

References getWinners(), m_Mode, and MODE_DONE.

28 { return m_Mode == MODE_DONE; }
dword m_Mode
Definition: Searcher.h:80
void Searcher::selectWinners ( )
protected

Definition at line 513 of file Searcher.cpp.

References m_Clusters, m_Time, Model::ST_DEL, and TRACE.

Referenced by evolve(), and getShapeWeight().

514 {
515  dword m_NBinWinners = 1;
516  for(list< MBin >::iterator cluster = m_Clusters.begin();
517  cluster != m_Clusters.end(); cluster++) {
518  if(!cluster->empty()) {
519  MBin::iterator crep = cluster->begin();
520 //select winners
521  if(!(*crep)->hasFlags(Model::ST_DEL)) {
522  (*crep)->setOldState(false);
523  if(!(*crep)->isWinner()) {
524 // float time = m_Time;
525 // if((*crep)->m_TimeStamp[Model::TS_WIN]!=0)
526 // time = (*crep)->m_TimeStamp[Model::TS_WIN];
527  (*crep)->setWinner(true); //, time);
528  }
529  (*crep)->setLooser(false);
530  crep++;
531  } else TRACE("DELETED CLUSTER WINNER????????");
532 //select rest as loosers
533  while(crep != cluster->end()) {
534  //if((*crep)->isOldState()) {
535  (*crep)->setOldState(false);
536  if((*crep)->isWinner()) (*crep)->setWinner(false);
537  if(!(*crep)->isLooser()) {
538  (*crep)->setLooser(true, m_Time);
539  }
540  crep++;
541  }
542  }
543  } // for each cluster
544 }
#define TRACE(msg)
Definition: common.h:14
float m_Time
Definition: Searcher.h:77
unsigned long dword
Definition: simpletypes.h:6
std::list< MBin > m_Clusters
Definition: Searcher.h:74
void Searcher::setExpectationMap ( const ExpectationMap em)

Definition at line 346 of file Searcher.cpp.

References ExpectationMap::correctLBUB(), EMDRect::getLB(), getPropPos(), EMDRect::getUB(), m_EMap, m_PosMax, m_PosMin, m_PosRange, EMDRect::setLB(), EMDRect::setUB(), and ExpectationMap::updateIntegral().

Referenced by getWinList(), main(), MStructure::rebuildExpMap(), and Brain::setupSearch().

347 {
348  if(&em != &m_EMap) m_EMap = em;
349  PropVec ub = m_EMap.getUB();
350  PropVec lb = m_EMap.getLB();
352  m_EMap.setLB(lb); m_EMap.setUB(ub);
353  m_PosMax = getPropPos(ub);
354  m_PosMin = getPropPos(lb);
355  //cout << "pos max=" << m_PosMax << " pos min=" << m_PosMin << endl;
358 
359 }
Point m_PosMax
Definition: Searcher.h:78
Point2D getPropPos(const PropVec &prop)
Definition: PropVec.h:13
static void correctLBUB(PropVec &lb, PropVec &ub)
Definition: ExpMap.cpp:193
Point m_PosRange
Definition: Searcher.h:78
void setUB(const PropVec &ub)
Definition: ExpMap.h:87
const PropVec & getLB() const
Definition: ExpMap.h:86
Point m_PosMin
Definition: Searcher.h:78
float updateIntegral()
Definition: ExpMap.cpp:167
ExpectationMap m_EMap
Definition: Searcher.h:68
const PropVec & getUB() const
Definition: ExpMap.h:85
void setLB(const PropVec &lb)
Definition: ExpMap.h:88
void Searcher::setShapeWeight ( float  shapeweight)
inline

Definition at line 46 of file Searcher.h.

References m_ShapeWeight.

Referenced by getQualityRange(), and MStructure::read().

46 { m_ShapeWeight = shapeweight; }
float m_ShapeWeight
Definition: Searcher.h:85
void Searcher::startSearch ( bool  dostart = true)

Definition at line 718 of file Searcher.cpp.

References clear(), m_Mode, MODE_PAUSE, MODE_RUN, and updateWinList().

719 {
720  if(dostart) {
721  cout << "starting searcher..." << endl;
722  clear();
723  m_Mode = MODE_RUN;
724  updateWinList();
725  } else m_Mode = MODE_PAUSE;
726 }
dword m_Mode
Definition: Searcher.h:80
void clear()
Definition: Searcher.cpp:126
std::map< dword, Winner > & updateWinList()
Definition: Searcher.cpp:675
bool Searcher::step ( float  dt)

Definition at line 288 of file Searcher.cpp.

References m_EMap, m_Mode, m_Population, m_Time, MODE_DONE, and MODE_PAUSE.

Referenced by Brain::evolve(), and MStructure::stepSearch().

289 {
290  if(!m_EMap) return true;
291  if(m_Mode == MODE_PAUSE) return false;
292  else if(m_Mode == MODE_DONE) return true;
293 
294  m_Time+=dt;
295  for(list<Model*>::iterator m=m_Population.begin();
296  m != m_Population.end(); m++)
297  {
298  (*m)->updateParticles(dt);
299  }
300  return m_Mode==MODE_DONE; // not yet done
301 }
dword m_Mode
Definition: Searcher.h:80
float m_Time
Definition: Searcher.h:77
std::list< Model * > m_Population
Definition: Searcher.h:69
ExpectationMap m_EMap
Definition: Searcher.h:68
bool Searcher::triggerTest ( int  mx,
int  my,
int  what 
)

Definition at line 728 of file Searcher.cpp.

References clear(), Model::getName(), getQualityRange(), SearcherParams::global, m_EMap, EMDistribution::m_Integral, m_Mode, m_Population, m_Representative, m_Time, MODE_DONE, MODE_PAUSE, MODE_RUN, and updateWinList().

Referenced by getExpectationMap(), and Brain::triggerTest().

729 {
730  switch(what)
731  {
732  case KEY_r:
733  clear();
734  break;
735  case KEY_s:
736  if(m_Mode == MODE_PAUSE || m_Mode == MODE_DONE) {
737  m_Mode = MODE_RUN;
738  cout << "run" << endl;
739  } else {
740  m_Mode = MODE_PAUSE;
741  cout << "pause" << endl;
742  }
743  break;
744  case KEY_h:
745  cout << m_Representative.getName() <<
747  ? "is done " : "is busy ") << m_EMap.m_Integral << endl;
748  m_Mode = MODE_PAUSE;
749  cout << "now set to rest" << endl;
750  break;
751  case KEY_w:
752  {
753  list<Model*>::iterator model = m_Population.begin();
754  while(model != m_Population.end())
755  {
756  list<Model*>::iterator nm = model; nm++;
757  if(!(*model)->isWinner()) {
758  remove(model);
759  } else {
760  cout << "winner at " << (*model)->getCenter() << " age "
761  << m_Time-(*model)->m_TimeStamp<<" s "
762  << "quality= " << (*model)->getQualityOfFit()
763  << " nmerges = " << (*model)->getInstCount()
764  << " ID = " << (*model)->getID()
765  << endl;
766  }
767  model = nm;
768  }
769  }
770  break;
771  case KEY_F4:
772  {
773  float lqof,hqof;
774  getQualityRange(lqof,hqof);
775  float qth = (lqof+hqof)*0.5;
776  list<Model*>::iterator model = m_Population.begin();
777  while(model != m_Population.end())
778  {
779  list<Model*>::iterator nm = model; nm++;
780  if((*model)->getQualityOfFit() < qth) {
781  remove(model);
782  }
783  model = nm;
784  }
785  }
786  break;
787  default:
788  return false;
789  }
790  updateWinList();
791  return true;
792 }
float m_Integral
Definition: ExpMap.h:67
dword m_Mode
Definition: Searcher.h:80
void getQualityRange(float &lqof, float &hqof, float shapeweight=-1) const
Definition: Searcher.cpp:649
float m_Time
Definition: Searcher.h:77
void clear()
Definition: Searcher.cpp:126
std::list< Model * > m_Population
Definition: Searcher.h:69
Model m_Representative
Definition: Searcher.h:65
ExpectationMap m_EMap
Definition: Searcher.h:68
const std::string & getName() const
Definition: Model.h:81
std::map< dword, Winner > & updateWinList()
Definition: Searcher.cpp:675
std::map< dword, Winner > & Searcher::updateWinList ( )
protected

Definition at line 675 of file Searcher.cpp.

References m_Population, and m_Winners.

Referenced by getShapeWeight(), operator=(), startSearch(), and triggerTest().

676 {
677  m_Winners.clear();
678  for(list<Model*>::iterator m = m_Population.begin();
679  m!=m_Population.end(); m++)
680  {
681  if((*m)->isWinner())
682  m_Winners[(*m)->getID()] = Winner(*m);
683  }
684  return m_Winners;
685 }
std::map< dword, Winner > m_Winners
Definition: Searcher.h:83
Definition: ExpMap.h:10
std::list< Model * > m_Population
Definition: Searcher.h:69

Member Data Documentation

PropVec Searcher::m_AvgWinner
protected

Definition at line 66 of file Searcher.h.

Referenced by buildBins(), cleanFlags(), distribute(), and operator=().

float Searcher::m_BinDist
protected

Definition at line 73 of file Searcher.h.

Referenced by buildBins(), buildClusters(), and operator=().

std::vector< MBin > Searcher::m_Bins
protected

Definition at line 71 of file Searcher.h.

Referenced by buildBins(), buildClusters(), clear(), and operator=().

int Searcher::m_BinsX
protected

Definition at line 72 of file Searcher.h.

Referenced by buildBins(), buildClusters(), clear(), getBindex(), and operator=().

int Searcher::m_BinsY
protected

Definition at line 72 of file Searcher.h.

Referenced by buildBins(), clear(), getBindex(), and operator=().

std::list< MBin > Searcher::m_Clusters
protected

Definition at line 74 of file Searcher.h.

Referenced by buildClusters(), and selectWinners().

MBin* Searcher::m_CurCluster
protected

Definition at line 76 of file Searcher.h.

Referenced by buildClusters().

ExpectationMap Searcher::m_EMap
protected
float Searcher::m_EvolveT
protected

Definition at line 81 of file Searcher.h.

Referenced by clear(), operator=(), and Searcher().

PropVec Searcher::m_MaxModel
protected

Definition at line 67 of file Searcher.h.

Referenced by buildBins(), and cleanFlags().

PropVec Searcher::m_MinModel
protected

Definition at line 67 of file Searcher.h.

Referenced by buildBins(), and cleanFlags().

dword Searcher::m_Mode
protected

Definition at line 80 of file Searcher.h.

Referenced by evolve(), operator=(), searchDone(), startSearch(), step(), and triggerTest().

float Searcher::m_MutateRate
protected
int Searcher::m_NClusters
protected
dword Searcher::m_NextWinID
protected

Definition at line 84 of file Searcher.h.

Referenced by evolve(), and operator=().

int Searcher::m_NPop
protected

Definition at line 70 of file Searcher.h.

Referenced by add(), clear(), evolve(), operator=(), and remove().

std::list<Model*> Searcher::m_Population
protected
Point Searcher::m_PosMax
protected

Definition at line 78 of file Searcher.h.

Referenced by operator=(), and setExpectationMap().

Point Searcher::m_PosMin
protected

Definition at line 78 of file Searcher.h.

Referenced by operator=(), and setExpectationMap().

Point Searcher::m_PosRange
protected

Definition at line 78 of file Searcher.h.

Referenced by buildBins(), operator=(), and setExpectationMap().

Model Searcher::m_Representative
protected
float Searcher::m_ShapeWeight
protected
PropVec Searcher::m_StdWinner
protected

Definition at line 66 of file Searcher.h.

Referenced by buildBins(), cleanFlags(), distribute(), and operator=().

float Searcher::m_Time
protected
std::map<dword,Winner> Searcher::m_Winners
protected

Definition at line 83 of file Searcher.h.

Referenced by clear(), draw(), evolve(), getWinList(), getWinner(), operator=(), and updateWinList().

enum { ... } Searcher::SMode

The documentation for this class was generated from the following files: