-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
50 lines (42 loc) · 1.54 KB
/
Copy pathmain.cpp
File metadata and controls
50 lines (42 loc) · 1.54 KB
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
#include <iomanip>
#include "optimize.hpp"
#include "opec.hpp"
#include "cartel.hpp"
#include "debug.hpp"
using namespace opec;
void dump(const Market& market, const Solution& solution) {
std::cout << std::setw(20) << "Countries: ";
for (auto actor : market.actors) {
std::cout << actor->name << ", ";
}
std::cout << std::endl;
std::cout << solution << std::endl;
std::cout << "Marginal revenue (inflated):" << std::endl;
for (int a = 0; a < market.size(); a++) {
auto& actor = *market.actors[a];
auto q = solution.quantities.row(a);
auto margin = actor.marginalRevenue(solution.prices, q, market, solution.production);
margin -= actor.marginalCost(q);
margin = Market::inflate(margin);
std::cout << std::setw(18) << actor.name << ": " << margin.transpose() << std::endl;
}
}
int main() {
std::vector<Actor*> countries;
for (int c = 0; c < Opec::NumCountries; c++) {
countries.push_back(&opec::opec[c]);
}
std::cout << std::setw(40) << "" << "COMPETITION:" << std::endl;
Market competitive(countries);
auto competitiveSolution = solve(competitive);
dump(competitive, competitiveSolution);
std::cout << std::endl << std::endl
<< std::setw(40) << "" << "MONOPOLY:" << std::endl;
Cartel opec("Opec", countries, competitiveSolution);
std::vector<Actor*> opecv{&opec};
Market monopoly(opecv);
auto monopolySolution = solve(monopoly);
dump(monopoly, monopolySolution);
opec.dump(monopolySolution);
return 0;
}