dReal4
Environment Class Reference

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

#include </home/soonhokong/work/dreal4/third_party/com_github_robotlocomotion_drake/dreal/symbolic/symbolic_environment.h>

Public Types

typedef Variable key_type
 
typedef double mapped_type
 
typedef std::unordered_map< key_type, mapped_type, hash_value< key_type > > map
 
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 (const Environment &)=default
 
Environmentoperator= (const Environment &)=default
 
 Environment (Environment &&)=default
 
Environmentoperator= (Environment &&)=default
 
 Environment ()=default
 Default constructor. More...
 
 ~Environment ()=default
 Default destructor. More...
 
 Environment (std::initializer_list< value_type > init)
 List constructor. More...
 
 Environment (std::initializer_list< key_type > vars)
 List constructor. More...
 
 Environment (map m)
 Constructs an environment from m.
 
iterator begin ()
 Returns an iterator to the beginning. More...
 
iterator end ()
 Returns an iterator to the end. More...
 
const_iterator begin () const
 Returns a const iterator to the beginning. More...
 
const_iterator end () const
 Returns a const iterator to the end. More...
 
const_iterator cbegin () const
 Returns a const iterator to the beginning. More...
 
const_iterator cend () const
 Returns a const iterator to the end. More...
 
void insert (const key_type &key, const mapped_type &elem)
 Inserts a pair (key, elem). More...
 
bool empty () const
 Checks whether the container is empty. More...
 
size_t size () const
 Returns the number of elements. More...
 
iterator find (const key_type &key)
 Finds element with specific key. More...
 
const_iterator find (const key_type &key) const
 Finds element with specific key. More...
 
Variables domain () const
 Returns the domain of this environment. More...
 
std::string to_string () const
 Returns string representation. More...
 
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.
 
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. More...
 

Friends

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

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

Note that it is not allowed to have a dummy variable in an environment. It throws std::runtime_error for the attempts to create an environment with a dummy variable, to insert a dummy variable to an existing environment, or to take a reference to a value mapped to a dummy variable. See the following examples.

Variable var_dummy{}; // OK to have a dummy variable
Environment e1{var_dummy}; // throws std::runtime_error exception
Environment e2{{var_dummy, 1.0}}; // throws std::runtime_error exception
e.insert(var_dummy, 1.0); // throws std::runtime_error exception
e[var_dummy] = 3.0; // throws std::runtime_error exception

Constructor & Destructor Documentation

◆ Environment() [1/3]

Environment ( )
default

Default constructor.

◆ ~Environment()

~Environment ( )
default

Default destructor.

◆ Environment() [2/3]

Environment ( std::initializer_list< value_type init)

List constructor.

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

◆ Environment() [3/3]

Environment ( std::initializer_list< key_type vars)

List constructor.

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

Member Function Documentation

◆ begin() [1/2]

iterator begin ( )
inline

Returns an iterator to the beginning.

◆ begin() [2/2]

const_iterator begin ( ) const
inline

Returns a const iterator to the beginning.

◆ cbegin()

const_iterator cbegin ( ) const
inline

Returns a const iterator to the beginning.

◆ cend()

const_iterator cend ( ) const
inline

Returns a const iterator to the end.

◆ domain()

Variables domain ( ) const

Returns the domain of this environment.

◆ empty()

bool empty ( ) const
inline

Checks whether the container is empty.

◆ end() [1/2]

iterator end ( )
inline

Returns an iterator to the end.

◆ end() [2/2]

const_iterator end ( ) const
inline

Returns a const iterator to the end.

◆ find() [1/2]

iterator find ( const key_type key)
inline

Finds element with specific key.

◆ find() [2/2]

const_iterator find ( const key_type key) const
inline

Finds element with specific key.

◆ insert()

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

Inserts a pair (key, elem).

◆ operator[]()

const Environment::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
inline

Returns the number of elements.

◆ to_string()

string to_string ( ) const

Returns string representation.


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