diff --git a/malva/rep/GA/newGA.hh b/malva/rep/GA/newGA.hh index 552b2648923ec9383125099fb7ad87e4f924c4a9..4d2423e81a83d39af2f15086836bac4c5673eb07 100644 --- a/malva/rep/GA/newGA.hh +++ b/malva/rep/GA/newGA.hh @@ -62,24 +62,26 @@ skeleton newGA Direction direction () const; - int cantDias() const; - int cantEmpleados() const; - int dimension() const; +//------------------------------------------------------------------------------------------------ + + int cantFilas() const; + int cantColumnas() const; - Empleado * empleados() const; - int * tareasEsf() const; - int * tareasIndex() const; - int ** limite_barrios() const; - const char* getfield(char* line, int num); + int** datosColumnas() const; + int** datosFilas() const; + + int* cantGruposColumna() const; + int* cantGruposFila() const; + + const char* getfield(char* line, int num); //??? private: - int _cantDias; - Empleado * _empleados; - int * _tareasEsf; - int * _tareasIndex; - int _cantEmpleados; - int _dimension; - int ** _limite_barrios; + int _cantFilas; + int _cantColumnas; + int** _datosColumnas; + int** _datosFilas; + int* _cantGruposColumna; + int* _cantGruposFila; }; //Solution ---------------------------------------------------------------------------- @@ -113,7 +115,7 @@ skeleton newGA Rarray<int>& array_var(); private: - Rarray<int> _var; + Rarray<Rarray<int>> _var; const Problem& _pbm; }; diff --git a/malva/rep/GA/newGA.req.cc b/malva/rep/GA/newGA.req.cc index 653d43b819666278652d4834d7116555127fdffd..4b2ffb92757b8045c8450a8cc66bc6759a5ad4bf 100644 --- a/malva/rep/GA/newGA.req.cc +++ b/malva/rep/GA/newGA.req.cc @@ -20,20 +20,11 @@ skeleton newGA ostream& operator<< (ostream& os, const Problem& pbm) { - os << endl << endl << "Number of Variables " << pbm._dimension + os << endl << endl << "Number of Columns " << pbm._cantColumnas; << endl; - //Imprimo el arreglo con los limites de barrios - os<<"Limites de barrios: "<<endl<<endl; - for (int i=0;i<pbm._dimension;i++){ - os<<i<<": "; - int indice=0; - while (pbm._limite_barrios[i][indice]!=-1){ - os<<pbm._limite_barrios[i][indice]<<","; - indice++; - } - os<<endl; - } + os << "Number of Rows " << pbm._cantFilas << endl; + os<<endl; return os; } @@ -288,42 +279,40 @@ skeleton newGA return minimize; } - int Problem::dimension() const + int Problem::cantColumnas() const { - return _dimension; + return _cantColumnas; } - int Problem::cantEmpleados() const + int Problem::cantFilas() const { - return _cantEmpleados; + return _cantFilas; } - int Problem::cantDias() const + + int ** Problem::datosFilas() const { - return _cantDias; + return _datosFilas; } - int * Problem::tareasEsf() const + int ** Problem::datosColumnas() const { - return _tareasEsf; + return _datosColumnas; } - - int * Problem::tareasIndex() const + + int * Problem::cantGruposColumna() const { - return _tareasIndex; + return _cantGruposColumna(); } - - Empleado *Problem::empleados() const + + int * Problem::cantGruposFila() const { - return _empleados; + return _cantGruposFila(); } Problem::~Problem() { //Libero la memoria pedida para almacenar los limites de los barrios - for (int i=0;i<_dimension;i++) - delete [] _limite_barrios[i]; - delete [] _limite_barrios; - delete [] _empleados; - delete [] _tareasEsf; + delete[] _datosColumnas; + delete[] _datosFilas; } // Solution -------------------------------------------------------------- @@ -425,11 +414,35 @@ skeleton newGA void Solution::initialize() { - //cout << _pbm.dimension(); - for (int i=0;i<_pbm.dimension();i++) + for (int x = 0; x < _pbm.cantColumnas(); x++) + { + for (int y = 0; y < _pbm.cantFilas(); y++) + { + _var[x][y] = 0; + } + } + + for (int i=0;i<_pbm.cantColumnas();i++) { - _var[i]=rand_int(0,_pbm.cantEmpleados() - 1); - //_var[i]=rand_int(0,3); + int _firstPossible = 0; + int** _grupos = _pbm.datosColumnas(); + int* _cantGruposEnColumna = _pbm.cantGruposColumna(); + + for(int j=0; j < _cantGruposEnColumna[i]; j++) + { + int _lastPossible = _pbm.cantFilas() - _grupos[i][j]; + for (int k=j+1; k < _cantGruposEnColumna[i]; k++) + { + _lastPossible -= _grupos[i][k] + 1; + } + + int _startPosition = rand_int(_firstPossible, _lastPossible); + int _endPosition = _startPosition + _grupos[i][j] - 1; + for(int c = _startPosition; c < _endPosition; c++) + { + _var[j][c] = 1; + } + } } }