-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStationRailway.cpp
181 lines (147 loc) · 4.33 KB
/
StationRailway.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//
// Created by Joao on 3/28/2023.
//
#include "StationRailway.h"
// Station
Station::Station() {
this->id = 0;
this->name = "";
this->district = "";
this->municipality = "";
this->township = "";
this->line = "";
}
Station::Station(const int &id, const std::string &name, const std::string &district, const std::string &municipality,
const std::string &township, const std::string &line) {
this->id = id;
this->name = name;
this->district = district;
this->municipality = municipality;
this->township = township;
this->line = line;
}
void Station::removeRailway(Railway *railway) {
auto it = outgoingRailways.begin();
while (it != outgoingRailways.end()) {
Railway* r = *it;
Station* s = r->getDestinyStationPointer();
if(s->getId() == railway->getDestinyStationPointer()->getId()){
it = outgoingRailways.erase(it);
deleteRailway(r);
}
else{
it++;
}
}
}
void Station::deleteRailway(Railway *railway) {
Station* destinyStation = railway->getDestinyStationPointer();
auto it = destinyStation->incomingRailways.begin();
while (it != destinyStation->incomingRailways.end()) {
if((*it)->getSourceStationPointer()->getId() == id){
it = destinyStation->incomingRailways.erase(it);
}
else{
it++;
}
}
delete railway;
}
const std::string &Station::getName() const {
return name;
}
const std::string &Station::getDistrict() const {
return district;
}
const std::string &Station::getMunicipality() const {
return municipality;
}
const std::string &Station::getLine() const {
return line;
}
int Station::getId() const {
return id;
}
std::vector<Railway *> Station::getOutgoingRailways() const {
return this->outgoingRailways;
}
std::vector<Railway *> Station::getIncomingRailways() const {
return this->incomingRailways;
}
bool Station::isVisited() const {
return visited;
}
int Station::getDistance() const {
return distance;
}
int Station::getBottleneck() const{
return bottleneck;
}
void Station::setVisited(bool visited) {
Station::visited = visited;
}
void Station::setDistance(int distance) {
Station::distance = distance;
}
Railway *Station::addRailway(Station *station, std::string sourceName, std::string destinyName, double capacity, const std::string &service) {
Railway* railway = new Railway(this, station, sourceName, destinyName, capacity, service);
outgoingRailways.push_back(railway);
station->incomingRailways.push_back(railway);
return railway;
}
void Station::setPath(Railway *previousRailway) {
this->path = previousRailway;
}
Railway *Station::getPath() const {
return path;
}
// Raillway
Railway::Railway(const std::string& sourceStation, const std::string& destinyStation, double capacity, const std::string &service) {
this->sourceStationString = sourceStation;
this->destinyStationString = destinyStation;
this->capacity = capacity;
this->service = service;
this->flow = 0;
}
Railway::Railway(Station *origin, Station *destination, std::string sourceName, std::string destinyName, double capacity, const std::string &service) {
this->sourceStationPointer = origin;
this->destinyStationPointer = destination;
this->destinyStationString = destinyName;
this->sourceStationString = sourceName;
this->capacity = capacity;
this->service = service;
this->flow = 0;
}
double Railway::getCapacity() const {
return capacity;
}
double Railway::getFlow() const {
return flow;
}
const std::string &Railway::getService() const {
return service;
}
void Railway::setFlow(double flow) {
Railway::flow = flow;
}
Station *Railway::getSourceStationPointer() const {
return sourceStationPointer;
}
Station *Railway::getDestinyStationPointer() const {
return destinyStationPointer;
}
const std::string &Railway::getSourceStationString() const {
return sourceStationString;
}
const std::string &Railway::getDestinyStationString() const {
return destinyStationString;
}
Railway* Railway::getReverseRailway() const {
return this->reverseRailway;
}
void Railway::setReverseRailway(Railway *railway) {
this->reverseRailway = railway;
}
void Station::setBottleneck(int bottleNeck){
this->bottleneck = bottleNeck;
}