GEGELATI

Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
CodeGen::TPGGenerationEngine Class Referenceabstract

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

`#include <tpgGenerationEngine.h>`

Inheritance diagram for CodeGen::TPGGenerationEngine:

## Public Member Functions
| TPGGenerationEngine (const std::string &filename, const TPG::TPGGraph &tpg, const std::string &path="./")
| Main constructor of the class.
virtual | ~TPGGenerationEngine ()
| destructor of the class.
virtual void | generateTPGGraph ()=0
| function that creates the C files required to execute the TPG without gegelati.
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 ()=0
| function printing generic code in the main file.
virtual void | initHeaderFile ()=0
| function printing generic code declaration in the main file header.
virtual void | generateEdge (const TPG::TPGEdge &edge)=0
| Method for generating the code for an edge of the graph.
virtual void | generateTeam (const TPG::TPGTeam &team)=0
| Method for generating the code for a team of the graph.
virtual void | generateAction (const TPG::TPGAction &action)=0
| Method for generating a action of the graph.
Protected Member Functions inherited from TPG::TPGAbstractEngine
| TPGAbstractEngine (const TPG::TPGGraph &tpg)
| Constructor for the abstract engine.

## Protected Attributes
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
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

## ◆ TPGGenerationEngine()

CodeGen::TPGGenerationEngine::TPGGenerationEngine | ( | 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) :

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.

## ◆ ~TPGGenerationEngine()

CodeGen::TPGGenerationEngine::~TPGGenerationEngine | ( |  | ) |
| virtual

destructor of the class.

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

## Member Function Documentation

## ◆ generateAction()

virtual void CodeGen::TPGGenerationEngine::generateAction | ( | const TPG::TPGAction & | action | ) |
| protected pure 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.

Implemented in CodeGen::TPGStackGenerationEngine, and CodeGen::TPGSwitchGenerationEngine.

## ◆ generateEdge()

virtual void CodeGen::TPGGenerationEngine::generateEdge | ( | const TPG::TPGEdge & | edge | ) |
| protected pure 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.

Implemented in CodeGen::TPGStackGenerationEngine, and CodeGen::TPGSwitchGenerationEngine.

## ◆ generateTeam()

virtual void CodeGen::TPGGenerationEngine::generateTeam | ( | const TPG::TPGTeam & | team | ) |
| protected pure 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.

Implemented in CodeGen::TPGStackGenerationEngine, and CodeGen::TPGSwitchGenerationEngine.

## ◆ generateTPGGraph()

virtual void CodeGen::TPGGenerationEngine::generateTPGGraph | ( |  | ) |
| pure 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.

Implemented in CodeGen::TPGStackGenerationEngine, and CodeGen::TPGSwitchGenerationEngine.

## ◆ initHeaderFile()

virtual void CodeGen::TPGGenerationEngine::initHeaderFile | ( |  | ) |
| protected pure 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.

Implemented in CodeGen::TPGStackGenerationEngine, and CodeGen::TPGSwitchGenerationEngine.

## ◆ initTpgFile()

virtual void CodeGen::TPGGenerationEngine::initTpgFile | ( |  | ) |
| protected pure 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.

Implemented in CodeGen::TPGStackGenerationEngine, and CodeGen::TPGSwitchGenerationEngine.

## Member Data Documentation

## ◆ filenameProg

const std::string CodeGen::TPGGenerationEngine::filenameProg = "program"
| inline static protected

String added at the end of the parameter filename to create the filename of the file with the programs of the TPGGraph.

## ◆ progGenerationEngine

CodeGen::ProgramGenerationEngine CodeGen::TPGGenerationEngine::progGenerationEngine
| protected

ProgramGenerationEngine for generating Programs of edges.

Keeping this ProgramGenerationEngine as an attribute avoids wasting time rebuilding a new one for each edge.

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

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