src/drop.cpp
/**
 * This is an impl. of a "drop" heuristic in which a market is dropped from the
 * tour as soon as the decrease in traveling costs is greater than the increase
 * in purchase costs.
 *
 * The 'solution' is modified in place if an improvement is found.
 *
 * Returns a change in total solution cost, i.e. improvement.
 *
 * The complexity is O(M^2 * K) for the U-TPP but if no market is
 * dropped it will perform only O(M * max(K, M)) operations.
 */
This is an impl. of a "drop" heuristic in which a market is dropped from the
tour as soon as the decrease in traveling costs is greater than the increase
in purchase costs.

The 'solution' is modified in place if an improvement is found.

Returns a change in total solution cost, i.e. improvement.

The complexity is O(M^2 * K) for the U-TPP but if no market is
dropped it will perform only O(M * max(K, M)) operations.
This is an impl . of a " drop " heuristic in which a market is dropped from the tour as soon as the decrease in traveling costs is greater than the increase in purchase costs . The ' solution ' is modified in place if an improvement is found . Returns a change in total solution cost i . e . improvement . The complexity is O ( M^2 * K ) for the U - TPP but if no market is dropped it will perform only O ( M * max ( K M )) operations .
int drop_heuristic(const TPP::Instance &instance, TPP::Solution &solution) {
    const auto start_cost = solution.cost_;
    auto solution_changed = false;
    for (auto i = 1u; i < solution.route_.size(); ++i) {
        const auto market_id = solution.route_.at(i);
        const auto after = solution.calc_market_removal_cost(market_id,
                true);
        if (after.demand_satisfied_ && after.cost_change_ < 0) {
            solution.remove_market_at_pos(i);
            solution_changed = true;
            --i;
        }
    }
    if (solution_changed) {
        CHECK_F(is_solution_valid(instance, solution.route_),
                "Sol. should be valid");
    }
    return solution.cost_ - start_cost;
}
int drop_heuristic ( const TPP :: Instance & instance , TPP :: Solution & solution ) { const auto start_cost = solution . cost_ ; auto solution_changed = false ; for ( auto i = 1u ; i < solution . route_ . size ( ) ; ++ i ) { const auto market_id = solution . route_ . at ( i ) ; const auto after = solution . calc_market_removal_cost ( market_id , true ) ; if ( after . demand_satisfied_ && after . cost_change_ < 0 ) { solution . remove_market_at_pos ( i ) ; solution_changed = true ; -- i ; } } if ( solution_changed ) { CHECK_F ( is_solution_valid ( instance , solution . route_ ) , " " ) ; } return solution . cost_ - start_cost ; }
This is an impl.
This is an impl .
//LOG_SCOPE_F(INFO, "drop_heuristic"); /*validity_required=*/