Sample of the main function

int main(int argc, char**argv)
{
  TOptionParser option(argc,argv);  // parsing command line option

  TAgent  agent;
  std::ofstream debug;
  if (!ParseCmdLineOption (agent, option, debug))  return 0;  // scripts are loaded

  // searching modules made by the script
  MBasicLearningManager *p_lmanager = dynamic_cast<MBasicLearningManager*>(agent.SearchModule("lmanager"));
  MMazeEnvironment *p_environment = dynamic_cast<MMazeEnvironment*>(agent.SearchModule("environment"));
  if(p_lmanager==NULL)  {LERROR("module `lmanager' is not defined correctly"); return 1;}
  if(p_environment==NULL)  {LERROR("module `environment' is not defined correctly"); return 1;}
  MBasicLearningManager &lmanager(*p_lmanager);
  MMazeEnvironment &environment(*p_environment);


  // save agent into file
  agent.SaveToFile (agent.GetDataFileName("before.agent"),"before-");

  // -help option and detecting invalid options
  {
    stringstream optss;
    if (option("help")!="")
      {cerr<<"valid options:"<<endl; option.PrintUsed(); return 0;}
    if (option.PrintNotAccessed(optss))
      {cerr<<"invalid options:"<<endl<<optss.str(); return 1;}
  }

  /// main process:

  lmanager.Initialize();  // call directory the member-function
  lmanager.StartLearning();  // call directory the member-function

  while (lmanager.IsLearning())
  {
    environment.StepLoop();
  }

  // save agent into file
  agent.SaveToFile (agent.GetDataFileName("after.agent"),"after-");

  return 0;
}

Front page   New List of pages Search Recent changes   Help   RSS of recent changes