Tutorial - Making Executable
Start:
''Table of Contents''
#contents
* Overview [#gcb2e842]
In the main function, the following should be done:
- Instantiate the TAgent class
- Load agent scripts
- Execute at least one of member function of a module
* Simple Example [#p26b9a48]
SkyAI provides utility functions which make the main func...
The following is a simple example:
#codeh(cpp){{
#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<MMazeTaskMo...
if(p_maze_task==NULL) {LERROR("module `maze_task' is n...
agent.SaveToFile (agent.GetDataFileName("before.agent")...
p_maze_task->Start();
agent.SaveToFile (agent.GetDataFileName("after.agent"),...
return 0;
}
}}
The ParseCmdLineOption provides some command line options:
- -path PATH_LIST : specify the path list separated by co...
- -agent AGENT_LIST : specify the list of agent scripts s...
- -outdir OUT_DIR : specify the output directory where da...
In executing ParseCmdLineOption, the agent files are load...
#codeh(cpp){{
MMazeTaskModule *p_maze_task = dynamic_cast<MMazeTaskMo...
if(p_maze_task==NULL) {LERROR("module `maze_task' is n...
}}
This part searches the module named `maze_task' and gets ...
p_maze_task is used later.
The SaveToFile function saves the current agent status in...
#codeh(cpp){{
p_maze_task->Start();
}}
This calls the member function Start of the MMazeTaskModu...
* Advanced Example [#ma3bdfa2]
The following example is a more complicated example.
#codeh(cpp){{
int main(int argc, char**argv)
{
TOptionParser option(argc,argv); // parsing command li...
TAgent agent;
std::ofstream debug;
if (!ParseCmdLineOption (agent, option, debug)) return...
// searching modules made by the script
MBasicLearningManager *p_lmanager = dynamic_cast<MBasic...
MMazeEnvironment *p_environment = dynamic_cast<MMazeEnv...
if(p_lmanager==NULL) {LERROR("module `lmanager' is not...
if(p_environment==NULL) {LERROR("module `environment' ...
MBasicLearningManager &lmanager(*p_lmanager);
MMazeEnvironment &environment(*p_environment);
// save agent into file
agent.SaveToFile (agent.GetDataFileName("before.agent")...
// -help option and detecting invalid options
{
stringstream optss;
if (option("help")!="")
{cerr<<"valid options:"<<endl; option.PrintUsed(); ...
if (option.PrintNotAccessed(optss))
{cerr<<"invalid options:"<<endl<<optss.str(); retur...
}
/// main process:
lmanager.Initialize(); // call directory the member-fu...
lmanager.StartLearning(); // call directory the member...
while (lmanager.IsLearning())
{
environment.StepLoop();
}
// save agent into file
agent.SaveToFile (agent.GetDataFileName("after.agent"),...
return 0;
}
}}
Here, we access a generic learning manager module MBasicL...
In order to access the members of this module, the follow...
#codeh(cpp){{
#include <skyai/modules_core/learning_manager.h>
}}
* Makefile [#hf7a3a9d]
Write the makefile as follows:
#codeh(makefile){{
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:
- BASE_REL_DIR : relative path to the base directory of t...
- EXEC : specify the name of executable
- OBJS : specify the names of the object files separated ...
- USING_SKYAI_ODE or USING_SKYAI : set true if you want t...
- MAKING_SKYAI : set true if you want to make the library
End:
''Table of Contents''
#contents
* Overview [#gcb2e842]
In the main function, the following should be done:
- Instantiate the TAgent class
- Load agent scripts
- Execute at least one of member function of a module
* Simple Example [#p26b9a48]
SkyAI provides utility functions which make the main func...
The following is a simple example:
#codeh(cpp){{
#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<MMazeTaskMo...
if(p_maze_task==NULL) {LERROR("module `maze_task' is n...
agent.SaveToFile (agent.GetDataFileName("before.agent")...
p_maze_task->Start();
agent.SaveToFile (agent.GetDataFileName("after.agent"),...
return 0;
}
}}
The ParseCmdLineOption provides some command line options:
- -path PATH_LIST : specify the path list separated by co...
- -agent AGENT_LIST : specify the list of agent scripts s...
- -outdir OUT_DIR : specify the output directory where da...
In executing ParseCmdLineOption, the agent files are load...
#codeh(cpp){{
MMazeTaskModule *p_maze_task = dynamic_cast<MMazeTaskMo...
if(p_maze_task==NULL) {LERROR("module `maze_task' is n...
}}
This part searches the module named `maze_task' and gets ...
p_maze_task is used later.
The SaveToFile function saves the current agent status in...
#codeh(cpp){{
p_maze_task->Start();
}}
This calls the member function Start of the MMazeTaskModu...
* Advanced Example [#ma3bdfa2]
The following example is a more complicated example.
#codeh(cpp){{
int main(int argc, char**argv)
{
TOptionParser option(argc,argv); // parsing command li...
TAgent agent;
std::ofstream debug;
if (!ParseCmdLineOption (agent, option, debug)) return...
// searching modules made by the script
MBasicLearningManager *p_lmanager = dynamic_cast<MBasic...
MMazeEnvironment *p_environment = dynamic_cast<MMazeEnv...
if(p_lmanager==NULL) {LERROR("module `lmanager' is not...
if(p_environment==NULL) {LERROR("module `environment' ...
MBasicLearningManager &lmanager(*p_lmanager);
MMazeEnvironment &environment(*p_environment);
// save agent into file
agent.SaveToFile (agent.GetDataFileName("before.agent")...
// -help option and detecting invalid options
{
stringstream optss;
if (option("help")!="")
{cerr<<"valid options:"<<endl; option.PrintUsed(); ...
if (option.PrintNotAccessed(optss))
{cerr<<"invalid options:"<<endl<<optss.str(); retur...
}
/// main process:
lmanager.Initialize(); // call directory the member-fu...
lmanager.StartLearning(); // call directory the member...
while (lmanager.IsLearning())
{
environment.StepLoop();
}
// save agent into file
agent.SaveToFile (agent.GetDataFileName("after.agent"),...
return 0;
}
}}
Here, we access a generic learning manager module MBasicL...
In order to access the members of this module, the follow...
#codeh(cpp){{
#include <skyai/modules_core/learning_manager.h>
}}
* Makefile [#hf7a3a9d]
Write the makefile as follows:
#codeh(makefile){{
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:
- BASE_REL_DIR : relative path to the base directory of t...
- EXEC : specify the name of executable
- OBJS : specify the names of the object files separated ...
- USING_SKYAI_ODE or USING_SKYAI : set true if you want t...
- MAKING_SKYAI : set true if you want to make the library
Page: