dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
symbolic_environment.h
1#pragma once
2
3#include <initializer_list>
4#include <ostream>
5#include <string>
6#include <unordered_map>
7
8#include "dlinear/libs/libgmp.h"
9#include "dlinear/symbolic/symbolic_variable.h"
10#include "dlinear/symbolic/symbolic_variables.h"
11
12namespace dlinear::drake::symbolic {
52 public:
53 Environment(const Environment &) = default;
54 Environment &operator=(const Environment &) = default;
55 Environment(Environment &&) = default;
56 Environment &operator=(Environment &&) = default;
57
58 typedef Variable key_type;
59 typedef mpq_class mapped_type;
60 typedef typename std::unordered_map<key_type, mapped_type> map;
61 typedef typename std::unordered_map<key_type, double> double_map;
63 typedef typename map::value_type value_type;
64 typedef typename map::iterator iterator;
65 typedef typename map::const_iterator const_iterator;
66
68 Environment() = default;
69
71 ~Environment() = default;
72
75 Environment(std::initializer_list<value_type> init);
76
79 Environment(std::initializer_list<key_type> vars);
80
82 explicit Environment(map m);
83 explicit Environment(const double_map &m);
84
86 iterator begin() { return map_.begin(); }
88 iterator end() { return map_.end(); }
90 const_iterator begin() const { return map_.cbegin(); }
92 const_iterator end() const { return map_.cend(); }
94 const_iterator cbegin() const { return map_.cbegin(); }
96 const_iterator cend() const { return map_.cend(); }
97
99 std::pair<Environment::iterator, bool> insert(const key_type &key, const mapped_type &elem);
101 bool empty() const { return map_.empty(); }
103 size_t size() const { return map_.size(); }
104
106 iterator find(const key_type &key) { return map_.find(key); }
108 const_iterator find(const key_type &key) const { return map_.find(key); }
109
111 const mapped_type &at(const key_type &key) const;
112
114 std::size_t erase(const key_type &key);
116 void erase(const iterator &pos);
117
120
122 std::string to_string() const;
123
127 mapped_type &operator[](const key_type &key);
128
131 const mapped_type &operator[](const key_type &key) const;
132
134 bool contains(const key_type &key) const;
135
136 friend std::ostream &operator<<(std::ostream &os, const Environment &env);
137
138 private:
139 map map_;
140};
141} // namespace dlinear::drake::symbolic
Represents a symbolic environment (mapping from a variable to a value).
std::string to_string() const
Returns string representation.
const mapped_type & at(const key_type &key) const
Returns the value that is mapped to a key equivalent to key.
iterator find(const key_type &key)
Finds element with specific key.
Variables domain() const
Returns the domain of this environment.
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 i...
const_iterator find(const key_type &key) const
Finds element with specific key.
const_iterator begin() const
Returns a const iterator to the beginning.
Environment(std::initializer_list< value_type > init)
List constructor.
const_iterator end() const
Returns a const iterator to the end.
const_iterator cbegin() const
Returns a const iterator to the beginning.
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)...
iterator end()
Returns an iterator to the end.
std::pair< Environment::iterator, bool > insert(const key_type &key, const mapped_type &elem)
Inserts a pair (key, elem).
const_iterator cend() const
Returns a const iterator to the end.
map::value_type value_type
std::pair<key_type, mapped_type>
Environment()=default
Default constructor.
~Environment()=default
Default destructor.
bool contains(const key_type &key) const
Checks whether the environment contains a variable key.
Environment(map m)
Constructs an environment from m.
size_t size() const
Returns the number of elements.
void erase(const iterator &pos)
Erases the element at the specified pos.
Environment(std::initializer_list< key_type > vars)
List constructor.
iterator begin()
Returns an iterator to the beginning.
bool empty() const
Checks whether the container is empty.
std::size_t erase(const key_type &key)
Erases the element with specific key.
Represents a symbolic variable.
Represents a set of variables.