GEGELATI

Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
CodeGen::TPGStackGenerationEngine Class Reference

Class in charge of generating the C code of a TPGGraph. More...

`#include <tpgStackGenerationEngine.h>`

Inheritance diagram for CodeGen::TPGStackGenerationEngine:

## Public Member Functions
| TPGStackGenerationEngine (const std::string &filename, const TPG::TPGGraph &tpg, const std::string &path="./")
| Main constructor of the class.
| ~TPGStackGenerationEngine ()
| destructor of the class.
virtual void | generateTPGGraph ()
| function that creates the C files required to execute the TPG without gegelati.
virtual void | generateEdge (const TPG::TPGEdge &edge)
| Method for generating the code for an edge of the graph.
virtual void | generateTeam (const TPG::TPGTeam &team)
| Method for generating the code for a team of the graph.
virtual void | generateAction (const TPG::TPGAction &action)
| Method for generating a action of the graph.
virtual void | setRoot (const TPG::TPGVertex &root)
| Define the function pointer root to the vertex given in parameter.
std::string | vertexName (const TPG::TPGVertex &v)
| Generate function name depending on the vertex type.
Public Member Functions inherited from CodeGen::TPGGenerationEngine
| TPGGenerationEngine (const std::string &filename, const TPG::TPGGraph &tpg, const std::string &path="./")
| Main constructor of the class.
virtual | ~TPGGenerationEngine ()
| destructor of the class.
Public Member Functions inherited from TPG::TPGAbstractEngine
bool | programIDIsNew (const uint64_t &progID)
| Method to find if the given Program is already in the programID set.

## Protected Member Functions
virtual void | initTpgFile ()
| function printing generic code in the main file.
virtual void | initHeaderFile ()
| function printing generic code declaration in the main file header.
Protected Member Functions inherited from TPG::TPGAbstractEngine
| TPGAbstractEngine (const TPG::TPGGraph &tpg)
| Constructor for the abstract engine.

## Additional Inherited Members
Protected Attributes inherited from CodeGen::TPGGenerationEngine
std::ofstream | fileMain
| File holding the functions in charge of iterating through the TPG.
std::ofstream | fileMainH
| header file for the function that iterates through the TPG.
CodeGen::ProgramGenerationEngine | progGenerationEngine
| ProgramGenerationEngine for generating Programs of edges.
Protected Attributes inherited from TPG::TPGAbstractEngine
const TPG::TPGGraph & | tpg
| Reference to the TPGGraph whose content will be used to fill the maps.
std::set< uint64_t > | programID
| Set of all program ID.
uint64_t | nbActions
| Integer number used during export to associate a unique integer identifier to each TPGAction.
Static Protected Attributes inherited from CodeGen::TPGGenerationEngine
static const std::string | filenameProg = "program"

## Detailed Description

Class in charge of generating the C code of a TPGGraph.

Each program of the TPGGraph is represented by a C function. All the functions are regrouped in a file. Another file holds the required functions to iterate through the TPGGraph.

To use the generated code two code templates are provided in the directory doc/codeGen. One template is for generic learning environment. The other one is dedicated for adversarial learning environment and manages the switch between the players. Both templates can use the inference with the codeGen or the inference with Gegelati.

The repo gegelati apps give some example of the template code completed for TicTacToe, Pendulum and StickGame.

## Constructor & Destructor Documentation

## ◆ TPGStackGenerationEngine()

CodeGen::TPGStackGenerationEngine::TPGStackGenerationEngine | ( | const std::string & | filename,
|  | const TPG::TPGGraph & | tpg,
|  | const std::string & | path = "./" )

Main constructor of the class.

Parameters

  [in] | filename | : filename of the file holding the main function of the generated program.
  [in] | tpg | Environment in which the Program of the TPGGraph will be executed.
  [in] | path | to the folder in which the file are generated. If the folder does not exist.

Copyright or © or Copr. IETR/INSA - Rennes (2019 - 2025) :

Elinor Montmasson elino.nosp@m.r.mo.nosp@m.ntmas.nosp@m.son@.nosp@m.gmail.nosp@m..com (2022) Karol Desnos kdesn.nosp@m.os@i.nosp@m.nsa-r.nosp@m.enne.nosp@m.s.fr (2019 - 2022) Mickaël Dardaillon mdard.nosp@m.ail@.nosp@m.insa-.nosp@m.renn.nosp@m.es.fr (2022) Quentin Vacher qvach.nosp@m.er@i.nosp@m.nsa-r.nosp@m.enne.nosp@m.s.fr (2025) Thomas Bourgoin tbour.nosp@m.goi@.nosp@m.insa-.nosp@m.renn.nosp@m.es.fr (2021)

GEGELATI is an open-source reinforcement learning framework for training artificial intelligence based on Tangled Program Graphs (TPGs).

This software is governed by the CeCILL-C license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".

As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability.

In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security.

The fact that you are presently reading this means that you have had knowledge of the CeCILL-C license and that you accept its terms.

## ◆ ~TPGStackGenerationEngine()

CodeGen::TPGStackGenerationEngine::~TPGStackGenerationEngine | ( |  | ) |

destructor of the class.

add endif at the end of the header and close both file.

## Member Function Documentation

## ◆ generateAction()

void CodeGen::TPGStackGenerationEngine::generateAction | ( | const TPG::TPGAction & | action | ) |
| virtual

Method for generating a action of the graph.

This method generates the C function that represents an action. The generated function return a NULL pointer and write the action in the pointer given as parameter.

Parameters

  [in] | action | const reference of the TPGAction that must be generated.

Implements CodeGen::TPGGenerationEngine.

## ◆ generateEdge()

void CodeGen::TPGStackGenerationEngine::generateEdge | ( | const TPG::TPGEdge & | edge | ) |
| virtual

Method for generating the code for an edge of the graph.

This function generates the code that represents an edge. An edge of a team is represented by a struct with: an integer, a function pointer of type : double (ptr_prog)() for the program of the edge a a function pointer of type : void (ptr_vertex)(int) to represent the destination of the edge

Parameters

  [in] | edge | that must be generated.

Implements CodeGen::TPGGenerationEngine.

## ◆ generateTeam()

void CodeGen::TPGStackGenerationEngine::generateTeam | ( | const TPG::TPGTeam & | team | ) |
| virtual

Method for generating the code for a team of the graph.

This method generates the C function that represents a team. Each function representing a team contains a static array of TPGEdge and calls the function executeTeam(Edge*, int).

Parameters

  [in] | team | const reference of the TPGTeam that must be generated.

Implements CodeGen::TPGGenerationEngine.

## ◆ generateTPGGraph()

void CodeGen::TPGStackGenerationEngine::generateTPGGraph | ( |  | ) |
| virtual

function that creates the C files required to execute the TPG without gegelati.

This function iterates trough the TPGGraph and create the required C code to represent each element of the TPGGraph.

Implements CodeGen::TPGGenerationEngine.

## ◆ initHeaderFile()

void CodeGen::TPGStackGenerationEngine::initHeaderFile | ( |  | ) |
| protected virtual

function printing generic code declaration in the main file header.

This function print the the struct required to represent the TPG and the prototypes of the function to execute the TPG and manage the stack of visited edges.

Implements CodeGen::TPGGenerationEngine.

## ◆ initTpgFile()

void CodeGen::TPGStackGenerationEngine::initTpgFile | ( |  | ) |
| protected virtual

function printing generic code in the main file.

This function prints generic code to execute the TPG and manage the stack of visited edges.

Implements CodeGen::TPGGenerationEngine.

## ◆ setRoot()

void CodeGen::TPGStackGenerationEngine::setRoot | ( | const TPG::TPGVertex & | root | ) |
| virtual

Define the function pointer root to the vertex given in parameter.

Parameters

  [in] | root | const reference to the root of the TPG graph.

## ◆ vertexName()

std::string CodeGen::TPGStackGenerationEngine::vertexName | ( | const TPG::TPGVertex & | v | ) |

Generate function name depending on the vertex type.

Parameters

  v | vertex to be named.

Returns
  std::string name of the vertex.

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

- D:/a/gegelati/gegelati/gegelatilib/include/codeGen/tpgStackGenerationEngine.h
- D:/a/gegelati/gegelati/gegelatilib/src/codeGen/tpgStackGenerationEngine.cpp