diff --git a/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/MainLan b/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/MainLan index 98b7ca3a11f6bba9a06427709a234279a43463b5..dab1dc79bf353d0f899df5ff03cb425d66216531 100755 Binary files a/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/MainLan and b/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/MainLan differ diff --git a/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/MainSeq b/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/MainSeq index 30047a9d68025a5ea304598c2e8d327aa6c82d67..55e5b86acc0295e756cbd36ef7de88c13a26e95d 100755 Binary files a/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/MainSeq and b/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/MainSeq differ diff --git a/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/newGA.req.cc b/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/newGA.req.cc index 556e92b0ae42780ff5445631fff4c32cc49c1e89..87caff6b03724ae44b78cdcdcbe666d90859887c 100644 --- a/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/newGA.req.cc +++ b/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/newGA.req.cc @@ -257,14 +257,14 @@ skeleton newGA // Solution -------------------------------------------------------------- - Solution::Solution (const Problem& pbm):_pbm(pbm),_var(pbm.cantColumnas()) + Solution::Solution (const Problem& pbm):_pbm(pbm) { - + /* for (int i = 0; i <pbm.cantColumnas(); i++) { Rarray<int> aux(pbm.cantFilas()); _var[i] = aux; - } + }*/ _var = Rarray<Rarray<int>>(_pbm.cantColumnas()); @@ -285,7 +285,8 @@ skeleton newGA { return _pbm; } - + + Solution::Solution(const Solution& sol):_pbm(sol.pbm()) { _var = Rarray<Rarray<int>>(_pbm.cantColumnas()); @@ -301,11 +302,11 @@ skeleton newGA } } *this=sol; - if (_var[0][0] != 0 && _var[0][0] != 1) + /*if (_var[0][0] != 0 && _var[0][0] != 1) { cout << "cons sol" << endl; exit(EXIT_FAILURE); - } + }*/ } istream& operator>> (istream& is, Solution& sol) @@ -379,11 +380,11 @@ skeleton newGA Solution& Solution::operator= (const Solution &sol) { _var=sol._var; - if (_var[0][0] != 0 && _var[0][0] != 1) + /* if (_var[0][0] != 0 && _var[0][0] != 1) { cout << "=======" << endl; exit(EXIT_FAILURE); - } + }*/ return *this; } @@ -475,7 +476,7 @@ skeleton newGA double Solution::fitness () { - cout << "ESTOY ENTRANDO A FITNESS" << endl; + //cout << "ESTOY ENTRANDO A FITNESS" << endl; double fitness = 0.0; std::vector<std::vector<int>> datosDeFilas = _pbm.datosFilas(); std::vector<int> cantGruposDeFila = _pbm.cantGruposFila(); @@ -531,20 +532,21 @@ skeleton newGA //cout << "FIL" << _var[0] << endl; //cout << "FIL" << _var[1] << endl; - /*for (int fil = 0; fil < _pbm.cantFilas(); fil++) + for (int fil = 0; fil < _pbm.cantFilas(); fil++) { for(int col = 0; col < _pbm.cantColumnas(); col++) { - cout << _var[col][fil] << " "; + //cout << sol.var(col, fil) << " "; if (_var[col][fil] != 0 && _var[col][fil] != 1) { - //exit(EXIT_FAILURE); + cout << "fitness end" << endl; + exit(EXIT_FAILURE); } } - cout << endl; - }*/ + //cout << endl; + } - cout << "ESTOY SALIENDO DE FITNESS" << endl; + //cout << "ESTOY SALIENDO DE FITNESS" << endl; if (fitness == 0) { cout << "found sol lmao" << endl; @@ -554,7 +556,23 @@ skeleton newGA } char *Solution::to_String() const - { cout << "EN TO STRING" << endl; + { + cout << "EN TO STRING" << endl; + + for (int fil = 0; fil < _pbm.cantFilas(); fil++) + { + for(int col = 0; col < _pbm.cantColumnas(); col++) + { + //cout << sol.var(col, fil) << " "; + if (_var[col][fil] != 0 && _var[col][fil] != 1) + { + cout << "tostring begin" << endl; + exit(EXIT_FAILURE); + } + } + //cout << endl; + } + Rarray<int> aux = Rarray<int>((_pbm.cantColumnas() + 1) * _pbm.cantFilas()); int c = 0; for (int k = 0; k < _pbm.cantFilas(); k++) @@ -572,21 +590,19 @@ skeleton newGA { cout << "j=TO STRING " << j << " -> " << _var[i][j] << endl; } - if (_var[i][j] != 0 && _var[i][j] != 1) - { - exit(EXIT_FAILURE); - } - aux[c] = _var[i][j]; -// } -// else -// { -// aux[c] = 0; -// } - cout << _var[i][j] << " "; + aux[c] = _var[i][j]; c++; } - cout << endl; } +// for(int i = 0; i < _pbm.cantColumnas(); i++) +// { +// for(int j = 0; j < _pbm.cantFilas(); j++) +// { cout << _var[i][j] << " "; +// } +// cout << endl; +// +// } + //char * k = (char *)_var.get_first(); //cout << "ACA" << (int *)k << endl; return (char *)aux.get_first(); @@ -603,7 +619,8 @@ skeleton newGA ptr++; } - int c = _pbm.cantFilas(); + + int c = _pbm.cantColumnas(); for(int i = 0; i < _pbm.cantColumnas(); i++) { for(int j = 0; j < _pbm.cantFilas(); j++) @@ -614,12 +631,22 @@ skeleton newGA cout << "j= " << j << " -> " << _var[i][j] << endl; } - if (_var[i][j] != 0 && _var[i][j] != 1) + c++; + } + } + + for (int fil = 0; fil < _pbm.cantFilas(); fil++) + { + for(int col = 0; col < _pbm.cantColumnas(); col++) + { + //cout << sol.var(col, fil) << " "; + if (_var[col][fil] != 0 && _var[col][fil] != 1) { - //exit(EXIT_FAILURE); + cout << "tosolution end" << endl; + exit(EXIT_FAILURE); } - c++; } + //cout << endl; } // int *ptr=(int *)_string_; @@ -891,54 +918,54 @@ skeleton newGA */ void Mutation::mutate(Solution& sol) const { - cout << "ESTOY ENTRANDO A MUTATION" << endl; - - for (int fil = 0; fil < sol.pbm().cantFilas(); fil++) - { - for(int col = 0; col < sol.pbm().cantColumnas(); col++) - { - cout << sol.var(col, fil) << " "; - if (sol.var(col, fil) != 0 && sol.var(col, fil) != 1) - { - //exit(EXIT_FAILURE); - } - } - cout << endl; - } +// cout << "ESTOY ENTRANDO A MUTATION" << endl; + +// for (int fil = 0; fil < sol.pbm().cantFilas(); fil++) +// { +// for(int col = 0; col < sol.pbm().cantColumnas(); col++) +// { +// cout << sol.var(col, fil) << " "; +// if (sol.var(col, fil) != 0 && sol.var(col, fil) != 1) +// { +// //exit(EXIT_FAILURE); +// } +// } +// cout << endl; +// } std::vector<std::vector<int>> _grupos = sol.pbm().datosColumnas(); //Rarray<Rarray<int>> tempVar = sol.array_var(); bool didit = false; - cout << "printed sol" << endl; +// cout << "printed sol" << endl; for (int i=0;i<sol.pbm().cantColumnas();i++) { - cout << "forColumnasBegin" << endl; +// cout << "forColumnasBegin" << endl; int j = 0; - cout << "grupos.size() = " << _grupos[i].size() << endl; +// cout << "grupos.size() = " << _grupos[i].size() << endl; for (int g=0; g<_grupos[i].size(); g++) { - cout << "forGruposBegin" << endl; - cout << "i = " << i << endl; - cout << "j = " << j << endl; +// cout << "forGruposBegin" << endl; +// cout << "i = " << i << endl; +// cout << "j = " << j << endl; //cout << "sol.var(i, j) = " << sol.var(i,j) << endl; while (sol.var(i, j) != 1) { j+= 1; //cout << "sol.var(i, j) = " << sol.var(i,j) << endl; } - cout << "j after while = " << j << endl; - cout << "here?" << endl; + //cout << "j after while = " << j << endl; + //cout << "here?" << endl; if (rand01()<=probability[1]) { didit = true; - cout << "selectedForMutation" << endl; + //cout << "selectedForMutation" << endl; int selector = rand_int(0, 1); if (selector == 0) { - cout << "selector0Begin" << endl; + //cout << "selector0Begin" << endl; if ((j-2 >= 0) && (sol.var(i, j - 2) == 0)) { sol.var(i, j - 1) = 1; @@ -951,11 +978,11 @@ skeleton newGA sol.var(i, j + _grupos[i][g]) = 1; j = j + _grupos [i][g] + 1; } - cout << "selector0End" << endl; + //cout << "selector0End" << endl; } else { - cout << "selector1Begin" << endl; + //cout << "selector1Begin" << endl; if ((j + _grupos[i][g] + 1 < sol.pbm().cantFilas()) && (sol.var(i, j + _grupos[i][g] + 1) == 0)) { sol.var(i, j) = 0; @@ -968,7 +995,7 @@ skeleton newGA sol.var(i, j + _grupos[i][g] - 1) = 0; j = j + _grupos [i][g] - 1; } - cout << "selector1End" << endl; + //cout << "selector1End" << endl; } } else @@ -976,32 +1003,33 @@ skeleton newGA j = j + _grupos[i][g]; } - cout << "forGruposEnd" << endl; + //cout << "forGruposEnd" << endl; } - cout << "forColumnasEnd" << endl; + //cout << "forColumnasEnd" << endl; } - cout << "secondPrint: " << endl; - for (int fil = 0; fil < sol.pbm().cantFilas(); fil++) - { +// cout << "secondPrint: " << endl; + for (int fil = 0; fil < sol.pbm().cantFilas(); fil++) + { for(int col = 0; col < sol.pbm().cantColumnas(); col++) { - cout << sol.var(col, fil) << " "; - //if (sol.var(col, fil) != 0 && sol.var(col, fil) != 1) - //{ - //exit(EXIT_FAILURE); - //} + //cout << sol.var(col, fil) << " "; + if (sol.var(col, fil) != 0 && sol.var(col, fil) != 1) + { + cout << "mutation end" << endl; + exit(EXIT_FAILURE); + } } - cout << endl; +// cout << endl; } - if (didit) + /*if (didit) { exit(EXIT_FAILURE); - } + }*/ - cout << "ESTOY SALIENDO DE MUTATION" << endl; +// cout << "ESTOY SALIENDO DE MUTATION" << endl; } void Mutation::execute(Rarray<Solution*>& sols) const diff --git a/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/newGA.req.o b/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/newGA.req.o index bf75e3bb74e95103c2dc4c05f0132026453f27b3..5870685a5daf0898db697bf8fad0813ac1df73ec 100644 Binary files a/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/newGA.req.o and b/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/newGA.req.o differ diff --git a/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/res/sol.txt b/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/res/sol.txt index 4ce60fb2a68c2cd84f1ad181bc4066f3a062c2d3..f5ffab34a78455b600466253486c4c2a238a1603 100644 --- a/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/res/sol.txt +++ b/ProyectoFinal/AlgoritmoGenetico/malva/rep/GA/res/sol.txt @@ -3,14 +3,14 @@ STATISTICS OF TRIALS ------------------------------------------------------------------ -1 22300 57300 860 8 40337 383813 -2 21300 54200 1160 11 47287 413008 -3 17200 58400 160 1 4412 373711 -4 23300 52200 60 0 0 377470 -5 15000 62400 1060 10 39140 377810 -6 19500 53400 760 7 29629 410845 -7 20300 59200 460 4 13027 378379 -8 15100 57100 1060 10 31828 394500 -9 18300 61300 560 5 30163 407316 -10 18300 61400 560 5 15957 393246 +1 14000 51100 1960 19 11244 56560 +2 14200 56400 1460 14 7515 52727 +3 9000 55200 2460 24 10842 44523 +4 12200 56400 2060 20 8742 43456 +5 11000 52200 9660 96 48456 50138 +6 15100 54300 3960 39 17263 47436 +7 14400 52200 1760 17 12878 56495 +8 18100 63500 1960 19 8947 50044 +9 10100 51200 1260 12 5809 44501 +10 14300 58300 7560 75 34227 44742 ------------------------------------------------------------------