GAMS  1.4.0
gams::controllers::BaseController Class Reference

The basic controller that can be used to perform actions on platforms and algorithms. More...

#include <BaseController.h>

Public Member Functions

 BaseController (madara::knowledge::KnowledgeBase &knowledge, const ControllerSettings &settings=ControllerSettings())
 Constructor. More...
 
virtual ~BaseController ()
 Destructor. More...
 
void add_algorithm_factory (const std::vector< std::string > &aliases, algorithms::AlgorithmFactory *factory)
 Adds an aliased algorithm factory. More...
 
void add_platform_factory (const std::vector< std::string > &aliases, platforms::PlatformFactory *factory)
 Adds an aliased platform factory. More...
 
virtual int analyze (void)
 Defines the analyze function(the A of MAPE). More...
 
void clear_accents (void)
 Clears all accent algorithms. More...
 
void configure (const ControllerSettings &settings)
 Configures the controller with initialization settings. More...
 
virtual int execute (void)
 Defines the execute function(the E of MAPE). More...
 
algorithms::BaseAlgorithmget_algorithm (void)
 Gets the current algorithm. More...
 
madara::knowledge::KnowledgeBase * get_kb (void)
 Gets the KB. More...
 
platforms::BasePlatformget_platform (void)
 Gets the current platform. More...
 
variables::Selfget_self (void)
 Gets the Self. More...
 
variables::Sensorsget_sensors (void)
 Gets the sensors map. More...
 
void init_accent (const std::string &algorithm, const madara::knowledge::KnowledgeMap &args=madara::knowledge::KnowledgeMap())
 Adds an accent algorithm. More...
 
void init_algorithm (algorithms::BaseAlgorithm *algorithm)
 Initializes the controller with a user-provided algorithm. More...
 
void init_algorithm (const std::string &algorithm, const madara::knowledge::KnowledgeMap &args=madara::knowledge::KnowledgeMap())
 Initializes an algorithm. More...
 
void init_platform (const std::string &platform, const madara::knowledge::KnowledgeMap &args=madara::knowledge::KnowledgeMap())
 Initializes the platform. More...
 
void init_platform (platforms::BasePlatform *platform)
 Initializes the controller with a user-provided platform. More...
 
void init_vars (algorithms::BaseAlgorithm &algorithm)
 Initializes containers and knowledge base in an algorithm. More...
 
void init_vars (const madara::knowledge::KnowledgeRecord::Integer &id=0, const madara::knowledge::KnowledgeRecord::Integer &agents=-1)
 Initializes global variable containers. More...
 
void init_vars (const std::string &self_prefix, const groups::GroupBase *group)
 Initializes global variable containers. More...
 
void init_vars (const std::string &self_prefix, const std::string &group_name="")
 Initializes global variable containers. More...
 
void init_vars (platforms::BasePlatform &platform)
 Initializes containers and knowledge base in a platform This is usually the first thing a developer should do with a user-defined platform. More...
 
virtual int monitor (void)
 Defines the monitor function(the M of MAPE). More...
 
virtual int plan (void)
 Defines the plan function(the P of MAPE). More...
 
int run (double loop_period, double max_runtime=-1, double send_period=-1.0)
 Runs iterations of the MAPE loop with specified periods. More...
 
int run (void)
 Runs iterations of the MAPE loop with configured settings. More...
 
int run_hz (double loop_hz=0.0, double max_runtime=-1, double send_hz=-1.0)
 Runs iterations of the MAPE loop with specified hertz. More...
 
int run_once (void)
 Runs a single iteration of the MAPE loop Always sends updates after the iteration. More...
 
void save_checkpoint (void)
 Saves a checkpoint according to the configured settings. More...
 
virtual int system_analyze (void)
 Analyzes the system to determine if platform or algorithm changes are necessary. More...
 

Protected Attributes

algorithms::Algorithms accents_
 Accents on the primary algorithm. More...
 
variables::Agents agents_
 Containers for agent-related variables. More...
 
algorithms::BaseAlgorithmalgorithm_
 Algorithm to perform. More...
 
variables::Algorithms algorithms_
 Containers for algorithm information. More...
 
int checkpoint_count_
 keeps track of the checkpoints saved in the control loop More...
 
madara::knowledge::KnowledgeBase & knowledge_
 Knowledge base. More...
 
platforms::BasePlatformplatform_
 Platform on which the controller is running. More...
 
variables::Platforms platforms_
 Containers for platform information. More...
 
variables::Self self_
 Containers for self-referencing variables. More...
 
variables::Sensors sensors_
 Containers for sensor information. More...
 
ControllerSettings settings_
 Settings for controller management and qos. More...
 
variables::Swarm swarm_
 Containers for swarm-related variables. More...
 

Private Member Functions

int run_once_ (void)
 Code shared between run and run_once. More...
 

Detailed Description

The basic controller that can be used to perform actions on platforms and algorithms.

Definition at line 87 of file BaseController.h.

Constructor & Destructor Documentation

◆ BaseController()

gams::controllers::BaseController::BaseController ( madara::knowledge::KnowledgeBase &  knowledge,
const ControllerSettings settings = ControllerSettings() 
)

Constructor.

Parameters
knowledgeThe knowledge base to reference and mutate
settingsan initial configuration for the controller

◆ ~BaseController()

virtual gams::controllers::BaseController::~BaseController ( )
virtual

Destructor.

Member Function Documentation

◆ add_algorithm_factory()

void gams::controllers::BaseController::add_algorithm_factory ( const std::vector< std::string > &  aliases,
algorithms::AlgorithmFactory factory 
)

Adds an aliased algorithm factory.

This factory will be initialized with all appropriate variables in the AlgorithmFactory class by the BaseController.

Parameters
aliasesthe named aliases for the factory. All aliases will be converted to lower case
factorythe factory for creating an algorithm

◆ add_platform_factory()

void gams::controllers::BaseController::add_platform_factory ( const std::vector< std::string > &  aliases,
platforms::PlatformFactory factory 
)

Adds an aliased platform factory.

This factory will be initialized with all appropriate variables in the PlatformFactory class by the BaseController.

Parameters
aliasesthe named aliases for the factory. All aliases will be converted to lower case
factorythe factory for creating a platform

◆ analyze()

virtual int gams::controllers::BaseController::analyze ( void  )
virtual

Defines the analyze function(the A of MAPE).

This function should return a 0 unless the MAPE loop should stop.

◆ clear_accents()

void gams::controllers::BaseController::clear_accents ( void  )

Clears all accent algorithms.

◆ configure()

void gams::controllers::BaseController::configure ( const ControllerSettings settings)

Configures the controller with initialization settings.

◆ execute()

virtual int gams::controllers::BaseController::execute ( void  )
virtual

Defines the execute function(the E of MAPE).

This function should return a 0 unless the MAPE loop should stop.

◆ get_algorithm()

algorithms::BaseAlgorithm* gams::controllers::BaseController::get_algorithm ( void  )

Gets the current algorithm.

Returns
the algorithm

◆ get_kb()

madara::knowledge::KnowledgeBase* gams::controllers::BaseController::get_kb ( void  )

Gets the KB.

Returns
the KB

◆ get_platform()

platforms::BasePlatform* gams::controllers::BaseController::get_platform ( void  )

Gets the current platform.

Returns
the platform

◆ get_self()

variables::Self* gams::controllers::BaseController::get_self ( void  )

Gets the Self.

Returns
the Self

◆ get_sensors()

variables::Sensors* gams::controllers::BaseController::get_sensors ( void  )

Gets the sensors map.

Returns
the sensors

◆ init_accent()

void gams::controllers::BaseController::init_accent ( const std::string &  algorithm,
const madara::knowledge::KnowledgeMap &  args = madara::knowledge::KnowledgeMap() 
)

Adds an accent algorithm.

Parameters
algorithmthe name of the accent algorithm to add
argsvector of knowledge record arguments

◆ init_algorithm() [1/2]

void gams::controllers::BaseController::init_algorithm ( algorithms::BaseAlgorithm algorithm)

Initializes the controller with a user-provided algorithm.

This algorithm's memory will be maintained by the controller. DO NOT DELETE THIS POINTER.

Parameters
algorithmthe algorithm to use

◆ init_algorithm() [2/2]

void gams::controllers::BaseController::init_algorithm ( const std::string &  algorithm,
const madara::knowledge::KnowledgeMap &  args = madara::knowledge::KnowledgeMap() 
)

Initializes an algorithm.

Parameters
algorithmthe name of the algorithm to run
argsvector of knowledge record arguments

◆ init_platform() [1/2]

void gams::controllers::BaseController::init_platform ( const std::string &  platform,
const madara::knowledge::KnowledgeMap &  args = madara::knowledge::KnowledgeMap() 
)

Initializes the platform.

Parameters
platformthe name of the platform the controller is using
argsvector of knowledge record arguments

◆ init_platform() [2/2]

void gams::controllers::BaseController::init_platform ( platforms::BasePlatform platform)

Initializes the controller with a user-provided platform.

This platform's memory will be maintained by the controller. DO NOT DELETE THIS POINTER.

Parameters
platformthe platform to use

◆ init_vars() [1/5]

void gams::controllers::BaseController::init_vars ( algorithms::BaseAlgorithm algorithm)

Initializes containers and knowledge base in an algorithm.

This is usually the first thing a developer should do with a user-defined algorithm.

Parameters
algorithmthe algorithm to initialize

◆ init_vars() [2/5]

void gams::controllers::BaseController::init_vars ( const madara::knowledge::KnowledgeRecord::Integer &  id = 0,
const madara::knowledge::KnowledgeRecord::Integer &  agents = -1 
)

Initializes global variable containers.

Parameters
idnode identifier
agentsnumber of total agents

◆ init_vars() [3/5]

void gams::controllers::BaseController::init_vars ( const std::string &  self_prefix,
const groups::GroupBase group 
)

Initializes global variable containers.

Parameters
self_prefixthe prefix of the agent in the knowledge base
groupthe group that should populate agents

◆ init_vars() [4/5]

void gams::controllers::BaseController::init_vars ( const std::string &  self_prefix,
const std::string &  group_name = "" 
)

Initializes global variable containers.

Parameters
self_prefixthe prefix of the agent in the knowledge base
group_namethe name of the group that the agent listing should come from

◆ init_vars() [5/5]

void gams::controllers::BaseController::init_vars ( platforms::BasePlatform platform)

Initializes containers and knowledge base in a platform This is usually the first thing a developer should do with a user-defined platform.

Parameters
platformthe platform to initialize

◆ monitor()

virtual int gams::controllers::BaseController::monitor ( void  )
virtual

Defines the monitor function(the M of MAPE).

This function should return a 0 unless the MAPE loop should stop.

◆ plan()

virtual int gams::controllers::BaseController::plan ( void  )
virtual

Defines the plan function(the P of MAPE).

This function should return a 0 unless the MAPE loop should stop.

◆ run() [1/2]

int gams::controllers::BaseController::run ( double  loop_period,
double  max_runtime = -1,
double  send_period = -1.0 
)

Runs iterations of the MAPE loop with specified periods.

Parameters
loop_periodtime(in seconds) between executions of the loop. 0 period is meant to run loop iterations as fast as possible. Negative loop periods are invalid.
max_runtimemaximum total runtime to execute the MAPE loops
send_periodtime(in seconds) between sending data. If send_period <= 0, send period will use the loop period.
Returns
the result of the MAPE loop

◆ run() [2/2]

int gams::controllers::BaseController::run ( void  )

Runs iterations of the MAPE loop with configured settings.

Returns
the result of the MAPE loop

◆ run_hz()

int gams::controllers::BaseController::run_hz ( double  loop_hz = 0.0,
double  max_runtime = -1,
double  send_hz = -1.0 
)
inline

Runs iterations of the MAPE loop with specified hertz.

Parameters
loop_hzthe intended hz at which the loop should execute. anything non-negative is valid. 0hz is treated as as infinite hertz
max_runtimemaximum total runtime to execute the MAPE loops
send_hzthe intended hz at which updates should be sent. If non-positive, loop_hz is used.
Returns
the result of the MAPE loop

Definition at line 167 of file BaseController.h.

◆ run_once()

int gams::controllers::BaseController::run_once ( void  )

Runs a single iteration of the MAPE loop Always sends updates after the iteration.

Returns
the result of the MAPE loop iteration

◆ run_once_()

int gams::controllers::BaseController::run_once_ ( void  )
private

Code shared between run and run_once.

◆ save_checkpoint()

void gams::controllers::BaseController::save_checkpoint ( void  )

Saves a checkpoint according to the configured settings.

◆ system_analyze()

virtual int gams::controllers::BaseController::system_analyze ( void  )
virtual

Analyzes the system to determine if platform or algorithm changes are necessary.

This function should return a 0 unless the MAPE loop should stop.

Member Data Documentation

◆ accents_

algorithms::Algorithms gams::controllers::BaseController::accents_
protected

Accents on the primary algorithm.

Definition at line 365 of file BaseController.h.

◆ agents_

variables::Agents gams::controllers::BaseController::agents_
protected

Containers for agent-related variables.

Definition at line 374 of file BaseController.h.

◆ algorithm_

algorithms::BaseAlgorithm* gams::controllers::BaseController::algorithm_
protected

Algorithm to perform.

Definition at line 368 of file BaseController.h.

◆ algorithms_

variables::Algorithms gams::controllers::BaseController::algorithms_
protected

Containers for algorithm information.

Definition at line 371 of file BaseController.h.

◆ checkpoint_count_

int gams::controllers::BaseController::checkpoint_count_
protected

keeps track of the checkpoints saved in the control loop

Definition at line 398 of file BaseController.h.

◆ knowledge_

madara::knowledge::KnowledgeBase& gams::controllers::BaseController::knowledge_
protected

Knowledge base.

Definition at line 377 of file BaseController.h.

◆ platform_

platforms::BasePlatform* gams::controllers::BaseController::platform_
protected

Platform on which the controller is running.

Definition at line 380 of file BaseController.h.

◆ platforms_

variables::Platforms gams::controllers::BaseController::platforms_
protected

Containers for platform information.

Definition at line 383 of file BaseController.h.

◆ self_

variables::Self gams::controllers::BaseController::self_
protected

Containers for self-referencing variables.

Definition at line 386 of file BaseController.h.

◆ sensors_

variables::Sensors gams::controllers::BaseController::sensors_
protected

Containers for sensor information.

Definition at line 389 of file BaseController.h.

◆ settings_

ControllerSettings gams::controllers::BaseController::settings_
protected

Settings for controller management and qos.

Definition at line 395 of file BaseController.h.

◆ swarm_

variables::Swarm gams::controllers::BaseController::swarm_
protected

Containers for swarm-related variables.

Definition at line 392 of file BaseController.h.


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