dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
Box.h
1
8#pragma once
9
10#include <iosfwd>
11#include <memory>
12#include <string>
13#include <unordered_map>
14#include <utility>
15#include <vector>
16
17#include "dlinear/libs/libgmp.h"
18#include "dlinear/symbolic/literal.h"
19#include "dlinear/symbolic/symbolic.h" // IWYU pragma: keep for hash_value
20#include "dlinear/util/Config.h"
21#include "dlinear/util/Interval.h"
22
23namespace dlinear {
24
31class Box {
32 public:
38
44 explicit Box(const std::vector<Variable> &variables, Config::LPSolver lp_solver);
45
50 void Add(const Variable &v);
51
58 void Add(const Variable &v, const mpq_class &lb, const mpq_class &ub);
59
64 [[nodiscard]] bool empty() const;
65
70 void set_empty();
71
73 [[nodiscard]] int size() const;
74
80 Interval &operator[](int i);
81
87 Interval &operator[](const Variable &var);
88
94 const Interval &operator[](int i) const;
95
101 const Interval &operator[](const Variable &var) const;
102
104 [[nodiscard]] Config::LPSolver lp_solver() const { return lp_solver_; }
106 [[nodiscard]] const std::vector<Variable> &variables() const;
107
113 [[nodiscard]] const Variable &variable(int i) const;
114
121 [[nodiscard]] bool has_variable(const Variable &var) const;
122
127 [[nodiscard]] const std::vector<Interval> &interval_vector() const;
128
133 std::vector<Interval> &m_interval_vector();
134
140 [[nodiscard]] int index(const Variable &var) const;
141
146 [[nodiscard]] std::pair<mpq_class, int> MaxDiam() const;
147
154 [[nodiscard]] std::pair<Box, Box> Bisect(int i) const;
155
162 [[nodiscard]] std::pair<Box, Box> Bisect(const Variable &var) const;
163
164 private:
172 [[nodiscard]] std::pair<Box, Box> BisectInt(int i) const;
173
181 [[nodiscard]] std::pair<Box, Box> BisectContinuous(int i) const;
182
184 std::vector<Interval> values_;
185 std::shared_ptr<std::vector<Variable>> variables_;
186 std::shared_ptr<std::unordered_map<Variable, int>> var_to_idx_;
187 std::shared_ptr<std::unordered_map<int, Variable>> idx_to_var_;
188
189 friend std::ostream &operator<<(std::ostream &os, const Box &box);
190};
191
192std::ostream &operator<<(std::ostream &os, const Box &box);
193
194bool operator==(const Box &b1, const Box &b2);
195
196bool operator!=(const Box &b1, const Box &b2);
197
198std::ostream &DisplayDiff(std::ostream &os, const std::vector<Variable> &variables, const std::vector<Interval> &old_iv,
199 const std::vector<Interval> &new_iv);
200
201} // namespace dlinear
202
203#ifdef DLINEAR_INCLUDE_FMT
204
205#include "dlinear/util/logging.h"
206
207OSTREAM_FORMATTER(dlinear::Box)
208
209#endif
Collection of variables with associated intervals.
Definition Box.h:31
std::vector< Interval > values_
Interval vector of the box.
Definition Box.h:184
std::pair< mpq_class, int > MaxDiam() const
Return the max diameter of the box and the associated index.
Definition Box.cpp:124
std::shared_ptr< std::unordered_map< Variable, int > > var_to_idx_
Variable to index map.
Definition Box.h:186
std::vector< Interval > & m_interval_vector()
Return the interval vector of the box.
Definition Box.cpp:122
std::shared_ptr< std::vector< Variable > > variables_
Variables in the box.
Definition Box.h:185
void Add(const Variable &v)
Add the variable v to the box.
Definition Box.cpp:39
std::shared_ptr< std::unordered_map< int, Variable > > idx_to_var_
Index to variable map.
Definition Box.h:187
Interval & operator[](int i)
Return the interval at index i.
Definition Box.cpp:102
Config::LPSolver lp_solver_
LP solver.
Definition Box.h:183
std::pair< Box, Box > Bisect(int i) const
Bisect the box at i -th dimension.
Definition Box.cpp:137
int index(const Variable &var) const
Return the index associated with var.
Definition Box.cpp:119
std::pair< Box, Box > BisectInt(int i) const
Bisects the box at i -th dimension.
Definition Box.cpp:164
const std::vector< Variable > & variables() const
Get read-only access to the variables of the box.
Definition Box.cpp:113
Box(Config::LPSolver lp_solver)
Construct a new Box object associated with the given lp_solver.
Definition Box.cpp:26
const std::vector< Interval > & interval_vector() const
Return the interval vector of the box.
Definition Box.cpp:121
Config::LPSolver lp_solver() const
Get read-only access to the lp_solver of the box.
Definition Box.h:104
bool empty() const
Check whether the box is empty.
Definition Box.cpp:94
std::pair< Box, Box > BisectContinuous(int i) const
Bisects the box at i -th dimension.
Definition Box.cpp:185
int size() const
Get read-only access to the number of variables of the box.
Definition Box.cpp:100
const Variable & variable(int i) const
Return the i -th variable in the box.
Definition Box.cpp:115
void set_empty()
Clear the box, making it empty.
Definition Box.cpp:96
bool has_variable(const Variable &var) const
Checks if this box contains var.
Definition Box.cpp:117
LPSolver
Underlying LP solver used by the theory solver.
Definition Config.h:41
Represents a symbolic variable.
Global namespace for the dlinear library.