-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
122 lines (108 loc) · 4.08 KB
/
Copy pathmain.cpp
File metadata and controls
122 lines (108 loc) · 4.08 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
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <iomanip>
int main() {
srand(time(NULL)); // Random seed
const int simulations = 1;
const int population = 10000;
const int dimensions = 10;
double totalSoakedAverages;
for (int sim = 0; sim < simulations; sim++) {
double numInSample = 0;
// Create all random points
double XYZ[population][dimensions];
for (int p = 0; p < population; p++) {
for (int d = 0; d < dimensions; d++) {
XYZ[p][d] = ((double) rand() / (RAND_MAX));
}
}
// I don't like this... but it creates a list for all the coordinates of soaked people. Defaults to -1.
// I could have used a vector but idk how to use multi-dimensional vectors.
double soakedPoints[population][dimensions];
for (int p = 0; p < population; p++) {
for (int d = 0; d < dimensions; d++) {
soakedPoints[p][d] = -5;
}
}
int soakedIndex = 0;
for (int subject = 0; subject < population; subject++) {
double minDist = 3;
double XYZclosest[dimensions];
bool subjectInSample = true;
bool targetInSample = true;
for (int target = 0; target < population; target++) {
if (subject != target) {
double dist = 0;
for (int d = 0; d < dimensions; d++) {
dist += ((XYZ[target][d] - XYZ[subject][d])*(XYZ[target][d] - XYZ[subject][d]));
}
if (dist < minDist) {
minDist = dist;
for (int d = 0; d < dimensions; d++) {
XYZclosest[d] = XYZ[target][d]; // XYZclosest becomes the target that will ultimately be shot
}
}
}
}
for (int d = 0; d < dimensions; d++) {
if (XYZ[subject][d] < 0.10 || XYZ[subject][d] > 0.90) {
subjectInSample = false;
}
if (XYZclosest[d] < 0.10 || XYZclosest[d] > 0.90) {
targetInSample = false;
}
}
if (subjectInSample) {
numInSample++;
}
if (targetInSample) {
// Checks if the XYZclosest point already exists in soakedPoints.
int matchCounter;
bool alreadyExists = false;
for (int s = 0; s <= subject; s++) {
matchCounter = 0;
for (int d = 0; d < dimensions; d++) {
if (XYZclosest[d] == soakedPoints[s][d]) {
matchCounter++;
}
}
if (matchCounter == dimensions) {
alreadyExists = true;
}
}
// Adds XYZclosest to soakedPoints if it isn't already there.
if (!alreadyExists) {
for (int d = 0; d < dimensions; d++) {
soakedPoints[soakedIndex][d] = XYZclosest[d];
}
soakedIndex++;
}
}
}
// Find the number of soaked people in soakedPoints.
bool endOfSP = false;
double numSoaked = 0;
for (int p = 0; p < population; p++) {
for (int d = 0; d < dimensions; d++) {
std::cout << soakedPoints[p][d] << std::endl;
if (soakedPoints[p][d] == -5) {
endOfSP = true;
break;
}
}
if (!endOfSP) {
numSoaked++;
} else {
break;
}
}
if (numInSample != 0) {
//std::cout << numSoaked << std::endl;
totalSoakedAverages += numSoaked/numInSample;
}
}
double aveSoaked = 100*totalSoakedAverages/simulations;
std::cout << aveSoaked << std::endl;
}