Changed signature of tree insert

release/4.3a0
Frank Dellaert 2010-01-14 16:05:04 +00:00
parent f645b560ea
commit 53a03a0021
4 changed files with 21 additions and 15 deletions

View File

@ -288,7 +288,7 @@ PredecessorMap<Key> FactorGraph<Factor>::findMinimumSpanningTree() const {
string key = boost::get(boost::vertex_name, g, *itVertex);
string parent = boost::get(boost::vertex_name, g, *vi);
// printf("%s parent: %s\n", key.c_str(), parent.c_str());
tree.insert(make_pair(key, parent));
tree.insert(key, parent);
}
return tree;

View File

@ -40,8 +40,14 @@ namespace gtsam {
/**
* Map from variable key to parent key
*/
template <class Key>
class PredecessorMap : public std::map<Key,Key> {};
template<class Key>
class PredecessorMap: public std::map<Key, Key> {
public:
/** convenience insert so we can pass ints for Symbol keys */
inline void insert(const Key& key, const Key& parent) {
std::map<Key, Key>::insert(std::make_pair(key, parent));
}
};
/**
* Convert the factor graph to an SDGraph

View File

@ -29,9 +29,9 @@ TEST( Graph, predecessorMap2Graph )
map<string, SVertex> key2vertex;
PredecessorMap<string> p_map;
p_map.insert(make_pair("x1", "x2"));
p_map.insert(make_pair("x2", "x2"));
p_map.insert(make_pair("x3", "x2"));
p_map.insert("x1", "x2");
p_map.insert("x2", "x2");
p_map.insert("x3", "x2");
tie(graph, root, key2vertex) = predecessorMap2Graph<SGraph<string>, SVertex, string>(p_map);
LONGS_EQUAL(3, boost::num_vertices(graph));
@ -47,9 +47,9 @@ TEST( Graph, composePoses )
graph.push_back(boost::shared_ptr<Pose2Factor>(new Pose2Factor(2,3, Pose2(3.0, 0.0, 0.0), cov)));
PredecessorMap<Pose2Config::Key> tree;
tree.insert(make_pair(1,2));
tree.insert(make_pair(2,2));
tree.insert(make_pair(3,2));
tree.insert(1,2);
tree.insert(2,2);
tree.insert(3,2);
Pose2 rootPose(3.0, 0.0, 0.0);

View File

@ -20,14 +20,14 @@ using namespace boost::assign;
TEST ( Ordering, predecessorMap2Keys ) {
typedef Symbol<Pose2,'x'> Key;
PredecessorMap<Key> p_map;
p_map.insert(make_pair(Key(1), Key(1)));
p_map.insert(make_pair(Key(2), Key(1)));
p_map.insert(make_pair(Key(3), Key(1)));
p_map.insert(make_pair(Key(4), Key(3)));
p_map.insert(make_pair(Key(5), Key(1)));
p_map.insert(1,1);
p_map.insert(2,1);
p_map.insert(3,1);
p_map.insert(4,3);
p_map.insert(5,1);
list<Key> expected;
expected += Key(4), Key(5), Key(3), Key(2), Key(1);
expected += 4,5,3,2,1;//Key(4), Key(5), Key(3), Key(2), Key(1);
list<Key> actual = predecessorMap2Keys<Key>(p_map);
LONGS_EQUAL(expected.size(), actual.size());