1 | #include "mdd.h" |
---|
2 | |
---|
3 | /* |
---|
4 | * MDD Package |
---|
5 | * |
---|
6 | * $Id: mdd_literal.c,v 1.10 2002/08/24 21:48:15 fabio Exp $ |
---|
7 | * |
---|
8 | * Author: Timothy Kam |
---|
9 | * |
---|
10 | * Copyright 1992 by the Regents of the University of California. |
---|
11 | * |
---|
12 | * All rights reserved. Permission to use, copy, modify and distribute |
---|
13 | * this software is hereby granted, provided that the above copyright |
---|
14 | * notice and this permission notice appear in all copies. This software |
---|
15 | * is made available as is, with no warranties. |
---|
16 | */ |
---|
17 | |
---|
18 | /* Returns \/_{i in values}(mddid == i) */ |
---|
19 | /* Algorithm used to be quadratic. Is linear now */ |
---|
20 | mdd_t * |
---|
21 | mdd_literal( |
---|
22 | mdd_manager *mgr, |
---|
23 | int mddid, |
---|
24 | array_t *values) |
---|
25 | { |
---|
26 | mvar_type mvar; |
---|
27 | mdd_t *one, *zero; |
---|
28 | array_t *allValues; /* Holds one in pos i iff value i is allowed */ |
---|
29 | int i; /* iterator */ |
---|
30 | int value; /* iterates over values */ |
---|
31 | mdd_t *result; |
---|
32 | |
---|
33 | mvar = mdd_get_var_by_id(mgr, mddid); |
---|
34 | one = mdd_one(mgr); |
---|
35 | zero = mdd_zero(mgr); |
---|
36 | allValues = array_alloc(mdd_t *, mvar.values); |
---|
37 | |
---|
38 | /* first set every value to zero */ |
---|
39 | for(i = 0; i < mvar.values; i++) |
---|
40 | array_insert(mdd_t *, allValues, i, zero); |
---|
41 | |
---|
42 | /* then set requested values to one */ |
---|
43 | arrayForEachItem(int, values, i, value) |
---|
44 | array_insert(mdd_t *, allValues, value, one); |
---|
45 | |
---|
46 | result = mdd_case(mgr, mddid, allValues); |
---|
47 | array_free(allValues); |
---|
48 | |
---|
49 | mdd_free(one); |
---|
50 | mdd_free(zero); |
---|
51 | |
---|
52 | return result; |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | /*---------------------------------------------------------------------------*/ |
---|
57 | /* Static function prototypes */ |
---|
58 | /*---------------------------------------------------------------------------*/ |
---|
59 | |
---|
60 | |
---|