Initial revision
This commit is contained in:
parent
1fa73989e0
commit
cf5dd46350
67 changed files with 44947 additions and 0 deletions
200
buddy/CHANGES
Normal file
200
buddy/CHANGES
Normal file
|
|
@ -0,0 +1,200 @@
|
||||||
|
----------------------------------------------------------------------------
|
||||||
|
Logfile for changes to the BDD package
|
||||||
|
----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
+ means added code
|
||||||
|
x means bugfix or changed code
|
||||||
|
- means removed code
|
||||||
|
|
||||||
|
Thanks to the following people for bug reports, suggestions and source code:
|
||||||
|
Alan Mishchenko
|
||||||
|
Gerd Behrmann
|
||||||
|
Henrik Hulgaard
|
||||||
|
Henrik Reif Andersen
|
||||||
|
Jacob Lichtenberg
|
||||||
|
Ken Larsen
|
||||||
|
Nicola Soranzo
|
||||||
|
Nikolaj Bjorner
|
||||||
|
|
||||||
|
|
||||||
|
VER 2.2 (november 2002)
|
||||||
|
-----------------------
|
||||||
|
+ Added bvec_ite() for calculating an if-then-else operation on
|
||||||
|
a boolean vector.
|
||||||
|
x Fixed some garbage collection problems introduced in version 2.1.
|
||||||
|
|
||||||
|
|
||||||
|
VER 2.1 (march 2002)
|
||||||
|
--------------------
|
||||||
|
+ Added bdd_allsat() for calculating all possible variable assignments
|
||||||
|
to a bdd.
|
||||||
|
x Fixed some wrong garbage collection #defines in kernel.h. If you
|
||||||
|
haven't experinced any problems using BuDDy, then this should not
|
||||||
|
be an issue. No bug reports reported for this one - found by code
|
||||||
|
inspection thanx to Nicola Soranzo.
|
||||||
|
x Fixed some copy paste errors in the prime number calculation.
|
||||||
|
This should not be an issue. No bug reports reported for this one
|
||||||
|
- found by code inspection thanx to Nicola Soranzo.
|
||||||
|
|
||||||
|
|
||||||
|
VER 2.0 (march 2001)
|
||||||
|
--------------------
|
||||||
|
x Change the copyright notice to a more acceptable form.
|
||||||
|
x Speedup changes in bdd_support()
|
||||||
|
x Rewrote all the prime number calculations in order to get the
|
||||||
|
copyright right.
|
||||||
|
|
||||||
|
|
||||||
|
VER 1.9 (august 2000)
|
||||||
|
---------------------
|
||||||
|
+ Added bdd_pathcount
|
||||||
|
+ Added bdd_anodecount
|
||||||
|
+ Added bdd_buildcube, bdd_ibuildcube
|
||||||
|
x Bugfix in bdd_satcountset and bdd_satcountlnset. This corrects a bug
|
||||||
|
introduced in version 1.8.
|
||||||
|
x bug fixes in bdd_constraint and bdd_simplify. Both did calculate a
|
||||||
|
correct cofactor, but not necessarily a minimal one. Changed the name
|
||||||
|
of bdd_constraint to bdd_constrain at the same time.
|
||||||
|
x bug fix in memory allocation for bdd_addvarblock
|
||||||
|
x Changed functions in bddop.c in order to avoid some compiler warnings.
|
||||||
|
x Makefile also installs "fdd.h" and "bvec.h".
|
||||||
|
x Small #include fix in N-Queen example.
|
||||||
|
x Minor changes in the documentation.
|
||||||
|
|
||||||
|
|
||||||
|
VER 1.8 (may 2000)
|
||||||
|
------------------
|
||||||
|
+ Bugfix in the kernel: canonicity was not unfortunately not guaranteed
|
||||||
|
on certain compilers (at least the microsoft visual C compiler) due to a
|
||||||
|
signed/unsigned bug in kernel.c (and actually not microsofts fault).
|
||||||
|
+ Speedups in the reordering code.
|
||||||
|
+ Added the use of an interaction matrix for variable swapping.
|
||||||
|
+ Added bdd_satoneset
|
||||||
|
+ Added bdd_getallocnum
|
||||||
|
+ Added bdd_setvarorder
|
||||||
|
+ Added bdd_unique, bdd_appuni.
|
||||||
|
+ Added bvec_shlfixed, bvec_shrfixed and changed the prototype for
|
||||||
|
bvec_shl and bvec_shr.
|
||||||
|
+ Added bvec_mulfixed, bdd_divfixed, bdd_div and changed the
|
||||||
|
prototype for bvec_mul.
|
||||||
|
+ Added bdd_printstat
|
||||||
|
+ Added new examples: solitare and money
|
||||||
|
+ Forces cache tables to prime-number size.
|
||||||
|
+ Added bdd_clear_error() if anybody needs that.
|
||||||
|
+ Added reorder method WIN3 and WIN3ITE
|
||||||
|
x Small change in queen.cxx - with a huge impact on runtime!
|
||||||
|
x Bugfix in reordering. In some cases reordering would go on forever;
|
||||||
|
first reroder, then retry, then reorder again without resize etc. always
|
||||||
|
reordering in the same operation. Now at most one reordering is allowed
|
||||||
|
for each bdd operation.
|
||||||
|
x Bugfix in C++ printing in Dot format. Wrote zero for one and vice versa.
|
||||||
|
x Bugfix in the garbage collector. If bdd_setmaxincrease was used, then
|
||||||
|
BuDDy would call bdd_error prematurely. Not a major bug, but annoying.
|
||||||
|
x Bugfix in bdd_load.
|
||||||
|
x Speedup in bdd_satcountset and bdd_satcountlnset
|
||||||
|
x Updates to the docs.
|
||||||
|
x Updates to the makefiles
|
||||||
|
|
||||||
|
|
||||||
|
VER 1.7 (september 1999)
|
||||||
|
------------------------
|
||||||
|
+ Added support for boolean vector operations used in integer arithmetics
|
||||||
|
+ Split "bdd.h" into "bdd.h", "fdd.h" and "bvec.h"
|
||||||
|
+ Added bdd_cachestats
|
||||||
|
+ Added bdd_and, bdd_or, bdd_xor, bdd_impl, bdd_biimpl
|
||||||
|
(wrappers for bdd_apply).
|
||||||
|
+ Added a BDD calculator for combinatorial circuits as an example.
|
||||||
|
+ Added an example showing the use of the FDD interface.
|
||||||
|
+ Added bdd_autoreorder_times, bdd_getreorder_method, bdd_getreorder_times,
|
||||||
|
bdd_reorder_probe, bdd_enable_reorder, bdd_disable_reorder,
|
||||||
|
bdd_var2level, bdd_level2var, bdd_reorder_gain, bdd_swapvar
|
||||||
|
+ Added bdd_file_hook, bdd_strm_hook, fdd_file_hook, fdd_strm_hook
|
||||||
|
+ Added support for dynamic resizing of the operator caches with
|
||||||
|
the function bdd_setcacheratio.
|
||||||
|
+ Added more documentation.
|
||||||
|
x Bugfix in reordering code. This would appear when recursive variable
|
||||||
|
blocks were defined (blocks with sub-blocks).
|
||||||
|
x Speedup changes in the variable reordering code
|
||||||
|
x The automatic reordering threshhold function has been changed
|
||||||
|
x Automatic reordering is now interrupting and restarts bdd operations
|
||||||
|
x Prototype for bdd_reorder_hook changed.
|
||||||
|
x Printing of reorder information (verbose level > 0) is changed.
|
||||||
|
x The threshold for stopping of the iterative reordering methods has
|
||||||
|
been changed. The reordering now continues until no progress is done
|
||||||
|
at all (before it would stop when less than 5% where gained).
|
||||||
|
x Added a few sanity checks to many of the functions.
|
||||||
|
x Bugfix (parameter checking) in fdd_ithvar.
|
||||||
|
- bdd_varlevel removed (use bdd_var2level and bdd_level2var).
|
||||||
|
|
||||||
|
|
||||||
|
VER 1.6 (november 1998)
|
||||||
|
-----------------------
|
||||||
|
+ Added bdd_resetpair
|
||||||
|
+ Added bdd_satcountset, bdd_satcountlnset
|
||||||
|
+ Added macro bdd_relprod
|
||||||
|
+ Added fdd_overlapdomain
|
||||||
|
+ Added fdd_domain
|
||||||
|
x Fixed a bug in bdd_setvarnum and bdd_extvarnum.
|
||||||
|
x Fixed a bug in bdd_newpair() which would give problems with reordering.
|
||||||
|
x Speedup changes in bdd_exist, bdd_forall, bdd_appex, bdd_appall
|
||||||
|
x Speedup changes in bdd_restrict
|
||||||
|
x Changed bdd_gbc_hook to include both pre and post garbage collection.
|
||||||
|
|
||||||
|
|
||||||
|
VER 1.5 (september 1998)
|
||||||
|
------------------------
|
||||||
|
+ Added bdd_cofactor
|
||||||
|
+ Added and fixed some error checks in fdd.c
|
||||||
|
x Fixed a bug in bdd_setvarnum().
|
||||||
|
|
||||||
|
|
||||||
|
VER 1.4 (july 1998)
|
||||||
|
-------------------
|
||||||
|
The package just got a name: BuDDy
|
||||||
|
+ Added functions bdd_compose, bdd_veccompose, bdd_ite.
|
||||||
|
+ Added functions bdd_setbddpair, bdd_setbddpairs.
|
||||||
|
+ Added functions bdd_var, bdd_low, bdd_high.
|
||||||
|
+ Added technical documentation in docs/tech.txt
|
||||||
|
x Overloaded C++ functions are not used any more. This mainly changes
|
||||||
|
the name of the printing functions in C++.
|
||||||
|
x Changed datatype names (You'll hate me for this one):
|
||||||
|
BddPair -> bddPair
|
||||||
|
BddStat -> bddStat
|
||||||
|
BddGbcStat -> bddGbcStat
|
||||||
|
x Added slightly more documentation.
|
||||||
|
x Some internal changes to the code - should not be visible to users.
|
||||||
|
|
||||||
|
|
||||||
|
VER 1.3 (june 1998)
|
||||||
|
-------------------
|
||||||
|
x Fixed a few serious bugs in the reordering code
|
||||||
|
|
||||||
|
|
||||||
|
VER 1.2 (june 1998)
|
||||||
|
-------------------
|
||||||
|
+ Added support for dynamic variable reordering
|
||||||
|
+ Added reordering handler (bdd_reorder_hook)
|
||||||
|
+ More added to the docs
|
||||||
|
x Changed the event handlers (bdd_xxx_hook)
|
||||||
|
|
||||||
|
|
||||||
|
VER 1.1 (april 1998)
|
||||||
|
--------------------
|
||||||
|
+ Added bdd_varprofile
|
||||||
|
+ Added fdd_scanset
|
||||||
|
+ Mucho better documentation.
|
||||||
|
+ Added Henrik Reif Andersen's BDD notes to the documentation.
|
||||||
|
+ Added BDD_REORDER_RANDOM for test purposes (usefull for others?)
|
||||||
|
x Fixed a bug in bdd_appex and bdd_appall.
|
||||||
|
x Fixed a bug in bdd_simplify.
|
||||||
|
x Speed fixup to fdd_extdomain
|
||||||
|
x Lots of small (insignificant?) bug fixes in fdd.c.
|
||||||
|
x bdd_load/save updated to take reordering into account.
|
||||||
|
x Generalized bdd_restrict to use a BDD variable set.
|
||||||
|
x Fixed the identifiers for the operator caches.
|
||||||
|
x The math functions log1p and pow2 has been removed as they didn't
|
||||||
|
exist on some systems. The same applies to M_LN2.
|
||||||
|
x New file structure and makefiles.
|
||||||
|
- Removed bdd_break, bdd_restart1
|
||||||
|
|
||||||
|
|
||||||
118
buddy/README
Normal file
118
buddy/README
Normal file
|
|
@ -0,0 +1,118 @@
|
||||||
|
==========================================================================
|
||||||
|
*** BuDDy ***
|
||||||
|
Binary Decision Diagrams
|
||||||
|
Library Package v2.2
|
||||||
|
--------------------------------------------------------------------------
|
||||||
|
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.
|
||||||
|
==========================================================================
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
--- REQUIREMENTS ----------------------------------------------------
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
|
||||||
|
* A (not to old) C++ compiler
|
||||||
|
* A machine that supports 32 bit integers
|
||||||
|
|
||||||
|
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
--- INSTALLING ------------------------------------------------------
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
|
||||||
|
2) Edit the file "config" to specify your compiler options and
|
||||||
|
where the package is to be installed.
|
||||||
|
|
||||||
|
3) type "make" to make the binary.
|
||||||
|
|
||||||
|
4) type "make install" to copy the BDD files to their appropriate
|
||||||
|
directories.
|
||||||
|
|
||||||
|
5) type "make examples" to make the examples
|
||||||
|
|
||||||
|
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
--- USING -----------------------------------------------------------
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
|
||||||
|
Assuming that the files "bdd.h" and "libbdd.a" are in directories
|
||||||
|
"/usr/local/include" and "/usr/local/lib" then the compile command
|
||||||
|
could be:
|
||||||
|
|
||||||
|
g++ -I/usr/local/include myfile.cc -o myfile -L/usr/local/lib -lbdd
|
||||||
|
|
||||||
|
Your machine may be setup to use the above directories auto-
|
||||||
|
matically, so you might be able to do:
|
||||||
|
|
||||||
|
g++ myfile.cc -o myfile -lbdd
|
||||||
|
|
||||||
|
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
--- FILES -----------------------------------------------------------
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
|
||||||
|
src: All files needed for the BuDDy package.
|
||||||
|
examples: Example files
|
||||||
|
fdd: An example of use of the FDD interface.
|
||||||
|
calculator: An example of a BDD calculator. Uses reordering.
|
||||||
|
adder: Construction of a N-bit adder. Uses reordering.
|
||||||
|
milner: A calculation of the reachable statespace for Milner's
|
||||||
|
scheduler. C++.
|
||||||
|
cmilner: As above but purely in ANSI-C.
|
||||||
|
queen: Solution to the N-queen chess problem.
|
||||||
|
solitare: Solution to a solitare game.
|
||||||
|
money: Solution to the send-more-money problem (bvec demo).
|
||||||
|
internal: Some internal regression tests.
|
||||||
|
doc: Documentation.
|
||||||
|
buddy.ps: Package documentation.
|
||||||
|
bddnotes.ps: BDD introduction notes.
|
||||||
|
|
||||||
|
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
--- FEEDBACK --------------------------------------------------------
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
|
||||||
|
Please do not hesitate to send any questions or bug reports to:
|
||||||
|
|
||||||
|
Jorn Lind-Nielsen: buddy@itu.dk
|
||||||
|
(or maybe jorn_lind_nielsen@hotmail.com or jln@fjeldgruppen.dk)
|
||||||
|
|
||||||
|
It may take some time to get an answer since BuDDy do not have that
|
||||||
|
much focus any more - but I'll try to give a reasonable answer
|
||||||
|
in (finite) time.
|
||||||
|
|
||||||
|
New updates and other info can be found at:
|
||||||
|
|
||||||
|
http://www.it-c.dk/research/buddy/
|
||||||
|
(or http://www.itu.dk/research/buddy)
|
||||||
|
|
||||||
|
|
||||||
|
Hope you find some use for this software
|
||||||
|
|
||||||
|
Jorn Lind-Nielsen
|
||||||
|
|
||||||
46
buddy/config
Normal file
46
buddy/config
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
# ==============================================================
|
||||||
|
# Makefile for the BuDDy package
|
||||||
|
# - Edit the lines below to configure
|
||||||
|
# ==============================================================
|
||||||
|
|
||||||
|
# --- Your compiler flags
|
||||||
|
CFLAGS = -g -ansi -Wmissing-prototypes -Wall
|
||||||
|
|
||||||
|
# --- Where to install the library (directory, no trailing slash)
|
||||||
|
LIBDIR = /usr/local/lib
|
||||||
|
|
||||||
|
# --- Where to install the include file (directory, no trailing slash)
|
||||||
|
INCDIR = /usr/local/include
|
||||||
|
|
||||||
|
# --- Your C compiler
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
# --- Your C++ compiler
|
||||||
|
CPP = g++
|
||||||
|
|
||||||
|
# Some machines are missing "CLOCKS_PER_SEC". Please define a default value
|
||||||
|
# If you do not know this, then leave it as it is.
|
||||||
|
CLOCK=60
|
||||||
|
|
||||||
|
CLOCKFLAG = -DDEFAULT_CLOCK=$(CLOCK)
|
||||||
|
|
||||||
|
# Debugging and statistical flags. Possible values are:
|
||||||
|
# -DSWAPCOUNT : Count number of fundamental variable swaps
|
||||||
|
# -DCACHESTATS : Gather statistical information about operator and
|
||||||
|
# unique node caching
|
||||||
|
DEBUGFLAGS =
|
||||||
|
|
||||||
|
# Some of the BuDDy library needs 64 bit arithmetics.
|
||||||
|
# With gnu C++, Microsoft C++ and KAI C++ this is part of the
|
||||||
|
# language and used by BuDDy. With other compilers BuDDy need
|
||||||
|
# to implement the math it self -- which is a bit slower. If
|
||||||
|
# you now of a 64 bit unsigned integer type on your platform
|
||||||
|
# then define that in the BUDDYUINT64 variable. Example:
|
||||||
|
# BUDDYUINT64 = -DBUDDYUINT64="long long"
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------
|
||||||
|
# Do not touch
|
||||||
|
# --------------------------------------------------------------
|
||||||
|
DFLAGS = $(CLOCKFLAG) $(DEBUGFLAGS) $(BUDDYUINT64)
|
||||||
|
|
||||||
15417
buddy/doc/bddnotes.ps
Normal file
15417
buddy/doc/bddnotes.ps
Normal file
File diff suppressed because it is too large
Load diff
7287
buddy/doc/buddy.ps
Normal file
7287
buddy/doc/buddy.ps
Normal file
File diff suppressed because it is too large
Load diff
1
buddy/doc/makefile
Normal file
1
buddy/doc/makefile
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
clean:
|
||||||
186
buddy/doc/tech.txt
Normal file
186
buddy/doc/tech.txt
Normal file
|
|
@ -0,0 +1,186 @@
|
||||||
|
****************************************************************************
|
||||||
|
How to create your own internal BDD functions.
|
||||||
|
****************************************************************************
|
||||||
|
|
||||||
|
PLEASE NOTE
|
||||||
|
That interrupting variable reordering has been introduced after this document was written.
|
||||||
|
|
||||||
|
|
||||||
|
===[ Functions that do not change or produce new BDDs ]=====================
|
||||||
|
|
||||||
|
I'll do this by example. Take "bdd_satcount" that counts the number of
|
||||||
|
satisfying assignments that makes a BDD true.
|
||||||
|
|
||||||
|
Almost all functions consists of some introduction followed by a
|
||||||
|
recursion through the BDD.
|
||||||
|
|
||||||
|
* Use the type BDD for all references (numbers) to BDD nodes.
|
||||||
|
* External BDD variables used internally in the package are
|
||||||
|
defined in "kernel.h"
|
||||||
|
* Macros for reading BDD nodes are:
|
||||||
|
LEVEL(r)
|
||||||
|
LOW(r)
|
||||||
|
HIGH(r)
|
||||||
|
ISCONST(r) => true if r is one of the terminals
|
||||||
|
|
||||||
|
|
||||||
|
double bdd_satcount(BDD r)
|
||||||
|
{
|
||||||
|
double size=1;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
CHECKa(r, 0.0); /* CHECK for valid nodes - defined in kernel.h */
|
||||||
|
|
||||||
|
miscid = CACHEID_SATCOU; /* Setup global variables. This is
|
||||||
|
used extensively instead of passing
|
||||||
|
arguments to the recursive functions,
|
||||||
|
for faster recursive calls */
|
||||||
|
|
||||||
|
for (n=0 ; n<LEVEL(r) ; n++) /* Setup whatever is needed for the */
|
||||||
|
size *= 2; /* recursion */
|
||||||
|
|
||||||
|
return size * bdd_satcount_rec(r); /* Do the recurison */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Cache tables are used for storing intermidiate results when doing BDD
|
||||||
|
operations. These are defined as static in the top of bddop.c (the
|
||||||
|
code is in cache.c) and they should be setup, cleared and delete at
|
||||||
|
the top of bddop.c in the functions bdd_operator_init,
|
||||||
|
bdd_operator_done, bdd_operator_reset.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static double bdd_satcount_rec(BDD root)
|
||||||
|
{
|
||||||
|
BddCacheData *entry; /* Entry pointer in the cache */
|
||||||
|
BddNode *node;
|
||||||
|
double size, s;
|
||||||
|
int m;
|
||||||
|
|
||||||
|
if (ISCONST(root)) /* Check for the constant terminals */
|
||||||
|
return root;
|
||||||
|
|
||||||
|
/* Lookup entry in the cache table used for this function */
|
||||||
|
|
||||||
|
entry = BddCache_lookup(&misccache, SATCOUHASH(root));
|
||||||
|
if (entry->a == root && entry->c == miscid)
|
||||||
|
return entry->r.dres;
|
||||||
|
|
||||||
|
/* Do whatever calculations are needed */
|
||||||
|
|
||||||
|
size = 0;
|
||||||
|
s = 1;
|
||||||
|
|
||||||
|
for (m=LEVEL(root)+1 ; m<LEVEL(LOW(root)) ; m++)
|
||||||
|
s *= 2;
|
||||||
|
size += s * bdd_satcount_rec(LOW(root)); /* Recurse on low part */
|
||||||
|
|
||||||
|
s = 1;
|
||||||
|
for (m=LEVEL(root)+1 ; m<LEVEL(HIGH(root)) ; m++)
|
||||||
|
s *= 2;
|
||||||
|
size += s * bdd_satcount_rec(HIGH(root)); /* Recurse on high part */
|
||||||
|
|
||||||
|
/* Insert result in cache table */
|
||||||
|
|
||||||
|
entry->a = root;
|
||||||
|
entry->c = miscid;
|
||||||
|
entry->r.dres = size;
|
||||||
|
|
||||||
|
return size; /* Return result */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
===[ Functions that produces new BDDs ]=====================================
|
||||||
|
|
||||||
|
Functions that produces BDD nodes must take great care to avoid
|
||||||
|
loosing intermidiate nodes when automatic garbage collections
|
||||||
|
occur. This is doneby stacking each intermidiate result until they are no more used. This stack is check by the garbage collector.
|
||||||
|
|
||||||
|
Macros for accessing the stack:
|
||||||
|
INITREF: Reset the stack
|
||||||
|
PUSHREF(n): Push the node 'n' on the stack
|
||||||
|
READREF(p): Read 'p' positions down the stack
|
||||||
|
POPREF(p): Pop 'p' nodes off the stack.
|
||||||
|
|
||||||
|
Again I'll illustrate this with an example - the NOT operator.
|
||||||
|
|
||||||
|
BDD bdd_not(BDD r)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
CHECKa(r, bddfalse); /* Validate arguments */
|
||||||
|
|
||||||
|
INITREF; /* Important! resets the stack */
|
||||||
|
|
||||||
|
res = not_rec(r); /* Recurse */
|
||||||
|
checkreorder(res); /* Check to see if a reordering was called for */
|
||||||
|
|
||||||
|
return res; /* Return result */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static BDD not_rec(BDD r)
|
||||||
|
{
|
||||||
|
BddCacheData *entry; /* Cache entry pointer */
|
||||||
|
BDD res;
|
||||||
|
|
||||||
|
if (ISZERO(r)) /* Check constant terminals */
|
||||||
|
return BDDONE;
|
||||||
|
if (ISONE(r))
|
||||||
|
return BDDZERO;
|
||||||
|
|
||||||
|
/* Lookup in cache */
|
||||||
|
entry = BddCache_lookup(&applycache, NOTHASH(r));
|
||||||
|
if (entry->a == r && entry->c == bddop_not)
|
||||||
|
return entry->r.res;
|
||||||
|
|
||||||
|
/* Recurse AND push result on the reference stack */
|
||||||
|
PUSHREF( not_rec(LOW(r)) );
|
||||||
|
PUSHREF( not_rec(HIGH(r)) );
|
||||||
|
|
||||||
|
/* Create a new BDD node */
|
||||||
|
res = bdd_makenode(LEVEL(r), READREF(2), READREF(1));
|
||||||
|
|
||||||
|
/* Pop result off the stack */
|
||||||
|
POPREF(2);
|
||||||
|
|
||||||
|
/* Insert in cache */
|
||||||
|
entry->a = r;
|
||||||
|
entry->c = bddop_not;
|
||||||
|
entry->r.res = res;
|
||||||
|
|
||||||
|
/* Return the result */
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
===[ Documentation ]========================================================
|
||||||
|
|
||||||
|
ALL entries visible to the user should be documentet by an commented
|
||||||
|
section like the one shown here, placed right before the code.
|
||||||
|
|
||||||
|
Each doc. entry consist of a keyword followed by {* ... text
|
||||||
|
... *}. The entries are:
|
||||||
|
|
||||||
|
NAME: Name of the function.
|
||||||
|
SECTION: Which part to place the documentation in.
|
||||||
|
SHORT: One line description of the code.
|
||||||
|
PROTO: The exact prototype.
|
||||||
|
DESCR: Multiline description of the code.
|
||||||
|
ALSO: Other relevant stuff.
|
||||||
|
RETURN: The returned value.
|
||||||
|
|
||||||
|
/*
|
||||||
|
NAME {* bdd\_satcount *}
|
||||||
|
SECTION {* info *}
|
||||||
|
SHORT {* Calculates the number of satisfying variable assignments *}
|
||||||
|
PROTO {* double bdd_satcount(BDD r) *}
|
||||||
|
DESCR {* Calculates how many possible variable assignments there exists
|
||||||
|
such that {\tt r} is satisfied, taking all defined variables
|
||||||
|
into account. *}
|
||||||
|
ALSO {* bdd\_satone, bdd\_fullsatone, bdd\_satcountln *}
|
||||||
|
RETURN {* The number of possible assignments. *}
|
||||||
|
*/
|
||||||
218
buddy/examples/adder/adder.cxx
Normal file
218
buddy/examples/adder/adder.cxx
Normal file
|
|
@ -0,0 +1,218 @@
|
||||||
|
/*************************************************************************
|
||||||
|
FILE: adder.cc
|
||||||
|
DESCR: BDD implementation of an N bit adder.
|
||||||
|
AUTH: Jorn Lind
|
||||||
|
DATE: feb 1998
|
||||||
|
*************************************************************************/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include "bdd.h"
|
||||||
|
|
||||||
|
int N;
|
||||||
|
|
||||||
|
bdd *ainp;
|
||||||
|
bdd *binp;
|
||||||
|
bdd *co;
|
||||||
|
bdd *xout;
|
||||||
|
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
Adder
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
void build_adder(void)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
|
||||||
|
for (n=0 ; n<N ; n++)
|
||||||
|
{
|
||||||
|
if (n > 0)
|
||||||
|
{
|
||||||
|
xout[n] = ainp[n] ^ binp[n] ^ co[n-1];
|
||||||
|
co[n] = ainp[n] & binp[n] |
|
||||||
|
ainp[n] & co[n-1] |
|
||||||
|
binp[n] & co[n-1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
xout[n] = ainp[n] ^ binp[n];
|
||||||
|
co[n] = ainp[n] & binp[n];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int method=BDD_REORDER_NONE;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
if(argc < 2 || argc > 3)
|
||||||
|
{
|
||||||
|
cout << "usage: adder N R\n";
|
||||||
|
cout << " N number of bits\n";
|
||||||
|
cout << " R -> enable reordering if R is win2,win2ite,win3,win3ite,sift,siftite\n";
|
||||||
|
cout << " in this case 'adder' starts with a worst case ordering\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
N = atoi(argv[1]);
|
||||||
|
if (N <= 0)
|
||||||
|
{
|
||||||
|
cout << "The number of bits must be more than zero\n";
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc == 3)
|
||||||
|
{
|
||||||
|
if (strcmp(argv[2], "win2") == 0)
|
||||||
|
method = BDD_REORDER_WIN2;
|
||||||
|
else
|
||||||
|
if (strcmp(argv[2], "win2ite") == 0)
|
||||||
|
method = BDD_REORDER_WIN2ITE;
|
||||||
|
else
|
||||||
|
if (strcmp(argv[2], "win3") == 0)
|
||||||
|
method = BDD_REORDER_WIN3;
|
||||||
|
else
|
||||||
|
if (strcmp(argv[2], "win3ite") == 0)
|
||||||
|
method = BDD_REORDER_WIN3ITE;
|
||||||
|
else
|
||||||
|
if (strcmp(argv[2], "sift") == 0)
|
||||||
|
method = BDD_REORDER_SIFT;
|
||||||
|
else
|
||||||
|
if (strcmp(argv[2], "siftite") == 0)
|
||||||
|
method = BDD_REORDER_SIFTITE;
|
||||||
|
else
|
||||||
|
if (strcmp(argv[2], "rand") == 0)
|
||||||
|
method = BDD_REORDER_RANDOM;
|
||||||
|
}
|
||||||
|
|
||||||
|
long c0 = clock();
|
||||||
|
|
||||||
|
bdd_init(500,1000);
|
||||||
|
bdd_setvarnum(2*N);
|
||||||
|
|
||||||
|
ainp = new bdd[N];
|
||||||
|
binp = new bdd[N];
|
||||||
|
co = new bdd[N];
|
||||||
|
xout = new bdd[N];
|
||||||
|
|
||||||
|
for (n=0 ; n<N ; n++)
|
||||||
|
{
|
||||||
|
if (method == BDD_REORDER_NONE)
|
||||||
|
{
|
||||||
|
ainp[n] = bdd_ithvar(2*n);
|
||||||
|
binp[n] = bdd_ithvar(2*n+1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ainp[n] = bdd_ithvar(n);
|
||||||
|
binp[n] = bdd_ithvar(N+n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (n=0 ; n<N ; n++)
|
||||||
|
{
|
||||||
|
bdd_addvarblock(ainp[n],1);
|
||||||
|
bdd_addvarblock(binp[n],1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//bdd_autoreorder(method);
|
||||||
|
//bdd_reorder_verbose(2);
|
||||||
|
build_adder();
|
||||||
|
|
||||||
|
if (method != BDD_REORDER_NONE)
|
||||||
|
{
|
||||||
|
cout << "Sizes before reordering:\n";
|
||||||
|
for (n=0 ; n<N ; n++)
|
||||||
|
cout << "Out[" << n << "]: " << bdd_nodecount(xout[n]) << " nodes\n";
|
||||||
|
|
||||||
|
long c1 = clock();
|
||||||
|
cout << (float)(c1-c0)/(float)(CLOCKS_PER_SEC) << " sec.\n";
|
||||||
|
|
||||||
|
bdd_reorder(method);
|
||||||
|
cout << "Sizes after reordering:\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cout << "Sizes:\n";
|
||||||
|
|
||||||
|
long c1 = clock();
|
||||||
|
|
||||||
|
for (n=0 ; n<N ; n++)
|
||||||
|
cout << "Out[" << n << "]: " << bdd_nodecount(xout[n]) << " nodes\n";
|
||||||
|
|
||||||
|
cout << (float)(c1-c0)/(float)(CLOCKS_PER_SEC) << " sec.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*=== DEBUGING =========================================================*/
|
||||||
|
|
||||||
|
bdd setval(int val, int v)
|
||||||
|
{
|
||||||
|
bdd x = bddtrue;
|
||||||
|
|
||||||
|
for (int n=0 ; n<N ; n++)
|
||||||
|
{
|
||||||
|
if (val & 1)
|
||||||
|
{
|
||||||
|
if (v == 0)
|
||||||
|
x &= ainp[n];
|
||||||
|
else
|
||||||
|
x &= binp[n];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (v == 0)
|
||||||
|
x &= !ainp[n];
|
||||||
|
else
|
||||||
|
x &= !binp[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
val = val >> 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int test_vector(bdd av, bdd bv, int a, int b)
|
||||||
|
{
|
||||||
|
int res = a+b;
|
||||||
|
|
||||||
|
for (int n=0 ; n<N ; n++)
|
||||||
|
{
|
||||||
|
bdd resv = av & bv & xout[n];
|
||||||
|
|
||||||
|
if (resv == bddfalse && (res & 1) || resv != bddfalse && !(res & 1))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
res = res >> 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int test_adder(void)
|
||||||
|
{
|
||||||
|
int m = 1 << N;
|
||||||
|
|
||||||
|
for (int a=0 ; a<m ; a++)
|
||||||
|
{
|
||||||
|
for (int b=0 ; b<m ; b++)
|
||||||
|
{
|
||||||
|
bdd av = setval(a,0);
|
||||||
|
bdd bv = setval(b,1);
|
||||||
|
|
||||||
|
if (test_vector(av,bv,a,b) == 0)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* EOF */
|
||||||
36
buddy/examples/adder/makefile
Normal file
36
buddy/examples/adder/makefile
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
# --------------------------------
|
||||||
|
# Makefile for adder test example
|
||||||
|
# --------------------------------
|
||||||
|
|
||||||
|
# --- Compiler flags
|
||||||
|
CFLAGS = -g -pedantic -Wall -ansi -L../../src -I../../src
|
||||||
|
|
||||||
|
# --- C++ compiler
|
||||||
|
CPP = g++
|
||||||
|
|
||||||
|
# --- C compiler
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
|
||||||
|
# --- Do not touch ---
|
||||||
|
|
||||||
|
.SUFFIXES: .cxx .c
|
||||||
|
|
||||||
|
.cxx.o:
|
||||||
|
$(CPP) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(CC) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
adder: adder.o bddlib
|
||||||
|
$(CPP) $(CFLAGS) adder.o -o adder -lbdd -lm
|
||||||
|
|
||||||
|
bddlib:
|
||||||
|
cd ../..; make
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *~
|
||||||
|
rm -f *.o
|
||||||
|
rm -f adder
|
||||||
|
|
||||||
|
adder.o: ../../src/bdd.h
|
||||||
10
buddy/examples/calculator/example.cal
Normal file
10
buddy/examples/calculator/example.cal
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
initial 100 100;
|
||||||
|
|
||||||
|
inputs
|
||||||
|
a b c;
|
||||||
|
|
||||||
|
actions
|
||||||
|
t1 = (a | b) & c;
|
||||||
|
t2 = (a & c) | (b & c);
|
||||||
|
t3 = t1 <> t2;
|
||||||
|
tautology t3;
|
||||||
818
buddy/examples/calculator/examples/c1355.cal
Normal file
818
buddy/examples/calculator/examples/c1355.cal
Normal file
|
|
@ -0,0 +1,818 @@
|
||||||
|
/* BDD Calculator data file */
|
||||||
|
|
||||||
|
initial 10000 10000;
|
||||||
|
|
||||||
|
inputs
|
||||||
|
_1gat _8gat _15gat _22gat _29gat _36gat _43gat _50gat _57gat _64gat
|
||||||
|
_71gat _78gat _85gat _92gat _99gat _106gat _113gat _120gat _127gat _134gat
|
||||||
|
_141gat _148gat _155gat _162gat _169gat _176gat _183gat _190gat _197gat _204gat
|
||||||
|
_211gat _218gat _225gat _226gat _227gat _228gat _229gat _230gat _231gat _232gat
|
||||||
|
_233gat ;
|
||||||
|
|
||||||
|
actions
|
||||||
|
autoreorder 0 sift;
|
||||||
|
|
||||||
|
t2 = _1gat;
|
||||||
|
t3 = _29gat;
|
||||||
|
t4 = t2 nand t3;
|
||||||
|
t5 = t2 nand t4;
|
||||||
|
t6 = t3 nand t4;
|
||||||
|
t7 = t5 nand t6;
|
||||||
|
t8 = _57gat;
|
||||||
|
t9 = _85gat;
|
||||||
|
t10 = t8 nand t9;
|
||||||
|
t11 = t8 nand t10;
|
||||||
|
t12 = t9 nand t10;
|
||||||
|
t13 = t11 nand t12;
|
||||||
|
t14 = t7 nand t13;
|
||||||
|
t15 = t7 nand t14;
|
||||||
|
t16 = t13 nand t14;
|
||||||
|
t17 = t15 nand t16;
|
||||||
|
t18 = _225gat;
|
||||||
|
t19 = _233gat;
|
||||||
|
t20 = t18 and t19;
|
||||||
|
t21 = _113gat;
|
||||||
|
t22 = _120gat;
|
||||||
|
t23 = t21 nand t22;
|
||||||
|
t24 = t21 nand t23;
|
||||||
|
t25 = t22 nand t23;
|
||||||
|
t26 = t24 nand t25;
|
||||||
|
t27 = _127gat;
|
||||||
|
t28 = _134gat;
|
||||||
|
t29 = t27 nand t28;
|
||||||
|
t30 = t27 nand t29;
|
||||||
|
t31 = t28 nand t29;
|
||||||
|
t32 = t30 nand t31;
|
||||||
|
t33 = t26 nand t32;
|
||||||
|
t34 = t26 nand t33;
|
||||||
|
t35 = t32 nand t33;
|
||||||
|
t36 = t34 nand t35;
|
||||||
|
t37 = _141gat;
|
||||||
|
t38 = _148gat;
|
||||||
|
t39 = t37 nand t38;
|
||||||
|
t40 = t37 nand t39;
|
||||||
|
t41 = t38 nand t39;
|
||||||
|
t42 = t40 nand t41;
|
||||||
|
t43 = _155gat;
|
||||||
|
t44 = _162gat;
|
||||||
|
t45 = t43 nand t44;
|
||||||
|
t46 = t43 nand t45;
|
||||||
|
t47 = t44 nand t45;
|
||||||
|
t48 = t46 nand t47;
|
||||||
|
t49 = t42 nand t48;
|
||||||
|
t50 = t42 nand t49;
|
||||||
|
t51 = t48 nand t49;
|
||||||
|
t52 = t50 nand t51;
|
||||||
|
t53 = t36 nand t52;
|
||||||
|
t54 = t36 nand t53;
|
||||||
|
t55 = t52 nand t53;
|
||||||
|
t56 = t54 nand t55;
|
||||||
|
t57 = t20 nand t56;
|
||||||
|
t58 = t20 nand t57;
|
||||||
|
t59 = t56 nand t57;
|
||||||
|
t60 = t58 nand t59;
|
||||||
|
t61 = t17 nand t60;
|
||||||
|
t62 = t17 nand t61;
|
||||||
|
t63 = t60 nand t61;
|
||||||
|
t64 = t62 nand t63;
|
||||||
|
t65 = t28 nand t44;
|
||||||
|
t66 = t28 nand t65;
|
||||||
|
t67 = t44 nand t65;
|
||||||
|
t68 = t66 nand t67;
|
||||||
|
t69 = _190gat;
|
||||||
|
t70 = _218gat;
|
||||||
|
t71 = t69 nand t70;
|
||||||
|
t72 = t69 nand t71;
|
||||||
|
t73 = t70 nand t71;
|
||||||
|
t74 = t72 nand t73;
|
||||||
|
t75 = t68 nand t74;
|
||||||
|
t76 = t68 nand t75;
|
||||||
|
t77 = t74 nand t75;
|
||||||
|
t78 = t76 nand t77;
|
||||||
|
t79 = _232gat;
|
||||||
|
t80 = t79 and t19;
|
||||||
|
t81 = _36gat;
|
||||||
|
t82 = t3 nand t81;
|
||||||
|
t83 = t3 nand t82;
|
||||||
|
t84 = t81 nand t82;
|
||||||
|
t85 = t83 nand t84;
|
||||||
|
t86 = _43gat;
|
||||||
|
t87 = _50gat;
|
||||||
|
t88 = t86 nand t87;
|
||||||
|
t89 = t86 nand t88;
|
||||||
|
t90 = t87 nand t88;
|
||||||
|
t91 = t89 nand t90;
|
||||||
|
t92 = t85 nand t91;
|
||||||
|
t93 = t85 nand t92;
|
||||||
|
t94 = t91 nand t92;
|
||||||
|
t95 = t93 nand t94;
|
||||||
|
t96 = _92gat;
|
||||||
|
t97 = t9 nand t96;
|
||||||
|
t98 = t9 nand t97;
|
||||||
|
t99 = t96 nand t97;
|
||||||
|
t100 = t98 nand t99;
|
||||||
|
t101 = _99gat;
|
||||||
|
t102 = _106gat;
|
||||||
|
t103 = t101 nand t102;
|
||||||
|
t104 = t101 nand t103;
|
||||||
|
t105 = t102 nand t103;
|
||||||
|
t106 = t104 nand t105;
|
||||||
|
t107 = t100 nand t106;
|
||||||
|
t108 = t100 nand t107;
|
||||||
|
t109 = t106 nand t107;
|
||||||
|
t110 = t108 nand t109;
|
||||||
|
t111 = t95 nand t110;
|
||||||
|
t112 = t95 nand t111;
|
||||||
|
t113 = t110 nand t111;
|
||||||
|
t114 = t112 nand t113;
|
||||||
|
t115 = t80 nand t114;
|
||||||
|
t116 = t80 nand t115;
|
||||||
|
t117 = t114 nand t115;
|
||||||
|
t118 = t116 nand t117;
|
||||||
|
t119 = t78 nand t118;
|
||||||
|
t120 = t78 nand t119;
|
||||||
|
t121 = t118 nand t119;
|
||||||
|
t122 = t120 nand t121;
|
||||||
|
t123 = not t122;
|
||||||
|
t124 = t27 nand t43;
|
||||||
|
t125 = t27 nand t124;
|
||||||
|
t126 = t43 nand t124;
|
||||||
|
t127 = t125 nand t126;
|
||||||
|
t128 = _183gat;
|
||||||
|
t129 = _211gat;
|
||||||
|
t130 = t128 nand t129;
|
||||||
|
t131 = t128 nand t130;
|
||||||
|
t132 = t129 nand t130;
|
||||||
|
t133 = t131 nand t132;
|
||||||
|
t134 = t127 nand t133;
|
||||||
|
t135 = t127 nand t134;
|
||||||
|
t136 = t133 nand t134;
|
||||||
|
t137 = t135 nand t136;
|
||||||
|
t138 = _231gat;
|
||||||
|
t139 = t138 and t19;
|
||||||
|
t140 = _8gat;
|
||||||
|
t141 = t2 nand t140;
|
||||||
|
t142 = t2 nand t141;
|
||||||
|
t143 = t140 nand t141;
|
||||||
|
t144 = t142 nand t143;
|
||||||
|
t145 = _15gat;
|
||||||
|
t146 = _22gat;
|
||||||
|
t147 = t145 nand t146;
|
||||||
|
t148 = t145 nand t147;
|
||||||
|
t149 = t146 nand t147;
|
||||||
|
t150 = t148 nand t149;
|
||||||
|
t151 = t144 nand t150;
|
||||||
|
t152 = t144 nand t151;
|
||||||
|
t153 = t150 nand t151;
|
||||||
|
t154 = t152 nand t153;
|
||||||
|
t155 = _64gat;
|
||||||
|
t156 = t8 nand t155;
|
||||||
|
t157 = t8 nand t156;
|
||||||
|
t158 = t155 nand t156;
|
||||||
|
t159 = t157 nand t158;
|
||||||
|
t160 = _71gat;
|
||||||
|
t161 = _78gat;
|
||||||
|
t162 = t160 nand t161;
|
||||||
|
t163 = t160 nand t162;
|
||||||
|
t164 = t161 nand t162;
|
||||||
|
t165 = t163 nand t164;
|
||||||
|
t166 = t159 nand t165;
|
||||||
|
t167 = t159 nand t166;
|
||||||
|
t168 = t165 nand t166;
|
||||||
|
t169 = t167 nand t168;
|
||||||
|
t170 = t154 nand t169;
|
||||||
|
t171 = t154 nand t170;
|
||||||
|
t172 = t169 nand t170;
|
||||||
|
t173 = t171 nand t172;
|
||||||
|
t174 = t139 nand t173;
|
||||||
|
t175 = t139 nand t174;
|
||||||
|
t176 = t173 nand t174;
|
||||||
|
t177 = t175 nand t176;
|
||||||
|
t178 = t137 nand t177;
|
||||||
|
t179 = t137 nand t178;
|
||||||
|
t180 = t177 nand t178;
|
||||||
|
t181 = t179 nand t180;
|
||||||
|
t182 = t21 nand t37;
|
||||||
|
t183 = t21 nand t182;
|
||||||
|
t184 = t37 nand t182;
|
||||||
|
t185 = t183 nand t184;
|
||||||
|
t186 = _169gat;
|
||||||
|
t187 = _197gat;
|
||||||
|
t188 = t186 nand t187;
|
||||||
|
t189 = t186 nand t188;
|
||||||
|
t190 = t187 nand t188;
|
||||||
|
t191 = t189 nand t190;
|
||||||
|
t192 = t185 nand t191;
|
||||||
|
t193 = t185 nand t192;
|
||||||
|
t194 = t191 nand t192;
|
||||||
|
t195 = t193 nand t194;
|
||||||
|
t196 = _229gat;
|
||||||
|
t197 = t196 and t19;
|
||||||
|
t198 = t154 nand t95;
|
||||||
|
t199 = t154 nand t198;
|
||||||
|
t200 = t95 nand t198;
|
||||||
|
t201 = t199 nand t200;
|
||||||
|
t202 = t197 nand t201;
|
||||||
|
t203 = t197 nand t202;
|
||||||
|
t204 = t201 nand t202;
|
||||||
|
t205 = t203 nand t204;
|
||||||
|
t206 = t195 nand t205;
|
||||||
|
t207 = t195 nand t206;
|
||||||
|
t208 = t205 nand t206;
|
||||||
|
t209 = t207 nand t208;
|
||||||
|
t210 = t22 nand t38;
|
||||||
|
t211 = t22 nand t210;
|
||||||
|
t212 = t38 nand t210;
|
||||||
|
t213 = t211 nand t212;
|
||||||
|
t214 = _176gat;
|
||||||
|
t215 = _204gat;
|
||||||
|
t216 = t214 nand t215;
|
||||||
|
t217 = t214 nand t216;
|
||||||
|
t218 = t215 nand t216;
|
||||||
|
t219 = t217 nand t218;
|
||||||
|
t220 = t213 nand t219;
|
||||||
|
t221 = t213 nand t220;
|
||||||
|
t222 = t219 nand t220;
|
||||||
|
t223 = t221 nand t222;
|
||||||
|
t224 = _230gat;
|
||||||
|
t225 = t224 and t19;
|
||||||
|
t226 = t169 nand t110;
|
||||||
|
t227 = t169 nand t226;
|
||||||
|
t228 = t110 nand t226;
|
||||||
|
t229 = t227 nand t228;
|
||||||
|
t230 = t225 nand t229;
|
||||||
|
t231 = t225 nand t230;
|
||||||
|
t232 = t229 nand t230;
|
||||||
|
t233 = t231 nand t232;
|
||||||
|
t234 = t223 nand t233;
|
||||||
|
t235 = t223 nand t234;
|
||||||
|
t236 = t233 nand t234;
|
||||||
|
t237 = t235 nand t236;
|
||||||
|
t238 = not t237;
|
||||||
|
t239 = t209 and t238;
|
||||||
|
t240 = t181 and t239;
|
||||||
|
t241 = t123 and t240;
|
||||||
|
t242 = t145 nand t86;
|
||||||
|
t243 = t145 nand t242;
|
||||||
|
t244 = t86 nand t242;
|
||||||
|
t245 = t243 nand t244;
|
||||||
|
t246 = t160 nand t101;
|
||||||
|
t247 = t160 nand t246;
|
||||||
|
t248 = t101 nand t246;
|
||||||
|
t249 = t247 nand t248;
|
||||||
|
t250 = t245 nand t249;
|
||||||
|
t251 = t245 nand t250;
|
||||||
|
t252 = t249 nand t250;
|
||||||
|
t253 = t251 nand t252;
|
||||||
|
t254 = _227gat;
|
||||||
|
t255 = t254 and t19;
|
||||||
|
t256 = t186 nand t214;
|
||||||
|
t257 = t186 nand t256;
|
||||||
|
t258 = t214 nand t256;
|
||||||
|
t259 = t257 nand t258;
|
||||||
|
t260 = t128 nand t69;
|
||||||
|
t261 = t128 nand t260;
|
||||||
|
t262 = t69 nand t260;
|
||||||
|
t263 = t261 nand t262;
|
||||||
|
t264 = t259 nand t263;
|
||||||
|
t265 = t259 nand t264;
|
||||||
|
t266 = t263 nand t264;
|
||||||
|
t267 = t265 nand t266;
|
||||||
|
t268 = t36 nand t267;
|
||||||
|
t269 = t36 nand t268;
|
||||||
|
t270 = t267 nand t268;
|
||||||
|
t271 = t269 nand t270;
|
||||||
|
t272 = t255 nand t271;
|
||||||
|
t273 = t255 nand t272;
|
||||||
|
t274 = t271 nand t272;
|
||||||
|
t275 = t273 nand t274;
|
||||||
|
t276 = t253 nand t275;
|
||||||
|
t277 = t253 nand t276;
|
||||||
|
t278 = t275 nand t276;
|
||||||
|
t279 = t277 nand t278;
|
||||||
|
t280 = not t279;
|
||||||
|
t281 = not t64;
|
||||||
|
t282 = t140 nand t81;
|
||||||
|
t283 = t140 nand t282;
|
||||||
|
t284 = t81 nand t282;
|
||||||
|
t285 = t283 nand t284;
|
||||||
|
t286 = t155 nand t96;
|
||||||
|
t287 = t155 nand t286;
|
||||||
|
t288 = t96 nand t286;
|
||||||
|
t289 = t287 nand t288;
|
||||||
|
t290 = t285 nand t289;
|
||||||
|
t291 = t285 nand t290;
|
||||||
|
t292 = t289 nand t290;
|
||||||
|
t293 = t291 nand t292;
|
||||||
|
t294 = _226gat;
|
||||||
|
t295 = t294 and t19;
|
||||||
|
t296 = t187 nand t215;
|
||||||
|
t297 = t187 nand t296;
|
||||||
|
t298 = t215 nand t296;
|
||||||
|
t299 = t297 nand t298;
|
||||||
|
t300 = t129 nand t70;
|
||||||
|
t301 = t129 nand t300;
|
||||||
|
t302 = t70 nand t300;
|
||||||
|
t303 = t301 nand t302;
|
||||||
|
t304 = t299 nand t303;
|
||||||
|
t305 = t299 nand t304;
|
||||||
|
t306 = t303 nand t304;
|
||||||
|
t307 = t305 nand t306;
|
||||||
|
t308 = t267 nand t307;
|
||||||
|
t309 = t267 nand t308;
|
||||||
|
t310 = t307 nand t308;
|
||||||
|
t311 = t309 nand t310;
|
||||||
|
t312 = t295 nand t311;
|
||||||
|
t313 = t295 nand t312;
|
||||||
|
t314 = t311 nand t312;
|
||||||
|
t315 = t313 nand t314;
|
||||||
|
t316 = t293 nand t315;
|
||||||
|
t317 = t293 nand t316;
|
||||||
|
t318 = t315 nand t316;
|
||||||
|
t319 = t317 nand t318;
|
||||||
|
t320 = t281 and t319;
|
||||||
|
t321 = t280 and t320;
|
||||||
|
t322 = t146 nand t87;
|
||||||
|
t323 = t146 nand t322;
|
||||||
|
t324 = t87 nand t322;
|
||||||
|
t325 = t323 nand t324;
|
||||||
|
t326 = t161 nand t102;
|
||||||
|
t327 = t161 nand t326;
|
||||||
|
t328 = t102 nand t326;
|
||||||
|
t329 = t327 nand t328;
|
||||||
|
t330 = t325 nand t329;
|
||||||
|
t331 = t325 nand t330;
|
||||||
|
t332 = t329 nand t330;
|
||||||
|
t333 = t331 nand t332;
|
||||||
|
t334 = _228gat;
|
||||||
|
t335 = t334 and t19;
|
||||||
|
t336 = t52 nand t307;
|
||||||
|
t337 = t52 nand t336;
|
||||||
|
t338 = t307 nand t336;
|
||||||
|
t339 = t337 nand t338;
|
||||||
|
t340 = t335 nand t339;
|
||||||
|
t341 = t335 nand t340;
|
||||||
|
t342 = t339 nand t340;
|
||||||
|
t343 = t341 nand t342;
|
||||||
|
t344 = t333 nand t343;
|
||||||
|
t345 = t333 nand t344;
|
||||||
|
t346 = t343 nand t344;
|
||||||
|
t347 = t345 nand t346;
|
||||||
|
t348 = not t347;
|
||||||
|
t349 = t321 and t348;
|
||||||
|
t350 = not t319;
|
||||||
|
t351 = t281 and t350;
|
||||||
|
t352 = t280 and t351;
|
||||||
|
t353 = t352 and t347;
|
||||||
|
t354 = t279 and t351;
|
||||||
|
t355 = t354 and t348;
|
||||||
|
t356 = t353 or t355;
|
||||||
|
t357 = t349 or t356;
|
||||||
|
t358 = t64 and t350;
|
||||||
|
t359 = t280 and t358;
|
||||||
|
t360 = t359 and t348;
|
||||||
|
t361 = t357 or t360;
|
||||||
|
t362 = t241 and t361;
|
||||||
|
t363 = t64 and t362;
|
||||||
|
t364 = t2 nand t363;
|
||||||
|
t365 = t2 nand t364;
|
||||||
|
t366 = t363 nand t364;
|
||||||
|
t367 = t365 nand t366;
|
||||||
|
t368 = t281 and t280;
|
||||||
|
t369 = t368 and t348;
|
||||||
|
t370 = t351 and t280;
|
||||||
|
t371 = t351 and t348;
|
||||||
|
t372 = t370 or t371;
|
||||||
|
t373 = t369 or t372;
|
||||||
|
t374 = t350 and t280;
|
||||||
|
t375 = t374 and t348;
|
||||||
|
t376 = t373 or t375;
|
||||||
|
t377 = t241 and t376;
|
||||||
|
t378 = t64 and t377;
|
||||||
|
t379 = t2 nand t378;
|
||||||
|
t380 = t2 nand t379;
|
||||||
|
t381 = t378 nand t379;
|
||||||
|
t382 = t380 nand t381;
|
||||||
|
t383 = t367 biimp t382;
|
||||||
|
t384 = t319 and t362;
|
||||||
|
t385 = t140 nand t384;
|
||||||
|
t386 = t140 nand t385;
|
||||||
|
t387 = t384 nand t385;
|
||||||
|
t388 = t386 nand t387;
|
||||||
|
t389 = t319 and t377;
|
||||||
|
t390 = t140 nand t389;
|
||||||
|
t391 = t140 nand t390;
|
||||||
|
t392 = t389 nand t390;
|
||||||
|
t393 = t391 nand t392;
|
||||||
|
t394 = t388 biimp t393;
|
||||||
|
t466 = not t209;
|
||||||
|
t467 = t466 and t237;
|
||||||
|
t468 = t181 and t467;
|
||||||
|
t469 = t123 and t468;
|
||||||
|
t470 = t469 and t361;
|
||||||
|
t494 = t279 and t470;
|
||||||
|
t495 = t160 nand t494;
|
||||||
|
t496 = t160 nand t495;
|
||||||
|
t497 = t494 nand t495;
|
||||||
|
t498 = t496 nand t497;
|
||||||
|
t476 = t469 and t376;
|
||||||
|
t499 = t279 and t476;
|
||||||
|
t500 = t160 nand t499;
|
||||||
|
t501 = t160 nand t500;
|
||||||
|
t502 = t499 nand t500;
|
||||||
|
t503 = t501 nand t502;
|
||||||
|
t504 = t498 biimp t503;
|
||||||
|
t505 = t347 and t470;
|
||||||
|
t506 = t161 nand t505;
|
||||||
|
t507 = t161 nand t506;
|
||||||
|
t508 = t505 nand t506;
|
||||||
|
t509 = t507 nand t508;
|
||||||
|
t510 = t347 and t476;
|
||||||
|
t511 = t161 nand t510;
|
||||||
|
t512 = t161 nand t511;
|
||||||
|
t513 = t510 nand t511;
|
||||||
|
t514 = t512 nand t513;
|
||||||
|
t515 = t509 biimp t514;
|
||||||
|
t417 = not t181;
|
||||||
|
t516 = t417 and t467;
|
||||||
|
t517 = t122 and t516;
|
||||||
|
t518 = t517 and t361;
|
||||||
|
t519 = t64 and t518;
|
||||||
|
t520 = t9 nand t519;
|
||||||
|
t521 = t9 nand t520;
|
||||||
|
t522 = t519 nand t520;
|
||||||
|
t523 = t521 nand t522;
|
||||||
|
t524 = t517 and t376;
|
||||||
|
t525 = t64 and t524;
|
||||||
|
t526 = t9 nand t525;
|
||||||
|
t527 = t9 nand t526;
|
||||||
|
t528 = t525 nand t526;
|
||||||
|
t529 = t527 nand t528;
|
||||||
|
t530 = t523 biimp t529;
|
||||||
|
t531 = t319 and t518;
|
||||||
|
t532 = t96 nand t531;
|
||||||
|
t533 = t96 nand t532;
|
||||||
|
t534 = t531 nand t532;
|
||||||
|
t535 = t533 nand t534;
|
||||||
|
t536 = t319 and t524;
|
||||||
|
t537 = t96 nand t536;
|
||||||
|
t538 = t96 nand t537;
|
||||||
|
t539 = t536 nand t537;
|
||||||
|
t540 = t538 nand t539;
|
||||||
|
t541 = t535 biimp t540;
|
||||||
|
t542 = t279 and t518;
|
||||||
|
t543 = t101 nand t542;
|
||||||
|
t544 = t101 nand t543;
|
||||||
|
t545 = t542 nand t543;
|
||||||
|
t546 = t544 nand t545;
|
||||||
|
t547 = t279 and t524;
|
||||||
|
t548 = t101 nand t547;
|
||||||
|
t549 = t101 nand t548;
|
||||||
|
t550 = t547 nand t548;
|
||||||
|
t551 = t549 nand t550;
|
||||||
|
t552 = t546 biimp t551;
|
||||||
|
t553 = t347 and t518;
|
||||||
|
t554 = t102 nand t553;
|
||||||
|
t555 = t102 nand t554;
|
||||||
|
t556 = t553 nand t554;
|
||||||
|
t557 = t555 nand t556;
|
||||||
|
t558 = t347 and t524;
|
||||||
|
t559 = t102 nand t558;
|
||||||
|
t560 = t102 nand t559;
|
||||||
|
t561 = t558 nand t559;
|
||||||
|
t562 = t560 nand t561;
|
||||||
|
t563 = t557 biimp t562;
|
||||||
|
t564 = t279 and t358;
|
||||||
|
t565 = t348 and t564;
|
||||||
|
t566 = t516 and t123;
|
||||||
|
t567 = t466 and t238;
|
||||||
|
t568 = t417 and t567;
|
||||||
|
t569 = t568 and t122;
|
||||||
|
t570 = t181 and t567;
|
||||||
|
t571 = t570 and t123;
|
||||||
|
t572 = t569 or t571;
|
||||||
|
t573 = t566 or t572;
|
||||||
|
t418 = t417 and t239;
|
||||||
|
t574 = t418 and t123;
|
||||||
|
t575 = t573 or t574;
|
||||||
|
t576 = t565 and t575;
|
||||||
|
t577 = t209 and t576;
|
||||||
|
t578 = t21 nand t577;
|
||||||
|
t579 = t21 nand t578;
|
||||||
|
t580 = t577 nand t578;
|
||||||
|
t581 = t579 nand t580;
|
||||||
|
t582 = t466 and t417;
|
||||||
|
t583 = t582 and t123;
|
||||||
|
t584 = t567 and t417;
|
||||||
|
t585 = t567 and t123;
|
||||||
|
t586 = t584 or t585;
|
||||||
|
t587 = t583 or t586;
|
||||||
|
t588 = t238 and t417;
|
||||||
|
t589 = t588 and t123;
|
||||||
|
t590 = t587 or t589;
|
||||||
|
t591 = t565 and t590;
|
||||||
|
t592 = t209 and t591;
|
||||||
|
t593 = t21 nand t592;
|
||||||
|
t594 = t21 nand t593;
|
||||||
|
t595 = t592 nand t593;
|
||||||
|
t596 = t594 nand t595;
|
||||||
|
t597 = t581 biimp t596;
|
||||||
|
t598 = t237 and t576;
|
||||||
|
t599 = t22 nand t598;
|
||||||
|
t600 = t22 nand t599;
|
||||||
|
t601 = t598 nand t599;
|
||||||
|
t602 = t600 nand t601;
|
||||||
|
t603 = t237 and t591;
|
||||||
|
t604 = t22 nand t603;
|
||||||
|
t605 = t22 nand t604;
|
||||||
|
t606 = t603 nand t604;
|
||||||
|
t607 = t605 nand t606;
|
||||||
|
t608 = t602 biimp t607;
|
||||||
|
t609 = t181 and t576;
|
||||||
|
t610 = t27 nand t609;
|
||||||
|
t611 = t27 nand t610;
|
||||||
|
t612 = t609 nand t610;
|
||||||
|
t613 = t611 nand t612;
|
||||||
|
t614 = t181 and t591;
|
||||||
|
t615 = t27 nand t614;
|
||||||
|
t616 = t27 nand t615;
|
||||||
|
t617 = t614 nand t615;
|
||||||
|
t618 = t616 nand t617;
|
||||||
|
t619 = t613 biimp t618;
|
||||||
|
t620 = t122 and t576;
|
||||||
|
t621 = t28 nand t620;
|
||||||
|
t622 = t28 nand t621;
|
||||||
|
t623 = t620 nand t621;
|
||||||
|
t624 = t622 nand t623;
|
||||||
|
t625 = t122 and t591;
|
||||||
|
t626 = t28 nand t625;
|
||||||
|
t627 = t28 nand t626;
|
||||||
|
t628 = t625 nand t626;
|
||||||
|
t629 = t627 nand t628;
|
||||||
|
t630 = t624 biimp t629;
|
||||||
|
t395 = t279 and t362;
|
||||||
|
t396 = t145 nand t395;
|
||||||
|
t397 = t145 nand t396;
|
||||||
|
t398 = t395 nand t396;
|
||||||
|
t399 = t397 nand t398;
|
||||||
|
t400 = t279 and t377;
|
||||||
|
t401 = t145 nand t400;
|
||||||
|
t402 = t145 nand t401;
|
||||||
|
t403 = t400 nand t401;
|
||||||
|
t404 = t402 nand t403;
|
||||||
|
t405 = t399 biimp t404;
|
||||||
|
t631 = t347 and t359;
|
||||||
|
t632 = t631 and t575;
|
||||||
|
t633 = t209 and t632;
|
||||||
|
t634 = t37 nand t633;
|
||||||
|
t635 = t37 nand t634;
|
||||||
|
t636 = t633 nand t634;
|
||||||
|
t637 = t635 nand t636;
|
||||||
|
t638 = t631 and t590;
|
||||||
|
t639 = t209 and t638;
|
||||||
|
t640 = t37 nand t639;
|
||||||
|
t641 = t37 nand t640;
|
||||||
|
t642 = t639 nand t640;
|
||||||
|
t643 = t641 nand t642;
|
||||||
|
t644 = t637 biimp t643;
|
||||||
|
t645 = t237 and t632;
|
||||||
|
t646 = t38 nand t645;
|
||||||
|
t647 = t38 nand t646;
|
||||||
|
t648 = t645 nand t646;
|
||||||
|
t649 = t647 nand t648;
|
||||||
|
t650 = t237 and t638;
|
||||||
|
t651 = t38 nand t650;
|
||||||
|
t652 = t38 nand t651;
|
||||||
|
t653 = t650 nand t651;
|
||||||
|
t654 = t652 nand t653;
|
||||||
|
t655 = t649 biimp t654;
|
||||||
|
t656 = t181 and t632;
|
||||||
|
t657 = t43 nand t656;
|
||||||
|
t658 = t43 nand t657;
|
||||||
|
t659 = t656 nand t657;
|
||||||
|
t660 = t658 nand t659;
|
||||||
|
t661 = t181 and t638;
|
||||||
|
t662 = t43 nand t661;
|
||||||
|
t663 = t43 nand t662;
|
||||||
|
t664 = t661 nand t662;
|
||||||
|
t665 = t663 nand t664;
|
||||||
|
t666 = t660 biimp t665;
|
||||||
|
t667 = t122 and t632;
|
||||||
|
t668 = t44 nand t667;
|
||||||
|
t669 = t44 nand t668;
|
||||||
|
t670 = t667 nand t668;
|
||||||
|
t671 = t669 nand t670;
|
||||||
|
t672 = t122 and t638;
|
||||||
|
t673 = t44 nand t672;
|
||||||
|
t674 = t44 nand t673;
|
||||||
|
t675 = t672 nand t673;
|
||||||
|
t676 = t674 nand t675;
|
||||||
|
t677 = t671 biimp t676;
|
||||||
|
t678 = t279 and t320;
|
||||||
|
t679 = t348 and t678;
|
||||||
|
t680 = t679 and t575;
|
||||||
|
t681 = t209 and t680;
|
||||||
|
t682 = t186 nand t681;
|
||||||
|
t683 = t186 nand t682;
|
||||||
|
t684 = t681 nand t682;
|
||||||
|
t685 = t683 nand t684;
|
||||||
|
t686 = t679 and t590;
|
||||||
|
t687 = t209 and t686;
|
||||||
|
t688 = t186 nand t687;
|
||||||
|
t689 = t186 nand t688;
|
||||||
|
t690 = t687 nand t688;
|
||||||
|
t691 = t689 nand t690;
|
||||||
|
t692 = t685 biimp t691;
|
||||||
|
t693 = t237 and t680;
|
||||||
|
t694 = t214 nand t693;
|
||||||
|
t695 = t214 nand t694;
|
||||||
|
t696 = t693 nand t694;
|
||||||
|
t697 = t695 nand t696;
|
||||||
|
t698 = t237 and t686;
|
||||||
|
t699 = t214 nand t698;
|
||||||
|
t700 = t214 nand t699;
|
||||||
|
t701 = t698 nand t699;
|
||||||
|
t702 = t700 nand t701;
|
||||||
|
t703 = t697 biimp t702;
|
||||||
|
t704 = t181 and t680;
|
||||||
|
t705 = t128 nand t704;
|
||||||
|
t706 = t128 nand t705;
|
||||||
|
t707 = t704 nand t705;
|
||||||
|
t708 = t706 nand t707;
|
||||||
|
t709 = t181 and t686;
|
||||||
|
t710 = t128 nand t709;
|
||||||
|
t711 = t128 nand t710;
|
||||||
|
t712 = t709 nand t710;
|
||||||
|
t713 = t711 nand t712;
|
||||||
|
t714 = t708 biimp t713;
|
||||||
|
t715 = t122 and t680;
|
||||||
|
t716 = t69 nand t715;
|
||||||
|
t717 = t69 nand t716;
|
||||||
|
t718 = t715 nand t716;
|
||||||
|
t719 = t717 nand t718;
|
||||||
|
t720 = t122 and t686;
|
||||||
|
t721 = t69 nand t720;
|
||||||
|
t722 = t69 nand t721;
|
||||||
|
t723 = t720 nand t721;
|
||||||
|
t724 = t722 nand t723;
|
||||||
|
t725 = t719 biimp t724;
|
||||||
|
t726 = t347 and t321;
|
||||||
|
t727 = t726 and t575;
|
||||||
|
t728 = t209 and t727;
|
||||||
|
t729 = t187 nand t728;
|
||||||
|
t730 = t187 nand t729;
|
||||||
|
t731 = t728 nand t729;
|
||||||
|
t732 = t730 nand t731;
|
||||||
|
t733 = t726 and t590;
|
||||||
|
t734 = t209 and t733;
|
||||||
|
t735 = t187 nand t734;
|
||||||
|
t736 = t187 nand t735;
|
||||||
|
t737 = t734 nand t735;
|
||||||
|
t738 = t736 nand t737;
|
||||||
|
t739 = t732 biimp t738;
|
||||||
|
t740 = t237 and t727;
|
||||||
|
t741 = t215 nand t740;
|
||||||
|
t742 = t215 nand t741;
|
||||||
|
t743 = t740 nand t741;
|
||||||
|
t744 = t742 nand t743;
|
||||||
|
t745 = t237 and t733;
|
||||||
|
t746 = t215 nand t745;
|
||||||
|
t747 = t215 nand t746;
|
||||||
|
t748 = t745 nand t746;
|
||||||
|
t749 = t747 nand t748;
|
||||||
|
t750 = t744 biimp t749;
|
||||||
|
t406 = t347 and t362;
|
||||||
|
t407 = t146 nand t406;
|
||||||
|
t408 = t146 nand t407;
|
||||||
|
t409 = t406 nand t407;
|
||||||
|
t410 = t408 nand t409;
|
||||||
|
t411 = t347 and t377;
|
||||||
|
t412 = t146 nand t411;
|
||||||
|
t413 = t146 nand t412;
|
||||||
|
t414 = t411 nand t412;
|
||||||
|
t415 = t413 nand t414;
|
||||||
|
t416 = t410 biimp t415;
|
||||||
|
t751 = t181 and t727;
|
||||||
|
t752 = t129 nand t751;
|
||||||
|
t753 = t129 nand t752;
|
||||||
|
t754 = t751 nand t752;
|
||||||
|
t755 = t753 nand t754;
|
||||||
|
t756 = t181 and t733;
|
||||||
|
t757 = t129 nand t756;
|
||||||
|
t758 = t129 nand t757;
|
||||||
|
t759 = t756 nand t757;
|
||||||
|
t760 = t758 nand t759;
|
||||||
|
t761 = t755 biimp t760;
|
||||||
|
t762 = t122 and t727;
|
||||||
|
t763 = t70 nand t762;
|
||||||
|
t764 = t70 nand t763;
|
||||||
|
t765 = t762 nand t763;
|
||||||
|
t766 = t764 nand t765;
|
||||||
|
t767 = t122 and t733;
|
||||||
|
t768 = t70 nand t767;
|
||||||
|
t769 = t70 nand t768;
|
||||||
|
t770 = t767 nand t768;
|
||||||
|
t771 = t769 nand t770;
|
||||||
|
t772 = t766 biimp t771;
|
||||||
|
t419 = t122 and t418;
|
||||||
|
t420 = t419 and t361;
|
||||||
|
t421 = t64 and t420;
|
||||||
|
t422 = t3 nand t421;
|
||||||
|
t423 = t3 nand t422;
|
||||||
|
t424 = t421 nand t422;
|
||||||
|
t425 = t423 nand t424;
|
||||||
|
t426 = t419 and t376;
|
||||||
|
t427 = t64 and t426;
|
||||||
|
t428 = t3 nand t427;
|
||||||
|
t429 = t3 nand t428;
|
||||||
|
t430 = t427 nand t428;
|
||||||
|
t431 = t429 nand t430;
|
||||||
|
t432 = t425 biimp t431;
|
||||||
|
t433 = t319 and t420;
|
||||||
|
t434 = t81 nand t433;
|
||||||
|
t435 = t81 nand t434;
|
||||||
|
t436 = t433 nand t434;
|
||||||
|
t437 = t435 nand t436;
|
||||||
|
t438 = t319 and t426;
|
||||||
|
t439 = t81 nand t438;
|
||||||
|
t440 = t81 nand t439;
|
||||||
|
t441 = t438 nand t439;
|
||||||
|
t442 = t440 nand t441;
|
||||||
|
t443 = t437 biimp t442;
|
||||||
|
t444 = t279 and t420;
|
||||||
|
t445 = t86 nand t444;
|
||||||
|
t446 = t86 nand t445;
|
||||||
|
t447 = t444 nand t445;
|
||||||
|
t448 = t446 nand t447;
|
||||||
|
t449 = t279 and t426;
|
||||||
|
t450 = t86 nand t449;
|
||||||
|
t451 = t86 nand t450;
|
||||||
|
t452 = t449 nand t450;
|
||||||
|
t453 = t451 nand t452;
|
||||||
|
t454 = t448 biimp t453;
|
||||||
|
t455 = t347 and t420;
|
||||||
|
t456 = t87 nand t455;
|
||||||
|
t457 = t87 nand t456;
|
||||||
|
t458 = t455 nand t456;
|
||||||
|
t459 = t457 nand t458;
|
||||||
|
t460 = t347 and t426;
|
||||||
|
t461 = t87 nand t460;
|
||||||
|
t462 = t87 nand t461;
|
||||||
|
t463 = t460 nand t461;
|
||||||
|
t464 = t462 nand t463;
|
||||||
|
t465 = t459 biimp t464;
|
||||||
|
t471 = t64 and t470;
|
||||||
|
t472 = t8 nand t471;
|
||||||
|
t473 = t8 nand t472;
|
||||||
|
t474 = t471 nand t472;
|
||||||
|
t475 = t473 nand t474;
|
||||||
|
t477 = t64 and t476;
|
||||||
|
t478 = t8 nand t477;
|
||||||
|
t479 = t8 nand t478;
|
||||||
|
t480 = t477 nand t478;
|
||||||
|
t481 = t479 nand t480;
|
||||||
|
t482 = t475 biimp t481;
|
||||||
|
t483 = t319 and t470;
|
||||||
|
t484 = t155 nand t483;
|
||||||
|
t485 = t155 nand t484;
|
||||||
|
t486 = t483 nand t484;
|
||||||
|
t487 = t485 nand t486;
|
||||||
|
t488 = t319 and t476;
|
||||||
|
t489 = t155 nand t488;
|
||||||
|
t490 = t155 nand t489;
|
||||||
|
t491 = t488 nand t489;
|
||||||
|
t492 = t490 nand t491;
|
||||||
|
t493 = t487 biimp t492;
|
||||||
|
|
||||||
|
tautology t383;
|
||||||
|
tautology t394;
|
||||||
|
tautology t504;
|
||||||
|
tautology t515;
|
||||||
|
tautology t530;
|
||||||
|
tautology t541;
|
||||||
|
tautology t552;
|
||||||
|
tautology t563;
|
||||||
|
tautology t597;
|
||||||
|
tautology t608;
|
||||||
|
tautology t619;
|
||||||
|
tautology t630;
|
||||||
|
tautology t405;
|
||||||
|
tautology t644;
|
||||||
|
tautology t655;
|
||||||
|
tautology t666;
|
||||||
|
tautology t677;
|
||||||
|
tautology t692;
|
||||||
|
tautology t703;
|
||||||
|
tautology t714;
|
||||||
|
tautology t725;
|
||||||
|
tautology t739;
|
||||||
|
tautology t750;
|
||||||
|
tautology t416;
|
||||||
|
tautology t761;
|
||||||
|
tautology t772;
|
||||||
|
tautology t432;
|
||||||
|
tautology t443;
|
||||||
|
tautology t454;
|
||||||
|
tautology t465;
|
||||||
|
tautology t482;
|
||||||
|
tautology t493;
|
||||||
531
buddy/examples/calculator/examples/c1908.cal
Normal file
531
buddy/examples/calculator/examples/c1908.cal
Normal file
|
|
@ -0,0 +1,531 @@
|
||||||
|
/* BDD Calculator data file */
|
||||||
|
|
||||||
|
initial 8000 10000;
|
||||||
|
|
||||||
|
inputs
|
||||||
|
_101 _104 _107 _110 _113 _116 _119 _122 _125 _128
|
||||||
|
_131 _134 _137 _140 _143 _146 _210 _214 _217 _221
|
||||||
|
_224 _227 _234 _237 _469 _472 _475 _478 _898 _900
|
||||||
|
_902 _952 _953 ;
|
||||||
|
|
||||||
|
actions
|
||||||
|
autoreorder 0 sift;
|
||||||
|
|
||||||
|
t2 = _952;
|
||||||
|
t3 = not t2;
|
||||||
|
t4 = _953;
|
||||||
|
t5 = not t4;
|
||||||
|
t6 = _146;
|
||||||
|
t7 = not t6;
|
||||||
|
t8 = _143;
|
||||||
|
t9 = not t8;
|
||||||
|
t10 = not t9;
|
||||||
|
t11 = t7 nand t10;
|
||||||
|
t12 = not t7;
|
||||||
|
t13 = t9 nand t12;
|
||||||
|
t14 = t11 nand t13;
|
||||||
|
t15 = _128;
|
||||||
|
t16 = not t15;
|
||||||
|
t17 = not t16;
|
||||||
|
t18 = t14 nand t17;
|
||||||
|
t19 = not t14;
|
||||||
|
t20 = t16 nand t19;
|
||||||
|
t21 = t18 nand t20;
|
||||||
|
t22 = _125;
|
||||||
|
t23 = not t22;
|
||||||
|
t24 = not t23;
|
||||||
|
t25 = t21 nand t24;
|
||||||
|
t26 = not t21;
|
||||||
|
t27 = t23 nand t26;
|
||||||
|
t28 = t25 nand t27;
|
||||||
|
t29 = _224;
|
||||||
|
t30 = t29 and t5;
|
||||||
|
t31 = not t30;
|
||||||
|
t32 = t28 nand t31;
|
||||||
|
t33 = not t28;
|
||||||
|
t34 = t30 nand t33;
|
||||||
|
t35 = t32 nand t34;
|
||||||
|
t36 = not t35;
|
||||||
|
t37 = _107;
|
||||||
|
t38 = not t37;
|
||||||
|
t39 = _104;
|
||||||
|
t40 = not t39;
|
||||||
|
t41 = not t40;
|
||||||
|
t42 = t38 nand t41;
|
||||||
|
t43 = not t38;
|
||||||
|
t44 = t40 nand t43;
|
||||||
|
t45 = t42 nand t44;
|
||||||
|
t46 = _101;
|
||||||
|
t47 = not t46;
|
||||||
|
t48 = not t47;
|
||||||
|
t49 = t45 nand t48;
|
||||||
|
t50 = not t45;
|
||||||
|
t51 = t47 nand t50;
|
||||||
|
t52 = t49 nand t51;
|
||||||
|
t53 = not t52;
|
||||||
|
t54 = _119;
|
||||||
|
t55 = not t54;
|
||||||
|
t56 = _116;
|
||||||
|
t57 = not t56;
|
||||||
|
t58 = not t57;
|
||||||
|
t59 = t55 nand t58;
|
||||||
|
t60 = not t55;
|
||||||
|
t61 = t57 nand t60;
|
||||||
|
t62 = t59 nand t61;
|
||||||
|
t63 = _113;
|
||||||
|
t64 = not t63;
|
||||||
|
t65 = not t64;
|
||||||
|
t66 = t62 nand t65;
|
||||||
|
t67 = not t62;
|
||||||
|
t68 = t64 nand t67;
|
||||||
|
t69 = t66 nand t68;
|
||||||
|
t70 = not t69;
|
||||||
|
t71 = t53 nand t70;
|
||||||
|
t72 = not t53;
|
||||||
|
t73 = t69 nand t72;
|
||||||
|
t74 = t71 nand t73;
|
||||||
|
t75 = _122;
|
||||||
|
t76 = not t75;
|
||||||
|
t77 = _110;
|
||||||
|
t78 = not t77;
|
||||||
|
t79 = not t78;
|
||||||
|
t80 = t76 nand t79;
|
||||||
|
t81 = not t76;
|
||||||
|
t82 = t78 nand t81;
|
||||||
|
t83 = t80 nand t82;
|
||||||
|
t84 = not t83;
|
||||||
|
t85 = not t84;
|
||||||
|
t86 = t74 nand t85;
|
||||||
|
t87 = not t74;
|
||||||
|
t88 = t84 nand t87;
|
||||||
|
t89 = t86 nand t88;
|
||||||
|
t90 = not t89;
|
||||||
|
t91 = t36 nand t90;
|
||||||
|
t92 = not t36;
|
||||||
|
t93 = t89 nand t92;
|
||||||
|
t94 = t91 nand t93;
|
||||||
|
t95 = not t94;
|
||||||
|
t96 = _902;
|
||||||
|
t97 = not t96;
|
||||||
|
t98 = t95 nand t97;
|
||||||
|
t99 = _210;
|
||||||
|
t100 = _237;
|
||||||
|
t101 = not t100;
|
||||||
|
t102 = t101 nand t97;
|
||||||
|
t103 = t99 nand t102;
|
||||||
|
t104 = not t103;
|
||||||
|
t105 = t98 nand t104;
|
||||||
|
t106 = not t98;
|
||||||
|
t107 = t103 nand t106;
|
||||||
|
t108 = t105 nand t107;
|
||||||
|
t109 = not t108;
|
||||||
|
t110 = _140;
|
||||||
|
t111 = not t110;
|
||||||
|
t112 = not t111;
|
||||||
|
t113 = t78 nand t112;
|
||||||
|
t114 = t111 nand t79;
|
||||||
|
t115 = t113 nand t114;
|
||||||
|
t116 = _227;
|
||||||
|
t117 = t116 and t5;
|
||||||
|
t118 = not t117;
|
||||||
|
t119 = t115 nand t118;
|
||||||
|
t120 = not t115;
|
||||||
|
t121 = t117 nand t120;
|
||||||
|
t122 = t119 nand t121;
|
||||||
|
t123 = not t26;
|
||||||
|
t124 = t52 nand t123;
|
||||||
|
t125 = t26 nand t53;
|
||||||
|
t126 = t124 nand t125;
|
||||||
|
t127 = _137;
|
||||||
|
t128 = not t127;
|
||||||
|
t129 = _134;
|
||||||
|
t130 = not t129;
|
||||||
|
t131 = not t130;
|
||||||
|
t132 = t128 nand t131;
|
||||||
|
t133 = not t128;
|
||||||
|
t134 = t130 nand t133;
|
||||||
|
t135 = t132 nand t134;
|
||||||
|
t136 = _131;
|
||||||
|
t137 = not t136;
|
||||||
|
t138 = not t137;
|
||||||
|
t139 = t135 nand t138;
|
||||||
|
t140 = not t135;
|
||||||
|
t141 = t137 nand t140;
|
||||||
|
t142 = t139 nand t141;
|
||||||
|
t143 = not t142;
|
||||||
|
t144 = not t143;
|
||||||
|
t145 = t126 nand t144;
|
||||||
|
t146 = not t126;
|
||||||
|
t147 = t143 nand t146;
|
||||||
|
t148 = t145 nand t147;
|
||||||
|
t149 = not t148;
|
||||||
|
t150 = not t149;
|
||||||
|
t151 = t122 nand t150;
|
||||||
|
t152 = not t122;
|
||||||
|
t153 = t149 nand t152;
|
||||||
|
t154 = t151 nand t153;
|
||||||
|
t155 = t154 nand t97;
|
||||||
|
t156 = _469;
|
||||||
|
t157 = not t156;
|
||||||
|
t158 = not t157;
|
||||||
|
t159 = t155 nand t158;
|
||||||
|
t160 = not t155;
|
||||||
|
t161 = t157 nand t160;
|
||||||
|
t162 = t159 nand t161;
|
||||||
|
t163 = not t162;
|
||||||
|
t164 = _214;
|
||||||
|
t165 = t164 nand t102;
|
||||||
|
t166 = t99 and t101;
|
||||||
|
t167 = t166 and t5;
|
||||||
|
t168 = not t167;
|
||||||
|
t169 = t47 nand t168;
|
||||||
|
t170 = t167 nand t48;
|
||||||
|
t171 = t169 nand t170;
|
||||||
|
t172 = not t171;
|
||||||
|
t173 = t143 nand t26;
|
||||||
|
t174 = t21 nand t144;
|
||||||
|
t175 = t173 nand t174;
|
||||||
|
t176 = not t70;
|
||||||
|
t177 = t175 nand t176;
|
||||||
|
t178 = not t175;
|
||||||
|
t179 = t70 nand t178;
|
||||||
|
t180 = t177 nand t179;
|
||||||
|
t181 = not t180;
|
||||||
|
t182 = not t181;
|
||||||
|
t183 = t172 nand t182;
|
||||||
|
t184 = not t172;
|
||||||
|
t185 = t181 nand t184;
|
||||||
|
t186 = t183 nand t185;
|
||||||
|
t187 = t186 nand t97;
|
||||||
|
t188 = _472;
|
||||||
|
t189 = not t188;
|
||||||
|
t190 = not t189;
|
||||||
|
t191 = t187 nand t190;
|
||||||
|
t192 = not t187;
|
||||||
|
t193 = t189 nand t192;
|
||||||
|
t194 = t191 nand t193;
|
||||||
|
t195 = not t194;
|
||||||
|
t196 = t23 nand t112;
|
||||||
|
t197 = t111 nand t24;
|
||||||
|
t198 = t196 nand t197;
|
||||||
|
t199 = t198 nand t12;
|
||||||
|
t200 = not t198;
|
||||||
|
t201 = t7 nand t200;
|
||||||
|
t202 = t199 nand t201;
|
||||||
|
t203 = t164 and t101;
|
||||||
|
t204 = t203 and t5;
|
||||||
|
t205 = not t204;
|
||||||
|
t206 = t9 nand t205;
|
||||||
|
t207 = t204 nand t10;
|
||||||
|
t208 = t206 nand t207;
|
||||||
|
t209 = t208 nand t138;
|
||||||
|
t210 = not t208;
|
||||||
|
t211 = t137 nand t210;
|
||||||
|
t212 = t209 nand t211;
|
||||||
|
t213 = not t212;
|
||||||
|
t214 = t202 nand t213;
|
||||||
|
t215 = not t202;
|
||||||
|
t216 = t212 nand t215;
|
||||||
|
t217 = t214 nand t216;
|
||||||
|
t218 = t76 nand t65;
|
||||||
|
t219 = t64 nand t81;
|
||||||
|
t220 = t218 nand t219;
|
||||||
|
t221 = t220 nand t41;
|
||||||
|
t222 = not t220;
|
||||||
|
t223 = t40 nand t222;
|
||||||
|
t224 = t221 nand t223;
|
||||||
|
t225 = not t224;
|
||||||
|
t226 = t217 nand t225;
|
||||||
|
t227 = not t217;
|
||||||
|
t228 = t224 nand t227;
|
||||||
|
t229 = t226 nand t228;
|
||||||
|
t230 = t229 nand t97;
|
||||||
|
t231 = _475;
|
||||||
|
t232 = not t231;
|
||||||
|
t233 = not t232;
|
||||||
|
t234 = t230 nand t233;
|
||||||
|
t235 = not t230;
|
||||||
|
t236 = t232 nand t235;
|
||||||
|
t237 = t234 nand t236;
|
||||||
|
t238 = not t237;
|
||||||
|
t239 = t16 nand t60;
|
||||||
|
t240 = t55 nand t17;
|
||||||
|
t241 = t239 nand t240;
|
||||||
|
t242 = t241 nand t79;
|
||||||
|
t243 = not t241;
|
||||||
|
t244 = t78 nand t243;
|
||||||
|
t245 = t242 nand t244;
|
||||||
|
t246 = not t245;
|
||||||
|
t247 = not t246;
|
||||||
|
t248 = t215 nand t247;
|
||||||
|
t249 = not t215;
|
||||||
|
t250 = t246 nand t249;
|
||||||
|
t251 = t248 nand t250;
|
||||||
|
t252 = _221;
|
||||||
|
t253 = _234;
|
||||||
|
t254 = t252 and t253;
|
||||||
|
t255 = t254 and t5;
|
||||||
|
t256 = t255 nand t133;
|
||||||
|
t257 = not t255;
|
||||||
|
t258 = t128 nand t257;
|
||||||
|
t259 = t256 nand t258;
|
||||||
|
t260 = not t259;
|
||||||
|
t261 = not t260;
|
||||||
|
t262 = t251 nand t261;
|
||||||
|
t263 = not t251;
|
||||||
|
t264 = t260 nand t263;
|
||||||
|
t265 = t262 nand t264;
|
||||||
|
t266 = t265 nand t97;
|
||||||
|
t267 = _217;
|
||||||
|
t268 = t253 nand t97;
|
||||||
|
t269 = t267 nand t268;
|
||||||
|
t270 = not t269;
|
||||||
|
t271 = t266 nand t270;
|
||||||
|
t272 = not t266;
|
||||||
|
t273 = t269 nand t272;
|
||||||
|
t274 = t271 nand t273;
|
||||||
|
t275 = not t274;
|
||||||
|
t276 = t76 nand t58;
|
||||||
|
t277 = t57 nand t81;
|
||||||
|
t278 = t276 nand t277;
|
||||||
|
t279 = t278 nand t43;
|
||||||
|
t280 = not t278;
|
||||||
|
t281 = t38 nand t280;
|
||||||
|
t282 = t279 nand t281;
|
||||||
|
t283 = t9 nand t17;
|
||||||
|
t284 = t16 nand t10;
|
||||||
|
t285 = t283 nand t284;
|
||||||
|
t286 = t285 nand t131;
|
||||||
|
t287 = not t285;
|
||||||
|
t288 = t130 nand t287;
|
||||||
|
t289 = t286 nand t288;
|
||||||
|
t290 = not t289;
|
||||||
|
t291 = t282 nand t290;
|
||||||
|
t292 = not t282;
|
||||||
|
t293 = t289 nand t292;
|
||||||
|
t294 = t291 nand t293;
|
||||||
|
t295 = t267 and t253;
|
||||||
|
t296 = t295 and t5;
|
||||||
|
t297 = not t296;
|
||||||
|
t298 = t294 nand t297;
|
||||||
|
t299 = not t294;
|
||||||
|
t300 = t296 nand t299;
|
||||||
|
t301 = t298 nand t300;
|
||||||
|
t302 = t301 nand t97;
|
||||||
|
t303 = _478;
|
||||||
|
t304 = not t303;
|
||||||
|
t305 = not t304;
|
||||||
|
t306 = t302 nand t305;
|
||||||
|
t307 = not t302;
|
||||||
|
t308 = t304 nand t307;
|
||||||
|
t309 = t306 nand t308;
|
||||||
|
t310 = not t309;
|
||||||
|
t311 = t275 and t310;
|
||||||
|
t312 = t238 and t311;
|
||||||
|
t313 = t195 and t312;
|
||||||
|
t314 = t165 and t313;
|
||||||
|
t315 = t163 and t314;
|
||||||
|
t316 = t109 and t315;
|
||||||
|
t317 = t252 nand t268;
|
||||||
|
t318 = t316 nand t317;
|
||||||
|
t319 = t5 and t318;
|
||||||
|
t320 = t3 and t319;
|
||||||
|
t321 = t320 and t3;
|
||||||
|
t322 = t2 and t319;
|
||||||
|
t323 = t310 and t238;
|
||||||
|
t324 = t274 and t194;
|
||||||
|
t325 = t165 and t108;
|
||||||
|
t326 = t317 and t163;
|
||||||
|
t327 = t325 and t326;
|
||||||
|
t328 = t324 and t327;
|
||||||
|
t329 = t323 and t328;
|
||||||
|
t330 = _898;
|
||||||
|
t331 = not t330;
|
||||||
|
t332 = t331 and t96;
|
||||||
|
t333 = t4 and t332;
|
||||||
|
t334 = t253 nand t100;
|
||||||
|
t335 = t333 nand t334;
|
||||||
|
t336 = t2 and t5;
|
||||||
|
t337 = t336 nand t334;
|
||||||
|
t338 = t335 nand t337;
|
||||||
|
t339 = t329 nand t338;
|
||||||
|
t340 = t309 and t238;
|
||||||
|
t341 = t275 and t194;
|
||||||
|
t342 = t341 and t327;
|
||||||
|
t343 = t340 and t342;
|
||||||
|
t344 = t343 nand t338;
|
||||||
|
t345 = t310 and t237;
|
||||||
|
t346 = t345 and t342;
|
||||||
|
t347 = t346 nand t338;
|
||||||
|
t348 = t274 and t195;
|
||||||
|
t349 = t317 and t162;
|
||||||
|
t350 = t325 and t349;
|
||||||
|
t351 = t348 and t350;
|
||||||
|
t352 = t323 and t351;
|
||||||
|
t353 = t352 nand t338;
|
||||||
|
t354 = t275 and t195;
|
||||||
|
t355 = t354 and t350;
|
||||||
|
t356 = t340 and t355;
|
||||||
|
t357 = t356 nand t338;
|
||||||
|
t358 = t341 and t350;
|
||||||
|
t359 = t323 and t358;
|
||||||
|
t360 = t359 nand t338;
|
||||||
|
t361 = t345 and t355;
|
||||||
|
t362 = t361 nand t338;
|
||||||
|
t363 = t360 and t362;
|
||||||
|
t364 = t357 and t363;
|
||||||
|
t365 = t353 and t364;
|
||||||
|
t366 = t347 and t365;
|
||||||
|
t367 = t344 and t366;
|
||||||
|
t368 = t339 and t367;
|
||||||
|
t369 = t309 and t237;
|
||||||
|
t370 = t354 and t327;
|
||||||
|
t371 = t369 and t370;
|
||||||
|
t372 = t371 nand t338;
|
||||||
|
t373 = t368 and t372;
|
||||||
|
t374 = t369 and t358;
|
||||||
|
t375 = _900;
|
||||||
|
t376 = not t375;
|
||||||
|
t377 = t376 and t96;
|
||||||
|
t378 = t4 and t377;
|
||||||
|
t379 = t378 nand t334;
|
||||||
|
t380 = t379 nand t337;
|
||||||
|
t381 = t374 nand t380;
|
||||||
|
t382 = t165 and t109;
|
||||||
|
t383 = t382 and t349;
|
||||||
|
t384 = t348 and t383;
|
||||||
|
t385 = t345 and t384;
|
||||||
|
t386 = t385 nand t380;
|
||||||
|
t387 = t324 and t383;
|
||||||
|
t388 = t323 and t387;
|
||||||
|
t389 = t388 nand t380;
|
||||||
|
t390 = t341 and t383;
|
||||||
|
t391 = t340 and t390;
|
||||||
|
t392 = t391 nand t380;
|
||||||
|
t393 = t345 and t390;
|
||||||
|
t394 = t393 nand t380;
|
||||||
|
t395 = t348 and t327;
|
||||||
|
t396 = t345 and t395;
|
||||||
|
t397 = t396 nand t380;
|
||||||
|
t398 = t324 and t350;
|
||||||
|
t399 = t340 and t398;
|
||||||
|
t400 = t399 nand t380;
|
||||||
|
t401 = t397 and t400;
|
||||||
|
t402 = t394 and t401;
|
||||||
|
t403 = t392 and t402;
|
||||||
|
t404 = t389 and t403;
|
||||||
|
t405 = t386 and t404;
|
||||||
|
t406 = t381 and t405;
|
||||||
|
t407 = t345 and t398;
|
||||||
|
t408 = t407 nand t380;
|
||||||
|
t409 = t406 and t408;
|
||||||
|
t410 = t373 and t409;
|
||||||
|
t411 = not t317;
|
||||||
|
t412 = t411 and t163;
|
||||||
|
t413 = t382 and t412;
|
||||||
|
t414 = t354 and t413;
|
||||||
|
t415 = t323 and t414;
|
||||||
|
t416 = t336 and t334;
|
||||||
|
t417 = t415 nand t416;
|
||||||
|
t418 = t382 and t326;
|
||||||
|
t419 = t348 and t418;
|
||||||
|
t420 = t323 and t419;
|
||||||
|
t421 = t420 nand t416;
|
||||||
|
t422 = t354 and t418;
|
||||||
|
t423 = t340 and t422;
|
||||||
|
t424 = t423 nand t416;
|
||||||
|
t425 = t345 and t422;
|
||||||
|
t426 = t425 nand t416;
|
||||||
|
t427 = t341 and t418;
|
||||||
|
t428 = t323 and t427;
|
||||||
|
t429 = t428 nand t416;
|
||||||
|
t430 = t323 and t370;
|
||||||
|
t431 = t430 nand t416;
|
||||||
|
t432 = t354 and t383;
|
||||||
|
t433 = t323 and t432;
|
||||||
|
t434 = t433 nand t416;
|
||||||
|
t435 = t431 and t434;
|
||||||
|
t436 = t429 and t435;
|
||||||
|
t437 = t426 and t436;
|
||||||
|
t438 = t424 and t437;
|
||||||
|
t439 = t421 and t438;
|
||||||
|
t440 = t417 and t439;
|
||||||
|
t441 = not t165;
|
||||||
|
t442 = t441 and t109;
|
||||||
|
t443 = t442 and t326;
|
||||||
|
t444 = t354 and t443;
|
||||||
|
t445 = t323 and t444;
|
||||||
|
t446 = t445 nand t416;
|
||||||
|
t447 = t440 and t446;
|
||||||
|
t448 = t410 and t447;
|
||||||
|
t449 = t322 and t448;
|
||||||
|
t450 = t321 nor t449;
|
||||||
|
t451 = t319 and t3;
|
||||||
|
t452 = t382 and t163;
|
||||||
|
t453 = t354 and t452;
|
||||||
|
t454 = t323 and t453;
|
||||||
|
t455 = t454 nand t334;
|
||||||
|
t456 = t420 nand t334;
|
||||||
|
t457 = t423 nand t334;
|
||||||
|
t458 = t425 nand t334;
|
||||||
|
t459 = t428 nand t334;
|
||||||
|
t460 = t430 nand t334;
|
||||||
|
t461 = t433 nand t334;
|
||||||
|
t462 = t460 and t461;
|
||||||
|
t463 = t459 and t462;
|
||||||
|
t464 = t458 and t463;
|
||||||
|
t465 = t457 and t464;
|
||||||
|
t466 = t456 and t465;
|
||||||
|
t467 = t455 and t466;
|
||||||
|
t468 = t109 and t326;
|
||||||
|
t469 = t354 and t468;
|
||||||
|
t470 = t323 and t469;
|
||||||
|
t471 = t470 nand t334;
|
||||||
|
t472 = t467 and t471;
|
||||||
|
t473 = t410 and t472;
|
||||||
|
t474 = t319 and t473;
|
||||||
|
t475 = t451 nor t474;
|
||||||
|
t476 = t450 biimp t475;
|
||||||
|
t477 = t35 nand t90;
|
||||||
|
t478 = t89 nand t36;
|
||||||
|
t479 = t477 nand t478;
|
||||||
|
t480 = t99 and t102;
|
||||||
|
t481 = t480 and t96;
|
||||||
|
t482 = t373 nand t409;
|
||||||
|
t483 = t481 and t482;
|
||||||
|
t484 = not t483;
|
||||||
|
t485 = t479 nand t484;
|
||||||
|
t486 = not t479;
|
||||||
|
t487 = t483 nand t486;
|
||||||
|
t488 = t485 nand t487;
|
||||||
|
t489 = t3 nand t4;
|
||||||
|
t490 = t488 and t489;
|
||||||
|
t491 = t99 and t96;
|
||||||
|
t492 = t491 and t482;
|
||||||
|
t493 = not t492;
|
||||||
|
t494 = t479 nand t493;
|
||||||
|
t495 = t492 nand t486;
|
||||||
|
t496 = t494 nand t495;
|
||||||
|
t497 = t496 and t489;
|
||||||
|
t498 = t490 biimp t497;
|
||||||
|
t499 = t267 and t268;
|
||||||
|
t500 = t499 and t96;
|
||||||
|
t501 = t500 and t482;
|
||||||
|
t502 = not t501;
|
||||||
|
t503 = t265 nand t502;
|
||||||
|
t504 = not t265;
|
||||||
|
t505 = t501 nand t504;
|
||||||
|
t506 = t503 nand t505;
|
||||||
|
t507 = t489 and t506;
|
||||||
|
t508 = t267 and t96;
|
||||||
|
t509 = t508 and t482;
|
||||||
|
t510 = not t509;
|
||||||
|
t511 = t265 nand t510;
|
||||||
|
t512 = t509 nand t504;
|
||||||
|
t513 = t511 nand t512;
|
||||||
|
t514 = t489 and t513;
|
||||||
|
t515 = t507 biimp t514;
|
||||||
|
|
||||||
|
tautology t476;
|
||||||
|
tautology t498;
|
||||||
|
tautology t515;
|
||||||
1237
buddy/examples/calculator/examples/c2670.cal
Normal file
1237
buddy/examples/calculator/examples/c2670.cal
Normal file
File diff suppressed because it is too large
Load diff
2007
buddy/examples/calculator/examples/c3540.cal
Normal file
2007
buddy/examples/calculator/examples/c3540.cal
Normal file
File diff suppressed because it is too large
Load diff
260
buddy/examples/calculator/examples/c432.cal
Normal file
260
buddy/examples/calculator/examples/c432.cal
Normal file
|
|
@ -0,0 +1,260 @@
|
||||||
|
/* BDD Calculator data file */
|
||||||
|
|
||||||
|
initial 10000 10000;
|
||||||
|
|
||||||
|
inputs
|
||||||
|
_1gat _4gat _8gat _11gat _14gat _17gat _21gat _24gat _27gat _30gat
|
||||||
|
_34gat _37gat _40gat _43gat _47gat _50gat _53gat _56gat _60gat _63gat
|
||||||
|
_66gat _69gat _73gat _76gat _79gat _82gat _86gat _89gat _92gat _95gat
|
||||||
|
_99gat _102gat _105gat _108gat _112gat _115gat ;
|
||||||
|
|
||||||
|
actions
|
||||||
|
autoreorder 0 win2ite;
|
||||||
|
|
||||||
|
t2 = _8gat;
|
||||||
|
t3 = _89gat;
|
||||||
|
t4 = not t3;
|
||||||
|
t5 = _95gat;
|
||||||
|
t6 = t4 nand t5;
|
||||||
|
t7 = _76gat;
|
||||||
|
t8 = not t7;
|
||||||
|
t9 = _82gat;
|
||||||
|
t10 = t8 nand t9;
|
||||||
|
t11 = _63gat;
|
||||||
|
t12 = not t11;
|
||||||
|
t13 = _69gat;
|
||||||
|
t14 = t12 nand t13;
|
||||||
|
t15 = _50gat;
|
||||||
|
t16 = not t15;
|
||||||
|
t17 = _56gat;
|
||||||
|
t18 = t16 nand t17;
|
||||||
|
t19 = _37gat;
|
||||||
|
t20 = not t19;
|
||||||
|
t21 = _43gat;
|
||||||
|
t22 = t20 nand t21;
|
||||||
|
t23 = _24gat;
|
||||||
|
t24 = not t23;
|
||||||
|
t25 = _30gat;
|
||||||
|
t26 = t24 nand t25;
|
||||||
|
t27 = _1gat;
|
||||||
|
t28 = not t27;
|
||||||
|
t29 = _4gat;
|
||||||
|
t30 = t28 nand t29;
|
||||||
|
t31 = _11gat;
|
||||||
|
t32 = not t31;
|
||||||
|
t33 = _17gat;
|
||||||
|
t34 = t32 nand t33;
|
||||||
|
t35 = t30 and t34;
|
||||||
|
t36 = t26 and t35;
|
||||||
|
t37 = t22 and t36;
|
||||||
|
t38 = t18 and t37;
|
||||||
|
t39 = t14 and t38;
|
||||||
|
t40 = t10 and t39;
|
||||||
|
t41 = t6 and t40;
|
||||||
|
t42 = _102gat;
|
||||||
|
t43 = not t42;
|
||||||
|
t44 = _108gat;
|
||||||
|
t45 = t43 nand t44;
|
||||||
|
t46 = t41 and t45;
|
||||||
|
t47 = not t46;
|
||||||
|
t48 = t47 xor t6;
|
||||||
|
t49 = _99gat;
|
||||||
|
t50 = not t5;
|
||||||
|
t51 = t49 nor t50;
|
||||||
|
t52 = t48 nand t51;
|
||||||
|
t53 = t47 xor t10;
|
||||||
|
t54 = _86gat;
|
||||||
|
t55 = not t9;
|
||||||
|
t56 = t54 nor t55;
|
||||||
|
t57 = t53 nand t56;
|
||||||
|
t58 = t47 xor t14;
|
||||||
|
t59 = _73gat;
|
||||||
|
t60 = not t13;
|
||||||
|
t61 = t59 nor t60;
|
||||||
|
t62 = t58 nand t61;
|
||||||
|
t63 = t47 xor t18;
|
||||||
|
t64 = _60gat;
|
||||||
|
t65 = not t17;
|
||||||
|
t66 = t64 nor t65;
|
||||||
|
t67 = t63 nand t66;
|
||||||
|
t68 = t47 xor t22;
|
||||||
|
t69 = _47gat;
|
||||||
|
t70 = not t21;
|
||||||
|
t71 = t69 nor t70;
|
||||||
|
t72 = t68 nand t71;
|
||||||
|
t73 = t47 xor t26;
|
||||||
|
t74 = _34gat;
|
||||||
|
t75 = not t25;
|
||||||
|
t76 = t74 nor t75;
|
||||||
|
t77 = t73 nand t76;
|
||||||
|
t78 = t47 xor t30;
|
||||||
|
t79 = not t29;
|
||||||
|
t80 = t2 nor t79;
|
||||||
|
t81 = t78 nand t80;
|
||||||
|
t82 = t47 xor t34;
|
||||||
|
t83 = _21gat;
|
||||||
|
t84 = not t33;
|
||||||
|
t85 = t83 nor t84;
|
||||||
|
t86 = t82 nand t85;
|
||||||
|
t87 = t81 and t86;
|
||||||
|
t88 = t77 and t87;
|
||||||
|
t89 = t72 and t88;
|
||||||
|
t90 = t67 and t89;
|
||||||
|
t91 = t62 and t90;
|
||||||
|
t92 = t57 and t91;
|
||||||
|
t93 = t52 and t92;
|
||||||
|
t94 = t47 xor t45;
|
||||||
|
t95 = _112gat;
|
||||||
|
t96 = not t44;
|
||||||
|
t97 = t95 nor t96;
|
||||||
|
t98 = t94 nand t97;
|
||||||
|
t99 = t93 and t98;
|
||||||
|
t100 = not t99;
|
||||||
|
t101 = t2 nand t100;
|
||||||
|
t102 = t27 nand t47;
|
||||||
|
t103 = t29 and t102;
|
||||||
|
t104 = t101 and t103;
|
||||||
|
t105 = _14gat;
|
||||||
|
t106 = t100 xor t52;
|
||||||
|
t107 = _105gat;
|
||||||
|
t108 = t107 nor t50;
|
||||||
|
t109 = t48 nand t108;
|
||||||
|
t110 = not t109;
|
||||||
|
t111 = t106 nand t110;
|
||||||
|
t112 = t100 xor t57;
|
||||||
|
t113 = _92gat;
|
||||||
|
t114 = t113 nor t55;
|
||||||
|
t115 = t53 nand t114;
|
||||||
|
t116 = not t115;
|
||||||
|
t117 = t112 nand t116;
|
||||||
|
t118 = t100 xor t62;
|
||||||
|
t119 = _79gat;
|
||||||
|
t120 = t119 nor t60;
|
||||||
|
t121 = t58 nand t120;
|
||||||
|
t122 = not t121;
|
||||||
|
t123 = t118 nand t122;
|
||||||
|
t124 = t100 xor t67;
|
||||||
|
t125 = _66gat;
|
||||||
|
t126 = t125 nor t65;
|
||||||
|
t127 = t63 nand t126;
|
||||||
|
t128 = not t127;
|
||||||
|
t129 = t124 nand t128;
|
||||||
|
t130 = t100 xor t72;
|
||||||
|
t131 = _53gat;
|
||||||
|
t132 = t131 nor t70;
|
||||||
|
t133 = t68 nand t132;
|
||||||
|
t134 = not t133;
|
||||||
|
t135 = t130 nand t134;
|
||||||
|
t136 = t100 xor t77;
|
||||||
|
t137 = _40gat;
|
||||||
|
t138 = t137 nor t75;
|
||||||
|
t139 = t73 nand t138;
|
||||||
|
t140 = not t139;
|
||||||
|
t141 = t136 nand t140;
|
||||||
|
t142 = t100 xor t81;
|
||||||
|
t143 = t105 nor t79;
|
||||||
|
t144 = t78 nand t143;
|
||||||
|
t145 = not t144;
|
||||||
|
t146 = t142 nand t145;
|
||||||
|
t147 = t100 xor t86;
|
||||||
|
t148 = _27gat;
|
||||||
|
t149 = t148 nor t84;
|
||||||
|
t150 = t82 nand t149;
|
||||||
|
t151 = not t150;
|
||||||
|
t152 = t147 nand t151;
|
||||||
|
t153 = t146 and t152;
|
||||||
|
t154 = t141 and t153;
|
||||||
|
t155 = t135 and t154;
|
||||||
|
t156 = t129 and t155;
|
||||||
|
t157 = t123 and t156;
|
||||||
|
t158 = t117 and t157;
|
||||||
|
t159 = t111 and t158;
|
||||||
|
t160 = t100 xor t98;
|
||||||
|
t161 = _115gat;
|
||||||
|
t162 = t161 nor t96;
|
||||||
|
t163 = t94 nand t162;
|
||||||
|
t164 = not t163;
|
||||||
|
t165 = t160 nand t164;
|
||||||
|
t166 = t159 and t165;
|
||||||
|
t167 = not t166;
|
||||||
|
t168 = t105 nand t167;
|
||||||
|
t169 = t104 nand t168;
|
||||||
|
t170 = not t169;
|
||||||
|
t171 = t167 nand t107;
|
||||||
|
t172 = t47 nand t3;
|
||||||
|
t173 = t100 nand t49;
|
||||||
|
t174 = t172 and t173;
|
||||||
|
t175 = t171 and t174;
|
||||||
|
t176 = t175 nand t5;
|
||||||
|
t177 = t167 nand t113;
|
||||||
|
t178 = t47 nand t7;
|
||||||
|
t179 = t100 nand t54;
|
||||||
|
t180 = t178 and t179;
|
||||||
|
t181 = t177 and t180;
|
||||||
|
t182 = t181 nand t9;
|
||||||
|
t183 = t167 nand t119;
|
||||||
|
t184 = t47 nand t11;
|
||||||
|
t185 = t100 nand t59;
|
||||||
|
t186 = t184 and t185;
|
||||||
|
t187 = t183 and t186;
|
||||||
|
t188 = t187 nand t13;
|
||||||
|
t189 = t167 nand t125;
|
||||||
|
t190 = t47 nand t15;
|
||||||
|
t191 = t100 nand t64;
|
||||||
|
t192 = t190 and t191;
|
||||||
|
t193 = t189 and t192;
|
||||||
|
t194 = t193 nand t17;
|
||||||
|
t195 = t167 nand t131;
|
||||||
|
t196 = t47 nand t19;
|
||||||
|
t197 = t100 nand t69;
|
||||||
|
t198 = t196 and t197;
|
||||||
|
t199 = t195 and t198;
|
||||||
|
t200 = t199 nand t21;
|
||||||
|
t201 = t167 nand t148;
|
||||||
|
t202 = t47 nand t31;
|
||||||
|
t203 = t100 nand t83;
|
||||||
|
t204 = t202 and t203;
|
||||||
|
t205 = t201 and t204;
|
||||||
|
t206 = t205 nand t33;
|
||||||
|
t207 = t167 nand t137;
|
||||||
|
t208 = t47 nand t23;
|
||||||
|
t209 = t100 nand t74;
|
||||||
|
t210 = t208 and t209;
|
||||||
|
t211 = t207 and t210;
|
||||||
|
t212 = t211 nand t25;
|
||||||
|
t213 = t206 and t212;
|
||||||
|
t214 = t200 and t213;
|
||||||
|
t215 = t194 and t214;
|
||||||
|
t216 = t188 and t215;
|
||||||
|
t217 = t182 and t216;
|
||||||
|
t218 = t176 and t217;
|
||||||
|
t219 = t167 nand t161;
|
||||||
|
t220 = t47 nand t42;
|
||||||
|
t221 = t100 nand t95;
|
||||||
|
t222 = t220 and t221;
|
||||||
|
t223 = t219 and t222;
|
||||||
|
t224 = t223 nand t44;
|
||||||
|
t225 = t218 and t224;
|
||||||
|
t226 = t170 nor t225;
|
||||||
|
t227 = t218 and t96;
|
||||||
|
t228 = t170 nor t227;
|
||||||
|
t229 = t226 biimp t228;
|
||||||
|
t230 = not t188;
|
||||||
|
t231 = t212 and t200;
|
||||||
|
t232 = t230 and t231;
|
||||||
|
t233 = t232 nand t194;
|
||||||
|
t234 = not t200;
|
||||||
|
t235 = t212 nand t234;
|
||||||
|
t236 = t206 and t235;
|
||||||
|
t237 = t233 and t236;
|
||||||
|
t238 = t182 and t231;
|
||||||
|
t239 = not t176;
|
||||||
|
t240 = t238 nand t239;
|
||||||
|
t241 = t237 nand t240;
|
||||||
|
t242 = t212 and t182;
|
||||||
|
t243 = t242 nand t239;
|
||||||
|
t244 = t237 nand t243;
|
||||||
|
t245 = t241 biimp t244;
|
||||||
|
|
||||||
|
tautology t229;
|
||||||
|
tautology t245;
|
||||||
409
buddy/examples/calculator/examples/c499.cal
Normal file
409
buddy/examples/calculator/examples/c499.cal
Normal file
|
|
@ -0,0 +1,409 @@
|
||||||
|
/* BDD Calculator data file */
|
||||||
|
|
||||||
|
initial 10000 10000;
|
||||||
|
|
||||||
|
inputs
|
||||||
|
id0 id1 id2 id3 id4 id5 id6 id7 id8 id9
|
||||||
|
id10 id11 id12 id13 id14 id15 id16 id17 id18 id19
|
||||||
|
id20 id21 id22 id23 id24 id25 id26 id27 id28 id29
|
||||||
|
id30 id31 ic0 ic1 ic2 ic3 ic4 ic5 ic6 ic7
|
||||||
|
r ;
|
||||||
|
|
||||||
|
actions
|
||||||
|
autoreorder 0 sift;
|
||||||
|
t2 = id0;
|
||||||
|
t3 = id4;
|
||||||
|
t4 = t2 xor t3;
|
||||||
|
t5 = id8;
|
||||||
|
t6 = id12;
|
||||||
|
t7 = t5 xor t6;
|
||||||
|
t8 = t4 xor t7;
|
||||||
|
t9 = ic0;
|
||||||
|
t10 = r;
|
||||||
|
t11 = t9 and t10;
|
||||||
|
t12 = id16;
|
||||||
|
t13 = id17;
|
||||||
|
t14 = t12 xor t13;
|
||||||
|
t15 = id18;
|
||||||
|
t16 = id19;
|
||||||
|
t17 = t15 xor t16;
|
||||||
|
t18 = t14 xor t17;
|
||||||
|
t19 = id20;
|
||||||
|
t20 = id21;
|
||||||
|
t21 = t19 xor t20;
|
||||||
|
t22 = id22;
|
||||||
|
t23 = id23;
|
||||||
|
t24 = t22 xor t23;
|
||||||
|
t25 = t21 xor t24;
|
||||||
|
t26 = t18 xor t25;
|
||||||
|
t27 = t11 xor t26;
|
||||||
|
t28 = t8 xor t27;
|
||||||
|
t29 = t16 xor t23;
|
||||||
|
t30 = id27;
|
||||||
|
t31 = id31;
|
||||||
|
t32 = t30 xor t31;
|
||||||
|
t33 = t29 xor t32;
|
||||||
|
t34 = ic7;
|
||||||
|
t35 = t34 and t10;
|
||||||
|
t36 = id5;
|
||||||
|
t37 = t3 xor t36;
|
||||||
|
t38 = id6;
|
||||||
|
t39 = id7;
|
||||||
|
t40 = t38 xor t39;
|
||||||
|
t41 = t37 xor t40;
|
||||||
|
t42 = id13;
|
||||||
|
t43 = t6 xor t42;
|
||||||
|
t44 = id14;
|
||||||
|
t45 = id15;
|
||||||
|
t46 = t44 xor t45;
|
||||||
|
t47 = t43 xor t46;
|
||||||
|
t48 = t41 xor t47;
|
||||||
|
t49 = t35 xor t48;
|
||||||
|
t50 = t33 xor t49;
|
||||||
|
t51 = not t50;
|
||||||
|
t52 = t15 xor t22;
|
||||||
|
t53 = id26;
|
||||||
|
t54 = id30;
|
||||||
|
t55 = t53 xor t54;
|
||||||
|
t56 = t52 xor t55;
|
||||||
|
t57 = ic6;
|
||||||
|
t58 = t57 and t10;
|
||||||
|
t59 = id1;
|
||||||
|
t60 = t2 xor t59;
|
||||||
|
t61 = id2;
|
||||||
|
t62 = id3;
|
||||||
|
t63 = t61 xor t62;
|
||||||
|
t64 = t60 xor t63;
|
||||||
|
t65 = id9;
|
||||||
|
t66 = t5 xor t65;
|
||||||
|
t67 = id10;
|
||||||
|
t68 = id11;
|
||||||
|
t69 = t67 xor t68;
|
||||||
|
t70 = t66 xor t69;
|
||||||
|
t71 = t64 xor t70;
|
||||||
|
t72 = t58 xor t71;
|
||||||
|
t73 = t56 xor t72;
|
||||||
|
t74 = t12 xor t19;
|
||||||
|
t75 = id24;
|
||||||
|
t76 = id28;
|
||||||
|
t77 = t75 xor t76;
|
||||||
|
t78 = t74 xor t77;
|
||||||
|
t79 = ic4;
|
||||||
|
t80 = t79 and t10;
|
||||||
|
t81 = t64 xor t41;
|
||||||
|
t82 = t80 xor t81;
|
||||||
|
t83 = t78 xor t82;
|
||||||
|
t84 = t13 xor t20;
|
||||||
|
t85 = id25;
|
||||||
|
t86 = id29;
|
||||||
|
t87 = t85 xor t86;
|
||||||
|
t88 = t84 xor t87;
|
||||||
|
t89 = ic5;
|
||||||
|
t90 = t89 and t10;
|
||||||
|
t91 = t70 xor t47;
|
||||||
|
t92 = t90 xor t91;
|
||||||
|
t93 = t88 xor t92;
|
||||||
|
t94 = not t93;
|
||||||
|
t95 = t83 and t94;
|
||||||
|
t96 = t73 and t95;
|
||||||
|
t97 = t51 and t96;
|
||||||
|
t98 = t61 xor t38;
|
||||||
|
t99 = t67 xor t44;
|
||||||
|
t100 = t98 xor t99;
|
||||||
|
t101 = ic2;
|
||||||
|
t102 = t101 and t10;
|
||||||
|
t103 = t75 xor t85;
|
||||||
|
t104 = t53 xor t30;
|
||||||
|
t105 = t103 xor t104;
|
||||||
|
t106 = t18 xor t105;
|
||||||
|
t107 = t102 xor t106;
|
||||||
|
t108 = t100 xor t107;
|
||||||
|
t109 = not t108;
|
||||||
|
t110 = not t28;
|
||||||
|
t111 = t59 xor t36;
|
||||||
|
t112 = t65 xor t42;
|
||||||
|
t113 = t111 xor t112;
|
||||||
|
t114 = ic1;
|
||||||
|
t115 = t114 and t10;
|
||||||
|
t116 = t76 xor t86;
|
||||||
|
t117 = t54 xor t31;
|
||||||
|
t118 = t116 xor t117;
|
||||||
|
t119 = t105 xor t118;
|
||||||
|
t120 = t115 xor t119;
|
||||||
|
t121 = t113 xor t120;
|
||||||
|
t122 = t110 and t121;
|
||||||
|
t123 = t109 and t122;
|
||||||
|
t124 = t62 xor t39;
|
||||||
|
t125 = t68 xor t45;
|
||||||
|
t126 = t124 xor t125;
|
||||||
|
t127 = ic3;
|
||||||
|
t128 = t127 and t10;
|
||||||
|
t129 = t25 xor t118;
|
||||||
|
t130 = t128 xor t129;
|
||||||
|
t131 = t126 xor t130;
|
||||||
|
t132 = not t131;
|
||||||
|
t133 = t123 and t132;
|
||||||
|
t134 = not t121;
|
||||||
|
t135 = t110 and t134;
|
||||||
|
t136 = t109 and t135;
|
||||||
|
t137 = t136 and t131;
|
||||||
|
t138 = t108 and t135;
|
||||||
|
t139 = t138 and t132;
|
||||||
|
t140 = t137 or t139;
|
||||||
|
t141 = t133 or t140;
|
||||||
|
t142 = t28 and t134;
|
||||||
|
t143 = t109 and t142;
|
||||||
|
t144 = t143 and t132;
|
||||||
|
t145 = t141 or t144;
|
||||||
|
t146 = t97 and t145;
|
||||||
|
t147 = t28 and t146;
|
||||||
|
t148 = t2 xor t147;
|
||||||
|
t149 = t110 and t109;
|
||||||
|
t150 = t149 and t132;
|
||||||
|
t151 = t135 and t109;
|
||||||
|
t152 = t135 and t132;
|
||||||
|
t153 = t151 or t152;
|
||||||
|
t154 = t150 or t153;
|
||||||
|
t155 = t134 and t109;
|
||||||
|
t156 = t155 and t132;
|
||||||
|
t157 = t154 or t156;
|
||||||
|
t158 = t97 and t157;
|
||||||
|
t159 = t28 and t158;
|
||||||
|
t160 = t2 xor t159;
|
||||||
|
t161 = t148 biimp t160;
|
||||||
|
t162 = t121 and t146;
|
||||||
|
t163 = t59 xor t162;
|
||||||
|
t164 = t121 and t158;
|
||||||
|
t165 = t59 xor t164;
|
||||||
|
t166 = t163 biimp t165;
|
||||||
|
t202 = not t83;
|
||||||
|
t203 = t202 and t93;
|
||||||
|
t204 = t73 and t203;
|
||||||
|
t205 = t51 and t204;
|
||||||
|
t206 = t205 and t145;
|
||||||
|
t218 = t108 and t206;
|
||||||
|
t219 = t67 xor t218;
|
||||||
|
t209 = t205 and t157;
|
||||||
|
t220 = t108 and t209;
|
||||||
|
t221 = t67 xor t220;
|
||||||
|
t222 = t219 biimp t221;
|
||||||
|
t223 = t131 and t206;
|
||||||
|
t224 = t68 xor t223;
|
||||||
|
t225 = t131 and t209;
|
||||||
|
t226 = t68 xor t225;
|
||||||
|
t227 = t224 biimp t226;
|
||||||
|
t177 = not t73;
|
||||||
|
t228 = t177 and t203;
|
||||||
|
t229 = t50 and t228;
|
||||||
|
t230 = t229 and t145;
|
||||||
|
t231 = t28 and t230;
|
||||||
|
t232 = t6 xor t231;
|
||||||
|
t233 = t229 and t157;
|
||||||
|
t234 = t28 and t233;
|
||||||
|
t235 = t6 xor t234;
|
||||||
|
t236 = t232 biimp t235;
|
||||||
|
t237 = t121 and t230;
|
||||||
|
t238 = t42 xor t237;
|
||||||
|
t239 = t121 and t233;
|
||||||
|
t240 = t42 xor t239;
|
||||||
|
t241 = t238 biimp t240;
|
||||||
|
t242 = t108 and t230;
|
||||||
|
t243 = t44 xor t242;
|
||||||
|
t244 = t108 and t233;
|
||||||
|
t245 = t44 xor t244;
|
||||||
|
t246 = t243 biimp t245;
|
||||||
|
t247 = t131 and t230;
|
||||||
|
t248 = t45 xor t247;
|
||||||
|
t249 = t131 and t233;
|
||||||
|
t250 = t45 xor t249;
|
||||||
|
t251 = t248 biimp t250;
|
||||||
|
t252 = t108 and t142;
|
||||||
|
t253 = t132 and t252;
|
||||||
|
t254 = t228 and t51;
|
||||||
|
t255 = t202 and t94;
|
||||||
|
t256 = t177 and t255;
|
||||||
|
t257 = t256 and t50;
|
||||||
|
t258 = t73 and t255;
|
||||||
|
t259 = t258 and t51;
|
||||||
|
t260 = t257 or t259;
|
||||||
|
t261 = t254 or t260;
|
||||||
|
t178 = t177 and t95;
|
||||||
|
t262 = t178 and t51;
|
||||||
|
t263 = t261 or t262;
|
||||||
|
t264 = t253 and t263;
|
||||||
|
t265 = t83 and t264;
|
||||||
|
t266 = t12 xor t265;
|
||||||
|
t267 = t202 and t177;
|
||||||
|
t268 = t267 and t51;
|
||||||
|
t269 = t255 and t177;
|
||||||
|
t270 = t255 and t51;
|
||||||
|
t271 = t269 or t270;
|
||||||
|
t272 = t268 or t271;
|
||||||
|
t273 = t94 and t177;
|
||||||
|
t274 = t273 and t51;
|
||||||
|
t275 = t272 or t274;
|
||||||
|
t276 = t253 and t275;
|
||||||
|
t277 = t83 and t276;
|
||||||
|
t278 = t12 xor t277;
|
||||||
|
t279 = t266 biimp t278;
|
||||||
|
t280 = t93 and t264;
|
||||||
|
t281 = t13 xor t280;
|
||||||
|
t282 = t93 and t276;
|
||||||
|
t283 = t13 xor t282;
|
||||||
|
t284 = t281 biimp t283;
|
||||||
|
t285 = t73 and t264;
|
||||||
|
t286 = t15 xor t285;
|
||||||
|
t287 = t73 and t276;
|
||||||
|
t288 = t15 xor t287;
|
||||||
|
t289 = t286 biimp t288;
|
||||||
|
t290 = t50 and t264;
|
||||||
|
t291 = t16 xor t290;
|
||||||
|
t292 = t50 and t276;
|
||||||
|
t293 = t16 xor t292;
|
||||||
|
t294 = t291 biimp t293;
|
||||||
|
t167 = t108 and t146;
|
||||||
|
t168 = t61 xor t167;
|
||||||
|
t169 = t108 and t158;
|
||||||
|
t170 = t61 xor t169;
|
||||||
|
t171 = t168 biimp t170;
|
||||||
|
t295 = t131 and t143;
|
||||||
|
t296 = t295 and t263;
|
||||||
|
t297 = t83 and t296;
|
||||||
|
t298 = t19 xor t297;
|
||||||
|
t299 = t295 and t275;
|
||||||
|
t300 = t83 and t299;
|
||||||
|
t301 = t19 xor t300;
|
||||||
|
t302 = t298 biimp t301;
|
||||||
|
t303 = t93 and t296;
|
||||||
|
t304 = t20 xor t303;
|
||||||
|
t305 = t93 and t299;
|
||||||
|
t306 = t20 xor t305;
|
||||||
|
t307 = t304 biimp t306;
|
||||||
|
t308 = t73 and t296;
|
||||||
|
t309 = t22 xor t308;
|
||||||
|
t310 = t73 and t299;
|
||||||
|
t311 = t22 xor t310;
|
||||||
|
t312 = t309 biimp t311;
|
||||||
|
t313 = t50 and t296;
|
||||||
|
t314 = t23 xor t313;
|
||||||
|
t315 = t50 and t299;
|
||||||
|
t316 = t23 xor t315;
|
||||||
|
t317 = t314 biimp t316;
|
||||||
|
t318 = t108 and t122;
|
||||||
|
t319 = t132 and t318;
|
||||||
|
t320 = t319 and t263;
|
||||||
|
t321 = t83 and t320;
|
||||||
|
t322 = t75 xor t321;
|
||||||
|
t323 = t319 and t275;
|
||||||
|
t324 = t83 and t323;
|
||||||
|
t325 = t75 xor t324;
|
||||||
|
t326 = t322 biimp t325;
|
||||||
|
t327 = t93 and t320;
|
||||||
|
t328 = t85 xor t327;
|
||||||
|
t329 = t93 and t323;
|
||||||
|
t330 = t85 xor t329;
|
||||||
|
t331 = t328 biimp t330;
|
||||||
|
t332 = t73 and t320;
|
||||||
|
t333 = t53 xor t332;
|
||||||
|
t334 = t73 and t323;
|
||||||
|
t335 = t53 xor t334;
|
||||||
|
t336 = t333 biimp t335;
|
||||||
|
t337 = t50 and t320;
|
||||||
|
t338 = t30 xor t337;
|
||||||
|
t339 = t50 and t323;
|
||||||
|
t340 = t30 xor t339;
|
||||||
|
t341 = t338 biimp t340;
|
||||||
|
t342 = t131 and t123;
|
||||||
|
t343 = t342 and t263;
|
||||||
|
t344 = t83 and t343;
|
||||||
|
t345 = t76 xor t344;
|
||||||
|
t346 = t342 and t275;
|
||||||
|
t347 = t83 and t346;
|
||||||
|
t348 = t76 xor t347;
|
||||||
|
t349 = t345 biimp t348;
|
||||||
|
t350 = t93 and t343;
|
||||||
|
t351 = t86 xor t350;
|
||||||
|
t352 = t93 and t346;
|
||||||
|
t353 = t86 xor t352;
|
||||||
|
t354 = t351 biimp t353;
|
||||||
|
t172 = t131 and t146;
|
||||||
|
t173 = t62 xor t172;
|
||||||
|
t174 = t131 and t158;
|
||||||
|
t175 = t62 xor t174;
|
||||||
|
t176 = t173 biimp t175;
|
||||||
|
t355 = t73 and t343;
|
||||||
|
t356 = t54 xor t355;
|
||||||
|
t357 = t73 and t346;
|
||||||
|
t358 = t54 xor t357;
|
||||||
|
t359 = t356 biimp t358;
|
||||||
|
t360 = t50 and t343;
|
||||||
|
t361 = t31 xor t360;
|
||||||
|
t362 = t50 and t346;
|
||||||
|
t363 = t31 xor t362;
|
||||||
|
t364 = t361 biimp t363;
|
||||||
|
t179 = t50 and t178;
|
||||||
|
t180 = t179 and t145;
|
||||||
|
t181 = t28 and t180;
|
||||||
|
t182 = t3 xor t181;
|
||||||
|
t183 = t179 and t157;
|
||||||
|
t184 = t28 and t183;
|
||||||
|
t185 = t3 xor t184;
|
||||||
|
t186 = t182 biimp t185;
|
||||||
|
t187 = t121 and t180;
|
||||||
|
t188 = t36 xor t187;
|
||||||
|
t189 = t121 and t183;
|
||||||
|
t190 = t36 xor t189;
|
||||||
|
t191 = t188 biimp t190;
|
||||||
|
t192 = t108 and t180;
|
||||||
|
t193 = t38 xor t192;
|
||||||
|
t194 = t108 and t183;
|
||||||
|
t195 = t38 xor t194;
|
||||||
|
t196 = t193 biimp t195;
|
||||||
|
t197 = t131 and t180;
|
||||||
|
t198 = t39 xor t197;
|
||||||
|
t199 = t131 and t183;
|
||||||
|
t200 = t39 xor t199;
|
||||||
|
t201 = t198 biimp t200;
|
||||||
|
t207 = t28 and t206;
|
||||||
|
t208 = t5 xor t207;
|
||||||
|
t210 = t28 and t209;
|
||||||
|
t211 = t5 xor t210;
|
||||||
|
t212 = t208 biimp t211;
|
||||||
|
t213 = t121 and t206;
|
||||||
|
t214 = t65 xor t213;
|
||||||
|
t215 = t121 and t209;
|
||||||
|
t216 = t65 xor t215;
|
||||||
|
t217 = t214 biimp t216;
|
||||||
|
|
||||||
|
tautology t161;
|
||||||
|
tautology t166;
|
||||||
|
tautology t222;
|
||||||
|
tautology t227;
|
||||||
|
tautology t236;
|
||||||
|
tautology t241;
|
||||||
|
tautology t246;
|
||||||
|
tautology t251;
|
||||||
|
tautology t279;
|
||||||
|
tautology t284;
|
||||||
|
tautology t289;
|
||||||
|
tautology t294;
|
||||||
|
tautology t171;
|
||||||
|
tautology t302;
|
||||||
|
tautology t307;
|
||||||
|
tautology t312;
|
||||||
|
tautology t317;
|
||||||
|
tautology t326;
|
||||||
|
tautology t331;
|
||||||
|
tautology t336;
|
||||||
|
tautology t341;
|
||||||
|
tautology t349;
|
||||||
|
tautology t354;
|
||||||
|
tautology t176;
|
||||||
|
tautology t359;
|
||||||
|
tautology t364;
|
||||||
|
tautology t186;
|
||||||
|
tautology t191;
|
||||||
|
tautology t196;
|
||||||
|
tautology t201;
|
||||||
|
tautology t212;
|
||||||
|
tautology t217;
|
||||||
3
buddy/examples/calculator/examples/readme
Normal file
3
buddy/examples/calculator/examples/readme
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
The files here are from the ISCAS85 benchmark set. They have been
|
||||||
|
adjustet such that the comparison of two combinatorial circuits
|
||||||
|
are joined into one file.
|
||||||
174
buddy/examples/calculator/hashtbl.cxx
Normal file
174
buddy/examples/calculator/hashtbl.cxx
Normal file
|
|
@ -0,0 +1,174 @@
|
||||||
|
/*************************************************************************
|
||||||
|
$Header: /Volumes/CVS/repository/spot/spot/buddy/examples/calculator/Attic/hashtbl.cxx,v 1.1 2003/05/05 10:57:55 aduret Exp $
|
||||||
|
FILE: hashtbl.cc
|
||||||
|
DESCR: Compiler hash table
|
||||||
|
AUTH: Jorn Lind
|
||||||
|
DATE: (C) september 1998
|
||||||
|
*************************************************************************/
|
||||||
|
#include "hashtbl.h"
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
/*======================================================================*/
|
||||||
|
|
||||||
|
hashTable::hashTable(void)
|
||||||
|
{
|
||||||
|
table = NULL;
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
hashTable::~hashTable(void)
|
||||||
|
{
|
||||||
|
delete[] table;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void hashTable::add(hashData &d)
|
||||||
|
{
|
||||||
|
if (freepos == -1)
|
||||||
|
reallocate_table();
|
||||||
|
|
||||||
|
unsigned int h = hashval(d.id);
|
||||||
|
int tmppos = table[freepos].next;
|
||||||
|
|
||||||
|
table[freepos].data = d;
|
||||||
|
table[freepos].next = table[h].first;
|
||||||
|
table[h].first = freepos;
|
||||||
|
freepos = tmppos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int hashTable::exists(const char *id)
|
||||||
|
{
|
||||||
|
if (size == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int p = table[hashval(id)].first;
|
||||||
|
|
||||||
|
while (p != -1)
|
||||||
|
{
|
||||||
|
if (strcmp(id, table[p].data.id) == 0)
|
||||||
|
return 1;
|
||||||
|
p = table[p].next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int hashTable::lookup(const char *id, hashData &d) const
|
||||||
|
{
|
||||||
|
if (size == 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
int p = table[hashval(id)].first;
|
||||||
|
|
||||||
|
while (p != -1)
|
||||||
|
{
|
||||||
|
if (strcmp(id, table[p].data.id) == 0)
|
||||||
|
{
|
||||||
|
d = table[p].data;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
p = table[p].next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int hashTable::remove(const char *id)
|
||||||
|
{
|
||||||
|
if (size == 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
int h = hashval(id);
|
||||||
|
int next = table[h].first;
|
||||||
|
int prev = -1;
|
||||||
|
|
||||||
|
while (next != -1)
|
||||||
|
{
|
||||||
|
if (strcmp(id, table[next].data.id) == 0)
|
||||||
|
{
|
||||||
|
if (prev == -1)
|
||||||
|
table[h].first = table[next].next;
|
||||||
|
else
|
||||||
|
table[prev].next = table[next].next;
|
||||||
|
|
||||||
|
table[next].next = freepos;
|
||||||
|
freepos = next;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
prev = next;
|
||||||
|
next = table[next].next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void hashTable::clear(void)
|
||||||
|
{
|
||||||
|
delete[] table;
|
||||||
|
freepos = -1;
|
||||||
|
size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void hashTable::reallocate_table(void)
|
||||||
|
{
|
||||||
|
hashElement *newtable;
|
||||||
|
int oldsize = size;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
if (size > 0)
|
||||||
|
{
|
||||||
|
size *= 2;
|
||||||
|
newtable = new hashElement[size];
|
||||||
|
for (int n=0 ; n<oldsize ; n++)
|
||||||
|
newtable[n] = table[n];
|
||||||
|
delete[] table;
|
||||||
|
table = newtable;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size = 10;
|
||||||
|
table = new hashElement[size];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (n=0 ; n<oldsize ; n++)
|
||||||
|
table[n].first = -1;
|
||||||
|
|
||||||
|
for (n=oldsize ; n<size ; n++)
|
||||||
|
{
|
||||||
|
table[n].first = -1;
|
||||||
|
table[n].next = n+1;
|
||||||
|
}
|
||||||
|
table[size-1].next = -1;
|
||||||
|
freepos = oldsize;
|
||||||
|
|
||||||
|
for (n=0 ; n<oldsize ; n++)
|
||||||
|
{
|
||||||
|
unsigned int h = hashval(table[n].data.id);
|
||||||
|
table[n].next = table[h].first;
|
||||||
|
table[h].first = n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int hashTable::hashval(const char *s) const
|
||||||
|
{
|
||||||
|
unsigned int h = 0;
|
||||||
|
|
||||||
|
for (const char *p=s ; *p!=0 ; p++)
|
||||||
|
h = (h + *p) % size;
|
||||||
|
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* EOF */
|
||||||
56
buddy/examples/calculator/hashtbl.h
Normal file
56
buddy/examples/calculator/hashtbl.h
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*************************************************************************
|
||||||
|
$Header: /Volumes/CVS/repository/spot/spot/buddy/examples/calculator/Attic/hashtbl.h,v 1.1 2003/05/05 10:57:55 aduret Exp $
|
||||||
|
FILE: hashtbl.h
|
||||||
|
DESCR: Compiler hashtable
|
||||||
|
AUTH: Jorn Lind
|
||||||
|
DATE: (C) september 1998
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
#ifndef _HASHTBL_H
|
||||||
|
#define _HASHTBL_H
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
class hashData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
hashData(void) { id=NULL; type=0; def=NULL; }
|
||||||
|
hashData(const char *s, int t, void *d) : id(s) { type=t; def=d; }
|
||||||
|
const char *id;
|
||||||
|
int type;
|
||||||
|
void *def;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class hashElement
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
hashData data;
|
||||||
|
int first;
|
||||||
|
int next;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class hashTable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
hashTable(void);
|
||||||
|
~hashTable(void);
|
||||||
|
void add(hashData &);
|
||||||
|
int exists(const char *);
|
||||||
|
int lookup(const char *, hashData &) const;
|
||||||
|
int remove(const char *);
|
||||||
|
void clear(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void reallocate_table(void);
|
||||||
|
unsigned int hashval(const char *) const;
|
||||||
|
hashElement *table;
|
||||||
|
int size, freepos;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _HASHTBL_H */
|
||||||
|
|
||||||
|
|
||||||
|
/* EOF */
|
||||||
101
buddy/examples/calculator/lexer.l
Normal file
101
buddy/examples/calculator/lexer.l
Normal file
|
|
@ -0,0 +1,101 @@
|
||||||
|
/*************************************************************************
|
||||||
|
FILE: lexer.l
|
||||||
|
DESCR: FLEX rules for BDD calculator
|
||||||
|
AUTH: Jorn Lind
|
||||||
|
DATE: (C) may 1999
|
||||||
|
*************************************************************************/
|
||||||
|
%{
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "parser.h"
|
||||||
|
#include "tokens.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
Macros and sub-lexers
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
DIGIT [0-9]
|
||||||
|
ID [a-zA-Z_][a-zA-Z0-9_]*
|
||||||
|
LINE [^\n]
|
||||||
|
|
||||||
|
%x COMM
|
||||||
|
|
||||||
|
%%
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
Tokens
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
/* Keywords */
|
||||||
|
|
||||||
|
"initial" return T_initial;
|
||||||
|
"inputs" return T_inputs;
|
||||||
|
"actions" return T_actions;
|
||||||
|
"exist" return T_exist;
|
||||||
|
"forall" return T_forall;
|
||||||
|
"size" return T_size;
|
||||||
|
"dot" return T_dot;
|
||||||
|
"autoreorder" return T_autoreorder;
|
||||||
|
"reorder" return T_reorder;
|
||||||
|
"win2" return T_win2;
|
||||||
|
"win2ite" return T_win2ite;
|
||||||
|
"sift" return T_sift;
|
||||||
|
"siftite" return T_siftite;
|
||||||
|
"none" return T_none;
|
||||||
|
"cache" return T_cache;
|
||||||
|
"tautology" return T_tautology;
|
||||||
|
"true" return T_true;
|
||||||
|
"false" return T_false;
|
||||||
|
"print" return T_print;
|
||||||
|
|
||||||
|
/* Symbols and operators */
|
||||||
|
|
||||||
|
"." return T_dot;
|
||||||
|
"(" return T_lpar;
|
||||||
|
")" return T_rpar;
|
||||||
|
";" return T_semi;
|
||||||
|
"=" return T_equal;
|
||||||
|
"<>" return T_biimp;
|
||||||
|
"=>" return T_imp;
|
||||||
|
"|" return T_or;
|
||||||
|
"^" return T_xor;
|
||||||
|
"&" return T_and;
|
||||||
|
"~" return T_not;
|
||||||
|
"biimp" return T_biimp;
|
||||||
|
"imp" return T_imp;
|
||||||
|
"or" return T_or;
|
||||||
|
"xor" return T_xor;
|
||||||
|
"and" return T_and;
|
||||||
|
"not" return T_not;
|
||||||
|
"nand" return T_nand;
|
||||||
|
"nor" return T_nor;
|
||||||
|
|
||||||
|
/* Identifiers and constant values */
|
||||||
|
{ID} { strncpy(yylval.id, yytext, MAXIDLEN); return T_id; }
|
||||||
|
{DIGIT}+ { yylval.ival = atol(yytext); return T_intval; }
|
||||||
|
|
||||||
|
/* Strings */
|
||||||
|
\"[^\"]*\" { yylval.str=sdup(yytext+1);
|
||||||
|
yylval.str[strlen(yylval.str)-1]=0; return T_str; }
|
||||||
|
|
||||||
|
/* Whitespace */
|
||||||
|
[\n] { linenum++; }
|
||||||
|
[\r\t\f ] /* ignore blanks */
|
||||||
|
|
||||||
|
|
||||||
|
"//"{LINE}* /* Remove one line comments */
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
Remove multi line comments
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
"/*" BEGIN COMM;
|
||||||
|
<COMM>[^*\n]* /* ignore */
|
||||||
|
<COMM>"*"[^*/\n]* /* ignore */
|
||||||
|
<COMM>\n { linenum++; }
|
||||||
|
<COMM>"*/" BEGIN INITIAL;
|
||||||
|
|
||||||
|
. { yyerror("Unknown symbol"); }
|
||||||
48
buddy/examples/calculator/makefile
Normal file
48
buddy/examples/calculator/makefile
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
# ---------------------------
|
||||||
|
# Makefile for BDD calculator
|
||||||
|
# ---------------------------
|
||||||
|
|
||||||
|
all: bddcalc
|
||||||
|
|
||||||
|
# --- Compiler flags
|
||||||
|
CFLAGS = -O3 -pedantic -Wall -ansi -L../../src -I../../src
|
||||||
|
|
||||||
|
# --- C++ compiler
|
||||||
|
CPP = g++
|
||||||
|
|
||||||
|
# --- C compiler
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
# --- You may need to change these according to your flex and bison versions
|
||||||
|
parser.cxx: parser.h parser.y
|
||||||
|
bison -d -o parser.cxx parser.y
|
||||||
|
mv parser.cxx.h tokens.h
|
||||||
|
|
||||||
|
lexer.cxx: tokens.h parser.h lexer.l
|
||||||
|
flex -olexer.cxx lexer.l
|
||||||
|
|
||||||
|
|
||||||
|
# --- Do not touch ---
|
||||||
|
|
||||||
|
.SUFFIXES: .cxx .c
|
||||||
|
|
||||||
|
.cxx.o:
|
||||||
|
$(CPP) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(CC) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
bddcalc: parser.o lexer.o hashtbl.o bddlib
|
||||||
|
$(CPP) $(CFLAGS) parser.o lexer.o hashtbl.o -o bddcalc -lbdd -lm
|
||||||
|
|
||||||
|
bddlib:
|
||||||
|
cd ../..; make
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *~ examples/*~
|
||||||
|
rm -f *.o
|
||||||
|
rm -f bddcalc parser.cxx lexer.cxx
|
||||||
|
|
||||||
|
# --- Needed for the author's Cygwin compiler
|
||||||
|
export BISONLIB=/cygnus/cygwin-b20/share/
|
||||||
|
|
||||||
44
buddy/examples/calculator/parser.h
Normal file
44
buddy/examples/calculator/parser.h
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*************************************************************************
|
||||||
|
FILE: parser.h
|
||||||
|
DESCR: parser defs. for BDD calculator
|
||||||
|
AUTH: Jorn Lind
|
||||||
|
DATE: (C) may 1999
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
#ifndef _PARSER_H
|
||||||
|
#define _PARSER_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "bdd.h"
|
||||||
|
|
||||||
|
#define MAXIDLEN 32 /* Max. number of allowed characters in an identifier */
|
||||||
|
|
||||||
|
struct token /* BISON token data */
|
||||||
|
{
|
||||||
|
char id[MAXIDLEN+1];
|
||||||
|
char *str;
|
||||||
|
int ival;
|
||||||
|
bdd *bval;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define YYSTYPE token
|
||||||
|
#define YY_SKIP_YYWRAP
|
||||||
|
#define YY_NO_UNPUT
|
||||||
|
#define yywrap() (1)
|
||||||
|
|
||||||
|
extern YYSTYPE yylval; /* Declare for flex user */
|
||||||
|
extern void yyerror(char *,...); /* Declare for flex and bison */
|
||||||
|
extern FILE *yyin;
|
||||||
|
extern int yylex(void); /* Declare for bison */
|
||||||
|
extern int yyparse(void); /* Declare for bison user */
|
||||||
|
extern int linenum; /* Declare for error handler */
|
||||||
|
|
||||||
|
/* Use this instead of strdup() to avoid malloc() */
|
||||||
|
inline char *sdup(const char *s)
|
||||||
|
{
|
||||||
|
return strcpy(new char[strlen(s)+1], s);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* _PARSER_H */
|
||||||
|
|
||||||
|
/* EOF */
|
||||||
457
buddy/examples/calculator/parser.y
Normal file
457
buddy/examples/calculator/parser.y
Normal file
|
|
@ -0,0 +1,457 @@
|
||||||
|
/*************************************************************************
|
||||||
|
FILE: parser.y
|
||||||
|
DESCR: BISON rules and main program for BDD calculator
|
||||||
|
AUTH: Jorn Lind
|
||||||
|
DATE: (C) may 1999
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <fstream.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#define IMPLEMENTSLIST /* Special for list template handling */
|
||||||
|
#include "slist.h"
|
||||||
|
#include "hashtbl.h"
|
||||||
|
#include "parser.h"
|
||||||
|
|
||||||
|
/* Definitions for storing and caching of identifiers */
|
||||||
|
#define inputTag 0
|
||||||
|
#define exprTag 1
|
||||||
|
|
||||||
|
struct nodeData
|
||||||
|
{
|
||||||
|
nodeData(const nodeData &d) { tag=d.tag; name=sdup(d.name); val=d.val; }
|
||||||
|
nodeData(int t, char *n, bdd v) { tag=t; name=n; val=v; }
|
||||||
|
~nodeData(void) { delete[] name; }
|
||||||
|
int tag;
|
||||||
|
char *name;
|
||||||
|
bdd val;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef SList<nodeData> nodeLst;
|
||||||
|
nodeLst inputs;
|
||||||
|
hashTable names;
|
||||||
|
|
||||||
|
/* Other */
|
||||||
|
int linenum;
|
||||||
|
|
||||||
|
bddgbchandler gbcHandler = bdd_default_gbchandler;
|
||||||
|
|
||||||
|
/* Prototypes */
|
||||||
|
void actInit(token *nodes, token *cache);
|
||||||
|
void actInputs(void);
|
||||||
|
void actAddInput(token *id);
|
||||||
|
void actAssign(token *id, token *expr);
|
||||||
|
void actOpr2(token *res, token *left, token *right, int opr);
|
||||||
|
void actNot(token *res, token *right);
|
||||||
|
void actId(token *res, token *id);
|
||||||
|
void actConst(token *res, int);
|
||||||
|
void actSize(token *id);
|
||||||
|
void actDot(token *fname, token *id);
|
||||||
|
void actAutoreorder(token *times, token *method);
|
||||||
|
void actCache(void);
|
||||||
|
void actTautology(token *id);
|
||||||
|
void actExist(token *res, token *var, token *expr);
|
||||||
|
void actForall(token *res, token *var, token *expr);
|
||||||
|
void actQuantVar2(token *res, token *id, token *list);
|
||||||
|
void actQuantVar1(token *res, token *id);
|
||||||
|
void actPrint(token *id);
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
Token definitions
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
%token T_id, T_str, T_intval, T_true, T_false
|
||||||
|
|
||||||
|
%token T_initial, T_inputs, T_actions
|
||||||
|
%token T_size, T_dumpdot
|
||||||
|
%token T_autoreorder, T_reorder, T_win2, T_win2ite, T_sift, T_siftite, T_none
|
||||||
|
%token T_cache, T_tautology, T_print
|
||||||
|
|
||||||
|
%token T_lpar, T_rpar
|
||||||
|
%token T_equal
|
||||||
|
%token T_semi, T_dot
|
||||||
|
|
||||||
|
%right T_exist, T_forall, T_dot
|
||||||
|
%left T_biimp
|
||||||
|
%left T_imp
|
||||||
|
%left T_or, T_nor
|
||||||
|
%left T_xor
|
||||||
|
%left T_nand, T_and
|
||||||
|
%right T_not
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
BISON rules
|
||||||
|
*************************************************************************/
|
||||||
|
%%
|
||||||
|
|
||||||
|
/*=[ Top ]==============================================================*/
|
||||||
|
|
||||||
|
calc:
|
||||||
|
initial inputs actions
|
||||||
|
;
|
||||||
|
|
||||||
|
/*=[ Initializers ]=====================================================*/
|
||||||
|
|
||||||
|
initial:
|
||||||
|
T_initial T_intval T_intval T_semi { actInit(&$2,&$3); }
|
||||||
|
;
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
T_inputs inputSeq T_semi { actInputs(); }
|
||||||
|
;
|
||||||
|
|
||||||
|
inputSeq:
|
||||||
|
inputSeq T_id { actAddInput(&$2); }
|
||||||
|
| T_id { actAddInput(&$1); }
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
/*=[ Actions ]==========================================================*/
|
||||||
|
|
||||||
|
actions:
|
||||||
|
T_actions actionSeq
|
||||||
|
;
|
||||||
|
|
||||||
|
actionSeq:
|
||||||
|
action T_semi actionSeq
|
||||||
|
| action T_semi
|
||||||
|
;
|
||||||
|
|
||||||
|
action:
|
||||||
|
assign
|
||||||
|
| size
|
||||||
|
| dot
|
||||||
|
| reorder
|
||||||
|
| cache
|
||||||
|
| tautology
|
||||||
|
| print
|
||||||
|
;
|
||||||
|
|
||||||
|
assign:
|
||||||
|
T_id T_equal expr { actAssign(&$1,&$3); }
|
||||||
|
;
|
||||||
|
|
||||||
|
expr:
|
||||||
|
expr T_and expr { actOpr2(&$$,&$1,&$3,bddop_and); }
|
||||||
|
| expr T_nand expr { actOpr2(&$$,&$1,&$3,bddop_nand); }
|
||||||
|
| expr T_xor expr { actOpr2(&$$,&$1,&$3,bddop_xor); }
|
||||||
|
| expr T_or expr { actOpr2(&$$,&$1,&$3,bddop_or); }
|
||||||
|
| expr T_nor expr { actOpr2(&$$,&$1,&$3,bddop_nor); }
|
||||||
|
| expr T_imp expr { actOpr2(&$$,&$1,&$3,bddop_imp); }
|
||||||
|
| expr T_biimp expr { actOpr2(&$$,&$1,&$3,bddop_biimp); }
|
||||||
|
| T_not expr { actNot(&$$,&$2); }
|
||||||
|
| T_lpar expr T_rpar { $$.bval = $2.bval; }
|
||||||
|
| T_id { actId(&$$,&$1); }
|
||||||
|
| T_true { $$.bval = new bdd(bddtrue); }
|
||||||
|
| T_false { $$.bval = new bdd(bddfalse); }
|
||||||
|
| quantifier { $$.bval = $1.bval; }
|
||||||
|
;
|
||||||
|
|
||||||
|
quantifier:
|
||||||
|
T_exist varlist T_dot expr { actExist(&$$,&$2,&$4); }
|
||||||
|
| T_forall varlist T_dot expr { actForall(&$$,&$2,&$4); }
|
||||||
|
;
|
||||||
|
|
||||||
|
varlist:
|
||||||
|
T_id varlist { actQuantVar2(&$$,&$1,&$2); }
|
||||||
|
| T_id { actQuantVar1(&$$,&$1); }
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
size:
|
||||||
|
T_size T_id { actSize(&$2); }
|
||||||
|
;
|
||||||
|
|
||||||
|
dot:
|
||||||
|
T_dumpdot T_str T_id { actDot(&$2,&$3); }
|
||||||
|
;
|
||||||
|
|
||||||
|
reorder:
|
||||||
|
T_reorder method { bdd_reorder($2.ival); }
|
||||||
|
| T_autoreorder T_intval method { actAutoreorder(&$2,&$3); }
|
||||||
|
;
|
||||||
|
|
||||||
|
method:
|
||||||
|
T_win2 { $$.ival = BDD_REORDER_WIN2; }
|
||||||
|
| T_win2ite { $$.ival = BDD_REORDER_WIN2ITE; }
|
||||||
|
| T_sift { $$.ival = BDD_REORDER_SIFT; }
|
||||||
|
| T_siftite { $$.ival = BDD_REORDER_SIFTITE; }
|
||||||
|
| T_none { $$.ival = BDD_REORDER_NONE; }
|
||||||
|
;
|
||||||
|
|
||||||
|
cache:
|
||||||
|
T_cache { actCache(); }
|
||||||
|
;
|
||||||
|
|
||||||
|
tautology:
|
||||||
|
T_tautology T_id { actTautology(&$2); }
|
||||||
|
;
|
||||||
|
|
||||||
|
print:
|
||||||
|
T_print T_id { actPrint(&$2); }
|
||||||
|
|
||||||
|
%%
|
||||||
|
/*************************************************************************
|
||||||
|
Main and more
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
void usage(void)
|
||||||
|
{
|
||||||
|
cerr << "USAGE: bddcalc [-hg] file\n";
|
||||||
|
cerr << " -h : print this message\n";
|
||||||
|
cerr << " -g : disable garbage collection info\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int ac, char **av)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
|
||||||
|
while ((c=getopt(ac, av, "hg")) != EOF)
|
||||||
|
{
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case 'h':
|
||||||
|
usage();
|
||||||
|
break;
|
||||||
|
case 'g':
|
||||||
|
gbcHandler = bdd_default_gbchandler;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optind >= ac)
|
||||||
|
usage();
|
||||||
|
|
||||||
|
yyin = fopen(av[optind],"r");
|
||||||
|
if (!yyin)
|
||||||
|
{
|
||||||
|
cerr << "Could not open file: " << av[optind] << endl;
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
linenum = 1;
|
||||||
|
bdd_setcacheratio(2);
|
||||||
|
yyparse();
|
||||||
|
|
||||||
|
bdd_printstat();
|
||||||
|
bdd_done();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void yyerror(char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list argp;
|
||||||
|
va_start(argp,fmt);
|
||||||
|
fprintf(stderr, "Parse error in (or before) line %d: ", linenum);
|
||||||
|
vfprintf(stderr, fmt, argp);
|
||||||
|
va_end(argp);
|
||||||
|
exit(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
Semantic actions
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
void actInit(token *nodes, token *cache)
|
||||||
|
{
|
||||||
|
bdd_init(nodes->ival, cache->ival);
|
||||||
|
bdd_gbc_hook(gbcHandler);
|
||||||
|
bdd_reorder_verbose(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void actInputs(void)
|
||||||
|
{
|
||||||
|
bdd_setvarnum(inputs.size());
|
||||||
|
|
||||||
|
int vnum=0;
|
||||||
|
for (nodeLst::ite i=inputs.first() ; i.more() ; i++, vnum++)
|
||||||
|
{
|
||||||
|
if (names.exists((*i).name))
|
||||||
|
yyerror("Redefinition of input %s", (*i).name);
|
||||||
|
|
||||||
|
(*i).val = bdd_ithvar(vnum);
|
||||||
|
hashData hd((*i).name, 0, &(*i));
|
||||||
|
names.add(hd);
|
||||||
|
}
|
||||||
|
|
||||||
|
bdd_varblockall();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void actAddInput(token *id)
|
||||||
|
{
|
||||||
|
inputs.append( nodeData(inputTag,sdup(id->id),bddtrue) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void actAssign(token *id, token *expr)
|
||||||
|
{
|
||||||
|
if (names.exists(id->id))
|
||||||
|
yyerror("Redefinition of %s", id->id);
|
||||||
|
|
||||||
|
nodeData *d = new nodeData(exprTag, sdup(id->id), *expr->bval);
|
||||||
|
hashData hd(d->name, 0, d);
|
||||||
|
names.add(hd);
|
||||||
|
delete expr->bval;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void actOpr2(token *res, token *left, token *right, int opr)
|
||||||
|
{
|
||||||
|
res->bval = new bdd( bdd_apply(*left->bval, *right->bval, opr) );
|
||||||
|
delete left->bval;
|
||||||
|
delete right->bval;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void actNot(token *res, token *right)
|
||||||
|
{
|
||||||
|
res->bval = new bdd( bdd_not(*right->bval) );
|
||||||
|
delete right->bval;
|
||||||
|
//printf("%5d -> %f\n", fixme, bdd_satcount(*res->bval));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void actId(token *res, token *id)
|
||||||
|
{
|
||||||
|
hashData hd;
|
||||||
|
|
||||||
|
if (names.lookup(id->id,hd) == 0)
|
||||||
|
{
|
||||||
|
res->bval = new bdd( ((nodeData*)hd.def)->val );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
yyerror("Unknown variable %s", id->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void actExist(token *res, token *var, token *expr)
|
||||||
|
{
|
||||||
|
res->bval = new bdd( bdd_exist(*expr->bval, *var->bval) );
|
||||||
|
delete var->bval;
|
||||||
|
delete expr->bval;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void actForall(token *res, token *var, token *expr)
|
||||||
|
{
|
||||||
|
res->bval = new bdd( bdd_forall(*expr->bval, *var->bval) );
|
||||||
|
delete var->bval;
|
||||||
|
delete expr->bval;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void actQuantVar2(token *res, token *id, token *list)
|
||||||
|
{
|
||||||
|
hashData hd;
|
||||||
|
|
||||||
|
if (names.lookup(id->id,hd) == 0)
|
||||||
|
{
|
||||||
|
if (hd.type == inputTag)
|
||||||
|
{
|
||||||
|
res->bval = list->bval;
|
||||||
|
*res->bval &= ((nodeData*)hd.def)->val;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
yyerror("%s is not a variable", id->id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
yyerror("Unknown variable %s", id->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void actQuantVar1(token *res, token *id)
|
||||||
|
{
|
||||||
|
hashData hd;
|
||||||
|
|
||||||
|
if (names.lookup(id->id,hd) == 0)
|
||||||
|
{
|
||||||
|
if (hd.type == inputTag)
|
||||||
|
res->bval = new bdd( ((nodeData*)hd.def)->val );
|
||||||
|
else
|
||||||
|
yyerror("%s is not a variable", id->id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
yyerror("Unknown variable %s", id->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void actSize(token *id)
|
||||||
|
{
|
||||||
|
hashData hd;
|
||||||
|
|
||||||
|
if (names.lookup(id->id,hd) == 0)
|
||||||
|
{
|
||||||
|
cout << "Number of nodes used for " << id->id << " = "
|
||||||
|
<< bdd_nodecount(((nodeData*)hd.def)->val) << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
yyerror("Unknown variable %s", id->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void actDot(token *fname, token *id)
|
||||||
|
{
|
||||||
|
hashData hd;
|
||||||
|
|
||||||
|
if (names.lookup(id->id,hd) == 0)
|
||||||
|
{
|
||||||
|
if (bdd_fnprintdot(fname->str, ((nodeData*)hd.def)->val) < 0)
|
||||||
|
cout << "Could not open file: " << fname->str << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
yyerror("Unknown variable %s", id->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void actAutoreorder(token *times, token *method)
|
||||||
|
{
|
||||||
|
if (times->ival == 0)
|
||||||
|
bdd_autoreorder(method->ival);
|
||||||
|
else
|
||||||
|
bdd_autoreorder_times(method->ival, times->ival);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void actCache(void)
|
||||||
|
{
|
||||||
|
bdd_printstat();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void actTautology(token *id)
|
||||||
|
{
|
||||||
|
hashData hd;
|
||||||
|
|
||||||
|
if (names.lookup(id->id,hd) == 0)
|
||||||
|
{
|
||||||
|
if (((nodeData*)hd.def)->val == bddtrue)
|
||||||
|
cout << "Formula " << id->id << " is a tautology!\n";
|
||||||
|
else
|
||||||
|
cout << "Formula " << id->id << " is NOT a tautology!\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
yyerror("Unknown variable %s", id->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void actPrint(token *id)
|
||||||
|
{
|
||||||
|
hashData hd;
|
||||||
|
|
||||||
|
if (names.lookup(id->id,hd) == 0)
|
||||||
|
cout << id->id << " = " << bddset << ((nodeData*)hd.def)->val << endl;
|
||||||
|
else
|
||||||
|
yyerror("Unknown variable %s", id->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* EOF */
|
||||||
99
buddy/examples/calculator/readme
Normal file
99
buddy/examples/calculator/readme
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
A PRIMITIVE BDD CALCULATOR
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
This is a small program that parses commands for a BDD calculator. The
|
||||||
|
input file contains the definition of the basic BDD variables (inputs)
|
||||||
|
and a sequence of actions - typically assignments. The calculator can
|
||||||
|
be used for verification of combinatorial circuits (tautology check),
|
||||||
|
such as some of the ISCAS85 circuits in the "examples" directory. These
|
||||||
|
ISCAS85 have been modified by another program before they where added to
|
||||||
|
the BuDDy examples, so please do not compare the runtime results to other
|
||||||
|
test runs.
|
||||||
|
|
||||||
|
|
||||||
|
A BDD calculator file could be something like this ("example.cal"):
|
||||||
|
|
||||||
|
initial 100 100;
|
||||||
|
|
||||||
|
inputs
|
||||||
|
a b c;
|
||||||
|
|
||||||
|
actions
|
||||||
|
t1 = (a | b) & c;
|
||||||
|
t2 = (a & c) | (b & c);
|
||||||
|
t3 = t1 <> t2;
|
||||||
|
tautology t3; /* Verify that (a | b) & c == (a & c) | (b & c) */
|
||||||
|
|
||||||
|
|
||||||
|
Where the blocks are like this:
|
||||||
|
|
||||||
|
initial n c
|
||||||
|
-----------
|
||||||
|
Initialize the BDD package using 'n' bddnodes and 'c' elements in
|
||||||
|
the caches. This part is mandatory.
|
||||||
|
|
||||||
|
|
||||||
|
inputs id-seq
|
||||||
|
-------------
|
||||||
|
Define all identifiers in the sequence 'id-seq' to be primary
|
||||||
|
inputs. This also corresponds to the initial BDD variable ordering,
|
||||||
|
starting with the first identifier in the top.
|
||||||
|
|
||||||
|
|
||||||
|
outputs id-seq
|
||||||
|
--------------
|
||||||
|
Define all identifiers in the sequence 'id-seq' to be primary
|
||||||
|
outputs. The sequence is space separated.
|
||||||
|
|
||||||
|
|
||||||
|
actions act-seq
|
||||||
|
---------------
|
||||||
|
A list of all the calculations and more. This list is traversed and
|
||||||
|
interpreted in the same order as written in the file. An action can
|
||||||
|
be one of the following:
|
||||||
|
|
||||||
|
Assignments: "id = expression"
|
||||||
|
Calculate the right-hand side and assign the value to the
|
||||||
|
left-hand identifier. The expression may contain:
|
||||||
|
|
||||||
|
+ identifiers : A previously defined identifier
|
||||||
|
+ true : The constant true BDD
|
||||||
|
+ false : The constant false BDD
|
||||||
|
+ ( ... ) : Parenteses
|
||||||
|
+ E1 & E2 : Conjunction of two sub-expressions
|
||||||
|
+ E1 | E2 : Disjunction of two sub-expressions
|
||||||
|
+ E1 ^ E2 : Xor
|
||||||
|
+ E1 => E2 : Implication
|
||||||
|
+ E1 <> E2 : Biimplication
|
||||||
|
+ ~E : Negation
|
||||||
|
+ exist V.E :
|
||||||
|
+ forall V. E : Existential/Universal quantification of the
|
||||||
|
variables V in the expression E. V is a space
|
||||||
|
separated list of input names.
|
||||||
|
|
||||||
|
|
||||||
|
Tautology check: "tautology id"
|
||||||
|
Check the variable 'id' for tautology (being equal to the constant
|
||||||
|
true BDD).
|
||||||
|
|
||||||
|
Size information: "size id"
|
||||||
|
Print the number of distinct BDD nodes used to represent 'id'.
|
||||||
|
|
||||||
|
Dump as a dot file: "dot "filename" id"
|
||||||
|
Dump the BDD representing 'id' as commands to the graph drawing
|
||||||
|
program Dot. The commands are written to the file 'filename'.
|
||||||
|
|
||||||
|
Reordering: "reorder mtd"
|
||||||
|
Do a dynamic variable reordering now using the method 'mtd'. The
|
||||||
|
argument 'mtd' may be either: win2, win2ite or sift.
|
||||||
|
|
||||||
|
Automatic reordering: "autoreorder times mtd"
|
||||||
|
Enable automatic dynamic variable reordering using the method
|
||||||
|
'mtd'. The argument 'mtd' may be either: win2, win2ite, sift or
|
||||||
|
none. Use none to disable automatic reordering. The 'times'
|
||||||
|
argument supplies the number of times that reordering may be
|
||||||
|
done. Use for example 1 if you only want a "one-shot" reordering.
|
||||||
|
|
||||||
|
Cache statistics: "cache"
|
||||||
|
Print various cache statistics for the BDD kernel.
|
||||||
|
|
||||||
235
buddy/examples/calculator/slist.h
Normal file
235
buddy/examples/calculator/slist.h
Normal file
|
|
@ -0,0 +1,235 @@
|
||||||
|
/*************************************************************************
|
||||||
|
$Header: /Volumes/CVS/repository/spot/spot/buddy/examples/calculator/Attic/slist.h,v 1.1 2003/05/05 10:57:55 aduret Exp $
|
||||||
|
FILE: slist.h
|
||||||
|
DESCR: Single linked list
|
||||||
|
AUTH: Jorn Lind
|
||||||
|
DATE: (C)
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
#ifndef _SLIST_H
|
||||||
|
#define _SLIST_H
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* === Base void list ==================================================*/
|
||||||
|
|
||||||
|
class voidSList;
|
||||||
|
|
||||||
|
class voidSList
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
class voidSListElem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void *data;
|
||||||
|
voidSListElem *next;
|
||||||
|
~voidSListElem(void) { delete next; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
voidSListElem(void *d) { data=d; next=NULL; }
|
||||||
|
friend voidSList;
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
voidSList(void) { head=tail=NULL; len=0; }
|
||||||
|
~voidSList(void) { delete head; }
|
||||||
|
void *append(void *);
|
||||||
|
void *append(voidSListElem *p, void *d);
|
||||||
|
void *insert(void *);
|
||||||
|
int size(void) const { return len; }
|
||||||
|
int empty(void) const { return len==0; }
|
||||||
|
void reverse(void);
|
||||||
|
void eraseHead(void);
|
||||||
|
void eraseAll(void) { delete head; head=tail=NULL; len=0; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int len;
|
||||||
|
voidSListElem *head, *tail;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef IMPLEMENTSLIST
|
||||||
|
|
||||||
|
void *voidSList::append(void *d)
|
||||||
|
{
|
||||||
|
voidSListElem *elem = new voidSListElem(d);
|
||||||
|
|
||||||
|
if (tail)
|
||||||
|
tail->next = elem;
|
||||||
|
else
|
||||||
|
head = elem;
|
||||||
|
|
||||||
|
tail = elem;
|
||||||
|
len++;
|
||||||
|
|
||||||
|
return elem->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void *voidSList::append(voidSListElem *p, void *d)
|
||||||
|
{
|
||||||
|
voidSListElem *elem = new voidSListElem(d);
|
||||||
|
|
||||||
|
if (p)
|
||||||
|
{
|
||||||
|
elem->next = p->next;
|
||||||
|
p->next = elem;
|
||||||
|
if (p == tail)
|
||||||
|
tail = p->next;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (tail)
|
||||||
|
tail->next = elem;
|
||||||
|
else
|
||||||
|
head = elem;
|
||||||
|
tail = elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
len++;
|
||||||
|
|
||||||
|
return elem->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void *voidSList::insert(void *d)
|
||||||
|
{
|
||||||
|
voidSListElem *elem = new voidSListElem(d);
|
||||||
|
|
||||||
|
if (tail == NULL)
|
||||||
|
tail = elem;
|
||||||
|
|
||||||
|
elem->next = head;
|
||||||
|
head = elem;
|
||||||
|
len++;
|
||||||
|
|
||||||
|
return elem->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void voidSList::reverse(void)
|
||||||
|
{
|
||||||
|
voidSListElem *newTail = head;
|
||||||
|
voidSListElem *tmpHead = NULL;
|
||||||
|
|
||||||
|
if (len < 2)
|
||||||
|
return ;
|
||||||
|
|
||||||
|
while (head != NULL)
|
||||||
|
{
|
||||||
|
voidSListElem *tmpNext = head->next;
|
||||||
|
|
||||||
|
head->next = tmpHead;
|
||||||
|
tmpHead = head;
|
||||||
|
|
||||||
|
head = tmpNext;
|
||||||
|
}
|
||||||
|
|
||||||
|
tail = newTail;
|
||||||
|
head = tmpHead;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void voidSList::eraseHead(void)
|
||||||
|
{
|
||||||
|
if (head != NULL)
|
||||||
|
{
|
||||||
|
head = head->next;
|
||||||
|
if (head == NULL)
|
||||||
|
tail = NULL;
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* IMPLEMENTSLIST */
|
||||||
|
|
||||||
|
|
||||||
|
/* === Base void list ==================================================*/
|
||||||
|
|
||||||
|
//sorting
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
class SList : private voidSList
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
class ite
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ite(void) { next=NULL; }
|
||||||
|
ite(const ite &start) { next=start.next;}
|
||||||
|
ite(voidSListElem *start) { next=start; }
|
||||||
|
int more(void) const { return next!=NULL; }
|
||||||
|
ite &operator=(const ite &start) { next=start.next; return *this; }
|
||||||
|
ite operator++(void)
|
||||||
|
{ if (next) next=next->next; return *this; }
|
||||||
|
ite operator++(int)
|
||||||
|
{ ite tmp=*this; if (next) next=next->next; return tmp; }
|
||||||
|
T &operator*(void) const { return *((T*)next->data); }
|
||||||
|
int operator==(ite x) { return x.next==next; }
|
||||||
|
private:
|
||||||
|
voidSListElem *next;
|
||||||
|
friend SList<T>;
|
||||||
|
};
|
||||||
|
|
||||||
|
~SList(void) { for (ite x=first() ; x.more() ; x++) delete &(*x); }
|
||||||
|
T &append(const T &d) { return *((T*)voidSList::append(new T(d))); }
|
||||||
|
T &insert(const T &d) { return *((T*)voidSList::insert(new T(d))); }
|
||||||
|
T &head(void) const { return *((T*)voidSList::head->data); }
|
||||||
|
T &tail(void) const { return *((T*)voidSList::tail->data); }
|
||||||
|
ite first(void) const { return ite(voidSList::head); }
|
||||||
|
int empty(void) const { return voidSList::empty(); }
|
||||||
|
int size(void) const { return voidSList::size(); }
|
||||||
|
void reverse(void) { voidSList::reverse(); }
|
||||||
|
void filter(int (*)(T&));
|
||||||
|
void append(SList<T> &l)
|
||||||
|
{ for (ite x=l.first() ; x.more() ; x++) append(*x); }
|
||||||
|
T &append(ite &i, const T &d)
|
||||||
|
{ return *((T*)voidSList::append(i.next, new T(d))); }
|
||||||
|
void eraseHead(void)
|
||||||
|
{ delete ((T*)voidSList::head->data); voidSList::eraseHead(); }
|
||||||
|
void eraseAll(void)
|
||||||
|
{ for (ite x=first() ; x.more() ; x++) delete &(*x); voidSList::eraseAll();}
|
||||||
|
void map(void (*f)(T&))
|
||||||
|
{ for (ite x=first() ; x.more() ; x++) f(*x); }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void SList<T>::filter(int (*f)(T&))
|
||||||
|
{
|
||||||
|
voidSListElem *prev=NULL, *next=voidSList::head;
|
||||||
|
|
||||||
|
while (next)
|
||||||
|
{
|
||||||
|
if (f(*((T*)next->data)))
|
||||||
|
{
|
||||||
|
prev = next;
|
||||||
|
next = next->next;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
voidSListElem *n = next->next;
|
||||||
|
|
||||||
|
if (prev == NULL)
|
||||||
|
voidSList::head = next->next;
|
||||||
|
else
|
||||||
|
prev->next = next->next;
|
||||||
|
if (voidSList::head == NULL)
|
||||||
|
voidSList::tail = NULL;
|
||||||
|
|
||||||
|
delete next->data;
|
||||||
|
next->next = NULL;
|
||||||
|
delete next;
|
||||||
|
|
||||||
|
next = n;
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _SLIST_H */
|
||||||
|
|
||||||
|
|
||||||
|
/* EOF */
|
||||||
41
buddy/examples/calculator/tokens.h
Normal file
41
buddy/examples/calculator/tokens.h
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
#ifndef YYSTYPE
|
||||||
|
#define YYSTYPE int
|
||||||
|
#endif
|
||||||
|
#define T_id 257
|
||||||
|
#define T_str 258
|
||||||
|
#define T_intval 259
|
||||||
|
#define T_true 260
|
||||||
|
#define T_false 261
|
||||||
|
#define T_initial 262
|
||||||
|
#define T_inputs 263
|
||||||
|
#define T_actions 264
|
||||||
|
#define T_size 265
|
||||||
|
#define T_dumpdot 266
|
||||||
|
#define T_autoreorder 267
|
||||||
|
#define T_reorder 268
|
||||||
|
#define T_win2 269
|
||||||
|
#define T_win2ite 270
|
||||||
|
#define T_sift 271
|
||||||
|
#define T_siftite 272
|
||||||
|
#define T_none 273
|
||||||
|
#define T_cache 274
|
||||||
|
#define T_tautology 275
|
||||||
|
#define T_print 276
|
||||||
|
#define T_lpar 277
|
||||||
|
#define T_rpar 278
|
||||||
|
#define T_equal 279
|
||||||
|
#define T_semi 280
|
||||||
|
#define T_dot 281
|
||||||
|
#define T_exist 282
|
||||||
|
#define T_forall 283
|
||||||
|
#define T_biimp 284
|
||||||
|
#define T_imp 285
|
||||||
|
#define T_or 286
|
||||||
|
#define T_nor 287
|
||||||
|
#define T_xor 288
|
||||||
|
#define T_nand 289
|
||||||
|
#define T_and 290
|
||||||
|
#define T_not 291
|
||||||
|
|
||||||
|
|
||||||
|
extern YYSTYPE yylval;
|
||||||
36
buddy/examples/cmilner/makefile
Normal file
36
buddy/examples/cmilner/makefile
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
# --------------------------------
|
||||||
|
# Makefile for milner test example
|
||||||
|
# --------------------------------
|
||||||
|
|
||||||
|
# --- Compiler flags
|
||||||
|
CFLAGS = -O3 -pedantic -Wall -ansi -L../../src -I../../src
|
||||||
|
|
||||||
|
# --- C++ compiler
|
||||||
|
CPP = g++
|
||||||
|
|
||||||
|
# --- C compiler
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
|
||||||
|
# --- Do not touch ---
|
||||||
|
|
||||||
|
.SUFFIXES: .cxx .c
|
||||||
|
|
||||||
|
.cxx.o:
|
||||||
|
$(CPP) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(CC) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
milner: milner.o bddlib
|
||||||
|
$(CC) $(CFLAGS) milner.o -o milner -lbdd -lm
|
||||||
|
|
||||||
|
bddlib:
|
||||||
|
cd ../..; make
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *~
|
||||||
|
rm -f *.o
|
||||||
|
rm -f milner
|
||||||
|
|
||||||
|
milner.o: ../../src/bdd.h
|
||||||
299
buddy/examples/cmilner/milner.c
Normal file
299
buddy/examples/cmilner/milner.c
Normal file
|
|
@ -0,0 +1,299 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "bdd.h"
|
||||||
|
|
||||||
|
int N; /* Number of cyclers */
|
||||||
|
int *normvar; /* Current state variables */
|
||||||
|
int *primvar; /* Next state variables */
|
||||||
|
|
||||||
|
bdd normvarset;
|
||||||
|
bddPair *pairs;
|
||||||
|
|
||||||
|
bdd A(bdd* x, bdd* y, int z)
|
||||||
|
{
|
||||||
|
bdd res = bddtrue, tmp1, tmp2;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i=0 ; i<N ; i++)
|
||||||
|
if(i != z)
|
||||||
|
{
|
||||||
|
bdd_addref(res);
|
||||||
|
tmp1 = bdd_addref(bdd_apply(x[i],y[i],bddop_biimp));
|
||||||
|
tmp2 = bdd_apply(res, tmp1, bddop_and);
|
||||||
|
bdd_delref(tmp1);
|
||||||
|
bdd_delref(res);
|
||||||
|
res = tmp2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bdd transitions(bdd* t, bdd* tp, bdd* h, bdd* hp, bdd* c, bdd* cp)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
bdd P, E, T = bddfalse;
|
||||||
|
bdd tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
|
||||||
|
|
||||||
|
for(i=0; i<N; i++)
|
||||||
|
{
|
||||||
|
bdd_addref(T);
|
||||||
|
|
||||||
|
tmp1 = bdd_addref( bdd_apply(c[i], cp[i], bddop_diff) );
|
||||||
|
tmp2 = bdd_addref( bdd_apply(tp[i], t[i], bddop_diff) );
|
||||||
|
tmp3 = bdd_addref( A(c, cp, i) );
|
||||||
|
tmp4 = bdd_addref( A(t, tp, i) );
|
||||||
|
tmp5 = bdd_addref( A(h, hp, i) );
|
||||||
|
|
||||||
|
tmp6 = bdd_addref( bdd_apply(tmp1, tmp2, bddop_and) );
|
||||||
|
bdd_delref(tmp1);
|
||||||
|
bdd_delref(tmp2);
|
||||||
|
|
||||||
|
tmp1 = bdd_addref( bdd_apply(tmp6, hp[i], bddop_and) );
|
||||||
|
bdd_delref(tmp6);
|
||||||
|
|
||||||
|
tmp2 = bdd_addref( bdd_apply(tmp1, tmp3, bddop_and) );
|
||||||
|
bdd_delref(tmp1);
|
||||||
|
bdd_delref(tmp3);
|
||||||
|
|
||||||
|
tmp3 = bdd_addref( bdd_apply(tmp2, tmp4, bddop_and) );
|
||||||
|
bdd_delref(tmp2);
|
||||||
|
bdd_delref(tmp4);
|
||||||
|
|
||||||
|
tmp1 = bdd_addref( bdd_apply(tmp3, tmp5, bddop_and) );
|
||||||
|
bdd_delref(tmp3);
|
||||||
|
bdd_delref(tmp5);
|
||||||
|
|
||||||
|
|
||||||
|
tmp4 = bdd_addref( bdd_apply(h[i], hp[i], bddop_diff) );
|
||||||
|
|
||||||
|
tmp5 = bdd_addref( bdd_apply(tmp4, cp[(i+1)%N], bddop_and) );
|
||||||
|
bdd_delref(tmp4);
|
||||||
|
|
||||||
|
tmp6 = bdd_addref( A(c, cp, (i+1)%N) );
|
||||||
|
|
||||||
|
tmp2 = bdd_addref( bdd_apply(tmp5, tmp6, bddop_and) );
|
||||||
|
bdd_delref(tmp5);
|
||||||
|
bdd_delref(tmp6);
|
||||||
|
|
||||||
|
tmp3 = bdd_addref( A(h, hp, i) );
|
||||||
|
|
||||||
|
tmp4 = bdd_addref( bdd_apply(tmp2, tmp3, bddop_and) );
|
||||||
|
bdd_delref(tmp2);
|
||||||
|
bdd_delref(tmp3);
|
||||||
|
|
||||||
|
tmp5 = bdd_addref( A(t, tp, N) );
|
||||||
|
|
||||||
|
tmp6 = bdd_addref( bdd_apply(tmp4, tmp5, bddop_and) );
|
||||||
|
bdd_delref(tmp4);
|
||||||
|
bdd_delref(tmp5);
|
||||||
|
|
||||||
|
P = bdd_addref( bdd_apply(tmp1, tmp6, bddop_or) );
|
||||||
|
bdd_delref(tmp1);
|
||||||
|
bdd_delref(tmp6);
|
||||||
|
|
||||||
|
|
||||||
|
tmp1 = bdd_addref( bdd_apply(t[i], tp[i], bddop_diff) );
|
||||||
|
|
||||||
|
tmp2 = bdd_addref( A(t, tp, i) );
|
||||||
|
|
||||||
|
tmp3 = bdd_addref( bdd_apply(tmp1, tmp2, bddop_and) );
|
||||||
|
bdd_delref(tmp1);
|
||||||
|
bdd_delref(tmp2);
|
||||||
|
|
||||||
|
tmp4 = bdd_addref( A(h, hp, N) );
|
||||||
|
tmp5 = bdd_addref( A(c, cp, N) );
|
||||||
|
|
||||||
|
tmp6 = bdd_addref( bdd_apply(tmp3, tmp4, bddop_and) );
|
||||||
|
bdd_delref(tmp3);
|
||||||
|
bdd_delref(tmp4);
|
||||||
|
|
||||||
|
E = bdd_addref( bdd_apply(tmp6, tmp5, bddop_and) );
|
||||||
|
bdd_delref(tmp6);
|
||||||
|
bdd_delref(tmp5);
|
||||||
|
|
||||||
|
|
||||||
|
tmp1 = bdd_addref( bdd_apply(P, E, bddop_or) );
|
||||||
|
bdd_delref(P);
|
||||||
|
bdd_delref(E);
|
||||||
|
|
||||||
|
tmp2 = bdd_apply(T, tmp1, bddop_or);
|
||||||
|
bdd_delref(T);
|
||||||
|
T = tmp2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return T;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bdd initial_state(bdd* t, bdd* h, bdd* c)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
bdd I, tmp1, tmp2, tmp3;
|
||||||
|
|
||||||
|
tmp1 = bdd_addref( bdd_not(h[0]) );
|
||||||
|
|
||||||
|
tmp2 = bdd_addref( bdd_apply(c[0], tmp1, bddop_and) );
|
||||||
|
bdd_delref(tmp1);
|
||||||
|
|
||||||
|
tmp1 = bdd_addref( bdd_not(t[0]) );
|
||||||
|
|
||||||
|
I = bdd_apply(tmp1, tmp2, bddop_and);
|
||||||
|
bdd_delref(tmp1);
|
||||||
|
bdd_delref(tmp2);
|
||||||
|
|
||||||
|
|
||||||
|
for(i=1; i<N; i++)
|
||||||
|
{
|
||||||
|
bdd_addref(I);
|
||||||
|
|
||||||
|
tmp1 = bdd_addref( bdd_not(c[i]) );
|
||||||
|
tmp2 = bdd_addref( bdd_not(h[i]) );
|
||||||
|
|
||||||
|
tmp3 = bdd_addref( bdd_apply(tmp1, tmp2, bddop_and) );
|
||||||
|
bdd_delref(tmp1);
|
||||||
|
bdd_delref(tmp2);
|
||||||
|
|
||||||
|
tmp1 = bdd_addref( bdd_not(t[i]) );
|
||||||
|
tmp2 = bdd_addref( bdd_apply(tmp3, tmp1, bddop_and) );
|
||||||
|
bdd_delref(tmp3);
|
||||||
|
bdd_delref(tmp1);
|
||||||
|
|
||||||
|
tmp1 = bdd_apply(I, tmp2, bddop_and);
|
||||||
|
bdd_delref(tmp2);
|
||||||
|
bdd_delref(I);
|
||||||
|
|
||||||
|
I = tmp1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return I;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bdd reachable_states(bdd I, bdd T)
|
||||||
|
{
|
||||||
|
bdd C, by, bx = bddfalse;
|
||||||
|
bdd tmp1;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
bdd_addref(bx);
|
||||||
|
|
||||||
|
by = bx;
|
||||||
|
#if 1
|
||||||
|
tmp1 = bdd_addref( bdd_apply(T, bx, bddop_and) );
|
||||||
|
C = bdd_addref( bdd_exist(tmp1, normvarset) );
|
||||||
|
bdd_delref(tmp1);
|
||||||
|
#else
|
||||||
|
C = bdd_addref( bdd_appex(bx, T, bddop_and, normvar, N*3) );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
tmp1 = bdd_addref( bdd_replace(C, pairs) );
|
||||||
|
bdd_delref(C);
|
||||||
|
C = tmp1;
|
||||||
|
|
||||||
|
tmp1 = bdd_apply(I, C, bddop_or);
|
||||||
|
bdd_delref(C);
|
||||||
|
|
||||||
|
bdd_delref(bx);
|
||||||
|
bx = tmp1;
|
||||||
|
|
||||||
|
/*printf("."); fflush(stdout);*/
|
||||||
|
}
|
||||||
|
while(bx != by);
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
return bx;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
int has_deadlocks(bdd R, bdd T)
|
||||||
|
{
|
||||||
|
bdd C = bddtrue;
|
||||||
|
|
||||||
|
for(int i=0; i<N; i++)
|
||||||
|
C &= bdd_exist(T, primvar, N*3);
|
||||||
|
//C &= bdd_exist(bdd_exist(bdd_exist(T,i*6+3),i*6+5),i*6+1);
|
||||||
|
|
||||||
|
if(C != bddfalse && R != bddfalse)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
bdd *c, *cp, *h, *hp, *t, *tp;
|
||||||
|
bdd I, T, R;
|
||||||
|
long clk1, clk2;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
if(argc < 2)
|
||||||
|
{
|
||||||
|
printf("usage: %s N\n",argv[0]);
|
||||||
|
printf("\tN number of cyclers\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
N = atoi(argv[1]);
|
||||||
|
if (N <= 0)
|
||||||
|
{
|
||||||
|
printf("The number of cyclers must more than zero\n");
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
clk1 = clock();
|
||||||
|
|
||||||
|
bdd_init(100000, 10000);
|
||||||
|
bdd_setvarnum(N*6);
|
||||||
|
|
||||||
|
c = (bdd *)malloc(sizeof(bdd)*N);
|
||||||
|
cp = (bdd *)malloc(sizeof(bdd)*N);
|
||||||
|
t = (bdd *)malloc(sizeof(bdd)*N);
|
||||||
|
tp = (bdd *)malloc(sizeof(bdd)*N);
|
||||||
|
h = (bdd *)malloc(sizeof(bdd)*N);
|
||||||
|
hp = (bdd *)malloc(sizeof(bdd)*N);
|
||||||
|
|
||||||
|
normvar = (int *)malloc(sizeof(int)*N*3);
|
||||||
|
primvar = (int *)malloc(sizeof(int)*N*3);
|
||||||
|
|
||||||
|
for (n=0 ; n<N*3 ; n++)
|
||||||
|
{
|
||||||
|
normvar[n] = n*2;
|
||||||
|
primvar[n] = n*2+1;
|
||||||
|
}
|
||||||
|
normvarset = bdd_addref( bdd_makeset(normvar, N*3) );
|
||||||
|
pairs = bdd_newpair();
|
||||||
|
bdd_setpairs(pairs, primvar, normvar, N*3);
|
||||||
|
|
||||||
|
for (n=0 ; n<N ; n++)
|
||||||
|
{
|
||||||
|
c[n] = bdd_ithvar(n*6);
|
||||||
|
cp[n] = bdd_ithvar(n*6+1);
|
||||||
|
t[n] = bdd_ithvar(n*6+2);
|
||||||
|
tp[n] = bdd_ithvar(n*6+3);
|
||||||
|
h[n] = bdd_ithvar(n*6+4);
|
||||||
|
hp[n] = bdd_ithvar(n*6+5);
|
||||||
|
}
|
||||||
|
|
||||||
|
I = bdd_addref( initial_state(t,h,c) );
|
||||||
|
T = bdd_addref( transitions(t,tp,h,hp,c,cp) );
|
||||||
|
R = bdd_addref( reachable_states(I,T) );
|
||||||
|
|
||||||
|
/*if(has_deadlocks(R,T))
|
||||||
|
printf("Milner's Scheduler has deadlocks!\n"); */
|
||||||
|
|
||||||
|
clk2 = clock();
|
||||||
|
|
||||||
|
printf("SatCount R = %.0f\n", bdd_satcount(R));
|
||||||
|
printf("Calc = %.0f\n", (double)N*pow(2.0,1.0+N)*pow(2.0,3.0*N));
|
||||||
|
printf("%.2f sec.\n", (float)(clk2 - clk1)/(float)(CLOCKS_PER_SEC));
|
||||||
|
|
||||||
|
bdd_done();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
7
buddy/examples/cmilner/readme
Normal file
7
buddy/examples/cmilner/readme
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
MILNERS SCHEDULER - AN EXAMPLE OF BDDs USED FOR STATE SPACE CALCULATION
|
||||||
|
-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
This program should illustrate how cumbersome it is to do manual
|
||||||
|
reference counting of the BDD nodes.
|
||||||
|
|
||||||
|
Please see further documentation in "../milner/doc.txt".
|
||||||
36
buddy/examples/fdd/makefile
Normal file
36
buddy/examples/fdd/makefile
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
# --------------------------------
|
||||||
|
# Makefile for FDD test example
|
||||||
|
# --------------------------------
|
||||||
|
|
||||||
|
# --- Compiler flags
|
||||||
|
CFLAGS = -O3 -pedantic -Wall -ansi -L../../src -I../../src
|
||||||
|
|
||||||
|
# --- C++ compiler
|
||||||
|
CPP = g++
|
||||||
|
|
||||||
|
# --- C compiler
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
|
||||||
|
# --- Do not touch ---
|
||||||
|
|
||||||
|
.SUFFIXES: .cxx .c
|
||||||
|
|
||||||
|
.cxx.o:
|
||||||
|
$(CPP) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(CC) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
statespace: statespace.o bddlib
|
||||||
|
$(CPP) $(CFLAGS) statespace.o -o statespace -lbdd -lm
|
||||||
|
|
||||||
|
bddlib:
|
||||||
|
cd ../../src; make
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *~
|
||||||
|
rm -f *.o
|
||||||
|
rm -f statespace
|
||||||
|
|
||||||
|
statespace.o: ../../src/fdd.h
|
||||||
77
buddy/examples/fdd/statespace.cxx
Normal file
77
buddy/examples/fdd/statespace.cxx
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
/* This program creates a transition relation for a finite state machine.
|
||||||
|
* This transition relation is then used to find the reachable statespace
|
||||||
|
* of the state machine. The state machine has 8 states with state 0 being
|
||||||
|
* the initial state. The transitions form a ring:
|
||||||
|
*
|
||||||
|
* 0 -> 1 -> 2 -> 3 -> 4 -> 5 -> -> 7 -> 0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "fdd.h"
|
||||||
|
|
||||||
|
/* Use the transition relation "transRel" to iterate through the statespace
|
||||||
|
*/
|
||||||
|
void findStateSpace(bdd transRel)
|
||||||
|
{
|
||||||
|
/* Create a new pair for renaming the next-state variables to
|
||||||
|
* current-state variables */
|
||||||
|
bddPair *p = bdd_newpair();
|
||||||
|
fdd_setpair(p,1,0);
|
||||||
|
|
||||||
|
/* Get a BDD that represents all the current-state variables */
|
||||||
|
bdd currentStateVar = fdd_ithset(0);
|
||||||
|
|
||||||
|
/* Start with the initial state */
|
||||||
|
bdd reachedStates = fdd_ithvar(0,0);
|
||||||
|
|
||||||
|
bdd tmp = bddfalse;
|
||||||
|
|
||||||
|
/* Repeat until no new states are found */
|
||||||
|
do
|
||||||
|
{
|
||||||
|
tmp = reachedStates;
|
||||||
|
|
||||||
|
/* Calculate: Newset = (exists V_cur. transRel & Reached)[cur/next] */
|
||||||
|
bdd newset;
|
||||||
|
newset = reachedStates & transRel;
|
||||||
|
newset = bdd_exist(newset, currentStateVar);
|
||||||
|
newset = bdd_replace(newset, p);
|
||||||
|
|
||||||
|
cout << "Front: " << (newset - reachedStates) << endl;
|
||||||
|
|
||||||
|
/* Add the new states to the found states */
|
||||||
|
reachedStates = reachedStates | newset;
|
||||||
|
}
|
||||||
|
while (tmp != reachedStates);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
/* Initialize BuDDy and declare two interleaved FDD variable blocks
|
||||||
|
* with the domain [0..7] */
|
||||||
|
int domain[2] = {8,8};
|
||||||
|
|
||||||
|
bdd_init(100,100);
|
||||||
|
fdd_extdomain(domain, 2);
|
||||||
|
|
||||||
|
/* Initialize the transition relation with no transitions */
|
||||||
|
bdd T = bddfalse;
|
||||||
|
|
||||||
|
/* Add all the transitions (from state 'i' to state 'i+1') */
|
||||||
|
for (int i=0 ; i<8 ; i++)
|
||||||
|
{
|
||||||
|
/* Set the current state to be state 'i' */
|
||||||
|
bdd current = fdd_ithvar(0,i);
|
||||||
|
|
||||||
|
/* Set the next state to be state 'i+1' */
|
||||||
|
bdd next = fdd_ithvar(1, (i+1) % 8);
|
||||||
|
|
||||||
|
/* Add the transition */
|
||||||
|
T = T | (current & next);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << fddset << "Transition relation: " << T << endl << endl;
|
||||||
|
|
||||||
|
/* Calculate the reachable statespace */
|
||||||
|
findStateSpace(T);
|
||||||
|
}
|
||||||
143
buddy/examples/internal/bddtest.cxx
Normal file
143
buddy/examples/internal/bddtest.cxx
Normal file
|
|
@ -0,0 +1,143 @@
|
||||||
|
#include <iomanip>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <bdd.h>
|
||||||
|
|
||||||
|
static const int varnum = 5;
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
Example of allsat print handler.
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
void allsatHandlerPrint(char* varset, int size)
|
||||||
|
{
|
||||||
|
for (int v=0; v<size ; ++v)
|
||||||
|
{
|
||||||
|
cout << (varset[v] < 0 ? 'X' : (char)('0' + varset[v]));
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
allsat handler for checking that all assignments are detected.
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
static bdd allsatBDD;
|
||||||
|
static bdd allsatSumBDD;
|
||||||
|
|
||||||
|
void allsatHandler(char* varset, int size)
|
||||||
|
{
|
||||||
|
bdd x = bddtrue;
|
||||||
|
for (int v=0 ; v<size ; ++v)
|
||||||
|
if (varset[v] == 0)
|
||||||
|
x &= bdd_nithvar(v);
|
||||||
|
else if (varset[v] == 1)
|
||||||
|
x &= bdd_ithvar(v);
|
||||||
|
|
||||||
|
// Sum up all assignments
|
||||||
|
allsatSumBDD |= x;
|
||||||
|
|
||||||
|
// Remove assignment from initial set
|
||||||
|
allsatBDD -= x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test1_check(bdd x)
|
||||||
|
{
|
||||||
|
double anum = bdd_satcount(x);
|
||||||
|
|
||||||
|
cout << "Checking bdd with " << setw(4) << anum << " assignments: ";
|
||||||
|
|
||||||
|
allsatBDD = x;
|
||||||
|
allsatSumBDD = bddfalse;
|
||||||
|
|
||||||
|
// Calculate whole set of asignments and remove all assignments
|
||||||
|
// from original set
|
||||||
|
bdd_allsat(x, allsatHandler);
|
||||||
|
|
||||||
|
// Now the summed set should be equal to the original set
|
||||||
|
if (allsatSumBDD == x)
|
||||||
|
cout << " Sum-OK. ";
|
||||||
|
else
|
||||||
|
cout << " Sum-ERROR. ";
|
||||||
|
|
||||||
|
// The subtracted set should be empty
|
||||||
|
if (allsatBDD == bddfalse)
|
||||||
|
cout << "Sub-OK.\n";
|
||||||
|
else
|
||||||
|
cout << "Sub-ERROR.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test1()
|
||||||
|
{
|
||||||
|
bdd a = bdd_ithvar(0);
|
||||||
|
bdd b = bdd_ithvar(1);
|
||||||
|
bdd c = bdd_ithvar(2);
|
||||||
|
bdd d = bdd_ithvar(3);
|
||||||
|
bdd x;
|
||||||
|
|
||||||
|
x = bddtrue;
|
||||||
|
test1_check(x);
|
||||||
|
|
||||||
|
x = bddfalse;
|
||||||
|
test1_check(x);
|
||||||
|
|
||||||
|
x = a & b | !a & !b;
|
||||||
|
test1_check(x);
|
||||||
|
|
||||||
|
x = a & b | c & d;
|
||||||
|
test1_check(x);
|
||||||
|
|
||||||
|
x = a & !b | a & !d | a & b & !c;
|
||||||
|
test1_check(x);
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i=0 ; i<varnum ; ++i)
|
||||||
|
{
|
||||||
|
test1_check(bdd_ithvar(i));
|
||||||
|
test1_check(bdd_nithvar(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
bdd set = bddtrue;
|
||||||
|
for (i=0 ; i<50 ; ++i)
|
||||||
|
{
|
||||||
|
int v = rand() % varnum;
|
||||||
|
int s = rand() % 2;
|
||||||
|
int o = rand() % 2;
|
||||||
|
|
||||||
|
if (o == 0)
|
||||||
|
{
|
||||||
|
if (s == 0)
|
||||||
|
set &= bdd_ithvar(v);
|
||||||
|
else
|
||||||
|
set &= bdd_nithvar(v);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (s == 0)
|
||||||
|
set |= bdd_ithvar(v);
|
||||||
|
else
|
||||||
|
set |= bdd_nithvar(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
test1_check(set);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
Main
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
bdd_init(1000,1000);
|
||||||
|
bdd_setvarnum(varnum);
|
||||||
|
|
||||||
|
test1();
|
||||||
|
|
||||||
|
bdd_done();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
38
buddy/examples/internal/makefile
Normal file
38
buddy/examples/internal/makefile
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
# --------------------------------
|
||||||
|
# Makefile for internal tests
|
||||||
|
# --------------------------------
|
||||||
|
|
||||||
|
# --- Compiler flags
|
||||||
|
CFLAGS = -g -pedantic -Wall -ansi -L../../src -I../../src
|
||||||
|
|
||||||
|
# --- C++ compiler
|
||||||
|
CPP = g++
|
||||||
|
|
||||||
|
# --- C compiler
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
|
||||||
|
# --- Do not touch ---
|
||||||
|
|
||||||
|
.SUFFIXES: .cxx .c
|
||||||
|
|
||||||
|
.cxx.o:
|
||||||
|
$(CPP) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(CC) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
bddtest: bddtest.o bddlib
|
||||||
|
$(CPP) $(CFLAGS) bddtest.o -o bddtest -lbdd -lm
|
||||||
|
|
||||||
|
bddlib:
|
||||||
|
cd ../..; make
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *~
|
||||||
|
rm -f *.o
|
||||||
|
rm -f bddtest
|
||||||
|
|
||||||
|
bddtest.o: ../../src/bdd.h
|
||||||
|
|
||||||
|
|
||||||
36
buddy/examples/milner/makefile
Normal file
36
buddy/examples/milner/makefile
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
# --------------------------------
|
||||||
|
# Makefile for milner test example
|
||||||
|
# --------------------------------
|
||||||
|
|
||||||
|
# --- Compiler flags
|
||||||
|
CFLAGS = -g -pedantic -Wall -ansi -L../../src -I../../src
|
||||||
|
|
||||||
|
# --- C++ compiler
|
||||||
|
CPP = g++
|
||||||
|
|
||||||
|
# --- C compiler
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
|
||||||
|
# --- Do not touch ---
|
||||||
|
|
||||||
|
.SUFFIXES: .cxx .c
|
||||||
|
|
||||||
|
.cxx.o:
|
||||||
|
$(CPP) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(CC) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
milner: milner.o bddlib
|
||||||
|
$(CPP) $(CFLAGS) milner.o -o milner -lbdd -lm
|
||||||
|
|
||||||
|
bddlib:
|
||||||
|
cd ../../src; make
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *~
|
||||||
|
rm -f *.o
|
||||||
|
rm -f milner
|
||||||
|
|
||||||
|
milner.o: ../../src/bdd.h
|
||||||
183
buddy/examples/milner/milner.cxx
Normal file
183
buddy/examples/milner/milner.cxx
Normal file
|
|
@ -0,0 +1,183 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "bdd.h"
|
||||||
|
|
||||||
|
int N; // Number of cyclers
|
||||||
|
bdd normvar; // Current state variables
|
||||||
|
bdd primvar; // Next state variables
|
||||||
|
bddPair *renamepair; // Variable pairs for renaming
|
||||||
|
|
||||||
|
|
||||||
|
/* Build a BDD expressing that all other variables than 'z' is unchanged.
|
||||||
|
*/
|
||||||
|
bdd A(bdd* x, bdd* y, int z)
|
||||||
|
{
|
||||||
|
bdd res = bddtrue;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i=0 ; i<N ; i++)
|
||||||
|
if(i != z)
|
||||||
|
res &= bdd_apply(x[i],y[i],bddop_biimp);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Loop through all cyclers and create the transition relation for each
|
||||||
|
of them.
|
||||||
|
*/
|
||||||
|
bdd transitions(bdd* t, bdd* tp, bdd* h, bdd* hp, bdd* c, bdd* cp)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
bdd P; // Cycler i's handling of the token
|
||||||
|
bdd E; // Cycler i's handling of it's task
|
||||||
|
bdd T = bddfalse; // The monolithic transition relation
|
||||||
|
|
||||||
|
for(i=0 ; i<N ; i++)
|
||||||
|
{
|
||||||
|
P = ((c[i]>cp[i]) & (tp[i]>t[i]) & hp[i] & A(c,cp,i)
|
||||||
|
& A(t,tp,i) & A(h,hp,i))
|
||||||
|
| ((h[i]>hp[i]) & cp[(i+1)%N] & A(c,cp,(i+1)%N) & A(h,hp,i)
|
||||||
|
& A(t,tp,N));
|
||||||
|
|
||||||
|
E = t[i] & !tp[i] & A(t,tp,i) & A(h,hp,N) & A(c,cp,N);
|
||||||
|
|
||||||
|
T |= P | E;
|
||||||
|
}
|
||||||
|
|
||||||
|
return T;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Create a BDD for the initial state.
|
||||||
|
*/
|
||||||
|
bdd initial_state(bdd* t, bdd* h, bdd* c)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
bdd I = c[0] & !h[0] & !t[0];
|
||||||
|
|
||||||
|
for(i=1; i<N; i++)
|
||||||
|
I &= !c[i] & !h[i] & !t[i];
|
||||||
|
|
||||||
|
return I;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Calculate the reachable states.
|
||||||
|
*/
|
||||||
|
bdd reachable_states(bdd I, bdd T)
|
||||||
|
{
|
||||||
|
bdd R = I, // Reachable state space
|
||||||
|
prevR, // Previously reached state space
|
||||||
|
tmp;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
prevR = R;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// Apply and exist as different operations => slow
|
||||||
|
tmp = T & bx;
|
||||||
|
tmp = bdd_exist(tmp, normvar);
|
||||||
|
#else
|
||||||
|
// Apply and exist as one operation => fast
|
||||||
|
tmp = bdd_appex(R, T, bddop_and, normvar);
|
||||||
|
#endif
|
||||||
|
tmp = bdd_replace(tmp, renamepair);
|
||||||
|
R |= tmp;
|
||||||
|
}
|
||||||
|
while(prevR != R);
|
||||||
|
|
||||||
|
return R;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
if(argc < 2)
|
||||||
|
{
|
||||||
|
cerr << "usage: milner N\n";
|
||||||
|
cerr << " N number of cyclers\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
N = atoi(argv[1]);
|
||||||
|
if (N <= 0)
|
||||||
|
{
|
||||||
|
cerr << "The number of cyclers must be more than zero\n";
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
long clk1 = clock();
|
||||||
|
|
||||||
|
bdd_init(500000, 50000);
|
||||||
|
bdd_setvarnum(N*6);
|
||||||
|
|
||||||
|
bdd* c = new bdd[N];
|
||||||
|
bdd* cp = new bdd[N];
|
||||||
|
bdd* t = new bdd[N];
|
||||||
|
bdd* tp = new bdd[N];
|
||||||
|
bdd* h = new bdd[N];
|
||||||
|
bdd* hp = new bdd[N];
|
||||||
|
|
||||||
|
int *nvar = new int[N*3];
|
||||||
|
int *pvar = new int[N*3];
|
||||||
|
|
||||||
|
for (n=0 ; n<N*3 ; n++)
|
||||||
|
{
|
||||||
|
nvar[n] = n*2;
|
||||||
|
pvar[n] = n*2+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
normvar = bdd_makeset(nvar, N*3);
|
||||||
|
primvar = bdd_makeset(pvar, N*3);
|
||||||
|
renamepair = bdd_newpair();
|
||||||
|
bdd_setpairs(renamepair, pvar, nvar, N*3);
|
||||||
|
|
||||||
|
for (n=0 ; n<N ; n++)
|
||||||
|
{
|
||||||
|
c[n] = bdd_ithvar(n*6);
|
||||||
|
cp[n] = bdd_ithvar(n*6+1);
|
||||||
|
t[n] = bdd_ithvar(n*6+2);
|
||||||
|
tp[n] = bdd_ithvar(n*6+3);
|
||||||
|
h[n] = bdd_ithvar(n*6+4);
|
||||||
|
hp[n] = bdd_ithvar(n*6+5);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
bdd_addvarblock(c[n], BDD_REORDER_FIXED);
|
||||||
|
bdd_addvarblock(cp[n], BDD_REORDER_FIXED);
|
||||||
|
bdd_addvarblock(t[n], BDD_REORDER_FIXED);
|
||||||
|
bdd_addvarblock(tp[n], BDD_REORDER_FIXED);
|
||||||
|
bdd_addvarblock(h[n], BDD_REORDER_FIXED);
|
||||||
|
bdd_addvarblock(hp[n], BDD_REORDER_FIXED);
|
||||||
|
bdd_addvarblock(c[n] & cp[n] & t[n] & tp[n] & h[n] & hp[n],
|
||||||
|
BDD_REORDER_FREE);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bdd I = initial_state(t,h,c);
|
||||||
|
bdd T = transitions(t,tp,h,hp,c,cp);
|
||||||
|
bdd R = reachable_states(I,T);
|
||||||
|
|
||||||
|
long clk2 = clock();
|
||||||
|
|
||||||
|
bddStat s;
|
||||||
|
bdd_stats(&s);
|
||||||
|
|
||||||
|
cout << "SatCount R = " << bdd_satcount(R) << endl;
|
||||||
|
cout << "Calc = " << (double)N*pow(2.0,1.0+N)*pow(2.0,3.0*N) << endl;
|
||||||
|
cout << "Nodes = " << s.produced << endl;
|
||||||
|
cout << endl << "Number of nodes in T is " << bdd_nodecount( T ) << endl;
|
||||||
|
cout << "Number of nodes in R is " << bdd_nodecount( R ) << endl << endl;
|
||||||
|
|
||||||
|
cout << (float)(clk2 - clk1)/(float)(CLOCKS_PER_SEC) << " sec.\n";
|
||||||
|
|
||||||
|
//bdd_printstat();
|
||||||
|
cout << "Nodenum: " << bdd_getnodenum() << endl;
|
||||||
|
bdd_done();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
15
buddy/examples/milner/readme
Normal file
15
buddy/examples/milner/readme
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
MILNERS SCHEDULER - AN EXAMPLE OF BDDs USED FOR STATE SPACE CALCULATION
|
||||||
|
-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
Please read chapter seven in "An Introduction To Binary Decision
|
||||||
|
Diagrams" which is supplied in the "doc" directory. This chapter will
|
||||||
|
explain the example.
|
||||||
|
|
||||||
|
The program is called as "milner N" where N is the number of
|
||||||
|
cyclers. It will output the size of the reachable state space for the
|
||||||
|
system (compared to the true calculated size - for debugging purpose)
|
||||||
|
and a set of cache statistics.
|
||||||
|
|
||||||
|
Please also note that this file is used as an internal benchmark for
|
||||||
|
the author, so do not be too supprised if you find some strange debug
|
||||||
|
information in the code ...
|
||||||
36
buddy/examples/money/makefile
Normal file
36
buddy/examples/money/makefile
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
# --------------------------------
|
||||||
|
# Makefile for BVEC example
|
||||||
|
# --------------------------------
|
||||||
|
|
||||||
|
# --- Compiler flags
|
||||||
|
CFLAGS = -O3 -pedantic -Wall -ansi -L../../src -I../../src
|
||||||
|
|
||||||
|
# --- C++ compiler
|
||||||
|
CPP = g++
|
||||||
|
|
||||||
|
# --- C compiler
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
|
||||||
|
# --- Do not touch ---
|
||||||
|
|
||||||
|
.SUFFIXES: .cxx .c
|
||||||
|
|
||||||
|
.cxx.o:
|
||||||
|
$(CPP) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(CC) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
money: money.o bddlib
|
||||||
|
$(CPP) $(CFLAGS) money.o -o money -lbdd -lm
|
||||||
|
|
||||||
|
bddlib:
|
||||||
|
cd ../../src; make
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *~
|
||||||
|
rm -f *.o
|
||||||
|
rm -f money
|
||||||
|
|
||||||
|
money.o: ../../src/bvec.h ../../src/fdd.h ../../src/bdd.h
|
||||||
73
buddy/examples/money/money.cxx
Normal file
73
buddy/examples/money/money.cxx
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
#include "bvec.h"
|
||||||
|
|
||||||
|
/* Find a solution to the send-more-money example
|
||||||
|
* The problem is to assign values for the digits s,e,n,d,m,o,r,y
|
||||||
|
* in such a way that the following equation is true:
|
||||||
|
*
|
||||||
|
* s e n d +
|
||||||
|
* m o r e =
|
||||||
|
* m o n e y
|
||||||
|
*
|
||||||
|
* with the additional constraints that all digits must have different values
|
||||||
|
* and s>0 and m>0.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
// Allocate 11 domains with room for up to 3*10
|
||||||
|
static int dom[11] = {30,30,30,30,30,30,30,30,30,30,30};
|
||||||
|
|
||||||
|
bdd_init(10000,10000);
|
||||||
|
fdd_extdomain(dom,11);
|
||||||
|
|
||||||
|
// Assign binary vectors (expressions) to the digits
|
||||||
|
|
||||||
|
bvec s = bvec_varfdd(0); // The 's' digit
|
||||||
|
bvec e = bvec_varfdd(1); // The 'e' digit
|
||||||
|
bvec n = bvec_varfdd(2); // ...
|
||||||
|
bvec d = bvec_varfdd(3);
|
||||||
|
bvec m = bvec_varfdd(4);
|
||||||
|
bvec o = bvec_varfdd(5);
|
||||||
|
bvec r = bvec_varfdd(6);
|
||||||
|
bvec y = bvec_varfdd(7);
|
||||||
|
bvec m1 = bvec_varfdd(8); // Carry out 1
|
||||||
|
bvec m2 = bvec_varfdd(9); // Carry out 2
|
||||||
|
bvec m3 = bvec_varfdd(10); // Carry out 3
|
||||||
|
|
||||||
|
// Create a few constants of the right bit number (5)
|
||||||
|
bvec c10 = bvec_con(5,10);
|
||||||
|
bvec c2 = bvec_con(5,2);
|
||||||
|
bvec c0 = bvec_con(5,0);
|
||||||
|
|
||||||
|
// Create constraints
|
||||||
|
|
||||||
|
// Constraint 1: addition of the last digits and constraints on
|
||||||
|
// the max. value of the involved variables and carry-out
|
||||||
|
bdd t1 = (d + e == y + m1*10) & d<c10 & e<c10 & y<c10 & m1<c2;
|
||||||
|
|
||||||
|
// The use of "m1*10" instead of "m1*c10" avoids a bitnum mismatch since
|
||||||
|
// "m1*10" results in 5 bits but "m1*c10" results in 10 bits!
|
||||||
|
|
||||||
|
// And so on ...
|
||||||
|
bdd t2 = (n + r + m1 == e + m2*10) & n<c10 & r<c10 & m2<c2;
|
||||||
|
bdd t3 = (e + o + m2 == n + m3*10) & o<c10 & m3<c2;
|
||||||
|
bdd t4 = (s + m + m3 == o + m*10) & s<c10 & m<c2;
|
||||||
|
bdd t5 = (m > c0 & s > c0);
|
||||||
|
|
||||||
|
// Make sure all digits are different
|
||||||
|
bdd t6 = (s!=e & s!=n & s!=d & s!=m & s!=o & s!=r & s!=y);
|
||||||
|
bdd t7 = (e!=n & e!=d & e!=m & e!=o & e!=r & e!=y);
|
||||||
|
bdd t8 = (n!=d & n!=m & n!=o & n!=r & n!=y);
|
||||||
|
bdd t9 = (d!=m & d!=o & d!=r & d!=y);
|
||||||
|
bdd t10 = (m!=o & m!=r & m!=y);
|
||||||
|
bdd t11 = (o!=r & o!=y);
|
||||||
|
bdd t12 = (r!=y);
|
||||||
|
|
||||||
|
// Join all constraints
|
||||||
|
bdd t = t1 & t2 & t3 & t4 & t5 & t6 & t7 & t8 & t9 & t10 & t11 & t12;
|
||||||
|
|
||||||
|
// Print result
|
||||||
|
cout << fddset << t << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
37
buddy/examples/queen/makefile
Normal file
37
buddy/examples/queen/makefile
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
# ---------------------------------
|
||||||
|
# Makefile for N-queen test example
|
||||||
|
# ---------------------------------
|
||||||
|
|
||||||
|
# --- Compiler flags
|
||||||
|
CFLAGS = -O3 -pedantic -Wall -ansi -L../../src -I../../src
|
||||||
|
|
||||||
|
# --- C++ compiler
|
||||||
|
CPP = g++
|
||||||
|
|
||||||
|
# --- C compiler
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
|
||||||
|
# --- Do not touch ---
|
||||||
|
|
||||||
|
.SUFFIXES: .cxx .c
|
||||||
|
|
||||||
|
.cxx.o:
|
||||||
|
$(CPP) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(CC) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
queen: queen.o bddlib
|
||||||
|
$(CPP) $(CFLAGS) queen.o -o queen -lbdd -lm
|
||||||
|
|
||||||
|
bddlib:
|
||||||
|
cd ../..; make
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *~
|
||||||
|
rm -f *.o
|
||||||
|
rm -f queen
|
||||||
|
|
||||||
|
queen.o: ../../src/bdd.h
|
||||||
|
|
||||||
133
buddy/examples/queen/queen.cxx
Normal file
133
buddy/examples/queen/queen.cxx
Normal file
|
|
@ -0,0 +1,133 @@
|
||||||
|
/**************************************************************************
|
||||||
|
BDD demonstration of the N-Queen chess problem.
|
||||||
|
-----------------------------------------------
|
||||||
|
The BDD variables correspond to a NxN chess board like:
|
||||||
|
|
||||||
|
0 N 2N .. N*N-N
|
||||||
|
1 N+1 2N+1 .. N*N-N+1
|
||||||
|
2 N+2 2N+2 .. N*N-N+2
|
||||||
|
.. .. .. .. ..
|
||||||
|
N-1 2N-1 3N-1 .. N*N-1
|
||||||
|
|
||||||
|
So for example a 4x4 is:
|
||||||
|
|
||||||
|
0 4 8 12
|
||||||
|
1 5 9 13
|
||||||
|
2 6 10 14
|
||||||
|
3 7 11 15
|
||||||
|
|
||||||
|
One solution is then that 2,4,11,13 should be true, meaning a queen
|
||||||
|
should be placed there:
|
||||||
|
|
||||||
|
. X . .
|
||||||
|
. . . X
|
||||||
|
X . . .
|
||||||
|
. . X .
|
||||||
|
|
||||||
|
**************************************************************************/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "bdd.h"
|
||||||
|
|
||||||
|
int N; /* Size of the chess board */
|
||||||
|
bdd **X; /* BDD variable array */
|
||||||
|
bdd queen; /* N-queen problem express as a BDD */
|
||||||
|
|
||||||
|
|
||||||
|
/* Build the requirements for all other fields than (i,j) assuming
|
||||||
|
that (i,j) has a queen */
|
||||||
|
void build(int i, int j)
|
||||||
|
{
|
||||||
|
bdd a=bddtrue, b=bddtrue, c=bddtrue, d=bddtrue;
|
||||||
|
int k,l;
|
||||||
|
|
||||||
|
/* No one in the same column */
|
||||||
|
for (l=0 ; l<N ; l++)
|
||||||
|
if (l != j)
|
||||||
|
a &= X[i][j] >> !X[i][l];
|
||||||
|
|
||||||
|
/* No one in the same row */
|
||||||
|
for (k=0 ; k<N ; k++)
|
||||||
|
if (k != i)
|
||||||
|
b &= X[i][j] >> !X[k][j];
|
||||||
|
|
||||||
|
/* No one in the same up-right diagonal */
|
||||||
|
for (k=0 ; k<N ; k++)
|
||||||
|
{
|
||||||
|
int ll = k-i+j;
|
||||||
|
if (ll>=0 && ll<N)
|
||||||
|
if (k != i)
|
||||||
|
c &= X[i][j] >> !X[k][ll];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* No one in the same down-right diagonal */
|
||||||
|
for (k=0 ; k<N ; k++)
|
||||||
|
{
|
||||||
|
int ll = i+j-k;
|
||||||
|
if (ll>=0 && ll<N)
|
||||||
|
if (k != i)
|
||||||
|
d &= X[i][j] >> !X[k][ll];
|
||||||
|
}
|
||||||
|
|
||||||
|
queen &= a & b & c & d;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int ac, char **av)
|
||||||
|
{
|
||||||
|
int n,i,j;
|
||||||
|
|
||||||
|
if (ac != 2)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "USAGE: queen N\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
N = atoi(av[1]);
|
||||||
|
if (N <= 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "USAGE: queen N\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize with 100000 nodes, 10000 cache entries and NxN variables */
|
||||||
|
bdd_init(N*N*256, 10000);
|
||||||
|
bdd_setvarnum(N*N);
|
||||||
|
|
||||||
|
queen = bddtrue;
|
||||||
|
|
||||||
|
/* Build variable array */
|
||||||
|
X = new bdd*[N];
|
||||||
|
for (n=0 ; n<N ; n++)
|
||||||
|
X[n] = new bdd[N];
|
||||||
|
|
||||||
|
for (i=0 ; i<N ; i++)
|
||||||
|
for (j=0 ; j<N ; j++)
|
||||||
|
X[i][j] = bdd_ithvar(i*N+j);
|
||||||
|
|
||||||
|
/* Place a queen in each row */
|
||||||
|
for (i=0 ; i<N ; i++)
|
||||||
|
{
|
||||||
|
bdd e = bddfalse;
|
||||||
|
for (j=0 ; j<N ; j++)
|
||||||
|
e |= X[i][j];
|
||||||
|
queen &= e;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Build requirements for each variable(field) */
|
||||||
|
for (i=0 ; i<N ; i++)
|
||||||
|
for (j=0 ; j<N ; j++)
|
||||||
|
{
|
||||||
|
cout << "Adding position " << i << "," << j << "\n" << flush;
|
||||||
|
build(i,j);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print the results */
|
||||||
|
cout << "There are " << bdd_satcount(queen) << " solutions\n";
|
||||||
|
cout << "one is:\n";
|
||||||
|
bdd solution = bdd_satone(queen);
|
||||||
|
cout << bddset << solution << endl;
|
||||||
|
|
||||||
|
bdd_done();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
36
buddy/examples/solitare/makefile
Normal file
36
buddy/examples/solitare/makefile
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
# --------------------------------
|
||||||
|
# Makefile for solitare test example
|
||||||
|
# --------------------------------
|
||||||
|
|
||||||
|
# --- Compiler flags
|
||||||
|
CFLAGS = -O3 -pedantic -Wall -ansi -L../../src -I../../src
|
||||||
|
|
||||||
|
# --- C++ compiler
|
||||||
|
CPP = g++
|
||||||
|
|
||||||
|
# --- C compiler
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
|
||||||
|
# --- Do not touch ---
|
||||||
|
|
||||||
|
.SUFFIXES: .cxx .c
|
||||||
|
|
||||||
|
.cxx.o:
|
||||||
|
$(CPP) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(CC) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
solitare: solitare.o bddlib
|
||||||
|
$(CPP) $(CFLAGS) solitare.o -o solitare -lbdd -lm
|
||||||
|
|
||||||
|
bddlib:
|
||||||
|
cd ../..; make
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *~
|
||||||
|
rm -f *.o
|
||||||
|
rm -f solitare
|
||||||
|
|
||||||
|
milner.o: ../../src/bdd.h
|
||||||
35
buddy/examples/solitare/readme
Normal file
35
buddy/examples/solitare/readme
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
SOLITARE GAME
|
||||||
|
-------------
|
||||||
|
|
||||||
|
This example tries to calculate the reachable state space of the
|
||||||
|
Solitare game. The board is sketched below. At the beginning all
|
||||||
|
places except number 17 has a pin in them. A pin may be moved by
|
||||||
|
jumping over another pin into an empty place. The pin in between is
|
||||||
|
then removed. The goal is to remove all pins execept one - which
|
||||||
|
should be left in the center.
|
||||||
|
|
||||||
|
It took a few hours to run this example on a Alpha machine and it
|
||||||
|
required some 8000000 BDD nodes.
|
||||||
|
|
||||||
|
(*****************************************************************************)
|
||||||
|
(* *)
|
||||||
|
(* ---------------- *)
|
||||||
|
(* | 07 | 14 | 21 | *)
|
||||||
|
(* ---------------- *)
|
||||||
|
(* | 08 | 15 | 22 | *)
|
||||||
|
(* ------------------------------------ *)
|
||||||
|
(* | 01 | 04 | 09 | 16 | 23 | 28 | 31 | *)
|
||||||
|
(* ------------------------------------ *)
|
||||||
|
(* | 02 | 05 | 10 | 17 | 24 | 29 | 32 | *)
|
||||||
|
(* ------------------------------------ *)
|
||||||
|
(* | 03 | 06 | 11 | 18 | 25 | 30 | 33 | *)
|
||||||
|
(* ------------------------------------ *)
|
||||||
|
(* | 12 | 19 | 26 | *)
|
||||||
|
(* ---------------- *)
|
||||||
|
(* | 13 | 20 | 27 | *)
|
||||||
|
(* ---------------- *)
|
||||||
|
(* *)
|
||||||
|
(*****************************************************************************)
|
||||||
|
|
||||||
|
|
||||||
|
Thanks to Ken Larsen for his help with this example.
|
||||||
222
buddy/examples/solitare/solitare.cxx
Normal file
222
buddy/examples/solitare/solitare.cxx
Normal file
|
|
@ -0,0 +1,222 @@
|
||||||
|
#include <math.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "bdd.h"
|
||||||
|
|
||||||
|
float dummyStateNum; // Use to remove the number of states defined by the
|
||||||
|
// next-state variables
|
||||||
|
|
||||||
|
#define SIZE 33 // Size of the board
|
||||||
|
#define CENTER 16 // Location of the center place
|
||||||
|
|
||||||
|
bdd boardC[SIZE]; // Current state variables
|
||||||
|
bdd boardN[SIZE]; // Next state variables
|
||||||
|
bdd I; // Initial state
|
||||||
|
bdd T; // Transition relation
|
||||||
|
|
||||||
|
bdd currentvar; // All current state variables
|
||||||
|
bddPair *pair; // Renaming pair
|
||||||
|
|
||||||
|
|
||||||
|
// All the possible moves. Note that the numbering starts from '1'
|
||||||
|
int moves[][3] =
|
||||||
|
{ {1,4,9}, {1,2,3},
|
||||||
|
{2,5,10},
|
||||||
|
{3,2,1}, {3,6,11},
|
||||||
|
{4,5,6}, {4,9,16},
|
||||||
|
{5,10,17},
|
||||||
|
{6,5,4}, {6,11,18},
|
||||||
|
{7,8,9}, {7,14,21},
|
||||||
|
{8,9,10}, {8,15,22},
|
||||||
|
{9,8,7}, {9,10,11}, {9,4,1}, {9,16,23},
|
||||||
|
{10,9,8}, {10,11,12}, {10,5,2}, {10,17,24},
|
||||||
|
{11,10,9}, {11,12,13}, {11,6,3}, {11,18,25},
|
||||||
|
{12,11,10}, {12,19,26},
|
||||||
|
{13,12,11}, {13,20,27},
|
||||||
|
{14,15,16},
|
||||||
|
{15,16,17},
|
||||||
|
{16,15,14}, {16,17,18}, {16,9,4}, {16,23,28},
|
||||||
|
{17,16,15}, {17,18,19}, {17,10,5}, {17,24,29},
|
||||||
|
{18,17,16}, {18,19,20}, {18,11,6}, {18,25,30},
|
||||||
|
{19,18,17},
|
||||||
|
{20,19,18},
|
||||||
|
{21,22,23}, {21,14,7},
|
||||||
|
{22,23,24}, {22,15,8},
|
||||||
|
{23,22,21}, {23,24,25}, {23,16,9}, {23,28,31},
|
||||||
|
{24,23,22}, {24,25,26}, {24,17,10}, {24,29,32},
|
||||||
|
{25,24,23}, {25,26,27}, {25,18,11}, {25,30,33},
|
||||||
|
{26,25,24}, {26,19,12},
|
||||||
|
{27,26,25}, {27,20,13},
|
||||||
|
{28,29,30}, {28,23,16},
|
||||||
|
{29,24,17},
|
||||||
|
{30,29,28}, {30,25,18},
|
||||||
|
{31,32,33}, {31,28,23},
|
||||||
|
{32,29,24},
|
||||||
|
{33,32,31}, {33,30,25},
|
||||||
|
{0,0,0}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Setup the variables needed for the board
|
||||||
|
void make_board(void)
|
||||||
|
{
|
||||||
|
bdd_setvarnum(SIZE*2);
|
||||||
|
|
||||||
|
for (int n=0 ; n<SIZE ; n++)
|
||||||
|
{
|
||||||
|
boardC[n] = bdd_ithvar(n*2);
|
||||||
|
boardN[n] = bdd_ithvar(n*2+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Make the initial state predicate
|
||||||
|
void make_initial_state(void)
|
||||||
|
{
|
||||||
|
I = bddtrue;
|
||||||
|
|
||||||
|
for (int n=0 ; n<SIZE ; n++)
|
||||||
|
if (n == CENTER)
|
||||||
|
I &= !boardC[n];
|
||||||
|
else
|
||||||
|
I &= boardC[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Make sure all other places does nothing when
|
||||||
|
// there's a move from 'src' to 'dst' over 'tmp'
|
||||||
|
bdd all_other_idle(int src, int tmp, int dst)
|
||||||
|
{
|
||||||
|
bdd idle = bddtrue;
|
||||||
|
|
||||||
|
for (int n=0 ; n<SIZE ; n++)
|
||||||
|
{
|
||||||
|
if (n != src && n != tmp && n != dst)
|
||||||
|
idle &= bdd_biimp(boardC[n], boardN[n]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return idle;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Encode one move from 'src' to 'dst' over 'tmp'
|
||||||
|
bdd make_move(int src, int tmp, int dst)
|
||||||
|
{
|
||||||
|
bdd move = boardC[src] & boardC[tmp] & !boardC[dst] &
|
||||||
|
!boardN[src] & !boardN[tmp] & boardN[dst];
|
||||||
|
|
||||||
|
move &= all_other_idle(src, tmp, dst);
|
||||||
|
|
||||||
|
return move;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void make_transition_relation(void)
|
||||||
|
{
|
||||||
|
T = bddfalse;
|
||||||
|
|
||||||
|
for (int n=0 ; moves[n][0]!=moves[n][1] ; n++)
|
||||||
|
T |= make_move(moves[n][0]-1, moves[n][1]-1, moves[n][2]-1);
|
||||||
|
|
||||||
|
cout << "Transition relation: " << bdd_nodecount(T) << " nodes, "
|
||||||
|
<< bdd_satcount(T)/dummyStateNum << " states\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Make renaming pair and current state variables
|
||||||
|
void make_itedata(void)
|
||||||
|
{
|
||||||
|
pair = bdd_newpair();
|
||||||
|
for (int n=0 ; n<SIZE ; n++)
|
||||||
|
bdd_setpair(pair, n*2+1, n*2);
|
||||||
|
|
||||||
|
currentvar = bddtrue;
|
||||||
|
for (int n=0 ; n<SIZE ; n++)
|
||||||
|
currentvar &= boardC[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Do the forward iteration
|
||||||
|
void iterate(void)
|
||||||
|
{
|
||||||
|
bdd tmp;
|
||||||
|
bdd reachable = I;
|
||||||
|
int cou = 1;
|
||||||
|
|
||||||
|
make_itedata();
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
tmp = reachable;
|
||||||
|
bdd next = bdd_appex(reachable, T, bddop_and, currentvar);
|
||||||
|
next = bdd_replace(next, pair);
|
||||||
|
reachable |= next;
|
||||||
|
|
||||||
|
cout << cou << ": " << bdd_nodecount(reachable)
|
||||||
|
<< " nodes, " << bdd_satcount(reachable)/dummyStateNum
|
||||||
|
<< " states\n" << flush;
|
||||||
|
cou++;
|
||||||
|
}
|
||||||
|
while (tmp != reachable);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void iterate_front(void)
|
||||||
|
{
|
||||||
|
bdd tmp;
|
||||||
|
bdd reachable = I;
|
||||||
|
bdd front = reachable;
|
||||||
|
int cou = 1;
|
||||||
|
|
||||||
|
make_itedata();
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
tmp = reachable;
|
||||||
|
bdd next = bdd_appex(front, T, bddop_and, currentvar);
|
||||||
|
next = bdd_replace(next, pair);
|
||||||
|
front = next - reachable;
|
||||||
|
reachable |= front;
|
||||||
|
|
||||||
|
cout << cou << ": " << bdd_nodecount(reachable)
|
||||||
|
<< " , " << bdd_satcount(reachable)/dummyStateNum << endl;
|
||||||
|
cout << cou << ": " << bdd_nodecount(front)
|
||||||
|
<< " , " << bdd_satcount(front)/dummyStateNum << endl;
|
||||||
|
cou++;
|
||||||
|
}
|
||||||
|
while (tmp != reachable);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void setup(void)
|
||||||
|
{
|
||||||
|
bdd_init(100000,1000);
|
||||||
|
bdd_setcacheratio(64);
|
||||||
|
bdd_setmaxincrease(500000);
|
||||||
|
|
||||||
|
dummyStateNum = pow(2.0, SIZE);
|
||||||
|
|
||||||
|
make_board();
|
||||||
|
make_transition_relation();
|
||||||
|
make_initial_state();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
long c1, c2;
|
||||||
|
|
||||||
|
c1 = clock();
|
||||||
|
|
||||||
|
setup();
|
||||||
|
iterate();
|
||||||
|
|
||||||
|
c2 = clock();
|
||||||
|
printf("Time: %.1f sec.\n", ((float)(c2-c1))/CLOCKS_PER_SEC);
|
||||||
|
system("ps aux | grep \"./solitare\" | grep -v \"grep\"");
|
||||||
|
}
|
||||||
|
|
||||||
112
buddy/makefile
Normal file
112
buddy/makefile
Normal file
|
|
@ -0,0 +1,112 @@
|
||||||
|
# ==============================================================
|
||||||
|
# Makefile for the BuDDy package
|
||||||
|
# - Do not touch. Edit "config" instead.
|
||||||
|
# ==============================================================
|
||||||
|
|
||||||
|
include config
|
||||||
|
|
||||||
|
# --------------------------------------------------------------
|
||||||
|
# The primary targets.
|
||||||
|
# --------------------------------------------------------------
|
||||||
|
|
||||||
|
buddy:
|
||||||
|
cd src; make
|
||||||
|
|
||||||
|
docs:
|
||||||
|
cd doc; make doc
|
||||||
|
|
||||||
|
install:
|
||||||
|
cp -f src/libbdd.a $(LIBDIR)/libbdd.a
|
||||||
|
chmod 644 $(LIBDIR)/libbdd.a
|
||||||
|
cp -f src/bdd.h $(INCDIR)/bdd.h
|
||||||
|
chmod 644 $(INCDIR)/bdd.h
|
||||||
|
cp -f src/fdd.h $(INCDIR)/fdd.h
|
||||||
|
chmod 644 $(INCDIR)/fdd.h
|
||||||
|
cp -f src/bvec.h $(INCDIR)/bvec.h
|
||||||
|
chmod 644 $(INCDIR)/bvec.h
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
rm -f $(LIBDIR)/libbdd.a
|
||||||
|
rm -f $(INCDIR)/bdd.h
|
||||||
|
rm -f $(INCDIR)/fdd.h
|
||||||
|
rm -f $(INCDIR)/bvec.h
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------
|
||||||
|
# Housekeeping
|
||||||
|
# --------------------------------------------------------------
|
||||||
|
TARGET = buddy
|
||||||
|
VERSION = 22
|
||||||
|
RD = $(TARGET)$(VERSION)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
cd examples/milner; make clean
|
||||||
|
cd examples/cmilner; make clean
|
||||||
|
cd examples/queen; make clean
|
||||||
|
cd examples/adder; make clean
|
||||||
|
cd examples/fdd; make clean
|
||||||
|
cd examples/calculator; make clean
|
||||||
|
cd examples/solitare; make clean
|
||||||
|
cd examples/money; make clean
|
||||||
|
cd examples/internal; make clean
|
||||||
|
cd src; make clean
|
||||||
|
cd doc; make clean
|
||||||
|
rm -f *~
|
||||||
|
rm -f $(TARGET).tar.gz
|
||||||
|
rm -f $(RD).tar.gz
|
||||||
|
|
||||||
|
examples: dummy
|
||||||
|
cd examples/milner; make
|
||||||
|
cd examples/cmilner; make
|
||||||
|
cd examples/queen; make
|
||||||
|
cd examples/adder; make
|
||||||
|
cd examples/fdd; make
|
||||||
|
cd examples/calculator; make
|
||||||
|
cd examples/solitare; make
|
||||||
|
cd examples/money; make
|
||||||
|
|
||||||
|
dummy:
|
||||||
|
|
||||||
|
backup: clean
|
||||||
|
tar -cvf $(TARGET).tar *
|
||||||
|
gzip $(TARGET).tar
|
||||||
|
|
||||||
|
rel: clean docs
|
||||||
|
cd src; make depend
|
||||||
|
mkdir $(RD)
|
||||||
|
mkdir $(RD)/src
|
||||||
|
mkdir $(RD)/doc
|
||||||
|
mkdir $(RD)/examples
|
||||||
|
cp config makefile README CHANGES $(RD)
|
||||||
|
./copysource $(RD)/src
|
||||||
|
cp src/depend.inf src/makefile $(RD)/src
|
||||||
|
cp doc/buddy.ps $(RD)/doc
|
||||||
|
cp doc/bddnotes.ps $(RD)/doc
|
||||||
|
cp doc/tech.txt $(RD)/doc
|
||||||
|
echo "clean:" > $(RD)/doc/makefile
|
||||||
|
mkdir $(RD)/examples/milner
|
||||||
|
cp examples/milner/* $(RD)/examples/milner
|
||||||
|
mkdir $(RD)/examples/cmilner
|
||||||
|
cp examples/cmilner/* $(RD)/examples/cmilner
|
||||||
|
mkdir $(RD)/examples/adder
|
||||||
|
cp examples/adder/* $(RD)/examples/adder
|
||||||
|
mkdir $(RD)/examples/queen
|
||||||
|
cp examples/queen/* $(RD)/examples/queen
|
||||||
|
mkdir $(RD)/examples/fdd
|
||||||
|
cp examples/fdd/* $(RD)/examples/fdd
|
||||||
|
mkdir $(RD)/examples/calculator
|
||||||
|
mkdir $(RD)/examples/calculator/examples
|
||||||
|
cp -R examples/calculator/* $(RD)/examples/calculator
|
||||||
|
mkdir $(RD)/examples/solitare
|
||||||
|
cp examples/solitare/* $(RD)/examples/solitare
|
||||||
|
mkdir $(RD)/examples/money
|
||||||
|
cp examples/money/* $(RD)/examples/money
|
||||||
|
mkdir $(RD)/examples/internal
|
||||||
|
cp examples/internal/* $(RD)/examples/internal
|
||||||
|
tar -cvf $(TARGET)$(VERSION).tar $(RD)/*
|
||||||
|
gzip $(TARGET)$(VERSION).tar
|
||||||
|
rm -fr $(RD)
|
||||||
|
@cat RELEASE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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