dReal4
config.h
1 #pragma once
2 
3 #include <ostream>
4 
5 #include "dreal/solver/brancher.h"
6 #include "dreal/util/box.h"
7 #include "dreal/util/dynamic_bitset.h"
8 #include "dreal/util/option_value.h"
9 
10 namespace dreal {
11 
12 class Config {
13  public:
14  Config() = default;
15  Config(const Config&) = default;
16  Config(Config&&) = default;
17  Config& operator=(const Config&) = default;
18  Config& operator=(Config&&) = default;
19  ~Config() = default;
20 
21  using Brancher = std::function<int(
22  const Box& box, const DynamicBitset& bitset, Box* left, Box* right)>;
23 
24  /// Returns the precision option.
25  double precision() const;
26 
27  /// Returns a mutable OptionValue for 'precision'.
29 
30  /// Returns the produce_models option.
31  bool produce_models() const;
32 
33  /// Returns a mutable OptionValue for 'produce_models'.
35 
36  /// Returns whether it uses polytope contractors or not.
37  bool use_polytope() const;
38 
39  /// Returns a mutable OptionValue for 'use_polytope'.
41 
42  /// Returns whether it uses polytope contractors inside forall contractors.
43  bool use_polytope_in_forall() const;
44 
45  /// Returns a mutable OptionValue for 'use_polytope_in_forall'.
47 
48  /// Returns whether it uses worklist-fixpoint algorithm.
49  bool use_worklist_fixpoint() const;
50 
51  /// Returns a mutable OptionValue for 'use_worklist_fixpoint'.
53 
54  /// Returns whether it uses local optimization algorithm in exist-forall
55  /// problems.
56  bool use_local_optimization() const;
57 
58  /// Returns a mutable OptionValue for 'use_local_optimization'.
60 
61  /// Returns the number of parallel jobs.
62  int number_of_jobs() const;
63 
64  /// Returns a mutable OptionValue for 'number_of_jobs'.
66 
67  /// Returns whether the ICP algorithm stacks the left box first
68  /// after branching.
69  bool stack_left_box_first() const;
70 
71  /// Returns a mutable OptionValue for 'stack_left_box_first'.
73 
74  /// Returns the brancher.
75  const Brancher& brancher() const;
76 
77  /// Returns a mutable OptionValue for `brancher`.
79 
80  /// @name NLopt Options
81  ///
82  /// Specifies stopping criteria of NLopt. See
83  /// https://nlopt.readthedocs.io/en/latest/NLopt_Reference/#stopping-criteria
84  /// for more information.
85  ///
86  /// @{
87 
88  /// Returns relative tolerance on function value in NLopt.
89  double nlopt_ftol_rel() const;
90 
91  /// Returns a mutable OptionValue for `nlopt_ftol_rel`.
93 
94  /// Returns absolute tolerance on function value in NLopt.
95  double nlopt_ftol_abs() const;
96 
97  /// Returns a mutable OptionValue for `nlopt_ftol_abs`.
99 
100  // Returns the number of maximum function evaluations allowed in NLopt.
101  int nlopt_maxeval() const;
102 
103  /// Returns a mutable OptionValue for `nlopt_maxeval`.
105 
106  /// Returns the maxtime in NLopt.
107  double nlopt_maxtime() const;
108 
109  /// Returns a mutable OptionValue for `nlopt_maxtime`.
111 
112  enum class SatDefaultPhase {
113  False = 0,
114  True = 1,
115  JeroslowWang = 2, // Default option
116  RandomInitialPhase = 3
117  };
118 
119  /// Returns the default phase for SAT solver.
120  SatDefaultPhase sat_default_phase() const;
121 
122  /// Returns a mutable OptionValue for `sat_default_phase`.
124 
125  /// Returns the random seed.
126  uint32_t random_seed() const;
127 
128  /// Returns a mutable OptionValue for `random_seed`.
130 
131  /// Returns if it's smtlib2_compliant mode.
132  bool smtlib2_compliant() const;
133 
134  /// Returns a mutable OptionValue for `smtlib2_compliant`.
136 
137  /// @}
138 
139  static constexpr double kDefaultPrecision{0.001};
140  static constexpr double kDefaultNloptFtolRel{1e-6};
141  static constexpr double kDefaultNloptFtolAbs{1e-6};
142  static constexpr int kDefaultNloptMaxEval{100};
143  static constexpr double kDefaultNloptMaxTime{0.01};
144 
145  private:
146  // NOTE: Make sure to match the default values specified here with the ones
147  // specified in dreal/dreal_main.cc.
148  OptionValue<double> precision_{kDefaultPrecision};
149  OptionValue<bool> produce_models_{false};
150  OptionValue<bool> use_polytope_{false};
151  OptionValue<bool> use_polytope_in_forall_{false};
152  OptionValue<bool> use_worklist_fixpoint_{false};
153  OptionValue<bool> use_local_optimization_{false};
154  OptionValue<int> number_of_jobs_{1};
155  OptionValue<bool> stack_left_box_first_{false};
156  OptionValue<bool> smtlib2_compliant_{false};
157 
158  // --------------------------------------------------------------------------
159  // NLopt options (stopping criteria)
160  // --------------------------------------------------------------------------
161  // These options are used when we use NLopt in refining
162  // counterexamples via local-optimization. The following
163  // descriptions are from
164  // https://nlopt.readthedocs.io/en/latest/NLopt_Reference/#stopping-criteria
165  //
166  // Set relative tolerance on function value: stop when an
167  // optimization step (or an estimate of the optimum) changes the
168  // objective function value by less than tol multiplied by the
169  // absolute value of the function value. (If there is any chance
170  // that your optimum function value is close to zero, you might want
171  // to set an absolute tolerance with nlopt_set_ftol_abs as well.)
172  // Criterion is disabled if tol is non-positive.
173  OptionValue<double> nlopt_ftol_rel_{kDefaultNloptFtolRel};
174 
175  // Set absolute tolerance on function value: stop when an
176  // optimization step (or an estimate of the optimum) changes the
177  // function value by less than tol. Criterion is disabled if tol is
178  // non-positive.
179  OptionValue<double> nlopt_ftol_abs_{kDefaultNloptFtolAbs};
180 
181  // Stop when the number of function evaluations exceeds
182  // maxeval. (This is not a strict maximum: the number of function
183  // evaluations may exceed maxeval slightly, depending upon the
184  // algorithm.) Criterion is disabled if maxeval is non-positive.
185  OptionValue<int> nlopt_maxeval_{kDefaultNloptMaxEval};
186 
187  // Stop when the optimization time (in seconds) exceeds
188  // maxtime. (This is not a strict maximum: the time may exceed
189  // maxtime slightly, depending upon the algorithm and on how slow
190  // your function evaluation is.) Criterion is disabled if maxtime is
191  // non-positive.
192  OptionValue<double> nlopt_maxtime_{kDefaultNloptMaxTime};
193 
194  // Default initial phase (for PICOSAT):
195  // 0 = false
196  // 1 = true
197  // 2 = Jeroslow-Wang (default)
198  // 3 = random initial phase
199  OptionValue<SatDefaultPhase> sat_default_phase_{
200  SatDefaultPhase::JeroslowWang};
201 
202  // Seed for Random Number Generator.
203  OptionValue<uint32_t> random_seed_{0};
204 
205  // Brancher to use. By default it uses `BranchLargestFirst`.
207 };
208 std::ostream& operator<<(std::ostream& os,
209  const Config::SatDefaultPhase& sat_default_phase);
210 
211 std::ostream& operator<<(std::ostream& os, const Config& config);
212 
213 } // namespace dreal
double nlopt_ftol_abs() const
Returns absolute tolerance on function value in NLopt.
Definition: config.cc:76
OptionValue< double > & mutable_nlopt_ftol_rel()
Returns a mutable OptionValue for nlopt_ftol_rel.
Definition: config.cc:72
const Brancher & brancher() const
Returns the brancher.
Definition: config.cc:66
OptionValue< int > & mutable_number_of_jobs()
Returns a mutable OptionValue for &#39;number_of_jobs&#39;.
Definition: config.cc:51
Sum type of symbolic::Expression and symbolic::Formula.
Definition: api.cc:9
bool use_polytope_in_forall() const
Returns whether it uses polytope contractors inside forall contractors.
Definition: config.cc:29
OptionValue< double > & mutable_nlopt_maxtime()
Returns a mutable OptionValue for nlopt_maxtime.
Definition: config.cc:88
bool use_local_optimization() const
Returns whether it uses local optimization algorithm in exist-forall problems.
Definition: config.cc:43
OptionValue< bool > & mutable_use_worklist_fixpoint()
Returns a mutable OptionValue for &#39;use_worklist_fixpoint&#39;.
Definition: config.cc:39
int number_of_jobs() const
Returns the number of parallel jobs.
Definition: config.cc:50
OptionValue< double > & mutable_precision()
Returns a mutable OptionValue for &#39;precision&#39;.
Definition: config.cc:21
OptionValue< bool > & mutable_stack_left_box_first()
Returns a mutable OptionValue for &#39;stack_left_box_first&#39;.
Definition: config.cc:56
SatDefaultPhase sat_default_phase() const
Returns the default phase for SAT solver.
Definition: config.cc:90
OptionValue< SatDefaultPhase > & mutable_sat_default_phase()
Returns a mutable OptionValue for sat_default_phase.
Definition: config.cc:94
bool use_polytope() const
Returns whether it uses polytope contractors or not.
Definition: config.cc:26
OptionValue< bool > & mutable_produce_models()
Returns a mutable OptionValue for &#39;produce_models&#39;.
Definition: config.cc:24
OptionValue< bool > & mutable_use_polytope_in_forall()
Returns a mutable OptionValue for &#39;use_polytope_in_forall&#39;.
Definition: config.cc:32
double nlopt_ftol_rel() const
Returns relative tolerance on function value in NLopt.
Definition: config.cc:70
OptionValue< double > & mutable_nlopt_ftol_abs()
Returns a mutable OptionValue for nlopt_ftol_abs.
Definition: config.cc:78
int BranchLargestFirst(const Box &box, const DynamicBitset &active_set, Box *const left, Box *const right)
Finds the largest dimension in active_set and partitions box into two sub-boxes by branching on the c...
Definition: brancher.cc:28
OptionValue< bool > & mutable_use_polytope()
Returns a mutable OptionValue for &#39;use_polytope&#39;.
Definition: config.cc:27
double precision() const
Returns the precision option.
Definition: config.cc:20
OptionValue< bool > & mutable_use_local_optimization()
Returns a mutable OptionValue for &#39;use_local_optimization&#39;.
Definition: config.cc:46
bool smtlib2_compliant() const
Returns if it&#39;s smtlib2_compliant mode.
Definition: config.cc:60
double nlopt_maxtime() const
Returns the maxtime in NLopt.
Definition: config.cc:86
Represents a n-dimensional interval vector.
Definition: box.h:17
uint32_t random_seed() const
Returns the random seed.
Definition: config.cc:98
Definition: config.h:12
bool use_worklist_fixpoint() const
Returns whether it uses worklist-fixpoint algorithm.
Definition: config.cc:36
OptionValue< bool > & mutable_smtlib2_compliant()
Returns a mutable OptionValue for smtlib2_compliant.
Definition: config.cc:62
OptionValue< uint32_t > & mutable_random_seed()
Returns a mutable OptionValue for random_seed.
Definition: config.cc:100
bool stack_left_box_first() const
Returns whether the ICP algorithm stacks the left box first after branching.
Definition: config.cc:53
OptionValue< Brancher > & mutable_brancher()
Returns a mutable OptionValue for brancher.
Definition: config.cc:68
OptionValue< int > & mutable_nlopt_maxeval()
Returns a mutable OptionValue for nlopt_maxeval.
Definition: config.cc:84
bool produce_models() const
Returns the produce_models option.
Definition: config.cc:23