[8] | 1 | /**CFile*********************************************************************** |
---|
| 2 | |
---|
| 3 | FileName [cuddLiteral.c] |
---|
| 4 | |
---|
| 5 | PackageName [cudd] |
---|
| 6 | |
---|
| 7 | Synopsis [Functions for manipulation of literal sets represented by |
---|
| 8 | BDDs.] |
---|
| 9 | |
---|
| 10 | Description [External procedures included in this file: |
---|
| 11 | <ul> |
---|
| 12 | <li> Cudd_bddLiteralSetIntersection() |
---|
| 13 | </ul> |
---|
| 14 | Internal procedures included in this file: |
---|
| 15 | <ul> |
---|
| 16 | <li> cuddBddLiteralSetIntersectionRecur() |
---|
| 17 | </ul>] |
---|
| 18 | |
---|
| 19 | Author [Fabio Somenzi] |
---|
| 20 | |
---|
| 21 | Copyright [Copyright (c) 1995-2004, Regents of the University of Colorado |
---|
| 22 | |
---|
| 23 | All rights reserved. |
---|
| 24 | |
---|
| 25 | Redistribution and use in source and binary forms, with or without |
---|
| 26 | modification, are permitted provided that the following conditions |
---|
| 27 | are met: |
---|
| 28 | |
---|
| 29 | Redistributions of source code must retain the above copyright |
---|
| 30 | notice, this list of conditions and the following disclaimer. |
---|
| 31 | |
---|
| 32 | Redistributions in binary form must reproduce the above copyright |
---|
| 33 | notice, this list of conditions and the following disclaimer in the |
---|
| 34 | documentation and/or other materials provided with the distribution. |
---|
| 35 | |
---|
| 36 | Neither the name of the University of Colorado nor the names of its |
---|
| 37 | contributors may be used to endorse or promote products derived from |
---|
| 38 | this software without specific prior written permission. |
---|
| 39 | |
---|
| 40 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
| 41 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
| 42 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
---|
| 43 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
---|
| 44 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
---|
| 45 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
---|
| 46 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
---|
| 47 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
---|
| 48 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
| 49 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
---|
| 50 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
| 51 | POSSIBILITY OF SUCH DAMAGE.] |
---|
| 52 | |
---|
| 53 | ******************************************************************************/ |
---|
| 54 | |
---|
| 55 | #include "util.h" |
---|
| 56 | #include "cuddInt.h" |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | /*---------------------------------------------------------------------------*/ |
---|
| 60 | /* Constant declarations */ |
---|
| 61 | /*---------------------------------------------------------------------------*/ |
---|
| 62 | |
---|
| 63 | /*---------------------------------------------------------------------------*/ |
---|
| 64 | /* Stucture declarations */ |
---|
| 65 | /*---------------------------------------------------------------------------*/ |
---|
| 66 | |
---|
| 67 | /*---------------------------------------------------------------------------*/ |
---|
| 68 | /* Type declarations */ |
---|
| 69 | /*---------------------------------------------------------------------------*/ |
---|
| 70 | |
---|
| 71 | /*---------------------------------------------------------------------------*/ |
---|
| 72 | /* Variable declarations */ |
---|
| 73 | /*---------------------------------------------------------------------------*/ |
---|
| 74 | |
---|
| 75 | #ifndef lint |
---|
| 76 | static char rcsid[] DD_UNUSED = "$Id: cuddLiteral.c,v 1.8 2004/08/13 18:04:50 fabio Exp $"; |
---|
| 77 | #endif |
---|
| 78 | |
---|
| 79 | /*---------------------------------------------------------------------------*/ |
---|
| 80 | /* Macro declarations */ |
---|
| 81 | /*---------------------------------------------------------------------------*/ |
---|
| 82 | |
---|
| 83 | /**AutomaticStart*************************************************************/ |
---|
| 84 | |
---|
| 85 | /*---------------------------------------------------------------------------*/ |
---|
| 86 | /* Static function prototypes */ |
---|
| 87 | /*---------------------------------------------------------------------------*/ |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | /**AutomaticEnd***************************************************************/ |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | /*---------------------------------------------------------------------------*/ |
---|
| 94 | /* Definition of exported functions */ |
---|
| 95 | /*---------------------------------------------------------------------------*/ |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | /**Function******************************************************************** |
---|
| 99 | |
---|
| 100 | Synopsis [Computes the intesection of two sets of literals |
---|
| 101 | represented as BDDs.] |
---|
| 102 | |
---|
| 103 | Description [Computes the intesection of two sets of literals |
---|
| 104 | represented as BDDs. Each set is represented as a cube of the |
---|
| 105 | literals in the set. The empty set is represented by the constant 1. |
---|
| 106 | No variable can be simultaneously present in both phases in a set. |
---|
| 107 | Returns a pointer to the BDD representing the intersected sets, if |
---|
| 108 | successful; NULL otherwise.] |
---|
| 109 | |
---|
| 110 | SideEffects [None] |
---|
| 111 | |
---|
| 112 | ******************************************************************************/ |
---|
| 113 | DdNode * |
---|
| 114 | Cudd_bddLiteralSetIntersection( |
---|
| 115 | DdManager * dd, |
---|
| 116 | DdNode * f, |
---|
| 117 | DdNode * g) |
---|
| 118 | { |
---|
| 119 | DdNode *res; |
---|
| 120 | |
---|
| 121 | do { |
---|
| 122 | dd->reordered = 0; |
---|
| 123 | res = cuddBddLiteralSetIntersectionRecur(dd,f,g); |
---|
| 124 | } while (dd->reordered == 1); |
---|
| 125 | return(res); |
---|
| 126 | |
---|
| 127 | } /* end of Cudd_bddLiteralSetIntersection */ |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | /*---------------------------------------------------------------------------*/ |
---|
| 131 | /* Definition of internal functions */ |
---|
| 132 | /*---------------------------------------------------------------------------*/ |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | /**Function******************************************************************** |
---|
| 136 | |
---|
| 137 | Synopsis [Performs the recursive step of |
---|
| 138 | Cudd_bddLiteralSetIntersection.] |
---|
| 139 | |
---|
| 140 | Description [Performs the recursive step of |
---|
| 141 | Cudd_bddLiteralSetIntersection. Scans the cubes for common variables, |
---|
| 142 | and checks whether they agree in phase. Returns a pointer to the |
---|
| 143 | resulting cube if successful; NULL otherwise.] |
---|
| 144 | |
---|
| 145 | SideEffects [None] |
---|
| 146 | |
---|
| 147 | ******************************************************************************/ |
---|
| 148 | DdNode * |
---|
| 149 | cuddBddLiteralSetIntersectionRecur( |
---|
| 150 | DdManager * dd, |
---|
| 151 | DdNode * f, |
---|
| 152 | DdNode * g) |
---|
| 153 | { |
---|
| 154 | DdNode *res, *tmp; |
---|
| 155 | DdNode *F, *G; |
---|
| 156 | DdNode *fc, *gc; |
---|
| 157 | DdNode *one; |
---|
| 158 | DdNode *zero; |
---|
| 159 | unsigned int topf, topg, comple; |
---|
| 160 | int phasef, phaseg; |
---|
| 161 | |
---|
| 162 | statLine(dd); |
---|
| 163 | if (f == g) return(f); |
---|
| 164 | |
---|
| 165 | F = Cudd_Regular(f); |
---|
| 166 | G = Cudd_Regular(g); |
---|
| 167 | one = DD_ONE(dd); |
---|
| 168 | |
---|
| 169 | /* Here f != g. If F == G, then f and g are complementary. |
---|
| 170 | ** Since they are two cubes, this case only occurs when f == v, |
---|
| 171 | ** g == v', and v is a variable or its complement. |
---|
| 172 | */ |
---|
| 173 | if (F == G) return(one); |
---|
| 174 | |
---|
| 175 | zero = Cudd_Not(one); |
---|
| 176 | topf = cuddI(dd,F->index); |
---|
| 177 | topg = cuddI(dd,G->index); |
---|
| 178 | /* Look for a variable common to both cubes. If there are none, this |
---|
| 179 | ** loop will stop when the constant node is reached in both cubes. |
---|
| 180 | */ |
---|
| 181 | while (topf != topg) { |
---|
| 182 | if (topf < topg) { /* move down on f */ |
---|
| 183 | comple = f != F; |
---|
| 184 | f = cuddT(F); |
---|
| 185 | if (comple) f = Cudd_Not(f); |
---|
| 186 | if (f == zero) { |
---|
| 187 | f = cuddE(F); |
---|
| 188 | if (comple) f = Cudd_Not(f); |
---|
| 189 | } |
---|
| 190 | F = Cudd_Regular(f); |
---|
| 191 | topf = cuddI(dd,F->index); |
---|
| 192 | } else if (topg < topf) { |
---|
| 193 | comple = g != G; |
---|
| 194 | g = cuddT(G); |
---|
| 195 | if (comple) g = Cudd_Not(g); |
---|
| 196 | if (g == zero) { |
---|
| 197 | g = cuddE(G); |
---|
| 198 | if (comple) g = Cudd_Not(g); |
---|
| 199 | } |
---|
| 200 | G = Cudd_Regular(g); |
---|
| 201 | topg = cuddI(dd,G->index); |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | /* At this point, f == one <=> g == 1. It suffices to test one of them. */ |
---|
| 206 | if (f == one) return(one); |
---|
| 207 | |
---|
| 208 | res = cuddCacheLookup2(dd,Cudd_bddLiteralSetIntersection,f,g); |
---|
| 209 | if (res != NULL) { |
---|
| 210 | return(res); |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | /* Here f and g are both non constant and have the same top variable. */ |
---|
| 214 | comple = f != F; |
---|
| 215 | fc = cuddT(F); |
---|
| 216 | phasef = 1; |
---|
| 217 | if (comple) fc = Cudd_Not(fc); |
---|
| 218 | if (fc == zero) { |
---|
| 219 | fc = cuddE(F); |
---|
| 220 | phasef = 0; |
---|
| 221 | if (comple) fc = Cudd_Not(fc); |
---|
| 222 | } |
---|
| 223 | comple = g != G; |
---|
| 224 | gc = cuddT(G); |
---|
| 225 | phaseg = 1; |
---|
| 226 | if (comple) gc = Cudd_Not(gc); |
---|
| 227 | if (gc == zero) { |
---|
| 228 | gc = cuddE(G); |
---|
| 229 | phaseg = 0; |
---|
| 230 | if (comple) gc = Cudd_Not(gc); |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | tmp = cuddBddLiteralSetIntersectionRecur(dd,fc,gc); |
---|
| 234 | if (tmp == NULL) { |
---|
| 235 | return(NULL); |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | if (phasef != phaseg) { |
---|
| 239 | res = tmp; |
---|
| 240 | } else { |
---|
| 241 | cuddRef(tmp); |
---|
| 242 | if (phasef == 0) { |
---|
| 243 | res = cuddBddAndRecur(dd,Cudd_Not(dd->vars[F->index]),tmp); |
---|
| 244 | } else { |
---|
| 245 | res = cuddBddAndRecur(dd,dd->vars[F->index],tmp); |
---|
| 246 | } |
---|
| 247 | if (res == NULL) { |
---|
| 248 | Cudd_RecursiveDeref(dd,tmp); |
---|
| 249 | return(NULL); |
---|
| 250 | } |
---|
| 251 | cuddDeref(tmp); /* Just cuddDeref, because it is included in result */ |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | cuddCacheInsert2(dd,Cudd_bddLiteralSetIntersection,f,g,res); |
---|
| 255 | |
---|
| 256 | return(res); |
---|
| 257 | |
---|
| 258 | } /* end of cuddBddLiteralSetIntersectionRecur */ |
---|
| 259 | |
---|
| 260 | |
---|
| 261 | /*---------------------------------------------------------------------------*/ |
---|
| 262 | /* Definition of static functions */ |
---|
| 263 | /*---------------------------------------------------------------------------*/ |
---|
| 264 | |
---|