Initial revision
This commit is contained in:
parent
1fa73989e0
commit
cf5dd46350
67 changed files with 44947 additions and 0 deletions
833
buddy/src/bdd.h
Normal file
833
buddy/src/bdd.h
Normal file
|
|
@ -0,0 +1,833 @@
|
|||
/*========================================================================
|
||||
Copyright (C) 1996-2002 by Jorn Lind-Nielsen
|
||||
All rights reserved
|
||||
|
||||
Permission is hereby granted, without written agreement and without
|
||||
license or royalty fees, to use, reproduce, prepare derivative
|
||||
works, distribute, and display this software and its documentation
|
||||
for any purpose, provided that (1) the above copyright notice and
|
||||
the following two paragraphs appear in all copies of the source code
|
||||
and (2) redistributions, including without limitation binaries,
|
||||
reproduce these notices in the supporting documentation. Substantial
|
||||
modifications to this software may be copyrighted by their authors
|
||||
and need not follow the licensing terms described here, provided
|
||||
that the new terms are clearly indicated in all files where they apply.
|
||||
|
||||
IN NO EVENT SHALL JORN LIND-NIELSEN, OR DISTRIBUTORS OF THIS
|
||||
SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
|
||||
SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE
|
||||
ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
JORN LIND-NIELSEN SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
|
||||
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
||||
MODIFICATIONS.
|
||||
========================================================================*/
|
||||
|
||||
/*************************************************************************
|
||||
$Header: /Volumes/CVS/repository/spot/spot/buddy/src/bdd.h,v 1.1 2003/05/05 10:57:56 aduret Exp $
|
||||
FILE: bdd.h
|
||||
DESCR: C,C++ User interface for the BDD package
|
||||
AUTH: Jorn Lind
|
||||
DATE: (C) feb 1997
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef _BDD_H
|
||||
#define _BDD_H
|
||||
|
||||
/* Allow this headerfile to define C++ constructs if requested */
|
||||
#ifdef __cplusplus
|
||||
#define CPLUSPLUS
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/*=== Defined operators for apply calls ================================*/
|
||||
|
||||
#define bddop_and 0
|
||||
#define bddop_xor 1
|
||||
#define bddop_or 2
|
||||
#define bddop_nand 3
|
||||
#define bddop_nor 4
|
||||
#define bddop_imp 5
|
||||
#define bddop_biimp 6
|
||||
#define bddop_diff 7
|
||||
#define bddop_less 8
|
||||
#define bddop_invimp 9
|
||||
|
||||
/* Should *not* be used in bdd_apply calls !!! */
|
||||
#define bddop_not 10
|
||||
#define bddop_simplify 11
|
||||
|
||||
|
||||
/*=== User BDD types ===================================================*/
|
||||
|
||||
typedef int BDD;
|
||||
|
||||
#ifndef CPLUSPLUS
|
||||
typedef BDD bdd;
|
||||
#endif /* CPLUSPLUS */
|
||||
|
||||
|
||||
typedef struct s_bddPair
|
||||
{
|
||||
BDD *result;
|
||||
int last;
|
||||
int id;
|
||||
struct s_bddPair *next;
|
||||
} bddPair;
|
||||
|
||||
|
||||
/*=== Status information ===============================================*/
|
||||
|
||||
/*
|
||||
NAME {* bddStat *}
|
||||
SECTION {* kernel *}
|
||||
SHORT {* Status information about the bdd package *}
|
||||
PROTO {* typedef struct s_bddStat
|
||||
{
|
||||
long int produced;
|
||||
int nodenum;
|
||||
int maxnodenum;
|
||||
int freenodes;
|
||||
int minfreenodes;
|
||||
int varnum;
|
||||
int cachesize;
|
||||
int gbcnum;
|
||||
} bddStat; *}
|
||||
DESCR {* The fields are \\[\baselineskip] \begin{tabular}{lp{10cm}}
|
||||
{\tt produced} & total number of new nodes ever produced \\
|
||||
{\tt nodenum} & currently allocated number of bdd nodes \\
|
||||
{\tt maxnodenum} & user defined maximum number of bdd nodes \\
|
||||
{\tt freenodes} & number of currently free nodes \\
|
||||
{\tt minfreenodes} & minimum number of nodes that should be left after a
|
||||
garbage collection. \\
|
||||
{\tt varnum} & number of defined bdd variables \\
|
||||
{\tt cachesize} & number of entries in the internal caches \\
|
||||
{\tt gbcnum} & number of garbage collections done until now
|
||||
\end{tabular} *}
|
||||
ALSO {* bdd\_stats *}
|
||||
*/
|
||||
typedef struct s_bddStat
|
||||
{
|
||||
long int produced;
|
||||
int nodenum;
|
||||
int maxnodenum;
|
||||
int freenodes;
|
||||
int minfreenodes;
|
||||
int varnum;
|
||||
int cachesize;
|
||||
int gbcnum;
|
||||
} bddStat;
|
||||
|
||||
|
||||
/*
|
||||
NAME {* bddGbcStat *}
|
||||
SECTION {* kernel *}
|
||||
SHORT {* Status information about garbage collections *}
|
||||
PROTO {* typedef struct s_bddGbcStat
|
||||
{
|
||||
int nodes;
|
||||
int freenodes;
|
||||
long time;
|
||||
long sumtime;
|
||||
int num;
|
||||
} bddGbcStat; *}
|
||||
DESCR {* The fields are \\[\baselineskip] \begin{tabular}{ll}
|
||||
{\tt nodes} & Total number of allocated nodes in the nodetable \\
|
||||
{\tt freenodes} & Number of free nodes in the nodetable \\
|
||||
{\tt time} & Time used for garbage collection this time \\
|
||||
{\tt sumtime} & Total time used for garbage collection \\
|
||||
{\tt num} & number of garbage collections done until now
|
||||
\end{tabular} *}
|
||||
ALSO {* bdd\_gbc\_hook *}
|
||||
*/
|
||||
typedef struct s_bddGbcStat
|
||||
{
|
||||
int nodes;
|
||||
int freenodes;
|
||||
long time;
|
||||
long sumtime;
|
||||
int num;
|
||||
} bddGbcStat;
|
||||
|
||||
|
||||
/*
|
||||
NAME {* bddCacheStat *}
|
||||
SECTION {* kernel *}
|
||||
SHORT {* Status information about cache usage *}
|
||||
PROTO {* typedef struct s_bddCacheStat
|
||||
{
|
||||
long unsigned int uniqueAccess;
|
||||
long unsigned int uniqueChain;
|
||||
long unsigned int uniqueHit;
|
||||
long unsigned int uniqueMiss;
|
||||
long unsigned int opHit;
|
||||
long unsigned int opMiss;
|
||||
long unsigned int swapCount;
|
||||
} bddCacheStat; *}
|
||||
DESCR {* The fields are \\[\baselineskip] \begin{tabular}{ll}
|
||||
{\bf Name} & {\bf Number of } \\
|
||||
uniqueAccess & accesses to the unique node table \\
|
||||
uniqueChain & iterations through the cache chains in the unique node table\\
|
||||
uniqueHit & entries actually found in the the unique node table \\
|
||||
uniqueMiss & entries not found in the the unique node table \\
|
||||
opHit & entries found in the operator caches \\
|
||||
opMiss & entries not found in the operator caches \\
|
||||
swapCount & number of variable swaps in reordering \\
|
||||
\end{tabular} *}
|
||||
ALSO {* bdd\_cachestats *}
|
||||
*/
|
||||
typedef struct s_bddCacheStat
|
||||
{
|
||||
long unsigned int uniqueAccess;
|
||||
long unsigned int uniqueChain;
|
||||
long unsigned int uniqueHit;
|
||||
long unsigned int uniqueMiss;
|
||||
long unsigned int opHit;
|
||||
long unsigned int opMiss;
|
||||
long unsigned int swapCount;
|
||||
} bddCacheStat;
|
||||
|
||||
/*=== BDD interface prototypes =========================================*/
|
||||
|
||||
/*
|
||||
NAME {* bdd\_relprod *}
|
||||
SECTION {* operator *}
|
||||
SHORT {* relational product *}
|
||||
PROTO {* #define bdd_relprod(a,b,var) bdd_appex(a,b,bddop_and,var) *}
|
||||
DESCR {* Calculates the relational product of {\tt a} and {\tt b} as
|
||||
{\tt a AND b} with the variables in {\tt var} quantified out
|
||||
afterwards. *}
|
||||
RETURN {* The relational product or {\tt bddfalse} on errors. *}
|
||||
ALSO {* bdd\_appex *}
|
||||
*/
|
||||
#define bdd_relprod(a,b,var) bdd_appex((a),(b),bddop_and,(var))
|
||||
|
||||
|
||||
/* In file "kernel.c" */
|
||||
|
||||
#ifdef CPLUSPLUS
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*bddinthandler)(int);
|
||||
typedef void (*bddgbchandler)(int,bddGbcStat*);
|
||||
typedef void (*bdd2inthandler)(int,int);
|
||||
typedef int (*bddsizehandler)(void);
|
||||
typedef void (*bddfilehandler)(FILE *, int);
|
||||
typedef void (*bddallsathandler)(char*, int);
|
||||
|
||||
extern bddinthandler bdd_error_hook(bddinthandler);
|
||||
extern bddgbchandler bdd_gbc_hook(bddgbchandler);
|
||||
extern bdd2inthandler bdd_resize_hook(bdd2inthandler);
|
||||
extern bddinthandler bdd_reorder_hook(bddinthandler);
|
||||
extern bddfilehandler bdd_file_hook(bddfilehandler);
|
||||
|
||||
extern int bdd_init(int, int);
|
||||
extern void bdd_done(void);
|
||||
extern int bdd_setvarnum(int);
|
||||
extern int bdd_extvarnum(int);
|
||||
extern int bdd_isrunning(void);
|
||||
extern int bdd_setmaxnodenum(int);
|
||||
extern int bdd_setmaxincrease(int);
|
||||
extern int bdd_setminfreenodes(int);
|
||||
extern int bdd_getnodenum(void);
|
||||
extern int bdd_getallocnum(void);
|
||||
extern char* bdd_versionstr(void);
|
||||
extern int bdd_versionnum(void);
|
||||
extern void bdd_stats(bddStat *);
|
||||
extern void bdd_cachestats(bddCacheStat *);
|
||||
extern void bdd_fprintstat(FILE *);
|
||||
extern void bdd_printstat(void);
|
||||
extern void bdd_default_gbchandler(int, bddGbcStat *);
|
||||
extern void bdd_default_errhandler(int);
|
||||
extern const char *bdd_errstring(int);
|
||||
extern void bdd_clear_error(void);
|
||||
#ifndef CPLUSPLUS
|
||||
extern BDD bdd_true(void);
|
||||
extern BDD bdd_false(void);
|
||||
#endif
|
||||
extern int bdd_varnum(void);
|
||||
extern BDD bdd_ithvar(int);
|
||||
extern BDD bdd_nithvar(int);
|
||||
extern int bdd_var(BDD);
|
||||
extern BDD bdd_low(BDD);
|
||||
extern BDD bdd_high(BDD);
|
||||
extern int bdd_varlevel(int);
|
||||
extern BDD bdd_addref(BDD);
|
||||
extern BDD bdd_delref(BDD);
|
||||
extern void bdd_gbc(void);
|
||||
extern int bdd_scanset(BDD, int**, int*);
|
||||
extern BDD bdd_makeset(int *, int);
|
||||
extern bddPair* bdd_newpair(void);
|
||||
extern int bdd_setpair(bddPair*, int, int);
|
||||
extern int bdd_setpairs(bddPair*, int*, int*, int);
|
||||
extern int bdd_setbddpair(bddPair*, int, BDD);
|
||||
extern int bdd_setbddpairs(bddPair*, int*, BDD*, int);
|
||||
extern void bdd_resetpair(bddPair *);
|
||||
extern void bdd_freepair(bddPair*);
|
||||
|
||||
/* In bddop.c */
|
||||
|
||||
extern int bdd_setcacheratio(int);
|
||||
extern BDD bdd_buildcube(int, int, BDD *);
|
||||
extern BDD bdd_ibuildcube(int, int, int *);
|
||||
extern BDD bdd_not(BDD);
|
||||
extern BDD bdd_apply(BDD, BDD, int);
|
||||
extern BDD bdd_and(BDD, BDD);
|
||||
extern BDD bdd_or(BDD, BDD);
|
||||
extern BDD bdd_xor(BDD, BDD);
|
||||
extern BDD bdd_imp(BDD, BDD);
|
||||
extern BDD bdd_biimp(BDD, BDD);
|
||||
extern BDD bdd_ite(BDD, BDD, BDD);
|
||||
extern BDD bdd_restrict(BDD, BDD);
|
||||
extern BDD bdd_constrain(BDD, BDD);
|
||||
extern BDD bdd_replace(BDD, bddPair*);
|
||||
extern BDD bdd_compose(BDD, BDD, BDD);
|
||||
extern BDD bdd_veccompose(BDD, bddPair*);
|
||||
extern BDD bdd_simplify(BDD, BDD);
|
||||
extern BDD bdd_exist(BDD, BDD);
|
||||
extern BDD bdd_forall(BDD, BDD);
|
||||
extern BDD bdd_unique(BDD, BDD);
|
||||
extern BDD bdd_appex(BDD, BDD, int, BDD);
|
||||
extern BDD bdd_appall(BDD, BDD, int, BDD);
|
||||
extern BDD bdd_appuni(BDD, BDD, int, BDD);
|
||||
extern BDD bdd_support(BDD);
|
||||
extern BDD bdd_satone(BDD);
|
||||
extern BDD bdd_satoneset(BDD, BDD, BDD);
|
||||
extern BDD bdd_fullsatone(BDD);
|
||||
extern void bdd_allsat(BDD r, bddallsathandler handler);
|
||||
extern double bdd_satcount(BDD);
|
||||
extern double bdd_satcountset(BDD, BDD);
|
||||
extern double bdd_satcountln(BDD);
|
||||
extern double bdd_satcountlnset(BDD, BDD);
|
||||
extern int bdd_nodecount(BDD);
|
||||
extern int bdd_anodecount(BDD *, int);
|
||||
extern int* bdd_varprofile(BDD);
|
||||
extern double bdd_pathcount(BDD);
|
||||
|
||||
|
||||
/* In file "bddio.c" */
|
||||
|
||||
extern void bdd_printall(void);
|
||||
extern void bdd_fprintall(FILE *);
|
||||
extern void bdd_fprinttable(FILE *, BDD);
|
||||
extern void bdd_printtable(BDD);
|
||||
extern void bdd_fprintset(FILE *, BDD);
|
||||
extern void bdd_printset(BDD);
|
||||
extern int bdd_fnprintdot(char *, BDD);
|
||||
extern void bdd_fprintdot(FILE *, BDD);
|
||||
extern void bdd_printdot(BDD);
|
||||
extern int bdd_fnsave(char *, BDD);
|
||||
extern int bdd_save(FILE *, BDD);
|
||||
extern int bdd_fnload(char *, BDD *);
|
||||
extern int bdd_load(FILE *ifile, BDD *);
|
||||
|
||||
/* In file reorder.c */
|
||||
|
||||
extern int bdd_swapvar(int v1, int v2);
|
||||
extern void bdd_default_reohandler(int);
|
||||
extern void bdd_reorder(int);
|
||||
extern int bdd_reorder_gain(void);
|
||||
extern bddsizehandler bdd_reorder_probe(bddsizehandler);
|
||||
extern void bdd_clrvarblocks(void);
|
||||
extern int bdd_addvarblock(BDD, int);
|
||||
extern int bdd_intaddvarblock(int, int, int);
|
||||
extern void bdd_varblockall(void);
|
||||
extern bddfilehandler bdd_blockfile_hook(bddfilehandler);
|
||||
extern int bdd_autoreorder(int);
|
||||
extern int bdd_autoreorder_times(int, int);
|
||||
extern int bdd_var2level(int);
|
||||
extern int bdd_level2var(int);
|
||||
extern int bdd_getreorder_times(void);
|
||||
extern int bdd_getreorder_method(void);
|
||||
extern void bdd_enable_reorder(void);
|
||||
extern void bdd_disable_reorder(void);
|
||||
extern int bdd_reorder_verbose(int);
|
||||
extern void bdd_setvarorder(int *);
|
||||
extern void bdd_printorder(void);
|
||||
extern void bdd_fprintorder(FILE *);
|
||||
|
||||
#ifdef CPLUSPLUS
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*=== BDD constants ====================================================*/
|
||||
|
||||
#ifndef CPLUSPLUS
|
||||
|
||||
extern const BDD bddfalse;
|
||||
extern const BDD bddtrue;
|
||||
|
||||
#endif /* CPLUSPLUS */
|
||||
|
||||
|
||||
/*=== Reordering algorithms ============================================*/
|
||||
|
||||
#define BDD_REORDER_NONE 0
|
||||
#define BDD_REORDER_WIN2 1
|
||||
#define BDD_REORDER_WIN2ITE 2
|
||||
#define BDD_REORDER_SIFT 3
|
||||
#define BDD_REORDER_SIFTITE 4
|
||||
#define BDD_REORDER_WIN3 5
|
||||
#define BDD_REORDER_WIN3ITE 6
|
||||
#define BDD_REORDER_RANDOM 7
|
||||
|
||||
#define BDD_REORDER_FREE 0
|
||||
#define BDD_REORDER_FIXED 1
|
||||
|
||||
|
||||
/*=== Error codes ======================================================*/
|
||||
|
||||
#define BDD_MEMORY (-1) /* Out of memory */
|
||||
#define BDD_VAR (-2) /* Unknown variable */
|
||||
#define BDD_RANGE (-3) /* Variable value out of range (not in domain) */
|
||||
#define BDD_DEREF (-4) /* Removing external reference to unknown node */
|
||||
#define BDD_RUNNING (-5) /* Called bdd_init() twice whithout bdd_done() */
|
||||
#define BDD_FILE (-6) /* Some file operation failed */
|
||||
#define BDD_FORMAT (-7) /* Incorrect file format */
|
||||
#define BDD_ORDER (-8) /* Vars. not in order for vector based functions */
|
||||
#define BDD_BREAK (-9) /* User called break */
|
||||
#define BDD_VARNUM (-10) /* Different number of vars. for vector pair */
|
||||
#define BDD_NODES (-11) /* Tried to set max. number of nodes to be fewer */
|
||||
/* than there already has been allocated */
|
||||
#define BDD_OP (-12) /* Unknown operator */
|
||||
#define BDD_VARSET (-13) /* Illegal variable set */
|
||||
#define BDD_VARBLK (-14) /* Bad variable block operation */
|
||||
#define BDD_DECVNUM (-15) /* Trying to decrease the number of variables */
|
||||
#define BDD_REPLACE (-16) /* Replacing to already existing variables */
|
||||
#define BDD_NODENUM (-17) /* Number of nodes reached user defined maximum */
|
||||
#define BDD_ILLBDD (-18) /* Illegal bdd argument */
|
||||
#define BDD_SIZE (-19) /* Illegal size argument */
|
||||
|
||||
#define BVEC_SIZE (-20) /* Mismatch in bitvector size */
|
||||
#define BVEC_SHIFT (-21) /* Illegal shift-left/right parameter */
|
||||
#define BVEC_DIVZERO (-22) /* Division by zero */
|
||||
|
||||
#define BDD_ERRNUM 24
|
||||
|
||||
/*************************************************************************
|
||||
If this file is included from a C++ compiler then the following
|
||||
classes, wrappers and hacks are supplied.
|
||||
*************************************************************************/
|
||||
#ifdef CPLUSPLUS
|
||||
#include <iostream>
|
||||
|
||||
/*=== User BDD class ===================================================*/
|
||||
|
||||
class bvec;
|
||||
|
||||
class bdd
|
||||
{
|
||||
public:
|
||||
|
||||
bdd(void) { root=0; }
|
||||
bdd(const bdd &r) { bdd_addref(root=r.root); }
|
||||
~bdd(void) { bdd_delref(root); }
|
||||
|
||||
int id(void) const;
|
||||
|
||||
bdd operator=(const bdd &r);
|
||||
|
||||
bdd operator&(const bdd &r) const;
|
||||
bdd operator&=(const bdd &r);
|
||||
bdd operator^(const bdd &r) const;
|
||||
bdd operator^=(const bdd &r);
|
||||
bdd operator|(const bdd &r) const;
|
||||
bdd operator|=(const bdd &r);
|
||||
bdd operator!(void) const;
|
||||
bdd operator>>(const bdd &r) const;
|
||||
bdd operator>>=(const bdd &r);
|
||||
bdd operator-(const bdd &r) const;
|
||||
bdd operator-=(const bdd &r);
|
||||
bdd operator>(const bdd &r) const;
|
||||
bdd operator<(const bdd &r) const;
|
||||
bdd operator<<(const bdd &r) const;
|
||||
bdd operator<<=(const bdd &r);
|
||||
int operator==(const bdd &r) const;
|
||||
int operator!=(const bdd &r) const;
|
||||
|
||||
private:
|
||||
BDD root;
|
||||
|
||||
bdd(BDD r) { bdd_addref(root=r); }
|
||||
bdd operator=(BDD r);
|
||||
|
||||
friend int bdd_init(int, int);
|
||||
friend int bdd_setvarnum(int);
|
||||
friend bdd bdd_true(void);
|
||||
friend bdd bdd_false(void);
|
||||
friend bdd bdd_ithvarpp(int);
|
||||
friend bdd bdd_nithvarpp(int);
|
||||
friend int bdd_var(const bdd &);
|
||||
friend bdd bdd_low(const bdd &);
|
||||
friend bdd bdd_high(const bdd &);
|
||||
friend int bdd_scanset(const bdd &, int *&, int &);
|
||||
friend bdd bdd_makesetpp(int *, int);
|
||||
friend int bdd_setbddpair(bddPair*, int, const bdd &);
|
||||
friend int bdd_setbddpairs(bddPair*, int*, const bdd *, int);
|
||||
friend bdd bdd_buildcube(int, int, const bdd *);
|
||||
friend bdd bdd_ibuildcubepp(int, int, int *);
|
||||
friend bdd bdd_not(const bdd &);
|
||||
friend bdd bdd_simplify(const bdd &, const bdd &);
|
||||
friend bdd bdd_apply(const bdd &, const bdd &, int);
|
||||
friend bdd bdd_and(const bdd &, const bdd &);
|
||||
friend bdd bdd_or(const bdd &, const bdd &);
|
||||
friend bdd bdd_xor(const bdd &, const bdd &);
|
||||
friend bdd bdd_imp(const bdd &, const bdd &);
|
||||
friend bdd bdd_biimp(const bdd &, const bdd &);
|
||||
friend bdd bdd_ite(const bdd &, const bdd &, const bdd &);
|
||||
friend bdd bdd_restrict(const bdd &, const bdd &);
|
||||
friend bdd bdd_constrain(const bdd &, const bdd &);
|
||||
friend bdd bdd_exist(const bdd &, const bdd &);
|
||||
friend bdd bdd_forall(const bdd &, const bdd &);
|
||||
friend bdd bdd_unique(const bdd &, const bdd &);
|
||||
friend bdd bdd_appex(const bdd &, const bdd &, int, const bdd &);
|
||||
friend bdd bdd_appall(const bdd &, const bdd &, int, const bdd &);
|
||||
friend bdd bdd_appuni(const bdd &, const bdd &, int, const bdd &);
|
||||
friend bdd bdd_replace(const bdd &, bddPair*);
|
||||
friend bdd bdd_compose(const bdd &, const bdd &, int);
|
||||
friend bdd bdd_veccompose(const bdd &, bddPair*);
|
||||
friend bdd bdd_support(const bdd &);
|
||||
friend bdd bdd_satone(const bdd &);
|
||||
friend bdd bdd_satoneset(const bdd &, const bdd &, const bdd &);
|
||||
friend bdd bdd_fullsatone(const bdd &);
|
||||
friend void bdd_allsat(const bdd &r, bddallsathandler handler);
|
||||
friend double bdd_satcount(const bdd &);
|
||||
friend double bdd_satcountset(const bdd &, const bdd &);
|
||||
friend double bdd_satcountln(const bdd &);
|
||||
friend double bdd_satcountlnset(const bdd &, const bdd &);
|
||||
friend int bdd_nodecount(const bdd &);
|
||||
friend int bdd_anodecountpp(const bdd *, int);
|
||||
friend int* bdd_varprofile(const bdd &);
|
||||
friend double bdd_pathcount(const bdd &);
|
||||
|
||||
friend void bdd_fprinttable(FILE *, const bdd &);
|
||||
friend void bdd_printtable(const bdd &);
|
||||
friend void bdd_fprintset(FILE *, const bdd &);
|
||||
friend void bdd_printset(const bdd &);
|
||||
friend void bdd_printdot(const bdd &);
|
||||
friend int bdd_fnprintdot(char*, const bdd &);
|
||||
friend void bdd_fprintdot(FILE*, const bdd &);
|
||||
friend std::ostream &operator<<(std::ostream &, const bdd &);
|
||||
friend int bdd_fnsave(char*, const bdd &);
|
||||
friend int bdd_save(FILE*, const bdd &);
|
||||
friend int bdd_fnload(char*, bdd &);
|
||||
friend int bdd_load(FILE*, bdd &);
|
||||
|
||||
friend bdd fdd_ithvarpp(int, int);
|
||||
friend bdd fdd_ithsetpp(int);
|
||||
friend bdd fdd_domainpp(int);
|
||||
friend int fdd_scanvar(const bdd &, int);
|
||||
friend int* fdd_scanallvar(const bdd &);
|
||||
friend bdd fdd_equalspp(int, int);
|
||||
friend void fdd_printset(const bdd &);
|
||||
friend void fdd_fprintset(FILE*, const bdd &);
|
||||
friend bdd fdd_makesetpp(int*, int);
|
||||
friend int fdd_scanset(const bdd &, int *&, int &);
|
||||
|
||||
friend int bdd_addvarblock(const bdd &, int);
|
||||
|
||||
friend class bvec;
|
||||
friend bvec bvec_ite(const bdd& a, const bvec& b, const bvec& c);
|
||||
friend bvec bvec_shlfixed(const bvec &e, int pos, const bdd &c);
|
||||
friend bvec bvec_shl(const bvec &left, const bvec &right, const bdd &c);
|
||||
friend bvec bvec_shrfixed(const bvec &e, int pos, const bdd &c);
|
||||
friend bvec bvec_shr(const bvec &left, const bvec &right, const bdd &c);
|
||||
friend bdd bvec_lth(const bvec &left, const bvec &right);
|
||||
friend bdd bvec_lte(const bvec &left, const bvec &right);
|
||||
friend bdd bvec_gth(const bvec &left, const bvec &right);
|
||||
friend bdd bvec_gte(const bvec &left, const bvec &right);
|
||||
friend bdd bvec_equ(const bvec &left, const bvec &right);
|
||||
friend bdd bvec_neq(const bvec &left, const bvec &right);
|
||||
};
|
||||
|
||||
|
||||
/*=== BDD constants ====================================================*/
|
||||
|
||||
extern const bdd bddfalsepp;
|
||||
extern const bdd bddtruepp;
|
||||
|
||||
#define bddtrue bddtruepp
|
||||
#define bddfalse bddfalsepp
|
||||
|
||||
/*=== C++ interface ====================================================*/
|
||||
|
||||
extern int bdd_cpp_init(int, int);
|
||||
|
||||
inline void bdd_stats(bddStat& s)
|
||||
{ bdd_stats(&s); }
|
||||
|
||||
inline bdd bdd_ithvarpp(int v)
|
||||
{ return bdd_ithvar(v); }
|
||||
|
||||
inline bdd bdd_nithvarpp(int v)
|
||||
{ return bdd_nithvar(v); }
|
||||
|
||||
inline int bdd_var(const bdd &r)
|
||||
{ return bdd_var(r.root); }
|
||||
|
||||
inline bdd bdd_low(const bdd &r)
|
||||
{ return bdd_low(r.root); }
|
||||
|
||||
inline bdd bdd_high(const bdd &r)
|
||||
{ return bdd_high(r.root); }
|
||||
|
||||
inline int bdd_scanset(const bdd &r, int *&v, int &n)
|
||||
{ return bdd_scanset(r.root, &v, &n); }
|
||||
|
||||
inline bdd bdd_makesetpp(int *v, int n)
|
||||
{ return bdd(bdd_makeset(v,n)); }
|
||||
|
||||
inline int bdd_setbddpair(bddPair *p, int ov, const bdd &nv)
|
||||
{ return bdd_setbddpair(p,ov,nv.root); }
|
||||
|
||||
/* In bddop.c */
|
||||
|
||||
inline bdd bdd_replace(const bdd &r, bddPair *p)
|
||||
{ return bdd_replace(r.root, p); }
|
||||
|
||||
inline bdd bdd_compose(const bdd &f, const bdd &g, int v)
|
||||
{ return bdd_compose(f.root, g.root, v); }
|
||||
|
||||
inline bdd bdd_veccompose(const bdd &f, bddPair *p)
|
||||
{ return bdd_veccompose(f.root, p); }
|
||||
|
||||
inline bdd bdd_restrict(const bdd &r, const bdd &var)
|
||||
{ return bdd_restrict(r.root, var.root); }
|
||||
|
||||
inline bdd bdd_constrain(const bdd &f, const bdd &c)
|
||||
{ return bdd_constrain(f.root, c.root); }
|
||||
|
||||
inline bdd bdd_simplify(const bdd &d, const bdd &b)
|
||||
{ return bdd_simplify(d.root, b.root); }
|
||||
|
||||
inline bdd bdd_ibuildcubepp(int v, int w, int *a)
|
||||
{ return bdd_ibuildcube(v,w,a); }
|
||||
|
||||
inline bdd bdd_not(const bdd &r)
|
||||
{ return bdd_not(r.root); }
|
||||
|
||||
inline bdd bdd_apply(const bdd &l, const bdd &r, int op)
|
||||
{ return bdd_apply(l.root, r.root, op); }
|
||||
|
||||
inline bdd bdd_and(const bdd &l, const bdd &r)
|
||||
{ return bdd_apply(l.root, r.root, bddop_and); }
|
||||
|
||||
inline bdd bdd_or(const bdd &l, const bdd &r)
|
||||
{ return bdd_apply(l.root, r.root, bddop_or); }
|
||||
|
||||
inline bdd bdd_xor(const bdd &l, const bdd &r)
|
||||
{ return bdd_apply(l.root, r.root, bddop_xor); }
|
||||
|
||||
inline bdd bdd_imp(const bdd &l, const bdd &r)
|
||||
{ return bdd_apply(l.root, r.root, bddop_imp); }
|
||||
|
||||
inline bdd bdd_biimp(const bdd &l, const bdd &r)
|
||||
{ return bdd_apply(l.root, r.root, bddop_biimp); }
|
||||
|
||||
inline bdd bdd_ite(const bdd &f, const bdd &g, const bdd &h)
|
||||
{ return bdd_ite(f.root, g.root, h.root); }
|
||||
|
||||
inline bdd bdd_exist(const bdd &r, const bdd &var)
|
||||
{ return bdd_exist(r.root, var.root); }
|
||||
|
||||
inline bdd bdd_forall(const bdd &r, const bdd &var)
|
||||
{ return bdd_forall(r.root, var.root); }
|
||||
|
||||
inline bdd bdd_unique(const bdd &r, const bdd &var)
|
||||
{ return bdd_unique(r.root, var.root); }
|
||||
|
||||
inline bdd bdd_appex(const bdd &l, const bdd &r, int op, const bdd &var)
|
||||
{ return bdd_appex(l.root, r.root, op, var.root); }
|
||||
|
||||
inline bdd bdd_appall(const bdd &l, const bdd &r, int op, const bdd &var)
|
||||
{ return bdd_appall(l.root, r.root, op, var.root); }
|
||||
|
||||
inline bdd bdd_appuni(const bdd &l, const bdd &r, int op, const bdd &var)
|
||||
{ return bdd_appuni(l.root, r.root, op, var.root); }
|
||||
|
||||
inline bdd bdd_support(const bdd &r)
|
||||
{ return bdd_support(r.root); }
|
||||
|
||||
inline bdd bdd_satone(const bdd &r)
|
||||
{ return bdd_satone(r.root); }
|
||||
|
||||
inline bdd bdd_satoneset(const bdd &r, const bdd &var, const bdd &pol)
|
||||
{ return bdd_satoneset(r.root, var.root, pol.root); }
|
||||
|
||||
inline bdd bdd_fullsatone(const bdd &r)
|
||||
{ return bdd_fullsatone(r.root); }
|
||||
|
||||
inline void bdd_allsat(const bdd &r, bddallsathandler handler)
|
||||
{ bdd_allsat(r.root, handler); }
|
||||
|
||||
inline double bdd_satcount(const bdd &r)
|
||||
{ return bdd_satcount(r.root); }
|
||||
|
||||
inline double bdd_satcountset(const bdd &r, const bdd &varset)
|
||||
{ return bdd_satcountset(r.root, varset.root); }
|
||||
|
||||
inline double bdd_satcountln(const bdd &r)
|
||||
{ return bdd_satcountln(r.root); }
|
||||
|
||||
inline double bdd_satcountlnset(const bdd &r, const bdd &varset)
|
||||
{ return bdd_satcountlnset(r.root, varset.root); }
|
||||
|
||||
inline int bdd_nodecount(const bdd &r)
|
||||
{ return bdd_nodecount(r.root); }
|
||||
|
||||
inline int* bdd_varprofile(const bdd &r)
|
||||
{ return bdd_varprofile(r.root); }
|
||||
|
||||
inline double bdd_pathcount(const bdd &r)
|
||||
{ return bdd_pathcount(r.root); }
|
||||
|
||||
|
||||
/* I/O extensions */
|
||||
|
||||
inline void bdd_fprinttable(FILE *file, const bdd &r)
|
||||
{ bdd_fprinttable(file, r.root); }
|
||||
|
||||
inline void bdd_printtable(const bdd &r)
|
||||
{ bdd_printtable(r.root); }
|
||||
|
||||
inline void bdd_fprintset(FILE *file, const bdd &r)
|
||||
{ bdd_fprintset(file, r.root); }
|
||||
|
||||
inline void bdd_printset(const bdd &r)
|
||||
{ bdd_printset(r.root); }
|
||||
|
||||
inline void bdd_printdot(const bdd &r)
|
||||
{ bdd_printdot(r.root); }
|
||||
|
||||
inline void bdd_fprintdot(FILE* ofile, const bdd &r)
|
||||
{ bdd_fprintdot(ofile, r.root); }
|
||||
|
||||
inline int bdd_fnprintdot(char* fname, const bdd &r)
|
||||
{ return bdd_fnprintdot(fname, r.root); }
|
||||
|
||||
inline int bdd_fnsave(char *fname, const bdd &r)
|
||||
{ return bdd_fnsave(fname, r.root); }
|
||||
|
||||
inline int bdd_save(FILE *ofile, const bdd &r)
|
||||
{ return bdd_save(ofile, r.root); }
|
||||
|
||||
inline int bdd_fnload(char *fname, bdd &r)
|
||||
{ int lr,e; e=bdd_fnload(fname, &lr); r=bdd(lr); return e; }
|
||||
|
||||
inline int bdd_load(FILE *ifile, bdd &r)
|
||||
{ int lr,e; e=bdd_load(ifile, &lr); r=bdd(lr); return e; }
|
||||
|
||||
inline int bdd_addvarblock(const bdd &v, int f)
|
||||
{ return bdd_addvarblock(v.root, f); }
|
||||
|
||||
/* Hack to allow for overloading */
|
||||
#define bdd_init bdd_cpp_init
|
||||
#define bdd_ithvar bdd_ithvarpp
|
||||
#define bdd_nithvar bdd_nithvarpp
|
||||
#define bdd_makeset bdd_makesetpp
|
||||
#define bdd_ibuildcube bdd_ibuildcubepp
|
||||
#define bdd_anodecount bdd_anodecountpp
|
||||
|
||||
/*=== Inline C++ functions =============================================*/
|
||||
|
||||
inline int bdd::id(void) const
|
||||
{ return root; }
|
||||
|
||||
inline bdd bdd::operator&(const bdd &r) const
|
||||
{ return bdd_apply(*this,r,bddop_and); }
|
||||
|
||||
inline bdd bdd::operator&=(const bdd &r)
|
||||
{ return (*this=bdd_apply(*this,r,bddop_and)); }
|
||||
|
||||
inline bdd bdd::operator^(const bdd &r) const
|
||||
{ return bdd_apply(*this,r,bddop_xor); }
|
||||
|
||||
inline bdd bdd::operator^=(const bdd &r)
|
||||
{ return (*this=bdd_apply(*this,r,bddop_xor)); }
|
||||
|
||||
inline bdd bdd::operator|(const bdd &r) const
|
||||
{ return bdd_apply(*this,r,bddop_or); }
|
||||
|
||||
inline bdd bdd::operator|=(const bdd &r)
|
||||
{ return (*this=bdd_apply(*this,r,bddop_or)); }
|
||||
|
||||
inline bdd bdd::operator!(void) const
|
||||
{ return bdd_not(*this);}
|
||||
|
||||
inline bdd bdd::operator>>(const bdd &r) const
|
||||
{ return bdd_apply(*this,r,bddop_imp); }
|
||||
|
||||
inline bdd bdd::operator>>=(const bdd &r)
|
||||
{ return (*this=bdd_apply(*this,r,bddop_imp)); }
|
||||
|
||||
inline bdd bdd::operator-(const bdd &r) const
|
||||
{ return bdd_apply(*this,r,bddop_diff); }
|
||||
|
||||
inline bdd bdd::operator-=(const bdd &r)
|
||||
{ return (*this=bdd_apply(*this,r,bddop_diff)); }
|
||||
|
||||
inline bdd bdd::operator>(const bdd &r) const
|
||||
{ return bdd_apply(*this,r,bddop_diff); }
|
||||
|
||||
inline bdd bdd::operator<(const bdd &r) const
|
||||
{ return bdd_apply(*this,r,bddop_less); }
|
||||
|
||||
inline bdd bdd::operator<<(const bdd &r) const
|
||||
{ return bdd_apply(*this,r,bddop_invimp); }
|
||||
|
||||
inline bdd bdd::operator<<=(const bdd &r)
|
||||
{ return (*this=bdd_apply(*this,r,bddop_invimp)); }
|
||||
|
||||
inline int bdd::operator==(const bdd &r) const
|
||||
{ return r.root==root; }
|
||||
|
||||
inline int bdd::operator!=(const bdd &r) const
|
||||
{ return r.root!=root; }
|
||||
|
||||
inline bdd bdd_true(void)
|
||||
{ return 1; }
|
||||
|
||||
inline bdd bdd_false(void)
|
||||
{ return 0; }
|
||||
|
||||
|
||||
/*=== Iostream printing ================================================*/
|
||||
|
||||
class bdd_ioformat
|
||||
{
|
||||
public:
|
||||
bdd_ioformat(int f) { format=f; }
|
||||
private:
|
||||
bdd_ioformat(void) { }
|
||||
int format;
|
||||
static int curformat;
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &, const bdd_ioformat &);
|
||||
friend std::ostream &operator<<(std::ostream &, const bdd &);
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &, const bdd &);
|
||||
std::ostream &operator<<(std::ostream &, const bdd_ioformat &);
|
||||
|
||||
extern bdd_ioformat bddset;
|
||||
extern bdd_ioformat bddtable;
|
||||
extern bdd_ioformat bdddot;
|
||||
extern bdd_ioformat bddall;
|
||||
extern bdd_ioformat fddset;
|
||||
|
||||
typedef void (*bddstrmhandler)(std::ostream &, int);
|
||||
|
||||
extern bddstrmhandler bdd_strm_hook(bddstrmhandler);
|
||||
|
||||
#endif /* CPLUSPLUS */
|
||||
|
||||
#endif /* _BDD_H */
|
||||
|
||||
/* EOF */
|
||||
593
buddy/src/bddio.c
Normal file
593
buddy/src/bddio.c
Normal file
|
|
@ -0,0 +1,593 @@
|
|||
/*========================================================================
|
||||
Copyright (C) 1996-2002 by Jorn Lind-Nielsen
|
||||
All rights reserved
|
||||
|
||||
Permission is hereby granted, without written agreement and without
|
||||
license or royalty fees, to use, reproduce, prepare derivative
|
||||
works, distribute, and display this software and its documentation
|
||||
for any purpose, provided that (1) the above copyright notice and
|
||||
the following two paragraphs appear in all copies of the source code
|
||||
and (2) redistributions, including without limitation binaries,
|
||||
reproduce these notices in the supporting documentation. Substantial
|
||||
modifications to this software may be copyrighted by their authors
|
||||
and need not follow the licensing terms described here, provided
|
||||
that the new terms are clearly indicated in all files where they apply.
|
||||
|
||||
IN NO EVENT SHALL JORN LIND-NIELSEN, OR DISTRIBUTORS OF THIS
|
||||
SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
|
||||
SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE
|
||||
ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
JORN LIND-NIELSEN SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
|
||||
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
||||
MODIFICATIONS.
|
||||
========================================================================*/
|
||||
|
||||
/*************************************************************************
|
||||
$Header: /Volumes/CVS/repository/spot/spot/buddy/src/bddio.c,v 1.1 2003/05/05 10:57:56 aduret Exp $
|
||||
FILE: bddio.c
|
||||
DESCR: File I/O routines for BDD package
|
||||
AUTH: Jorn Lind
|
||||
DATE: (C) june 1997
|
||||
*************************************************************************/
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <sys/stat.h>
|
||||
#include "kernel.h"
|
||||
|
||||
static void bdd_printset_rec(FILE *, int, int *);
|
||||
static void bdd_fprintdot_rec(FILE*, BDD);
|
||||
static int bdd_save_rec(FILE*, int);
|
||||
static int bdd_loaddata(FILE *);
|
||||
static int loadhash_get(int);
|
||||
static void loadhash_add(int, int);
|
||||
|
||||
static bddfilehandler filehandler;
|
||||
|
||||
typedef struct s_LoadHash
|
||||
{
|
||||
int key;
|
||||
int data;
|
||||
int first;
|
||||
int next;
|
||||
} LoadHash;
|
||||
|
||||
static LoadHash *lh_table;
|
||||
static int lh_freepos;
|
||||
static int lh_nodenum;
|
||||
static int *loadvar2level;
|
||||
|
||||
/*=== PRINTING ========================================================*/
|
||||
|
||||
|
||||
/*
|
||||
NAME {* bdd\_file\_hook *}
|
||||
SECTION {* kernel *}
|
||||
SHORT {* Specifies a printing callback handler *}
|
||||
PROTO {* bddfilehandler bdd_file_hook(bddfilehandler handler) *}
|
||||
DESCR {* A printing callback handler for use with BDDs is used to
|
||||
convert the BDD variable number into something readable by the
|
||||
end user. Typically the handler will print a string name
|
||||
instead of the number. A handler could look like this:
|
||||
\begin{verbatim}
|
||||
void printhandler(FILE *o, int var)
|
||||
{
|
||||
extern char **names;
|
||||
fprintf(o, "%s", names[var]);
|
||||
}
|
||||
\end{verbatim}
|
||||
|
||||
\noindent
|
||||
The handler can then be passed to BuDDy like this:
|
||||
{\tt bdd\_file\_hook(printhandler)}.
|
||||
|
||||
No default handler is supplied. The argument {\tt handler} may be
|
||||
NULL if no handler is needed. *}
|
||||
RETURN {* The old handler *}
|
||||
ALSO {* bdd\_printset, bdd\_strm\_hook, fdd\_file\_hook *}
|
||||
*/
|
||||
bddfilehandler bdd_file_hook(bddfilehandler handler)
|
||||
{
|
||||
bddfilehandler old = filehandler;
|
||||
filehandler = handler;
|
||||
return old;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
NAME {* bdd\_printall *}
|
||||
EXTRA {* bdd\_fprintall *}
|
||||
SECTION {* fileio *}
|
||||
SHORT {* prints all used entries in the node table *}
|
||||
PROTO {* void bdd_printall(void)
|
||||
void bdd_fprintall(FILE* ofile) *}
|
||||
DESCR {* Prints to either stdout or the file {\tt ofile} all the used
|
||||
entries in the main node table. The format is:
|
||||
\begin{Ill}
|
||||
{\tt [Nodenum] Var/level Low High}
|
||||
\end{Ill}
|
||||
Where {\tt Nodenum} is the position in the node table and level
|
||||
is the position in the current variable order. *}
|
||||
ALSO {* bdd\_printtable, bdd\_printset, bdd\_printdot *}
|
||||
*/
|
||||
void bdd_printall(void)
|
||||
{
|
||||
bdd_fprintall(stdout);
|
||||
}
|
||||
|
||||
|
||||
void bdd_fprintall(FILE *ofile)
|
||||
{
|
||||
int n;
|
||||
|
||||
for (n=0 ; n<bddnodesize ; n++)
|
||||
{
|
||||
if (LOW(n) != -1)
|
||||
{
|
||||
fprintf(ofile, "[%5d - %2d] ", n, bddnodes[n].refcou);
|
||||
if (filehandler)
|
||||
filehandler(ofile, bddlevel2var[LEVEL(n)]);
|
||||
else
|
||||
fprintf(ofile, "%3d", bddlevel2var[LEVEL(n)]);
|
||||
|
||||
fprintf(ofile, ": %3d", LOW(n));
|
||||
fprintf(ofile, " %3d", HIGH(n));
|
||||
fprintf(ofile, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
NAME {* bdd\_printtable *}
|
||||
EXTRA {* bdd\_fprinttable *}
|
||||
SECTION {* fileio *}
|
||||
SHORT {* prints the node table entries used by a BDD *}
|
||||
PROTO {* void bdd_printtable(BDD r)
|
||||
void bdd_fprinttable(FILE* ofile, BDD r) *}
|
||||
DESCR {* Prints to either stdout or the file {\tt ofile} all the entries
|
||||
in the main node table used by {\tt r}. The format is:
|
||||
\begin{Ill}
|
||||
{\tt [Nodenum] Var/level : Low High}
|
||||
\end{Ill}
|
||||
Where {\tt Nodenum} is the position in the node table and level
|
||||
is the position in the current variable order. *}
|
||||
ALSO {* bdd\_printall, bdd\_printset, bdd\_printdot *}
|
||||
*/
|
||||
void bdd_printtable(BDD r)
|
||||
{
|
||||
bdd_fprinttable(stdout, r);
|
||||
}
|
||||
|
||||
|
||||
void bdd_fprinttable(FILE *ofile, BDD r)
|
||||
{
|
||||
BddNode *node;
|
||||
int n;
|
||||
|
||||
fprintf(ofile, "ROOT: %d\n", r);
|
||||
if (r < 2)
|
||||
return;
|
||||
|
||||
bdd_mark(r);
|
||||
|
||||
for (n=0 ; n<bddnodesize ; n++)
|
||||
{
|
||||
if (LEVEL(n) & MARKON)
|
||||
{
|
||||
node = &bddnodes[n];
|
||||
|
||||
LEVELp(node) &= MARKOFF;
|
||||
|
||||
fprintf(ofile, "[%5d] ", n);
|
||||
if (filehandler)
|
||||
filehandler(ofile, bddlevel2var[LEVELp(node)]);
|
||||
else
|
||||
fprintf(ofile, "%3d", bddlevel2var[LEVELp(node)]);
|
||||
|
||||
fprintf(ofile, ": %3d", LOWp(node));
|
||||
fprintf(ofile, " %3d", HIGHp(node));
|
||||
fprintf(ofile, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
NAME {* bdd\_printset *}
|
||||
EXTRA {* bdd\_fprintset *}
|
||||
SECTION {* fileio *}
|
||||
SHORT {* prints the set of truth assignments specified by a BDD *}
|
||||
PROTO {* bdd_printset(BDD r)
|
||||
bdd_fprintset(FILE* ofile, BDD r) *}
|
||||
DESCR {* Prints all the truth assignments for {\tt r} that would yield
|
||||
it true. The format is:
|
||||
\begin{Ill}
|
||||
{\tt < $x_{1,1}:c_{1,1},\ldots,x_{1,n_1}:c_{1,n_1}$ >\\
|
||||
< $x_{2,1}:c_{2,1},\ldots,x_{2,n_2}:c_{2,n_2}$ >\\
|
||||
$\ldots$ \\
|
||||
< $x_{N,1}:c_{N,1},\ldots,x_{N,n_3}:c_{N,n_3}$ > }
|
||||
\end{Ill}
|
||||
Where the $x$'s are variable numbers (and the position in the
|
||||
current order) and the $c$'s are the
|
||||
possible assignments to these. Each set of brackets designates
|
||||
one possible assignment to the set of variables that make up the
|
||||
BDD. All variables not shown are don't cares. It is possible to
|
||||
specify a callback handler for printing of the variables using
|
||||
{\tt bdd\_file\_hook} or {\tt bdd\_strm\_hook}. *}
|
||||
ALSO {* bdd\_printall, bdd\_printtable, bdd\_printdot, bdd\_file\_hook, bdd\_strm\_hook *}
|
||||
*/
|
||||
void bdd_printset(BDD r)
|
||||
{
|
||||
bdd_fprintset(stdout, r);
|
||||
}
|
||||
|
||||
|
||||
void bdd_fprintset(FILE *ofile, BDD r)
|
||||
{
|
||||
int *set;
|
||||
|
||||
if (r < 2)
|
||||
{
|
||||
fprintf(ofile, "%s", r == 0 ? "F" : "T");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((set=(int *)malloc(sizeof(int)*bddvarnum)) == NULL)
|
||||
{
|
||||
bdd_error(BDD_MEMORY);
|
||||
return;
|
||||
}
|
||||
|
||||
memset(set, 0, sizeof(int) * bddvarnum);
|
||||
bdd_printset_rec(ofile, r, set);
|
||||
free(set);
|
||||
}
|
||||
|
||||
|
||||
static void bdd_printset_rec(FILE *ofile, int r, int *set)
|
||||
{
|
||||
int n;
|
||||
int first;
|
||||
|
||||
if (r == 0)
|
||||
return;
|
||||
else
|
||||
if (r == 1)
|
||||
{
|
||||
fprintf(ofile, "<");
|
||||
first = 1;
|
||||
|
||||
for (n=0 ; n<bddvarnum ; n++)
|
||||
{
|
||||
if (set[n] > 0)
|
||||
{
|
||||
if (!first)
|
||||
fprintf(ofile, ", ");
|
||||
first = 0;
|
||||
if (filehandler)
|
||||
filehandler(ofile, bddlevel2var[n]);
|
||||
else
|
||||
fprintf(ofile, "%d", bddlevel2var[n]);
|
||||
fprintf(ofile, ":%d", (set[n]==2 ? 1 : 0));
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(ofile, ">");
|
||||
}
|
||||
else
|
||||
{
|
||||
set[LEVEL(r)] = 1;
|
||||
bdd_printset_rec(ofile, LOW(r), set);
|
||||
|
||||
set[LEVEL(r)] = 2;
|
||||
bdd_printset_rec(ofile, HIGH(r), set);
|
||||
|
||||
set[LEVEL(r)] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
NAME {* bdd\_printdot *}
|
||||
EXTRA {* bdd\_fprintdot *}
|
||||
SECTION {* fileio *}
|
||||
SHORT {* prints a description of a BDD in DOT format *}
|
||||
PROTO {* void bdd_printdot(BDD r)
|
||||
int bdd_fnprintdot(char* fname, BDD r)
|
||||
void bdd_fprintdot(FILE* ofile, BDD r) *}
|
||||
DESCR {* Prints a BDD in a format suitable for use with the graph
|
||||
drawing program DOT to either stdout, a designated file
|
||||
{\tt ofile} or the file named by {\tt fname}. In the last case
|
||||
the file will be opened for writing, any previous contents
|
||||
destroyed and then closed again. *}
|
||||
ALSO {* bdd\_printall, bdd\_printtable, bdd\_printset *}
|
||||
*/
|
||||
void bdd_printdot(BDD r)
|
||||
{
|
||||
bdd_fprintdot(stdout, r);
|
||||
}
|
||||
|
||||
|
||||
int bdd_fnprintdot(char *fname, BDD r)
|
||||
{
|
||||
FILE *ofile = fopen(fname, "w");
|
||||
if (ofile == NULL)
|
||||
return bdd_error(BDD_FILE);
|
||||
bdd_fprintdot(ofile, r);
|
||||
fclose(ofile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void bdd_fprintdot(FILE* ofile, BDD r)
|
||||
{
|
||||
fprintf(ofile, "digraph G {\n");
|
||||
fprintf(ofile, "0 [shape=box, label=\"0\", style=filled, shape=box, height=0.3, width=0.3];\n");
|
||||
fprintf(ofile, "1 [shape=box, label=\"1\", style=filled, shape=box, height=0.3, width=0.3];\n");
|
||||
|
||||
bdd_fprintdot_rec(ofile, r);
|
||||
|
||||
fprintf(ofile, "}\n");
|
||||
|
||||
bdd_unmark(r);
|
||||
}
|
||||
|
||||
|
||||
static void bdd_fprintdot_rec(FILE* ofile, BDD r)
|
||||
{
|
||||
if (ISCONST(r) || MARKED(r))
|
||||
return;
|
||||
|
||||
fprintf(ofile, "%d [label=\"", r);
|
||||
if (filehandler)
|
||||
filehandler(ofile, bddlevel2var[LEVEL(r)]);
|
||||
else
|
||||
fprintf(ofile, "%d", bddlevel2var[LEVEL(r)]);
|
||||
fprintf(ofile, "\"];\n");
|
||||
|
||||
fprintf(ofile, "%d -> %d [style=dotted];\n", r, LOW(r));
|
||||
fprintf(ofile, "%d -> %d [style=filled];\n", r, HIGH(r));
|
||||
|
||||
SETMARK(r);
|
||||
|
||||
bdd_fprintdot_rec(ofile, LOW(r));
|
||||
bdd_fprintdot_rec(ofile, HIGH(r));
|
||||
}
|
||||
|
||||
|
||||
/*=== SAVE =============================================================*/
|
||||
|
||||
/*
|
||||
NAME {* bdd\_save *}
|
||||
EXTRA {* bdd\_fnsave *}
|
||||
SECTION {* fileio *}
|
||||
SHORT {* saves a BDD to a file *}
|
||||
PROTO {* int bdd_fnsave(char *fname, BDD r)
|
||||
int bdd_save(FILE *ofile, BDD r) *}
|
||||
DESCR {* Saves the nodes used by {\tt r} to either a file {\tt ofile}
|
||||
which must be opened for writing or to the file named {\tt fname}.
|
||||
In the last case the file will be truncated and opened for
|
||||
writing. *}
|
||||
ALSO {* bdd\_load *}
|
||||
RETURN {* Zero on succes, otherwise an error code from {\tt bdd.h}. *}
|
||||
*/
|
||||
int bdd_fnsave(char *fname, BDD r)
|
||||
{
|
||||
FILE *ofile;
|
||||
int ok;
|
||||
|
||||
if ((ofile=fopen(fname,"w")) == NULL)
|
||||
return bdd_error(BDD_FILE);
|
||||
|
||||
ok = bdd_save(ofile, r);
|
||||
fclose(ofile);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
int bdd_save(FILE *ofile, BDD r)
|
||||
{
|
||||
int err, n=0;
|
||||
|
||||
if (r < 2)
|
||||
{
|
||||
fprintf(ofile, "0 0 %d\n", r);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bdd_markcount(r, &n);
|
||||
bdd_unmark(r);
|
||||
fprintf(ofile, "%d %d\n", n, bddvarnum);
|
||||
|
||||
for (n=0 ; n<bddvarnum ; n++)
|
||||
fprintf(ofile, "%d ", bddvar2level[n]);
|
||||
fprintf(ofile, "\n");
|
||||
|
||||
err = bdd_save_rec(ofile, r);
|
||||
bdd_unmark(r);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
static int bdd_save_rec(FILE *ofile, int root)
|
||||
{
|
||||
BddNode *node = &bddnodes[root];
|
||||
int err;
|
||||
|
||||
if (root < 2)
|
||||
return 0;
|
||||
|
||||
if (LEVELp(node) & MARKON)
|
||||
return 0;
|
||||
LEVELp(node) |= MARKON;
|
||||
|
||||
if ((err=bdd_save_rec(ofile, LOWp(node))) < 0)
|
||||
return err;
|
||||
if ((err=bdd_save_rec(ofile, HIGHp(node))) < 0)
|
||||
return err;
|
||||
|
||||
fprintf(ofile, "%d %d %d %d\n",
|
||||
root, bddlevel2var[LEVELp(node) & MARKHIDE],
|
||||
LOWp(node), HIGHp(node));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*=== LOAD =============================================================*/
|
||||
|
||||
/*
|
||||
NAME {* bdd\_load *}
|
||||
EXTRA {* bdd\_fnload *}
|
||||
SECTION {* fileio *}
|
||||
SHORT {* loads a BDD from a file *}
|
||||
PROTO {* int bdd_fnload(char *fname, BDD *r)
|
||||
int bdd_load(FILE *ifile, BDD *r) *}
|
||||
DESCR {* Loads a BDD from a file into the BDD pointed to by {\tt r}.
|
||||
The file can either be the file {\tt ifile} which must be opened
|
||||
for reading or the file named {\tt fname} which will be opened
|
||||
automatically for reading.
|
||||
|
||||
The input file format consists of integers arranged in the following
|
||||
manner. First the number of nodes $N$ used by the BDD and then the
|
||||
number of variables $V$ allocated and the variable ordering
|
||||
in use at the time the BDD was saved.
|
||||
If $N$ and $V$ are both zero then the BDD is either the constant
|
||||
true or false BDD, indicated by a $1$ or a $0$ as the next integer.
|
||||
|
||||
In any other case the next $N$ sets of $4$ integers will describe
|
||||
the nodes used by the BDD. Each set consists of first the node
|
||||
number, then the variable number and then the low and high nodes.
|
||||
|
||||
The nodes {\it must} be saved in a order such that any low or
|
||||
high node must be defined before it is mentioned. *}
|
||||
ALSO {* bdd\_save *}
|
||||
RETURN {* Zero on succes, otherwise an error code from {\tt bdd.h}. *}
|
||||
*/
|
||||
int bdd_fnload(char *fname, BDD *root)
|
||||
{
|
||||
FILE *ifile;
|
||||
int ok;
|
||||
|
||||
if ((ifile=fopen(fname,"r")) == NULL)
|
||||
return bdd_error(BDD_FILE);
|
||||
|
||||
ok = bdd_load(ifile, root);
|
||||
fclose(ifile);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
int bdd_load(FILE *ifile, BDD *root)
|
||||
{
|
||||
int n, vnum, tmproot;
|
||||
|
||||
if (fscanf(ifile, "%d %d", &lh_nodenum, &vnum) != 2)
|
||||
return bdd_error(BDD_FORMAT);
|
||||
|
||||
/* Check for constant true / false */
|
||||
if (lh_nodenum==0 && vnum==0)
|
||||
{
|
||||
fscanf(ifile, "%d", root);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((loadvar2level=(int*)malloc(sizeof(int)*vnum)) == NULL)
|
||||
return bdd_error(BDD_MEMORY);
|
||||
for (n=0 ; n<vnum ; n++)
|
||||
fscanf(ifile, "%d", &loadvar2level[n]);
|
||||
|
||||
if (vnum > bddvarnum)
|
||||
bdd_setvarnum(vnum);
|
||||
|
||||
if ((lh_table=(LoadHash*)malloc(lh_nodenum*sizeof(LoadHash))) == NULL)
|
||||
return bdd_error(BDD_MEMORY);
|
||||
|
||||
for (n=0 ; n<lh_nodenum ; n++)
|
||||
{
|
||||
lh_table[n].first = -1;
|
||||
lh_table[n].next = n+1;
|
||||
}
|
||||
lh_table[lh_nodenum-1].next = -1;
|
||||
lh_freepos = 0;
|
||||
|
||||
tmproot = bdd_loaddata(ifile);
|
||||
|
||||
for (n=0 ; n<lh_nodenum ; n++)
|
||||
bdd_delref(lh_table[n].data);
|
||||
|
||||
free(lh_table);
|
||||
free(loadvar2level);
|
||||
|
||||
*root = 0;
|
||||
if (tmproot < 0)
|
||||
return tmproot;
|
||||
else
|
||||
*root = tmproot;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int bdd_loaddata(FILE *ifile)
|
||||
{
|
||||
int key,var,low,high,root=0,n;
|
||||
|
||||
for (n=0 ; n<lh_nodenum ; n++)
|
||||
{
|
||||
if (fscanf(ifile,"%d %d %d %d", &key, &var, &low, &high) != 4)
|
||||
return bdd_error(BDD_FORMAT);
|
||||
|
||||
if (low >= 2)
|
||||
low = loadhash_get(low);
|
||||
if (high >= 2)
|
||||
high = loadhash_get(high);
|
||||
|
||||
if (low<0 || high<0 || var<0)
|
||||
return bdd_error(BDD_FORMAT);
|
||||
|
||||
root = bdd_addref( bdd_ite(bdd_ithvar(var), high, low) );
|
||||
|
||||
loadhash_add(key, root);
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
|
||||
static void loadhash_add(int key, int data)
|
||||
{
|
||||
int hash = key % lh_nodenum;
|
||||
int pos = lh_freepos;
|
||||
|
||||
lh_freepos = lh_table[pos].next;
|
||||
lh_table[pos].next = lh_table[hash].first;
|
||||
lh_table[hash].first = pos;
|
||||
|
||||
lh_table[pos].key = key;
|
||||
lh_table[pos].data = data;
|
||||
}
|
||||
|
||||
|
||||
static int loadhash_get(int key)
|
||||
{
|
||||
int hash = lh_table[key % lh_nodenum].first;
|
||||
|
||||
while (hash != -1 && lh_table[hash].key != key)
|
||||
hash = lh_table[hash].next;
|
||||
|
||||
if (hash == -1)
|
||||
return -1;
|
||||
return lh_table[hash].data;
|
||||
}
|
||||
|
||||
|
||||
/* EOF */
|
||||
2832
buddy/src/bddop.c
Normal file
2832
buddy/src/bddop.c
Normal file
File diff suppressed because it is too large
Load diff
110
buddy/src/bddtest.cxx
Normal file
110
buddy/src/bddtest.cxx
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
/*========================================================================
|
||||
Copyright (C) 1996-2002 by Jorn Lind-Nielsen
|
||||
All rights reserved
|
||||
|
||||
Permission is hereby granted, without written agreement and without
|
||||
license or royalty fees, to use, reproduce, prepare derivative
|
||||
works, distribute, and display this software and its documentation
|
||||
for any purpose, provided that (1) the above copyright notice and
|
||||
the following two paragraphs appear in all copies of the source code
|
||||
and (2) redistributions, including without limitation binaries,
|
||||
reproduce these notices in the supporting documentation. Substantial
|
||||
modifications to this software may be copyrighted by their authors
|
||||
and need not follow the licensing terms described here, provided
|
||||
that the new terms are clearly indicated in all files where they apply.
|
||||
|
||||
IN NO EVENT SHALL JORN LIND-NIELSEN, OR DISTRIBUTORS OF THIS
|
||||
SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
|
||||
SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE
|
||||
ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
JORN LIND-NIELSEN SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
|
||||
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
||||
MODIFICATIONS.
|
||||
========================================================================*/
|
||||
|
||||
#include <string>
|
||||
#include "bdd.h"
|
||||
#include "bvec.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
#define ERROR(msg) fail(msg, __FILE__, __LINE__)
|
||||
|
||||
static void fail(const string msg, const char* file, int lineNum)
|
||||
{
|
||||
cout << "Error in " << file << "(" << lineNum << "): " << msg << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
static void testSupport(void)
|
||||
{
|
||||
bdd even = bdd_ithvar(0) | bdd_ithvar(2) | bdd_ithvar(4);
|
||||
bdd odd = bdd_ithvar(1) | bdd_ithvar(3) | bdd_ithvar(5);
|
||||
|
||||
cout << "Testing support\n";
|
||||
|
||||
bdd s1 = bdd_support(even);
|
||||
bdd s2 = bdd_support(odd);
|
||||
|
||||
if (s1 != (bdd_ithvar(0) & bdd_ithvar(2) & bdd_ithvar(4)))
|
||||
ERROR("Support of 'even' failed\n");
|
||||
if (s2 != (bdd_ithvar(1) & bdd_ithvar(3) & bdd_ithvar(5)))
|
||||
ERROR("Support of 'odd' failed\n");
|
||||
|
||||
/* Try many time in order check that the internal support ID
|
||||
* is set correctly */
|
||||
for (int n=0 ; n<500 ; ++n)
|
||||
{
|
||||
s1 = bdd_support(even);
|
||||
s2 = bdd_support(odd);
|
||||
|
||||
if (s1 != (bdd_ithvar(0) & bdd_ithvar(2) & bdd_ithvar(4)))
|
||||
ERROR("Support of 'even' failed");
|
||||
if (s2 != (bdd_ithvar(1) & bdd_ithvar(3) & bdd_ithvar(5)))
|
||||
ERROR("Support of 'odd' failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void testBvecIte()
|
||||
{
|
||||
cout << "Testing ITE for vector\n";
|
||||
|
||||
bdd a = bdd_ithvar(0);
|
||||
bvec b = bvec_var(3, 1, 2);
|
||||
bvec c = bvec_var(3, 2, 2);
|
||||
|
||||
bvec res = bvec_ite(a,b,c);
|
||||
|
||||
bdd r0 = bdd_ite( bdd_ithvar(0), bdd_ithvar(1), bdd_ithvar(2) );
|
||||
bdd r1 = bdd_ite( bdd_ithvar(0), bdd_ithvar(3), bdd_ithvar(4) );
|
||||
bdd r2 = bdd_ite( bdd_ithvar(0), bdd_ithvar(5), bdd_ithvar(6) );
|
||||
|
||||
if (res[0] != r0)
|
||||
ERROR("Bit 0 failed.");
|
||||
if (res[1] != r1)
|
||||
ERROR("Bit 1 failed.");
|
||||
if (res[2] != r2)
|
||||
ERROR("Bit 2 failed.");
|
||||
}
|
||||
|
||||
|
||||
int main(int ac, char** av)
|
||||
{
|
||||
bdd_init(1000,1000);
|
||||
|
||||
bdd_setvarnum(10);
|
||||
|
||||
testSupport();
|
||||
testBvecIte();
|
||||
|
||||
bdd_done();
|
||||
return 0;
|
||||
}
|
||||
60
buddy/src/bddtree.h
Normal file
60
buddy/src/bddtree.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*========================================================================
|
||||
Copyright (C) 1996-2002 by Jorn Lind-Nielsen
|
||||
All rights reserved
|
||||
|
||||
Permission is hereby granted, without written agreement and without
|
||||
license or royalty fees, to use, reproduce, prepare derivative
|
||||
works, distribute, and display this software and its documentation
|
||||
for any purpose, provided that (1) the above copyright notice and
|
||||
the following two paragraphs appear in all copies of the source code
|
||||
and (2) redistributions, including without limitation binaries,
|
||||
reproduce these notices in the supporting documentation. Substantial
|
||||
modifications to this software may be copyrighted by their authors
|
||||
and need not follow the licensing terms described here, provided
|
||||
that the new terms are clearly indicated in all files where they apply.
|
||||
|
||||
IN NO EVENT SHALL JORN LIND-NIELSEN, OR DISTRIBUTORS OF THIS
|
||||
SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
|
||||
SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE
|
||||
ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
JORN LIND-NIELSEN SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
|
||||
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
||||
MODIFICATIONS.
|
||||
========================================================================*/
|
||||
|
||||
/*************************************************************************
|
||||
$Header: /Volumes/CVS/repository/spot/spot/buddy/src/bddtree.h,v 1.1 2003/05/05 10:57:56 aduret Exp $
|
||||
FILE: tree.h
|
||||
DESCR: Trees for BDD variables
|
||||
AUTH: Jorn Lind
|
||||
DATE: (C) march 1998
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef _TREE_H
|
||||
#define _TREE_H
|
||||
|
||||
typedef struct s_BddTree
|
||||
{
|
||||
int first, last; /* First and last variable in this block */
|
||||
int pos; /* Sifting position */
|
||||
int *seq; /* Sequence of first...last in the current order */
|
||||
char fixed; /* Are the sub-blocks fixed or may they be reordered */
|
||||
int id; /* A sequential id number given by addblock */
|
||||
struct s_BddTree *next, *prev;
|
||||
struct s_BddTree *nextlevel;
|
||||
} BddTree;
|
||||
|
||||
BddTree *bddtree_new(int);
|
||||
void bddtree_del(BddTree *);
|
||||
BddTree *bddtree_addrange(BddTree *, int, int, int, int);
|
||||
void bddtree_print(FILE *, BddTree *, int);
|
||||
|
||||
#endif /* _TREE_H */
|
||||
|
||||
|
||||
/* EOF */
|
||||
1352
buddy/src/bvec.c
Normal file
1352
buddy/src/bvec.c
Normal file
File diff suppressed because it is too large
Load diff
297
buddy/src/bvec.h
Normal file
297
buddy/src/bvec.h
Normal file
|
|
@ -0,0 +1,297 @@
|
|||
/*========================================================================
|
||||
Copyright (C) 1996-2002 by Jorn Lind-Nielsen
|
||||
All rights reserved
|
||||
|
||||
Permission is hereby granted, without written agreement and without
|
||||
license or royalty fees, to use, reproduce, prepare derivative
|
||||
works, distribute, and display this software and its documentation
|
||||
for any purpose, provided that (1) the above copyright notice and
|
||||
the following two paragraphs appear in all copies of the source code
|
||||
and (2) redistributions, including without limitation binaries,
|
||||
reproduce these notices in the supporting documentation. Substantial
|
||||
modifications to this software may be copyrighted by their authors
|
||||
and need not follow the licensing terms described here, provided
|
||||
that the new terms are clearly indicated in all files where they apply.
|
||||
|
||||
IN NO EVENT SHALL JORN LIND-NIELSEN, OR DISTRIBUTORS OF THIS
|
||||
SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
|
||||
SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE
|
||||
ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
JORN LIND-NIELSEN SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
|
||||
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
||||
MODIFICATIONS.
|
||||
========================================================================*/
|
||||
|
||||
/*************************************************************************
|
||||
$Header: /Volumes/CVS/repository/spot/spot/buddy/src/bvec.h,v 1.1 2003/05/05 10:57:56 aduret Exp $
|
||||
FILE: bvec.h
|
||||
DESCR: Boolean (BDD) vector handling
|
||||
AUTH: Jorn Lind
|
||||
DATE: (C) may 1999
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef _BVEC_H
|
||||
#define _BVEC_H
|
||||
|
||||
#include "fdd.h"
|
||||
|
||||
/* Boolean (BDD) vector */
|
||||
/*
|
||||
NAME {* bvec *}
|
||||
SECTION {* bvec *}
|
||||
SHORT {* A boolean vector *}
|
||||
PROTO {* typedef struct s_bvec
|
||||
{
|
||||
int bitnum;
|
||||
BDD *bitvec;
|
||||
} BVEC;
|
||||
|
||||
typedef BVEC bvec; *}
|
||||
DESCR {* This data structure is used to store boolean vectors. The field
|
||||
{\tt bitnum} is the number of elements in the vector and the
|
||||
field {\tt bitvec} contains the actual BDDs in the vector.
|
||||
The C++ version of {\tt bvec} is documented at the beginning of
|
||||
this document *}
|
||||
*/
|
||||
typedef struct s_bvec
|
||||
{
|
||||
int bitnum;
|
||||
BDD *bitvec;
|
||||
} BVEC;
|
||||
|
||||
#ifndef CPLUSPLUS
|
||||
typedef BVEC bvec;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef CPLUSPLUS
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Prototypes for bvec.c */
|
||||
extern BVEC bvec_copy(BVEC v);
|
||||
extern BVEC bvec_true(int bitnum);
|
||||
extern BVEC bvec_false(int bitnum);
|
||||
extern BVEC bvec_con(int bitnum, int val);
|
||||
extern BVEC bvec_var(int bitnum, int offset, int step);
|
||||
extern BVEC bvec_varfdd(int var);
|
||||
extern BVEC bvec_varvec(int bitnum, int *var);
|
||||
extern BVEC bvec_coerce(int bitnum, BVEC v);
|
||||
extern int bvec_isconst(BVEC e);
|
||||
extern int bvec_val(BVEC e);
|
||||
extern void bvec_free(BVEC v);
|
||||
extern BVEC bvec_addref(BVEC v);
|
||||
extern BVEC bvec_delref(BVEC v);
|
||||
extern BVEC bvec_map1(BVEC a, BDD (*fun)(BDD));
|
||||
extern BVEC bvec_map2(BVEC a, BVEC b, BDD (*fun)(BDD,BDD));
|
||||
extern BVEC bvec_map3(BVEC a, BVEC b, BVEC c, BDD (*fun)(BDD,BDD,BDD));
|
||||
extern BVEC bvec_add(BVEC left, BVEC right);
|
||||
extern BVEC bvec_sub(BVEC left, BVEC right);
|
||||
extern BVEC bvec_mulfixed(BVEC e, int c);
|
||||
extern BVEC bvec_mul(BVEC left, BVEC right);
|
||||
extern int bvec_divfixed(BVEC e, int c, BVEC *res, BVEC *rem);
|
||||
extern int bvec_div(BVEC left, BVEC right, BVEC *res, BVEC *rem);
|
||||
extern BVEC bvec_ite(BDD a, BVEC b, BVEC c);
|
||||
extern BVEC bvec_shlfixed(BVEC e, int pos, BDD c);
|
||||
extern BVEC bvec_shl(BVEC l, BVEC r, BDD c);
|
||||
extern BVEC bvec_shrfixed(BVEC e, int pos, BDD c);
|
||||
extern BVEC bvec_shr(BVEC l, BVEC r, BDD c);
|
||||
extern BDD bvec_lth(BVEC left, BVEC right);
|
||||
extern BDD bvec_lte(BVEC left, BVEC right);
|
||||
extern BDD bvec_gth(BVEC left, BVEC right);
|
||||
extern BDD bvec_gte(BVEC left, BVEC right);
|
||||
extern BDD bvec_equ(BVEC left, BVEC right);
|
||||
extern BDD bvec_neq(BVEC left, BVEC right);
|
||||
|
||||
#ifdef CPLUSPLUS
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
If this file is included from a C++ compiler then the following
|
||||
classes, wrappers and hacks are supplied.
|
||||
*************************************************************************/
|
||||
#ifdef CPLUSPLUS
|
||||
|
||||
/*=== User BVEC class ==================================================*/
|
||||
|
||||
class bvec
|
||||
{
|
||||
public:
|
||||
|
||||
bvec(void) { roots.bitvec=NULL; roots.bitnum=0; }
|
||||
bvec(int bitnum) { roots=bvec_false(bitnum); }
|
||||
bvec(int bitnum, int val) { roots=bvec_con(bitnum,val); }
|
||||
bvec(const bvec &v) { roots=bvec_copy(v.roots); }
|
||||
~bvec(void) { bvec_free(roots); }
|
||||
|
||||
void set(int i, const bdd &b);
|
||||
bdd operator[](int i) const { return roots.bitvec[i]; }
|
||||
int bitnum(void) const { return roots.bitnum; }
|
||||
int empty(void) const { return roots.bitnum==0; }
|
||||
bvec operator=(const bvec &src);
|
||||
|
||||
private:
|
||||
BVEC roots;
|
||||
|
||||
bvec(const BVEC &v) { roots=v; } /* NOTE: Must be a shallow copy! */
|
||||
|
||||
friend bvec bvec_truepp(int bitnum);
|
||||
friend bvec bvec_falsepp(int bitnum);
|
||||
friend bvec bvec_conpp(int bitnum, int val);
|
||||
friend bvec bvec_varpp(int bitnum, int offset, int step);
|
||||
friend bvec bvec_varfddpp(int var);
|
||||
friend bvec bvec_varvecpp(int bitnum, int *var);
|
||||
friend bvec bvec_coerce(int bitnum, const bvec &v);
|
||||
friend int bvec_isconst(const bvec &e);
|
||||
friend int bvec_val(const bvec &e);
|
||||
friend bvec bvec_copy(const bvec &v);
|
||||
friend bvec bvec_map1(const bvec &a,
|
||||
bdd (*fun)(const bdd &));
|
||||
friend bvec bvec_map2(const bvec &a, const bvec &b,
|
||||
bdd (*fun)(const bdd &, const bdd &));
|
||||
friend bvec bvec_map3(const bvec &a, const bvec &b, const bvec &c,
|
||||
bdd (*fun)(const bdd &, const bdd &, const bdd &));
|
||||
friend bvec bvec_add(const bvec &left, const bvec &right);
|
||||
friend bvec bvec_sub(const bvec &left, const bvec &right);
|
||||
friend bvec bvec_mulfixed(const bvec &e, int c);
|
||||
friend bvec bvec_mul(const bvec &left, const bvec &right);
|
||||
friend int bvec_divfixed(const bvec &e, int c, bvec &res, bvec &rem);
|
||||
friend int bvec_div(const bvec &l, const bvec &r, bvec &res, bvec &rem);
|
||||
friend bvec bvec_ite(const bdd& a, const bvec& b, const bvec& c);
|
||||
friend bvec bvec_shlfixed(const bvec &e, int pos, const bdd &c);
|
||||
friend bvec bvec_shl(const bvec &left, const bvec &right, const bdd &c);
|
||||
friend bvec bvec_shrfixed(const bvec &e, int pos, const bdd &c);
|
||||
friend bvec bvec_shr(const bvec &left, const bvec &right, const bdd &c);
|
||||
friend bdd bvec_lth(const bvec &left, const bvec &right);
|
||||
friend bdd bvec_lte(const bvec &left, const bvec &right);
|
||||
friend bdd bvec_gth(const bvec &left, const bvec &right);
|
||||
friend bdd bvec_gte(const bvec &left, const bvec &right);
|
||||
friend bdd bvec_equ(const bvec &left, const bvec &right);
|
||||
friend bdd bvec_neq(const bvec &left, const bvec &right);
|
||||
|
||||
public:
|
||||
bvec operator&(const bvec &a) const { return bvec_map2(*this, a, bdd_and); }
|
||||
bvec operator^(const bvec &a) const { return bvec_map2(*this, a, bdd_xor); }
|
||||
bvec operator|(const bvec &a) const { return bvec_map2(*this, a, bdd_or); }
|
||||
bvec operator!(void) const { return bvec_map1(*this, bdd_not); }
|
||||
bvec operator<<(int a) const { return bvec_shlfixed(*this,a,bddfalse); }
|
||||
bvec operator<<(const bvec &a) const { return bvec_shl(*this,a,bddfalse); }
|
||||
bvec operator>>(int a) const { return bvec_shrfixed(*this,a,bddfalse); }
|
||||
bvec operator>>(const bvec &a) const { return bvec_shr(*this,a,bddfalse); }
|
||||
bvec operator+(const bvec &a) const { return bvec_add(*this, a); }
|
||||
bvec operator-(const bvec &a) const { return bvec_sub(*this, a); }
|
||||
bvec operator*(int a) const { return bvec_mulfixed(*this, a); }
|
||||
bvec operator*(const bvec a) const { return bvec_mul(*this, a); }
|
||||
bdd operator<(const bvec &a) const { return bvec_lth(*this, a); }
|
||||
bdd operator<=(const bvec &a) const { return bvec_lte(*this, a); }
|
||||
bdd operator>(const bvec &a) const { return bvec_gth(*this, a); }
|
||||
bdd operator>=(const bvec &a) const { return bvec_gte(*this, a); }
|
||||
bdd operator==(const bvec &a) const { return bvec_equ(*this, a); }
|
||||
bdd operator!=(const bvec &a) const { return bvec_neq(*this, a); }
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &, const bvec &);
|
||||
|
||||
inline bvec bvec_truepp(int bitnum)
|
||||
{ return bvec_true(bitnum); }
|
||||
|
||||
inline bvec bvec_falsepp(int bitnum)
|
||||
{ return bvec_false(bitnum); }
|
||||
|
||||
inline bvec bvec_conpp(int bitnum, int val)
|
||||
{ return bvec_con(bitnum, val); }
|
||||
|
||||
inline bvec bvec_varpp(int bitnum, int offset, int step)
|
||||
{ return bvec_var(bitnum, offset, step); }
|
||||
|
||||
inline bvec bvec_varfddpp(int var)
|
||||
{ return bvec_varfdd(var); }
|
||||
|
||||
inline bvec bvec_varvecpp(int bitnum, int *var)
|
||||
{ return bvec_varvec(bitnum, var); }
|
||||
|
||||
inline bvec bvec_coerce(int bitnum, const bvec &v)
|
||||
{ return bvec_coerce(bitnum, v.roots); }
|
||||
|
||||
inline int bvec_isconst(const bvec &e)
|
||||
{ return bvec_isconst(e.roots); }
|
||||
|
||||
inline int bvec_val(const bvec &e)
|
||||
{ return bvec_val(e.roots); }
|
||||
|
||||
inline bvec bvec_copy(const bvec &v)
|
||||
{ return bvec_copy(v.roots); }
|
||||
|
||||
inline bvec bvec_add(const bvec &left, const bvec &right)
|
||||
{ return bvec_add(left.roots, right.roots); }
|
||||
|
||||
inline bvec bvec_sub(const bvec &left, const bvec &right)
|
||||
{ return bvec_sub(left.roots, right.roots); }
|
||||
|
||||
inline bvec bvec_mulfixed(const bvec &e, int c)
|
||||
{ return bvec_mulfixed(e.roots, c); }
|
||||
|
||||
inline bvec bvec_mul(const bvec &left, const bvec &right)
|
||||
{ return bvec_mul(left.roots, right.roots); }
|
||||
|
||||
inline int bvec_divfixed(const bvec &e, int c, bvec &res, bvec &rem)
|
||||
{ return bvec_divfixed(e.roots, c, &res.roots, &rem.roots); }
|
||||
|
||||
inline int bvec_div(const bvec &l, const bvec &r, bvec &res, bvec &rem)
|
||||
{ return bvec_div(l.roots, r.roots, &res.roots, &rem.roots); }
|
||||
|
||||
inline bvec bvec_ite(const bdd& a, const bvec& b, const bvec& c)
|
||||
{ return bvec_ite(a.root, b.roots, c.roots); }
|
||||
|
||||
inline bvec bvec_shlfixed(const bvec &e, int pos, const bdd &c)
|
||||
{ return bvec_shlfixed(e.roots, pos, c.root); }
|
||||
|
||||
inline bvec bvec_shl(const bvec &left, const bvec &right, const bdd &c)
|
||||
{ return bvec_shl(left.roots, right.roots, c.root); }
|
||||
|
||||
inline bvec bvec_shrfixed(const bvec &e, int pos, const bdd &c)
|
||||
{ return bvec_shrfixed(e.roots, pos, c.root); }
|
||||
|
||||
inline bvec bvec_shr(const bvec &left, const bvec &right, const bdd &c)
|
||||
{ return bvec_shr(left.roots, right.roots, c.root); }
|
||||
|
||||
inline bdd bvec_lth(const bvec &left, const bvec &right)
|
||||
{ return bvec_lth(left.roots, right.roots); }
|
||||
|
||||
inline bdd bvec_lte(const bvec &left, const bvec &right)
|
||||
{ return bvec_lte(left.roots, right.roots); }
|
||||
|
||||
inline bdd bvec_gth(const bvec &left, const bvec &right)
|
||||
{ return bvec_gth(left.roots, right.roots); }
|
||||
|
||||
inline bdd bvec_gte(const bvec &left, const bvec &right)
|
||||
{ return bvec_gte(left.roots, right.roots); }
|
||||
|
||||
inline bdd bvec_equ(const bvec &left, const bvec &right)
|
||||
{ return bvec_equ(left.roots, right.roots); }
|
||||
|
||||
inline bdd bvec_neq(const bvec &left, const bvec &right)
|
||||
{ return bvec_neq(left.roots, right.roots); }
|
||||
|
||||
|
||||
/* Hack to allow for overloading */
|
||||
#define bvec_var(a,b,c) bvec_varpp(a,b,c)
|
||||
#define bvec_varfdd(a) bvec_varfddpp(a)
|
||||
#define bvec_varvec(a,b) bvec_varvecpp(a,b)
|
||||
#define bvec_true(a) bvec_truepp(a)
|
||||
#define bvec_false(a) bvec_falsepp(a)
|
||||
#define bvec_con(a,b) bvec_conpp((a),(b))
|
||||
|
||||
|
||||
#endif /* CPLUSPLUS */
|
||||
|
||||
#endif /* _BVEC_H */
|
||||
|
||||
/* EOF */
|
||||
97
buddy/src/cache.c
Normal file
97
buddy/src/cache.c
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
/*========================================================================
|
||||
Copyright (C) 1996-2002 by Jorn Lind-Nielsen
|
||||
All rights reserved
|
||||
|
||||
Permission is hereby granted, without written agreement and without
|
||||
license or royalty fees, to use, reproduce, prepare derivative
|
||||
works, distribute, and display this software and its documentation
|
||||
for any purpose, provided that (1) the above copyright notice and
|
||||
the following two paragraphs appear in all copies of the source code
|
||||
and (2) redistributions, including without limitation binaries,
|
||||
reproduce these notices in the supporting documentation. Substantial
|
||||
modifications to this software may be copyrighted by their authors
|
||||
and need not follow the licensing terms described here, provided
|
||||
that the new terms are clearly indicated in all files where they apply.
|
||||
|
||||
IN NO EVENT SHALL JORN LIND-NIELSEN, OR DISTRIBUTORS OF THIS
|
||||
SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
|
||||
SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE
|
||||
ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
JORN LIND-NIELSEN SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
|
||||
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
||||
MODIFICATIONS.
|
||||
========================================================================*/
|
||||
|
||||
/*************************************************************************
|
||||
$Header: /Volumes/CVS/repository/spot/spot/buddy/src/cache.c,v 1.1 2003/05/05 10:57:56 aduret Exp $
|
||||
FILE: cache.c
|
||||
DESCR: Cache class for caching apply/exist etc. results in BDD package
|
||||
AUTH: Jorn Lind
|
||||
DATE: (C) june 1997
|
||||
*************************************************************************/
|
||||
#include <stdlib.h>
|
||||
#include "kernel.h"
|
||||
#include "cache.h"
|
||||
#include "prime.h"
|
||||
|
||||
/*************************************************************************
|
||||
*************************************************************************/
|
||||
|
||||
int BddCache_init(BddCache *cache, int size)
|
||||
{
|
||||
int n;
|
||||
|
||||
size = bdd_prime_gte(size);
|
||||
|
||||
if ((cache->table=NEW(BddCacheData,size)) == NULL)
|
||||
return bdd_error(BDD_MEMORY);
|
||||
|
||||
for (n=0 ; n<size ; n++)
|
||||
cache->table[n].a = -1;
|
||||
cache->tablesize = size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void BddCache_done(BddCache *cache)
|
||||
{
|
||||
free(cache->table);
|
||||
cache->table = NULL;
|
||||
cache->tablesize = 0;
|
||||
}
|
||||
|
||||
|
||||
int BddCache_resize(BddCache *cache, int newsize)
|
||||
{
|
||||
int n;
|
||||
|
||||
free(cache->table);
|
||||
|
||||
newsize = bdd_prime_gte(newsize);
|
||||
|
||||
if ((cache->table=NEW(BddCacheData,newsize)) == NULL)
|
||||
return bdd_error(BDD_MEMORY);
|
||||
|
||||
for (n=0 ; n<newsize ; n++)
|
||||
cache->table[n].a = -1;
|
||||
cache->tablesize = newsize;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void BddCache_reset(BddCache *cache)
|
||||
{
|
||||
register int n;
|
||||
for (n=0 ; n<cache->tablesize ; n++)
|
||||
cache->table[n].a = -1;
|
||||
}
|
||||
|
||||
|
||||
/* EOF */
|
||||
70
buddy/src/cache.h
Normal file
70
buddy/src/cache.h
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/*========================================================================
|
||||
Copyright (C) 1996-2002 by Jorn Lind-Nielsen
|
||||
All rights reserved
|
||||
|
||||
Permission is hereby granted, without written agreement and without
|
||||
license or royalty fees, to use, reproduce, prepare derivative
|
||||
works, distribute, and display this software and its documentation
|
||||
for any purpose, provided that (1) the above copyright notice and
|
||||
the following two paragraphs appear in all copies of the source code
|
||||
and (2) redistributions, including without limitation binaries,
|
||||
reproduce these notices in the supporting documentation. Substantial
|
||||
modifications to this software may be copyrighted by their authors
|
||||
and need not follow the licensing terms described here, provided
|
||||
that the new terms are clearly indicated in all files where they apply.
|
||||
|
||||
IN NO EVENT SHALL JORN LIND-NIELSEN, OR DISTRIBUTORS OF THIS
|
||||
SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
|
||||
SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE
|
||||
ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
JORN LIND-NIELSEN SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
|
||||
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
||||
MODIFICATIONS.
|
||||
========================================================================*/
|
||||
|
||||
/*************************************************************************
|
||||
$Header: /Volumes/CVS/repository/spot/spot/buddy/src/cache.h,v 1.1 2003/05/05 10:57:56 aduret Exp $
|
||||
FILE: cache.h
|
||||
DESCR: Cache class for caching apply/exist etc. results
|
||||
AUTH: Jorn Lind
|
||||
DATE: (C) june 1997
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef _CACHE_H
|
||||
#define _CACHE_H
|
||||
|
||||
typedef struct
|
||||
{
|
||||
union
|
||||
{
|
||||
double dres;
|
||||
int res;
|
||||
} r;
|
||||
int a,b,c;
|
||||
} BddCacheData;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BddCacheData *table;
|
||||
int tablesize;
|
||||
} BddCache;
|
||||
|
||||
|
||||
extern int BddCache_init(BddCache *, int);
|
||||
extern void BddCache_done(BddCache *);
|
||||
extern int BddCache_resize(BddCache *, int);
|
||||
extern void BddCache_reset(BddCache *);
|
||||
|
||||
#define BddCache_lookup(cache, hash) (&(cache)->table[hash % (cache)->tablesize])
|
||||
|
||||
|
||||
#endif /* _CACHE_H */
|
||||
|
||||
|
||||
/* EOF */
|
||||
624
buddy/src/cppext.cxx
Normal file
624
buddy/src/cppext.cxx
Normal file
|
|
@ -0,0 +1,624 @@
|
|||
/*========================================================================
|
||||
Copyright (C) 1996-2002 by Jorn Lind-Nielsen
|
||||
All rights reserved
|
||||
|
||||
Permission is hereby granted, without written agreement and without
|
||||
license or royalty fees, to use, reproduce, prepare derivative
|
||||
works, distribute, and display this software and its documentation
|
||||
for any purpose, provided that (1) the above copyright notice and
|
||||
the following two paragraphs appear in all copies of the source code
|
||||
and (2) redistributions, including without limitation binaries,
|
||||
reproduce these notices in the supporting documentation. Substantial
|
||||
modifications to this software may be copyrighted by their authors
|
||||
and need not follow the licensing terms described here, provided
|
||||
that the new terms are clearly indicated in all files where they apply.
|
||||
|
||||
IN NO EVENT SHALL JORN LIND-NIELSEN, OR DISTRIBUTORS OF THIS
|
||||
SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
|
||||
SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE
|
||||
ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
JORN LIND-NIELSEN SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
|
||||
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
||||
MODIFICATIONS.
|
||||
========================================================================*/
|
||||
|
||||
/*************************************************************************
|
||||
$Header: /Volumes/CVS/repository/spot/spot/buddy/src/cppext.cxx,v 1.1 2003/05/05 10:57:56 aduret Exp $
|
||||
FILE: cppext.cxx
|
||||
DESCR: C++ extension of BDD package
|
||||
AUTH: Jorn Lind
|
||||
DATE: (C) august 1997
|
||||
*************************************************************************/
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <iomanip>
|
||||
#include "kernel.h"
|
||||
#include "bvec.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* Formatting objects for iostreams */
|
||||
#define IOFORMAT_SET 0
|
||||
#define IOFORMAT_TABLE 1
|
||||
#define IOFORMAT_DOT 2
|
||||
#define IOFORMAT_ALL 3
|
||||
#define IOFORMAT_FDDSET 4
|
||||
|
||||
int bdd_ioformat::curformat = IOFORMAT_SET;
|
||||
bdd_ioformat bddset(IOFORMAT_SET);
|
||||
bdd_ioformat bddtable(IOFORMAT_TABLE);
|
||||
bdd_ioformat bdddot(IOFORMAT_DOT);
|
||||
bdd_ioformat bddall(IOFORMAT_ALL);
|
||||
bdd_ioformat fddset(IOFORMAT_FDDSET);
|
||||
|
||||
/* Constant true and false extension */
|
||||
const bdd bddtruepp = bdd_true();
|
||||
const bdd bddfalsepp = bdd_false();
|
||||
|
||||
/* Internal prototypes */
|
||||
static void bdd_printset_rec(ostream&, int, int*);
|
||||
static void bdd_printdot_rec(ostream&, int);
|
||||
static void fdd_printset_rec(ostream &, int, int *);
|
||||
|
||||
|
||||
static bddstrmhandler strmhandler_bdd;
|
||||
static bddstrmhandler strmhandler_fdd;
|
||||
|
||||
// Avoid calling C++ version of anodecount
|
||||
#undef bdd_anodecount
|
||||
|
||||
/*************************************************************************
|
||||
Setup (and shutdown)
|
||||
*************************************************************************/
|
||||
|
||||
#undef bdd_init
|
||||
|
||||
int bdd_cpp_init(int n, int c)
|
||||
{
|
||||
int ok = bdd_init(n,c);
|
||||
|
||||
strmhandler_bdd = NULL;
|
||||
strmhandler_fdd = NULL;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
BDD C++ functions
|
||||
*************************************************************************/
|
||||
|
||||
bdd bdd_buildcube(int val, int width, const bdd *variables)
|
||||
{
|
||||
BDD *var = NEW(BDD,width);
|
||||
BDD res;
|
||||
int n;
|
||||
|
||||
// No need for ref.cou. since variables[n] holds the reference
|
||||
for (n=0 ; n<width ; n++)
|
||||
var[n] = variables[n].root;
|
||||
|
||||
res = bdd_buildcube(val, width, var);
|
||||
|
||||
free(var);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
int bdd_setbddpairs(bddPair *pair, int *oldvar, const bdd *newvar, int size)
|
||||
{
|
||||
if (pair == NULL)
|
||||
return 0;
|
||||
|
||||
for (int n=0,e=0 ; n<size ; n++)
|
||||
if ((e=bdd_setbddpair(pair, oldvar[n], newvar[n].root)) < 0)
|
||||
return e;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int bdd_anodecountpp(const bdd *r, int num)
|
||||
{
|
||||
BDD *cpr = NEW(BDD,num);
|
||||
int cou;
|
||||
int n;
|
||||
|
||||
// No need for ref.cou. since r[n] holds the reference
|
||||
for (n=0 ; n<num ; n++)
|
||||
cpr[n] = r[n].root;
|
||||
|
||||
cou = bdd_anodecount(cpr,num);
|
||||
|
||||
free(cpr);
|
||||
|
||||
return cou;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
BDD class functions
|
||||
*************************************************************************/
|
||||
|
||||
bdd bdd::operator=(const bdd &r)
|
||||
{
|
||||
if (root != r.root)
|
||||
{
|
||||
bdd_delref(root);
|
||||
root = r.root;
|
||||
bdd_addref(root);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
bdd bdd::operator=(int r)
|
||||
{
|
||||
if (root != r)
|
||||
{
|
||||
bdd_delref(root);
|
||||
root = r;
|
||||
bdd_addref(root);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
C++ iostream operators
|
||||
*************************************************************************/
|
||||
|
||||
/*
|
||||
NAME {* bdd\_strm\_hook *}
|
||||
SECTION {* kernel *}
|
||||
SHORT {* Specifies a printing callback handler *}
|
||||
PROTO {* bddstrmhandler bdd_strm_hook(bddstrmhandler handler) *}
|
||||
DESCR {* A printing callback handler for use with BDDs is used to
|
||||
convert the BDD variable number into something readable by the
|
||||
end user. Typically the handler will print a string name
|
||||
instead of the number. A handler could look like this:
|
||||
\begin{verbatim}
|
||||
void printhandler(ostream &o, int var)
|
||||
{
|
||||
extern char **names;
|
||||
o << names[var];
|
||||
}
|
||||
\end{verbatim}
|
||||
|
||||
\noindent
|
||||
The handler can then be passed to BuDDy like this:
|
||||
{\tt bdd\_strm\_hook(printhandler)}.
|
||||
|
||||
No default handler is supplied. The argument {\tt handler} may be
|
||||
NULL if no handler is needed. *}
|
||||
RETURN {* The old handler *}
|
||||
ALSO {* bdd\_printset, bdd\_file\_hook, fdd\_strm\_hook *}
|
||||
*/
|
||||
bddstrmhandler bdd_strm_hook(bddstrmhandler handler)
|
||||
{
|
||||
bddstrmhandler old = strmhandler_bdd;
|
||||
strmhandler_bdd = handler;
|
||||
return old;
|
||||
}
|
||||
|
||||
|
||||
ostream &operator<<(ostream &o, const bdd &r)
|
||||
{
|
||||
if (bdd_ioformat::curformat == IOFORMAT_SET)
|
||||
{
|
||||
if (r.root < 2)
|
||||
{
|
||||
o << (r.root == 0 ? "F" : "T");
|
||||
return o;
|
||||
}
|
||||
|
||||
int *set = new int[bddvarnum];
|
||||
if (set == NULL)
|
||||
{
|
||||
bdd_error(BDD_MEMORY);
|
||||
return o;
|
||||
}
|
||||
|
||||
memset(set, 0, sizeof(int) * bddvarnum);
|
||||
bdd_printset_rec(o, r.root, set);
|
||||
delete[] set;
|
||||
}
|
||||
else
|
||||
if (bdd_ioformat::curformat == IOFORMAT_TABLE)
|
||||
{
|
||||
o << "ROOT: " << r.root << "\n";
|
||||
if (r.root < 2)
|
||||
return o;
|
||||
|
||||
bdd_mark(r.root);
|
||||
|
||||
for (int n=0 ; n<bddnodesize ; n++)
|
||||
{
|
||||
if (LEVEL(n) & MARKON)
|
||||
{
|
||||
BddNode *node = &bddnodes[n];
|
||||
|
||||
LEVELp(node) &= MARKOFF;
|
||||
|
||||
o << "[" << setw(5) << n << "] ";
|
||||
if (strmhandler_bdd)
|
||||
strmhandler_bdd(o,bddlevel2var[LEVELp(node)]);
|
||||
else
|
||||
o << setw(3) << bddlevel2var[LEVELp(node)];
|
||||
o << " :";
|
||||
o << " " << setw(3) << LOWp(node);
|
||||
o << " " << setw(3) << HIGHp(node);
|
||||
o << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if (bdd_ioformat::curformat == IOFORMAT_DOT)
|
||||
{
|
||||
o << "digraph G {\n";
|
||||
o << "0 [shape=box, label=\"0\", style=filled, shape=box, height=0.3, width=0.3];\n";
|
||||
o << "1 [shape=box, label=\"1\", style=filled, shape=box, height=0.3, width=0.3];\n";
|
||||
|
||||
bdd_printdot_rec(o, r.root);
|
||||
|
||||
o << "}\n";
|
||||
|
||||
bdd_unmark(r.root);
|
||||
}
|
||||
else
|
||||
if (bdd_ioformat::curformat == IOFORMAT_FDDSET)
|
||||
{
|
||||
if (ISCONST(r.root))
|
||||
{
|
||||
o << (r == 0 ? "F" : "T");
|
||||
return o;
|
||||
}
|
||||
|
||||
int *set = new int[bddvarnum];
|
||||
if (set == NULL)
|
||||
{
|
||||
bdd_error(BDD_MEMORY);
|
||||
return o;
|
||||
}
|
||||
|
||||
memset(set, 0, sizeof(int) * bddvarnum);
|
||||
fdd_printset_rec(o, r.root, set);
|
||||
delete[] set;
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
NAME {* operator{\tt<<} *}
|
||||
SECTION {* fileio *}
|
||||
SHORT {* C++ output operator for BDDs *}
|
||||
PROTO {* ostream &operator<<(ostream &o, const bdd_ioformat &f)
|
||||
ostream &operator<<(ostream &o, const bdd &r) *}
|
||||
DESCR {* BDDs can be printed in various formats using the C++ iostreams
|
||||
library. The formats are the those used in {\tt bdd\_printset},
|
||||
{\tt bdd\_printtable}, {\tt fdd\_printset} and {\tt bdd\_printdot}.
|
||||
The format can be specified with the following format objects:
|
||||
\begin{tabular}{ll}\\
|
||||
{\tt bddset } & BDD level set format \\
|
||||
{\tt bddtable } & BDD level table format \\
|
||||
{\tt bdddot } & Output for use with Dot \\
|
||||
{\tt bddall } & The whole node table \\
|
||||
{\tt fddset } & FDD level set format \\
|
||||
\end{tabular}\\
|
||||
|
||||
\noindent
|
||||
So a BDD {\tt x} can for example be printed as a table with the
|
||||
command\\
|
||||
|
||||
\indent {\tt cout << bddtable << x << endl}.
|
||||
*}
|
||||
RETURN {* The specified output stream *}
|
||||
ALSO {* bdd\_strm\_hook, fdd\_strm\_hook *}
|
||||
*/
|
||||
ostream &operator<<(ostream &o, const bdd_ioformat &f)
|
||||
{
|
||||
if (f.format == IOFORMAT_SET || f.format == IOFORMAT_TABLE ||
|
||||
f.format == IOFORMAT_DOT || f.format == IOFORMAT_FDDSET)
|
||||
bdd_ioformat::curformat = f.format;
|
||||
else
|
||||
if (f.format == IOFORMAT_ALL)
|
||||
{
|
||||
for (int n=0 ; n<bddnodesize ; n++)
|
||||
{
|
||||
const BddNode *node = &bddnodes[n];
|
||||
|
||||
if (LOWp(node) != -1)
|
||||
{
|
||||
o << "[" << setw(5) << n << "] ";
|
||||
if (strmhandler_bdd)
|
||||
strmhandler_bdd(o,bddlevel2var[LEVELp(node)]);
|
||||
else
|
||||
o << setw(3) << bddlevel2var[LEVELp(node)] << " :";
|
||||
o << " " << setw(3) << LOWp(node);
|
||||
o << " " << setw(3) << HIGHp(node);
|
||||
o << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
static void bdd_printset_rec(ostream& o, int r, int* set)
|
||||
{
|
||||
int n;
|
||||
int first;
|
||||
|
||||
if (r == 0)
|
||||
return;
|
||||
else
|
||||
if (r == 1)
|
||||
{
|
||||
o << "<";
|
||||
first = 1;
|
||||
|
||||
for (n=0 ; n<bddvarnum ; n++)
|
||||
{
|
||||
if (set[n] > 0)
|
||||
{
|
||||
if (!first)
|
||||
o << ", ";
|
||||
first = 0;
|
||||
if (strmhandler_bdd)
|
||||
strmhandler_bdd(o,bddlevel2var[n]);
|
||||
else
|
||||
o << bddlevel2var[n];
|
||||
o << ":" << (set[n]==2 ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
o << ">";
|
||||
}
|
||||
else
|
||||
{
|
||||
set[LEVEL(r)] = 1;
|
||||
bdd_printset_rec(o, LOW(r), set);
|
||||
|
||||
set[LEVEL(r)] = 2;
|
||||
bdd_printset_rec(o, HIGH(r), set);
|
||||
|
||||
set[LEVEL(r)] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void bdd_printdot_rec(ostream& o, int r)
|
||||
{
|
||||
if (ISCONST(r) || MARKED(r))
|
||||
return;
|
||||
|
||||
o << r << "[label=\"";
|
||||
if (strmhandler_bdd)
|
||||
strmhandler_bdd(o,bddlevel2var[LEVEL(r)]);
|
||||
else
|
||||
o << bddlevel2var[LEVEL(r)];
|
||||
o << "\"];\n";
|
||||
o << r << " -> " << LOW(r) << "[style=dotted];\n";
|
||||
o << r << " -> " << HIGH(r) << "[style=filled];\n";
|
||||
|
||||
SETMARK(r);
|
||||
|
||||
bdd_printdot_rec(o, LOW(r));
|
||||
bdd_printdot_rec(o, HIGH(r));
|
||||
}
|
||||
|
||||
|
||||
static void fdd_printset_rec(ostream &o, int r, int *set)
|
||||
{
|
||||
int n,m,i;
|
||||
int used = 0;
|
||||
int *binval;
|
||||
int ok, first;
|
||||
|
||||
if (r == 0)
|
||||
return;
|
||||
else
|
||||
if (r == 1)
|
||||
{
|
||||
o << "<";
|
||||
first=1;
|
||||
int fdvarnum = fdd_domainnum();
|
||||
|
||||
for (n=0 ; n<fdvarnum ; n++)
|
||||
{
|
||||
int firstval=1;
|
||||
used = 0;
|
||||
int binsize = fdd_varnum(n);
|
||||
int *vars = fdd_vars(n);
|
||||
|
||||
for (m=0 ; m<binsize ; m++)
|
||||
if (set[vars[m]] != 0)
|
||||
used = 1;
|
||||
|
||||
if (used)
|
||||
{
|
||||
if (!first)
|
||||
o << ", ";
|
||||
first = 0;
|
||||
if (strmhandler_fdd)
|
||||
strmhandler_fdd(o, n);
|
||||
else
|
||||
o << n;
|
||||
o << ":";
|
||||
|
||||
for (m=0 ; m<(1<<binsize) ; m++)
|
||||
{
|
||||
binval = fdddec2bin(n, m);
|
||||
ok=1;
|
||||
|
||||
for (i=0 ; i<binsize && ok ; i++)
|
||||
if (set[vars[i]] == 1 && binval[i] != 0)
|
||||
ok = 0;
|
||||
else
|
||||
if (set[vars[i]] == 2 && binval[i] != 1)
|
||||
ok = 0;
|
||||
|
||||
if (ok)
|
||||
{
|
||||
if (firstval)
|
||||
o << m;
|
||||
else
|
||||
o << "/" << m;
|
||||
firstval = 0;
|
||||
}
|
||||
|
||||
free(binval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
o << ">";
|
||||
}
|
||||
else
|
||||
{
|
||||
set[bddlevel2var[LEVEL(r)]] = 1;
|
||||
fdd_printset_rec(o, LOW(r), set);
|
||||
|
||||
set[bddlevel2var[LEVEL(r)]] = 2;
|
||||
fdd_printset_rec(o, HIGH(r), set);
|
||||
|
||||
set[bddlevel2var[LEVEL(r)]] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*=[ FDD I/O functions ]================================================*/
|
||||
|
||||
/*
|
||||
NAME {* fdd\_strm\_hook *}
|
||||
SECTION {* fdd *}
|
||||
SHORT {* Specifies a printing callback handler *}
|
||||
PROTO {* bddstrmhandler fdd_strm_hook(bddstrmhandler handler) *}
|
||||
DESCR {* A printing callback handler for use with FDDs is used to
|
||||
convert the FDD integer identifier into something readable by the
|
||||
end user. Typically the handler will print a string name
|
||||
instead of the identifier. A handler could look like this:
|
||||
\begin{verbatim}
|
||||
void printhandler(ostream &o, int var)
|
||||
{
|
||||
extern char **names;
|
||||
o << names[var];
|
||||
}
|
||||
\end{verbatim}
|
||||
|
||||
\noindent
|
||||
The handler can then be passed to BuDDy like this:
|
||||
{\tt fdd\_strm\_hook(printhandler)}.
|
||||
|
||||
No default handler is supplied. The argument {\tt handler} may be
|
||||
NULL if no handler is needed. *}
|
||||
RETURN {* The old handler *}
|
||||
ALSO {* fdd\_printset, bdd\_file\_hook *}
|
||||
*/
|
||||
bddstrmhandler fdd_strm_hook(bddstrmhandler handler)
|
||||
{
|
||||
bddstrmhandler old = strmhandler_fdd;
|
||||
strmhandler_fdd = handler;
|
||||
return old;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
bvec functions
|
||||
*************************************************************************/
|
||||
|
||||
bvec bvec::operator=(const bvec &src)
|
||||
{
|
||||
if (&src != this)
|
||||
{
|
||||
bvec_free(roots);
|
||||
roots = bvec_copy(src.roots);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void bvec::set(int bitnum, const bdd &b)
|
||||
{
|
||||
bdd_delref(roots.bitvec[bitnum]);
|
||||
roots.bitvec[bitnum] = b.root;
|
||||
bdd_addref(roots.bitvec[bitnum]);
|
||||
}
|
||||
|
||||
|
||||
/*======================================================================*/
|
||||
|
||||
bvec bvec_map1(const bvec &a,
|
||||
bdd (*fun)(const bdd &))
|
||||
{
|
||||
bvec res;
|
||||
int n;
|
||||
|
||||
res = bvec_false(a.bitnum());
|
||||
for (n=0 ; n < a.bitnum() ; n++)
|
||||
res.set(n, fun(a[n]));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
bvec bvec_map2(const bvec &a, const bvec &b,
|
||||
bdd (*fun)(const bdd &, const bdd &))
|
||||
{
|
||||
bvec res;
|
||||
int n;
|
||||
|
||||
if (a.bitnum() != b.bitnum())
|
||||
{
|
||||
bdd_error(BVEC_SIZE);
|
||||
return res;
|
||||
}
|
||||
|
||||
res = bvec_false(a.bitnum());
|
||||
for (n=0 ; n < a.bitnum() ; n++)
|
||||
res.set(n, fun(a[n], b[n]));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
bvec bvec_map3(const bvec &a, const bvec &b, const bvec &c,
|
||||
bdd (*fun)(const bdd &, const bdd &, const bdd &))
|
||||
{
|
||||
bvec res;
|
||||
int n;
|
||||
|
||||
if (a.bitnum() != b.bitnum() || b.bitnum() != c.bitnum())
|
||||
{
|
||||
bdd_error(BVEC_SIZE);
|
||||
return res;
|
||||
}
|
||||
|
||||
res = bvec_false(a.bitnum());
|
||||
for (n=0 ; n < a.bitnum() ; n++)
|
||||
res.set(n, fun(a[n], b[n], c[n]) );
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
ostream &operator<<(ostream &o, const bvec &v)
|
||||
{
|
||||
for (int i=0 ; i<v.bitnum() ; ++i)
|
||||
{
|
||||
o << "B" << i << ":\n"
|
||||
<< v[i] << "\n";
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
12
buddy/src/depend.inf
Normal file
12
buddy/src/depend.inf
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
bddio.o: bddio.c kernel.h bdd.h
|
||||
bddop.o: bddop.c kernel.h bdd.h cache.h
|
||||
bvec.o: bvec.c kernel.h bdd.h bvec.h fdd.h
|
||||
cache.o: cache.c kernel.h bdd.h cache.h prime.h
|
||||
fdd.o: fdd.c kernel.h bdd.h fdd.h
|
||||
imatrix.o: imatrix.c kernel.h bdd.h imatrix.h
|
||||
kernel.o: kernel.c kernel.h bdd.h cache.h prime.h
|
||||
pairs.o: pairs.c kernel.h bdd.h
|
||||
prime.o: prime.c prime.h
|
||||
reorder.o: reorder.c kernel.h bdd.h bddtree.h imatrix.h prime.h
|
||||
tree.o: tree.c kernel.h bdd.h bddtree.h
|
||||
cppext.o: cppext.cxx kernel.h bdd.h bvec.h fdd.h
|
||||
1077
buddy/src/fdd.c
Normal file
1077
buddy/src/fdd.c
Normal file
File diff suppressed because it is too large
Load diff
173
buddy/src/fdd.h
Normal file
173
buddy/src/fdd.h
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
/*========================================================================
|
||||
Copyright (C) 1996-2002 by Jorn Lind-Nielsen
|
||||
All rights reserved
|
||||
|
||||
Permission is hereby granted, without written agreement and without
|
||||
license or royalty fees, to use, reproduce, prepare derivative
|
||||
works, distribute, and display this software and its documentation
|
||||
for any purpose, provided that (1) the above copyright notice and
|
||||
the following two paragraphs appear in all copies of the source code
|
||||
and (2) redistributions, including without limitation binaries,
|
||||
reproduce these notices in the supporting documentation. Substantial
|
||||
modifications to this software may be copyrighted by their authors
|
||||
and need not follow the licensing terms described here, provided
|
||||
that the new terms are clearly indicated in all files where they apply.
|
||||
|
||||
IN NO EVENT SHALL JORN LIND-NIELSEN, OR DISTRIBUTORS OF THIS
|
||||
SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
|
||||
SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE
|
||||
ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
JORN LIND-NIELSEN SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
|
||||
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
||||
MODIFICATIONS.
|
||||
========================================================================*/
|
||||
|
||||
/*************************************************************************
|
||||
$Header: /Volumes/CVS/repository/spot/spot/buddy/src/fdd.h,v 1.1 2003/05/05 10:57:56 aduret Exp $
|
||||
FILE: fdd.h
|
||||
DESCR: Finite domain data with BDDs
|
||||
AUTH: Jorn Lind
|
||||
DATE: (C) february 1999
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef _FDD_H
|
||||
#define _FDD_H
|
||||
|
||||
#include "bdd.h"
|
||||
|
||||
|
||||
#ifdef CPLUSPLUS
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* In file fdd.c */
|
||||
|
||||
extern int fdd_extdomain(int*, int);
|
||||
extern int fdd_overlapdomain(int, int);
|
||||
extern void fdd_clearall(void);
|
||||
extern int fdd_domainnum(void);
|
||||
extern int fdd_domainsize(int);
|
||||
extern int fdd_varnum(int);
|
||||
extern int* fdd_vars(int);
|
||||
extern BDD fdd_ithvar(int, int);
|
||||
extern int fdd_scanvar(BDD, int);
|
||||
extern int* fdd_scanallvar(BDD);
|
||||
extern BDD fdd_ithset(int);
|
||||
extern BDD fdd_domain(int);
|
||||
extern BDD fdd_equals(int, int);
|
||||
extern bddfilehandler fdd_file_hook(bddfilehandler);
|
||||
#ifdef CPLUSPLUS
|
||||
extern bddstrmhandler fdd_strm_hook(bddstrmhandler);
|
||||
#endif
|
||||
extern void fdd_printset(BDD);
|
||||
extern void fdd_fprintset(FILE*, BDD);
|
||||
extern int fdd_scanset(BDD, int**, int*);
|
||||
extern BDD fdd_makeset(int*, int);
|
||||
extern int fdd_intaddvarblock(int, int, int);
|
||||
extern int fdd_setpair(bddPair*, int, int);
|
||||
extern int fdd_setpairs(bddPair*, int*, int*, int);
|
||||
|
||||
#ifdef CPLUSPLUS
|
||||
}
|
||||
#endif
|
||||
|
||||
/*************************************************************************
|
||||
If this file is included from a C++ compiler then the following
|
||||
classes, wrappers and hacks are supplied.
|
||||
*************************************************************************/
|
||||
#ifdef CPLUSPLUS
|
||||
|
||||
/* FDD extensions */
|
||||
|
||||
inline bdd fdd_ithvarpp(int var, int val)
|
||||
{ return fdd_ithvar(var, val); }
|
||||
|
||||
inline bdd fdd_ithsetpp(int var)
|
||||
{ return fdd_ithset(var); }
|
||||
|
||||
inline bdd fdd_domainpp(int var)
|
||||
{ return fdd_domain(var); }
|
||||
|
||||
inline int fdd_scanvar(const bdd &r, int var)
|
||||
{ return fdd_scanvar(r.root, var); }
|
||||
|
||||
inline int* fdd_scanallvar(const bdd &r)
|
||||
{ return fdd_scanallvar(r.root); }
|
||||
|
||||
inline bdd fdd_equalspp(int left, int right)
|
||||
{ return fdd_equals(left, right); }
|
||||
|
||||
inline void fdd_printset(const bdd &r)
|
||||
{ fdd_printset(r.root); }
|
||||
|
||||
inline void fdd_fprintset(FILE* ofile, const bdd &r)
|
||||
{ fdd_fprintset(ofile, r.root); }
|
||||
|
||||
inline int fdd_scanset(const bdd &r, int *&v, int &n)
|
||||
{ return fdd_scanset(r.root, &v, &n); }
|
||||
|
||||
inline bdd fdd_makesetpp(int *v, int n)
|
||||
{ return fdd_makeset(v,n); }
|
||||
|
||||
#if 0
|
||||
inline bdd* fdd_conpp(int bitnum, int var)
|
||||
{ return fdd_transfer( bitnum, fdd_con(bitnum, var) ); }
|
||||
|
||||
inline bdd* fdd_varpp(int bitnum, int var)
|
||||
{ return fdd_transfer( bitnum, fdd_var(bitnum, var) ); }
|
||||
|
||||
extern int fdd_isconst(int bitnum, bdd *e);
|
||||
extern int fdd_val(int bitnum, bdd *e);
|
||||
|
||||
inline bdd* fdd_add(int bitnum, bdd *left, bdd *right)
|
||||
{ return fdd_termopr(bitnum, left, right,bdd::fddAdd); }
|
||||
|
||||
inline bdd* fdd_sub(int bitnum, bdd *left, bdd *right)
|
||||
{ return fdd_termopr(bitnum, left, right,bdd::fddSub); }
|
||||
|
||||
inline bdd* fdd_shl(int bitnum, bdd *expr, bdd c)
|
||||
{ return fdd_shift(bitnum, expr, c, bdd::fddShl); }
|
||||
|
||||
inline bdd* fdd_shr(int bitnum, bdd *expr, bdd c)
|
||||
{ return fdd_shift(bitnum, expr, c, bdd::fddShr); }
|
||||
|
||||
inline bdd fdd_lth(int bitnum, bdd *left, bdd *right)
|
||||
{ return fdd_relopr(bitnum, left, right, bdd::fddLth); }
|
||||
|
||||
inline bdd fdd_lte(int bitnum, bdd *left, bdd *right)
|
||||
{ return fdd_relopr(bitnum, left, right, bdd::fddLte); }
|
||||
|
||||
inline bdd fdd_gth(int bitnum, bdd *left, bdd *right)
|
||||
{ return fdd_relopr(bitnum, left, right, bdd::fddGth); }
|
||||
|
||||
inline bdd fdd_gte(int bitnum, bdd *left, bdd *right)
|
||||
{ return fdd_relopr(bitnum, left, right, bdd::fddGte); }
|
||||
|
||||
inline bdd fdd_equ(int bitnum, bdd *left, bdd *right)
|
||||
{ return fdd_relopr(bitnum, left, right, bdd::fddEqu); }
|
||||
|
||||
inline bdd fdd_neq(int bitnum, bdd *left, bdd *right)
|
||||
{ return fdd_relopr(bitnum, left, right, bdd::fddNeq); }
|
||||
#endif
|
||||
|
||||
/* Hacks to allow for overloading of return-types only */
|
||||
#define fdd_ithvar fdd_ithvarpp
|
||||
#define fdd_ithset fdd_ithsetpp
|
||||
#define fdd_domain fdd_domainpp
|
||||
#define fdd_equals fdd_equalspp
|
||||
#define fdd_makeset fdd_makesetpp
|
||||
#define fdd_con fdd_conpp
|
||||
#define fdd_var fdd_varpp
|
||||
|
||||
|
||||
#endif /* CPLUSPLUS */
|
||||
|
||||
#endif /* _FDD_H */
|
||||
|
||||
|
||||
/* EOF */
|
||||
149
buddy/src/imatrix.c
Normal file
149
buddy/src/imatrix.c
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
/*========================================================================
|
||||
Copyright (C) 1996-2002 by Jorn Lind-Nielsen
|
||||
All rights reserved
|
||||
|
||||
Permission is hereby granted, without written agreement and without
|
||||
license or royalty fees, to use, reproduce, prepare derivative
|
||||
works, distribute, and display this software and its documentation
|
||||
for any purpose, provided that (1) the above copyright notice and
|
||||
the following two paragraphs appear in all copies of the source code
|
||||
and (2) redistributions, including without limitation binaries,
|
||||
reproduce these notices in the supporting documentation. Substantial
|
||||
modifications to this software may be copyrighted by their authors
|
||||
and need not follow the licensing terms described here, provided
|
||||
that the new terms are clearly indicated in all files where they apply.
|
||||
|
||||
IN NO EVENT SHALL JORN LIND-NIELSEN, OR DISTRIBUTORS OF THIS
|
||||
SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
|
||||
SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE
|
||||
ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
JORN LIND-NIELSEN SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
|
||||
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
||||
MODIFICATIONS.
|
||||
========================================================================*/
|
||||
|
||||
/*************************************************************************
|
||||
FILE: imatrix.cc
|
||||
DESCR: Interaction matrix
|
||||
AUTH: Jorn Lind
|
||||
DATE: (C) february 2000
|
||||
*************************************************************************/
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "kernel.h"
|
||||
#include "imatrix.h"
|
||||
|
||||
/*************************************************************************
|
||||
*************************************************************************/
|
||||
|
||||
imatrix* imatrixNew(int size)
|
||||
{
|
||||
imatrix *mtx = NEW(imatrix,1);
|
||||
int n,m;
|
||||
|
||||
if (!mtx)
|
||||
return NULL;
|
||||
|
||||
if ((mtx->rows=NEW(char*,size)) == NULL)
|
||||
{
|
||||
free(mtx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (n=0 ; n<size ; n++)
|
||||
{
|
||||
if ((mtx->rows[n]=NEW(char,size/8+1)) == NULL)
|
||||
{
|
||||
for (m=0 ; m<n ; m++)
|
||||
free(mtx->rows[m]);
|
||||
free(mtx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(mtx->rows[n], 0, size/8+1);
|
||||
}
|
||||
|
||||
mtx->size = size;
|
||||
|
||||
return mtx;
|
||||
}
|
||||
|
||||
|
||||
void imatrixDelete(imatrix *mtx)
|
||||
{
|
||||
int n;
|
||||
|
||||
for (n=0 ; n<mtx->size ; n++)
|
||||
free(mtx->rows[n]);
|
||||
free(mtx->rows);
|
||||
free(mtx);
|
||||
}
|
||||
|
||||
|
||||
/*======================================================================*/
|
||||
|
||||
void imatrixFPrint(imatrix *mtx, FILE *ofile)
|
||||
{
|
||||
int x,y;
|
||||
|
||||
fprintf(ofile, " ");
|
||||
for (x=0 ; x<mtx->size ; x++)
|
||||
fprintf(ofile, "%c", x < 26 ? (x+'a') : (x-26)+'A');
|
||||
fprintf(ofile, "\n");
|
||||
|
||||
for (y=0 ; y<mtx->size ; y++)
|
||||
{
|
||||
fprintf(ofile, "%2d %c", y, y < 26 ? (y+'a') : (y-26)+'A');
|
||||
for (x=0 ; x<mtx->size ; x++)
|
||||
fprintf(ofile, "%c", imatrixDepends(mtx,y,x) ? 'x' : ' ');
|
||||
fprintf(ofile, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void imatrixPrint(imatrix *mtx)
|
||||
{
|
||||
imatrixFPrint(mtx, stdout);
|
||||
}
|
||||
|
||||
|
||||
void imatrixSet(imatrix *mtx, int a, int b)
|
||||
{
|
||||
mtx->rows[a][b/8] |= 1<<(b%8);
|
||||
}
|
||||
|
||||
|
||||
void imatrixClr(imatrix *mtx, int a, int b)
|
||||
{
|
||||
mtx->rows[a][b/8] &= ~(1<<(b%8));
|
||||
}
|
||||
|
||||
|
||||
int imatrixDepends(imatrix *mtx, int a, int b)
|
||||
{
|
||||
return mtx->rows[a][b/8] & (1<<(b%8));
|
||||
}
|
||||
|
||||
|
||||
/*======================================================================*/
|
||||
|
||||
#if 0
|
||||
void main(void)
|
||||
{
|
||||
imatrix *m = imatrixNew(16);
|
||||
|
||||
imatrixSet(m,0,2);
|
||||
imatrixSet(m,8,8);
|
||||
imatrixSet(m,15,15);
|
||||
|
||||
imatrixPrint(m);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* EOF */
|
||||
59
buddy/src/imatrix.h
Normal file
59
buddy/src/imatrix.h
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/*========================================================================
|
||||
Copyright (C) 1996-2002 by Jorn Lind-Nielsen
|
||||
All rights reserved
|
||||
|
||||
Permission is hereby granted, without written agreement and without
|
||||
license or royalty fees, to use, reproduce, prepare derivative
|
||||
works, distribute, and display this software and its documentation
|
||||
for any purpose, provided that (1) the above copyright notice and
|
||||
the following two paragraphs appear in all copies of the source code
|
||||
and (2) redistributions, including without limitation binaries,
|
||||
reproduce these notices in the supporting documentation. Substantial
|
||||
modifications to this software may be copyrighted by their authors
|
||||
and need not follow the licensing terms described here, provided
|
||||
that the new terms are clearly indicated in all files where they apply.
|
||||
|
||||
IN NO EVENT SHALL JORN LIND-NIELSEN, OR DISTRIBUTORS OF THIS
|
||||
SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
|
||||
SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE
|
||||
ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
JORN LIND-NIELSEN SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
|
||||
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
||||
MODIFICATIONS.
|
||||
========================================================================*/
|
||||
|
||||
/*************************************************************************
|
||||
FILE: imatrix.h
|
||||
DESCR: Interaction matrix
|
||||
AUTH: Jorn Lind
|
||||
DATE: (C) february 2000
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef _IMATRIX_H
|
||||
#define _IMATRIX_H
|
||||
|
||||
typedef struct _imatrix
|
||||
{
|
||||
char **rows;
|
||||
int size;
|
||||
} imatrix;
|
||||
|
||||
|
||||
extern imatrix* imatrixNew(int);
|
||||
extern void imatrixDelete(imatrix*);
|
||||
extern void imatrixFPrint(imatrix*,FILE *);
|
||||
extern void imatrixPrint(imatrix*);
|
||||
extern void imatrixSet(imatrix*,int,int);
|
||||
extern void imatrixClr(imatrix*,int,int);
|
||||
extern int imatrixDepends(imatrix*,int,int);
|
||||
|
||||
|
||||
#endif /* _IMATRIX_H */
|
||||
|
||||
|
||||
/* EOF */
|
||||
1492
buddy/src/kernel.c
Normal file
1492
buddy/src/kernel.c
Normal file
File diff suppressed because it is too large
Load diff
227
buddy/src/kernel.h
Normal file
227
buddy/src/kernel.h
Normal file
|
|
@ -0,0 +1,227 @@
|
|||
/*========================================================================
|
||||
Copyright (C) 1996-2002 by Jorn Lind-Nielsen
|
||||
All rights reserved
|
||||
|
||||
Permission is hereby granted, without written agreement and without
|
||||
license or royalty fees, to use, reproduce, prepare derivative
|
||||
works, distribute, and display this software and its documentation
|
||||
for any purpose, provided that (1) the above copyright notice and
|
||||
the following two paragraphs appear in all copies of the source code
|
||||
and (2) redistributions, including without limitation binaries,
|
||||
reproduce these notices in the supporting documentation. Substantial
|
||||
modifications to this software may be copyrighted by their authors
|
||||
and need not follow the licensing terms described here, provided
|
||||
that the new terms are clearly indicated in all files where they apply.
|
||||
|
||||
IN NO EVENT SHALL JORN LIND-NIELSEN, OR DISTRIBUTORS OF THIS
|
||||
SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
|
||||
SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE
|
||||
ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
JORN LIND-NIELSEN SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
|
||||
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
||||
MODIFICATIONS.
|
||||
========================================================================*/
|
||||
|
||||
/*************************************************************************
|
||||
$Header: /Volumes/CVS/repository/spot/spot/buddy/src/kernel.h,v 1.1 2003/05/05 10:57:57 aduret Exp $
|
||||
FILE: kernel.h
|
||||
DESCR: Kernel specific definitions for BDD package
|
||||
AUTH: Jorn Lind
|
||||
DATE: (C) june 1997
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef _KERNEL_H
|
||||
#define _KERNEL_H
|
||||
|
||||
/*=== Includes =========================================================*/
|
||||
|
||||
#include <limits.h>
|
||||
#include <setjmp.h>
|
||||
#include "bdd.h"
|
||||
|
||||
/*=== SANITY CHECKS ====================================================*/
|
||||
|
||||
/* Make sure we use at least 32 bit integers */
|
||||
#if (INT_MAX < 0x7FFFFFFF)
|
||||
#error The compiler does not support 4 byte integers!
|
||||
#endif
|
||||
|
||||
|
||||
/* Sanity check argument and return eventual error code */
|
||||
#define CHECK(r)\
|
||||
if (!bddrunning) return bdd_error(BDD_RUNNING);\
|
||||
else if ((r) < 0 || (r) >= bddnodesize) return bdd_error(BDD_ILLBDD);\
|
||||
else if (r >= 2 && LOW(r) == -1) return bdd_error(BDD_ILLBDD)\
|
||||
|
||||
/* Sanity check argument and return eventually the argument 'a' */
|
||||
#define CHECKa(r,a)\
|
||||
if (!bddrunning) { bdd_error(BDD_RUNNING); return (a); }\
|
||||
else if ((r) < 0 || (r) >= bddnodesize)\
|
||||
{ bdd_error(BDD_ILLBDD); return (a); }\
|
||||
else if (r >= 2 && LOW(r) == -1)\
|
||||
{ bdd_error(BDD_ILLBDD); return (a); }
|
||||
|
||||
#define CHECKn(r)\
|
||||
if (!bddrunning) { bdd_error(BDD_RUNNING); return; }\
|
||||
else if ((r) < 0 || (r) >= bddnodesize)\
|
||||
{ bdd_error(BDD_ILLBDD); return; }\
|
||||
else if (r >= 2 && LOW(r) == -1)\
|
||||
{ bdd_error(BDD_ILLBDD); return; }
|
||||
|
||||
|
||||
/*=== SEMI-INTERNAL TYPES ==============================================*/
|
||||
|
||||
typedef struct s_BddNode /* Node table entry */
|
||||
{
|
||||
unsigned int refcou : 10;
|
||||
unsigned int level : 22;
|
||||
int low;
|
||||
int high;
|
||||
int hash;
|
||||
int next;
|
||||
} BddNode;
|
||||
|
||||
|
||||
/*=== KERNEL VARIABLES =================================================*/
|
||||
|
||||
#ifdef CPLUSPLUS
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int bddrunning; /* Flag - package initialized */
|
||||
extern int bdderrorcond; /* Some error condition was met */
|
||||
extern int bddnodesize; /* Number of allocated nodes */
|
||||
extern int bddmaxnodesize; /* Maximum allowed number of nodes */
|
||||
extern int bddmaxnodeincrease; /* Max. # of nodes used to inc. table */
|
||||
extern BddNode* bddnodes; /* All of the bdd nodes */
|
||||
extern int bddvarnum; /* Number of defined BDD variables */
|
||||
extern int* bddrefstack; /* Internal node reference stack */
|
||||
extern int* bddrefstacktop; /* Internal node reference stack top */
|
||||
extern int* bddvar2level;
|
||||
extern int* bddlevel2var;
|
||||
extern jmp_buf bddexception;
|
||||
extern int bddreorderdisabled;
|
||||
extern int bddresized;
|
||||
extern bddCacheStat bddcachestats;
|
||||
|
||||
#ifdef CPLUSPLUS
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*=== KERNEL DEFINITIONS ===============================================*/
|
||||
|
||||
#define VERSION 22
|
||||
|
||||
#define MAXVAR 0x1FFFFF
|
||||
#define MAXREF 0x3FF
|
||||
|
||||
/* Reference counting */
|
||||
#define DECREF(n) if (bddnodes[n].refcou!=MAXREF && bddnodes[n].refcou>0) bddnodes[n].refcou--
|
||||
#define INCREF(n) if (bddnodes[n].refcou<MAXREF) bddnodes[n].refcou++
|
||||
#define DECREFp(n) if (n->refcou!=MAXREF && n->refcou>0) n->refcou--
|
||||
#define INCREFp(n) if (n->refcou<MAXREF) n->refcou++
|
||||
#define HASREF(n) (bddnodes[n].refcou > 0)
|
||||
|
||||
/* Marking BDD nodes */
|
||||
#define MARKON 0x200000 /* Bit used to mark a node (1) */
|
||||
#define MARKOFF 0x1FFFFF /* - unmark */
|
||||
#define MARKHIDE 0x1FFFFF
|
||||
#define SETMARK(n) (bddnodes[n].level |= MARKON)
|
||||
#define UNMARK(n) (bddnodes[n].level &= MARKOFF)
|
||||
#define MARKED(n) (bddnodes[n].level & MARKON)
|
||||
#define SETMARKp(p) (node->level |= MARKON)
|
||||
#define UNMARKp(p) (node->level &= MARKOFF)
|
||||
#define MARKEDp(p) (node->level & MARKON)
|
||||
|
||||
/* Hashfunctions */
|
||||
|
||||
#define PAIR(a,b) ((unsigned int)((((unsigned int)a)+((unsigned int)b))*(((unsigned int)a)+((unsigned int)b)+((unsigned int)1))/((unsigned int)2)+((unsigned int)a)))
|
||||
#define TRIPLE(a,b,c) ((unsigned int)(PAIR((unsigned int)c,PAIR(a,b))))
|
||||
|
||||
|
||||
/* Inspection of BDD nodes */
|
||||
#define ISCONST(a) ((a) < 2)
|
||||
#define ISNONCONST(a) ((a) >= 2)
|
||||
#define ISONE(a) ((a) == 1)
|
||||
#define ISZERO(a) ((a) == 0)
|
||||
#define LEVEL(a) (bddnodes[a].level)
|
||||
#define LOW(a) (bddnodes[a].low)
|
||||
#define HIGH(a) (bddnodes[a].high)
|
||||
#define LEVELp(p) ((p)->level)
|
||||
#define LOWp(p) ((p)->low)
|
||||
#define HIGHp(p) ((p)->high)
|
||||
|
||||
/* Stacking for garbage collector */
|
||||
#define INITREF bddrefstacktop = bddrefstack
|
||||
#define PUSHREF(a) *(bddrefstacktop++) = (a)
|
||||
#define READREF(a) *(bddrefstacktop-(a))
|
||||
#define POPREF(a) bddrefstacktop -= (a)
|
||||
|
||||
#define BDDONE 1
|
||||
#define BDDZERO 0
|
||||
|
||||
#ifndef CLOCKS_PER_SEC
|
||||
#define CLOCKS_PER_SEC DEFAULT_CLOCK
|
||||
#endif
|
||||
|
||||
#define DEFAULTMAXNODEINC 50000
|
||||
|
||||
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
||||
#define NEW(t,n) ( (t*)malloc(sizeof(t)*(n)) )
|
||||
|
||||
|
||||
/*=== KERNEL PROTOTYPES ================================================*/
|
||||
|
||||
#ifdef CPLUSPLUS
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int bdd_error(int);
|
||||
extern int bdd_makenode(unsigned int, int, int);
|
||||
extern int bdd_noderesize(int);
|
||||
extern void bdd_checkreorder(void);
|
||||
extern void bdd_mark(int);
|
||||
extern void bdd_mark_upto(int, int);
|
||||
extern void bdd_markcount(int, int*);
|
||||
extern void bdd_unmark(int);
|
||||
extern void bdd_unmark_upto(int, int);
|
||||
extern void bdd_register_pair(bddPair*);
|
||||
extern int *fdddec2bin(int, int);
|
||||
|
||||
extern int bdd_operator_init(int);
|
||||
extern void bdd_operator_done(void);
|
||||
extern void bdd_operator_varresize(void);
|
||||
extern void bdd_operator_reset(void);
|
||||
|
||||
extern void bdd_pairs_init(void);
|
||||
extern void bdd_pairs_done(void);
|
||||
extern int bdd_pairs_resize(int,int);
|
||||
extern void bdd_pairs_vardown(int);
|
||||
|
||||
extern void bdd_fdd_init(void);
|
||||
extern void bdd_fdd_done(void);
|
||||
|
||||
extern void bdd_reorder_init(void);
|
||||
extern void bdd_reorder_done(void);
|
||||
extern int bdd_reorder_ready(void);
|
||||
extern void bdd_reorder_auto(void);
|
||||
extern int bdd_reorder_vardown(int);
|
||||
extern int bdd_reorder_varup(int);
|
||||
|
||||
extern void bdd_cpp_init(void);
|
||||
|
||||
#ifdef CPLUSPLUS
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _KERNEL_H */
|
||||
|
||||
|
||||
/* EOF */
|
||||
49
buddy/src/makefile
Normal file
49
buddy/src/makefile
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# ==============================================================
|
||||
# Makefile for BDD source
|
||||
# - Do not touch
|
||||
# ==============================================================
|
||||
|
||||
# --- full object list
|
||||
OBJ = bddio.o bddop.o bvec.o cache.o cppext.o fdd.o imatrix.o kernel.o \
|
||||
pairs.o prime.o reorder.o tree.o
|
||||
CFILES = bddio.c bddop.c bvec.c cache.c fdd.c imatrix.c kernel.c \
|
||||
pairs.c prime.c reorder.c tree.c
|
||||
CCFILES = cppext.cxx
|
||||
|
||||
include ../config
|
||||
|
||||
# --------------------------------------------------------------
|
||||
# Code generation
|
||||
# --------------------------------------------------------------
|
||||
|
||||
.SUFFIXES: .cxx .c
|
||||
|
||||
.cxx.o:
|
||||
$(CPP) $(CFLAGS) $(DFLAGS) -c $<
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) $(DFLAGS) -c $<
|
||||
|
||||
|
||||
# --------------------------------------------------------------
|
||||
# The primary targets.
|
||||
# --------------------------------------------------------------
|
||||
|
||||
libbdd.a: $(OBJ) ../config
|
||||
ar r libbdd.a $(OBJ)
|
||||
ranlib libbdd.a
|
||||
|
||||
clean:
|
||||
rm -f lib$(TARGET).a
|
||||
rm -f *.o core *~
|
||||
rm -f libbdd.a
|
||||
rm -f bddtest
|
||||
|
||||
depend:
|
||||
gcc -MM $(CFLAGS) $(DFLAGS) $(CFILES) > depend.inf
|
||||
g++ -MM $(CFLAGS) $(DFLAGS) $(CCFILES) >> depend.inf
|
||||
|
||||
bddtest: libbdd.a bddtest.cxx ../config
|
||||
$(CPP) $(CFLAGS) $(DFLAGS) bddtest.cxx -o bddtest -L. -lbdd
|
||||
###
|
||||
include depend.inf
|
||||
335
buddy/src/pairs.c
Normal file
335
buddy/src/pairs.c
Normal file
|
|
@ -0,0 +1,335 @@
|
|||
/*========================================================================
|
||||
Copyright (C) 1996-2002 by Jorn Lind-Nielsen
|
||||
All rights reserved
|
||||
|
||||
Permission is hereby granted, without written agreement and without
|
||||
license or royalty fees, to use, reproduce, prepare derivative
|
||||
works, distribute, and display this software and its documentation
|
||||
for any purpose, provided that (1) the above copyright notice and
|
||||
the following two paragraphs appear in all copies of the source code
|
||||
and (2) redistributions, including without limitation binaries,
|
||||
reproduce these notices in the supporting documentation. Substantial
|
||||
modifications to this software may be copyrighted by their authors
|
||||
and need not follow the licensing terms described here, provided
|
||||
that the new terms are clearly indicated in all files where they apply.
|
||||
|
||||
IN NO EVENT SHALL JORN LIND-NIELSEN, OR DISTRIBUTORS OF THIS
|
||||
SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
|
||||
SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE
|
||||
ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
JORN LIND-NIELSEN SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
|
||||
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
||||
MODIFICATIONS.
|
||||
========================================================================*/
|
||||
|
||||
/*************************************************************************
|
||||
$Header: /Volumes/CVS/repository/spot/spot/buddy/src/pairs.c,v 1.1 2003/05/05 10:57:57 aduret Exp $
|
||||
FILE: pairs.c
|
||||
DESCR: Pair management for BDD package.
|
||||
AUTH: Jorn Lind
|
||||
DATE: february 1997
|
||||
*************************************************************************/
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include "kernel.h"
|
||||
|
||||
/*======================================================================*/
|
||||
|
||||
static int pairsid; /* Pair identifier */
|
||||
static bddPair* pairs; /* List of all replacement pairs in use */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
*************************************************************************/
|
||||
|
||||
void bdd_pairs_init(void)
|
||||
{
|
||||
pairsid = 0;
|
||||
pairs = NULL;
|
||||
}
|
||||
|
||||
|
||||
void bdd_pairs_done(void)
|
||||
{
|
||||
bddPair *p = pairs;
|
||||
int n;
|
||||
|
||||
while (p != NULL)
|
||||
{
|
||||
bddPair *next = p->next;
|
||||
for (n=0 ; n<bddvarnum ; n++)
|
||||
bdd_delref( p->result[n] );
|
||||
free(p->result);
|
||||
free(p);
|
||||
p = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int update_pairsid(void)
|
||||
{
|
||||
pairsid++;
|
||||
|
||||
if (pairsid == (INT_MAX >> 2))
|
||||
{
|
||||
bddPair *p;
|
||||
pairsid = 0;
|
||||
for (p=pairs ; p!=NULL ; p=p->next)
|
||||
p->id = pairsid++;
|
||||
bdd_operator_reset();
|
||||
}
|
||||
|
||||
return pairsid;
|
||||
}
|
||||
|
||||
|
||||
void bdd_register_pair(bddPair *p)
|
||||
{
|
||||
p->next = pairs;
|
||||
pairs = p;
|
||||
}
|
||||
|
||||
|
||||
void bdd_pairs_vardown(int level)
|
||||
{
|
||||
bddPair *p;
|
||||
|
||||
for (p=pairs ; p!=NULL ; p=p->next)
|
||||
{
|
||||
int tmp;
|
||||
|
||||
tmp = p->result[level];
|
||||
p->result[level] = p->result[level+1];
|
||||
p->result[level+1] = tmp;
|
||||
|
||||
if (p->last == level)
|
||||
p->last++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int bdd_pairs_resize(int oldsize, int newsize)
|
||||
{
|
||||
bddPair *p;
|
||||
int n;
|
||||
|
||||
for (p=pairs ; p!=NULL ; p=p->next)
|
||||
{
|
||||
if ((p->result=(BDD*)realloc(p->result,sizeof(BDD)*newsize)) == NULL)
|
||||
return bdd_error(BDD_MEMORY);
|
||||
|
||||
for (n=oldsize ; n<newsize ; n++)
|
||||
p->result[n] = bdd_ithvar(bddlevel2var[n]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
NAME {* bdd\_newpair *}
|
||||
SECTION {* kernel *}
|
||||
SHORT {* creates an empty variable pair table *}
|
||||
PROTO {* bddPair *bdd_newpair(void) *}
|
||||
DESCR {* Variable pairs of the type {\tt bddPair} are used in
|
||||
{\tt bdd\_replace} to define which variables to replace with
|
||||
other variables. This function allocates such an empty table. The
|
||||
table can be freed by a call to {\em bdd\_freepair}. *}
|
||||
RETURN {* Returns a new table of pairs. *}
|
||||
ALSO {* bdd\_freepair, bdd\_replace, bdd\_setpair, bdd\_setpairs *}
|
||||
*/
|
||||
bddPair *bdd_newpair(void)
|
||||
{
|
||||
int n;
|
||||
bddPair *p;
|
||||
|
||||
if ((p=(bddPair*)malloc(sizeof(bddPair))) == NULL)
|
||||
{
|
||||
bdd_error(BDD_MEMORY);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((p->result=(BDD*)malloc(sizeof(BDD)*bddvarnum)) == NULL)
|
||||
{
|
||||
free(p);
|
||||
bdd_error(BDD_MEMORY);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (n=0 ; n<bddvarnum ; n++)
|
||||
p->result[n] = bdd_ithvar(bddlevel2var[n]);
|
||||
|
||||
p->id = update_pairsid();
|
||||
p->last = -1;
|
||||
|
||||
bdd_register_pair(p);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
NAME {* bdd\_setpair *}
|
||||
EXTRA {* bdd\_setbddpair *}
|
||||
SECTION {* kernel *}
|
||||
SHORT {* set one variable pair *}
|
||||
PROTO {* int bdd_setpair(bddPair *pair, int oldvar, int newvar)
|
||||
int bdd_setbddpair(bddPair *pair, BDD oldvar, BDD newvar) *}
|
||||
DESCR {* Adds the pair {\tt (oldvar,newvar)} to the table of pairs
|
||||
{\tt pair}. This results in {\tt oldvar} being substituted
|
||||
with {\tt newvar} in a call to {\tt bdd\_replace}. In the first
|
||||
version {\tt newvar} is an integer representing the variable
|
||||
to be replaced with the old variable.
|
||||
In the second version {\tt oldvar} is a BDD.
|
||||
In this case the variable {\tt oldvar} is substituted with the
|
||||
BDD {\tt newvar}.
|
||||
The possibility to substitute with any BDD as {\tt newvar} is
|
||||
utilized in bdd\_compose, whereas only the topmost variable
|
||||
in the BDD is used in bdd\_replace. *}
|
||||
RETURN {* Zero on success, otherwise a negative error code. *}
|
||||
ALSO {* bdd\_newpair, bdd\_setpairs, bdd\_resetpair, bdd\_replace, bdd\_compose *}
|
||||
*/
|
||||
int bdd_setpair(bddPair *pair, int oldvar, int newvar)
|
||||
{
|
||||
if (pair == NULL)
|
||||
return 0;
|
||||
|
||||
if (oldvar < 0 || oldvar > bddvarnum-1)
|
||||
return bdd_error(BDD_VAR);
|
||||
if (newvar < 0 || newvar > bddvarnum-1)
|
||||
return bdd_error(BDD_VAR);
|
||||
|
||||
bdd_delref( pair->result[bddvar2level[oldvar]] );
|
||||
pair->result[bddvar2level[oldvar]] = bdd_ithvar(newvar);
|
||||
pair->id = update_pairsid();
|
||||
|
||||
if (bddvar2level[oldvar] > pair->last)
|
||||
pair->last = bddvar2level[oldvar];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int bdd_setbddpair(bddPair *pair, int oldvar, BDD newvar)
|
||||
{
|
||||
int oldlevel;
|
||||
|
||||
if (pair == NULL)
|
||||
return 0;
|
||||
|
||||
CHECK(newvar);
|
||||
if (oldvar < 0 || oldvar >= bddvarnum)
|
||||
return bdd_error(BDD_VAR);
|
||||
oldlevel = bddvar2level[oldvar];
|
||||
|
||||
bdd_delref( pair->result[oldlevel] );
|
||||
pair->result[oldlevel] = bdd_addref(newvar);
|
||||
pair->id = update_pairsid();
|
||||
|
||||
if (oldlevel > pair->last)
|
||||
pair->last = oldlevel;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
NAME {* bdd\_setpairs *}
|
||||
EXTRA {* bdd\_setbddpairs *}
|
||||
SECTION {* kernel *}
|
||||
SHORT {* defines a whole set of pairs *}
|
||||
PROTO {* int bdd_setpairs(bddPair *pair, int *oldvar, int *newvar, int size)
|
||||
int bdd_setbddpairs(bddPair *pair, int *oldvar, BDD *newvar, int size) *}
|
||||
DESCR {* As for {\tt bdd\_setpair} but with {\tt oldvar} and {\tt newvar}
|
||||
being arrays of variables (BDDs) of size {\tt size}. *}
|
||||
RETURN {* Zero on success, otherwise a negative error code. *}
|
||||
ALSO {* bdd\_newpair, bdd\_setpair, bdd\_replace, bdd\_compose *}
|
||||
*/
|
||||
int bdd_setpairs(bddPair *pair, int *oldvar, int *newvar, int size)
|
||||
{
|
||||
int n,e;
|
||||
if (pair == NULL)
|
||||
return 0;
|
||||
|
||||
for (n=0 ; n<size ; n++)
|
||||
if ((e=bdd_setpair(pair, oldvar[n], newvar[n])) < 0)
|
||||
return e;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int bdd_setbddpairs(bddPair *pair, int *oldvar, BDD *newvar, int size)
|
||||
{
|
||||
int n,e;
|
||||
if (pair == NULL)
|
||||
return 0;
|
||||
|
||||
for (n=0 ; n<size ; n++)
|
||||
if ((e=bdd_setbddpair(pair, oldvar[n], newvar[n])) < 0)
|
||||
return e;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
NAME {* bdd\_freepair *}
|
||||
SECTION {* kernel *}
|
||||
SHORT {* frees a table of pairs *}
|
||||
PROTO {* void bdd_freepair(bddPair *pair) *}
|
||||
DESCR {* Frees the table of pairs {\tt pair} that has been allocated
|
||||
by a call to {\tt bdd\_newpair}. *}
|
||||
ALSO {* bdd\_replace, bdd\_newpair, bdd\_setpair, bdd\_resetpair *}
|
||||
*/
|
||||
void bdd_freepair(bddPair *p)
|
||||
{
|
||||
int n;
|
||||
|
||||
if (p == NULL)
|
||||
return;
|
||||
|
||||
if (pairs != p)
|
||||
{
|
||||
bddPair *bp = pairs;
|
||||
while (bp != NULL && bp->next != p)
|
||||
bp = bp->next;
|
||||
|
||||
if (bp != NULL)
|
||||
bp->next = p->next;
|
||||
}
|
||||
else
|
||||
pairs = p->next;
|
||||
|
||||
for (n=0 ; n<bddvarnum ; n++)
|
||||
bdd_delref( p->result[n] );
|
||||
free(p->result);
|
||||
free(p);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
NAME {* bdd\_resetpair *}
|
||||
SECTION {* kernel *}
|
||||
SHORT {* clear all variable pairs *}
|
||||
PROTO {* void bdd_resetpair(bddPair *pair) *}
|
||||
DESCR {* Resets the table of pairs {\tt pair} by setting all substitutions
|
||||
to their default values (that is no change). *}
|
||||
ALSO {* bdd\_newpair, bdd\_setpair, bdd\_freepair *}
|
||||
*/
|
||||
void bdd_resetpair(bddPair *p)
|
||||
{
|
||||
int n;
|
||||
|
||||
for (n=0 ; n<bddvarnum ; n++)
|
||||
p->result[n] = bdd_ithvar(n);
|
||||
p->last = 0;
|
||||
}
|
||||
|
||||
|
||||
/* EOF */
|
||||
|
||||
321
buddy/src/prime.c
Normal file
321
buddy/src/prime.c
Normal file
|
|
@ -0,0 +1,321 @@
|
|||
/*========================================================================
|
||||
Copyright (C) 1996-2002 by Jorn Lind-Nielsen
|
||||
All rights reserved
|
||||
|
||||
Permission is hereby granted, without written agreement and without
|
||||
license or royalty fees, to use, reproduce, prepare derivative
|
||||
works, distribute, and display this software and its documentation
|
||||
for any purpose, provided that (1) the above copyright notice and
|
||||
the following two paragraphs appear in all copies of the source code
|
||||
and (2) redistributions, including without limitation binaries,
|
||||
reproduce these notices in the supporting documentation. Substantial
|
||||
modifications to this software may be copyrighted by their authors
|
||||
and need not follow the licensing terms described here, provided
|
||||
that the new terms are clearly indicated in all files where they apply.
|
||||
|
||||
IN NO EVENT SHALL JORN LIND-NIELSEN, OR DISTRIBUTORS OF THIS
|
||||
SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
|
||||
SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE
|
||||
ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
JORN LIND-NIELSEN SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
|
||||
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
||||
MODIFICATIONS.
|
||||
========================================================================*/
|
||||
|
||||
/*************************************************************************
|
||||
$Header: /Volumes/CVS/repository/spot/spot/buddy/src/prime.c,v 1.1 2003/05/05 10:57:57 aduret Exp $
|
||||
FILE: prime.c
|
||||
DESCR: Prime number calculations
|
||||
AUTH: Jorn Lind
|
||||
DATE: (C) feb 2001
|
||||
*************************************************************************/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "prime.h"
|
||||
|
||||
|
||||
#define Random(i) ( (rand() % (i)) + 1 )
|
||||
#define isEven(src) (!((src) & 0x1))
|
||||
#define hasFactor(src,n) ( (((src)!=(n)) && ((src)%(n) == 0)) )
|
||||
#define BitIsSet(src,b) ( ((src) & (1<<(b))) != 0 )
|
||||
|
||||
#define CHECKTIMES 20
|
||||
|
||||
#if defined(BUDDYUINT64)
|
||||
typedef BUDDYUINT64 UINT64;
|
||||
#define BUILTIN64
|
||||
#elif defined(__GNUC__) || defined(__KCC)
|
||||
typedef long long UINT64;
|
||||
#define BUILTIN64
|
||||
#elif defined(_MSV_VER)
|
||||
typedef unsigned _int64 UINT64;
|
||||
#define BUILTIN64
|
||||
#else
|
||||
typedef struct __UINT64
|
||||
{
|
||||
unsigned int hi;
|
||||
unsigned int lo;
|
||||
} UINT64;
|
||||
|
||||
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
||||
#define GETCARRY(a,b) ( ((a)+(b)) < MAX((a),(b)) ? 1 : 0 )
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef BUILTIN64
|
||||
/*************************************************************************
|
||||
64 bit unsigned int arithmetics
|
||||
*************************************************************************/
|
||||
|
||||
static UINT64 u64_mul(unsigned int x, unsigned int y)
|
||||
{
|
||||
UINT64 res;
|
||||
unsigned int yh = 0;
|
||||
unsigned int yl = y;
|
||||
int i;
|
||||
|
||||
res.lo = res.hi = 0;
|
||||
|
||||
for (i=0 ; i<32 ; ++i)
|
||||
{
|
||||
if (x & 0x1)
|
||||
{
|
||||
unsigned int carry = GETCARRY(res.lo,yl);
|
||||
res.lo += yl;
|
||||
res.hi += yh + carry;
|
||||
}
|
||||
|
||||
yh = (yh << 1) | (yl & 0x80000000 ? 1 : 0);
|
||||
yl = (yl << 1);
|
||||
|
||||
x >>= 1;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static void u64_shl(UINT64* a, unsigned int *carryOut)
|
||||
{
|
||||
*carryOut = (*carryOut << 1) | (a->hi & 0x80000000 ? 0x1 : 0x0);
|
||||
a->hi = (a->hi << 1) | (a->lo & 0x80000000 ? 0x1 : 0x0);
|
||||
a->lo = (a->lo << 1);
|
||||
}
|
||||
|
||||
|
||||
static unsigned int u64_mod(UINT64 dividend, unsigned int divisor)
|
||||
{
|
||||
unsigned int remainder = 0;
|
||||
int i;
|
||||
|
||||
u64_shl(÷nd, &remainder);
|
||||
|
||||
for (i=0 ; i<64 ; ++i)
|
||||
{
|
||||
if (remainder >= divisor)
|
||||
remainder -= divisor;
|
||||
|
||||
u64_shl(÷nd, &remainder);
|
||||
}
|
||||
|
||||
return remainder >> 1;
|
||||
}
|
||||
#endif /* BUILTIN64 */
|
||||
|
||||
#ifdef BUILTIN64
|
||||
#define u64_mulmod(a,b,c) ((unsigned int)( ((UINT64)a*(UINT64)b)%(UINT64)c ));
|
||||
#else
|
||||
#define u64_mulmod(a,b,c) u64_mod( u64_mul((a),(b)), (c) );
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
Miller Rabin check
|
||||
*************************************************************************/
|
||||
|
||||
static unsigned int numberOfBits(unsigned int src)
|
||||
{
|
||||
unsigned int b;
|
||||
|
||||
if (src == 0)
|
||||
return 0;
|
||||
|
||||
for (b=(sizeof(unsigned int)*8)-1 ; b>0 ; --b)
|
||||
if (BitIsSet(src,b))
|
||||
return b+1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int isWitness(unsigned int witness, unsigned int src)
|
||||
{
|
||||
unsigned int bitNum = numberOfBits(src-1)-1;
|
||||
unsigned int d = 1;
|
||||
int i;
|
||||
|
||||
for (i=bitNum ; i>=0 ; --i)
|
||||
{
|
||||
unsigned int x = d;
|
||||
|
||||
d = u64_mulmod(d,d,src);
|
||||
|
||||
if (d == 1 && x != 1 && x != src-1)
|
||||
return 1;
|
||||
|
||||
if (BitIsSet(src-1,i))
|
||||
d = u64_mulmod(d,witness,src);
|
||||
}
|
||||
|
||||
return d != 1;
|
||||
}
|
||||
|
||||
|
||||
static int isMillerRabinPrime(unsigned int src)
|
||||
{
|
||||
int n;
|
||||
|
||||
for (n=0 ; n<CHECKTIMES ; ++n)
|
||||
{
|
||||
unsigned int witness = Random(src-1);
|
||||
|
||||
if (isWitness(witness,src))
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
Basic prime searching stuff
|
||||
*************************************************************************/
|
||||
|
||||
static int hasEasyFactors(unsigned int src)
|
||||
{
|
||||
return hasFactor(src, 3)
|
||||
|| hasFactor(src, 5)
|
||||
|| hasFactor(src, 7)
|
||||
|| hasFactor(src, 11)
|
||||
|| hasFactor(src, 13);
|
||||
}
|
||||
|
||||
|
||||
static int isPrime(unsigned int src)
|
||||
{
|
||||
if (hasEasyFactors(src))
|
||||
return 0;
|
||||
|
||||
return isMillerRabinPrime(src);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
External interface
|
||||
*************************************************************************/
|
||||
|
||||
unsigned int bdd_prime_gte(unsigned int src)
|
||||
{
|
||||
if (isEven(src))
|
||||
++src;
|
||||
|
||||
while (!isPrime(src))
|
||||
src += 2;
|
||||
|
||||
return src;
|
||||
}
|
||||
|
||||
|
||||
unsigned int bdd_prime_lte(unsigned int src)
|
||||
{
|
||||
if (isEven(src))
|
||||
--src;
|
||||
|
||||
while (!isPrime(src))
|
||||
src -= 2;
|
||||
|
||||
return src;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
Testing
|
||||
*************************************************************************/
|
||||
|
||||
#if 0
|
||||
int main()
|
||||
{
|
||||
printf("Nb0 = %u\n", numberOfBits(0));
|
||||
printf("Nb1 = %u\n", numberOfBits(1));
|
||||
printf("Nb2 = %u\n", numberOfBits(2));
|
||||
printf("Nb3 = %u\n", numberOfBits(3));
|
||||
printf("Nb5 = %u\n", numberOfBits(5));
|
||||
printf("Nb9 = %u\n", numberOfBits(9));
|
||||
printf("Nb15 = %u\n", numberOfBits(15));
|
||||
printf("Nb17 = %u\n", numberOfBits(17));
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if 0
|
||||
void testMul(unsigned int a, unsigned int b)
|
||||
{
|
||||
UINT64 x = u64_mul(a,b);
|
||||
long long z1 = (long long)a * (long long)b;
|
||||
long long z2 = ((long long)x.hi << 32) + (long long)x.lo;
|
||||
if (z1 != z2)
|
||||
printf("%d * %d = %lld,%lld\n", a, b, z1, z2);
|
||||
}
|
||||
|
||||
|
||||
void testMod(unsigned int a, unsigned int b, unsigned int c)
|
||||
{
|
||||
UINT64 x = u64_mul(a,b);
|
||||
|
||||
long long z1 = (long long)a * (long long)b;
|
||||
long long z2 = ((long long)x.hi << 32) + (long long)x.lo;
|
||||
unsigned int m1 = z1 % c;
|
||||
unsigned int m2 = u64_mod(x,c);
|
||||
|
||||
if (z1 != z2)
|
||||
printf("%d * %d = %lld,%lld\n", a, b, z1, z2);
|
||||
|
||||
if (m1 != m2)
|
||||
printf("%llu %% %u = %u,%u\n", z1, c, m1, m2);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
for (n=0 ; n<1000 ; ++n)
|
||||
{
|
||||
unsigned int x = Random(10000)+2;
|
||||
int a = bdd_prime_lte(x);
|
||||
int b=_bdd_prime_lte(x);
|
||||
/*printf("%d: %d, %d ", x, );*/
|
||||
if (a != b)
|
||||
printf("ERROR");
|
||||
/*printf("\n");*/
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* EOF */
|
||||
|
||||
48
buddy/src/prime.h
Normal file
48
buddy/src/prime.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*========================================================================
|
||||
Copyright (C) 1996-2002 by Jorn Lind-Nielsen
|
||||
All rights reserved
|
||||
|
||||
Permission is hereby granted, without written agreement and without
|
||||
license or royalty fees, to use, reproduce, prepare derivative
|
||||
works, distribute, and display this software and its documentation
|
||||
for any purpose, provided that (1) the above copyright notice and
|
||||
the following two paragraphs appear in all copies of the source code
|
||||
and (2) redistributions, including without limitation binaries,
|
||||
reproduce these notices in the supporting documentation. Substantial
|
||||
modifications to this software may be copyrighted by their authors
|
||||
and need not follow the licensing terms described here, provided
|
||||
that the new terms are clearly indicated in all files where they apply.
|
||||
|
||||
IN NO EVENT SHALL JORN LIND-NIELSEN, OR DISTRIBUTORS OF THIS
|
||||
SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
|
||||
SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE
|
||||
ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
JORN LIND-NIELSEN SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
|
||||
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
||||
MODIFICATIONS.
|
||||
========================================================================*/
|
||||
|
||||
/*************************************************************************
|
||||
$Header: /Volumes/CVS/repository/spot/spot/buddy/src/prime.h,v 1.1 2003/05/05 10:57:57 aduret Exp $
|
||||
FILE: prime.c
|
||||
DESCR: Prime number calculations
|
||||
AUTH: Jorn Lind
|
||||
DATE: (C) feb 2001
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef _PRIME_H
|
||||
#define _PRIME_H
|
||||
|
||||
unsigned int bdd_prime_gte(unsigned int src);
|
||||
unsigned int bdd_prime_lte(unsigned int src);
|
||||
|
||||
|
||||
#endif /* _PRIME_H */
|
||||
|
||||
|
||||
/* EOF */
|
||||
2322
buddy/src/reorder.c
Normal file
2322
buddy/src/reorder.c
Normal file
File diff suppressed because it is too large
Load diff
222
buddy/src/tree.c
Normal file
222
buddy/src/tree.c
Normal file
|
|
@ -0,0 +1,222 @@
|
|||
/*========================================================================
|
||||
Copyright (C) 1996-2002 by Jorn Lind-Nielsen
|
||||
All rights reserved
|
||||
|
||||
Permission is hereby granted, without written agreement and without
|
||||
license or royalty fees, to use, reproduce, prepare derivative
|
||||
works, distribute, and display this software and its documentation
|
||||
for any purpose, provided that (1) the above copyright notice and
|
||||
the following two paragraphs appear in all copies of the source code
|
||||
and (2) redistributions, including without limitation binaries,
|
||||
reproduce these notices in the supporting documentation. Substantial
|
||||
modifications to this software may be copyrighted by their authors
|
||||
and need not follow the licensing terms described here, provided
|
||||
that the new terms are clearly indicated in all files where they apply.
|
||||
|
||||
IN NO EVENT SHALL JORN LIND-NIELSEN, OR DISTRIBUTORS OF THIS
|
||||
SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
||||
INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
|
||||
SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE
|
||||
ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
JORN LIND-NIELSEN SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
|
||||
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
||||
MODIFICATIONS.
|
||||
========================================================================*/
|
||||
|
||||
/*************************************************************************
|
||||
$Header: /Volumes/CVS/repository/spot/spot/buddy/src/tree.c,v 1.1 2003/05/05 10:57:57 aduret Exp $
|
||||
FILE: tree.c
|
||||
DESCR: Trees for BDD variables
|
||||
AUTH: Jorn Lind
|
||||
DATE: (C) march 1998
|
||||
*************************************************************************/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "kernel.h"
|
||||
#include "bddtree.h"
|
||||
|
||||
/*************************************************************************
|
||||
*************************************************************************/
|
||||
|
||||
BddTree *bddtree_addrange_rec(BddTree *, BddTree *, int, int, int, int);
|
||||
|
||||
|
||||
/*======================================================================*/
|
||||
|
||||
static void update_seq(BddTree *t)
|
||||
{
|
||||
int n;
|
||||
int low = t->first;
|
||||
|
||||
for (n=t->first ; n<=t->last ; n++)
|
||||
if (bddvar2level[n] < bddvar2level[low])
|
||||
low = n;
|
||||
|
||||
for (n=t->first ; n<=t->last ; n++)
|
||||
t->seq[bddvar2level[n]-bddvar2level[low]] = n;
|
||||
}
|
||||
|
||||
|
||||
BddTree *bddtree_new(int id)
|
||||
{
|
||||
BddTree *t = NEW(BddTree,1);
|
||||
if (t == NULL)
|
||||
return NULL;
|
||||
|
||||
t->first = t->last = -1;
|
||||
t->fixed = 1;
|
||||
t->next = t->prev = t->nextlevel = NULL;
|
||||
t->seq = NULL;
|
||||
t->id = id;
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
void bddtree_del(BddTree *t)
|
||||
{
|
||||
if (t == NULL)
|
||||
return;
|
||||
|
||||
bddtree_del(t->nextlevel);
|
||||
bddtree_del(t->next);
|
||||
if (t->seq != NULL)
|
||||
free(t->seq);
|
||||
free(t);
|
||||
}
|
||||
|
||||
|
||||
BddTree *bddtree_addrange_rec(BddTree *t, BddTree *prev,
|
||||
int first, int last, int fixed, int id)
|
||||
{
|
||||
if (first < 0 || last < 0 || last < first)
|
||||
return NULL;
|
||||
|
||||
/* Empty tree -> build one */
|
||||
if (t == NULL)
|
||||
{
|
||||
if ((t=bddtree_new(id)) == NULL)
|
||||
return NULL;
|
||||
t->first = first;
|
||||
t->fixed = fixed;
|
||||
t->seq = NEW(int,last-first+1);
|
||||
t->last = last;
|
||||
update_seq(t);
|
||||
t->prev = prev;
|
||||
return t;
|
||||
}
|
||||
|
||||
/* Check for identity */
|
||||
if (first == t->first && last == t->last)
|
||||
return t;
|
||||
|
||||
/* Before this section -> insert */
|
||||
if (last < t->first)
|
||||
{
|
||||
BddTree *tnew = bddtree_new(id);
|
||||
if (tnew == NULL)
|
||||
return NULL;
|
||||
tnew->first = first;
|
||||
tnew->last = last;
|
||||
tnew->fixed = fixed;
|
||||
tnew->seq = NEW(int,last-first+1);
|
||||
update_seq(tnew);
|
||||
tnew->next = t;
|
||||
tnew->prev = t->prev;
|
||||
t->prev = tnew;
|
||||
return tnew;
|
||||
}
|
||||
|
||||
/* After this this section -> go to next */
|
||||
if (first > t->last)
|
||||
{
|
||||
t->next = bddtree_addrange_rec(t->next, t, first, last, fixed, id);
|
||||
return t;
|
||||
}
|
||||
|
||||
/* Inside this section -> insert in next level */
|
||||
if (first >= t->first && last <= t->last)
|
||||
{
|
||||
t->nextlevel =
|
||||
bddtree_addrange_rec(t->nextlevel,NULL,first,last,fixed,id);
|
||||
return t;
|
||||
}
|
||||
|
||||
/* Covering this section -> insert above this level */
|
||||
if (first <= t->first)
|
||||
{
|
||||
BddTree *tnew;
|
||||
BddTree *this = t;
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* Partial cover ->error */
|
||||
if (last >= this->first && last < this->last)
|
||||
return NULL;
|
||||
|
||||
if (this->next == NULL || last < this->next->first)
|
||||
{
|
||||
tnew = bddtree_new(id);
|
||||
if (tnew == NULL)
|
||||
return NULL;
|
||||
tnew->first = first;
|
||||
tnew->last = last;
|
||||
tnew->fixed = fixed;
|
||||
tnew->seq = NEW(int,last-first+1);
|
||||
update_seq(tnew);
|
||||
tnew->nextlevel = t;
|
||||
tnew->next = this->next;
|
||||
tnew->prev = t->prev;
|
||||
if (this->next != NULL)
|
||||
this->next->prev = tnew;
|
||||
this->next = NULL;
|
||||
t->prev = NULL;
|
||||
return tnew;
|
||||
}
|
||||
|
||||
this = this->next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
BddTree *bddtree_addrange(BddTree *t, int first, int last, int fixed,int id)
|
||||
{
|
||||
return bddtree_addrange_rec(t,NULL,first,last,fixed,id);
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
int main(void)
|
||||
{
|
||||
BddTree *t = NULL;
|
||||
|
||||
t = bddtree_addrange(t, 8,10,1);
|
||||
printf("A\n"); bddtree_print(stdout, t, 0);
|
||||
t = bddtree_addrange(t, 2,99,1);
|
||||
printf("B\n"); bddtree_print(stdout, t, 0);
|
||||
t = bddtree_addrange(t, 11,50,1);
|
||||
printf("C\n"); bddtree_print(stdout, t, 0);
|
||||
t = bddtree_addrange(t, 5,7,1);
|
||||
printf("D\n"); bddtree_print(stdout, t, 0);
|
||||
t = bddtree_addrange(t, 5,10,1);
|
||||
printf("E\n"); bddtree_print(stdout, t, 0);
|
||||
t = bddtree_addrange(t, 100,150,1);
|
||||
printf("F\n"); bddtree_print(stdout, t, 0);
|
||||
t = bddtree_addrange(t, 60,65,1);
|
||||
printf("G\n"); bddtree_print(stdout, t, 0);
|
||||
t = bddtree_addrange(t, 3,200,1);
|
||||
|
||||
printf("H\n"); bddtree_print(stdout, t, 0);
|
||||
bddtree_del(t);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* EOF */
|
||||
Loading…
Add table
Add a link
Reference in a new issue