-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
142 lines (94 loc) · 3.29 KB
/
main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <random>
#include <algorithm>
#include "commuter.h"
bool compare(Commuter & c1, Commuter & c2){
return c1.getTauAMax() > c2.getTauAMax();
}
int main(){
std::vector<int> stationPop(38, 0);
int goal = 336;
double goalOcc = 0.8;
int stops = 416;
// read in station populations
std::ifstream file("data.txt");
std::string str;
int lineCount = 0;
int count = 0;
while(std::getline(file, str)){
lineCount++;
if(lineCount%2 == 0){
// divide daily number of commuters at station by num of trains stopping
stationPop[count] = std::stoi(str)/416;
count++;
}
}
std::vector<std::vector<Commuter>> stations;
std::vector<std::vector<double>> tauVec;
// construct commuters from each station
for(int i = 0; i != stationPop.size(); i++){
std::cout << i << " : " << stationPop[i];
std::vector<Commuter> s;
std::vector<double> t;
// double tauArr[stationPop[i].size()];
for(int j = 0; j != stationPop[i]; j++){
// randomize V
double V = (20 + ( std::rand() % ( 80 - 20 + 1 ) ))/100.0;
// randomize Tb
int Tb = 0;
if(i != 37){
Tb = 1 + ( std::rand() % ( 3*(37-i) - 1 + 1 ) );
}
// radomize Ta
int Ta = 37;
if(i != 37){
Ta = (i+1) + ( std::rand() % ( 37 - (i+1) + 1 ) );
}
Ta = 2*(Ta-i);
// randomize tauB
double tauB = (0 + ( std::rand() % ( 500 - 0 + 1 ) ))/100.0;
Commuter newCommuter (j, V, Ta, Tb, tauB);
while ( newCommuter.UapCheck() == false ){
newCommuter.reroll(i);
}
s.push_back(newCommuter);
t.push_back(newCommuter.getTauAMax());
}
std::cout << std::endl;
stations.push_back(s);
std::sort(t.begin(), t.end());
tauVec.push_back(t);
// std::sort(stationPop[i][0], stationPop[i][stationPop[i].size()], compare);
}
std::cout << std::endl << std::endl;
// for(int i = 0; i != tauVec[1].size(); i++){
// std::cout << tauVec[1][i] << std::endl;
// }
// traversal
std::vector<int> boardedNum;
int o = 0;
for (int i = 0; i != tauVec.size(); i++){
// seats = num of commuter unless cant fit all
int seats = stationPop[i];
if(o+seats > goal){seats = goal - o;}
if(seats > 0){
double toll = tauVec[i][tauVec[i].size()-seats];
std::cout << "Station " << i << " : " << seats << "/" << stationPop[i] << " : $" << toll << std::endl;
}else{
std::cout << "Station " << i << " : " << seats << " : $" << 35 << std::endl;
}
o += seats;
boardedNum.push_back(seats);
// deboard old passengers
if(i >= 5){
o -= boardedNum[i-5];
}
}
std::cout << std::endl << std::endl;
return 0;
}