forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clp_solver_common.cc
51 lines (43 loc) · 1.74 KB
/
clp_solver_common.cc
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
/* clang-format off to disable clang-format-includes */
#include "drake/solvers/clp_solver.h"
/* clang-format on */
#include "drake/common/never_destroyed.h"
#include "drake/solvers/aggregate_costs_constraints.h"
#include "drake/solvers/mathematical_program.h"
namespace drake {
namespace solvers {
ClpSolver::ClpSolver()
: SolverBase(&id, &is_available, &is_enabled, &ProgramAttributesSatisfied,
&UnsatisfiedProgramAttributes) {}
ClpSolver::~ClpSolver() = default;
SolverId ClpSolver::id() {
static const never_destroyed<SolverId> singleton{"CLP"};
return singleton.access();
}
bool ClpSolver::is_enabled() { return true; }
namespace {
// If the program is compatible with this solver, returns true and clears the
// explanation. Otherwise, returns false and sets the explanation. In either
// case, the explanation can be nullptr in which case it is ignored.
bool CheckAttributes(const MathematicalProgram& prog,
std::string* explanation) {
static const never_destroyed<ProgramAttributes> solver_capabilities(
std::initializer_list<ProgramAttribute>{
ProgramAttribute::kLinearEqualityConstraint,
ProgramAttribute::kLinearConstraint, ProgramAttribute::kLinearCost,
ProgramAttribute::kQuadraticCost});
return internal::CheckConvexSolverAttributes(
prog, solver_capabilities.access(), "ClpSolver", explanation);
}
} // namespace
bool ClpSolver::ProgramAttributesSatisfied(const MathematicalProgram& prog) {
return CheckAttributes(prog, nullptr);
}
std::string ClpSolver::UnsatisfiedProgramAttributes(
const MathematicalProgram& prog) {
std::string explanation;
CheckAttributes(prog, &explanation);
return explanation;
}
} // namespace solvers
} // namespace drake