-
Notifications
You must be signed in to change notification settings - Fork 3
/
individual.h
126 lines (94 loc) · 1.99 KB
/
individual.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
#ifndef __TINDIVIDUAL_H_
#define __TINDIVIDUAL_H_
//#include "global.h"
#include "objective.h"
class TIndividual{
public:
TIndividual();
virtual ~TIndividual();
vector <int> x_var;
vector <double> y_obj;
void rnd_init();
void obj_eval();
bool operator<(const TIndividual &ind2);
bool operator==(const TIndividual &ind2);
void operator=(const TIndividual &ind2);
void show_objective();
void show_variable();
};
TIndividual::TIndividual()
{
for(int i=0; i<numVariables; i++)
x_var.push_back(i+1); //this is better
for(int n=0; n<numObjectives; n++)
y_obj.push_back(0.0);
}
TIndividual::~TIndividual()
{
}
void TIndividual::rnd_init()
{
IGLP(x_var,node);
// rehearse(x_var);
}
void TIndividual::obj_eval()
{
objectives(x_var,y_obj);
}
void TIndividual::operator=(const TIndividual &ind2)
{
x_var = ind2.x_var;
y_obj = ind2.y_obj;
}
void TIndividual::show_objective()
{
for(int n=0; n<numObjectives; n++)
printf("%f ",y_obj[n]);
printf("\n");
}
void TIndividual::show_variable()
{
for(int n=0; n<numVariables; n++)
printf("%d ",x_var[n]);
printf("\n");
}
bool TIndividual::operator<(const TIndividual &ind2)
{
bool dominated = true;
for(int n=0; n<numObjectives; n++)
{
if(ind2.y_obj[n]<y_obj[n]) return false;
}
if(ind2.y_obj==y_obj) return false;
return dominated;
}
bool TIndividual::operator==(const TIndividual &ind2)
{
if(ind2.y_obj==y_obj) return true;
else return false;
}
class TSOP
{
public:
TSOP();
virtual ~TSOP();
TIndividual indiv;
vector <double> namda;
vector <int> table; // the vector for the indexes of neighboring subproblems
vector <int> array;
void operator=(const TSOP&sub2);
};
TSOP::TSOP()
{
}
TSOP::~TSOP()
{
}
void TSOP::operator=(const TSOP&sub2)
{
indiv = sub2.indiv;
table = sub2.table;
namda = sub2.namda;
array = sub2.array;
}
#endif