src/drop.cpp
/**
 * Insertion heuristic tries to insert a new market into the route if the
 * increase in travel cost is lower than the decrease in purchase costs.
 */
Insertion heuristic tries to insert a new market into the route if the
increase in travel cost is lower than the decrease in purchase costs.
Insertion heuristic tries to insert a new market into the route if the increase in travel cost is lower than the decrease in purchase costs .
int insertion_heuristic(const TPP::Instance &instance, TPP::Solution &solution) {
    LOG_SCOPE_F(INFO, "insertion_heuristic");
    auto &route = solution.route_;
    auto total_cost_change = 0;
    const auto &candidates = solution.get_unselected_markets();
    auto solution_changed = false;
    for (auto cand : candidates) {
        const auto verdict = solution.calc_market_add_cost(cand);
        if (verdict.cost_change_ <= 0) {
            const auto prev_cost = solution.cost_;
            total_cost_change += verdict.cost_change_;
            solution.insert_market_at_pos(cand, verdict.index_);
            CHECK_F(prev_cost + verdict.cost_change_ == solution.cost_,
                    "Updated cost should be OK, %d", solution.cost_);
            solution_changed = true;
        }
    }
    if (solution_changed) {
        CHECK_F(is_solution_valid(instance, route),
                "Sol. should be valid");
    }
    LOG_F(INFO, "Total cost change: %d", total_cost_change);
    LOG_F(INFO, "New sol. cost: %d", solution.cost_);
    return total_cost_change;
}
int insertion_heuristic ( const TPP :: Instance & instance , TPP :: Solution & solution ) { LOG_SCOPE_F ( INFO , " " ) ; auto & route = solution . route_ ; auto total_cost_change = 0 ; const auto & candidates = solution . get_unselected_markets ( ) ; auto solution_changed = false ; for ( auto cand : candidates ) { const auto verdict = solution . calc_market_add_cost ( cand ) ; if ( verdict . cost_change_ <= 0 ) { const auto prev_cost = solution . cost_ ; total_cost_change += verdict . cost_change_ ; solution . insert_market_at_pos ( cand , verdict . index_ ) ; CHECK_F ( prev_cost + verdict . cost_change_ == solution . cost_ , " " , solution . cost_ ) ; solution_changed = true ; } } if ( solution_changed ) { CHECK_F ( is_solution_valid ( instance , route ) , " " ) ; } LOG_F ( INFO , " " , total_cost_change ) ; LOG_F ( INFO , " " , solution . cost_ ) ; return total_cost_change ; }
Insertion heuristic tries to insert a new market into the route if the
 increase in travel cost is lower than the decrease in purchase costs.
Insertion heuristic tries to insert a new market into the route if the increase in travel cost is lower than the decrease in purchase costs .
//LOG_F(INFO, "Cost of adding %zu is %d at pos %zu", //cand, verdict.first, //verdict.second);