dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
dlinear::drake::symbolic::Environment Class Reference

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

#include <symbolic_environment.h>

Public Types

typedef map::value_type value_type
 std::pair<key_type, mapped_type>
 

Public Member Functions

 Environment ()=default
 Default constructor.
 
 ~Environment ()=default
 Default destructor.
 
 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.
 
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.
 
std::pair< Environment::iterator, bool > insert (const key_type &key, const mapped_type &elem)
 Inserts a pair (key, elem).
 
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.
 
const mapped_type & at (const key_type &key) const
 Returns the value that is mapped to a key equivalent to key.
 
std::size_t erase (const key_type &key)
 Erases the element with specific key.
 
void erase (const iterator &pos)
 Erases the element at the specified pos.
 
Variables domain () const
 Returns the domain of this environment.
 
std::string to_string () const
 Returns string representation.
 
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.
 
bool contains (const key_type &key) const
 Checks whether the environment contains a variable key.
 

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 mpq_class& res1 = e1.Evaluate(env); // x + y => 2.0 + 3.0 => 5.0
const mpq_class& 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()=default
Default constructor.
Represents a symbolic form of an expression.
mpq_class Evaluate(const Environment &env=Environment{}) const
Evaluates under a given environment (by default, an empty environment).
Represents a symbolic variable.

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
Represents a symbolic environment (mapping from a variable to a value).
std::pair< Environment::iterator, bool > insert(const key_type &key, const mapped_type &elem)
Inserts a pair (key, elem).

Definition at line 51 of file symbolic_environment.h.

Constructor & Destructor Documentation

◆ Environment() [1/2]

dlinear::drake::symbolic::Environment::Environment ( std::initializer_list< value_type > init)

List constructor.

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

◆ Environment() [2/2]

dlinear::drake::symbolic::Environment::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

◆ empty()

bool dlinear::drake::symbolic::Environment::empty ( ) const
inline

Checks whether the container is empty.


Definition at line 101 of file symbolic_environment.h.


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