From 5e29bc5b6754cc2bd6292e5b61b66d01323fc4b8 Mon Sep 17 00:00:00 2001 From: Andrew Melim Date: Sat, 26 Oct 2013 22:22:31 +0000 Subject: [PATCH] Return set partitions from DFSMap --- .cproject | 32 ++++-------------------- gtsam_unstable/base/DSFMap.h | 13 ++++++++++ gtsam_unstable/base/tests/testDSFMap.cpp | 31 +++++++++++++++++++++-- wrap/Module.cpp | 6 ++++- wrap/Module.h | 5 ++++ 5 files changed, 57 insertions(+), 30 deletions(-) diff --git a/.cproject b/.cproject index 36f003997..aa3744e5d 100644 --- a/.cproject +++ b/.cproject @@ -1,17 +1,11 @@ - - - + - - + + - - - - - + @@ -122,9 +116,6 @@ - - - @@ -171,23 +162,10 @@ - - - - - - - - - - - - - - + diff --git a/gtsam_unstable/base/DSFMap.h b/gtsam_unstable/base/DSFMap.h index 14b69f8c7..c9a1293f7 100644 --- a/gtsam_unstable/base/DSFMap.h +++ b/gtsam_unstable/base/DSFMap.h @@ -19,6 +19,9 @@ #pragma once #include +#include +#include + namespace gtsam { @@ -32,6 +35,8 @@ class DSFMap { /// We store the forest in an STL map typedef std::map Map; + typedef std::set Set; + typedef std::pair key_pair; mutable Map parent_; public: @@ -60,6 +65,14 @@ public: parent_[find(i2)] = find(i1); } + /// return all sets, i.e. a partition of all elements + std::map sets() const { + std::map sets; + BOOST_FOREACH(const key_pair& pair, parent_) + sets[find(pair.second)].insert(pair.first); + return sets; + } + }; } diff --git a/gtsam_unstable/base/tests/testDSFMap.cpp b/gtsam_unstable/base/tests/testDSFMap.cpp index 121bd50d0..23dd2a110 100644 --- a/gtsam_unstable/base/tests/testDSFMap.cpp +++ b/gtsam_unstable/base/tests/testDSFMap.cpp @@ -20,12 +20,12 @@ #include #include -//#include +#include using namespace boost::assign; // #include // -//#include +#include using namespace std; using namespace gtsam; @@ -115,7 +115,34 @@ TEST(DSFMap, mergePairwiseMatches2) { EXPECT(dsf.find(m25)==m14); EXPECT(dsf.find(m26)==m14); } +/* ************************************************************************* */ +TEST(DSFMap, sets){ + // Create some "matches" + typedef pair Match; + typedef pair > key_pair; + list matches; + matches += Match(1,2), Match(2,3), Match(4,5), Match(4,6); + // Merge matches + DSFMap dsf; + BOOST_FOREACH(const Match& m, matches) + dsf.merge(m.first,m.second); + + map > sets = dsf.sets(); + set s1, s2; + s1 += 1,2,3; + s2 += 4,5,6; + + /*BOOST_FOREACH(key_pair st, sets){ + cout << "Set " << st.first << " :{"; + BOOST_FOREACH(const size_t s, st.second) + cout << s << ", "; + cout << "}" << endl; + }*/ + + EXPECT(s1 == sets[1]); + EXPECT(s2 == sets[4]); +} /* ************************************************************************* */ int main() { TestResult tr; return TestRegistry::runAllTests(tr);} /* ************************************************************************* */ diff --git a/wrap/Module.cpp b/wrap/Module.cpp index e6c86a741..74003e277 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -20,7 +20,7 @@ #include "Module.h" #include "FileWriter.h" #include "TypeAttributesTable.h" -#include "utilities.h" +#include "utilities.h" //#define BOOST_SPIRIT_DEBUG #include "spirit_actors.h" @@ -457,6 +457,10 @@ void Module::generateIncludes(FileWriter& file) const { file.oss << "#include <" << *it << ">" << endl; file.oss << "\n"; } + +/* ************************************************************************* */ +void Module::python_code(const string& toolboxPath, const string& headerPath) const { +} /* ************************************************************************* */ void Module::matlab_code(const string& toolboxPath, const string& headerPath) const { diff --git a/wrap/Module.h b/wrap/Module.h index 93f699e14..c5344b67a 100644 --- a/wrap/Module.h +++ b/wrap/Module.h @@ -61,6 +61,11 @@ struct Module { const std::string& path, const std::string& headerPath) const; // FIXME: headerPath not actually used? + /// Python code generation: + void python_code( + const std::string& path, + const std::string& headerPath) const; // FIXME: headerPath not actually used? + void finish_wrapper(FileWriter& file, const std::vector& functionNames) const; void generateIncludes(FileWriter& file) const;