From 48435078ec6d6e3467e3908aed16adbdd023070f Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Wed, 17 Jul 2024 11:29:21 +0200 Subject: [PATCH] format fix --- ortools/algorithms/adjustable_k_ary_heap.h | 5 ++--- ortools/algorithms/adjustable_k_ary_heap_test.cc | 1 - ortools/algorithms/set_cover_heuristics.cc | 7 ++++++- ortools/algorithms/set_cover_heuristics.h | 1 - ortools/algorithms/set_cover_model.cc | 1 + ortools/algorithms/set_cover_orlib_test.cc | 2 +- ortools/base/mathutil.cc | 4 ++-- tools/cross_compile.sh | 1 - 8 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ortools/algorithms/adjustable_k_ary_heap.h b/ortools/algorithms/adjustable_k_ary_heap.h index ba1e9af3bc..48b01152f7 100644 --- a/ortools/algorithms/adjustable_k_ary_heap.h +++ b/ortools/algorithms/adjustable_k_ary_heap.h @@ -169,6 +169,7 @@ class AdjustableKAryHeap { bool Contains(Index index) const { return GetHeapPosition(index) != kNonExistent; } + // Checks that the heap is well-formed. bool CheckHeapProperty() const { for (HeapIndex i = heap_size() - 1; i >= Arity; --i) { @@ -254,7 +255,6 @@ class AdjustableKAryHeap { std::swap(heap_positions_[index(i)], heap_positions_[index(j)]); } - // Compares two elements based on whether we are dealing with a min- or a // max-heap. Returns true if (data indexed by) i has more priority // than j. Note that we only use operator::<. @@ -262,7 +262,6 @@ class AdjustableKAryHeap { return IsMaxHeap ? data_[j] < data_[i] : data_[i] < data_[j]; } - // Since Arity is a (small) constant, we expect compilers to avoid // multiplication instructions and use LEA instructions or a combination // of shifts and arithmetic operations. @@ -281,7 +280,6 @@ class AdjustableKAryHeap { // Gets the parent index of a given index. HeapIndex Parent(HeapIndex index) const { return (index - 1) / Arity; } - // Returns the index of the element at position i in the heap. Index index(HeapIndex i) const { return data_[i].second; } @@ -306,6 +304,7 @@ class AdjustableKAryHeap { // either when removing an element (which is not removed from data_), or // adding a new one. HeapIndex heap_size_ = 0; + // The index for Aggregates not in the heap. const Index kNonExistent = -1; }; diff --git a/ortools/algorithms/adjustable_k_ary_heap_test.cc b/ortools/algorithms/adjustable_k_ary_heap_test.cc index bc6e13e500..e9e861f2cc 100644 --- a/ortools/algorithms/adjustable_k_ary_heap_test.cc +++ b/ortools/algorithms/adjustable_k_ary_heap_test.cc @@ -23,7 +23,6 @@ namespace operations_research { - TEST(AdjustableKAryHeapTest, RandomDataStrongCheck) { const int kSize = 10'000; const double priority_range = kSize / 100; diff --git a/ortools/algorithms/set_cover_heuristics.cc b/ortools/algorithms/set_cover_heuristics.cc index cafa38f334..63c7fe3066 100644 --- a/ortools/algorithms/set_cover_heuristics.cc +++ b/ortools/algorithms/set_cover_heuristics.cc @@ -477,16 +477,17 @@ bool GuidedLocalSearch::NextSolution(absl::Span focus, inv_->MakeFullyUpdated(); Cost best_cost = inv_->cost(); SubsetBoolVector best_choices = inv_->is_selected(); + for (const SubsetIndex& subset : focus) { const float delta = ComputeDelta(subset); if (delta < kInfinity) { priority_heap_.Insert({delta, subset.value()}); } } + for (int iteration = 0; iteration < num_iterations; ++iteration) { // Improve current solution respective to the current penalties. const SubsetIndex best_subset(priority_heap_.TopIndex()); - if (inv_->is_selected()[best_subset]) { utility_heap_.Insert({0, best_subset.value()}); } else { @@ -512,23 +513,27 @@ bool GuidedLocalSearch::NextSolution(absl::Span focus, inv_->model()->subset_costs()[subset]); priority_heap_.Insert({delta_selected, subset.value()}); } + for (const SubsetIndex subset : {penalized_subset, best_subset}) { const float delta = ComputeDelta(subset); if (delta < kInfinity) { priority_heap_.Insert({delta, subset.value()}); } } + // Get new non removable subsets. // (Delete them from the heap) for (const SubsetIndex subset : inv_->new_non_removable_subsets()) { priority_heap_.Remove(subset.value()); } + if (inv_->cost() < best_cost) { best_cost = inv_->cost(); best_choices = inv_->is_selected(); } } inv_->LoadSolution(best_choices); + // Improve the solution by removing redundant subsets. for (const SubsetIndex& subset : focus) { if (inv_->is_selected()[subset] && inv_->ComputeIsRedundant(subset)) diff --git a/ortools/algorithms/set_cover_heuristics.h b/ortools/algorithms/set_cover_heuristics.h index cbffd2565b..70c2bc85cc 100644 --- a/ortools/algorithms/set_cover_heuristics.h +++ b/ortools/algorithms/set_cover_heuristics.h @@ -497,7 +497,6 @@ std::vector ClearMostCoveredElements(std::size_t num_subsets, std::vector ClearMostCoveredElements( absl::Span focus, std::size_t num_subsets, SetCoverInvariant* inv); - } // namespace operations_research #endif // OR_TOOLS_ALGORITHMS_SET_COVER_HEURISTICS_H_ diff --git a/ortools/algorithms/set_cover_model.cc b/ortools/algorithms/set_cover_model.cc index 1f2ec33389..6164d4b07c 100644 --- a/ortools/algorithms/set_cover_model.cc +++ b/ortools/algorithms/set_cover_model.cc @@ -248,6 +248,7 @@ std::vector ComputeDeciles(std::vector values) { return deciles; } } // namespace + SetCoverModel::Stats SetCoverModel::ComputeCostStats() { std::vector subset_costs(num_subsets()); std::copy(subset_costs_.begin(), subset_costs_.end(), subset_costs.begin()); diff --git a/ortools/algorithms/set_cover_orlib_test.cc b/ortools/algorithms/set_cover_orlib_test.cc index 03bbd7499e..604408513f 100644 --- a/ortools/algorithms/set_cover_orlib_test.cc +++ b/ortools/algorithms/set_cover_orlib_test.cc @@ -59,6 +59,7 @@ void LogCostAndTiming(std::string name, std::string algo, double cost, LOG(INFO) << ", " << name << ", " << algo << "_cost, " << cost << ", " << absl::ToInt64Microseconds(duration) << "e-6, s"; } + SetCoverInvariant RunChvatalAndSteepest(std::string name, SetCoverModel* model) { SetCoverInvariant inv(model); @@ -361,7 +362,6 @@ SCP_TEST("scpnrh5.txt", 55, 62, FEWTENTHS); #endif #ifdef EXTRA_SCP - SCP_TEST("scpclr10.txt", 0, 32, FEWMILLIS); SCP_TEST("scpclr11.txt", 0, 30, FEWMILLIS); SCP_TEST("scpclr12.txt", 0, 31, FEWMILLIS); diff --git a/ortools/base/mathutil.cc b/ortools/base/mathutil.cc index 0840b45f47..254bfccf65 100644 --- a/ortools/base/mathutil.cc +++ b/ortools/base/mathutil.cc @@ -10,14 +10,14 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + #if defined(_MSC_VER) #define _USE_MATH_DEFINES #include #endif -#include "ortools/base/mathutil.h" - #include "ortools/base/logging.h" +#include "ortools/base/mathutil.h" namespace operations_research { diff --git a/tools/cross_compile.sh b/tools/cross_compile.sh index c0f4307121..2325fe923e 100755 --- a/tools/cross_compile.sh +++ b/tools/cross_compile.sh @@ -446,7 +446,6 @@ function main() { expand_bootlin_config declare -r QEMU_ARCH=ppc64le ;; - riscv64) expand_bootlin_config declare -r QEMU_ARCH=riscv64 ;;