4 const Eigen::VectorXd& observations,
5 const Eigen::MatrixXd& covariance,
6 const Eigen::VectorXd& observation_confidences)
const {
7 const int num_observations = observations.size() / 2;
8 const int num_landmarks = landmarks.size() / 2;
10 Eigen::VectorXi best_hypothesis =
11 Eigen::VectorXi::Constant(num_observations, -1);
12 Eigen::VectorXi current_hypothesis = Eigen::VectorXi::Constant(num_observations, -1);
14 double best_score = -1.0;
17 Eigen::MatrixXd distances(num_observations, num_landmarks);
18 for (
int obs_idx = 0; obs_idx < num_observations; ++obs_idx) {
19 Eigen::Vector2d observation(observations(2 * obs_idx), observations(2 * obs_idx + 1));
20 for (
int lm_idx = 0; lm_idx < num_landmarks; ++lm_idx) {
21 Eigen::Vector2d landmark(landmarks(2 * lm_idx), landmarks(2 * lm_idx + 1));
22 distances(obs_idx, lm_idx) = (observation - landmark).norm();
28 best_hypothesis, best_score, 0.0);
30 return best_hypothesis;
34 const Eigen::MatrixXd& distances,
35 Eigen::VectorXi& current_hypothesis,
36 Eigen::VectorXi& best_hypothesis,
double& best_score,
37 double current_score)
const {
38 if (current_obs_idx >= num_observations) {
39 if (current_score > best_score) {
40 best_hypothesis = current_hypothesis;
41 best_score = current_score;
47 for (
int landmark_idx = 0; landmark_idx < num_landmarks; ++landmark_idx) {
50 current_hypothesis(current_obs_idx) = 2 * landmark_idx;
53 distances(current_obs_idx, landmark_idx));
56 double upper_bound = updated_score + (num_observations - current_obs_idx - 1) *
59 if (upper_bound >= best_score) {
61 current_hypothesis, best_hypothesis, best_score, updated_score);
65 current_hypothesis(current_obs_idx) = -1;
70 current_hypothesis(current_obs_idx) = -1;
75 if (upper_bound >= best_score) {
77 current_hypothesis, best_hypothesis, best_score, current_score);
81 current_hypothesis(current_obs_idx) = -1;
Eigen::VectorXi associate(const Eigen::VectorXd &landmarks, const Eigen::VectorXd &observations, const Eigen::MatrixXd &covariance, const Eigen::VectorXd &observation_confidences) const override
Perform data association using the Joint Compatibility Branch & Bound algorithm.
void search_branch_and_bound(int current_obs_idx, int num_observations, int num_landmarks, const Eigen::MatrixXd &distances, Eigen::VectorXi ¤t_hypothesis, Eigen::VectorXi &best_hypothesis, double &best_score, double current_score) const
Recursive branch and bound search to find the best hypothesis.