-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainTest.cc
199 lines (140 loc) · 3.62 KB
/
MainTest.cc
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include "newGA.hh"
#include <random>
#include <sstream>
using skeleton newGA;
void massCross(const Problem &pbm){
using skeleton newGA;
for (int i=0;i<5;i++) cout<<endl;
cout << "MASS::CROSS::INIT" <<endl;
Solution * F1= new Solution(pbm);
Solution * F2= new Solution(pbm);
cout<<"ok"<<endl;
F1->initialize();
F2->initialize();
cout << "FATHER::1" << endl << *F1 << endl;
cout << "FITNESS:: "<<F1->fitness() <<endl;
cout << "FATHER::2" << endl << *F2 << endl;
cout << "FITNESS:: "<<F2->fitness() <<endl;
Rarray<Solution*> population(2);
population[0]=F1;
population[1]=F2;
Intra_Operator *I= Intra_Operator::create(0);
for(int i=0; i<100;i++)
I->execute(population);
cout << "SON::1" << endl << *population[0] << endl;
cout << "FITNESS:: "<<population[0]->fitness() <<endl;
cout << "SON::2" << endl << *population[1] << endl;
cout << "FITNESS:: "<<population[1]->fitness() <<endl;
}
void massMutation(const Problem &pbm){
using skeleton newGA;
Solution * F1= new Solution(pbm);
F1->initialize();
Solution * copy = new Solution(*F1);
Rarray<Solution*> population(1);
population[0]=F1;
cout << "FATHER::1" << endl << *F1 << endl;
cout << "FITNESS:: "<<F1->fitness() <<endl;
Intra_Operator *I= Intra_Operator::create(1);
cout << "OK"<< endl;
for(int i=0; i<100;i++)
I->execute(population);
cout << "SON::1" << endl << *population[0] << endl;
cout << "FITNESS:: "<<population[0]->fitness() <<endl;
//printArray(population[0]->array_solucion(),pbm.cantidad_trabajos(),pbm.cantidad_maquinas());
if(*copy!=*population[0]) cout << "MUTATION!" << endl;
}
void testDelete(const Problem &pbm){
using skeleton newGA;
Solution * F1= new Solution(pbm);
F1->initialize();
Rarray<Solution*> population(1);
cout << "ok" <<endl;
population[0]=new Solution(pbm);
*population[0]=*F1;
cout << *population[0]<<endl;
}
void first(const Problem &pbm){
using skeleton newGA;
Solution * F1= new Solution(pbm);
Solution * F2= new Solution(pbm);
F1->initialize();
F2->to_Solution(F1->to_String());
cout << *F1 << endl;
cout << *F2 << endl;
}
int **get_machines(char **argv){
ifstream is(argv[1]);
string buffer;
getline(is,buffer);
int null;
int _cantidad_trabajos, _cantidad_maquinas;
istringstream iss(buffer);
iss >> _cantidad_trabajos;
iss >> _cantidad_maquinas;
int ** M= new int*[_cantidad_trabajos+1];
for(int i=0; i<_cantidad_trabajos; i++){
getline(is,buffer);
istringstream parse(buffer);
M[i]= new int[_cantidad_maquinas+1];
for(int j=0; j<_cantidad_maquinas; j++){
int aux;
int null;
parse >> aux;
parse >> null;
M[i][j]=aux;
}
}
return M;
}
void test1(char **argv){
//crea un problema y lo imprime
using skeleton newGA;
ifstream f1(argv[1]);
if (!f1) show_message(12);
Problem pbm;
f1 >> pbm;
cout << "OKK" << endl;
f1.close();
cout << pbm;
}
int main (int argc, char** argv)
{
using skeleton newGA;
ifstream f1(argv[1]);
if (!f1) show_message(12);
Problem pbm;
f1 >> pbm;
cout << "OKK" << endl;
f1.close();
cout << pbm;
Solution * Sol= new Solution(pbm);
cout<<"redfd"<<endl;
Sol->initialize();
cout<<"ok2"<<endl;
Sol->repair();
cout <<*Sol<<endl;
cout <<"ok sol"<<endl;
int fitness=Sol->fitness();
cout <<"FITNESS:: "<<fitness<<endl;
//cout<<pbm;
cout <<"FITNESS:: "<<fitness<<endl;
Solution *Sol2= new Solution(pbm);
Sol2->initialize();
cout<< pbm;
cout << "fin";
massCross(pbm);
cout << "FINISHED::CROSS" << endl;
//cout << pbm << endl;
massMutation(pbm);
cout << "FINISHED::MUTATION" << endl;
/*
testDelete(pbm);
Solution *Sol2 = new Solution(pbm);
Sol2->fromProblem(pbm);
Sol2->repair();
cout <<*Sol2 <<endl;
cout << Sol2->fitness() <<endl;
*/
return(0);
}