File: fixed.c

package info (click to toggle)
tablix2 0.3.3-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 9,816 kB
  • ctags: 2,970
  • sloc: ansic: 21,647; xml: 12,230; sh: 9,879; makefile: 762; perl: 564; yacc: 288
file content (84 lines) | stat: -rw-r--r-- 1,380 bytes parent folder | download | duplicates (5)
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
#include <stdlib.h>
#include "module.h"

#define	RESTYPE		"dummy-type"

struct fixed {
	int tupleid;
	int resid;
};

static int fixed_num;
static struct fixed *fixed_tuples;

static resourcetype *dummy;

int handler(char *restriction, char *content, tupleinfo *tuple)
{
	int resid;

	resid=res_findid(dummy, content);
	if(resid==INT_MIN) {
		error(_("Resource '%s' not found"), content);
		return -1;
	}

	fixed_tuples[fixed_num].resid=resid;
	fixed_tuples[fixed_num].tupleid=tuple->tupleid;

	fixed_num++;

	return 0;
}

int fitness(chromo **c, ext **e, slist **s)
{
	chromo *dummy_c;
	int n, sum;
	int tupleid, resid;

	dummy_c=c[0];

	sum=0;

	for(n=0;n<fixed_num;n++) {
		tupleid=fixed_tuples[n].tupleid;
		resid=fixed_tuples[n].resid;

		if(dummy_c->gen[tupleid]!=resid) sum++;
	}

	return sum;
}

int module_init(moduleoption *opt)
{
	fitnessfunc *f;

	dummy=restype_find(RESTYPE);
	if(dummy==NULL) {
		error(_("Resource type '%s' not found"), RESTYPE);
		return -1;
	}

	fixed_tuples=malloc(sizeof(*fixed_tuples)*dat_tuplenum);
	fixed_num=0;

	if(fixed_tuples==NULL) {
		error(_("Can't allocate memory"));
		return -1;
	}

	if(handler_tup_new("fixed-" RESTYPE, handler)==NULL) return -1;

	f=fitness_new("fixed-" RESTYPE,
		option_int(opt, "weight"),
		option_int(opt, "mandatory"),
		fitness);

	if(f==NULL) return -1;

	fitness_request_chromo(f, RESTYPE);

	return(0);
}