#include "mdd.h" /* * MDD Package * * $Id: mdd_init.c,v 1.21 2009/04/11 02:07:47 fabio Exp $ * * Author: Timothy Kam * * Copyright 1992 by the Regents of the University of California. * * All rights reserved. Permission to use, copy, modify and distribute * this software is hereby granted, provided that the above copyright * notice and this permission notice appear in all copies. This software * is made available as is, with no warranties. */ int integer_get_num_of_digits(int value) { double x; int num_of_digits; if (value > 0) x = log10((double) value); else if (value == 0) x = 0; else fail("mdd_init: internal error, value less than 0\n"); /* * Notice that floor(x) return a double, * so it needs to be cast into an integer using * this following expression. */ num_of_digits = (int) floor(x) + 1; return num_of_digits; } static void mdd_name_variables( array_t *mvar_list, int no_mvars, array_t **mvar_names_ptr) { char *istr; int i; if (*mvar_names_ptr == NIL(array_t)) { /* if no variable names are given, use generic naming */ /* mv_0, mv_1, ... for variable 0, 1, ... */ *mvar_names_ptr = array_alloc(char *, 0); for (i=0; i mvar_list */ for (i=0; i 0) stride = array_fetch(int, mvar_strides, i); else stride = 1; for(j=0; jmvar_list = mvar_list; mdd_hook->bvar_list = bvar_list; /* if some array arguments are NIL */ no_mvars = array_n(mvar_values); free_mvar_names_flag = (mvar_names == NIL(array_t)); mdd_name_variables(mvar_list, no_mvars, &mvar_names); /* create mdd manager */ vertex_sum = 0; for (i=0; imdd = (char *) mdd_hook; current_vertex = 0; if (mvar_strides == NIL(array_t)) { /* if no strides are specified, the variables are not interleaved */ /* i.e. mvar_strides = 1 */ /* must set a flag to know that this array needs to be freed */ free_mvar_strides_flag = TRUE; mvar_strides = array_alloc(int, 0); for (i=0; i 1) { sec_bit_of_mv = mdd_ret_bvar(&after_mv, 1, bvar_list); sec_bit_level = bdd_top_var_level( mgr, sec_bit_of_mv.node ); /* first_bit_of_last_interleaved_mvar */ fol_id = bdd_get_id_from_level( mgr, sec_bit_level - 1 ); } else fol_id = mdd_ret_bvar_id(&after_mv, 0); fol_mv = array_fetch( mvar_type, mvar_list, fol_id ); after_bv_id = mdd_ret_bvar_id(&fol_mv, fol_mv.encode_length - 1); /* if some array arguments are NIL */ no_mvars = array_n(mvar_values); free_mvar_names_flag = (mvar_names == NIL(array_t)); mdd_name_variables(mvar_list, no_mvars, &mvar_names); if (mvar_strides == NIL(array_t)) { /* if no strides are specified, the variables are not interleaved */ /* i.e. mvar_strides = 1 */ /* must set a flag to know that this array needs to be freed */ free_mvar_strides_flag = TRUE; mvar_strides = array_alloc(int, 0); for (i=0; i= array_n(bvar_list)) fail("bddId out of range"); /* Extract info. */ bddVar = array_fetch(bvar_type, bvar_list, bddId); mvVar = array_fetch(mvar_type, mvar_list, bddVar.mvar_id); bvars = array_alloc(int,array_n(mvVar.bvars)-1); /* Expunge fixed variable from list of BDD variables. */ position = array_n(mvVar.bvars); /* initialization for later checking */ arrayForEachItem(int, mvVar.bvars, i, id) { if (id != bddId) array_insert_last(int, bvars, id); else position = i; } /* Make sure we wrote position in the loop. */ assert(position < array_n(mvVar.bvars)); /* Count number of surviving values. */ shift = (mvVar.encode_length - position - 1); for (i = 0, values = 0; i < mvVar.values; i++) { values += (i >> shift) ^ ~val; } /* Update mvar_list */ array_free(mvVar.bvars); mvVar.bvars = bvars; mvVar.values = values; mvVar.encode_length--; array_insert(mvar_type, mvar_list, bddVar.mvar_id, mvVar); /* Update bvar_list. */ bvar_type bv = array_fetch(bvar_type, bvar_list, bddId); bv.mvar_id = -1; array_insert(bvar_type, bvar_list, bddId, bv); } /* mdd_var_expunge_bdd_variable */ /*---------------------------------------------------------------------------*/ /* Static function prototypes */ /*---------------------------------------------------------------------------*/