11 #define SRCH_CYCLE_T 1.0f 12 #define SRCH_MAXPOP 250 14 #define SRCH_NCLUSTERS 60 15 #define SRCH_NEW_SPAWNS 100 16 #define SRCH_NEW_SPAWNS_THRED 0.90f 17 #define SRCH_CLUSTERTH 0.6f 18 #define SRCH_CLUSTERDPOS 0.3f 19 #define SRCH_CLUSTERDMELT 0.05f 20 #define SRCH_CLUSTERDSCALE 0.3f 21 #define SRCH_CLUSTERDDIR 0.5f 22 #define SRCH_RELBINDIST 0.75f 24 #define SRCH_MUTATE_SPAWNS 0 25 #define SRCH_MUTATE_THRED 0.99f 26 #define SRCH_MUTATE_RATE 0.3f 27 #define SRCH_MUTATE_HL 30 28 #define SRCH_MUTATE_PDIR 0.5f 29 #define SRCH_MUTATE_PPOS 0.4f 30 #define SRCH_MUTATE_PNOISE 0.2f 31 #define SRCH_MUTATE_NOISERATE 0.1f 32 #define SRCH_MUTATE_PPROP 0.3f 33 #define SRCH_MUTATE_PROPRATE 0.5f 35 #define SRCH_RATINGTH 0.001f 36 #define SRCH_SHAPEWEIGHT 0.1f 37 #define SRCH_SCALESTD 1.f 39 #define PARA_PCTH 0.05f 42 #define PARA_MAXSHOOT 100 50 if(!lhs || !rhs)
return true;
56 class NMerge :
public binary_function<Model*, Model*, bool> {
59 m_DType(dtype), m_MaxD(maxd) {};
60 bool operator() (
const Model* lhs,
const Model* rhs)
const {
62 if(lhs == rhs)
return true;
64 register float dist = lhs->
distance(*rhs, m_DType);
77 m_NextWinID(
Winner::WID_FIRST),
97 if(&rhs ==
this)
return *
this;
103 for(list<Model*>::const_iterator gi=rhs.
m_Population.begin();
155 list<Model*>::iterator ci = mi++;
172 for(list<Model*>::const_iterator m =
m_Population.begin();
176 slowlive += (*m)->getLiveliness();
197 if(*m == lastmodel) pastlast=
true;
198 list<Model*>::iterator nm = m; nm++;
203 if(
m_NPop>1) {
remove(m); extrakill++; }
204 }
else if((*m)->isWinner()) {
205 PropVec propvec((*m)->getProperties());
225 float qth = (*m)->getQualityOfFit()*threduce;
236 if(misses%nspawns==0) qth*=threduce;
242 if(misses>nspawns)
DUMP(misses)<<
" for mutation"<<endl;
245 }
else if((*m)->getLiveliness()<slowlive) {
248 }
else if(
m_NPop>1 && (*m)->isLooser() &&
261 float qth = hqof*threduce;
270 if(misses%nspawns==0) qth*=threduce;
298 (*m)->updateParticles(dt);
309 #define _PROP_MUTATION_ 310 #ifdef _PROP_MUTATION_ 339 -radius+
frand(2*radius)));
387 for(list<Model*>::iterator model =
m_Population.begin();
390 (*model)->setOldState();
393 Point c = (*model)->getCenter();
400 for(
int py=by-MAXRAD; py<=by+
MAXRAD; py++) {
404 m_Bins[index].push_back(*model);
412 m_Bins[index].push_back(*model);
430 else m_MergeDist = m_MergeDistMM*100;
431 int nmelt = 0, nmerge = 0;
433 if(maxclusters == 0) maxclusters = numeric_limits<int>::max();
435 && (*model)->getQualityOfFit()>cqth
444 PropVec cprop = (*model)->getPropertiesMM();
450 Point c = (*model)->getCenter();
453 int binradius = (int)ceil(mdpos/
m_BinDist);
454 for(
int px=bx-binradius; px<=bx+binradius; px++) {
456 for(
int py=by-binradius; py<=by+binradius; py++) {
460 MBin::iterator be =
m_Bins[index].begin();
461 while(be !=
m_Bins[index].end()) {
462 MBin::iterator nextbe = be;
465 PropVec prop = (*be)->getPropertiesMM();
474 if(dscale>1) dscale = 1-1/dscale;
475 else dscale = 1-dscale;
476 if(dpos < mdpos && drot < mdrot &&
478 if(dpos < m_MergeDistMM &&
484 (*model)->mergeModel(**be);
493 }
else m_Bins[index].erase(be);
515 dword m_NBinWinners = 1;
516 for(list< MBin >::iterator cluster =
m_Clusters.begin();
518 if(!cluster->empty()) {
519 MBin::iterator crep = cluster->begin();
522 (*crep)->setOldState(
false);
523 if(!(*crep)->isWinner()) {
527 (*crep)->setWinner(
true);
529 (*crep)->setLooser(
false);
531 }
else TRACE(
"DELETED CLUSTER WINNER????????");
533 while(crep != cluster->end()) {
535 (*crep)->setOldState(
false);
536 if((*crep)->isWinner()) (*crep)->setWinner(
false);
537 if(!(*crep)->isLooser()) {
538 (*crep)->setLooser(
true,
m_Time);
560 list<Model*>::iterator nm = model; nm++;
576 if((*model)->isOldState()) {
580 }
else if((*model)->isWinner()) {
583 PropVec winprop = (*model)->getProperties();
588 if(!(*model)->isLooser())
589 (*model)->setLooser(
true,
m_Time);
610 cout <<
"representative age: " 612 <<
" (search time "<<
m_Time<<
" s)"<<endl;
613 cout << killcount<<
" loosers and " << wincount <<
" winners."<<endl;
620 for(list<Model*>::iterator model =
m_Population.begin();
623 (*model)->reattachSensors();
637 for(
int i=0; i<n; i++) {
650 float shapeweight)
const 656 bool cw = (shapeweight!=-1);
659 for(list<Model*>::const_iterator m =
m_Population.begin();
662 if(cw) (*m)->setShapeWeight(shapeweight);
663 if((*m)->getQualityOfFit()>hqof) hqof=(*m)->getQualityOfFit();
664 if((*m)->getQualityOfFit()<lqof) lqof=(*m)->getQualityOfFit();
670 map<dword,Winner>::const_iterator wi =
m_Winners.find(
id);
672 else return &wi->second;
690 for(list<Model*>::const_iterator m =
m_Population.begin();
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);
698 glColor4f(0.9,0.9,0.0,0.3);
703 glColor4f(0.1,0.9,0.0,1.0);
704 for(list<Model*>::const_iterator m =
m_Population.begin();
712 glColor4f(1.0f, 0.0f, 0.5f,1.0f);
721 cout <<
"starting searcher..." << endl;
738 cout <<
"run" << endl;
741 cout <<
"pause" << endl;
749 cout <<
"now set to rest" << endl;
756 list<Model*>::iterator nm = model; nm++;
757 if(!(*model)->isWinner()) {
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()
775 float qth = (lqof+hqof)*0.5;
779 list<Model*>::iterator nm = model; nm++;
780 if((*model)->getQualityOfFit() < qth) {
834 os <<
"searcher" << endl;
836 os<<
" evolvecycle "<<m_EvolveCycle<<endl;
837 else if(showcomment) os<<
" # evolvecycle "<<m_EvolveCycle<<endl;
839 os<<
" maxpop "<< m_MaxPop<<endl;
840 else if(showcomment) os<<
" # maxpop "<<m_MaxPop<<endl;
842 os<<
" nspawns "<< m_NSpawns<<endl;
843 else if(showcomment) os<<
" # nspawns "<<m_NSpawns<<endl;
845 os<<
" nspawnsthred "<< m_NSpawnsTHRed<<endl;
846 else if(showcomment) os<<
" # nspawnsthred "<<m_NSpawnsTHRed<<endl;
849 else if(showcomment) os<<
" # nclusters "<<
m_NClusters<<endl;
851 os<<
" clusterth "<< m_ClusterTH<<endl;
852 else if(showcomment) os<<
" # clusterth "<<m_ClusterTH<<endl;
854 os<<
" clusterdpos "<< m_ClusterDPos<<endl;
855 else if(showcomment) os<<
" # clusterdpos "<<m_ClusterDPos<<endl;
857 os<<
" clusterdscale "<< m_ClusterDScale<<endl;
858 else if(showcomment) os<<
" # clusterdscale "<<m_ClusterDScale<<endl;
860 os<<
" clusterddir "<< m_ClusterDDir<<endl;
861 else if(showcomment) os<<
" # clusterddir "<<m_ClusterDDir<<endl;
863 os<<
" clustermeltdist "<< m_ClusterMeltDist<<endl;
864 else if(showcomment) os<<
" # clustermeltdist "<<m_ClusterMeltDist<<endl;
866 os<<
" relbindist "<< m_RelBinDist<<endl;
867 else if(showcomment) os<<
" # relbindist "<<m_RelBinDist<<endl;
870 else if(showcomment) os<<
" # mutaterate "<<
m_MutateRate<<endl;
872 os<<
" mutatehl "<< m_MutateHL<<endl;
873 else if(showcomment) os<<
" # mutatehl "<<m_MutateHL<<endl;
875 os<<
" mutatespawns "<< m_MutateSpawns<<endl;
876 else if(showcomment) os<<
" # mutatespawns "<<m_MutateSpawns<<endl;
878 os<<
" mutatethred "<< m_MutateTHRed<<endl;
879 else if(showcomment) os<<
" # mutatethred "<<m_MutateTHRed<<endl;
881 os<<
" mutatepdir "<< m_MutatePDir<<endl;
882 else if(showcomment) os<<
" # mutatepdir "<<m_MutatePDir<<endl;
884 os<<
" mutateppos "<< m_MutatePPos<<endl;
885 else if(showcomment) os<<
" # mutateppos "<<m_MutatePPos<<endl;
887 os<<
" mutatepnoise "<< m_MutatePNoise<<endl;
888 else if(showcomment) os<<
" # mutatepnoise "<<m_MutatePNoise<<endl;
890 os<<
" mutatenoiserate "<< m_MutateNoiseRate<<endl;
891 else if(showcomment) os<<
" # mutatenoiserate "<<m_MutateNoiseRate<<endl;
893 os<<
" mutatepprop "<< m_MutatePProp<<endl;
894 else if(showcomment) os<<
" # mutatepprop "<<m_MutatePProp<<endl;
896 os<<
" mutateproprate "<< m_MutatePropRate<<endl;
897 else if(showcomment) os<<
" # mutateproprate "<<m_MutatePropRate<<endl;
900 else if(showcomment) os<<
" # shapeweight "<<
m_ShapeWeight<<endl;
902 os<<
" solver "<< m_ParaSolver<<endl;
903 else if(showcomment) os<<
" # solver "<<m_ParaSolver<<endl;
905 os<<
" ratingth "<< m_RatingTH<<endl;
906 else if(showcomment) os<<
" # ratingth "<<m_RatingTH<<endl;
908 os<<
" pcth "<< m_PCTH<<endl;
909 else if(showcomment) os<<
" # pcth "<<m_PCTH<<endl;
911 os<<
" pdist "<< m_PDist<<endl;
912 else if(showcomment) os<<
" # pdist "<<m_PDist<<endl;
914 os<<
" scalestd "<< m_ScaleStd<<endl;
915 else if(showcomment) os<<
" # scalestd "<<m_ScaleStd<<endl;
917 os<<
" maxshoot "<< m_MaxShoot <<endl;
918 else if(showcomment) os<<
" # maxshoot "<<m_MaxShoot<<endl;
926 bool issearcher =
false, goon=
true;
928 if(is.
getKey() ==
"searcher") issearcher =
true;
929 else if(!issearcher) {
932 }
else if(is.
getKey() ==
"evolvecycle") {
934 }
else if(is.
getKey() ==
"maxpop") {
936 }
else if(is.
getKey() ==
"nspawns") {
938 }
else if(is.
getKey() ==
"nspawnsthred") {
940 }
else if(is.
getKey() ==
"nclusters") {
942 }
else if(is.
getKey() ==
"clusterth") {
944 }
else if(is.
getKey() ==
"clusterdpos") {
946 }
else if(is.
getKey() ==
"clusterdscale") {
948 }
else if(is.
getKey() ==
"clusterddir") {
950 }
else if(is.
getKey() ==
"clustermeltdist") {
952 }
else if(is.
getKey() ==
"relbindist") {
954 }
else if(is.
getKey() ==
"mutaterate") {
956 }
else if(is.
getKey() ==
"mutatehl") {
958 }
else if(is.
getKey() ==
"mutatespawns") {
960 }
else if(is.
getKey() ==
"mutatethred") {
962 }
else if(is.
getKey() ==
"mutatepdir") {
964 }
else if(is.
getKey() ==
"mutateppos") {
966 }
else if(is.
getKey() ==
"mutatepnoise") {
968 }
else if(is.
getKey() ==
"mutatenoiserate") {
970 }
else if(is.
getKey() ==
"mutatepprop") {
972 }
else if(is.
getKey() ==
"mutateproprate") {
974 }
else if(is.
getKey() ==
"shapeweight") {
976 }
else if(is.
getKey() ==
"solver") {
978 }
else if(is.
getKey() ==
"ratingth") {
980 }
else if(is.
getKey() ==
"pcth") {
982 }
else if(is.
getKey() ==
"pdist") {
984 }
else if(is.
getKey() ==
"scalestd") {
986 }
else if(is.
getKey() ==
"maxshoot") {
988 }
else if(is.
getKey() ==
"end") goon =
false;
dword m_MutateSpawns
number of spawns when mutating a shape
float m_RelBinDist
distance of bins relative to representative radius
float m_ClusterMeltDist
maximum Hausdorff distance in mm for melting two shapes
std::list< Model * >::iterator & remove(std::list< Model * >::iterator &mi)
void startSearch(bool dostart=true)
float m_ShapeWeight
influence of shape deformation on QOF
std::vector< MBin > m_Bins
float getGeneration(const Model *model) const
bool buildBins(float bindist=0.f)
void setExpectationMap(const ExpectationMap &em)
float getQualityOfFit() const
T & fromString(const std::string &str, T &v)
void clear(bool oldonly=false)
const PropVec & getProperties() const
float getStdRadius(const Point ¢er) const
Returns mean squared distance from centroid.
void pushRotate(const Point &c, float angle)
bool triggerTest(int mx, int my, int what)
Model * generateInstance() const
void setShapeWeight(float shapeweight)
void adaptProportion(float ratio)
overall rest lengths sum is adapted to overall edge lengths by ratio
Point2D getPropPos(const PropVec &prop)
static void correctLBUB(PropVec &lb, PropVec &ub)
void getQualityRange(float &lqof, float &hqof, float shapeweight=-1) const
float m_MutateRate
initial mutation rate
float getPropScale(const PropVec &prop)
float ratePropVec(const PropVec &prop, Winner *winner=NULL) const
const std::string & getValue() const
float m_ClusterDScale
maximum relative difference in scale to cluster representative
float m_ClusterTH
least quality of cluster relative to the best
dword m_NSpawns
number of new spawned shapes at each cycle
float m_NSpawnsTHRed
threshold reduction factor for new spawns
static SearcherParams global
#define SRCH_CLUSTERDMELT
dword m_NClusters
number of clusters (winners) determined at each cycle
#define SRCH_CLUSTERDSCALE
std::ostream & write(std::ostream &os, bool showcomment=false) const
PropVec & setPropDir(PropVec &prop, float dir)
void reattachSensors()
get sensors from sensor collection
#define SRCH_MUTATE_PROPRATE
PropVec & setPropPos(PropVec &prop, const Point2D &p)
VT & clampUB(const VT &ub)
#define SRCH_NEW_SPAWNS_THRED
float sum() const
returns 1-norm
void setUB(const PropVec &ub)
float m_MutateTHRed
threshold reduction factor for mutated spawns
float getPropDir(const PropVec &prop)
#define SRCH_MUTATE_PNOISE
std::map< dword, Winner > m_Winners
bool operator()(Model *const &lhs, Model *const &rhs) const
int getBindex(int bx, int by, bool &culled=*((bool *) NULL)) const
int distribute(int n=-1, float qth=0, bool count=false)
const std::string & getKey() const
const Winner * getWinner(dword id) const
NMerge(float maxd, enum Model::DistType dtype=Model::DIST_XYS)
float m_EvolveCycle
time in seconds for one evolution cycle
const PropVec & getLB() const
SearcherParams & getSearchPara()
std::list< Model * > m_Population
void adaptProperties(const PropVec &prop)
VT & clampLB(const VT &lb)
Model & getRepresentative()
void draw(bool drawPoints=false) const
Draw using OpenGL.
float distance(const Model &rhs, enum Model::DistType kind=DIST_POINTS) const
std::list< MBin > m_Clusters
#define SRCH_MUTATE_NOISERATE
const PropVec & getUB() const
#define SRCH_MUTATE_SPAWNS
float m_ClusterDDir
maximum difference in direction in $$
float m_ClusterDPos
maximum distance of shapes in a cluster (relative to shape radius)
Searcher & operator=(const Searcher &rhs)
void setInstCount(dword ic)
dword m_MaxPop
maximum population count
void clear()
remove and destroy all geometry information (nodes and edges)
float mapAnglePI(float a)
const std::string & getName() const
Model & mutate(Model &model, float rate=1) const
void pushLine(const std::string &line)
std::map< dword, Winner > & updateWinList()
#define SRCH_MUTATE_PPROP
dword getDataScale() const
void setLB(const PropVec &lb)
#define SRCH_MUTATE_THRED
float m_TimeStamp
time stamps (see. TTimeStamp)
void push(const Point &t)