dReal4
icp.h
1 #pragma once
2 
3 #include <vector>
4 
5 #include "dreal/contractor/contractor.h"
6 #include "dreal/contractor/contractor_status.h"
7 #include "dreal/solver/config.h"
8 #include "dreal/solver/formula_evaluator.h"
9 #include "dreal/util/box.h"
10 #include "dreal/util/dynamic_bitset.h"
11 #include "dreal/util/optional.h"
12 
13 namespace dreal {
14 
15 /// Abstract Class for ICP (Interval Constraint Propagation) algorithm.
16 class Icp {
17  public:
18  /// Constructs an Icp based on @p config.
19  explicit Icp(const Config& config);
20  Icp(const Icp&) = default;
21  Icp(Icp&&) = default;
22  Icp& operator=(const Icp&) = delete;
23  Icp& operator=(Icp&&) = delete;
24 
25  virtual ~Icp() = default;
26 
27  /// Checks the delta-satisfiability of the current assertions.
28  /// @param[in] contractor Contractor to use in pruning phase
29  /// @param[in] formula_evaluators A vector of FormulaEvaluator which
30  /// determines when to stop and which
31  /// dimension to branch.
32  /// @param[in,out] cs A contractor to be updated.
33  /// Returns true if it's delta-SAT.
34  /// Returns false if it's UNSAT.
35  virtual bool CheckSat(const Contractor& contractor,
36  const std::vector<FormulaEvaluator>& formula_evaluators,
37  ContractorStatus* cs) = 0;
38 
39  protected:
40  const Config& config() const { return config_; }
41 
42  private:
43  const Config& config_;
44 };
45 
46 /// Evaluates each formula with @p box using interval
47 /// arithmetic. There are three possible outcomes:
48 ///
49 /// Returns None if there is fᵢ such that fᵢ(box) is empty.
50 /// (This indicates the problem is UNSAT)
51 ///
52 /// Returns Some(∅) if for all fᵢ, we have either
53 /// 1) fᵢ(x) is valid for all x ∈ B *or*
54 /// 2) |fᵢ(B)| ≤ δ.
55 /// (This indicates the problem is delta-SAT)
56 ///
57 /// Returns Some(Vars) if there is fᵢ such that
58 /// 1) Interval arithmetic can't validate that
59 /// fᵢ(x) is valid for all x ∈ B *and*
60 /// 2) |fᵢ(B)| > δ.
61 /// Vars = {v | v ∈ fᵢ ∧ |fᵢ(B)| > δ for all
62 /// fᵢs}.
63 ///
64 /// It cannot conclude if the constraint
65 /// is satisfied or not completely. It
66 /// checks the width/diameter of the
67 /// interval evaluation and adds the free
68 /// variables in the constraint into the
69 /// set that it will return.
70 ///
71 /// If it returns an DynamicBitset, it represents the dimensions on
72 /// which the ICP algorithm needs to consider branching.
73 ///
74 /// It sets @p cs's box empty if it detects UNSAT. It also calls
75 /// cs->AddUsedConstraint to store the constraint that is responsible
76 /// for the UNSAT.
77 optional<DynamicBitset> EvaluateBox(
78  const std::vector<FormulaEvaluator>& formula_evaluators, const Box& box,
79  double precision, ContractorStatus* cs);
80 
81 } // namespace dreal
virtual bool CheckSat(const Contractor &contractor, const std::vector< FormulaEvaluator > &formula_evaluators, ContractorStatus *cs)=0
Checks the delta-satisfiability of the current assertions.
Sum type of symbolic::Expression and symbolic::Formula.
Definition: api.cc:9
optional< DynamicBitset > EvaluateBox(const vector< FormulaEvaluator > &formula_evaluators, const Box &box, const double precision, ContractorStatus *const cs)
Evaluates each formula with box using interval arithmetic.
Definition: icp.cc:15
Abstract Class for ICP (Interval Constraint Propagation) algorithm.
Definition: icp.h:16
Icp(const Config &config)
Constructs an Icp based on config.
Definition: icp.cc:13
Represents a n-dimensional interval vector.
Definition: box.h:17
Definition: config.h:12
Contractor status.
Definition: contractor_status.h:13
Definition: contractor.h:30