-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSatisfactionIndex.cpp
More file actions
executable file
·123 lines (95 loc) · 3.36 KB
/
SatisfactionIndex.cpp
File metadata and controls
executable file
·123 lines (95 loc) · 3.36 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
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
/*
* Copyright 2023 University of Michigan EECS183
*
* SatisfactionIndex.cpp
* Project UID 848fee0125dbb5eb53ed294f20dbef81
*
* Final Project - Elevators
*/
#include "SatisfactionIndex.h"
using namespace std;
////////////////////////////////////////////////////////
//////// DO NOT MODIFY ANY CODE IN THIS FILE ///////////
////////////////////////////////////////////////////////
SatisfactionIndex::SatisfactionIndex() {
sumIndex = 0;
sumUpRequest = 0;
sumDownRequest = 0;
sumExploded = 0;
sumIdle = 0;
timeReached = 0;
}
int SatisfactionIndex::getSatisfaction() const {
return sumIndex;
}
void SatisfactionIndex::updateSumDirectionRequest(const Move& move,
const Building& building) {
sumIndex += move.getTotalSatisfaction();
int currentElevatorFloor =
building.getElevatorById(move.getElevatorId()).getCurrentFloor();
int targetFloor = move.getTargetFloor();
// Sum of times elevator "went down", NOT num people who wanted to go down
// and were picked up
if (currentElevatorFloor < targetFloor) {
sumUpRequest++;
} else {
sumDownRequest++;
}
}
void SatisfactionIndex::updateSumExploded(const int num) {
sumExploded += num;
sumIndex += (num * POINTS_LOST_PER_EXPLOSION);
}
void SatisfactionIndex::updateSumIdle(const Building& building) {
for (int i = 0; i < NUM_ELEVATORS; ++i) {
if (!building.getElevatorById(i).isServicing()) {
++sumIdle;
}
}
}
void SatisfactionIndex::updateTimeReached(const Building& b) {
timeReached = b.getTime();
return;
}
void SatisfactionIndex::readRawSatisfaction(istream& ins) {
ins >> sumIndex >> sumUpRequest >> sumDownRequest >> sumExploded >> sumIdle;
}
void SatisfactionIndex::printRawSatisfaction(ostream& outs) const {
outs << sumIndex << endl;
outs << sumUpRequest << endl;
outs << sumDownRequest << endl;
outs << sumExploded << endl;
outs << sumIdle << endl;
}
void SatisfactionIndex::printSatisfaction(ostream& outs, const bool isCSV) const {
if (!isCSV) {
outs << "sumIndex: \t" << sumIndex << endl;
outs << "sumUpRequest: \t" << sumUpRequest << endl;
outs << "sumDownRequest:\t" << sumDownRequest << endl;
outs << "sumExploded: \t" << sumExploded << endl;
outs << "sumIdle: \t" << sumIdle << endl;
outs << "timeReached: \t" << timeReached << endl;
} else {
outs << "test,sumIndex,sumUpRequest,sumDownRequest,sumExploded,";
outs << "sumIdle,timeReached" << endl;
outs << "student,";
outs << sumIndex << ',';
outs << sumUpRequest << ',';
outs << sumDownRequest << ',';
outs << sumExploded << ',';
outs << sumIdle << ',';
outs << timeReached;
}
}
void SatisfactionIndex::save() const {
ofstream result(RESULT_FILENAME);
printSatisfaction(result, true);
}
ostream& operator<<(ostream& outs, const SatisfactionIndex& index) {
index.printRawSatisfaction(outs);
return outs;
}
istream& operator>>(istream& ins, SatisfactionIndex& index) {
index.readRawSatisfaction(ins);
return ins;
}