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

#include <StructTable.h>

Collaboration diagram for StructTable:
Collaboration graph
[legend]

Public Types

typedef std::map< std::string, std::set< std::string > > Interpretations
 
typedef std::map< dword, StructPathNodePaths
 

Public Member Functions

 StructTable (Brain &brain, const std::string &filename=std::string())
 
 ~StructTable ()
 
void clear ()
 
void attachBrain (Brain &brain)
 
dataset_ptr getDataset ()
 
SensorCollectiongetSensors ()
 
void reattachSensors ()
 
void adaptDataScale ()
 
bool load (const std::string &filename)
 
bool read (ParseFile &is)
 
void write (std::ostream &os) const
 
const std::string & getFilename () const
 
const std::string & getPath () const
 
std::map< std::string, MStructure > & getStructs ()
 
const std::map< std::string, MStructure > & getStructs () const
 
bool hasStructure (const std::string &sname) const
 
const MStructuregetStructure (const std::string &sname) const
 
MStructuregetNextStruct (int dir=1, bool wrap=true)
 
void evalRelations ()
 
void rebuildExpMaps ()
 
void draw () const
 
void startSearch (bool dostart=true)
 
int searchDone () const
 
bool stepSearch (float dt)
 
bool triggerTest (int mx, int my, int what)
 
float findBestConnection ()
 
bool findBestConnection (StructPath &path, const Winner &winner) const
 
const StructPathgetBestPath () const
 
const std::string & getBestInterpretation () const
 
const std::map< std::string, StructPath > & getIPaths () const
 
void setShownIP (const std::string &curip) const
 
const std::string & getShownIP () const
 
bool showNextIP (int dir=1) const
 

Static Public Member Functions

static DMatrixfadjustByAvgDir (DMatrixf &mat)
 

Protected Types

enum  TimeMarks { TM_UPDEM, TM_TIMEOUT, TM_LAST }
 
enum  StateFlags { ST_RUN =1, ST_RESULT =2, ST_DONE =4, ST_TIMEOUT =16 }
 

Protected Member Functions

void connectSubSuper ()
 
bool readInterpreations (ParseFile &is)
 

Protected Attributes

std::map< std::string, MStructurem_Structs
 
std::string m_FileName
 
std::string m_Path
 
Brainm_Brain
 
std::string m_CurStruct
 
StructPath m_BestPath
 
float m_Time
 
dword m_State
 
std::vector< float > m_TMarks
 
Interpretations m_Interpretations
 
std::map< std::string, StructPathm_IPaths
 
std::string m_BestIP
 
std::string m_CurIP
 
std::map< std::string, NodePathsm_NodePaths
 

Friends

ParseFileoperator>> (ParseFile &is, StructTable &st)
 
std::ostream & operator<< (std::ostream &os, const StructTable &st)
 

Detailed Description

Definition at line 49 of file StructTable.h.

Member Typedef Documentation

typedef std::map<std::string, std::set<std::string> > StructTable::Interpretations

Definition at line 51 of file StructTable.h.

Definition at line 52 of file StructTable.h.

Member Enumeration Documentation

enum StructTable::StateFlags
protected
Enumerator
ST_RUN 
ST_RESULT 
ST_DONE 
ST_TIMEOUT 

Definition at line 106 of file StructTable.h.

enum StructTable::TimeMarks
protected
Enumerator
TM_UPDEM 
TM_TIMEOUT 
TM_LAST 

Definition at line 105 of file StructTable.h.

Constructor & Destructor Documentation

StructTable::StructTable ( Brain brain,
const std::string &  filename = std::string() 
)

Definition at line 18 of file StructTable.cpp.

19 {
20  m_TMarks.clear();
21  m_TMarks.resize(TM_LAST, 0.0f);
22  attachBrain(brain);
23  load(filename);
24 }
void attachBrain(Brain &brain)
Definition: StructTable.h:57
std::vector< float > m_TMarks
Definition: StructTable.h:115
bool load(const std::string &filename)
Definition: StructTable.cpp:69
StructTable::~StructTable ( )

Definition at line 26 of file StructTable.cpp.

27 {
28  clear();
29 }
void clear()
Definition: StructTable.cpp:31

Member Function Documentation

void StructTable::adaptDataScale ( )

Definition at line 60 of file StructTable.cpp.

Referenced by Brain::attachBrowseData().

61 {
62  for(map<string,MStructure>::iterator si = m_Structs.begin();
63  si != m_Structs.end(); si++)
64  {
65  si->second.getModel().adaptDataScale();
66  }
67 }
std::map< std::string, MStructure > m_Structs
Definition: StructTable.h:107
DMatrixf & StructTable::adjustByAvgDir ( DMatrixf mat)
static

Definition at line 216 of file StructTable.cpp.

References Point2D::angle(), DMatrix< T >::getData(), mapAnglePI(), Point2D::rotate(), and DMatrix< T >::size().

Referenced by SubStructure::analyseTF().

217 {
218  Point2D dir(0,0);
219  DMatrixf::iterator el = mat.getData().begin();
220  for(dword ind=0; ind<mat.size(); ind++, el++)
221  dir += Point2D(1,0).rotate(*el);
222  float avgdir = dir.angle();
223  el = mat.getData().begin();
224  for(dword ind=0; ind<mat.size(); ind++, el++)
225  *el = mapAnglePI(*el, avgdir);
226  return mat;
227 }
float angle(const Point2D &rhs=Point2D(1, 0)) const
Definition: Point.h:93
const Point2D rotate(float angle) const
Definition: Point.h:211
unsigned long dword
Definition: simpletypes.h:6
dword size() const
Definition: DMatrix.h:44
std::vector< float >::iterator iterator
Definition: DMatrix.h:16
Definition: Point.h:16
float mapAnglePI(float a)
Definition: mathutil.h:107
std::vector< T > & getData()
Definition: DMatrix.h:48
void StructTable::attachBrain ( Brain brain)
inline

Definition at line 57 of file StructTable.h.

57 { m_Brain = &brain; }
Brain * m_Brain
Definition: StructTable.h:110
void StructTable::clear ( )

Definition at line 31 of file StructTable.cpp.

32 {
33  m_Structs.clear();
34  m_CurStruct.clear();
35  m_Time = 0;
36  m_State = 0;
37  m_TMarks.clear();
38  m_TMarks.resize(TM_LAST, 0.0f);
39  m_BestPath.clear();
40  m_Interpretations.clear();
41 }
Interpretations m_Interpretations
Definition: StructTable.h:116
StructPath m_BestPath
Definition: StructTable.h:112
std::map< std::string, MStructure > m_Structs
Definition: StructTable.h:107
float m_Time
Definition: StructTable.h:113
std::vector< float > m_TMarks
Definition: StructTable.h:115
void clear()
std::string m_CurStruct
Definition: StructTable.h:111
dword m_State
Definition: StructTable.h:114
void StructTable::connectSubSuper ( )
protected

Definition at line 206 of file StructTable.cpp.

207 {
208  for(map<string,MStructure>::iterator si = m_Structs.begin();
209  si != m_Structs.end(); si++)
210  si->second.refSubSuper(true); // just clear super-list
211  for(map<string,MStructure>::iterator si = m_Structs.begin();
212  si != m_Structs.end(); si++)
213  si->second.refSubSuper(); // update super-list of substructs
214 }
std::map< std::string, MStructure > m_Structs
Definition: StructTable.h:107
void StructTable::draw ( ) const

Definition at line 377 of file StructTable.cpp.

References Model::draw(), and Winner::m_Model.

Referenced by Brain::drawAllModels().

378 {
379  const string& ipname = getShownIP();
380  map<string,StructPath>::const_iterator spath = m_IPaths.find(ipname);
381  for(map<string,MStructure>::const_iterator si = m_Structs.begin();
382  si != m_Structs.end(); si++)
383  {
384  if((m_State & ST_RESULT) == 0) si->second.m_Searcher.draw();
385  if(spath != m_IPaths.end()) {
386  StructPath::const_iterator wi = spath->second.find(si->first);
387  if(wi != spath->second.end()) {
388  const Winner *nw = si->second.getWinner(wi->second);
389  if(nw && nw->m_Model) {
390  glColor3f(1,.1,0);
391  glLineWidth(4.0f);
392  nw->m_Model->draw();
393  }
394  }
395  }
396  }
397 }
const std::string & getShownIP() const
Definition: StructTable.h:97
std::map< std::string, MStructure > m_Structs
Definition: StructTable.h:107
Model * m_Model
Definition: ExpMap.h:36
Definition: ExpMap.h:10
void draw(bool drawPoints=false) const
Draw using OpenGL.
Definition: Model.cpp:542
std::map< std::string, StructPath > m_IPaths
Definition: StructTable.h:117
dword m_State
Definition: StructTable.h:114
void StructTable::evalRelations ( )

Definition at line 187 of file StructTable.cpp.

Referenced by Brain::triggerTest().

188 {
189 // int ret = matlabCall(string("addpath ")+m_Path + ", antpca");
190 // DUMP(ret);
191  for(map<string,MStructure>::iterator si = m_Structs.begin();
192  si != m_Structs.end(); si++)
193  {
194  si->second.buildAllStats();
195  }
196  //rebuildExpMaps();
197 }
std::map< std::string, MStructure > m_Structs
Definition: StructTable.h:107
float StructTable::findBestConnection ( )

Definition at line 400 of file StructTable.cpp.

References StructPath::blockOtherPaths(), StructPath::getRelGoodness(), MStructure::getSearcher(), Searcher::getWinList(), and StructPath::m_Goodness.

401 {
402  if(m_Structs.empty()) return m_BestPath.m_Goodness;
404  m_BestPath.clear();
405  for(map<string,MStructure>::iterator si = m_Structs.begin();
406  si != m_Structs.end(); si++)
407  {
408  si->second.verifyWinnerRating();
409  }
410 
411  m_IPaths.clear();
412  for(Interpretations::const_iterator ip=m_Interpretations.begin();
413  ip != m_Interpretations.end(); ip++)
414  { // for each interpretation
415  cout << "scanning interpretation " << ip->first << endl;
416  m_NodePaths.clear();
417  for(map<string,MStructure>::iterator si = m_Structs.begin();
418  si != m_Structs.end(); si++)
419  { // for each structure
420  MStructure& st = si->second;
421  StructPath bestpath;
422  const map<dword,Winner>& winners = st.getSearcher().getWinList();
423  for(map<dword,Winner>::const_iterator wi = winners.begin();
424  wi != winners.end(); wi++)
425  { // for each winner in current structure
426  StructPath path;
427  path.blockOtherPaths(ip->second, *this);
428  findBestConnection(path, wi->second);
429  if(path.m_Goodness > bestpath.m_Goodness)
430  {
431  bestpath = path;
432  }
433  }
434  if(bestpath.m_Goodness > m_IPaths[ip->first].m_Goodness)
435  {
436  m_IPaths[ip->first] = bestpath;
437  }
438  cout << " best cost for " << si->first << ": "
439  << bestpath.m_Goodness
440  << " (" << bestpath.getRelGoodness() << ") " << endl;
441  //<< " length: "<<bestpath.size()<<endl;
442  }
443  if(m_IPaths[ip->first].getRelGoodness() > m_BestPath.getRelGoodness())
444  {
445  m_BestPath = m_IPaths[ip->first];
446  m_BestIP = ip->first;
447  }
448  }
449  cout << "best interpretation is " << m_BestIP << endl;
450  m_BestPath.protectWinners(*this);
451  m_BestPath.print(cout, *this);
452 // DUMP(m_BestPath.m_Goodness);
453 // DUMP(m_BestPath.size());
454 // cout << "showing path" << endl;
455 // for(StructPath::const_iterator ps=m_BestPath.begin();
456 // ps != m_BestPath.end(); ps++)
457 // {
458 // cout << ps->first << ": " << ps->second.m_BestRating << endl;
459 // }
460  return m_BestPath.getRelGoodness();
461 }
std::map< dword, Winner > & getWinList()
Definition: Searcher.h:30
float findBestConnection()
Interpretations m_Interpretations
Definition: StructTable.h:116
StructPath m_BestPath
Definition: StructTable.h:112
std::map< std::string, MStructure > m_Structs
Definition: StructTable.h:107
float m_Goodness
goodness of path
Definition: StructTable.h:42
float getRelGoodness() const
Definition: StructTable.h:37
const Searcher & getSearcher() const
Definition: MStruct.h:73
void blockOtherPaths(const std::set< std::string > &freepath, const StructTable &structs)
std::ostream & print(std::ostream &os, const StructTable &structs) const
std::map< std::string, NodePaths > m_NodePaths
Definition: StructTable.h:120
std::string m_BestIP
Definition: StructTable.h:118
void unprotectWinners(StructTable &structs)
std::map< std::string, StructPath > m_IPaths
Definition: StructTable.h:117
void clear()
void protectWinners(StructTable &structs)
bool StructTable::findBestConnection ( StructPath path,
const Winner winner 
) const

Definition at line 463 of file StructTable.cpp.

References StructPath::branch(), Model::getQualityOfFit(), MStructure::getWeight(), MStructure::getWinner(), StructPath::m_Goodness, StructPath::m_Maxness, Winner::m_Model, SubStructure::m_RateTH, SubStructure::m_RateWeight, Winner::m_Ratings, Winner::m_StructName, MStructure::m_SubStructures, Winner::m_WinnerID, StructPath::merge(), TRACE0, Winner::WID_EMPTY, and Winner::WID_FRAME.

465 {
466  if(winner.m_WinnerID == Winner::WID_EMPTY) { TRACE0; return false; }
467  const string& csname = winner.m_StructName;
468  if(csname.empty()) { TRACE0; return false; }
469  if(path[csname] != Winner::WID_EMPTY) {
470  return false; // termination criterion
471  }
472  if(winner.m_WinnerID == Winner::WID_FRAME) {
473  path[csname] = winner.m_WinnerID;
474  return true; // confirm, but don't add goodness
475  }
476  NodePaths &np = m_NodePaths[csname];
477  NodePaths::const_iterator wpath = np.find(winner.m_WinnerID);
478  if(wpath != np.end()) { // we already have this path!
479  path.merge(wpath->second);
480  return true;
481  }
482  StructPath &bestpath = np[winner.m_WinnerID];
483  bestpath = path.branch();
484 
485  const MStructure& cstruct = getStructure(csname);
486  bestpath[csname] = winner.m_WinnerID;
487  bestpath.m_Goodness += cstruct.getWeight()
488  *winner.m_Model->getQualityOfFit();
489  //* cstruct.m_Searcher.relativeQOF(winner.m_Model->getQualityOfFit());
490  bestpath.m_Maxness += cstruct.getWeight();
491 
492  for(Winner::Ratings::const_iterator wr = winner.m_Ratings.begin();
493  wr != winner.m_Ratings.end(); wr++)
494  { // for each rating structure
495  map<string,MStructure>::const_iterator sti =
496  m_Structs.find(wr->first);
497  if(sti != m_Structs.end()) {
498  const MStructure& refstruct = sti->second;
499  const SubStructure& subs =
500  refstruct.m_SubStructures.find(csname)->second;
501  StructPath spath = bestpath;
502  for(map<dword,float>::const_iterator wi = wr->second.begin();
503  wi != wr->second.end(); wi++)
504  {
505  const Winner* nextWinner = refstruct.getWinner(wi->first);
506  StructPath cpath = spath;
507  if(nextWinner && wi->second > subs.m_RateTH) {
508  if(findBestConnection(cpath, *nextWinner)) {
509  cpath.m_Goodness += subs.m_RateWeight*wi->second;
510  cpath.m_Maxness += subs.m_RateWeight;
511  }
512  }
513  if(cpath.m_Goodness > bestpath.m_Goodness)
514  bestpath = cpath;
515  }
516  }
517  }
518  path.merge(bestpath);
519  return true;
520 }
std::string m_StructName
Definition: ExpMap.h:38
void merge(const StructPath &mp)
float getQualityOfFit() const
Definition: Model.cpp:1204
std::map< std::string, SubStructure > m_SubStructures
Definition: MStruct.h:122
const Winner * getWinner(dword wid) const
Definition: MStruct.cpp:80
float findBestConnection()
std::map< std::string, MStructure > m_Structs
Definition: StructTable.h:107
float m_Goodness
goodness of path
Definition: StructTable.h:42
float m_RateWeight
Definition: MStruct.h:47
Model * m_Model
Definition: ExpMap.h:36
std::map< dword, StructPath > NodePaths
Definition: StructTable.h:52
float m_RateTH
Definition: MStruct.h:47
float getWeight() const
Definition: MStruct.h:70
std::map< std::string, NodePaths > m_NodePaths
Definition: StructTable.h:120
Definition: ExpMap.h:10
#define TRACE0
Definition: common.h:26
dword m_WinnerID
Definition: ExpMap.h:37
StructPath branch() const
Ratings m_Ratings
Definition: ExpMap.h:40
const MStructure & getStructure(const std::string &sname) const
float m_Maxness
maximum goodness
Definition: StructTable.h:43
const std::string& StructTable::getBestInterpretation ( ) const
inline

Definition at line 92 of file StructTable.h.

Referenced by Brain::run().

92 { return m_BestIP; }
std::string m_BestIP
Definition: StructTable.h:118
const StructPath& StructTable::getBestPath ( ) const
inline

Definition at line 91 of file StructTable.h.

91 { return m_BestPath; }
StructPath m_BestPath
Definition: StructTable.h:112
dataset_ptr StructTable::getDataset ( )

Definition at line 43 of file StructTable.cpp.

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

44 {
46 }
Brain * m_Brain
Definition: StructTable.h:110
std::shared_ptr< Derived > shared_from_base()
Definition: Sensor.h:162
Definition: Data.h:21
Dataset & getSensorData()
Definition: Brain.cpp:82
const std::string& StructTable::getFilename ( ) const
inline

Definition at line 69 of file StructTable.h.

Referenced by MStructure::getInfoFilename(), and Brain::triggerTest().

69 { return m_FileName; }
std::string m_FileName
Definition: StructTable.h:108
const std::map<std::string,StructPath>& StructTable::getIPaths ( ) const
inline

Definition at line 93 of file StructTable.h.

Referenced by Brain::drawAllModels(), Brain::run(), and Brain::triggerTest().

94  { return m_IPaths; }
std::map< std::string, StructPath > m_IPaths
Definition: StructTable.h:117
MStructure & StructTable::getNextStruct ( int  dir = 1,
bool  wrap = true 
)

Definition at line 156 of file StructTable.cpp.

Referenced by Brain::doCommand(), Brain::load(), Brain::run(), and Brain::triggerTest().

157 {
158  static MStructure nostruc;
159  if(m_Structs.empty()) return nostruc;
160  if(m_CurStruct.empty()) {
161  m_CurStruct = m_Structs.begin()->first;
162  return m_Structs.begin()->second;
163  }
164  map<string,MStructure>::iterator st = m_Structs.find(m_CurStruct);
165  if(st == m_Structs.end()) {
166  m_CurStruct = m_Structs.begin()->first;
167  return m_Structs.begin()->second;
168  }
169  if(dir > 0) {
170  st++;
171  if(st == m_Structs.end()) {
172  if(wrap) st = m_Structs.begin();
173  else { m_CurStruct.clear(); return nostruc; }
174  }
175  m_CurStruct = st->first;
176  } else if(dir < 0) {
177  if(st == m_Structs.begin()) {
178  if(wrap) st = m_Structs.end();
179  else { m_CurStruct.clear(); return nostruc; }
180  }
181  st--;
182  m_CurStruct = st->first;
183  }
184  return st->second;
185 }
std::map< std::string, MStructure > m_Structs
Definition: StructTable.h:107
std::string m_CurStruct
Definition: StructTable.h:111
const std::string& StructTable::getPath ( ) const
inline

Definition at line 70 of file StructTable.h.

Referenced by MStructure::write().

70 { return m_Path; }
std::string m_Path
Definition: StructTable.h:109
SensorCollection * StructTable::getSensors ( )

Definition at line 48 of file StructTable.cpp.

Referenced by MStructure::MStructure().

49 { return (SensorCollection*) &m_Brain->getSensors(); }
Brain * m_Brain
Definition: StructTable.h:110
const SensorCollection & getSensors() const
Definition: Brain.h:70
const std::string& StructTable::getShownIP ( ) const
inline

Definition at line 97 of file StructTable.h.

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

98  { return m_CurIP.empty() ? m_BestIP : m_CurIP; }
std::string m_CurIP
Definition: StructTable.h:119
std::string m_BestIP
Definition: StructTable.h:118
std::map<std::string, MStructure>& StructTable::getStructs ( )
inline
const std::map<std::string, MStructure>& StructTable::getStructs ( ) const
inline

Definition at line 72 of file StructTable.h.

73  { return m_Structs; }
std::map< std::string, MStructure > m_Structs
Definition: StructTable.h:107
const MStructure & StructTable::getStructure ( const std::string &  sname) const

Definition at line 151 of file StructTable.cpp.

Referenced by StructPath::print().

152 {
153  return m_Structs.find(sname)->second;
154 }
std::map< std::string, MStructure > m_Structs
Definition: StructTable.h:107
bool StructTable::hasStructure ( const std::string &  sname) const

Definition at line 146 of file StructTable.cpp.

147 {
148  return m_Structs.find(sname) != m_Structs.end();
149 }
std::map< std::string, MStructure > m_Structs
Definition: StructTable.h:107
bool StructTable::load ( const std::string &  filename)

Definition at line 69 of file StructTable.cpp.

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

70 {
71  if(filename.empty()) return false;
72  cout << "loading " << filename << endl;
73  ParseFile is(filename);
74  if(is) m_FileName = filename;
75  return read(is);
76 }
bool read(ParseFile &is)
Definition: StructTable.cpp:78
std::string m_FileName
Definition: StructTable.h:108
bool StructTable::read ( ParseFile is)

Definition at line 78 of file StructTable.cpp.

References ParseFile::error(), ParseFile::getErrorMsg(), MStructure::getName(), ParseFile::getPath(), MStructure::read(), and ParseFile::setParseError().

79 {
80  if(is) {
81  clear();
82  m_Path = is.getPath();
83  MStructure cstructure("", this);
84  while(is) {
85  if(cstructure.read(is)) {
86  if(cstructure) m_Structs[cstructure.getName()] = cstructure;
87  } else if(!readInterpreations(is))
88  is.setParseError(
89  string("error reading structure table. ") +
90  "(A structure has to begin with struct <name>)");
91  }
93  evalRelations();
94  }
95  if(is.error()) { cerr << is.getErrorMsg() << endl; return false; }
96  return true;
97 }
void clear()
Definition: StructTable.cpp:31
void evalRelations()
std::map< std::string, MStructure > m_Structs
Definition: StructTable.h:107
bool error() const
Definition: ParseFile.h:50
std::string m_Path
Definition: StructTable.h:109
const std::string & getPath() const
Definition: ParseFile.h:52
void setParseError(const std::string &msg="")
Definition: ParseFile.h:80
void connectSubSuper()
std::string getErrorMsg() const
Definition: ParseFile.h:85
bool readInterpreations(ParseFile &is)
Definition: StructTable.cpp:99
bool StructTable::readInterpreations ( ParseFile is)
protected

Definition at line 99 of file StructTable.cpp.

References ParseFile::getKey(), ParseFile::getNextLine(), ParseFile::getValue(), ParseFile::pushLine(), and ParseFile::setParseError().

100 {
101  m_Interpretations.clear();
102  bool readon = true, allright = false;
103  while(is.getNextLine() && readon) {
104  if(is.getKey() == "interpretations") allright = true;
105  else if(!allright) { is.pushLine(); return false; }
106  else if(is.getKey() == "end") readon = false;
107  else {
108  set<string>& elements = m_Interpretations[is.getKey()];
109  istringstream slist(is.getValue());
110  slist >> ws;
111  while(slist) {
112  string structure; slist >> structure;
113  if(structure.empty()) break;
114  elements.insert(structure);
115  slist >> ws;
116  }
117  if(elements.empty())
118  is.setParseError("error reading structure interpretation");
119  }
120  }
121  return true;
122 }
Interpretations m_Interpretations
Definition: StructTable.h:116
const std::string & getValue() const
Definition: ParseFile.h:57
const std::string & getKey() const
Definition: ParseFile.h:56
void setParseError(const std::string &msg="")
Definition: ParseFile.h:80
void pushLine(const std::string &line)
Definition: ParseFile.h:74
const bool getNextLine()
Definition: ParseFile.h:59
void StructTable::reattachSensors ( )

Definition at line 51 of file StructTable.cpp.

52 {
53  for(map<string,MStructure>::iterator si = m_Structs.begin();
54  si != m_Structs.end(); si++)
55  {
56  si->second.getModel().reattachSensors();
57  }
58 }
std::map< std::string, MStructure > m_Structs
Definition: StructTable.h:107
void StructTable::rebuildExpMaps ( )

Definition at line 199 of file StructTable.cpp.

200 {
201  for(map<string,MStructure>::iterator si = m_Structs.begin();
202  si != m_Structs.end(); si++)
203  si->second.rebuildExpMap();
204 }
std::map< std::string, MStructure > m_Structs
Definition: StructTable.h:107
int StructTable::searchDone ( ) const
inline

Definition at line 81 of file StructTable.h.

Referenced by Brain::run().

81  {
82  if(m_State&ST_DONE) return 1;
83  if(m_State&ST_TIMEOUT) return -1; else return 0;
84  }
dword m_State
Definition: StructTable.h:114
void StructTable::setShownIP ( const std::string &  curip) const
inline

Definition at line 95 of file StructTable.h.

Referenced by Brain::triggerTest().

96  { m_CurIP = curip; }
std::string m_CurIP
Definition: StructTable.h:119
bool StructTable::showNextIP ( int  dir = 1) const

Definition at line 345 of file StructTable.cpp.

Referenced by Brain::triggerTest().

346 {
347  bool ret = true;
348  Interpretations::const_iterator cip = m_Interpretations.find(m_CurIP);
349  if(cip == m_Interpretations.end()) {
350  if(m_Interpretations.empty()) {
351  m_CurIP.clear();
352  return false;
353  }
354  cip = m_Interpretations.begin();
355  }
356  if(dir == 1) {
357  cip++;
358  if(cip==m_Interpretations.end()) {
359  cip = m_Interpretations.begin();
360  ret = false;
361  }
362  } else if(dir > 1) {
363  cip = m_Interpretations.end(); cip--;
364  } else if(dir == -1) {
365  if(cip==m_Interpretations.begin()) {
366  cip = m_Interpretations.end();
367  ret = false;
368  }
369  cip--;
370  } else if(dir < -1) {
371  cip = m_Interpretations.begin();
372  }
373  m_CurIP = cip->first;
374  return ret;
375 }
Interpretations m_Interpretations
Definition: StructTable.h:116
std::string m_CurIP
Definition: StructTable.h:119
void StructTable::startSearch ( bool  dostart = true)

Definition at line 287 of file StructTable.cpp.

Referenced by Brain::run().

288 {
289  if(dostart) {
290  m_State|=ST_RUN;
292  m_Time=0;
294  m_BestPath.clear();
295  m_IPaths.clear();
296  } else m_State &= ~ST_RUN;
297  for(map<string,MStructure>::iterator si = m_Structs.begin();
298  si != m_Structs.end(); si++)
299  {
300  if(dostart) si->second.m_Searcher.clear();
301  si->second.m_Searcher.startSearch(dostart);
302  }
303 }
StructPath m_BestPath
Definition: StructTable.h:112
std::map< std::string, MStructure > m_Structs
Definition: StructTable.h:107
float m_Time
Definition: StructTable.h:113
std::vector< float > m_TMarks
Definition: StructTable.h:115
std::map< std::string, StructPath > m_IPaths
Definition: StructTable.h:117
void clear()
dword m_State
Definition: StructTable.h:114
bool StructTable::stepSearch ( float  dt)

Definition at line 305 of file StructTable.cpp.

References getSearchPara(), and SearcherParams::m_EvolveCycle.

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

306 {
307  bool dotimeout=false;
308  bool ret=true;
309  if((m_State&ST_DONE)) return true;
310  if((m_State&ST_RUN) == 0) return false;
311  if(m_Time == 0) {
312 //initialize
313  for(map<string,MStructure>::iterator si = m_Structs.begin();
314  si != m_Structs.end(); si++)
315  si->second.buildMasterModel();
317  }
318  if(dotimeout && m_TMarks[TM_TIMEOUT] - m_Time <= 0) {
319 //finalize
320  m_State &= ~ST_RUN;
321  m_State |= ST_RESULT;
322  ret = false;
323  } else {
324  bool doupdate = m_TMarks[TM_UPDEM] - m_Time <= 0;
325  if(doupdate) { //pre update
326  rebuildExpMaps();
328  }
329  for(map<string,MStructure>::iterator si = m_Structs.begin();
330  si != m_Structs.end(); si++)
331  {
332  if(doupdate) si->second.m_Searcher.evolve();
333  ret &= si->second.stepSearch(dt);
334  }
335  if(doupdate) findBestConnection();
336  }
337  m_Time += dt;
338  if(ret) {
339  m_State |= ST_DONE;
340  cout << "search terminated after " << m_Time << " seconds." << endl;
341  }
342  return ret;
343 }
void rebuildExpMaps()
float findBestConnection()
std::map< std::string, MStructure > m_Structs
Definition: StructTable.h:107
float m_Time
Definition: StructTable.h:113
std::vector< float > m_TMarks
Definition: StructTable.h:115
float m_EvolveCycle
time in seconds for one evolution cycle
Definition: Searcher.h:172
SearcherParams & getSearchPara()
Definition: Searcher.h:194
dword m_State
Definition: StructTable.h:114
bool StructTable::triggerTest ( int  mx,
int  my,
int  what 
)

Definition at line 229 of file StructTable.cpp.

Referenced by Brain::triggerTest().

230 {
231  switch(what)
232  {
233  case KEY_t:
234  rebuildExpMaps();
235  break;
236  case KEY_g:
237  evalRelations();
238  break;
239  case KEY_n:
240  {
241  for(map<string,MStructure>::iterator si = m_Structs.begin();
242  si != m_Structs.end(); si++)
243  si->second.buildMasterModel();
244  }
245  break;
246  case KEY_v:
247  {
249 // for(map<string,MStructure>::iterator si = m_Structs.begin();
250 // si != m_Structs.end(); si++)
251 // si->second.verifyWinnerRating();
252  }
253  break;
254  case KEY_c:
255  //m_TMarks[TM_TIMEOUT] = m_Time + 10;
257  break;
258  case KEY_u:
259  cout << "starting structure search" << endl;
260  startSearch();
261  break;
262  case KEY_i:
263  cout << "stopping structure search" << endl;
264  startSearch(false);
265  break;
266  default:
267  {
268  if(what == KEY_h) {
269  m_State&=~ST_RUN;
270  } if(what == KEY_s) {
271  m_State^=ST_RUN;
272  } else if(what == KEY_r) {
273  m_Time=0;
275  m_BestPath.clear();
276  }
277  bool ret=false;
278  for(map<string,MStructure>::iterator si = m_Structs.begin();
279  si != m_Structs.end(); si++)
280  ret = si->second.m_Searcher.triggerTest(mx,my,what);
281  return ret;
282  }
283  }
284  return true;
285 }
void rebuildExpMaps()
void startSearch(bool dostart=true)
void evalRelations()
float findBestConnection()
StructPath m_BestPath
Definition: StructTable.h:112
std::map< std::string, MStructure > m_Structs
Definition: StructTable.h:107
float m_Time
Definition: StructTable.h:113
std::vector< float > m_TMarks
Definition: StructTable.h:115
void clear()
dword m_State
Definition: StructTable.h:114
void StructTable::write ( std::ostream &  os) const

Definition at line 124 of file StructTable.cpp.

Referenced by MStructure::hasSupStruct().

125 {
126  for(map<string,MStructure>::const_iterator si = m_Structs.begin();
127  si != m_Structs.end(); si++)
128  {
129  si->second.write(os);
130  }
131  if(!m_Interpretations.empty()) {
132  os << "interpretations" << endl;
133  for(map<string,set<string> >::const_iterator ip =
134  m_Interpretations.begin(); ip != m_Interpretations.end(); ip++)
135  {
136  os << " " << ip->first;
137  for(set<string>::const_iterator sp = ip->second.begin();
138  sp != ip->second.end(); sp++)
139  os << " " << *sp;
140  os << endl;
141  }
142  os << "end" << endl << endl;
143  }
144 }
Interpretations m_Interpretations
Definition: StructTable.h:116
std::map< std::string, MStructure > m_Structs
Definition: StructTable.h:107

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const StructTable st 
)
friend

Definition at line 67 of file StructTable.h.

68  { st.write(os); return os; }
void write(std::ostream &os) const
ParseFile& operator>> ( ParseFile is,
StructTable st 
)
friend

Definition at line 65 of file StructTable.h.

66  { st.read(is); return is; }
bool read(ParseFile &is)
Definition: StructTable.cpp:78

Member Data Documentation

std::string StructTable::m_BestIP
protected

Definition at line 118 of file StructTable.h.

StructPath StructTable::m_BestPath
protected

Definition at line 112 of file StructTable.h.

Brain* StructTable::m_Brain
protected

Definition at line 110 of file StructTable.h.

std::string StructTable::m_CurIP
mutableprotected

Definition at line 119 of file StructTable.h.

std::string StructTable::m_CurStruct
protected

Definition at line 111 of file StructTable.h.

std::string StructTable::m_FileName
protected

Definition at line 108 of file StructTable.h.

Interpretations StructTable::m_Interpretations
protected

Definition at line 116 of file StructTable.h.

std::map<std::string,StructPath> StructTable::m_IPaths
protected

Definition at line 117 of file StructTable.h.

std::map<std::string,NodePaths> StructTable::m_NodePaths
mutableprotected

Definition at line 120 of file StructTable.h.

std::string StructTable::m_Path
protected

Definition at line 109 of file StructTable.h.

dword StructTable::m_State
protected

Definition at line 114 of file StructTable.h.

std::map<std::string, MStructure> StructTable::m_Structs
protected

Definition at line 107 of file StructTable.h.

float StructTable::m_Time
protected

Definition at line 113 of file StructTable.h.

std::vector<float> StructTable::m_TMarks
protected

Definition at line 115 of file StructTable.h.


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