00001
00021 #include "rwr.h"
00022
00026
00030
00042 void Rwr_Trav2_rec( Rwr_Man_t * p, Rwr_Node_t * pNode, int * pVolume )
00043 {
00044 if ( pNode->fUsed || pNode->TravId == p->nTravIds )
00045 return;
00046 pNode->TravId = p->nTravIds;
00047 (*pVolume)++;
00048 Rwr_Trav2_rec( p, Rwr_Regular(pNode->p0), pVolume );
00049 Rwr_Trav2_rec( p, Rwr_Regular(pNode->p1), pVolume );
00050 }
00051
00063 void Rwr_GetBushVolume( Rwr_Man_t * p, int Entry, int * pVolume, int * pnFuncs )
00064 {
00065 Rwr_Node_t * pNode;
00066 int Volume = 0;
00067 int nFuncs = 0;
00068 Rwr_ManIncTravId( p );
00069 for ( pNode = p->pTable[Entry]; pNode; pNode = pNode->pNext )
00070 {
00071 if ( pNode->uTruth != p->puCanons[pNode->uTruth] )
00072 continue;
00073 nFuncs++;
00074 Rwr_Trav2_rec( p, pNode, &Volume );
00075 }
00076 *pVolume = Volume;
00077 *pnFuncs = nFuncs;
00078 }
00079
00091 int Rwr_GetBushSumOfVolumes( Rwr_Man_t * p, int Entry )
00092 {
00093 Rwr_Node_t * pNode;
00094 int Volume, VolumeTotal = 0;
00095 for ( pNode = p->pTable[Entry]; pNode; pNode = pNode->pNext )
00096 {
00097 if ( pNode->uTruth != p->puCanons[pNode->uTruth] )
00098 continue;
00099 Volume = 0;
00100 Rwr_ManIncTravId( p );
00101 Rwr_Trav2_rec( p, pNode, &Volume );
00102 VolumeTotal += Volume;
00103 }
00104 return VolumeTotal;
00105 }
00106
00118 void Rwr_NodePrint_rec( FILE * pFile, Rwr_Node_t * pNode )
00119 {
00120 assert( !Rwr_IsComplement(pNode) );
00121
00122 if ( pNode->Id == 0 )
00123 {
00124 fprintf( pFile, "Const1" );
00125 return;
00126 }
00127
00128 if ( pNode->Id < 5 )
00129 {
00130 fprintf( pFile, "%c", 'a' + pNode->Id - 1 );
00131 return;
00132 }
00133
00134 if ( Rwr_IsComplement(pNode->p0) )
00135 {
00136 if ( Rwr_Regular(pNode->p0)->Id < 5 )
00137 {
00138 Rwr_NodePrint_rec( pFile, Rwr_Regular(pNode->p0) );
00139 fprintf( pFile, "\'" );
00140 }
00141 else
00142 {
00143 fprintf( pFile, "(" );
00144 Rwr_NodePrint_rec( pFile, Rwr_Regular(pNode->p0) );
00145 fprintf( pFile, ")\'" );
00146 }
00147 }
00148 else
00149 {
00150 if ( Rwr_Regular(pNode->p0)->Id < 5 )
00151 {
00152 Rwr_NodePrint_rec( pFile, Rwr_Regular(pNode->p0) );
00153 }
00154 else
00155 {
00156 fprintf( pFile, "(" );
00157 Rwr_NodePrint_rec( pFile, Rwr_Regular(pNode->p0) );
00158 fprintf( pFile, ")" );
00159 }
00160 }
00161
00162 if ( pNode->fExor )
00163 fprintf( pFile, "+" );
00164
00165 if ( Rwr_IsComplement(pNode->p1) )
00166 {
00167 if ( Rwr_Regular(pNode->p1)->Id < 5 )
00168 {
00169 Rwr_NodePrint_rec( pFile, Rwr_Regular(pNode->p1) );
00170 fprintf( pFile, "\'" );
00171 }
00172 else
00173 {
00174 fprintf( pFile, "(" );
00175 Rwr_NodePrint_rec( pFile, Rwr_Regular(pNode->p1) );
00176 fprintf( pFile, ")\'" );
00177 }
00178 }
00179 else
00180 {
00181 if ( Rwr_Regular(pNode->p1)->Id < 5 )
00182 {
00183 Rwr_NodePrint_rec( pFile, Rwr_Regular(pNode->p1) );
00184 }
00185 else
00186 {
00187 fprintf( pFile, "(" );
00188 Rwr_NodePrint_rec( pFile, Rwr_Regular(pNode->p1) );
00189 fprintf( pFile, ")" );
00190 }
00191 }
00192 }
00193
00205 void Rwr_NodePrint( FILE * pFile, Rwr_Man_t * p, Rwr_Node_t * pNode )
00206 {
00207 unsigned uTruth;
00208 fprintf( pFile, "%5d : ", pNode->Id );
00209 Extra_PrintHex( pFile, pNode->uTruth, 4 );
00210 fprintf( pFile, " tt=" );
00211 uTruth = pNode->uTruth;
00212 Extra_PrintBinary( pFile, &uTruth, 16 );
00213
00214
00215
00216 fprintf( pFile, " lev=%d", pNode->Level );
00217 fprintf( pFile, " vol=%d", pNode->Volume );
00218 fprintf( pFile, " " );
00219 Rwr_NodePrint_rec( pFile, pNode );
00220 fprintf( pFile, "\n" );
00221 }
00222
00234 void Rwr_ManPrint( Rwr_Man_t * p )
00235 {
00236 FILE * pFile;
00237 Rwr_Node_t * pNode;
00238 unsigned uTruth;
00239 int Limit, Counter, Volume, nFuncs, i;
00240 pFile = fopen( "graph_lib.txt", "w" );
00241 Counter = 0;
00242 Limit = (1 << 16);
00243 for ( i = 0; i < Limit; i++ )
00244 {
00245 if ( p->pTable[i] == NULL )
00246 continue;
00247 if ( i != p->puCanons[i] )
00248 continue;
00249 fprintf( pFile, "\nClass %3d. Func %6d. ", p->pMap[i], Counter++ );
00250 Rwr_GetBushVolume( p, i, &Volume, &nFuncs );
00251 fprintf( pFile, "Roots = %3d. Vol = %3d. Sum = %3d. ", nFuncs, Volume, Rwr_GetBushSumOfVolumes(p, i) );
00252 uTruth = i;
00253 Extra_PrintBinary( pFile, &uTruth, 16 );
00254 fprintf( pFile, "\n" );
00255 for ( pNode = p->pTable[i]; pNode; pNode = pNode->pNext )
00256 if ( pNode->uTruth == p->puCanons[pNode->uTruth] )
00257 Rwr_NodePrint( pFile, p, pNode );
00258 }
00259 fclose( pFile );
00260 }
00261
00265
00266