MultiAgentDecisionProcess
MADPComponentDiscreteActions Class Reference

MADPComponentDiscreteActions contains functionality for discrete action spaces. More...

#include <MADPComponentDiscreteActions.h>

Public Member Functions

void AddAction (Index AI, const std::string &name, const std::string &description="")
 Add a new action with name "name" to the actions of agent AI. More...
 
size_t ConstructJointActions ()
 Recursively constructs all the joint actions. More...
 
const ActionGetAction (Index agentI, Index a) const
 Return a ref to the a-th action of agent agentI. More...
 
const ActionDiscreteGetActionDiscrete (Index agentI, Index a) const
 Return a ref to the a-th action of agent agentI. More...
 
Index GetActionIndexByName (const std::string &s, Index agentI) const
 Returns the action index of the agent I's action s. More...
 
std::string GetActionName (Index a, Index i) const
 Returns the name of a particular action a of agent i. More...
 
const JointActionGetJointAction (Index i) const
 Return a ref to the i-th joint action. More...
 
const JointActionDiscreteGetJointActionDiscrete (Index i) const
 Return a ref to the i-th joint action (a JointActionDiscrete). More...
 
std::string GetJointActionName (Index a) const
 Returns the name of a particular joint action a. More...
 
const std::vector< size_t > & GetNrActions () const
 Return the number of actions vector. More...
 
size_t GetNrActions (Index AgentI) const
 Return the number of actions of agent agentI. More...
 
size_t GetNrJointActions () const
 Return the number of joiny actions. More...
 
size_t GetNrJointActions (const Scope &agScope) const
 Get the number of joint actions the agents in agScope can form. More...
 
Index IndividualToJointActionIndices (const std::vector< Index > &indivActionIndices) const
 Returns the joint action index that corresponds to the vector of specified individual action indices. More...
 
Index IndividualToJointActionIndices (const Index *IndexArray) const
 Returns the joint action index that corresponds to the array of specified individual action indices. More...
 
Index IndividualToJointActionIndices (const std::vector< Index > &ja_e, const Scope &agSC) const
 
bool JointIndicesValid () const
 Find out if there is an overflow in the joint indices variable. More...
 
const std::vector< Index > & JointToIndividualActionIndices (Index jaI) const
 Returns a vector of indices to indiv. More...
 
std::vector< IndexJointToIndividualActionIndices (Index ja_e, const Scope &agSC) const
 
Index JointToRestrictedJointActionIndex (Index jaI, const Scope &agSc_e) const
 
 MADPComponentDiscreteActions ()
 Default constructor. More...
 
 MADPComponentDiscreteActions (const MADPComponentDiscreteActions &a)
 Copy constructor. More...
 
void Print () const
 
bool SetInitialized (bool b)
 Sets _m_initialized to b. More...
 
void SetNrActions (Index AI, size_t nrA)
 Sets the number of actions for agent AI. More...
 
std::string SoftPrint () const
 
virtual ~MADPComponentDiscreteActions ()
 Destructor. More...
 

Private Member Functions

size_t ConstructJointActionsRecursively (Index curAgentI, JointActionDiscrete &ja, Index jaI)
 Recursively creates the joint actions. More...
 
std::string SoftPrintActionSets () const
 
std::string SoftPrintJointActionSet () const
 

Private Attributes

size_t * _m_actionStepSize
 The stepsize array - used for indiv->joint index calculation. More...
 
std::vector< std::vector
< ActionDiscrete > > 
_m_actionVecs
 The vectors of actions (vectors of ActionDiscrete) for each agent. More...
 
bool _m_cachedAllJointActions
 
bool _m_initialized
 
std::map< Index, std::vector
< Index > * > * 
_m_jointActionIndices
 When not all joint actions have been created, here we cache the individual indices created by JointToIndividualActionIndices() More...
 
std::vector
< JointActionDiscrete * > 
_m_jointActionVec
 The vector storing pointers to joint actions. More...
 
bool _m_jointIndicesValid
 
std::vector< size_t > _m_nrActions
 The number of actions for each agent. More...
 
size_t _m_nrJointActions
 

Detailed Description

MADPComponentDiscreteActions contains functionality for discrete action spaces.

It implements a part of the MultiAgentDecisionProcessDiscreteInterface.

Constructor & Destructor Documentation

MADPComponentDiscreteActions::MADPComponentDiscreteActions ( )

Default constructor.

MADPComponentDiscreteActions::~MADPComponentDiscreteActions ( )
virtual

Destructor.

Member Function Documentation

void MADPComponentDiscreteActions::AddAction ( Index  AI,
const std::string &  name,
const std::string &  description = "" 
)

Add a new action with name "name" to the actions of agent AI.

References DEBUG_ADD_DA.

Referenced by MultiAgentDecisionProcessDiscrete::AddAction(), and MultiAgentDecisionProcessDiscreteFactoredStates::AddAction().

size_t MADPComponentDiscreteActions::ConstructJointActions ( )
size_t MADPComponentDiscreteActions::ConstructJointActionsRecursively ( Index  curAgentI,
JointActionDiscrete ja,
Index  jaI 
)
private

Recursively creates the joint actions.

Creates (_m_jointActionVec) using _m_actionVecs (which need to be initialized before calling this function...)

References JointActionDiscrete::AddIndividualAction(), DEBUG_CJA, JointAction::Print(), and DiscreteEntity::SetIndex().

const Action * MADPComponentDiscreteActions::GetAction ( Index  agentI,
Index  a 
) const

Return a ref to the a-th action of agent agentI.

Referenced by MultiAgentDecisionProcessDiscrete::GetAction(), and MultiAgentDecisionProcessDiscreteFactoredStates::GetAction().

const ActionDiscrete * MADPComponentDiscreteActions::GetActionDiscrete ( Index  agentI,
Index  a 
) const

Return a ref to the a-th action of agent agentI.

Referenced by MultiAgentDecisionProcessDiscrete::GetActionDiscrete().

Index MADPComponentDiscreteActions::GetActionIndexByName ( const std::string &  s,
Index  agentI 
) const

Returns the action index of the agent I's action s.

Throws an exception if there is no action with name s.

Referenced by MultiAgentDecisionProcessDiscrete::GetActionIndexByName().

std::string MADPComponentDiscreteActions::GetActionName ( Index  a,
Index  i 
) const
inline

Returns the name of a particular action a of agent i.

const JointAction * MADPComponentDiscreteActions::GetJointAction ( Index  i) const
const JointActionDiscrete * MADPComponentDiscreteActions::GetJointActionDiscrete ( Index  i) const

Return a ref to the i-th joint action (a JointActionDiscrete).

Referenced by JointToIndividualActionIndices().

std::string MADPComponentDiscreteActions::GetJointActionName ( Index  a) const
inline

Returns the name of a particular joint action a.

Referenced by MultiAgentDecisionProcessDiscrete::SanityCheck().

const std::vector<size_t>& MADPComponentDiscreteActions::GetNrActions ( ) const
inline
size_t MADPComponentDiscreteActions::GetNrActions ( Index  AgentI) const

Return the number of actions of agent agentI.

size_t MADPComponentDiscreteActions::GetNrJointActions ( ) const
size_t MADPComponentDiscreteActions::GetNrJointActions ( const Scope agScope) const

Get the number of joint actions the agents in agScope can form.

References IndexTools::RestrictIndividualIndicesToScope(), and VectorTools::VectorProduct().

Index MADPComponentDiscreteActions::IndividualToJointActionIndices ( const std::vector< Index > &  indivActionIndices) const

Returns the joint action index that corresponds to the vector of specified individual action indices.

References IndexTools::IndividualToJointIndicesStepSize().

Referenced by MultiAgentDecisionProcessDiscrete::IndividualToJointActionIndices(), and MultiAgentDecisionProcessDiscreteFactoredStates::IndividualToJointActionIndices().

Index MADPComponentDiscreteActions::IndividualToJointActionIndices ( const Index IndexArray) const
inline

Returns the joint action index that corresponds to the array of specified individual action indices.

References IndexTools::IndividualToJointIndicesArrayStepSize().

Index MADPComponentDiscreteActions::IndividualToJointActionIndices ( const std::vector< Index > &  ja_e,
const Scope agSC 
) const
bool MADPComponentDiscreteActions::JointIndicesValid ( ) const
inline

Find out if there is an overflow in the joint indices variable.

References _m_jointIndicesValid.

Referenced by MultiAgentDecisionProcessDiscreteFactoredStates::JointAIndicesValid().

const std::vector<Index>& MADPComponentDiscreteActions::JointToIndividualActionIndices ( Index  jaI) const
inline
std::vector< Index > MADPComponentDiscreteActions::JointToIndividualActionIndices ( Index  ja_e,
const Scope agSC 
) const
void MADPComponentDiscreteActions::Print ( ) const
inline

References SoftPrint().

bool MADPComponentDiscreteActions::SetInitialized ( bool  b)

Sets _m_initialized to b.

When setting to true, a verification of member elements is performed.

(i.e. a check whether all vectors have the correct size and non-zero entries)

References IndexTools::CalculateStepSize().

Referenced by MultiAgentDecisionProcessDiscrete::SetActionsInitialized(), MultiAgentDecisionProcessDiscreteFactoredStates::SetActionsInitialized(), MultiAgentDecisionProcessDiscrete::SetInitialized(), and MultiAgentDecisionProcessDiscreteFactoredStates::SetInitialized().

void MADPComponentDiscreteActions::SetNrActions ( Index  AI,
size_t  nrA 
)

Sets the number of actions for agent AI.

This creates nrA unnamed actions.

Referenced by MultiAgentDecisionProcessDiscrete::SetNrActions(), and MultiAgentDecisionProcessDiscreteFactoredStates::SetNrActions().

string MADPComponentDiscreteActions::SoftPrint ( ) const
string MADPComponentDiscreteActions::SoftPrintActionSets ( ) const
private
string MADPComponentDiscreteActions::SoftPrintJointActionSet ( ) const
private

Member Data Documentation

size_t* MADPComponentDiscreteActions::_m_actionStepSize
private

The stepsize array - used for indiv->joint index calculation.

std::vector<std::vector<ActionDiscrete> > MADPComponentDiscreteActions::_m_actionVecs
private

The vectors of actions (vectors of ActionDiscrete) for each agent.

Referenced by MADPComponentDiscreteActions().

bool MADPComponentDiscreteActions::_m_cachedAllJointActions
private
bool MADPComponentDiscreteActions::_m_initialized
private
std::map<Index, std::vector<Index> *>* MADPComponentDiscreteActions::_m_jointActionIndices
private

When not all joint actions have been created, here we cache the individual indices created by JointToIndividualActionIndices()

Referenced by MADPComponentDiscreteActions().

std::vector<JointActionDiscrete*> MADPComponentDiscreteActions::_m_jointActionVec
private

The vector storing pointers to joint actions.

To use this, ConstructJointActions() should be called

Referenced by MADPComponentDiscreteActions().

bool MADPComponentDiscreteActions::_m_jointIndicesValid
private
std::vector<size_t> MADPComponentDiscreteActions::_m_nrActions
private

The number of actions for each agent.

Referenced by GetNrActions(), and MADPComponentDiscreteActions().

size_t MADPComponentDiscreteActions::_m_nrJointActions
private