dReal4
contractor_cell.h
1 #pragma once
2 
3 #include <iostream>
4 #include <memory>
5 #include <vector>
6 
7 #include "./ibex.h"
8 
9 #include "dreal/contractor/contractor.h"
10 #include "dreal/contractor/contractor_status.h"
11 #include "dreal/solver/config.h"
12 
13 namespace dreal {
14 
15 // Forward declarations.
16 class ContractorCell;
17 class ContractorId;
18 class ContractorInteger;
19 class ContractorSeq;
20 class ContractorIbexFwdbwd;
21 class ContractorIbexPolytope;
22 class ContractorFixpoint;
23 class ContractorWorklistFixpoint;
24 class ContractorJoin;
25 template <typename ContextType>
26 class ContractorForall;
27 
28 /// Abstract base class of contractors.
30  public:
31  /// Constructs a cell with @p kind and @p input.
32  ContractorCell(Contractor::Kind kind, DynamicBitset input, Config config);
33 
34  /// Deleted default constructor.
35  ContractorCell() = delete;
36 
37  /// Deleted copy constructor.
38  ContractorCell(const ContractorCell&) = delete;
39 
40  /// Deleted move constructor.
41  ContractorCell(ContractorCell&&) = delete;
42 
43  /// Deleted copy assign operator.
44  void operator=(const ContractorCell&) = delete;
45 
46  /// Deleted move assign operator.
47  void operator=(ContractorCell&&) = delete;
48 
49  /// Default destructor.
50  virtual ~ContractorCell() = default;
51 
52  /// Returns its kind.
53  Contractor::Kind kind() const;
54 
55  /// Returns its input.
56  const DynamicBitset& input() const;
57 
58  /// Returns its input.
59  DynamicBitset& mutable_input();
60 
61  /// Returns config.
62  const Config& config() const;
63 
64  /// Returns true if this contractor includes a forall contractor.
65  bool include_forall() const;
66 
67  /// Sets include_forall true.
68  void set_include_forall();
69 
70  /// Performs pruning on @p cs.
71  virtual void Prune(ContractorStatus* cs) const = 0;
72 
73  /// Outputs this contractor to @p os.
74  virtual std::ostream& display(std::ostream& os) const = 0;
75 
76  private:
77  const Contractor::Kind kind_;
78  DynamicBitset input_;
79  const Config config_;
80  bool include_forall_{false};
81 };
82 
83 // Returns max(c₁.input().size(), ..., cₙ.input().size()).
84 // This is used in ContractorSeq, ContractorFixpoint, and
85 // ContractorWorklistFixpoint to find the size of its input DynamicBitset.
86 DynamicBitset::size_type ComputeInputSize(
87  const std::vector<Contractor>& contractors);
88 
89 std::ostream& operator<<(std::ostream& os, const ContractorCell& c);
90 
91 /// Converts @p contractor to ContractorId.
92 std::shared_ptr<ContractorId> to_id(const Contractor& contractor);
93 
94 /// Converts @p contractor to ContractorInteger.
95 std::shared_ptr<ContractorInteger> to_integer(const Contractor& contractor);
96 
97 /// Converts @p contractor to ContractorSeq.
98 std::shared_ptr<ContractorSeq> to_seq(const Contractor& contractor);
99 
100 /// Converts @p contractor to ContractorIbexFwdbwd.
101 std::shared_ptr<ContractorIbexFwdbwd> to_ibex_fwdbwd(
102  const Contractor& contractor);
103 
104 /// Converts @p contractor to ContractorIbexPolytop.
105 std::shared_ptr<ContractorIbexPolytope> to_ibex_polytope(
106  const Contractor& contractor);
107 
108 /// Converts @p contractor to ContractorFixpoint.
109 std::shared_ptr<ContractorFixpoint> to_fixpoint(const Contractor& contractor);
110 
111 /// Converts @p contractor to ContractorWorklistFixpoint.
112 std::shared_ptr<ContractorWorklistFixpoint> to_worklist_fixpoint(
113  const Contractor& contractor);
114 
115 /// Converts @p contractor to ContractorJoin.
116 std::shared_ptr<ContractorJoin> to_join(const Contractor& contractor);
117 
118 /// Converts @p contractor to ContractorForall.
119 template <typename ContextType>
120 std::shared_ptr<ContractorForall<ContextType>> to_forall(
121  const Contractor& contractor);
122 
123 } // namespace dreal
virtual std::ostream & display(std::ostream &os) const =0
Outputs this contractor to os.
const Config & config() const
Returns config.
Definition: contractor_cell.cc:33
Abstract base class of contractors.
Definition: contractor_cell.h:29
shared_ptr< ContractorId > to_id(const Contractor &contractor)
Converts contractor to ContractorId.
Definition: contractor_cell.cc:55
shared_ptr< ContractorInteger > to_integer(const Contractor &contractor)
Converts contractor to ContractorInteger.
Definition: contractor_cell.cc:59
shared_ptr< ContractorIbexFwdbwd > to_ibex_fwdbwd(const Contractor &contractor)
Converts contractor to ContractorIbexFwdbwd.
Definition: contractor_cell.cc:67
Sum type of symbolic::Expression and symbolic::Formula.
Definition: api.cc:9
void operator=(const ContractorCell &)=delete
Deleted copy assign operator.
shared_ptr< ContractorJoin > to_join(const Contractor &contractor)
Converts contractor to ContractorJoin.
Definition: contractor_cell.cc:85
virtual ~ContractorCell()=default
Default destructor.
std::shared_ptr< ContractorForall< ContextType > > to_forall(const Contractor &contractor)
Converts contractor to ContractorForall.
Definition: contractor_forall.h:331
ContractorCell()=delete
Deleted default constructor.
const DynamicBitset & input() const
Returns its input.
Definition: contractor_cell.cc:29
bool include_forall() const
Returns true if this contractor includes a forall contractor.
Definition: contractor_cell.cc:35
Contractor::Kind kind() const
Returns its kind.
Definition: contractor_cell.cc:27
void set_include_forall()
Sets include_forall true.
Definition: contractor_cell.cc:37
shared_ptr< ContractorSeq > to_seq(const Contractor &contractor)
Converts contractor to ContractorSeq.
Definition: contractor_cell.cc:63
shared_ptr< ContractorFixpoint > to_fixpoint(const Contractor &contractor)
Converts contractor to ContractorFixpoint.
Definition: contractor_cell.cc:76
Definition: config.h:12
shared_ptr< ContractorIbexPolytope > to_ibex_polytope(const Contractor &contractor)
Converts contractor to ContractorIbexPolytop.
Definition: contractor_cell.cc:71
virtual void Prune(ContractorStatus *cs) const =0
Performs pruning on cs.
shared_ptr< ContractorWorklistFixpoint > to_worklist_fixpoint(const Contractor &contractor)
Converts contractor to ContractorWorklistFixpoint.
Definition: contractor_cell.cc:80
Contractor status.
Definition: contractor_status.h:13
Definition: contractor.h:30
DynamicBitset & mutable_input()
Returns its input.
Definition: contractor_cell.cc:31