Skip to content

Commit d609f59

Browse files
committed
Add parameter for heuristic-based max-clique problem
1 parent 1c4ae1a commit d609f59

File tree

11 files changed

+51
-34
lines changed

11 files changed

+51
-34
lines changed

cpp/examples/robust_distributed_optimization_example_2robots.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ int main(int argc, char *argv[]) {
3333
double pcm_threshold = 0.99; // confidence probability for the pairwise consistency computation.
3434
bool use_covariance = false; // use covariance in dataset file.
3535
bool use_PCM = false; // Use pairwise consistency maximization.
36+
bool use_heuristics = true; // Use heuristics-based algorithm for the max-clique solver.
3637

3738
try {
3839
// Parse program options
@@ -61,7 +62,8 @@ int main(int argc, char *argv[]) {
6162
("confidence, c", po::value<double>(&pcm_threshold), "confidence probability for the pairwise consistency computation (default: 0.99)")
6263
("useCovariance, i", po::value<bool>(&use_covariance), "use covariance in dataset file (default: false)")
6364
("debug, d", po::value<bool>(&debug), "debug (default: false)")
64-
("usePCM", po::value<bool>(&use_PCM), "use pairwise consistency maximization (default: true)");
65+
("usePCM", po::value<bool>(&use_PCM), "use pairwise consistency maximization (default: true)")
66+
("useHeuristics", po::value<bool>(&use_heuristics), "use heuristics-based algorithm for the max-clique solver. (default: true)");
6567

6668
po::variables_map vm;
6769
try {
@@ -89,7 +91,7 @@ int main(int argc, char *argv[]) {
8991
use_XY, use_OP, debug, priorModel, model,
9092
max_iter, rotation_estimate_change_threshold, pose_estimate_change_threshold,
9193
gamma, use_flagged_init, update_type, use_between_noise,
92-
use_chr_less_full_graph, use_landmarks, pcm_threshold, use_covariance, use_PCM);
94+
use_chr_less_full_graph, use_landmarks, pcm_threshold, use_covariance, use_PCM, use_heuristics);
9395

9496
return 0;
9597
}

cpp/include/distributed_mapper/distributed_mapper_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ distributedOptimizer(std::vector< boost::shared_ptr<DistributedMapper> >& dist_m
106106
const double& pcm_threshold = 0.99,
107107
const bool& use_covariance = false,
108108
const bool& use_pcm = true,
109+
const bool& use_heuristics = true,
109110
boost::optional<std::vector<gtsam::GraphAndValues>&> graph_and_values_vec = boost::none,
110111
boost::optional<std::vector<gtsam::Values>&> rotation_trace = boost::none,
111112
boost::optional<std::vector<gtsam::Values>&> pose_trace = boost::none,

cpp/include/distributed_mapper/run_distributed_mapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ namespace distributed_mapper {
2727
const size_t& max_iter, const double& rotation_estimate_change_threshold, const double& pose_estimate_change_threshold,
2828
const double& gamma, const bool& use_flagged_init, const distributed_mapper::DistributedMapper::UpdateType& update_type,
2929
const bool& use_between_noise, const bool& use_chr_less_full_graph, const bool& use_landmarks, const double& pcm_threshold, const bool& use_covariance,
30-
const bool& use_PCM);
30+
const bool& use_PCM, const bool& use_heuristics);
3131
}

cpp/include/pairwise_consistency_maximization/distributed_pcm/distributed_pcm.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ namespace distributed_pcm {
3030
*/
3131
static std::pair<int, int> solveCentralized(std::vector< boost::shared_ptr<distributed_mapper::DistributedMapper> >& dist_mappers,
3232
std::vector<gtsam::GraphAndValues>& graph_and_values_vector,
33-
const double& pcm_threshold, const bool& use_covariance);
33+
const double& pcm_threshold, const bool& use_covariance,
34+
const bool& use_heuristics);
3435

3536
/**
3637
* \brief Function that solves the pairwise consistency maximization according to the current constraints with limited information
@@ -46,7 +47,8 @@ namespace distributed_pcm {
4647
robot_measurements::RobotLocalMap& robot_local_map,
4748
const graph_utils::Trajectory& other_robot_trajectory,
4849
const double& pcm_threshold,
49-
const bool& is_prior_added);
50+
const bool& is_prior_added,
51+
const bool& use_heuristics);
5052

5153
private:
5254

@@ -61,15 +63,17 @@ namespace distributed_pcm {
6163
const std::map<std::pair<char, char>,graph_utils::Transforms>& separators_transforms_by_pair,
6264
std::vector< boost::shared_ptr<distributed_mapper::DistributedMapper> >& dist_mappers,
6365
std::vector<gtsam::GraphAndValues>& graph_and_values_vector,
64-
const double& pcm_threshold);
66+
const double& pcm_threshold,
67+
const bool& use_heuristics);
6568

6669
static std::pair<std::pair<int, int>, std::pair<std::set<std::pair<gtsam::Key, gtsam::Key>>, std::set<std::pair<gtsam::Key, gtsam::Key>>>>
6770
executePCMDecentralized(const int& other_robot_id, robot_measurements::RobotLocalMap& robot_local_map,
6871
const robot_measurements::RobotLocalMap& other_robot_local_info,
6972
boost::shared_ptr<distributed_mapper::DistributedMapper>& dist_mapper,
7073
gtsam::GraphAndValues& local_graph_and_values,
7174
const double& pcm_threshold,
72-
const bool& is_prior_added);
75+
const bool& is_prior_added,
76+
const bool& use_heuristics);
7377

7478
static bool isSeparatorToBeRejected(const std::vector<int>& max_clique, const int& separtor_id, const graph_utils::Transforms& separators_transforms,
7579
const graph_utils::LoopClosures& loop_closures, boost::shared_ptr<distributed_mapper::DistributedMapper>& dist_mapper);

cpp/include/pairwise_consistency_maximization/global_map/global_map.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ namespace global_map {
4242
GlobalMap(const robot_measurements::RobotLocalMap& robot1_local_map,
4343
const robot_measurements::RobotLocalMap& robot2_local_map,
4444
const robot_measurements::RobotMeasurements& interrobot_measurements,
45-
const double& pcm_threshold);
45+
const double& pcm_threshold,
46+
const bool& use_heuristics);
4647

4748
/**
4849
* \brief Function that solves the global maps according to the current constraints
@@ -54,6 +55,8 @@ namespace global_map {
5455
private:
5556
pairwise_consistency::PairwiseConsistency pairwise_consistency_; ///< Pairwise consistency solver.
5657

58+
bool use_heuristics_; ///< if true: uses the heuristics-based max-clique solver (faster), if false: uses the exact algorithm (slower)
59+
5760
};
5861
}
5962

cpp/src/distributed_mapper/distributed_mapper_utils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ distributedOptimizer(std::vector< boost::shared_ptr<DistributedMapper> >& dist_m
494494
const double& pcm_threshold,
495495
const bool& use_covariance,
496496
const bool& use_pcm,
497+
const bool& use_heuristics,
497498
boost::optional<std::vector<gtsam::GraphAndValues>&> graph_and_values_vec,
498499
boost::optional<std::vector<gtsam::Values>&> rotation_trace,
499500
boost::optional<std::vector<gtsam::Values>&> pose_trace,
@@ -516,7 +517,7 @@ distributedOptimizer(std::vector< boost::shared_ptr<DistributedMapper> >& dist_m
516517

517518
if (use_pcm && contains_odometry) {
518519
auto max_clique_info = distributed_pcm::DistributedPCM::solveCentralized(dist_mappers, graph_and_values_vec.get(),
519-
pcm_threshold, use_covariance);
520+
pcm_threshold, use_covariance, use_heuristics);
520521
max_clique_size = max_clique_info.first;
521522
}
522523

cpp/src/distributed_mapper/run_distributed_mapper.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ std::tuple<double, double, int> runDistributedMapper(const size_t& nr_robots, co
1515
const size_t& max_iter, const double& rotation_estimate_change_threshold, const double& pose_estimate_change_threshold,
1616
const double& gamma, const bool& use_flagged_init, const distributed_mapper::DistributedMapper::UpdateType& update_type,
1717
const bool& use_between_noise, const bool& use_chr_less_full_graph, const bool& use_landmarks, const double& pcm_threshold, const bool& use_covariance,
18-
const bool& use_PCM) {
18+
const bool& use_PCM,
19+
const bool& use_heuristics) {
1920

2021
vector <GraphAndValues> graph_and_values_vec; // vector of all graphs and initials
2122

@@ -114,7 +115,7 @@ std::tuple<double, double, int> runDistributedMapper(const size_t& nr_robots, co
114115
gamma, rotation_estimate_change_threshold,
115116
pose_estimate_change_threshold,
116117
use_flagged_init, use_landmarks, debug, true,
117-
pcm_threshold, use_covariance, use_PCM,
118+
pcm_threshold, use_covariance, use_PCM, use_heuristics,
118119
graph_and_values_vec,
119120
rotation_trace, pose_trace, subgraph_rotation_trace,
120121
subgraph_pose_trace, rotation_vector_values_trace);

cpp/src/pairwise_consistency_maximization/distributed_pcm/distributed_pcm.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace distributed_pcm {
66

77
std::pair<int, int> DistributedPCM::solveCentralized(std::vector< boost::shared_ptr<distributed_mapper::DistributedMapper> >& dist_mappers,
88
std::vector<gtsam::GraphAndValues>& graph_and_values_vector,
9-
const double& pcm_threshold, const bool& use_covariance) {
9+
const double& pcm_threshold, const bool& use_covariance, const bool& use_heuristics) {
1010

1111
std::vector<graph_utils::LoopClosures> separators_by_robot;
1212
std::vector<graph_utils::Transforms> transforms_by_robot;
@@ -23,7 +23,7 @@ namespace distributed_pcm {
2323

2424
auto max_clique_info = executePCMCentralized(roboti, robotj, transforms_by_robot, separators_by_robot,
2525
separators_transforms_by_pair, dist_mappers,
26-
graph_and_values_vector, pcm_threshold);
26+
graph_and_values_vector, pcm_threshold, use_heuristics);
2727

2828
total_max_clique_sizes += max_clique_info.first;
2929
total_outliers_rejected += max_clique_info.second;
@@ -40,15 +40,16 @@ namespace distributed_pcm {
4040
robot_measurements::RobotLocalMap& robot_local_map,
4141
const graph_utils::Trajectory& other_robot_trajectory,
4242
const double& pcm_threshold,
43-
const bool& is_prior_added) {
43+
const bool& is_prior_added,
44+
const bool& use_heuristics) {
4445

4546
graph_utils::Transforms empty_transforms;
4647
auto other_robot_local_info = robot_measurements::RobotLocalMap(other_robot_trajectory, empty_transforms, robot_local_map.getLoopClosures());
4748

4849
// Apply PCM for each pair of robots
4950
auto max_clique_info = executePCMDecentralized(other_robot_id, robot_local_map, other_robot_local_info,
5051
dist_mapper, local_graph_and_values,
51-
pcm_threshold, is_prior_added);
52+
pcm_threshold, is_prior_added, use_heuristics);
5253

5354
return max_clique_info;
5455
}
@@ -119,13 +120,14 @@ namespace distributed_pcm {
119120
const std::map<std::pair<char, char>,graph_utils::Transforms>& separators_transforms_by_pair,
120121
std::vector< boost::shared_ptr<distributed_mapper::DistributedMapper> >& dist_mappers,
121122
std::vector<gtsam::GraphAndValues>& graph_and_values_vector,
122-
const double& pcm_threshold){
123+
const double& pcm_threshold,
124+
const bool& use_heuristics){
123125
auto roboti_local_map = robot_measurements::RobotLocalMap(transforms_by_robot[roboti], separators_by_robot[roboti]);
124126
auto robotj_local_map = robot_measurements::RobotLocalMap(transforms_by_robot[robotj], separators_by_robot[robotj]);
125127
auto roboti_robotj_separators_transforms = separators_transforms_by_pair.at(std::make_pair(dist_mappers[roboti]->robotName(),dist_mappers[robotj]->robotName()));
126128
auto interrobot_measurements = robot_measurements::InterRobotMeasurements(roboti_robotj_separators_transforms, dist_mappers[roboti]->robotName(), dist_mappers[robotj]->robotName());
127129

128-
auto global_map = global_map::GlobalMap(roboti_local_map, robotj_local_map, interrobot_measurements, pcm_threshold);
130+
auto global_map = global_map::GlobalMap(roboti_local_map, robotj_local_map, interrobot_measurements, pcm_threshold, use_heuristics);
129131
auto max_clique_info = global_map.pairwiseConsistencyMaximization();
130132
std::vector<int> max_clique = max_clique_info.first;
131133

@@ -174,7 +176,8 @@ namespace distributed_pcm {
174176
boost::shared_ptr<distributed_mapper::DistributedMapper>& dist_mapper,
175177
gtsam::GraphAndValues& local_graph_and_values,
176178
const double& pcm_threshold,
177-
const bool& is_prior_added){
179+
const bool& is_prior_added,
180+
const bool& use_heuristics){
178181

179182
graph_utils::Transforms roboti_robotj_separators_transforms;
180183
for (const auto& transform : robot_local_map.getTransforms().transforms) {
@@ -188,7 +191,7 @@ namespace distributed_pcm {
188191
auto interrobot_measurements = robot_measurements::InterRobotMeasurements(roboti_robotj_separators_transforms,
189192
dist_mapper->robotName(), ((char) other_robot_id + 97));
190193

191-
auto global_map = global_map::GlobalMap(robot_local_map, other_robot_local_info, interrobot_measurements, pcm_threshold);
194+
auto global_map = global_map::GlobalMap(robot_local_map, other_robot_local_info, interrobot_measurements, pcm_threshold, use_heuristics);
192195
auto max_clique_info = global_map.pairwiseConsistencyMaximization();
193196
std::vector<int> max_clique = max_clique_info.first;
194197

cpp/src/pairwise_consistency_maximization/global_map/global_map.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ const std::string GlobalMap::CONSISTENCY_LOOP_CLOSURES_FILE_NAME = std::string(G
2020
GlobalMap::GlobalMap(const robot_measurements::RobotLocalMap& robot1_local_map,
2121
const robot_measurements::RobotLocalMap& robot2_local_map,
2222
const robot_measurements::RobotMeasurements& interrobot_measurements,
23-
const double& pcm_threshold):
23+
const double& pcm_threshold,
24+
const bool& use_heuristics):
2425
pairwise_consistency_(robot1_local_map.getTransforms(), robot2_local_map.getTransforms(),
2526
interrobot_measurements.getTransforms(), interrobot_measurements.getLoopClosures(),
2627
robot1_local_map.getTrajectory(), robot2_local_map.getTrajectory(),
27-
robot1_local_map.getNbDegreeFreedom(), pcm_threshold){}
28+
robot1_local_map.getNbDegreeFreedom(), pcm_threshold), use_heuristics_(use_heuristics) {}
2829

2930

3031
std::pair<std::vector<int>, int> GlobalMap::pairwiseConsistencyMaximization() {
@@ -39,6 +40,7 @@ std::pair<std::vector<int>, int> GlobalMap::pairwiseConsistencyMaximization() {
3940
gio.readGraph(consistency_matrix_file);
4041
int max_clique_size = 0;
4142
std::vector<int> max_clique_data;
43+
4244
//max_clique_size = FMC::maxClique(gio, max_clique_size, max_clique_data);
4345
max_clique_size = FMC::maxCliqueHeu(gio, max_clique_data);
4446

cpp/tests/test_distributed_mapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ distributedEstimation(size_t nrRobots, string dataPath, string traceFile, Values
8383
int max_clique_size = 0;
8484
vector< Values > estimates = distributedOptimizer(distMappers, maxIter, max_clique_size, DistributedMapper::incUpdate,
8585
gamma, rotationEstimateChangeThreshold, poseEstimateChangeThreshold,
86-
useFlaggedInit, false, false, contains_odometry, 0.99, false, true,
86+
useFlaggedInit, false, false, contains_odometry, 0.99, false, true, true,
8787
boost::none, rotationTrace, poseTrace,
8888
subgraphRotationTrace, subgraphPoseTrace, rotationVectorValuesTrace);
8989

0 commit comments

Comments
 (0)