GEGELATI
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Program::Program Class Reference

The Program class contains a list of program lines that can be executed within a well defined Environment. More...

#include <program.h>

Public Member Functions

 Program (const Environment &e)
 Main constructor of the Program. More...
 
 Program (const Program &other)
 Copy constructor of the Program. More...
 
Programoperator= (const Program &other)=delete
 
 ~Program ()
 Destructor for the Program class. More...
 
LineaddNewLine ()
 Add a new line to the Program with only 0 bits. More...
 
LineaddNewLine (const uint64_t idx)
 Add a new line to the Program with only 0 bits. More...
 
void clearIntrons ()
 Clear all intron instructions in the Program. More...
 
void removeLine (const uint64_t idx)
 Remove a Line from the Program. More...
 
void swapLines (const uint64_t idx0, const uint64_t idx1)
 Swap two existing lines from the Program. More...
 
const EnvironmentgetEnvironment () const
 Get the environment associated to the Program at construction. More...
 
size_t getNbLines () const
 Get the number of lines in the Program. More...
 
const LinegetLine (uint64_t index) const
 Get a const ref to a Line of the Program. More...
 
LinegetLine (uint64_t index)
 Get a non-const ref to a Line of the Program. More...
 
bool isIntron (uint64_t index) const
 Checks whether a Line at the given index is an intron. More...
 
uint64_t identifyIntrons ()
 Scan the Line of the Program to identify introns. More...
 
Data::ConstantHandlergetConstantHandler ()
 get the constantHandler object of the Program More...
 
const Data::ConstantHandlercGetConstantHandler () const
 get a const reference to the constantHandler object of the Program More...
 
const Data::Constant getConstantAt (size_t index) const
 Get the value of a constant at a given index. More...
 
bool hasIdenticalBehavior (const Program &other) const
 Check if two Program have the same behavior. More...
 

Protected Member Functions

 Program ()=delete
 Delete the default constructor.
 

Protected Attributes

const Environmentenvironment
 Environment within which the Program will be executed.
 
std::vector< std::pair< Line *, bool > > lines
 Lines of the program and intron property. More...
 
Data::ConstantHandler constants
 Constants of the Program. More...
 

Detailed Description

The Program class contains a list of program lines that can be executed within a well defined Environment.

Constructor & Destructor Documentation

◆ Program() [1/2]

Program::Program::Program ( const Environment e)
inline

Main constructor of the Program.

Parameters
[in]ethe reference to the Environment that will be referenced in the Program attributes.

◆ Program() [2/2]

Program::Program::Program ( const Program other)
inline

Copy constructor of the Program.

This copy constructor realises a deep copy of the Line of the given Program, instead of the default shallow copy.

Parameters
[in]othera const reference the the copied Program.

◆ ~Program()

Program::Program::~Program ( )

Destructor for the Program class.

This destructor deallocates all memory allocated for Program lines (if any).

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

Karol Desnos kdesn.nosp@m.os@i.nosp@m.nsa-r.nosp@m.enne.nosp@m.s.fr (2019 - 2021) Nicolas Sourbier nsour.nosp@m.bie@.nosp@m.insa-.nosp@m.renn.nosp@m.es.fr (2020)

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.

Member Function Documentation

◆ addNewLine() [1/2]

Program::Line & Program::Program::addNewLine ( )

Add a new line to the Program with only 0 bits.

The new line is inserted at the end of the program.

Returns
a non-const reference to the newly added Line.

◆ addNewLine() [2/2]

Program::Line & Program::Program::addNewLine ( const uint64_t  idx)

Add a new line to the Program with only 0 bits.

The new line is inserted at the given position of the program.

Parameters
[in]idxthe position at which the line should be inserted.
Returns
a non-const reference to the newly added Line.
Exceptions
std::out_of_rangeif the given position is beyond the end of the Program.

◆ cGetConstantHandler()

const Data::ConstantHandler & Program::Program::cGetConstantHandler ( ) const

get a const reference to the constantHandler object of the Program

This method gives a const reference to the constantHandler associated with the program

Returns
the constantHandler of the program through a const reference

◆ clearIntrons()

void Program::Program::clearIntrons ( )

Clear all intron instructions in the Program.

All introns lines from the Program are removed by this method. The behavior of the Program should not be modified after a call to this function.

Introns should have been identified before calling this methos, as this method does NOT call the identifyIntrons method.

◆ getConstantAt()

const Data::Constant Program::Program::getConstantAt ( size_t  index) const

Get the value of a constant at a given index.

Although this method is not required as the data is accessible from the constantHandler, it allows a shortcut and add readability.

Parameters
[in]indexthe position at which we access the constant
Returns
the value of the constant at the given index

◆ getConstantHandler()

Data::ConstantHandler & Program::Program::getConstantHandler ( )

get the constantHandler object of the Program

This method gives a reference to the constantHandler associated with the program

Returns
the constantHandler of the program

◆ getEnvironment()

const Environment & Program::Program::getEnvironment ( ) const

Get the environment associated to the Program at construction.

Returns
a const reference to the Environment of the Program and all its Line.

◆ getLine() [1/2]

Program::Line & Program::Program::getLine ( uint64_t  index)

Get a non-const ref to a Line of the Program.

Parameters
[in]indexThe integer index of the retrieved Line within the Program.
Returns
a const reference to the indexed Line of the Program.
Exceptions
std::out_of_rangeif the index is too large.

◆ getLine() [2/2]

const Program::Line & Program::Program::getLine ( uint64_t  index) const

Get a const ref to a Line of the Program.

Parameters
[in]indexThe integer index of the retrieved Line within the Program.
Returns
a const reference to the indexed Line of the Program.
Exceptions
std::out_of_rangeif the index is too large.

◆ getNbLines()

size_t Program::Program::getNbLines ( ) const

Get the number of lines in the Program.

Returns
the number of line contained in the Program.

◆ hasIdenticalBehavior()

bool Program::Program::hasIdenticalBehavior ( const Program other) const

Check if two Program have the same behavior.

Two Program have the same behaviour if their sequence of non-intron Lines are strictly identical (i.e. same instructions and operands, in the same order, and used Constant with identical values).

Parameters
[in]otherthe Program whose behavior is compared.

◆ identifyIntrons()

uint64_t Program::Program::identifyIntrons ( )

Scan the Line of the Program to identify introns.

This method update the boolean value associated to each Line of the Program to indicate if this Line is an intron or not.

Returns
the number of intron Lines idendified.

◆ isIntron()

bool Program::Program::isIntron ( uint64_t  index) const

Checks whether a Line at the given index is an intron.

Parameters
[in]indexThe integer index of the checked Line within the Program.
Returns
true if the Line is an intron, false otherwise.
Exceptions
std::out_of_rangeif the index is too large.

◆ operator=()

Program & Program::Program::operator= ( const Program other)
delete

Disable Program default assignment operator.

Until we see the need for it, there si no reason to enable assignment operator of Program.

◆ removeLine()

void Program::Program::removeLine ( const uint64_t  idx)

Remove a Line from the Program.

Remove the Line at the given index from the Program and free the associated memory.

Parameters
[in]idxthe integer index of the Program Line to remove.
Exceptions
std::out_of_rangeif the index is too large.

◆ swapLines()

void Program::Program::swapLines ( const uint64_t  idx0,
const uint64_t  idx1 
)

Swap two existing lines from the Program.

Parameters
[in]idx0the index of the first line to swap.
[in]idx1the index of the second line to swap.
Exceptions
std::out_of_rangeif any of the two index is too large.

Member Data Documentation

◆ constants

Data::ConstantHandler Program::Program::constants
protected

Constants of the Program.

A Program contains a set of constants in a dedicated Data::DataHandler

◆ lines

std::vector<std::pair<Line*, bool> > Program::Program::lines
protected

Lines of the program and intron property.

Each element of this vector stores a pointer to a Line, and a boolean value indicating whether this Line is an Intron whithin the program.

Introns are Lines of the program that do not contribute to its final result, stored in the first register. Hence, skipping these lines during a program execution can speed up the Program execution.


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