src/tpp.cpp
/*
 * Reads exactly market_count product offers from file.
 */
Reads exactly market_count product offers from file.
Reads exactly market_count product offers from file .
vector<vector<ProductOffer>>
read_offer_section(ifstream &file, size_t market_count) {
    vector<vector<ProductOffer>> market_offers;
    market_offers.resize(market_count);
    LOG_SCOPE_F(INFO, "read_offer_section");
    for (auto i = 0u; i < market_count; ++i) {
        string line;
        if (!getline(file, line, '\n')) {
            LOG_F(ERROR, "Too few lines in offer section");
            abort();
        }
        auto iss = istringstream(line);
        int market_id{ 0 };
        size_t offer_count{ 0 };
        iss >> market_id >> offer_count;
        assert(market_id == static_cast<int>(i + 1));
        auto &offers = market_offers.at(i);
        for (auto j = 0u; j < offer_count; ++j) {
            ProductOffer offer;
            iss >> offer.product_id_ >> offer.price_ >> offer.quantity_;
            --offer.product_id_;  
            offer.market_id_ = i;
            offers.emplace_back(offer);
            CHECK_F(offer.price_ >= 0, "Price should be >= 0");
            CHECK_F(offer.quantity_ > 0, "Quantity should be > 0");
        }
    }
    return market_offers;
}
vector < vector < ProductOffer > > read_offer_section ( ifstream & file , size_t market_count ) { vector < vector < ProductOffer > > market_offers ; market_offers . resize ( market_count ) ; LOG_SCOPE_F ( INFO , " " ) ; for ( auto i = 0u ; i < market_count ; ++ i ) { string line ; if ( ! getline ( file , line , ' \n ' ) ) { LOG_F ( ERROR , " " ) ; abort ( ) ; } auto iss = istringstream ( line ) ; int market_id { 0 } ; size_t offer_count { 0 } ; iss >> market_id >> offer_count ; assert ( market_id == static_cast < int > ( i + 1 ) ) ; auto & offers = market_offers . at ( i ) ; for ( auto j = 0u ; j < offer_count ; ++ j ) { ProductOffer offer ; iss >> offer . product_id_ >> offer . price_ >> offer . quantity_ ; -- offer . product_id_ ; offer . market_id_ = i ; offers . emplace_back ( offer ) ; CHECK_F ( offer . price_ >= 0 , " " ) ; CHECK_F ( offer . quantity_ > 0 , " " ) ; } } return market_offers ; }
Reads exactly market_count product offers from file.
Reads exactly market_count product offers from file .
// Keep product ids in range [0..dimension-1]