-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
68 lines (57 loc) · 1.57 KB
/
Copy pathutils.cpp
File metadata and controls
68 lines (57 loc) · 1.57 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
#pragma once
#include "Point.h"
#include <time.h>
/*
* This function loads the data from a csv file
* @param file_name: the name of the file to be loaded
* @return a vector of points
*/
std::vector<Point> load_csv (const std::string& file_name){
std::vector<Point> points;
std::ifstream file;
file.open(file_name, std::ios::in);
std::string line, word;
if(file.is_open()){
//std::cout<<"file is opened"<<std::endl;
while(getline(file, line)){
std::stringstream str(line);
Point p;
int i = 0;
while(getline(str, word, ',')){
p.coordinates[i] = std::stod(word);
i++;
}
p.cluster = -1;
points.push_back(p);
}
}
else std::cout<<"ERROR: couldn't open file"<<std::endl;
return points;
}
/*
* This function outputs the results to a csv file
* @param points: the vector of points to be written
* @return void
*/
void output_results (std::vector<Point>& points){
std::fstream output;
output.open("output.csv", std::ios::out);
if(output.is_open()){
for(Point p: points){
for (int i = 0; i < DIM; i++){
output<<p.coordinates[i]<<",";
}
output<<p.cluster;
output<<std::endl;
}
}
}
/*
* This function returns the current time in nanoseconds
* @return the current time in nanoseconds
*/
uint64_t nanos(){
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (uint64_t)ts.tv_sec * 1000000000 + ts.tv_nsec;
}