@@ -169,44 +169,29 @@ void WindowedOptimizer::optimizationLoop()
169169 {
170170 continue ;
171171 }
172- // Prepare for selecting the marginal variables -- Delegated to derived classes
173- preprocessMarginalization (*new_transaction);
174- // Combine the new transactions with any marginal transaction from the end of the last cycle
175- 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 ;
172+ // check if new transaction has added constraints to variables that are to be marginalized
173+ std::vector<fuse_core::UUID> faulty_constraints;
174+ for (auto & c: new_transaction->addedConstraints ()){
175+ for (auto var_uuid: c.variables ()){
176+ for (auto marginal_uuid : marginal_transaction_.removedVariables ()) {
177+ if (var_uuid == marginal_uuid) {
178+ faulty_constraints.push_back (c.uuid ());
193179 break ;
194180 }
195181 }
196- if (!is_contained) {
197- variables_to_remarginalize.push_back (uuid);
198- }
199182 }
200183 }
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);
184+ if (faulty_constraints.size () > 0 ){
185+ ROS_WARN_STREAM (" Removing invalid constraints." );
186+ for (auto & faulty_constraint: faulty_constraints){
187+ new_transaction->removeConstraint (faulty_constraint);
188+ }
208189 }
209190
191+ // Prepare for selecting the marginal variables -- Delegated to derived classes
192+ preprocessMarginalization (*new_transaction);
193+ // Combine the new transactions with any marginal transaction from the end of the last cycle
194+ new_transaction->merge (marginal_transaction_);
210195 // Update the graph
211196 try
212197 {
0 commit comments