smats  0.0.1
Satisfability Modulo Arithmetic Theories Symbols
Loading...
Searching...
No Matches
smats::Environment< T > Class Template Reference

#include <environment.h>

Public Types

using key_type = Variable
 
using mapped_type = T
 
using map = std::unordered_map<key_type, T>
 
using value_type = map::value_type
 
using iterator = map::iterator
 
using const_iterator = map::const_iterator
 

Public Member Functions

 Environment ()=default
 
 Environment (std::initializer_list< value_type > init)
 
 Environment (std::span< const value_type > init)
 
 Environment (std::initializer_list< key_type > vars)
 
 Environment (std::span< const key_type > vars)
 
 Environment (map m)
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
void insert (const key_type &key, const T &elem)
 
void insert_or_assign (const key_type &key, const T &elem)
 
bool empty () const
 
std::size_t size () const
 
Variables domain () const
 
bool contains (const key_type &key) const
 
iterator find (const key_type &key)
 
const_iterator find (const key_type &key) const
 
const T & at (const key_type &key) const
 
T & operator[] (const key_type &key)
 
const T & operator[] (const key_type &key) const
 
bool operator== (const Environment< T > &other) const
 

Private Attributes

map map_
 map between variables and values
 

Detailed Description

template<class T>
class smats::Environment< T >

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 numeric_type res1 = e1.Evaluate(env); // x + y => 2.0 + 3.0 => 5.0
const numeric_type 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
Definition expression.h:185
Definition variable.h:34
Template Parameters
Ttype of the value

Constructor & Destructor Documentation

◆ Environment() [1/6]

template<class T >
smats::Environment< T >::Environment ( )
default

Construct a new environment object.

◆ Environment() [2/6]

template<class T >
smats::Environment< T >::Environment ( std::initializer_list< value_type > init)
explicit

Construct a new environment object from a list of (Variable, numeric_type).

Parameters
initinitializer list of (Variable, numeric_type)
Exceptions
std::runtime_exceptionif init include a dummy variable or a NaN value.

◆ Environment() [3/6]

template<class T >
smats::Environment< T >::Environment ( std::span< const value_type > init)
explicit

Construct a new environment object from a list of (Variable, numeric_type).

Parameters
initinitializer list of (Variable, numeric_type)
Exceptions
std::runtime_exceptionif init include a dummy variable or a NaN value.

◆ Environment() [4/6]

template<class T >
smats::Environment< T >::Environment ( std::initializer_list< key_type > vars)
explicit

Construct a new environment object from a list of variables.

Initializes the variables with 0.0.

Parameters
varsinitializer list of variables
Exceptions
std::runtime_exceptionif vars include a dummy variable.

◆ Environment() [5/6]

template<class T >
smats::Environment< T >::Environment ( std::span< const key_type > vars)
explicit

Construct a new environment object from a list of variables.

Initializes the variables with 0.0.

Parameters
varsinitializer list of variables
Exceptions
std::runtime_exceptionif vars include a dummy variable.

◆ Environment() [6/6]

template<class T >
smats::Environment< T >::Environment ( map m)
explicit

Construct a new environment object from the map m between variables and values.

Parameters
mmap between variables and values
Exceptions
std::runtime_exceptionif m include a dummy variable or a NaN value.

Member Function Documentation

◆ at()

template<class T >
const T & smats::Environment< T >::at ( const key_type & key) const
nodiscard

Get a reference to the value that is mapped to a key equivalent to key.

Parameters
keykey of the element to find
Returns
reference to the mapped value of the requested key
Exceptions
std::out_of_rangeif the key does not exist

◆ begin() [1/2]

template<class T >
iterator smats::Environment< T >::begin ( )
inline

Get read-only access to the iterator to the beginning of the environment.

Returns
iterator to the beginning of the environment

◆ begin() [2/2]

template<class T >
const_iterator smats::Environment< T >::begin ( ) const
inlinenodiscard

Get read-only access to the const iterator to the beginning of the environment.

Returns
const iterator to the beginning of the environment

◆ cbegin()

template<class T >
const_iterator smats::Environment< T >::cbegin ( ) const
inlinenodiscard

Get read-only access to the const iterator to the beginning of the environment.

Returns
const iterator to the beginning of the environment

◆ cend()

template<class T >
const_iterator smats::Environment< T >::cend ( ) const
inlinenodiscard

Get read-only access to the const iterator to the end of the environment.

Returns
const iterator to the end of the environment

◆ contains()

template<class T >
bool smats::Environment< T >::contains ( const key_type & key) const
inlinenodiscard

Check if the environment contains the key.

Parameters
keykey to check
Returns
true if the environment contains key
false if the environment doesn't contain key

◆ domain()

template<class T >
Variables smats::Environment< T >::domain ( ) const
nodiscard

Get read-only access to the domain of the environment.

Returns
domain of the environment

◆ empty()

template<class T >
bool smats::Environment< T >::empty ( ) const
inlinenodiscard

Check whether the environment is empty.

Returns
true if the environment is empty
false if the environment is not empty

◆ end() [1/2]

template<class T >
iterator smats::Environment< T >::end ( )
inline

Get read-only access to the iterator to the end of the environment.

Returns
iterator to the end of the environment

◆ end() [2/2]

template<class T >
const_iterator smats::Environment< T >::end ( ) const
inlinenodiscard

Get read-only access to the const iterator to the end of the environment.

Returns
const iterator to the end of the environment

◆ find() [1/2]

template<class T >
iterator smats::Environment< T >::find ( const key_type & key)
inline

Finds element with specific key.

Parameters
keykey to find
Returns
iterator to the element with key equivalent to key.

◆ find() [2/2]

template<class T >
const_iterator smats::Environment< T >::find ( const key_type & key) const
inlinenodiscard

Finds element with specific key.

Parameters
keykey to find
Returns
const_iterator to the element with key equivalent to key.

◆ insert()

template<class T >
void smats::Environment< T >::insert ( const key_type & key,
const T & elem )

Insert 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.

Parameters
keykey to insert
elemvalue to insert

◆ insert_or_assign()

template<class T >
void smats::Environment< T >::insert_or_assign ( const key_type & key,
const T & elem )

Insert a pair (key, elem) or assign elem to the existing key if it exists.

Parameters
keykey to insert
elemvalue to insert

◆ operator[]() [1/2]

template<class T >
T & smats::Environment< T >::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.

Parameters
keykey of the element to find or insert

◆ operator[]() [2/2]

template<class T >
const T & smats::Environment< T >::operator[] ( const key_type & key) const

Returns a constant reference to the value that is mapped to a key equivalent to key.

Parameters
keykey of the element to find
Returns
reference to the mapped value of the requested key
Exceptions
std::out_of_rangeif the key does not exist

◆ size()

template<class T >
std::size_t smats::Environment< T >::size ( ) const
inlinenodiscard

Get read-only access to the number of elements of the environment.

Returns
number of elements of the environment

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