1 /**CHeaderFile*****************************************************************
7 Synopsis [Low level functions to read in and write out bdds to file]
9 Description [A set of internal low-level routines of the dddmp package
12 <li> read and write of node codes in binary mode,
13 <li> read and write of integers in binary mode,
14 <li> marking/unmarking nodes as visited,
19 Author [Gianpiero Cabodi and Stefano Quer]
22 Copyright (c) 2002 by Politecnico di Torino.
23 All Rights Reserved. This software is for educational purposes only.
24 Permission is given to academic institutions to use, copy, and modify
25 this software and its documentation provided that this introductory
26 message is not removed, that this software and its documentation is
27 used for the institutions' internal research and educational purposes,
28 and that no monies are exchanged. No guarantee is expressed or implied
29 by the distribution of this code.
30 Send bug-reports and/or questions to:
31 {gianpiero.cabodi,stefano.quer}@polito.it.
34 ******************************************************************************/
46 /*---------------------------------------------------------------------------*/
47 /* Constant declarations */
48 /*---------------------------------------------------------------------------*/
50 /* constants for code fields */
51 #define DDDMP_TERMINAL 0
52 #define DDDMP_ABSOLUTE_ID 1
53 #define DDDMP_RELATIVE_ID 2
54 #define DDDMP_RELATIVE_1 3
56 #define DDDMP_MAXSTRLEN 500
58 /*---------------------------------------------------------------------------*/
59 /* Type declarations */
60 /*---------------------------------------------------------------------------*/
62 /*---------------------------------------------------------------------------*/
63 /* Structure declarations */
64 /*---------------------------------------------------------------------------*/
66 /**Struct**********************************************************************
67 Synopsis [used in binary mode to store code info of a dd node]
68 Description [V , T , E store the mode used to represent variable, Then
69 and Else indexes. An index is either an absolute
70 ( DDDMP_ABSOLUTE_ID ),
71 a relative numbers ( DDDMP_RELATIVE_ID , DDDMP_RELATIVE_1 ) or
72 a terminal node ( DDDMP_TERMINAL ) .
73 Ecomp is used for the complemented edge attribute.
76 SeeAlso [DddmpWriteCode DddmpReadCode]
77 ******************************************************************************/
79 struct binary_dd_code
{
87 /**Struct*********************************************************************
89 Synopsis [BDD file header]
91 Description [Structure containing the BDD header file infos]
93 ******************************************************************************/
98 Dddmp_DecompType ddType
;
99 Dddmp_VarInfoType varinfo
;
104 char **orderedVarNames
;
118 /*---------------------------------------------------------------------------*/
119 /* Variable declarations */
120 /*---------------------------------------------------------------------------*/
122 /*---------------------------------------------------------------------------*/
123 /* Macro declarations */
124 /*---------------------------------------------------------------------------*/
126 /**Macro***********************************************************************
128 Synopsis [Memory Allocation Macro for DDDMP]
136 ******************************************************************************/
139 # define DDDMP_ALLOC(type, num) ALLOC(type,num)
141 # define DDDMP_ALLOC(type, num) \
142 ((type *) malloc(sizeof(type) * (num)))
145 /**Macro***********************************************************************
147 Synopsis [Memory Free Macro for DDDMP]
155 ******************************************************************************/
158 #define DDDMP_FREE(p) (FREE(p))
160 #define DDDMP_FREE(p) \
161 ((p)!=NULL)?(free(p)):0)
165 /**AutomaticStart*************************************************************/
167 /*---------------------------------------------------------------------------*/
168 /* Function prototypes */
169 /*---------------------------------------------------------------------------*/
171 extern int DddmpWriteCode(FILE *fp
, struct binary_dd_code code
);
172 extern int DddmpReadCode(FILE *fp
, struct binary_dd_code
*pcode
);
173 extern int DddmpWriteInt(FILE *fp
, int id
);
174 extern int DddmpReadInt(FILE *fp
, int *pid
);
175 extern int DddmpNumberAddNodes(DdManager
*ddMgr
, DdNode
**f
, int n
);
176 extern void DddmpUnnumberAddNodes(DdManager
*ddMgr
, DdNode
**f
, int n
);
177 extern void DddmpWriteNodeIndexAdd(DdNode
*f
, int id
);
178 extern int DddmpReadNodeIndexAdd(DdNode
*f
);
179 extern int DddmpVisitedAdd(DdNode
*f
);
180 extern void DddmpSetVisitedAdd(DdNode
*f
);
181 extern void DddmpClearVisitedAdd(DdNode
*f
);
182 extern int DddmpNumberBddNodes(DdManager
*ddMgr
, DdNode
**f
, int n
);
183 extern void DddmpUnnumberBddNodes(DdManager
*ddMgr
, DdNode
**f
, int n
);
184 extern void DddmpWriteNodeIndexBdd(DdNode
*f
, int id
);
185 extern int DddmpReadNodeIndexBdd(DdNode
*f
);
186 extern int DddmpVisitedBdd(DdNode
*f
);
187 extern void DddmpSetVisitedBdd(DdNode
*f
);
188 extern void DddmpClearVisitedBdd(DdNode
*f
);
189 extern int DddmpNumberDdNodesCnf(DdManager
*ddMgr
, DdNode
**f
, int rootN
, int *cnfIds
, int id
);
190 extern int DddmpDdNodesCountEdgesAndNumber(DdManager
*ddMgr
, DdNode
**f
, int rootN
, int edgeInTh
, int pathLengthTh
, int *cnfIds
, int id
);
191 extern void DddmpUnnumberDdNodesCnf(DdManager
*ddMgr
, DdNode
**f
, int rootN
);
192 extern int DddmpPrintBddAndNext(DdManager
*ddMgr
, DdNode
**f
, int rootN
);
193 extern int DddmpWriteNodeIndexCnf(DdNode
*f
, int id
);
194 extern int DddmpVisitedCnf(DdNode
*f
);
195 extern void DddmpSetVisitedCnf(DdNode
*f
);
196 extern int DddmpReadNodeIndexCnf(DdNode
*f
);
197 extern int DddmpCuddDdArrayStoreBdd(Dddmp_DecompType ddType
, DdManager
*ddMgr
, char *ddname
, int nRoots
, DdNode
**f
, char **rootnames
, char **varnames
, int *auxids
, int mode
, Dddmp_VarInfoType varinfo
, char *fname
, FILE *fp
);
198 extern int DddmpCuddBddArrayStore(Dddmp_DecompType ddType
, DdManager
*ddMgr
, char *ddname
, int nRoots
, DdNode
**f
, char **rootnames
, char **varnames
, int *auxids
, int mode
, Dddmp_VarInfoType varinfo
, char *fname
, FILE *fp
);
199 extern int QsortStrcmp(const void *ps1
, const void *ps2
);
200 extern int FindVarname(char *name
, char **array
, int n
);
201 extern char * DddmpStrDup(char *str
);
202 extern char ** DddmpStrArrayDup(char **array
, int n
);
203 extern char ** DddmpStrArrayRead(FILE *fp
, int n
);
204 extern int DddmpStrArrayWrite(FILE *fp
, char **array
, int n
);
205 extern void DddmpStrArrayFree(char **array
, int n
);
206 extern int * DddmpIntArrayDup(int *array
, int n
);
207 extern int * DddmpIntArrayRead(FILE *fp
, int n
);
208 extern int DddmpIntArrayWrite(FILE *fp
, int *array
, int n
);
210 /**AutomaticEnd***************************************************************/