00001
00021 #include "rwr.h"
00022
00026
00027 typedef struct Rwr_Man4_t_ Rwr_Man4_t;
00028 struct Rwr_Man4_t_
00029 {
00030
00031 int nFuncs;
00032 unsigned short * puCanons;
00033 int * pnCounts;
00034 int nConsidered;
00035 int nClasses;
00036 };
00037
00038 typedef struct Rwr_Man5_t_ Rwr_Man5_t;
00039 struct Rwr_Man5_t_
00040 {
00041
00042 stmm_table * tTableNN;
00043 stmm_table * tTableNPN;
00044 };
00045
00046 static Rwr_Man4_t * s_pManRwrExp4 = NULL;
00047 static Rwr_Man5_t * s_pManRwrExp5 = NULL;
00048
00052
00064 void Rwt_Man4ExploreStart()
00065 {
00066 Rwr_Man4_t * p;
00067 p = ALLOC( Rwr_Man4_t, 1 );
00068 memset( p, 0, sizeof(Rwr_Man4_t) );
00069
00070 p->nFuncs = (1<<16);
00071
00072 Extra_Truth4VarNPN( &p->puCanons, NULL, NULL, NULL );
00073
00074 p->pnCounts = ALLOC( int, p->nFuncs );
00075 memset( p->pnCounts, 0, sizeof(int) * p->nFuncs );
00076 s_pManRwrExp4 = p;
00077 }
00078
00090 void Rwt_Man4ExploreCount( unsigned uTruth )
00091 {
00092 assert( uTruth < (1<<16) );
00093 s_pManRwrExp4->pnCounts[ s_pManRwrExp4->puCanons[uTruth] ]++;
00094 }
00095
00107 void Rwt_Man4ExplorePrint()
00108 {
00109 FILE * pFile;
00110 int i, CountMax, CountWrite, nCuts, nClasses;
00111 int * pDistrib;
00112 int * pReprs;
00113
00114 nCuts = nClasses = 0;
00115 CountMax = 0;
00116 for ( i = 0; i < s_pManRwrExp4->nFuncs; i++ )
00117 {
00118 if ( CountMax < s_pManRwrExp4->pnCounts[i] )
00119 CountMax = s_pManRwrExp4->pnCounts[i];
00120 nCuts += s_pManRwrExp4->pnCounts[i];
00121 if ( s_pManRwrExp4->pnCounts[i] > 0 )
00122 nClasses++;
00123 }
00124 printf( "Number of cuts considered = %8d.\n", nCuts );
00125 printf( "Classes occurring at least once = %8d.\n", nClasses );
00126
00127 pDistrib = ALLOC( int, CountMax + 1 );
00128 pReprs = ALLOC( int, CountMax + 1 );
00129 memset( pDistrib, 0, sizeof(int)*(CountMax + 1) );
00130 for ( i = 0; i < s_pManRwrExp4->nFuncs; i++ )
00131 {
00132 pDistrib[ s_pManRwrExp4->pnCounts[i] ]++;
00133 pReprs[ s_pManRwrExp4->pnCounts[i] ] = i;
00134 }
00135
00136 printf( "Occurence = %6d. Num classes = %4d. \n", 0, 2288-nClasses );
00137 for ( i = 1; i <= CountMax; i++ )
00138 if ( pDistrib[i] )
00139 {
00140 printf( "Occurence = %6d. Num classes = %4d. Repr = ", i, pDistrib[i] );
00141 Extra_PrintBinary( stdout, (unsigned*)&(pReprs[i]), 16 );
00142 printf( "\n" );
00143 }
00144 free( pDistrib );
00145 free( pReprs );
00146
00147 CountWrite = 0;
00148 pFile = fopen( "npnclass_stats4.txt", "w" );
00149 for ( i = 0; i < s_pManRwrExp4->nFuncs; i++ )
00150 if ( s_pManRwrExp4->pnCounts[i] > 0 )
00151 {
00152 Extra_PrintHex( pFile, i, 4 );
00153 fprintf( pFile, " %10d\n", s_pManRwrExp4->pnCounts[i] );
00154
00155 CountWrite++;
00156 }
00157 fclose( pFile );
00158 printf( "%d classes written into file \"%s\".\n", CountWrite, "npnclass_stats4.txt" );
00159 }
00160
00161
00162
00163
00175 void Rwt_Man5ExploreStart()
00176 {
00177 Rwr_Man5_t * p;
00178 p = ALLOC( Rwr_Man5_t, 1 );
00179 memset( p, 0, sizeof(Rwr_Man5_t) );
00180 p->tTableNN = stmm_init_table( st_numcmp, st_numhash );
00181 p->tTableNPN = stmm_init_table( st_numcmp, st_numhash );
00182 s_pManRwrExp5 = p;
00183
00184
00185
00186 }
00187
00199 void Rwt_Man5ExploreCount( unsigned uTruth )
00200 {
00201 int * pCounter;
00202 if ( !stmm_find_or_add( s_pManRwrExp5->tTableNN, (char *)uTruth, (char***)&pCounter ) )
00203 *pCounter = 0;
00204 (*pCounter)++;
00205 }
00206
00218 void Rwt_Man5ExplorePrint()
00219 {
00220 FILE * pFile;
00221 stmm_generator * gen;
00222 int i, CountMax, nCuts, Counter;
00223 int * pDistrib;
00224 unsigned * pReprs;
00225 unsigned uTruth, uTruthC;
00226 int clk = clock();
00227 Vec_Int_t * vClassesNN, * vClassesNPN;
00228
00229
00230 nCuts = 0;
00231 CountMax = 0;
00232 stmm_foreach_item( s_pManRwrExp5->tTableNN, gen, (char **)&uTruth, (char **)&Counter )
00233 {
00234 nCuts += Counter;
00235 if ( CountMax < Counter )
00236 CountMax = Counter;
00237 }
00238 printf( "Number of cuts considered = %8d.\n", nCuts );
00239 printf( "Classes occurring at least once = %8d.\n", stmm_count(s_pManRwrExp5->tTableNN) );
00240 printf( "The largest number of occurence = %8d.\n", CountMax );
00241
00242
00243 pDistrib = ALLOC( int, CountMax + 1 );
00244 pReprs = ALLOC( unsigned, CountMax + 1 );
00245 memset( pDistrib, 0, sizeof(int)*(CountMax + 1) );
00246 stmm_foreach_item( s_pManRwrExp5->tTableNN, gen, (char **)&uTruth, (char **)&Counter )
00247 {
00248 assert( Counter <= CountMax );
00249 pDistrib[ Counter ]++;
00250 pReprs[ Counter ] = uTruth;
00251 }
00252
00253 for ( i = 1; i <= CountMax; i++ )
00254 if ( pDistrib[i] )
00255 {
00256 printf( "Occurence = %6d. Num classes = %4d. Repr = ", i, pDistrib[i] );
00257 Extra_PrintBinary( stdout, pReprs + i, 32 );
00258 printf( "\n" );
00259 }
00260 free( pDistrib );
00261 free( pReprs );
00262
00263
00264
00265 vClassesNN = Vec_IntAlloc( stmm_count(s_pManRwrExp5->tTableNN) );
00266 stmm_foreach_item( s_pManRwrExp5->tTableNN, gen, (char **)&uTruth, NULL )
00267 Vec_IntPush( vClassesNN, (int)uTruth );
00268 Vec_IntSortUnsigned( vClassesNN );
00269
00270
00271 pFile = fopen( "nnclass_stats5.txt", "w" );
00272 Vec_IntForEachEntry( vClassesNN, uTruth, i )
00273 {
00274 if ( !stmm_lookup( s_pManRwrExp5->tTableNN, (char *)uTruth, (char **)&Counter ) )
00275 {
00276 assert( 0 );
00277 }
00278 Extra_PrintHex( pFile, uTruth, 5 );
00279 fprintf( pFile, " %10d\n", Counter );
00280 }
00281 fclose( pFile );
00282 printf( "%d classes written into file \"%s\".\n", vClassesNN->nSize, "nnclass_stats5.txt" );
00283
00284
00285 clk = clock();
00286
00287 Vec_IntForEachEntry( vClassesNN, uTruth, i )
00288 {
00289 int * pCounter;
00290 uTruthC = Extra_TruthCanonNPN( uTruth, 5 );
00291 if ( !stmm_find_or_add( s_pManRwrExp5->tTableNPN, (char *)uTruthC, (char***)&pCounter ) )
00292 *pCounter = 0;
00293 if ( !stmm_lookup( s_pManRwrExp5->tTableNN, (char *)uTruth, (char **)&Counter ) )
00294 {
00295 assert( 0 );
00296 }
00297 (*pCounter) += Counter;
00298 }
00299 printf( "The numbe of NPN classes = %d.\n", stmm_count(s_pManRwrExp5->tTableNPN) );
00300 PRT( "Computing NPN classes", clock() - clk );
00301
00302
00303 vClassesNPN = Vec_IntAlloc( stmm_count(s_pManRwrExp5->tTableNPN) );
00304 stmm_foreach_item( s_pManRwrExp5->tTableNPN, gen, (char **)&uTruth, NULL )
00305 Vec_IntPush( vClassesNPN, (int)uTruth );
00306 Vec_IntSortUnsigned( vClassesNPN );
00307
00308
00309 pFile = fopen( "npnclass_stats5.txt", "w" );
00310 Vec_IntForEachEntry( vClassesNPN, uTruth, i )
00311 {
00312 if ( !stmm_lookup( s_pManRwrExp5->tTableNPN, (char *)uTruth, (char **)&Counter ) )
00313 {
00314 assert( 0 );
00315 }
00316 Extra_PrintHex( pFile, uTruth, 5 );
00317 fprintf( pFile, " %10d\n", Counter );
00318 }
00319 fclose( pFile );
00320 printf( "%d classes written into file \"%s\".\n", vClassesNPN->nSize, "npnclass_stats5.txt" );
00321
00322
00323
00324
00325 }
00326
00327
00328
00332
00333