Class sdm::MultiDiscreteSpace

Class List > sdm > MultiDiscreteSpace

This class provide a way to instantiate multi discrete space (i.e. list of discrete spaces). Typically it is used to store a set of spaces, one by agent (i.e. action_spaces in POSG). This can be view as a set of discrete spaces or as a discrete space of joint items. More...

  • #include <multi_discrete_space.hpp>

Inherits the following classes: sdm::DiscreteSpace, sdm::Joint

Public Types

Type Name
typedef DiscreteSpace::iterator_type iterator_type
typedef Joint< std::shared_ptr< Item > > value_type

Public Types inherited from sdm::DiscreteSpace

See sdm::DiscreteSpace

Type Name
typedef Space::iterator_type iterator_type
typedef std::shared_ptr< Item > value_type

Public Types inherited from sdm::Space

See sdm::Space

Type Name
typedef std::shared_ptr< ItemIterator > iterator_type

Public Types inherited from sdm::Joint

See sdm::Joint

Type Name
typedef T value_type

Public Types inherited from sdm::Function

See sdm::Function

Type Name
typedef TInput input_type
typedef TOutput output_type

Public Functions

Type Name
MultiDiscreteSpace ()
Instantiate a default discrete space ( MultiDiscreteSpace class)
MultiDiscreteSpace (const std::vector< std::shared_ptr< Space >> & sub_spaces, bool store_items=true)
Instantiate a multi discrete space from the list its sub-spaces (as shared pointer).
MultiDiscreteSpace (const std::vector< std::vector< std::shared_ptr< Item >>> & values, bool store_items=true)
Instantiate a multi discrete space from the list its sub-spaces (as shared pointer).
MultiDiscreteSpace (const MultiDiscreteSpace & copy)
Copy constructor.
MultiDiscreteSpace (const std::enable_if_t< TBool, std::vector< std::shared_ptr< Item >>> & num_items)
Instantiate a multi discrete space using a list of dimensions (one by single space). This constructor is only available for classes where std::shared_ptr<Item> is an integer (long, int, short, etc).
virtual iterator_type begin ()
bool contains (const std::shared_ptr< Item > &) const
Verify is the multi discrete space contains the Joint <std::shared_ptr<Item>>;.
virtual iterator_type end ()
std::vector< std::shared_ptr< Item > > getAll ()
Get all the joint values.
std::shared_ptr< Item > getItem (number index) const
Get a specific item from its index.
std::shared_ptr< Item > getItem (number ag_id, number item_index) const
Get a specific item for a given agent (from its index)
number getItemIndex (number ag_id, const std::shared_ptr< Item > & item) const
Get a specific index of an item for a given agent.
std::shared_ptr< Item > getJointItem (number) const
Get the corresponding joint item from its index.
number getJointItemIndex (std::shared_ptr< Joint< std::shared_ptr< Item >>> & jitem) const
Transform joint item to its index in the list of all joint items.
number getNumSpaces () const
Get the number of sub-space.
std::shared_ptr< Space > getSpace (number index) const
Get a specific subspace.
bool operator!= (const MultiDiscreteSpace & other) const
MultiDiscreteSpace & operator= (const MultiDiscreteSpace &)
bool operator== (const MultiDiscreteSpace & other) const
void setSpaces (const std::enable_if_t< TBool, std::vector< std::shared_ptr< Item >>> & num_items)
void setSpaces (const std::vector< std::vector< std::shared_ptr< Item >>> &)
void setSpaces (const std::vector< std::shared_ptr< Space >> & spaces)
virtual std::string str () const
Space as a string.

Public Functions inherited from sdm::DiscreteSpace

See sdm::DiscreteSpace

Type Name
DiscreteSpace ()
Construct a new Discrete Space object (default)
DiscreteSpace (const std::vector< std::shared_ptr< Item >> & items)
Construct a new Discrete Space object.
DiscreteSpace (const std::vector< T > & items)
DiscreteSpace (std::initializer_list< std::shared_ptr< Item >> vals)
Construct a new Discrete Space object from a list initializer.
DiscreteSpace (const DiscreteSpace & copy)
Copy constructor.
virtual iterator_type begin ()
bool contains (const std::shared_ptr< Item > &) const
Verify is the discrete space contains the std::shared_ptr<Item>;.
virtual iterator_type end ()
int find (const std::shared_ptr< Item > & item) const
std::vector< std::shared_ptr< Item > > getAll ()
Get all possible items in the space.
virtual std::vector< number > getDim () const
Get the dimension.
std::shared_ptr< Item > getItem (number index) const
Get the item at a specific index.
std::shared_ptr< Item > getItemAddress (const T & item_value)
Get the item at a specific index.
number getItemIndex (const std::shared_ptr< Item > & item) const
Get the index of an item.
number getNumItems () const
Get the number of items in the space.
virtual bool isDiscrete () const
Return true because this is a discrete space.
bool isStoringItems () const
bool operator!= (const DiscreteSpace & sp) const
bool operator== (const DiscreteSpace & sp) const
virtual std::shared_ptr< Item > sample () const
Sample a random item from the space.
std::string short_str () const
void storeItems (bool store_items)
virtual std::string str () const
Space as a string.

Public Functions inherited from sdm::Space

See sdm::Space

Type Name
virtual iterator_type begin () = 0
virtual iterator_type end () = 0
virtual std::vector< number > getDim () const = 0
Get the dimension of the space.
bool isContinuous () const
Check if the space is continous.
virtual bool isDiscrete () const = 0
Check if the space is discrete.
bool operator!= (const Space & sp) const
bool operator== (const Space & sp) const
virtual std::shared_ptr< Item > sample () const
Sample a random item from the space.
virtual std::string str () const = 0
Space as a string.
std::shared_ptr< DiscreteSpace > toDiscreteSpace ()
std::shared_ptr< MultiDiscreteSpace > toMultiDiscreteSpace ()
virtual ~Space ()

Public Functions inherited from sdm::Joint

See sdm::Joint

Type Name
Joint ()
Joint (const std::vector< T > & joint_item)
Joint (const std::vector< number > &, const std::vector< T > & joint_item)
Joint (std::initializer_list< T > list_values)
const T & get (const number &) const
Get the element for agent i.
number getNumAgents () const
Get the number of agents (i.e. the size of the joint element)
virtual T operator() (const number &)
Get the element for agent i.
void serialize (Archive & archive, const unsigned int)
std::string str () const
std::shared_ptr< Joint< std::shared_ptr< TOutput > > > toJoint ()
virtual ~Joint ()

Public Functions inherited from sdm::Function

See sdm::Function

Type Name
virtual output_type operator() (const input_type &) = 0
virtual ~Function ()

Protected Types

Type Name
typedef DiscreteSpace::items_bimap jitems_bimap
typedef jitems_bimap::value_type jitems_bimap_value

Protected Types inherited from sdm::DiscreteSpace

See sdm::DiscreteSpace

Type Name
typedef boost::bimaps::bimap< number, std::shared_ptr< Item > > items_bimap
typedef items_bimap::value_type items_bimap_value

Protected Attributes inherited from sdm::DiscreteSpace

See sdm::DiscreteSpace

Type Name
items_bimap all_items_
the list of possible items in the space with their index
std::vector< std::shared_ptr< Item > > list_items_
the list of possible items without their index
number num_items_
number of possible items in the space (ex: [5, 12] > 8 items)
bool store_items_ = = true

Protected Functions

Type Name
std::shared_ptr< DiscreteSpace > cast (const std::shared_ptr< Space > & space) const
void setNumJItems (number)
Sets the number of joint items.

Protected Functions inherited from sdm::DiscreteSpace

See sdm::DiscreteSpace

Type Name
void generateItems ()
Generates all joint items and maintains a bimap of indexes and corresponding pointers of joint items.
bool isGenerated ()

Detailed Description

Template parameters:

  • std::shared_ptr<Item> The type of items in each sub-discrete space.

Public Types Documentation

typedef iterator_type

using sdm::MultiDiscreteSpace::iterator_type =  DiscreteSpace::iterator_type;

typedef value_type

using sdm::MultiDiscreteSpace::value_type =  Joint<std::shared_ptr<Item> >;

Public Functions Documentation

function MultiDiscreteSpace [1/5]

sdm::MultiDiscreteSpace::MultiDiscreteSpace () 

function MultiDiscreteSpace [2/5]

sdm::MultiDiscreteSpace::MultiDiscreteSpace (
    const std::vector< std::shared_ptr< Space >> & sub_spaces,
    bool store_items=true
) 

function MultiDiscreteSpace [3/5]

sdm::MultiDiscreteSpace::MultiDiscreteSpace (
    const std::vector< std::vector< std::shared_ptr< Item >>> & values,
    bool store_items=true
) 

function MultiDiscreteSpace [4/5]

sdm::MultiDiscreteSpace::MultiDiscreteSpace (
    const MultiDiscreteSpace & copy
) 

Parameters:

  • copy the space to be copied

function MultiDiscreteSpace [5/5]

template<bool TBool>
sdm::MultiDiscreteSpace::MultiDiscreteSpace (
    const std::enable_if_t< TBool, std::vector< std::shared_ptr< Item >>> & num_items
) 

Parameters:

  • num_items the number of items in each spaces. If {k_1, k_2} then {0, 1, ..., k_1 - 1} are possible items in first subspace and {0, 1, ..., k_2 - 1} in the second subspace.

function begin

virtual iterator_type sdm::MultiDiscreteSpace::begin () 

Implements sdm::DiscreteSpace::begin

function contains

bool sdm::MultiDiscreteSpace::contains (
    const std::shared_ptr< Item > &
) const

Returns:

true

Returns:

false

function end

virtual iterator_type sdm::MultiDiscreteSpace::end () 

Implements sdm::DiscreteSpace::end

function getAll

std::vector< std::shared_ptr< Item > > sdm::MultiDiscreteSpace::getAll () 

Returns:

the list of all possible joint items

function getItem [1/2]

std::shared_ptr< Item > sdm::MultiDiscreteSpace::getItem (
    number index
) const

Parameters:

  • index the index

Returns:

a pointer on the item

function getItem [2/2]

std::shared_ptr< Item > sdm::MultiDiscreteSpace::getItem (
    number ag_id,
    number item_index
) const

Parameters:

  • ag_id index of the agent
  • item_index the index of the item we want to get

function getItemIndex

number sdm::MultiDiscreteSpace::getItemIndex (
    number ag_id,
    const std::shared_ptr< Item > & item
) const

Parameters:

  • ag_id index of the agent
  • item the item we want to get the index

function getJointItem

std::shared_ptr< Item > sdm::MultiDiscreteSpace::getJointItem (
    number
) const

function getJointItemIndex

number sdm::MultiDiscreteSpace::getJointItemIndex (
    std::shared_ptr< Joint < std::shared_ptr< Item >>> & jitem
) const

Parameters:

  • jitem the joint item we want to get the index

Returns:

the corresponding index

function getNumSpaces

number sdm::MultiDiscreteSpace::getNumSpaces () const

function getSpace

std::shared_ptr< Space > sdm::MultiDiscreteSpace::getSpace (
    number index
) const

Parameters:

  • index the index of the space

Returns:

a shared pointer on a specific space

function operator!=

bool sdm::MultiDiscreteSpace::operator!= (
    const MultiDiscreteSpace & other
) const

function operator=

MultiDiscreteSpace & sdm::MultiDiscreteSpace::operator= (
    const MultiDiscreteSpace &
) 

function operator==

bool sdm::MultiDiscreteSpace::operator== (
    const MultiDiscreteSpace & other
) const

function setSpaces [1/3]

template<bool TBool>
void sdm::MultiDiscreteSpace::setSpaces (
    const std::enable_if_t< TBool, std::vector< std::shared_ptr< Item >>> & num_items
) 

function setSpaces [2/3]

void sdm::MultiDiscreteSpace::setSpaces (
    const std::vector< std::vector< std::shared_ptr< Item >>> &
) 

function setSpaces [3/3]

void sdm::MultiDiscreteSpace::setSpaces (
    const std::vector< std::shared_ptr< Space >> & spaces
) 

function str

virtual std::string sdm::MultiDiscreteSpace::str () const

Implements sdm::DiscreteSpace::str

Protected Types Documentation

typedef jitems_bimap

using sdm::MultiDiscreteSpace::jitems_bimap =  DiscreteSpace::items_bimap;

typedef jitems_bimap_value

using sdm::MultiDiscreteSpace::jitems_bimap_value =  jitems_bimap::value_type;

Protected Functions Documentation

function cast

inline std::shared_ptr< DiscreteSpace > sdm::MultiDiscreteSpace::cast (
    const std::shared_ptr< Space > & space
) const

function setNumJItems

void sdm::MultiDiscreteSpace::setNumJItems (
    number
) 

Friends Documentation

friend operator<<

inline friend std::ostream & sdm::MultiDiscreteSpace::operator<< (
    std::ostream & os,
    const MultiDiscreteSpace & sp
) 

The documentation for this class was generated from the following file src/sdm/core/space/multi_discrete_space.hpp