From b39cdf06958761f81f8dcbc5503d116245b0e74e Mon Sep 17 00:00:00 2001 From: Nora Buschauer Date: Thu, 18 Apr 2024 14:36:50 +0200 Subject: [PATCH] [IR] Adapt Cost of Initial Upper Bound to Cost used during Search During the Search we do not consider the cost for the final result. Currentlty this cost is condidered in the initial upper bound for cost-based pruning. To resolve this issue, we only consider the sum of the costs of the left and the right subplan as the initial upper bound. Adapt Test Cases to lower Initial Upper Bound for Pruning. --- src/IR/HeuristicSearchPlanEnumerator.cpp | 6 ++- .../IR/HeuristicSearchPlanEnumeratorTest.cpp | 39 ++++++++++--------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/IR/HeuristicSearchPlanEnumerator.cpp b/src/IR/HeuristicSearchPlanEnumerator.cpp index b24079b1..20d6383f 100644 --- a/src/IR/HeuristicSearchPlanEnumerator.cpp +++ b/src/IR/HeuristicSearchPlanEnumerator.cpp @@ -328,11 +328,13 @@ bool heuristic_search_helper(const char *vertex_str, const char *expand_str, con if (options::initialize_upper_bound) { config.upper_bound = [&]() { /*----- Run GOO to compute upper bound of plan cost. -----*/ + /* Obtain the sum of the costs of the left and the right subplan of the resulting plan. The costs + * considered for the search do not include the cardinality of the result set. */ GOO Goo; Goo(G, CF, PT); - auto &plan = PT.get_final(); + const auto &plan = PT.get_final(); M_insist(not plan.left.empty() and not plan.right.empty()); - return plan.cost; + return PT[plan.left].cost + PT[plan.right].cost; }(); } } else if (options::initialize_upper_bound) { diff --git a/unittest/IR/HeuristicSearchPlanEnumeratorTest.cpp b/unittest/IR/HeuristicSearchPlanEnumeratorTest.cpp index a69c25c5..c866823a 100644 --- a/unittest/IR/HeuristicSearchPlanEnumeratorTest.cpp +++ b/unittest/IR/HeuristicSearchPlanEnumeratorTest.cpp @@ -3400,7 +3400,8 @@ TEST_CASE("AnytimeAStar_BottomUp_and_TopDown_initial_upper_bound", "[core][IR]") /*----- Run GOO to compute upper bound of plan cost. -----*/ GOO Goo; Goo(G, C_out, plan_table); - return plan_table.get_final().cost; + const auto &plan = plan_table.get_final(); + return plan_table[plan.left].cost + plan_table[plan.right].cost; }(); @@ -3460,19 +3461,19 @@ TEST_CASE("AnytimeAStar_BottomUp_and_TopDown_initial_upper_bound", "[core][IR]") CHECK(State::NUM_STATES_GENERATED() == 6); CHECK(State::NUM_STATES_EXPANDED() == 1); CHECK(State::NUM_STATES_CONSTRUCTED() == 7); - CHECK(State::NUM_STATES_DISPOSED() == 1); + CHECK(State::NUM_STATES_DISPOSED() == 3); const auto &SM = S.state_manager(); - CHECK(SM.num_new() == 6); + CHECK(SM.num_new() == 4); CHECK(SM.num_duplicates() == 0); CHECK(SM.num_discarded() == 0); CHECK(SM.num_cheaper() == 0); CHECK(SM.num_decrease_key() == 0); - CHECK(SM.num_pruned_by_cost() == 1); + CHECK(SM.num_pruned_by_cost() == 3); - CHECK(SM.num_states_seen() == 6); - CHECK(SM.num_states_in_regular_queue() == 5); + CHECK(SM.num_states_seen() == 4); + CHECK(SM.num_states_in_regular_queue() == 3); CHECK(SM.num_states_in_beam_queue() == 0); CHECK(S.num_cached_heuristic_value() == 0); CHECK(SM.num_regular_to_beam() == 0); @@ -3528,19 +3529,19 @@ TEST_CASE("AnytimeAStar_BottomUp_and_TopDown_initial_upper_bound", "[core][IR]") CHECK(State::NUM_STATES_GENERATED() == 6); CHECK(State::NUM_STATES_EXPANDED() == 1); CHECK(State::NUM_STATES_CONSTRUCTED() == 7); - CHECK(State::NUM_STATES_DISPOSED() == 1); + CHECK(State::NUM_STATES_DISPOSED() == 3); const auto &SM = S.state_manager(); - CHECK(SM.num_new() == 6); + CHECK(SM.num_new() == 4); CHECK(SM.num_duplicates() == 0); CHECK(SM.num_discarded() == 0); CHECK(SM.num_cheaper() == 0); CHECK(SM.num_decrease_key() == 0); - CHECK(SM.num_pruned_by_cost() == 1); + CHECK(SM.num_pruned_by_cost() == 3); - CHECK(SM.num_states_seen() == 6); - CHECK(SM.num_states_in_regular_queue() == 5); + CHECK(SM.num_states_seen() == 4); + CHECK(SM.num_states_in_regular_queue() == 3); CHECK(SM.num_states_in_beam_queue() == 0); CHECK(S.num_cached_heuristic_value() == 0); CHECK(SM.num_regular_to_beam() == 0); @@ -3658,21 +3659,21 @@ TEST_CASE("AnytimeAStar_BottomUp_and_TopDown_initial_upper_bound", "[core][IR]") CHECK(State::NUM_STATES_GENERATED() == 11); CHECK(State::NUM_STATES_EXPANDED() == 4); CHECK(State::NUM_STATES_CONSTRUCTED() == 12); - CHECK(State::NUM_STATES_DISPOSED() == 3); + CHECK(State::NUM_STATES_DISPOSED() == 5); const auto &SM = S.state_manager(); - CHECK(SM.num_new() == 9); - CHECK(SM.num_duplicates() == 1); - CHECK(SM.num_discarded() == 1); + CHECK(SM.num_new() == 7); + CHECK(SM.num_duplicates() == 0); + CHECK(SM.num_discarded() == 0); CHECK(SM.num_cheaper() == 0); CHECK(SM.num_decrease_key() == 0); - CHECK(SM.num_pruned_by_cost() == 2); + CHECK(SM.num_pruned_by_cost() == 5); - CHECK(SM.num_states_seen() == 9); - CHECK(SM.num_states_in_regular_queue() == 4); + CHECK(SM.num_states_seen() == 7); + CHECK(SM.num_states_in_regular_queue() == 2); CHECK(SM.num_states_in_beam_queue() == 0); - CHECK(S.num_cached_heuristic_value() == 1); + CHECK(S.num_cached_heuristic_value() == 0); CHECK(SM.num_regular_to_beam() == 0); CHECK(SM.num_none_to_beam() == 0); }