forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_cost.h
75 lines (63 loc) · 2.31 KB
/
create_cost.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
#pragma once
#include <memory>
#include <optional>
#include <type_traits>
#include <utility>
#include "drake/common/symbolic/expression.h"
#include "drake/solvers/binding.h"
#include "drake/solvers/cost.h"
#include "drake/solvers/function.h"
namespace drake {
namespace solvers {
namespace internal {
/*
* Assist MathematicalProgram::AddLinearCost(...).
*/
Binding<LinearCost> ParseLinearCost(const symbolic::Expression& e);
/*
* Assist MathematicalProgram::AddQuadraticCost(...).
*/
Binding<QuadraticCost> ParseQuadraticCost(
const symbolic::Expression& e,
std::optional<bool> is_convex = std::nullopt);
/*
* Assist MathematicalProgram::AddPolynomialCost(...).
*/
Binding<PolynomialCost> ParsePolynomialCost(const symbolic::Expression& e);
/*
* Assist MathematicalProgram::AddL2NormCost(...)
*/
Binding<L2NormCost> ParseL2NormCost(const symbolic::Expression& e,
double psd_tol, double coefficient_tol);
/*
* Assist MathematicalProgram::AddCost(...).
*/
Binding<Cost> ParseCost(const symbolic::Expression& e);
// TODO(eric.cousineau): Remove this when functor cost is no longer exposed
// externally, and must be explicitly called.
/**
* Enables us to catch and provide a meaningful assertion if a Constraint is
* passed in, when we should have a Cost.
* @tparam F The class to test if it is convertible to variants of C.
* @tparam C Intended to be either Cost or Constraint.
*/
template <typename F, typename C>
struct is_binding_compatible
: std::bool_constant<(std::is_convertible_v<F, C>) ||
(std::is_convertible_v<F, std::shared_ptr<C>>) ||
(std::is_convertible_v<F, std::unique_ptr<C>>) ||
(std::is_convertible_v<F, Binding<C>>)> {};
/**
* Template condition to check if @p F is a candidate to be used to construct a
* FunctionCost object for generic costs.
* @tparam T The type to be tested.
* @note Constraint is used to ensure that we do not preclude cost objects
* that lost their CostShim type somewhere in the process.
*/
template <typename F>
struct is_cost_functor_candidate
: std::bool_constant<(!is_binding_compatible<F, Cost>::value) &&
(!std::is_convertible_v<F, symbolic::Expression>)> {};
} // namespace internal
} // namespace solvers
} // namespace drake