46 lines
917 B
C++
46 lines
917 B
C++
#include "aliases.h"
|
|
#include "argparser.h"
|
|
#include "generator.h"
|
|
#include "haversine.h"
|
|
#include "point_types.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
|
|
#define EARTH_RADIUS_KM 6371.0
|
|
|
|
i32 main(i32 argc, char *argv[]) {
|
|
GeneratorArgs args = parse_args(argc, argv);
|
|
|
|
srand(args.seed);
|
|
|
|
PairArray arr = {args.count, NULL};
|
|
arr.pairs = (PointPair *)malloc(arr.count * sizeof(PointPair));
|
|
|
|
fill_pairs_array(&arr, args.clustered);
|
|
|
|
write_pairs_to_json(arr, "pairs.json");
|
|
|
|
FILE *fp = fopen("count_and_distances", "w");
|
|
|
|
if (fp) {
|
|
fwrite(&(arr.count), sizeof(arr.count), 1, fp);
|
|
|
|
i64 sum = 0;
|
|
for (u64 i = 0; i < arr.count; ++i) {
|
|
f64 distance = haversine_of_degrees(arr.pairs[i], EARTH_RADIUS_KM);
|
|
|
|
fwrite(&distance, sizeof(f64), 1, fp);
|
|
|
|
sum += distance;
|
|
}
|
|
printf("%ld\n", sum / arr.count);
|
|
|
|
fclose(fp);
|
|
}
|
|
|
|
free(arr.pairs);
|
|
|
|
return 0;
|
|
}
|