From 55e85fd8a55dd0657b36f884725e01b6723f04b5 Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Fri, 20 Nov 2009 05:14:34 +0000 Subject: [PATCH] [involves] checks whether variable with that key is involved in any factor --- cpp/FactorGraph.h | 5 +++++ cpp/testGaussianFactorGraph.cpp | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/cpp/FactorGraph.h b/cpp/FactorGraph.h index 8fcd183ec..f8802e302 100644 --- a/cpp/FactorGraph.h +++ b/cpp/FactorGraph.h @@ -92,6 +92,11 @@ namespace gtsam { /** return keys in some random order */ Ordering keys() const; + /** Check whether a factor with this variable exists */ + bool involves(const std::string& key) { + return !(indices_.find(key)==indices_.end()); + } + /** * Compute colamd ordering */ diff --git a/cpp/testGaussianFactorGraph.cpp b/cpp/testGaussianFactorGraph.cpp index c19ba6aa4..3e0535388 100644 --- a/cpp/testGaussianFactorGraph.cpp +++ b/cpp/testGaussianFactorGraph.cpp @@ -527,6 +527,16 @@ TEST( GaussianFactorGraph, keys ) CHECK(assert_equal(expected,fg.keys())); } +/* ************************************************************************* */ +TEST( GaussianFactorGraph, involves ) +{ + GaussianFactorGraph fg = createGaussianFactorGraph(); + CHECK(fg.involves("l1")); + CHECK(fg.involves("x1")); + CHECK(fg.involves("x2")); + CHECK(!fg.involves("x3")); +} + /* ************************************************************************* */ // Tests ported from ConstrainedGaussianFactorGraph /* ************************************************************************* */