Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DoglegOptimizer: Throw exception if infeasible test #33

Merged
merged 2 commits into from
May 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions tests/testDoglegOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
#include <CppUnitLite/TestHarness.h>

#include <tests/smallExample.h>
#include <gtsam/geometry/Pose2.h>
#include <gtsam/nonlinear/DoglegOptimizer.h>
#include <gtsam/nonlinear/DoglegOptimizerImpl.h>
#include <gtsam/nonlinear/NonlinearEquality.h>
#include <gtsam/slam/BetweenFactor.h>
#include <gtsam/inference/Symbol.h>
#include <gtsam/linear/JacobianFactor.h>
#include <gtsam/linear/GaussianBayesTree.h>
Expand Down Expand Up @@ -147,6 +151,39 @@ TEST(DoglegOptimizer, Iterate) {
}
}

/* ************************************************************************* */
TEST(DoglegOptimizer, Constraint) {
// Create a pose-graph graph with a constraint on the first pose
NonlinearFactorGraph graph;
const Pose2 origin(0, 0, 0), pose2(2, 0, 0);
graph.emplace_shared<NonlinearEquality<Pose2> >(1, origin);
auto model = noiseModel::Diagonal::Sigmas(Vector3(0.2, 0.2, 0.1));
graph.emplace_shared<BetweenFactor<Pose2> >(1, 2, pose2, model);

// Create feasible initial estimate
Values initial;
initial.insert(1, origin); // feasible !
initial.insert(2, Pose2(2.3, 0.1, -0.2));

// Optimize the initial values using DoglegOptimizer
DoglegParams params;
params.setVerbosityDL("VERBOSITY");
DoglegOptimizer optimizer(graph, initial, params);
Values result = optimizer.optimize();

// Check result
EXPECT(assert_equal(pose2, result.at<Pose2>(2)));

// Create infeasible initial estimate
Values infeasible;
infeasible.insert(1, Pose2(0.1, 0, 0)); // infeasible !
infeasible.insert(2, Pose2(2.3, 0.1, -0.2));

// Try optimizing with infeasible initial estimate
DoglegOptimizer optimizer2(graph, infeasible, params);
CHECK_EXCEPTION(optimizer2.optimize(), std::invalid_argument);
}

/* ************************************************************************* */
int main() { TestResult tr; return TestRegistry::runAllTests(tr); }
/* ************************************************************************* */