forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmax_clique_solver_via_mip.h
71 lines (56 loc) · 2.12 KB
/
max_clique_solver_via_mip.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
#pragma once
#include <memory>
#include <optional>
#include <Eigen/Sparse>
#include "drake/planning/graph_algorithms/max_clique_solver_base.h"
#include "drake/solvers/solver_options.h"
namespace drake {
namespace planning {
namespace graph_algorithms {
/**
* Solves the maximum clique problem to global optimality by solving the
* mixed-integer program
*
* Maximize ∑ᵢ xᵢ subject to
* xᵢ + xⱼ ≤ 1 if (i,j) is not in the edge
* xᵢ ∈ {0,1}.
*
* Note: This solver requires the availability of a Mixed-Integer Linear
* Programming solver (e.g. Gurobi and/or Mosek). We recommend enabling those
* solvers if possible (https://drake.mit.edu/bazel.html#proprietary_solvers).
*
* @throws std::exception if no Mixed-Integer Linear Programming solver is
* available.
* @throws std::exception if the initial guess has the wrong size for the
* provided adjacency matrix.
*/
class MaxCliqueSolverViaMip final : public MaxCliqueSolverBase {
public:
DRAKE_DEFAULT_COPY_AND_MOVE_AND_ASSIGN(MaxCliqueSolverViaMip);
MaxCliqueSolverViaMip() = default;
MaxCliqueSolverViaMip(const std::optional<Eigen::VectorXd>& initial_guess,
const solvers::SolverOptions& solver_options);
void SetSolverOptions(const solvers::SolverOptions& solver_options) {
solver_options_ = solver_options;
}
[[nodiscard]] solvers::SolverOptions GetSolverOptions() const {
return solver_options_;
}
void SetInitialGuess(const std::optional<Eigen::VectorXd>& initial_guess) {
initial_guess_ = initial_guess;
}
[[nodiscard]] std::optional<Eigen::VectorXd> GetInitialGuess() const {
return initial_guess_;
}
private:
VectorX<bool> DoSolveMaxClique(
const Eigen::SparseMatrix<bool>& adjacency_matrix) const final;
[[nodiscard]] std::unique_ptr<MaxCliqueSolverBase> DoClone() const final;
/* Initial guess to the MIP for solving max clique. */
std::optional<Eigen::VectorXd> initial_guess_{std::nullopt};
/* Options solved to the MIP solver used to solve max clique. */
solvers::SolverOptions solver_options_;
};
} // namespace graph_algorithms
} // namespace planning
} // namespace drake