diff --git a/malva/rep/GA/newGA.req.cc b/malva/rep/GA/newGA.req.cc index 60436aca27e590cd44d019597aec9a79252d2b7d..20168e31103be644d371db55df3753bdfd479d14 100644 --- a/malva/rep/GA/newGA.req.cc +++ b/malva/rep/GA/newGA.req.cc @@ -2,7 +2,7 @@ #define INC_REQ_newGA #include "newGA.hh" #include <math.h> - +#include <sstream> skeleton newGA { @@ -20,16 +20,81 @@ skeleton newGA istream& operator>> (istream& is, Problem& pbm) { - - FILE* stream = fopen("ejercicio1_cantidad_tareas", "r"); + /* char buffer[MAX_BUFFER]; int i; - is.getline(buffer,MAX_BUFFER,'\n'); + + is.getline(buffer,MAX_BUFFER,'\n'); sscanf(buffer,"%d",&pbm._dimension); + */ + + string line; + ifstream cantTareasFile ("datos_cantidad_tareas.txt"); + getline(cantTareasFile, line); + pbm._dimension = stoi(line); + + //string line; + ifstream cantEmpleadosFile ("datos_cantidad_empleados.txt"); + getline(cantEmpleadosFile, line); + pbm._cantEmpleados = stoi(line); + + string line23; + ifstream datosEmpleadosFile ("datos_empleados.txt"); + getline(datosEmpleadosFile, line23); + getline(datosEmpleadosFile, line23); + int i1; + int counter1 = 0; + stringstream os(line23); + /*Rarray<Empleado> tempEmpleados*/ pbm._empleados = Rarray<Empleado>(pbm._cantEmpleados); + //pbm._empleados = tempEmpleados; + for (int zz=0;zz<pbm._cantEmpleados;zz++) + { + //+pbm._empleados[zz] = new Empleado; + pbm._empleados[zz]._sueldo = 0; + pbm._empleados[zz]._habilidad=0; + pbm._empleados[zz]._horas=0; + } + while (os >> i1) + { + pbm._empleados[counter1]._horas = i1; + cout << pbm._empleados[counter1]._horas << endl; + counter1 += 1; + } + getline(datosEmpleadosFile, line); + float f1; + int counter2 = 0; + stringstream os2(line); + while (os2 >> f1) + { + pbm._empleados[counter2]._habilidad = f1; + counter2 += 1; + } + getline(datosEmpleadosFile, line); + int i2; + int counter3 = 0; + stringstream os3(line); + while (os3 >> i2) + { + pbm._empleados[counter3]._sueldo = i2; + counter3 += 1; + } + + //string line; + ifstream datosTareasFile ("datos_tareas.txt"); + getline(datosTareasFile, line); + pbm._cantDias = stoi(line); + getline(datosTareasFile, line); + getline(datosTareasFile, line); + int i3; + int counter4 = 0; + stringstream os4(line); + while (os4 >> i3) + { + pbm._tareasEsf[counter4] = i3; + counter4 += 1; + } + - cout << buffer[3] << buffer[4] << endl; - assert(false); - return is; } @@ -61,15 +126,18 @@ skeleton newGA Problem::~Problem() { } - - Rarray<Empleado>& Problem::empleadoss() + int Problem::cantDias() const + { + return _cantDias; + } + Rarray<Empleado> Problem::empleados() const { return _empleados; } - Rarray<int>& Problem::tareasDiass() + Rarray<int> Problem::tareasEsf() const { - return _tareasDias; + return _tareasEsf; } // Solution -------------------------------------------------------------- @@ -136,16 +204,17 @@ skeleton newGA void Solution::initialize() { for (int i=0;i<_pbm.dimension();i++) - _tareasSolucion[i]=rand() % _cantEmpleados + 1;//numero random entre 1 y CANT EMPLEADOS + _var[i]=rand() % _pbm.cantEmpleados() + 1;//numero random entre 1 y CANT EMPLEADOS } double Solution::fitness () { double fitness = 0.0; - - for (int i=0;i< _tareasSolucion.size();i++) { - int tipo = empleadoss[i]; - fitness += tipo.sueldo()*tareasDiass[i]; + Rarray<Empleado> grupo= _pbm.empleados(); + Rarray<int> soFun = _pbm.tareasEsf(); + for (int i=0;i< _var.size();i++) { + Empleado tipo = grupo[i]; + fitness += tipo._sueldo*soFun[i]; } return fitness; } @@ -292,7 +361,7 @@ skeleton newGA { int i=0; Rarray<int> aux(sol1.pbm().dimension()); - aux=sol2._tareasSolucion(); + aux=sol2.array_var(); int limit=rand_int((sol1.pbm().dimension()/2)+1,sol1.pbm().dimension()-1); int limit2=rand_int(0,limit-1); @@ -357,7 +426,7 @@ skeleton newGA { if (rand01()<=probability[1]) { - sol.var(i) = rand() % cantEmpleados + 1; + sol.var(i) = rand() % sol.pbm().cantEmpleados() + 1; //if (sol.var(i)==1) sol.var(i)=0; //else sol.var(i)=1; }