-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfitness-tool.c
49 lines (40 loc) · 882 Bytes
/
fitness-tool.c
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
/**
* fitness-tool.c
* Copyright (C) 2012 Jan Viktorin
*/
#include "chromo.h"
#include "fitness.h"
int main(int argc, char **argv)
{
int ccount = 1;
if(argc >= 2)
ccount = atoi(argv[1]);
if(ccount <= 0) {
fprintf(stderr, "Chromosome count must be a positive number\n");
return 1;
}
struct chromo_t *c = chromo_alloc((size_t) ccount);
int err = 0;
for(int i = 0; i < ccount; ++i) {
if(chromo_parse(stdin, chromo_at(c, (size_t) i))) {
fprintf(stderr, "Chromosome number %d couldn't be parsed\n", i);
err = 1;
}
}
if(err) {
chromo_free(c);
return 2;
}
for(int i = 0; i < ccount; ++i) {
fitness_t value;
if(fitness_compute(chromo_at(c, (size_t) i), &value)) {
fprintf(stderr, "Failed to compute fitness for chromosome %d\n", i);
err = 1;
}
else {
printf(FITNESS_FMT "\n", value);
}
}
chromo_free(c);
return err? 3 : 0;
}