Drake
Drake C++ Documentation
Loading...
Searching...
No Matches
Environment Class Reference

Detailed Description

Represents a symbolic environment (mapping from a variable to a value).

This class is used when we evaluate symbolic expressions or formulas which include unquantified (free) variables. Here are examples:

const Variable var_x{"x"};
const Variable var_y{"y"};
const Expression x{var_x};
const Expression y{var_x};
const Expression e1{x + y};
const Expression e2{x - y};
const Formula f{e1 > e2};
// env maps var_x to 2.0 and var_y to 3.0
const Environment env{{var_x, 2.0}, {var_y, 3.0}};
const double res1 = e1.Evaluate(env); // x + y => 2.0 + 3.0 => 5.0
const double res2 = e2.Evaluate(env); // x - y => 2.0 - 3.0 => -1.0
const bool res = f.Evaluate(env); // x + y > x - y => 5.0 >= -1.0 => True
Environment(const Environment &)=default
Represents a symbolic variable.
Definition variable.h:34
x
Definition light_parameter.h:147

#include <drake/common/symbolic/expression/environment.h>

Public Types

typedef Variable key_type
typedef double mapped_type
typedef std::unordered_map< key_type, mapped_typemap
typedef map::value_type value_type
 std::pair<key_type, mapped_type>
typedef map::iterator iterator
typedef map::const_iterator const_iterator

Public Member Functions

 Environment ()=default
 Default constructor.
 Environment (std::initializer_list< value_type > init)
 List constructor.
 Environment (std::initializer_list< key_type > vars)
 List constructor.
 Environment (map m)
 Constructs an environment from m (of map type, which is std::unordered_map).
 ~Environment ()
iterator begin ()
 Returns an iterator to the beginning.
iterator end ()
 Returns an iterator to the end.
const_iterator begin () const
 Returns a const iterator to the beginning.
const_iterator end () const
 Returns a const iterator to the end.
const_iterator cbegin () const
 Returns a const iterator to the beginning.
const_iterator cend () const
 Returns a const iterator to the end.
void insert (const key_type &key, const mapped_type &elem)
 Inserts a pair (key, elem) if this environment doesn't contain key.
void insert (const Eigen::Ref< const MatrixX< key_type > > &keys, const Eigen::Ref< const MatrixX< mapped_type > > &elements)
 Given a matrix of symbolic variables keys and a matrix of values elements, inserts each pair (keys(i, j), elements(i, j)) into the environment if this environment doesn't contain keys(i, j) .
bool empty () const
 Checks whether the container is empty.
size_t size () const
 Returns the number of elements.
iterator find (const key_type &key)
 Finds element with specific key.
const_iterator find (const key_type &key) const
 Finds element with specific key.
Variables domain () const
 Returns the domain of this environment.
std::string to_string () const
 Returns string representation.
mapped_typeoperator[] (const key_type &key)
 Returns a reference to the value that is mapped to a key equivalent to key, performing an insertion if such key does not already exist.
const mapped_typeoperator[] (const key_type &key) const
 As above, but returns a constref and does not perform an insertion (throwing a runtime error instead) if the key does not exist.
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 Environment (const Environment &)=default
Environmentoperator= (const Environment &)=default
 Environment (Environment &&)=default
Environmentoperator= (Environment &&)=default

Friends

std::ostream & operator<< (std::ostream &os, const Environment &env)

Member Typedef Documentation

◆ const_iterator

typedef map::const_iterator const_iterator

◆ iterator

typedef map::iterator iterator

◆ key_type

typedef Variable key_type

◆ map

typedef std::unordered_map<key_type, mapped_type> map

◆ mapped_type

◆ value_type

typedef map::value_type value_type

std::pair<key_type, mapped_type>

Constructor & Destructor Documentation

◆ Environment() [1/6]

Environment ( const Environment & )
default

◆ Environment() [2/6]

Environment ( Environment && )
default

◆ Environment() [3/6]

Environment ( )
default

Default constructor.

◆ Environment() [4/6]

Environment ( std::initializer_list< value_type > init)

List constructor.

Constructs an environment from a list of (Variable * double).

Exceptions
std::exceptionif init include a dummy variable or a NaN value.

◆ Environment() [5/6]

Environment ( std::initializer_list< key_type > vars)

List constructor.

Constructs an environment from a list of Variable. Initializes the variables with 0.0.

Exceptions
std::exceptionif vars include a dummy variable.

◆ Environment() [6/6]

Environment ( map m)
explicit

Constructs an environment from m (of map type, which is std::unordered_map).

Exceptions
std::exceptionif m include a dummy variable or a NaN value.

◆ ~Environment()

Member Function Documentation

◆ begin() [1/2]

iterator begin ( )

Returns an iterator to the beginning.

◆ begin() [2/2]

const_iterator begin ( ) const
nodiscard

Returns a const iterator to the beginning.

◆ cbegin()

const_iterator cbegin ( ) const
nodiscard

Returns a const iterator to the beginning.

◆ cend()

const_iterator cend ( ) const
nodiscard

Returns a const iterator to the end.

◆ domain()

Variables domain ( ) const
nodiscard

Returns the domain of this environment.

◆ empty()

bool empty ( ) const
nodiscard

Checks whether the container is empty.

◆ end() [1/2]

iterator end ( )

Returns an iterator to the end.

◆ end() [2/2]

const_iterator end ( ) const
nodiscard

Returns a const iterator to the end.

◆ find() [1/2]

iterator find ( const key_type & key)

Finds element with specific key.

◆ find() [2/2]

const_iterator find ( const key_type & key) const
nodiscard

Finds element with specific key.

◆ insert() [1/2]

void insert ( const Eigen::Ref< const MatrixX< key_type > > & keys,
const Eigen::Ref< const MatrixX< mapped_type > > & elements )

Given a matrix of symbolic variables keys and a matrix of values elements, inserts each pair (keys(i, j), elements(i, j)) into the environment if this environment doesn't contain keys(i, j) .

Similar to insert function in map, if keys(i, j) already exists in this environment, then this function doesn't change the its existing value in this environment.

Exceptions
std::exceptionif the size of keys is different from the size of elements.

◆ insert() [2/2]

void insert ( const key_type & key,
const mapped_type & elem )

Inserts a pair (key, elem) if this environment doesn't contain key.

Similar to insert function in map, if the key already exists in this environment, then calling insert(key, elem) doesn't change the existing key-value in this environment.

◆ operator=() [1/2]

Environment & operator= ( const Environment & )
default

◆ operator=() [2/2]

Environment & operator= ( Environment && )
default

◆ operator[]() [1/2]

mapped_type & operator[] ( const key_type & key)

Returns a reference to the value that is mapped to a key equivalent to key, performing an insertion if such key does not already exist.

◆ operator[]() [2/2]

const mapped_type & operator[] ( const key_type & key) const

As above, but returns a constref and does not perform an insertion (throwing a runtime error instead) if the key does not exist.

◆ size()

size_t size ( ) const
nodiscard

Returns the number of elements.

◆ to_string()

std::string to_string ( ) const
nodiscard

Returns string representation.

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const Environment & env )
friend

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