Skip to content

Commit caeb278

Browse files
Fix marginalization bug
1 parent febdb5f commit caeb278

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

fuse_optimizers/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.0.2)
22
project(fuse_optimizers)
33
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
44

5+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
6+
57
set(build_depends
68
diagnostic_updater
79
fuse_constraints

fuse_optimizers/src/windowed_optimizer.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,40 @@ void WindowedOptimizer::optimizationLoop()
173173
preprocessMarginalization(*new_transaction);
174174
// Combine the new transactions with any marginal transaction from the end of the last cycle
175175
new_transaction->merge(marginal_transaction_);
176+
177+
// check for hanging constraints (constraints added to variables that are about to be marginalized)
178+
auto new_marginal_transaction = fuse_core::Transaction::make_shared();
179+
std::vector<fuse_core::UUID> variables_to_remarginalize;
180+
for (auto &uuid : marginal_transaction_->removedVariables()) {
181+
// get constraints that are to be removed in marginal transaction
182+
auto to_remove_constraints = marginal_transaction_->getRemovedConstraints();
183+
// get connected constraint to this variable
184+
auto all_constraints = graph_->getConnectedConstraints(uuid);
185+
// check if there is a constraint on this variable that isnt in the
186+
// marginal transaction
187+
for (auto &constraint : all_constraints) {
188+
fuse_core::UUID constraint_uuid = constraint->uuid();
189+
bool is_contained = false;
190+
for (auto &to_remove : to_remove_constraints) {
191+
if (constraint_uuid == to_remove) {
192+
is_contained = true;
193+
break;
194+
}
195+
}
196+
if (!is_contained) {
197+
variables_to_remarginalize.push_back(uuid);
198+
}
199+
}
200+
}
201+
202+
// if some variables have hanging constraints then remarginalize them
203+
if (variables_to_remarginalize.size() > 0) {
204+
new_marginal_transaction = fuse_constraints::marginalizeVariables(
205+
ros::this_node::getName(), variables_to_remarginalize, *graph_);
206+
postprocessMarginalization(*new_marginal_transaction);
207+
new_transaction->merge(new_marginal_transaction);
208+
}
209+
176210
// Update the graph
177211
try
178212
{

0 commit comments

Comments
 (0)