testKruskal.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
20 #include <gtsam/base/kruskal.h>
21 #include <gtsam/geometry/Rot3.h>
23 #include <gtsam/inference/Symbol.h>
27 
28 #include <list>
29 #include <memory>
30 #include <vector>
31 
33  using namespace gtsam;
34  using namespace symbol_shorthand;
35 
37  Matrix I = I_2x2;
38  Vector2 b(0, 0);
40  gfg.emplace_shared<JacobianFactor>(X(1), I, X(2), I, b, model);
41  gfg.emplace_shared<JacobianFactor>(X(1), I, X(3), I, b, model);
42  gfg.emplace_shared<JacobianFactor>(X(1), I, X(4), I, b, model);
43  gfg.emplace_shared<JacobianFactor>(X(2), I, X(3), I, b, model);
44  gfg.emplace_shared<JacobianFactor>(X(2), I, X(4), I, b, model);
45  gfg.emplace_shared<JacobianFactor>(X(3), I, X(4), I, b, model);
46 
47  return gfg;
48 }
49 
51  using namespace gtsam;
52  using namespace symbol_shorthand;
53 
62 
63  return nfg;
64 }
65 
66 /* ************************************************************************* */
68  using namespace gtsam;
69 
70  // Create factor graph.
71  const auto g = makeTestGaussianFactorGraph();
72 
73  // Assign weights to all the edges in the graph.
74  const auto weights = std::vector<double>(g.size(), 1.0);
75 
76  const auto mstEdgeIndices = utils::kruskal(g, weights);
77 
78  EXPECT(mstEdgeIndices[0] == 0);
79  EXPECT(mstEdgeIndices[1] == 1);
80  EXPECT(mstEdgeIndices[2] == 2);
81 }
82 
83 /* ************************************************************************* */
85  using namespace gtsam;
86 
87  // Create factor graph.
88  const auto g = makeTestNonlinearFactorGraph();
89 
90  // Assign weights to all the edges in the graph.
91  const auto weights = std::vector<double>(g.size(), 1.0);
92 
93  const auto mstEdgeIndices = utils::kruskal(g, weights);
94 
95  EXPECT(mstEdgeIndices[0] == 0);
96  EXPECT(mstEdgeIndices[1] == 1);
97  EXPECT(mstEdgeIndices[2] == 2);
98 }
99 
100 /* ************************************************************************* */
101 int main() {
102  TestResult tr;
103  return TestRegistry::runAllTests(tr);
104 }
105 /* ************************************************************************* */
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
kruskal.h
GaussianFactorGraph.h
Linear Factor Graph where all factors are Gaussians.
gtsam::utils::kruskal
std::vector< size_t > kruskal(const FactorGraph< FACTOR > &fg, const std::vector< double > &weights)
Definition: kruskal-inl.h:55
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
gtsam::Vector2
Eigen::Vector2d Vector2
Definition: Vector.h:42
TestHarness.h
gtsam::JacobianFactor
Definition: JacobianFactor.h:91
makeTestNonlinearFactorGraph
gtsam::NonlinearFactorGraph makeTestNonlinearFactorGraph()
Definition: testKruskal.cpp:50
gtsam::Matrix
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
gtsam::noiseModel::Diagonal::Sigmas
static shared_ptr Sigmas(const Vector &sigmas, bool smart=true)
Definition: NoiseModel.cpp:270
Ordering.h
Variable ordering for the elimination algorithm.
makeTestGaussianFactorGraph
gtsam::GaussianFactorGraph makeTestGaussianFactorGraph()
Definition: testKruskal.cpp:32
TestableAssertions.h
Provides additional testing facilities for common data structures.
Rot3.h
3D rotation represented as a rotation matrix or quaternion
main
int main()
Definition: testKruskal.cpp:101
gtsam::GaussianFactorGraph
Definition: GaussianFactorGraph.h:73
gtsam::symbol_shorthand::X
Key X(std::uint64_t j)
Definition: inference/Symbol.h:171
BetweenFactor.h
gtsam::Rot3
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
Definition: Rot3.h:58
gtsam::NonlinearFactorGraph
Definition: NonlinearFactorGraph.h:55
gtsam::SharedDiagonal
noiseModel::Diagonal::shared_ptr SharedDiagonal
Definition: NoiseModel.h:743
Symbol.h
Vector2
Definition: test_operator_overloading.cpp:18
model
noiseModel::Diagonal::shared_ptr model
Definition: doc/Code/Pose2SLAMExample.cpp:7
g
void g(const string &key, int i)
Definition: testBTree.cpp:41
TestResult
Definition: TestResult.h:26
gtsam::b
const G & b
Definition: Group.h:79
gtsam::symbol_shorthand::I
Key I(std::uint64_t j)
Definition: inference/Symbol.h:156
gtsam
traits
Definition: chartTesting.h:28
gtsam::TEST
TEST(SmartFactorBase, Pinhole)
Definition: testSmartFactorBase.cpp:38
NonlinearFactorGraph.h
Factor Graph consisting of non-linear factors.
gtsam::FactorGraph::emplace_shared
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
Definition: FactorGraph.h:153
gtsam::BetweenFactor
Definition: BetweenFactor.h:40


gtsam
Author(s):
autogenerated on Thu Jun 13 2024 03:09:35