Skip to content
Snippets Groups Projects
Commit 09449d52 authored by Gonzalo Menéndez's avatar Gonzalo Menéndez
Browse files

generador

parent 5032374e
No related branches found
No related tags found
No related merge requests found
import sys
import random
import math
from collections import defaultdict
try:
#Constantes
width = 10
height = 10
archivo_salida = "placeholder"
#Sanity check
if (len(sys.argv)<4):
print "Ejecutar con la siguiente linea: ./generador <width> <height> <archivo_salida>"
sys.exit(1)
width=int(sys.argv[1])
height=int(sys.argv[2])
archivo_salida=sys.argv[3]
if (width<1):
print "La cantidad de columnas debe ser mayor o igual a 1."
sys.exit(1)
if (height<1):
print "La cantidad de filas debe ser mayor o igual a 1."
sys.exit(1)
#VARIABLES:
#inicializacion tablero
tablero = []
for i in range(0,width):
columna = []
for j in range(0, height):
columna.append(random.int(0,1))
tablero.append(columna)
######################
#calculo de datos de fila / columna
######################
datosColumnas = []
for i in range(0, width):
datos = []
counter = 0
for j in range (0, height):
if (tablero[i][j] == 0):
if (counter != 0):
datos.append(counter)
counter = 0
else:
counter += 1
if (counter != 0):
datos.append(counter)
datosColumnas.append(datos)
datosFilas = []
for i in range(0, height):
datos = []
counter = 0
for j in range (0, width):
if (tablero[j][i] == 0):
if (counter != 0):
datos.append(counter)
counter = 0
else:
counter += 1
if (counter != 0):
datos.append(counter)
datosFilas.append(datos)
#archivo de salida de columnas
archivo = open ("datos_columnas", "w")
for i in range(0, width):
for j in range(0, len(datosColumnas[i])):
archivo.write("%d "%datosColumnas[i][j])
archivo.write("\n")
archivo = open ("datos_filas", "w")
for i in range(0, height):
for j in range(0, len(datosFilas[i])):
archivo.write("%d "%datosFilas[i][j])
archivo.write("\n")
except IOError as error:
print error
......@@ -10,7 +10,7 @@
skeleton newGA
{
int currentBestFitness = INT_MAX;
// Problem ---------------------------------------------------------------
Problem::Problem ():_dimension(0),_limite_barrios(NULL),_tareasEsf(NULL),_tareasIndex(NULL),_empleados(NULL),_cantFilas(0),_cantColumnas(0),_datosFilas(NULL),_datosColumnas(NULL), _cantGruposColumna(NULL), _cantGruposFila(NULL)
......@@ -452,19 +452,25 @@ skeleton newGA
double fitness = 0.0;
int** datosDeFilas = _pbm.datosFilas();
int* cantGruposDeFila = _pbm.cantGruposFila();
for (int i=0;i<_pbm.cantFilas();i++) {
for (int i=0;i<_pbm.cantFilas();i++)
{
int cantSeguidos=0;
int columna=0;
cantGrupos= cantGruposDeFila[i];
int iteradorGrupos=0;
int resultado=0; //Resultado de la diferencia entre el bloque que tiene que haber y el bloque en el juego
boolean terminoBloque= true;
while (columna < _pbm.cantColumnas()) {
if (_var[i][columna] == 1) {
while (columna < _pbm.cantColumnas())
{
if (_var[i][columna] == 1)
{
cantSeguidos++;
terminoBloque=false;
} else {
if (!terminoBloque) {
}
else
{
if (!terminoBloque)
{
resultado= abs(datosDeFilas[i][iteradorGrupos] - cantSeguidos); //valor absoluto de la resta
fitness= 1000*resultado;
terminoBloque=true;
......@@ -475,44 +481,19 @@ skeleton newGA
}
columna++;
//Si se termino la columna y faltan bloques
if((columna == _pbm.cantColumnas() && (iteradorGrupos < cantGrupos)) {
if((columna == _pbm.cantColumnas() && (iteradorGrupos < cantGrupos))
{
int restar= cantGrupos - iteradorGrupos;
fitness= fitness + 2100*restar;
}
}
fitness= fitness + 2100*restar;
}
}
}
double fitness = 0.0;
double* horasTrabajados = new double[_pbm.cantEmpleados()];
for (int q=0; q < _pbm.cantEmpleados(); q++)
{
horasTrabajados[q] = 0;
}
for (int i=0;i< _pbm.dimension();i++)
{
Empleado tipo = _pbm.empleados()[_var[i]];
double horasReq = ((double)_pbm.tareasEsf()[_pbm.tareasIndex()[i]]/(double)(0.5+tipo._habilidad));
horasTrabajados[_var[i]] += horasReq;
}
for (int j = 0; j < _pbm.cantEmpleados(); j++)
{
double diasTrabajadosTemp = (double)horasTrabajados[j] / (double)_pbm.empleados()[j]._horas;
fitness += (double)diasTrabajadosTemp * (double)_pbm.empleados()[j]._sueldo;
if (isnan(fitness))
exit(0);
if (diasTrabajadosTemp > _pbm.cantDias())
{
fitness += 100000;
}
}
extern int currentBestFitness;
if (fitness < currentBestFitness)
{
currentBestFitness = fitness;
}
return fitness;
}
char *Solution::to_String() const
......@@ -814,7 +795,7 @@ skeleton newGA
bool StopCondition_1::EvaluateCondition(const Problem& pbm,const Solver& solver,const SetUpParams& setup)
{
bool fin=(int) (solver.current_time_spent() - solver.time_best_found_trial()) > 20000000;
bool fin=(currentBestFitness == 0 || (int) (solver.current_time_spent() - solver.time_best_found_trial()) > 20000000);
//Condicion de parada. Si el fitness es 0 terminamos la ejecucion.
//bool fin=(int)solver.best_cost_trial() == 0;
//cout << pbm.cantEmpleados();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment