-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages.h
103 lines (97 loc) · 2.17 KB
/
messages.h
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
void ip(Chromo *population, int p, int N)
{
for (int j = 0; j < p; j++)
{
printf("Gen: %d [ ", j);
for (int i = 0; i < N; i++)
{
printf(" %d ", population[j].config[i] + 1);
}
printf("] fitnes ==> %d \n", population[j].fitness);
}
}
void printConf(int *conf, int N)
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
if (conf[j] == i)
{
printf(" %c ", 'X');
}
else
{
printf(" %c ", '_');
}
}
printf("\n");
}
}
void confFinal(Chromo Best, int N, clock_t start, int numMaxGen)
{
printf("\n\n=============================================\n");
printf("La mejor solucion tiene un fit de %d \n", Best.fitness);
printf("La mejor solucion es: [ ");
for (int i = 0; i < N; i++)
{
printf(" %d ", Best.config[i] + 1);
}
printf("]\n");
if (N > 15)
{
printConf(Best.config, N);
}
else
{
imprimeTablero(Best.config, N);
}
printf("\n===============================================\n");
printf("Numero de generaciones transcurridas: %d\n", numMaxGen);
printf("Tiempo transcurrido: %2.10f seg.\n", ((double)clock() - start) / CLOCKS_PER_SEC);
}
void imprimeTablero(int *conf, int N)
{
printf("\n\n");
int i, j, aux;
aux = N;
printf(" ");
for (i = (N - 1); i >= 0; i--)
{
printf(" %c ", i + 65);
}
printf("\n ");
for (i = 0; i < N; i++)
{
printf(" ------");
}
printf("\n");
for (i = 0; i < N; i++)
{
printf("%d |", aux--);
for (j = 0; j < N; j++)
{
printf(" |");
}
printf("\n |");
for (j = 0; j < N; j++)
{
if (conf[j] == i)
{
printf(" Q |");
}
else
{
printf(" |");
}
}
printf("\n");
printf(" ");
for (int k = 0; k < N; k++)
{
printf(" ------");
}
printf("\n");
}
printf("\n\n");
}