dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
symbolic_variables.h
1#pragma once
2
3#include <cstddef>
4#include <functional>
5#include <initializer_list>
6#include <ostream>
7#include <set>
8#include <string>
9
10#include "dlinear/symbolic/symbolic_variable.h"
11
12namespace dlinear::drake {
13namespace symbolic {
14
24class Variables {
25 public:
26 Variables(const Variables &) = default;
27 Variables &operator=(const Variables &) = default;
28 Variables(Variables &&) = default;
29 Variables &operator=(Variables &&) = default;
30
31 typedef typename std::set<Variable>::size_type size_type;
32 typedef typename std::set<Variable>::iterator iterator;
33 typedef typename std::set<Variable>::const_iterator const_iterator;
34 typedef typename std::set<Variable>::reverse_iterator reverse_iterator;
35 typedef typename std::set<Variable>::const_reverse_iterator
36 const_reverse_iterator;
37
39 Variables() = default;
40
42 ~Variables() = default;
43
45 Variables(std::initializer_list<Variable> init);
46
48 size_t get_hash() const;
49
51 size_type size() const { return vars_.size(); }
52
54 bool empty() const { return vars_.empty(); }
55
57 std::string to_string() const;
58
60 iterator begin() { return vars_.begin(); }
62 iterator end() { return vars_.end(); }
64 const_iterator begin() const { return vars_.cbegin(); }
66 const_iterator end() const { return vars_.cend(); }
68 const_iterator cbegin() const { return vars_.cbegin(); }
70 const_iterator cend() const { return vars_.cend(); }
72 reverse_iterator rbegin() { return vars_.rbegin(); }
74 reverse_iterator rend() { return vars_.rend(); }
76 const_reverse_iterator rbegin() const { return vars_.crbegin(); }
78 const_reverse_iterator rend() const { return vars_.crend(); }
80 const_reverse_iterator crbegin() const { return vars_.crbegin(); }
82 const_reverse_iterator crend() const { return vars_.crend(); }
83
85 void insert(const Variable &var) { vars_.insert(var); }
87 template<class InputIt>
88 void insert(InputIt first, InputIt last) {
89 vars_.insert(first, last);
90 }
92 void insert(const Variables &vars) { vars_.insert(vars.begin(), vars.end()); }
93
95 size_type erase(const Variable &key) { return vars_.erase(key); }
96
99 size_type erase(const Variables &vars);
100
102 iterator find(const Variable &key) { return vars_.find(key); }
103 const_iterator find(const Variable &key) const { return vars_.find(key); }
104
106 bool include(const Variable &key) const { return find(key) != end(); }
107
109 bool IsSubsetOf(const Variables &vars) const;
111 bool IsSupersetOf(const Variables &vars) const;
113 bool IsStrictSubsetOf(const Variables &vars) const;
115 bool IsStrictSupersetOf(const Variables &vars) const;
116
117 friend bool operator==(const Variables &vars1, const Variables &vars2);
118
119 friend bool operator<(const Variables &vars1, const Variables &vars2);
120
121 friend std::ostream &operator<<(std::ostream &, const Variables &vars);
122
123 friend Variables intersect(const Variables &vars1, const Variables &vars2);
124
125 private:
126 /* Constructs from std::set<Variable>. */
127 explicit Variables(std::set<Variable> vars);
128
129 std::set<Variable> vars_;
130};
131
133// NOLINTNEXTLINE(runtime/references) per C++ standard signature.
134Variables operator+=(Variables &vars1, const Variables &vars2);
136// NOLINTNEXTLINE(runtime/references) per C++ standard signature.
137Variables operator+=(Variables &vars, const Variable &var);
139Variables operator+(Variables vars1, const Variables &vars2);
141Variables operator+(Variables vars, const Variable &var);
143Variables operator+(const Variable &var, Variables vars);
144
146// NOLINTNEXTLINE(runtime/references) per C++ standard signature.
147Variables operator-=(Variables &vars1, const Variables &vars2);
149// NOLINTNEXTLINE(runtime/references) per C++ standard signature.
150Variables operator-=(Variables &vars, const Variable &var);
152Variables operator-(Variables vars1, const Variables &vars2);
154Variables operator-(Variables vars, const Variable &var);
155
161Variables intersect(const Variables &vars1, const Variables &vars2);
162
163} // namespace symbolic
164
166template<>
167struct hash_value<symbolic::Variables> {
168 size_t operator()(const symbolic::Variables &vars) const {
169 return vars.get_hash();
170 }
171};
172
173} // namespace dlinear::drake
174
Represents a symbolic variable.
Represents a set of variables.
void insert(const Variables &vars)
Inserts variables in vars into a set.
void insert(const Variable &var)
Inserts a variable var into a set.
const_reverse_iterator crbegin() const
Returns a const reverse-iterator to the beginning.
size_type size() const
Returns the number of elements.
size_type erase(const Variables &vars)
Erases variables in vars from a set.
const_iterator begin() const
Returns an iterator to the beginning.
const_reverse_iterator rend() const
Returns a reverse iterator to the end.
bool IsStrictSupersetOf(const Variables &vars) const
Return true if vars is a strict superset of the Variables.
bool IsSubsetOf(const Variables &vars) const
Return true if vars is a subset of the Variables.
void insert(InputIt first, InputIt last)
Inserts variables in [first, last) into a set.
Variables()=default
Default constructor.
const_iterator end() const
Returns an iterator to the end.
const_reverse_iterator rbegin() const
Returns a reverse iterator to the beginning.
bool IsStrictSubsetOf(const Variables &vars) const
Return true if vars is a strict subset of the Variables.
const_iterator cend() const
Returns a const iterator to the end.
reverse_iterator rend()
Returns a reverse iterator to the end.
iterator begin()
Returns an iterator to the beginning.
Variables(std::initializer_list< Variable > init)
List constructor.
size_type erase(const Variable &key)
Erases key from a set.
bool empty() const
Checks if this set is empty or not.
std::string to_string() const
Returns string representation of Variables.
iterator end()
Returns an iterator to the end.
iterator find(const Variable &key)
Finds element with specific key.
const_reverse_iterator crend() const
Returns a const reverse-iterator to the end.
reverse_iterator rbegin()
Returns a reverse iterator to the beginning.
~Variables()=default
Default destructor.
const_iterator cbegin() const
Returns a const iterator to the beginning.
friend Variables intersect(const Variables &vars1, const Variables &vars2)
Returns the intersection of vars1 and vars2.
size_t get_hash() const
Returns hash value.
bool include(const Variable &key) const
Return true if key is included in the Variables.
bool IsSupersetOf(const Variables &vars) const
Return true if vars is a superset of the Variables.
LpColBound operator-(LpColBound bound)
Invert the bound with delta > 0.
Computes the hash value of v using std::hash.
Definition hash.h:33