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
|
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
FILE *F_cost;
FILE *F_fitness;
FILE *F_alias;
FILE *F_mutate;
void open_logs(void)
{
F_alias = fopen("./log/alias.log", "w+");
F_mutate = fopen("./log/mutate.log", "w+");
F_fitness = fopen("./log/fitness.log", "w+");
F_cost = fopen("./log/cost.log", "w+");
}
void close_logs(void)
{
fclose(F_cost);
fclose(F_alias);
fclose(F_mutate);
fclose(F_fitness);
}
void log_cost(const char *fmt, ...)
{
va_list ap;
if (F_cost != NULL && ferror(F_cost) == 0) {
va_start(ap, fmt);
vfprintf(F_cost, fmt, ap);
va_end(ap);
}
}
void log_fitness(const char *fmt, ...)
{
va_list ap;
if (F_fitness != NULL && ferror(F_fitness) == 0) {
va_start(ap, fmt);
vfprintf(F_fitness, fmt, ap);
va_end(ap);
}
}
void log_alias(const char *fmt, ...)
{
va_list ap;
if (F_alias != NULL && ferror(F_alias) == 0) {
va_start(ap, fmt);
vfprintf(F_alias, fmt, ap);
va_end(ap);
}
}
void log_mutate(const char *fmt, ...)
{
va_list ap;
if (F_mutate != NULL && ferror(F_mutate) == 0) {
va_start(ap, fmt);
vfprintf(F_mutate, fmt, ap);
va_end(ap);
}
}
|