dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
BoundPreprocessor.h
1
11#pragma once
12
13#include <iosfwd>
14#include <list>
15#include <map>
16#include <set>
17#include <span>
18#include <tuple>
19#include <unordered_map>
20#include <utility>
21#include <vector>
22
23#include "dlinear/libs/libgmp.h"
24#include "dlinear/solver/BoundVector.h"
25#include "dlinear/symbolic/PredicateAbstractor.h"
26#include "dlinear/symbolic/environment.h"
27#include "dlinear/symbolic/literal.h"
28#include "dlinear/symbolic/symbolic.h"
29#include "dlinear/util/Config.h"
30
31namespace dlinear {
32
38 public:
39 using Explanations = std::set<LiteralSet>;
40 using VarToEqBinomialMap = std::unordered_map<Variable, mpq_class>;
41
47
54 void AddVariable(const Variable& var);
55
66 std::set<LiteralSet> EnableLiterals(const std::vector<Literal>& enabled_literals);
76 void EnableLiterals(const std::vector<Literal>& enabled_literals, std::set<LiteralSet>& explanation);
77
88 std::set<LiteralSet> EnableLiteral(const Literal& lit);
98 void EnableLiteral(const Literal& lit, std::set<LiteralSet>& explanations);
99
109 Explanations Process();
118 void Process(Explanations& explanations);
129 Explanations Process(const LiteralSet& enabled_literals);
139 void Process(const LiteralSet& enabled_literals, Explanations& explanations);
140
148 void GetActiveExplanation(const Variable& var, LiteralSet& explanation);
149
158 void SetInfinityBounds(const Variable& var, const mpq_class& lb, const mpq_class& ub);
159
165 void Clear();
173 void Clear(const BoundPreprocessor& fixed_preprocessor);
174
176 [[nodiscard]] const Config& config() const { return config_; }
178 [[nodiscard]] const BoundVectorMap& theory_bounds() const { return theory_bounds_; }
180 [[nodiscard]] const PredicateAbstractor& predicate_abstractor() const { return predicate_abstractor_; }
182 [[nodiscard]] const Environment& env() const { return env_; }
184 [[nodiscard]] const IterationStats& stats() const { return stats_; }
185
203 static bool IsSimpleBound(const Formula& formula);
212 static bool IsEqualTo(const Formula& formula, bool truth = true);
221 static bool IsNotEqualTo(const Formula& formula, bool truth = true);
230 static bool IsGreaterThan(const Formula& formula, bool truth = true);
239 static bool IsLessThan(const Formula& formula, bool truth = true);
248 static bool IsGreaterThanOrEqualTo(const Formula& formula, bool truth = true);
257 static bool IsLessThanOrEqualTo(const Formula& formula, bool truth = true);
258
276 bool PropagateEqPolynomial(const Literal& lit, const Variable& var_to_propagate, Explanations& explanations);
294 bool PropagateBoundsPolynomial(const Literal& lit, const Variable& var_to_propagate, Explanations& explanations);
295
296 bool PropagateBoundsPolynomial(const Literal& lit, const Variable& var_to_propagate,
297 const std::vector<Bound>& assumptions, Explanations& explanations);
298
299 protected:
300 const Variable* ShouldPropagateEqPolynomial(const Literal& lit) const;
301 const Variable* ShouldPropagateEqPolynomial(const Formula& formula) const;
302 const Variable* ShouldPropagateBoundsPolynomial(const Literal& lit) const;
303 const Variable* ShouldPropagateBoundsPolynomial(const Formula& formula) const;
304 bool ShouldEvaluate(const Literal& lit) const;
305 bool ShouldEvaluate(const Formula& formula) const;
306
307 Bound GetSimpleBound(const dlinear::Literal& lit) const;
308 Bound GetSimpleBound(const Literal& lit, const Formula& formula) const;
309
310 void PropagateConstraints(std::list<Literal>& enabled_literals, Explanations& explanations);
311 void PropagateEqConstraints(std::list<Literal>& enabled_literals, Explanations& explanations);
312 void PropagateBoundConstraints(std::list<Literal>& enabled_literals, Explanations& explanations);
313 void EvaluateFormulas(std::list<Literal>& enabled_literals, Explanations& explanations);
314 void FormulaViolationExplanation(const Literal& lit, const Formula& formula, Explanations& explanations);
315
316 std::pair<Variable, Variable> ExtractBoundEdge(const Formula& formula) const;
326 mpq_class ExtractEqBoundCoefficient(const Formula& formula) const;
327
328 void GetExplanation(const Variable& var, LiteralSet& explanation);
329
331 const mpq_class* StoreTemporaryMpq(const mpq_class& value);
332
333#if DEBUGGING_PREPROCESSOR
334 std::vector<Variable> GetExplanationOrigins(const Variable& var);
335#endif
336
337 private:
338 std::list<mpq_class>
340
344
345 LiteralSet enabled_literals_;
346
347 BoundVectorMap theory_bounds_;
349
351};
352
353std::ostream& operator<<(std::ostream& os, const BoundPreprocessor& preprocessor);
354
355} // namespace dlinear
356
357#ifdef DLINEAR_INCLUDE_FMT
358
359#include "dlinear/util/logging.h"
360
361OSTREAM_FORMATTER(dlinear::BoundPreprocessor)
362
363#endif
This class uses some basic algebraic operations to preprocess the constraints and identify violations...
static bool IsSimpleBound(const Formula &formula)
Check whether the formula is a simple relational bound.
static bool IsGreaterThan(const Formula &formula, bool truth=true)
Check whether the formula is a simple relational bound with a greater than operator ( ).
std::list< mpq_class > temporary_mpq_vector_
Vector used to store temporary mpq values obtained from more complex constraints.
bool PropagateEqPolynomial(const Literal &lit, const Variable &var_to_propagate, Explanations &explanations)
Propagate the bounds of the variables in the given formula.
const BoundVectorMap & theory_bounds() const
Get read-only access to the bounds of the variables in the LP solver of the BoundPreprocessor.
const mpq_class * StoreTemporaryMpq(const mpq_class &value)
Vector used to store the mpq_class elements obtained from more complex constraints.
static bool IsLessThan(const Formula &formula, bool truth=true)
Check whether the formula is a simple relational bound with a less than operator ( ).
const Config & config() const
Get read-only access to the configuration of the BoundPreprocessor.
const Environment & env() const
Get read-only access to the propagated environment containing the variable's values of the BoundPrepr...
static bool IsLessThanOrEqualTo(const Formula &formula, bool truth=true)
Check whether the formula is a simple relational bound with a less than or equal to operator ( ).
BoundPreprocessor(const PredicateAbstractor &predicate_abstractor)
Construct a new Bound Preprocessor object using the predicate_abstractor.
static bool IsNotEqualTo(const Formula &formula, bool truth=true)
Check whether the formula is a simple relational bound with a non-equality operator ( ).
std::set< LiteralSet > EnableLiteral(const Literal &lit)
Enable the literal lit.
std::set< LiteralSet > EnableLiterals(const std::vector< Literal > &enabled_literals)
Preprocess all the enabled_literals.
void SetInfinityBounds(const Variable &var, const mpq_class &lb, const mpq_class &ub)
Set the lower and upper infinity bounds (lb, ub) of the variable var.
IterationStats stats_
Statistics of the preprocessing.
mpq_class ExtractEqBoundCoefficient(const Formula &formula) const
Given a formula of the form , with being constants, extract the coefficient .
const Config & config_
Configuration of the preprocessor.
bool PropagateBoundsPolynomial(const Literal &lit, const Variable &var_to_propagate, Explanations &explanations)
Propagate the bounds of the variables in the given formula.
const PredicateAbstractor & predicate_abstractor() const
Get read-only access to the predicate abstractor of the BoundPreprocessor.
void Clear()
Clear the preprocessor.
void GetActiveExplanation(const Variable &var, LiteralSet &explanation)
Get the active explanation for the variable var.
Explanations Process()
Process all enabled literals.
const IterationStats & stats() const
Get read-only access to the statistics of the BoundPreprocessor.
BoundVectorMap theory_bounds_
Theory bounds for each theory variable.
static bool IsGreaterThanOrEqualTo(const Formula &formula, bool truth=true)
Check whether the formula is a simple relational bound with a less than or equal to operator ( ).
static bool IsEqualTo(const Formula &formula, bool truth=true)
Check whether the formula is a simple relational bound with an equality operator ( ).
const PredicateAbstractor & predicate_abstractor_
Predicate abstractor used to get the constraints from the literals.
Environment env_
Environment storing the values of all the variables with a fixed value.
void AddVariable(const Variable &var)
Add a theory variable to the preprocessor.
Simple dataclass used to store the configuration of the program.
Definition Config.h:38
Dataclass collecting statistics about some operation or process.
Definition Stats.h:71
Predicate abstraction is a method to convert a first-order logic formula into a Boolean formula.
Represents a symbolic environment (mapping from a variable to a value).
Represents a symbolic form of a first-order logic formula.
Represents a symbolic variable.
Global namespace for the dlinear library.
std::set< Literal > LiteralSet
A set of literals.
Definition literal.h:28
Tuple containing the value, bound type and theory literal associated with the bound.
Definition Bound.h:24
A literal is a variable with an associated truth value, indicating whether it is true or false.
Definition literal.h:24