-
Notifications
You must be signed in to change notification settings - Fork 0
/
appc_sky_line.h
executable file
·126 lines (107 loc) · 2.41 KB
/
appc_sky_line.h
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
123
124
125
126
#include "lib_import.h"
class appc_sky_line_conjecture
{
public:
vector<double> operator()(vector<double>& re)
{
vector<double> v_re;
v_re.resize(4);
for(int cnt=0;cnt<re.size();cnt++)
{
v_re[cnt%4] += v_re[cnt];
}
return v_re;
}
bool operator()(const vector<double>&src ,const vector<double>&des) const
{
bool b_flag = false;
for(int cnt=0;cnt<min(src.size(),des.size());cnt++)
{
if (src[cnt] > des[cnt])
{
b_flag = true;
break;
}
}
if (b_flag)
{
return src[0] > des[0];
}
else
{
return false;
}
}
};
class appc_sky_line_compare
{
public:
double operator()(pair<int,vector<double> >& src,pair<int,vector<double> > & des)
{
for(int cnt=0;cnt<min(src.second.size(),des.second.size());cnt++)
{
if (src.second[cnt] < des.second[cnt])
return true;
else if (src.second[cnt] > des.second[cnt])
return false;
}
return false;
}
};
inline
double appc_sky_line_distance(vector<double>& src,vector<double>& des)
{
double d_re = 0;
for(int cnt=0;cnt<min(src.size(),des.size());cnt++)
{
d_re = (src[cnt] - des[cnt])*(src[cnt] - des[cnt]);
}
return sqrt(d_re);
}
class appc_sky_line
{
private:
cls_pso_multi_dim<double,appc_sky_line_conjecture> pso;
vector<vector<double> > v_best_area;
vector<vector<double> > v_data;
appc_sky_line_compare func_cmp;
int num_top;
public:
vector<vector<double> >& choose(vector<vector<double> > & re)
{
vector<tag_particle_multi_values<double,appc_sky_line_conjecture> > v_part = pso.get_particles();
return re;
}
appc_sky_line(string str_filename,int n_time,int arg_num_particle,int dim,int n_top):pso(n_time,arg_num_particle,dim,n_top)
{
num_top = n_top;
pso.max_bound = 100;
pso.min_bound = 0;
ifstream fin(str_filename.c_str());
while(!fin.eof())
{
vector<double> v_tmp;
v_tmp.resize(4);
int n;
double d;
char c;
fin>>n>>v_tmp[0]>>c>>v_tmp[1]>>c>>v_tmp[2]>>c>>v_tmp[3];
v_data.push_back(v_tmp);
}
fin.close();
}
void train()
{
pso.run();
}
void get_best_area()
{
v_best_area.clear();
vector<tag_particle_multi_values<double,appc_sky_line_conjecture> >& v_particle = pso.get_particles();
sort(v_particle.begin(),v_particle.end());
for(int cnt=0;cnt<v_particle.size();cnt++)
{
v_best_area.push_back(v_particle[cnt].v_pos);
}
}
};