mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-29 08:34:37 +08:00
Fix the struct weak ordering used by independent set ordering, tests for it
This commit is contained in:
@@ -50,7 +50,7 @@ class VertexDegreeLessThan {
|
||||
|
||||
bool operator()(const Vertex& lhs, const Vertex& rhs) const {
|
||||
if (graph_.Neighbors(lhs).size() == graph_.Neighbors(rhs).size()) {
|
||||
return lhs->user_state() < rhs->user_state();
|
||||
return (lhs < rhs);
|
||||
}
|
||||
return (graph_.Neighbors(lhs).size() < graph_.Neighbors(rhs).size());
|
||||
}
|
||||
|
||||
@@ -165,5 +165,29 @@ TEST(Degree2MaximumSpanningForest, StarGraph) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(VertexDegreeLessThan, TotalOrdering) {
|
||||
Graph<int> graph;
|
||||
graph.AddVertex(0);
|
||||
graph.AddVertex(1);
|
||||
graph.AddVertex(2);
|
||||
graph.AddVertex(3);
|
||||
|
||||
// 0-1 2-3
|
||||
// All vertices have degree 1.
|
||||
graph.AddEdge(0, 1, 1.0);
|
||||
graph.AddEdge(2, 3, 1.0);
|
||||
VertexDegreeLessThan<int> less_than(graph);
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
EXPECT_FALSE(less_than(i,i))
|
||||
<< "Failing vertex: " << i;
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
if (i != j) {
|
||||
EXPECT_TRUE(less_than(i,j) ^ less_than(j,i))
|
||||
<< "Failing vertex pair: " << i << " " << j;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace internal
|
||||
} // namespace ceres
|
||||
|
||||
Reference in New Issue
Block a user