-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalap-tool.c
91 lines (73 loc) · 1.74 KB
/
alap-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
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
/**
* alap-tool.c
* Copyright (C) 2012 Jan Viktorin
*/
#include "chromo.h"
#include "chromo_def.h"
#include "alap.h"
#include "cgp_config.h"
#include <stdio.h>
#include <stdlib.h>
int cell_in_list(const struct cell_t *list, const struct cell_t *cell)
{
const struct cell_t *curr;
for(curr = list; curr != NULL; curr = curr->next) {
if(curr == cell)
return 1;
}
return 0;
}
void print_cell(const struct cell_t *cell)
{
printf("%d ", cell->f);
for(size_t j = 0; j < func_inputs_max(); ++j)
printf("%zu ", cell->inputs[j]);
}
void plumb_cell(const struct cell_t *cell)
{
printf("-1 ");
for(size_t j = 0; j < func_inputs_max(); ++j)
printf("-1 ");
}
void print_chromo_without(const struct chromo_t *c, const struct cell_t *list)
{
printf("%d %d ", CGP_WIDTH, CGP_HEIGHT);
printf("%d %d ", CGP_INPUTS, CGP_OUTPUTS);
printf("%zu %zu ", func_inputs_max(), func_outputs_max());
for(size_t i = 0; i < CGP_WIDTH * CGP_HEIGHT; ++i) {
const struct cell_t *cell = c->cell + i;
if(cell_in_list(list, cell))
print_cell(cell);
else
plumb_cell(cell);
}
for(size_t j = 0; j < CGP_OUTPUTS; ++j)
printf("%zu ", c->outputs[j]);
}
int main(int argc, char **argv)
{
struct chromo_t *c = chromo_alloc(1);
if(c == NULL) {
fprintf(stderr, "Chromosome allocation failed\n");
return 1;
}
int err;
if((err = chromo_parse(stdin, c))) {
fprintf(stderr, "Can not parse the chromosome: %d\n", err);
return 2;
}
struct cell_t *alap = chromo_alap(c);
print_chromo_without(c, alap);
printf("\n");
struct cell_t *curr;
size_t count = 0;
for(curr = alap; curr != NULL; curr = curr->next) {
printf("[%zu ", curr->id);
print_cell(curr);
printf("\b] ");
count += 1;
}
printf("\nCells: %zu\n", count);
chromo_free(c);
return 0;
}