forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdreal_solver.h
99 lines (79 loc) · 3.12 KB
/
dreal_solver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#pragma once
#include <string>
#include <unordered_map>
#include "drake/common/drake_copyable.h"
#include "drake/common/drake_optional.h"
#include "drake/common/hash.h"
#include "drake/common/symbolic.h"
#include "drake/solvers/solver_base.h"
namespace drake {
namespace solvers {
class DrealSolver final : public SolverBase {
public:
/// Class representing an interval of doubles.
class Interval {
public:
DRAKE_DEFAULT_COPY_AND_MOVE_AND_ASSIGN(Interval)
/// Constructs an interval [low, high].
///
/// @pre Its lower bound @p low must be less than or equal to its upper
/// bound @p high.
Interval(double low, double high) : low_{low}, high_{high} {
DRAKE_DEMAND(low <= high);
}
/// Returns its diameter.
double diam() const { return high_ - low_; }
/// Returns its mid-point.
double mid() const { return high_ / 2 + low_ / 2; }
/// Returns its lower bound.
double low() const { return low_; }
/// Returns its upper bound.
double high() const { return high_; }
private:
double low_{};
double high_{};
};
using IntervalBox = std::unordered_map<symbolic::Variable, Interval>;
/// Indicates whether to use dReal's --local-optimization option or not.
enum class LocalOptimization {
kUse, ///< Use "--local-optimization" option.
kNotUse, ///< Do not use "--local-optimization" option.
};
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(DrealSolver)
DrealSolver();
~DrealSolver() final;
/// Checks the satisfiability of a given formula @p f with a given precision
/// @p delta.
///
/// @returns a model, a mapping from a variable to an interval, if @p f is
/// δ-satisfiable.
/// @returns a nullopt, if @p is unsatisfiable.
static optional<IntervalBox> CheckSatisfiability(const symbolic::Formula& f,
double delta);
/// Finds a solution to minimize @p objective function while satisfying a
/// given @p constraint using @p delta. When @p local_optimization is
/// Localoptimization::kUse, enable "--local-optimization" dReal option which
/// uses NLopt's local-optimization algorithms to refine counterexamples in
/// the process of global optimization.
///
/// @returns a model, a mapping from a variable to an interval, if a solution
/// exists.
/// @returns nullopt, if there is no solution.
static optional<IntervalBox> Minimize(const symbolic::Expression& objective,
const symbolic::Formula& constraint,
double delta,
LocalOptimization local_optimization);
/// @name Static versions of the instance methods with similar names.
//@{
static SolverId id();
static bool is_available();
static bool ProgramAttributesSatisfied(const MathematicalProgram&);
//@}
// A using-declaration adds these methods into our class's Doxygen.
using SolverBase::Solve;
private:
void DoSolve(const MathematicalProgram&, const Eigen::VectorXd&,
const SolverOptions&, MathematicalProgramResult*) const final;
};
} // namespace solvers
} // namespace drake