GAMS  1.4.0
gams::controllers::Multicontroller Class Reference

A controller that has the capability of managing multiple controllers. More...

#include <Multicontroller.h>

Public Member Functions

 Multicontroller (size_t num_controllers=1, const ControllerSettings &settings=ControllerSettings())
 Constructor. More...
 
virtual ~Multicontroller ()
 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...
 
void add_transports (const madara::transport::QoSTransportSettings &source_settings)
 Add transports to the knowledge bases that are being used by each controller. More...
 
void clear_accents (size_t controller_index=0)
 Clears all accent algorithms. More...
 
void clear_knowledge (void)
 Clears all controller knowledge bases. More...
 
void evaluate (const std::string &logic, const madara::knowledge::EvalSettings &settings=madara::knowledge::EvalSettings::DELAY)
 Evaluates a karl logic across all controllers and knowledge bases. More...
 
void evaluate (size_t controller_index, const std::string &logic, const madara::knowledge::EvalSettings &settings=madara::knowledge::EvalSettings::DELAY)
 Evaluates a karl logic across all controllers and knowledge bases. More...
 
algorithms::BaseAlgorithmget_algorithm (size_t controller_index=0)
 Gets the current algorithm at the controller index. More...
 
madara::knowledge::KnowledgeBase get_kb (size_t controller_index)
 Returns the kb that is being used by the internal controller. More...
 
size_t get_num_controllers (void)
 Returns the number of controllers being managed. More...
 
platforms::BasePlatformget_platform (size_t controller_index=0)
 Gets the current platform at the controller index. More...
 
void init_accent (const std::string &algorithm, const madara::knowledge::KnowledgeMap &args=madara::knowledge::KnowledgeMap())
 Initializes all managed controllers with an accent algorithm. More...
 
void init_accent (size_t controller_index, const std::string &algorithm, const madara::knowledge::KnowledgeMap &args=madara::knowledge::KnowledgeMap())
 Adds an accent algorithm. More...
 
void init_algorithm (const std::string &algorithm, const madara::knowledge::KnowledgeMap &args=madara::knowledge::KnowledgeMap())
 Initializes all managed controllers with an algorithm. More...
 
void init_algorithm (size_t controller_index, algorithms::BaseAlgorithm *algorithm)
 Initializes the controller with a user-provided algorithm. More...
 
void init_algorithm (size_t controller_index, const std::string &algorithm, const madara::knowledge::KnowledgeMap &args=madara::knowledge::KnowledgeMap())
 Initializes a specific controller with an algorithm. More...
 
void init_platform (const std::string &platform, const madara::knowledge::KnowledgeMap &args=madara::knowledge::KnowledgeMap())
 Initializes all managed controllers with the platform. More...
 
void init_platform (size_t controller_index, const std::string &platform, const madara::knowledge::KnowledgeMap &args=madara::knowledge::KnowledgeMap())
 Initializes the platform. More...
 
void init_platform (size_t controller_index, platforms::BasePlatform *platform)
 Initializes the controller with a user-provided platform. More...
 
void init_vars (const madara::knowledge::KnowledgeRecord::Integer &id=0, const madara::knowledge::KnowledgeRecord::Integer &processes=-1)
 Initializes global variable containers. More...
 
void init_vars (size_t controller_index, algorithms::BaseAlgorithm &algorithm)
 Initializes containers and knowledge base in an algorithm. More...
 
void init_vars (size_t controller_index, 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...
 
void refresh_vars (bool init_non_self_vars=false)
 Calls init_vars for each controller. More...
 
void resize (size_t num_controllers, bool init_non_self_vars=false)
 Resizes the number of controllers and knowledge bases. 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...
 

Protected Attributes

std::vector< BaseController * > controllers_
 Controllers that need to be instrumented. More...
 
std::vector< madara::knowledge::KnowledgeBase > kbs_
 Knowledge base. More...
 
ControllerSettings settings_
 Settings for controller management and qos. More...
 
int sim_step_ = 0
 used explicitly by the scrimmage platform. Will be moved More...
 
std::vector< madara::transport::SharedMemoryPush * > transports_
 transports meant for fast memory transport within the controller More...
 

Detailed Description

A controller that has the capability of managing multiple controllers.

Definition at line 89 of file Multicontroller.h.

Constructor & Destructor Documentation

◆ Multicontroller()

gams::controllers::Multicontroller::Multicontroller ( size_t  num_controllers = 1,
const ControllerSettings settings = ControllerSettings() 
)

Constructor.

Parameters
num_controllersthe number of controllers to manage
settingssettings to use

◆ ~Multicontroller()

virtual gams::controllers::Multicontroller::~Multicontroller ( )
virtual

Destructor.

Member Function Documentation

◆ add_algorithm_factory()

void gams::controllers::Multicontroller::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 Multicontroller.

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::Multicontroller::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 Multicontroller.

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

◆ add_transports()

void gams::controllers::Multicontroller::add_transports ( const madara::transport::QoSTransportSettings &  source_settings)

Add transports to the knowledge bases that are being used by each controller.

If multicast or broadcast transports, the hosts are simply copied. If using unicast-based connections, then the first host in the settings is used and ports are added in an ascending order for each subsequent KB. This latter functionality is meant to aid in the expected use case of the Multicontroller managing colocated agents that need to communicate with each other. Note that you should resize the Multicontroller to the appropriate number of controllers BEFORE calling this function. Changes made here are not retroactive for all future resizes.

Parameters
source_settingsbase transport settings to copy from

◆ clear_accents()

void gams::controllers::Multicontroller::clear_accents ( size_t  controller_index = 0)

Clears all accent algorithms.

Parameters
controller_indexthe index of the managed controllers

◆ clear_knowledge()

void gams::controllers::Multicontroller::clear_knowledge ( void  )

Clears all controller knowledge bases.

◆ evaluate() [1/2]

void gams::controllers::Multicontroller::evaluate ( const std::string &  logic,
const madara::knowledge::EvalSettings &  settings = madara::knowledge::EvalSettings::DELAY 
)

Evaluates a karl logic across all controllers and knowledge bases.

Parameters
logickarl logic to evaluate
settingsevaluation settings for the logic evaluation

◆ evaluate() [2/2]

void gams::controllers::Multicontroller::evaluate ( size_t  controller_index,
const std::string &  logic,
const madara::knowledge::EvalSettings &  settings = madara::knowledge::EvalSettings::DELAY 
)

Evaluates a karl logic across all controllers and knowledge bases.

Parameters
controller_indexthe index of the managed controllers
logickarl logic to evaluate
settingsevaluation settings for the logic evaluation

◆ get_algorithm()

algorithms::BaseAlgorithm* gams::controllers::Multicontroller::get_algorithm ( size_t  controller_index = 0)

Gets the current algorithm at the controller index.

Parameters
controller_indexthe index of the managed controllers
Returns
the algorithm

◆ get_kb()

madara::knowledge::KnowledgeBase gams::controllers::Multicontroller::get_kb ( size_t  controller_index)

Returns the kb that is being used by the internal controller.

Parameters
controller_indexthe index of the managed controllers
Returns
the knowledge base that is being referenced

◆ get_num_controllers()

size_t gams::controllers::Multicontroller::get_num_controllers ( void  )

Returns the number of controllers being managed.

Returns
the number of controllers managed by the multicontroller

◆ get_platform()

platforms::BasePlatform* gams::controllers::Multicontroller::get_platform ( size_t  controller_index = 0)

Gets the current platform at the controller index.

Parameters
controller_indexthe index of the managed controllers
Returns
the platform

◆ init_accent() [1/2]

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

Initializes all managed controllers with an accent algorithm.

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

◆ init_accent() [2/2]

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

Adds an accent algorithm.

Parameters
controller_indexthe index of the managed controllers
algorithmthe name of the accent algorithm to add
argsvector of knowledge record arguments

◆ init_algorithm() [1/3]

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

Initializes all managed controllers with an algorithm.

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

◆ init_algorithm() [2/3]

void gams::controllers::Multicontroller::init_algorithm ( size_t  controller_index,
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
controller_indexthe index of the managed controllers
algorithmthe algorithm to use

◆ init_algorithm() [3/3]

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

Initializes a specific controller with an algorithm.

Parameters
controller_indexthe index of the managed controllers
algorithmthe name of the algorithm to run
argsvector of knowledge record arguments

◆ init_platform() [1/3]

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

Initializes all managed controllers with the platform.

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

◆ init_platform() [2/3]

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

Initializes the platform.

Parameters
controller_indexthe index of the managed controllers
platformthe name of the platform the controller is using
argsvector of knowledge record arguments

◆ init_platform() [3/3]

void gams::controllers::Multicontroller::init_platform ( size_t  controller_index,
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
controller_indexthe index of the managed controllers
platformthe platform to use

◆ init_vars() [1/3]

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

Initializes global variable containers.

Parameters
idnode identifier
processesprocesses

◆ init_vars() [2/3]

void gams::controllers::Multicontroller::init_vars ( size_t  controller_index,
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
controller_indexthe index of the managed controllers
algorithmthe algorithm to initialize

◆ init_vars() [3/3]

void gams::controllers::Multicontroller::init_vars ( size_t  controller_index,
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
controller_indexthe index of the managed controllers
platformthe platform to initialize

◆ refresh_vars()

void gams::controllers::Multicontroller::refresh_vars ( bool  init_non_self_vars = false)

Calls init_vars for each controller.

Useful after clearing knowledge to repopulate the self identifying variables

Parameters
init_non_self_varsif true, populate agent vars for swarm, which is very memory expensive with 400+

◆ resize()

void gams::controllers::Multicontroller::resize ( size_t  num_controllers,
bool  init_non_self_vars = false 
)

Resizes the number of controllers and knowledge bases.

Parameters
num_controllersthe number of controllers to manage
init_non_self_varsif true, populate agent vars for swarm, which is very memory expensive with 400+

◆ run() [1/2]

int gams::controllers::Multicontroller::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::Multicontroller::run ( void  )

Runs iterations of the MAPE loop with configured settings.

Returns
the result of the MAPE loop

◆ run_hz()

int gams::controllers::Multicontroller::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 381 of file Multicontroller.h.

◆ run_once()

int gams::controllers::Multicontroller::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

Member Data Documentation

◆ controllers_

std::vector<BaseController *> gams::controllers::Multicontroller::controllers_
protected

Controllers that need to be instrumented.

Definition at line 407 of file Multicontroller.h.

◆ kbs_

std::vector<madara::knowledge::KnowledgeBase> gams::controllers::Multicontroller::kbs_
protected

Knowledge base.

Definition at line 410 of file Multicontroller.h.

◆ settings_

ControllerSettings gams::controllers::Multicontroller::settings_
protected

Settings for controller management and qos.

Definition at line 416 of file Multicontroller.h.

◆ sim_step_

int gams::controllers::Multicontroller::sim_step_ = 0
protected

used explicitly by the scrimmage platform. Will be moved

Definition at line 419 of file Multicontroller.h.

◆ transports_

std::vector<madara::transport::SharedMemoryPush *> gams::controllers::Multicontroller::transports_
protected

transports meant for fast memory transport within the controller

Definition at line 413 of file Multicontroller.h.


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