1 | /* |
---|
2 | * $Id: mdd_bund.c,v 1.5 2002/08/27 03:24:30 fabio Exp $ |
---|
3 | */ |
---|
4 | |
---|
5 | #include "mdd.h" |
---|
6 | |
---|
7 | int |
---|
8 | mdd_bundle_variables( |
---|
9 | mdd_manager *mgr, |
---|
10 | array_t *bundle_vars, |
---|
11 | char *mdd_var_name, |
---|
12 | int *mdd_id) |
---|
13 | { |
---|
14 | array_t *mvar_list, *bvar_list; |
---|
15 | mvar_type var_i, new_var; |
---|
16 | int i, var_i_id; |
---|
17 | bvar_type *bit_i_ptr; |
---|
18 | |
---|
19 | mvar_list = mdd_ret_mvar_list(mgr); |
---|
20 | bvar_list = mdd_ret_bvar_list(mgr); |
---|
21 | |
---|
22 | new_var.mvar_id = array_n(mvar_list); |
---|
23 | *mdd_id = new_var.mvar_id; |
---|
24 | |
---|
25 | new_var.name = ALLOC( char, MAX( (int) strlen(mdd_var_name), |
---|
26 | integer_get_num_of_digits(new_var.mvar_id) + 5 ) ); |
---|
27 | |
---|
28 | if ( strcmp(mdd_var_name,"") != 0) |
---|
29 | strcpy(new_var.name, mdd_var_name); |
---|
30 | else { |
---|
31 | strcpy(new_var.name,""); |
---|
32 | sprintf(new_var.name,"mv_%d", new_var.mvar_id); |
---|
33 | }; |
---|
34 | |
---|
35 | new_var.encode_length = array_n(bundle_vars); |
---|
36 | new_var.status = MDD_ACTIVE; |
---|
37 | |
---|
38 | new_var.encoding = ALLOC(int, new_var.encode_length); |
---|
39 | |
---|
40 | new_var.bvars = array_alloc(int, 0); |
---|
41 | new_var.values = 1; |
---|
42 | |
---|
43 | for(i=0; i<array_n(bundle_vars); i++){ |
---|
44 | var_i_id = array_fetch(int, bundle_vars, i); |
---|
45 | var_i = array_fetch(mvar_type, mvar_list, var_i_id); |
---|
46 | array_append(new_var.bvars, var_i.bvars); |
---|
47 | new_var.values *= var_i.values; |
---|
48 | if ( var_i.values != (int) pow(2.0, (double)var_i.encode_length) ) |
---|
49 | printf("WARNING: Variable %s has %d values which is not a power of 2 \nmdd_bundle_variables: Bundling is ambiguous \n",var_i.name, var_i.values); |
---|
50 | var_i.status = MDD_BUNDLED; |
---|
51 | } |
---|
52 | |
---|
53 | array_insert_last( mvar_type, mvar_list, new_var); |
---|
54 | |
---|
55 | for(i=0; i< array_n(new_var.bvars); i++) { |
---|
56 | bit_i_ptr = array_fetch_p( bvar_type, bvar_list, mdd_ret_bvar_id(&new_var, i) ); |
---|
57 | bit_i_ptr->mvar_id = new_var.mvar_id; |
---|
58 | } |
---|
59 | |
---|
60 | return TRUE; |
---|
61 | |
---|
62 | } |
---|
63 | |
---|
64 | /*---------------------------------------------------------------------------*/ |
---|
65 | /* Static function prototypes */ |
---|
66 | /*---------------------------------------------------------------------------*/ |
---|
67 | |
---|
68 | |
---|