-
Notifications
You must be signed in to change notification settings - Fork 1
/
Common.cpp
88 lines (77 loc) · 1.98 KB
/
Common.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
#include "stdafx.h"
#include "Common.h"
void minfastsort(vector<double> &x, vector<int> &idx, int n, int m)
{
minfastsort((double*)&(*(x.begin())), (int*)&(*(idx.begin())), n, m);
}
void minfastsort(double* x, int* idx, int n, int m) //sort the vector and the index
{
for(int i=0; i<m; i++)
{
for(int j=i+1; j<n; j++)
if(x[i]>x[j])
{
double temp = x[i];
x[i] = x[j];
x[j] = temp;
int id = idx[i];
idx[i] = idx[j];
idx[j] = id;
}
}
}
double dist_vector(vector <double> &vec1, vector <double> &vec2) //the distance of two vector
{
int dim = vec1.size();
double sum = 0;
for(int n=0; n<dim; n++)
sum+=(vec1[n] - vec2[n])*(vec1[n] - vec2[n]);
return sqrt(sum);
}
double observepoint_dist_vector(vector <double> &vec1, vector <double> &vec2)
{
int dim = vec1.size();
double sum = 0;
for(int n=0; n<dim; n++)
sum+=(vec1[n] - (vec2[n] ) )*(vec1[n] - (vec2[n] ));
return sqrt(sum);
}
//double fn_dist_vector(vector <double> &vec1, vector <double> &vec2, int n_fn)
//{
// //int dim = vec1.size();
// double dist ;
// //for(int n=0; n<dim; n++)
// // sum+=(vec1[n] - vec2[n])*(vec1[n] - vec2[n]);
// dist = abs( vec1[n_fn] - vec2[n_fn] );
// return dist;
//}
//double nofn_dist_vector(vector <double> &vec1, vector <double> &vec2, int n_fn)
//{
// int dim = vec1.size();
// double sum = 0;
// for(int n=0; n<dim; n++)
// if(n!=n_fn)
// sum+=(vec1[n] - vec2[n])*(vec1[n] - vec2[n]);
// return sqrt(sum);
//}
//double nofn_optimumpoint_dist_vector(vector <double> &vec1, vector<CSNGAInd> &vec2, int n_fn)
//{
// int dim = vec1.size();
// double sum = 0;
// for(int n=0; n<dim; n++)
// if(n!=n_fn)
// sum+=(vec1[n] - vec2[n].y_obj[n])*(vec1[n] - vec2[n].y_obj[n]);
// return sqrt(sum);
//}
//bool dominate(vector<double> &u, vector<double> &v, double epsilon)
//{
// int dim = u.size();
// for(int i=0; i<dim; i++)
// {
// if(u[i]<v[i]-epsilon)
// {
// return false;
// }
// }
// return true;
//}