src/tpp.cpp
/**
 * Returns true if route represents a valid TPP solution, based on the data in
 * instance.
*/
Returns true if route represents a valid TPP solution, based on the data in
instance.
Returns true if route represents a valid TPP solution based on the data in instance .
bool TPP::is_solution_valid(const Instance& instance,
                            const vector<uint32_t> &route) {
    if (route.size() > instance.dimension_) {
        LOG_F(INFO, "route too long: %zu", route.size());
        return false;
    }
    if (route.at(0) != 0) {
        LOG_F(INFO, "First node should be 0 (depot), not : %zu", route[0]);
        return false;
    }
    vector<int> product_quantities;
    product_quantities.resize(instance.product_count_);
    for (const auto node : route) {
        for (const auto &offer : instance.market_offers_.at(node)) {
            auto id = offer.product_id_;
            product_quantities.at(id) += offer.quantity_;
        }
    }
    for (auto i = 0ul, n = instance.demands_.size(); i < n; ++i) {
        if (product_quantities.at(i) < instance.demands_[i]) {
            LOG_F(INFO, "Product %zu quantity %d too small, required: %d", i,
                  product_quantities[i], instance.demands_[i]);
            return false;
        }
    }
    return true;
}
bool TPP :: is_solution_valid ( const Instance & instance , const vector < uint32_t > & route ) { if ( route . size ( ) > instance . dimension_ ) { LOG_F ( INFO , " " , route . size ( ) ) ; return false ; } if ( route . at ( 0 ) != 0 ) { LOG_F ( INFO , " " , route [ 0 ] ) ; return false ; } vector < int > product_quantities ; product_quantities . resize ( instance . product_count_ ) ; for ( const auto node : route ) { for ( const auto & offer : instance . market_offers_ . at ( node ) ) { auto id = offer . product_id_ ; product_quantities . at ( id ) += offer . quantity_ ; } } for ( auto i = 0ul , n = instance . demands_ . size ( ) ; i < n ; ++ i ) { if ( product_quantities . at ( i ) < instance . demands_ [ i ] ) { LOG_F ( INFO , " " , i , product_quantities [ i ] , instance . demands_ [ i ] ) ; return false ; } } return true ; }
Returns true if route represents a valid TPP solution, based on the data in
 instance.
Returns true if route represents a valid TPP solution based on the data in instance .
// A sum of product quantities available at visitied markets