Table of Contents
In the main function, the following should be done:
SkyAI provides utility functions which make the main function simple.
The following is a simple example:
#include <skyai/skyai.h>
#include <skyai/utility.h>
...
using namespace std;
using namespace loco_rabbits;
...
int main(int argc, char**argv)
{
  TOptionParser option(argc,argv);
  TAgent  agent;
  if (!ParseCmdLineOption (agent, option))  return 0;
  MMazeTaskModule *p_maze_task = dynamic_cast<MMazeTaskModule*>(agent.SearchModule("maze_task"));
  if(p_maze_task==NULL)  {LERROR("module `maze_task' is not defined as an instance of MMazeTaskModule"); return 1;}
  agent.SaveToFile (agent.GetDataFileName("before.agent"),"before-");
  p_maze_task->Start();
  agent.SaveToFile (agent.GetDataFileName("after.agent"),"after-");
  return 0;
}
The ParseCmdLineOption provides some command line options:
In executing ParseCmdLineOption, the agent files are loaded.
  MMazeTaskModule *p_maze_task = dynamic_cast<MMazeTaskModule*>(agent.SearchModule("maze_task"));
  if(p_maze_task==NULL)  {LERROR("module `maze_task' is not defined as an instance of MMazeTaskModule"); return 1;}
This part searches the module named `maze_task' and gets it as a pointer of MMazeTaskModule type. Here, MMazeTaskModule is a user-defined task module. p_maze_task is used later.
The SaveToFile function saves the current agent status into a file as an agent script in the data directory specified by -outdir option.
p_maze_task->Start();
This calls the member function Start of the MMazeTaskModule module, which starts a run.
The following example is a more complicated example.
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;
}
Here, we access a generic learning manager module MBasicLearningManager. In order to access the members of this module, the following should be included:
#include <skyai/modules_core/learning_manager.h>
Write the makefile as follows:
BASE_REL_DIR:=../.. include $(BASE_REL_DIR)/Makefile_preconf ##------------------------------------------------------------------------------------------- EXEC := maze.out OBJS := maze.o ##------------------------------------------------------------------------------------------- USING_SKYAI_ODE:=true MAKING_SKYAI:=true include $(BASE_REL_DIR)/Makefile_body
The following variables should be changed: