-
Notifications
You must be signed in to change notification settings - Fork 1
/
AdSupply.cpp
58 lines (47 loc) · 1.28 KB
/
AdSupply.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// Created by linpingta.
//
#include "AdSupply.h"
#include <sstream>
int AdSupply::getSupply(const std::string& supplyID) {
auto iter = this->supplyPair.find(supplyID);
if (iter != this->supplyPair.end()) {
return iter->second;
}
return -1;
}
std::vector<std::string> AdSupply::getSupplyKeys(){
std::vector<std::string> keys;
for (const auto& pair: this->supplyPair) {
keys.push_back(pair.first);
}
return keys;
}
void AdSupply::loadInventory(const std::string& file) {
std::ifstream f(file);
if (!f.is_open()) {
std::cerr << "Error for opening supply file: " << file << std::endl;
}
std::string line;
while (std::getline(f, line)) {
if (line.find("#") != std::string::npos) {
continue;
}
std::istringstream iss(line);
std::string supplyID = "";
int inventoryValue = -1;
iss >> supplyID >> inventoryValue;
supplyPair[supplyID] = inventoryValue;
}
}
void AdSupply::print() {
std::cout << "\nSupply:" << std::endl;
std::cout << "supply_node\tinventory\tsatisfy_demand" << std::endl;
for (const auto& i : this->getSupplyKeys()) {
std::cout << i << "\t\t" << this->getSupply(i) << "\t\t";
for (const auto& j : this->satisfyDemandList[i]) {
std::cout << j << ",";
}
std::cout << std::endl;
}
}