-
Notifications
You must be signed in to change notification settings - Fork 4
/
Step12FKSimu.cpp
113 lines (104 loc) · 2.83 KB
/
Step12FKSimu.cpp
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
#include <iostream>
#include <string>
#include <utility>
#include <fstream>
#include <sstream>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <map>
#define pi 3.14159265358979323846
#define EPSILON 0.0000001
using namespace std;
int loc_vec[100000]={0};
int id_map[100000]={0};
int main(int argc, char** argv){
//only users with locations between these numbers are used
int threshold_min=atoi(argv[1]);
int threshold_max=atoi(argv[2]);
string thres_min_str=argv[1];
string thres_max_str=argv[2];
string input_name=argv[3];
ifstream fid_in;
string file_name0=input_name+".txt";
fid_in.open(file_name0.c_str(),ifstream::in);
FILE * fout_id2;
string file_name1="FKSimu"+ thres_min_str + "To" + thres_max_str + ".txt";
fout_id2=fopen(file_name1.c_str(), "w");
string tline;
int num1;
int num2;
int num3;
double num4;
int num5;
int temp_number;
int num_person_count=0;
int num_place=0;
int personal_vector_size=0;
int personal_record_num=0;
vector<double> all_frequency_count;
vector<int> personal_freuency_count;
int person_id=0;
for (int i=0;i<10000;i++){
all_frequency_count.push_back(0);
}
while (getline(fid_in,tline)){
stringstream parse_line(tline);
parse_line>>num1>>num2>>num3>>num4>>num5;
if (num1==person_id){
loc_vec[personal_record_num]=num5;
personal_record_num++;
}
else{
//re-id and count the number of places;
for (int i=0;i<100000;i++){
id_map[i]=-1;
}
num_place=0;
for (int i=0;i<personal_record_num;i++){
if (id_map[loc_vec[i]]==-1){
id_map[loc_vec[i]]=++num_place;
}
}
//deal with the old one first
if (num_place>=threshold_min&&num_place<=threshold_max){
num_person_count++;
personal_freuency_count.clear();
for (int i=0;i<num_place+1;i++){
personal_freuency_count.push_back(0);
}
for (int i=0;i<personal_record_num;i++){
personal_freuency_count[id_map[loc_vec[i]]]++;
}
personal_vector_size=personal_freuency_count.size();
//do the bubble sort
for (int j=0;j<personal_vector_size-1;j++){
for (int k=j+1;k<personal_vector_size;k++){
if (personal_freuency_count[j]<personal_freuency_count[k]){
temp_number=personal_freuency_count[k];
personal_freuency_count[k]=personal_freuency_count[j];
personal_freuency_count[j]=temp_number;
}
}
}
//update the overall
for (int j=0;j<personal_vector_size;j++){
if (personal_freuency_count[j]>0){
all_frequency_count[j]+=(personal_freuency_count[j]+0.0001)/personal_record_num;
}
}
}
//start the new one
num_place=0;
personal_record_num=0;
person_id=num1;
//the first record
loc_vec[personal_record_num]=num5;
personal_record_num++;
}
}
//output the result
for (int i=0;i<10000;i++){
fprintf(fout_id2,"%11.6f\n",all_frequency_count[i]/num_person_count);
}
}