This commit is contained in:
Corentin Le Molgat
2024-04-26 11:47:08 +02:00
parent aac7ad8ebd
commit 8509c728e2
4 changed files with 34 additions and 4 deletions

View File

@@ -186,7 +186,11 @@ class AdjustableKAryHeap {
if (heap_index >= heap_size()) return false;
PerformSwap(heap_index, heap_size() - 1);
--heap_size_;
SiftDown(heap_index);
if (HasPriority(heap_index, Parent(heap_index))) {
SiftUp(heap_index);
} else {
SiftDown(heap_index);
}
return true;
}

View File

@@ -110,6 +110,27 @@ TEST(AdjustableKAryHeapTest, UpdateStrongCheck) {
}
}
TEST(AdjustableKAryHeapTest, RemoveStrongCheck) {
const int kSize = 10'000;
const int kNumRemovals = kSize;
const double priority_range = kSize / 10;
std::random_device rd;
std::mt19937 generator(rd()); // Mersenne Twister generator
std::uniform_real_distribution<float> priority_dist(0, priority_range);
std::uniform_int_distribution<int> index_dist(0, kSize);
std::vector<PriorityAggregate> subsets_and_values(kSize);
for (int i = 0; i < kSize; ++i) {
subsets_and_values[i] = {priority_dist(generator), i};
}
AdjustableKAryHeap<PriorityAggregate, 4, true> heap(subsets_and_values,
kSize);
EXPECT_TRUE(heap.CheckHeapProperty());
for (int iter = 0; iter < kNumRemovals; ++iter) {
heap.Remove(iter);
EXPECT_TRUE(heap.CheckHeapProperty());
}
}
TEST(AdjustableKAryHeapTest, OneByOneStrongCheck) {
const int kSize = 10'000;
const int kNumInsertions = kSize;

View File

@@ -14,7 +14,12 @@
#ifndef OR_TOOLS_ALGORITHMS_SET_COVER_MODEL_H_
#define OR_TOOLS_ALGORITHMS_SET_COVER_MODEL_H_
#if defined(_MSC_VER)
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#else
#include <sys/types.h>
#endif // defined(_MSC_VER)
#include <string>
#include <vector>

View File

@@ -285,9 +285,9 @@ class MyMPCallback : public MPCallback {
MyMPCallback(MPSolver* mpSolver, bool should_throw)
: MPCallback(false, false),
mpSolver_(mpSolver),
should_throw_(should_throw){};
should_throw_(should_throw) {};
~MyMPCallback() override{};
~MyMPCallback() override {};
void RunCallback(MPCallbackContext* callback_context) override {
if (should_throw_) {
@@ -1354,8 +1354,8 @@ TEST_F(XpressFixtureMIP, CallbackThrowsException) {
} // namespace operations_research
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
absl::SetFlag(&FLAGS_stderrthreshold, 0);
testing::InitGoogleTest(&argc, argv);
auto solver = operations_research::MPSolver::CreateSolver("XPRESS_LP");
if (solver == nullptr) {
LOG(ERROR) << "Xpress solver is not available";