abc/src/bdd/cudd/cuddReorder.c
/**Function********************************************************************

  Synopsis    [Reorders variables according to a given permutation.]

  Description [Reorders variables according to a given permutation.
  The i-th permutation array contains the index of the variable that
  should be brought to the i-th level. ddShuffle assumes that no
  dead nodes are present and that the interaction matrix is properly
  initialized.  The reordering is achieved by a series of upward sifts.
  Returns 1 if successful; 0 otherwise.]

  SideEffects [None]

  SeeAlso []

******************************************************************************/
Function
Synopsis    [Reorders variables according to a given permutation.]

Description [Reorders variables according to a given permutation.
The i-th permutation array contains the index of the variable that
should be brought to the i-th level. ddShuffle assumes that no
dead nodes are present and that the interaction matrix is properly
initialized.  The reordering is achieved by a series of upward sifts.
Returns 1 if successful; 0 otherwise.]




Function Synopsis [ Reorders variables according to a given permutation . ] Description [ Reorders variables according to a given permutation . The i - th permutation array contains the index of the variable that should be brought to the i - th level . ddShuffle assumes that no dead nodes are present and that the interaction matrix is properly initialized . The reordering is achieved by a series of upward sifts . Returns 1 if successful ; 0 otherwise . ]
static int
ddShuffle(
  DdManager * table,
  int * permutation)
{
    int         index;
    int         level;
    int         position;
    int         numvars;
    int         result;
#ifdef DD_STATS
    long        localTime;
    int         initialSize;
    int         finalSize;
    int         previousSize;
#endif
    ddTotalNumberSwapping = 0;
#ifdef DD_STATS
    localTime = util_cpu_time();
    initialSize = table->keys - table->isolated;
    (void) fprintf(table->out,"#:I_SHUFFLE %8d: initial size\n",
                   initialSize);
    ddTotalNISwaps = 0;
#endif
    numvars = table->size;
    for (level = 0; level < numvars; level++) {
        index = permutation[level];
        position = table->perm[index];
#ifdef DD_STATS
        previousSize = table->keys - table->isolated;
#endif
        result = ddSiftUp(table,position,level);
        if (!result) return(0);
#ifdef DD_STATS
        if (table->keys < (unsigned) previousSize + table->isolated) {
            (void) fprintf(table->out,"-");
        } else if (table->keys > (unsigned) previousSize + table->isolated) {
            (void) fprintf(table->out,"+");     
        } else {
            (void) fprintf(table->out,"=");
        }
        fflush(table->out);
#endif
    }
#ifdef DD_STATS
    (void) fprintf(table->out,"\n");
    finalSize = table->keys - table->isolated;
    (void) fprintf(table->out,"#:F_SHUFFLE %8d: final size\n",finalSize);
    (void) fprintf(table->out,"#:T_SHUFFLE %8g: total time (sec)\n",
        ((double)(util_cpu_time() - localTime)/1000.0));
    (void) fprintf(table->out,"#:N_SHUFFLE %8d: total swaps\n",
                   ddTotalNumberSwapping);
    (void) fprintf(table->out,"#:M_SHUFFLE %8d: NI swaps\n",ddTotalNISwaps);
#endif
    return(1);
}
static int ddShuffle ( DdManager * table , int * permutation ) { int index ; int level ; int position ; int numvars ; int result ; #ifdef DD_STATS long localTime ; int initialSize ; int finalSize ; int previousSize ; #endif ddTotalNumberSwapping = 0 ; #ifdef DD_STATS localTime = util_cpu_time ( ) ; initialSize = table -> keys - table -> isolated ; ( void ) fprintf ( table -> out , " \n " , initialSize ) ; ddTotalNISwaps = 0 ; #endif numvars = table -> size ; for ( level = 0 ; level < numvars ; level ++ ) { index = permutation [ level ] ; position = table -> perm [ index ] ; #ifdef DD_STATS previousSize = table -> keys - table -> isolated ; #endif result = ddSiftUp ( table , position , level ) ; if ( ! result ) return ( 0 ) ; #ifdef DD_STATS if ( table -> keys < ( unsigned ) previousSize + table -> isolated ) { ( void ) fprintf ( table -> out , " " ) ; } else if ( table -> keys > ( unsigned ) previousSize + table -> isolated ) { ( void ) fprintf ( table -> out , " " ) ; } else { ( void ) fprintf ( table -> out , " " ) ; } fflush ( table -> out ) ; #endif } #ifdef DD_STATS ( void ) fprintf ( table -> out , " \n " ) ; finalSize = table -> keys - table -> isolated ; ( void ) fprintf ( table -> out , " \n " , finalSize ) ; ( void ) fprintf ( table -> out , " \n " , ( ( double ) ( util_cpu_time ( ) - localTime ) / 1000.0 ) ) ; ( void ) fprintf ( table -> out , " \n " , ddTotalNumberSwapping ) ; ( void ) fprintf ( table -> out , " \n " , ddTotalNISwaps ) ; #endif return ( 1 ) ; }
Function
Synopsis    [Reorders variables according to a given permutation.]
Function Synopsis [ Reorders variables according to a given permutation . ]
/* should never happen */