Changed signature of tree insert
parent
f645b560ea
commit
53a03a0021
|
@ -288,7 +288,7 @@ PredecessorMap<Key> FactorGraph<Factor>::findMinimumSpanningTree() const {
|
||||||
string key = boost::get(boost::vertex_name, g, *itVertex);
|
string key = boost::get(boost::vertex_name, g, *itVertex);
|
||||||
string parent = boost::get(boost::vertex_name, g, *vi);
|
string parent = boost::get(boost::vertex_name, g, *vi);
|
||||||
// printf("%s parent: %s\n", key.c_str(), parent.c_str());
|
// printf("%s parent: %s\n", key.c_str(), parent.c_str());
|
||||||
tree.insert(make_pair(key, parent));
|
tree.insert(key, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tree;
|
return tree;
|
||||||
|
|
10
cpp/graph.h
10
cpp/graph.h
|
@ -40,8 +40,14 @@ namespace gtsam {
|
||||||
/**
|
/**
|
||||||
* Map from variable key to parent key
|
* Map from variable key to parent key
|
||||||
*/
|
*/
|
||||||
template <class Key>
|
template<class Key>
|
||||||
class PredecessorMap : public std::map<Key,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
|
* Convert the factor graph to an SDGraph
|
||||||
|
|
|
@ -29,9 +29,9 @@ TEST( Graph, predecessorMap2Graph )
|
||||||
map<string, SVertex> key2vertex;
|
map<string, SVertex> key2vertex;
|
||||||
|
|
||||||
PredecessorMap<string> p_map;
|
PredecessorMap<string> p_map;
|
||||||
p_map.insert(make_pair("x1", "x2"));
|
p_map.insert("x1", "x2");
|
||||||
p_map.insert(make_pair("x2", "x2"));
|
p_map.insert("x2", "x2");
|
||||||
p_map.insert(make_pair("x3", "x2"));
|
p_map.insert("x3", "x2");
|
||||||
tie(graph, root, key2vertex) = predecessorMap2Graph<SGraph<string>, SVertex, string>(p_map);
|
tie(graph, root, key2vertex) = predecessorMap2Graph<SGraph<string>, SVertex, string>(p_map);
|
||||||
|
|
||||||
LONGS_EQUAL(3, boost::num_vertices(graph));
|
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)));
|
graph.push_back(boost::shared_ptr<Pose2Factor>(new Pose2Factor(2,3, Pose2(3.0, 0.0, 0.0), cov)));
|
||||||
|
|
||||||
PredecessorMap<Pose2Config::Key> tree;
|
PredecessorMap<Pose2Config::Key> tree;
|
||||||
tree.insert(make_pair(1,2));
|
tree.insert(1,2);
|
||||||
tree.insert(make_pair(2,2));
|
tree.insert(2,2);
|
||||||
tree.insert(make_pair(3,2));
|
tree.insert(3,2);
|
||||||
|
|
||||||
Pose2 rootPose(3.0, 0.0, 0.0);
|
Pose2 rootPose(3.0, 0.0, 0.0);
|
||||||
|
|
||||||
|
|
|
@ -20,14 +20,14 @@ using namespace boost::assign;
|
||||||
TEST ( Ordering, predecessorMap2Keys ) {
|
TEST ( Ordering, predecessorMap2Keys ) {
|
||||||
typedef Symbol<Pose2,'x'> Key;
|
typedef Symbol<Pose2,'x'> Key;
|
||||||
PredecessorMap<Key> p_map;
|
PredecessorMap<Key> p_map;
|
||||||
p_map.insert(make_pair(Key(1), Key(1)));
|
p_map.insert(1,1);
|
||||||
p_map.insert(make_pair(Key(2), Key(1)));
|
p_map.insert(2,1);
|
||||||
p_map.insert(make_pair(Key(3), Key(1)));
|
p_map.insert(3,1);
|
||||||
p_map.insert(make_pair(Key(4), Key(3)));
|
p_map.insert(4,3);
|
||||||
p_map.insert(make_pair(Key(5), Key(1)));
|
p_map.insert(5,1);
|
||||||
|
|
||||||
list<Key> expected;
|
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);
|
list<Key> actual = predecessorMap2Keys<Key>(p_map);
|
||||||
LONGS_EQUAL(expected.size(), actual.size());
|
LONGS_EQUAL(expected.size(), actual.size());
|
||||||
|
|
Loading…
Reference in New Issue