-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
196 lines (158 loc) · 5.8 KB
/
main.cpp
File metadata and controls
196 lines (158 loc) · 5.8 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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <thread>
#include <chrono>
using namespace std;
const short LOTS = 6, MAX_D = 1000, MIN_D = 0;
void Populator(float*);
void Printer(float*);
void distanceCombiner(float*, float*, float*);
void Normalizer(float*, float *);
void coefficientCombiner(float*, float*, float*, float, float);
bool inputValidation(float, float);
void SpaceNormalizer(float*, float*);
int main(){
//Step one: Generate 3 arrays containing distance_one, occ_rate, distance_two
float distance_one[LOTS];
float empty_spaces[LOTS];
float distance_two[LOTS];
Populator(distance_one);
std::this_thread::sleep_for(std::chrono::seconds(1));
Populator(empty_spaces);
std::this_thread::sleep_for(std::chrono::seconds(1));
Populator(distance_two);
cout << "\nPrinting Current Data: \n\n";
cout << " 1 2 3 4 5 6 LOTS\n";
Printer(distance_one);
cout << " DISTANCE 1\n";
Printer(empty_spaces);
cout << " OCCUPANCY RATE\n";
Printer(distance_two);
cout << " DISTANCE 2\n\n";
//Combining distances to normalize data
float total_distances[LOTS];
distanceCombiner(distance_one, distance_two, total_distances);
cout << "Combining Distance Data...\n";
cout << "\nPrinting Current Data: \n\n";
cout << " 1 2 3 4 5 6 LOTS\n";
Printer(total_distances);
cout << " TOTAL DISTANCE\n";
Printer(empty_spaces);
cout << " OCCUPANCY RATE\n\n";
//Normalizing Data
float normalized_distance[LOTS];
float normalized_spaces[LOTS];
Normalizer(total_distances, normalized_distance);
SpaceNormalizer(empty_spaces, normalized_spaces);
cout << setprecision(3) << fixed;
cout << "Normalizing Total Distance Data...\n";
cout << "\nPrinting Current Data: \n\n";
cout << " 1 2 3 4 5 6 LOTS\n";
Printer(normalized_distance);
cout << " NORMALIZED TOTAL DISTANCE\n";
Printer(empty_spaces);
cout << " OCCUPANCY RATE\n\n";
//Combining Data Using Coefficients d,p
float combined_results[LOTS];
cout << "Combining Data Using Coefficients d and p";
/**************************************************************************************/
coefficientCombiner(normalized_distance, normalized_spaces, combined_results, 0.490, 0.510);
cout << "\n\nTesting using d = 0.45 and p = 0.55\n";
cout << "\nPrinting Current Data: \n\n";
cout << " 1 2 3 4 5 6 LOTS\n";
cout << setprecision(0);
Printer(empty_spaces);
cout << " OCCUPANCY RATE\n";
Printer(distance_one);
cout << " DISTANCE 1\n";
Printer(distance_two);
cout << " DISTANCE 2\n";
Printer(total_distances);
cout << " TOTAL DISTANCE\n";
cout << setprecision(3) << fixed;
Printer(combined_results);
cout << " Final Results\n";
//Trying User-entered values
float dRate, pRate;
do{
cout << "\nEnter a coefficient d for the distance weight and p for the parking weight: \n";
cout << "\nd: ";
cin >> dRate;
cout << "p: ";
cin >> pRate;
if(!inputValidation(dRate, pRate))
cout << "\nINVALID INPUT. VALID RANGE [0 - 1]\n";
}while(!inputValidation(dRate, pRate));
coefficientCombiner(normalized_distance, empty_spaces, combined_results, dRate, pRate);
cout << "\nTesting using d = 0.45 and p = 0.55\n";
cout << "\nPrinting Current Data: \n\n";
cout << " 1 2 3 4 5 6 LOTS\n";
Printer(empty_spaces);
cout << " OCCUPANCY RATE\n";
cout << setprecision(0);
Printer(distance_one);
cout << " DISTANCE 1\n";
Printer(distance_two);
cout << " DISTANCE 2\n";
Printer(total_distances);
cout << " TOTAL DISTANCE\n";
cout << setprecision(3) << fixed;
Printer(combined_results);
cout << " Final Results\n\n";
return(0);
}
void Populator(float* array_address){
srand(time(0));
for(short index = 0; index < LOTS; index++){
array_address[index] = (rand() % (MAX_D - MIN_D - 1) + MIN_D);
}
}
void Printer(float* array_address){
for(short index = 0; index < LOTS; index++){
cout << setw(5) << array_address[index] << " ";
}
}
void distanceCombiner(float* arg_one, float* arg_two, float* final_answer){
for(short index = 0; index < LOTS; index++){
final_answer[index] = arg_one[index] + arg_two[index];
}
}
void Normalizer(float* non_n_data, float* norm_data){
float MAX_VALUE = non_n_data[0];
float MIN_VALUE = non_n_data[0];
for(short index = 1; index < LOTS; index++){
if(non_n_data[index] > MAX_VALUE)
MAX_VALUE = non_n_data[index];
if(non_n_data[index] < MIN_VALUE)
MIN_VALUE = non_n_data[index];
}
for(short index = 0; index < LOTS; index++){
norm_data[index] = (non_n_data[index] - MIN_VALUE) / (MAX_VALUE - MIN_VALUE);
}
}
void coefficientCombiner(float* distance_array, float* occ_array, float* final_results_array, float dval, float pval){
for(short index =0; index <LOTS; index++){
final_results_array[index] = distance_array[index] * dval + occ_array[index] * pval;
}
}
bool inputValidation(float arg_one, float arg_two){
bool valid = true;
if(arg_one < 0 || arg_one > 1 || arg_two < 0 || arg_two > 1)
valid = false;
return valid;
}
void SpaceNormalizer(float* non, float* norm){
float MAX_VALUE = non[0];
float MIN_VALUE = non[0];
for(short index = 1; index < LOTS; index++){
if(non[index] > MAX_VALUE)
MAX_VALUE = non[index];
if(non[index] < MIN_VALUE)
MIN_VALUE = non[index];
}
for(short index = 0; index < LOTS; index++){
norm[index] = (MAX_VALUE - non[index]) / (MAX_VALUE - MIN_VALUE);
}
}