From 4f21c68409bc478c431a9b6aedf9e5cfdf11d2f3 Mon Sep 17 00:00:00 2001 From: Sameer Agarwal Date: Sun, 6 May 2012 15:33:47 -0700 Subject: [PATCH] Fix the struct weak ordering used by independent set ordering, tests for it --- internal/ceres/graph_algorithms.h | 2 +- internal/ceres/graph_algorithms_test.cc | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/internal/ceres/graph_algorithms.h b/internal/ceres/graph_algorithms.h index cb9913acf..e83531d50 100644 --- a/internal/ceres/graph_algorithms.h +++ b/internal/ceres/graph_algorithms.h @@ -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()); } diff --git a/internal/ceres/graph_algorithms_test.cc b/internal/ceres/graph_algorithms_test.cc index bce018381..a67d7b7c3 100644 --- a/internal/ceres/graph_algorithms_test.cc +++ b/internal/ceres/graph_algorithms_test.cc @@ -165,5 +165,29 @@ TEST(Degree2MaximumSpanningForest, StarGraph) { } } +TEST(VertexDegreeLessThan, TotalOrdering) { + Graph 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 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