00001
00019 #include "fraigInt.h"
00020
00024
00028
00041 void Fraig_ManAddChoices( Fraig_Man_t * pMan, int fVerbose, int nLimit )
00042 {
00043
00044 char Buffer[100];
00045 int clkTotal = clock();
00046 int i, nNodesBefore, nNodesAfter, nInputs, nMaxNodes;
00047 int nDistributive;
00048 Fraig_Node_t *pNode, *pRepr;
00049 Fraig_Node_t *pX, *pA, *pB, *pC, *pN, *pT;
00050 int fShortCut = 0;
00051
00052 nDistributive = 0;
00053
00054
00055
00056
00057 if (fShortCut) Fraig_ManSetFuncRed( pMan, 0 );
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 nNodesBefore = Fraig_ManReadNodeNum( pMan );
00071 nInputs = Fraig_ManReadInputNum( pMan );
00072 nMaxNodes = nInputs + nLimit * ( nNodesBefore - nInputs );
00073
00074 printf ("Limit = %d, Before = %d\n", nMaxNodes, nNodesBefore );
00075
00076 if (0)
00077 {
00078 char buffer[128];
00079 sprintf (buffer, "test" );
00080
00081 }
00082
00083
00084 Fraig_ManCheckConsistency( pMan );
00085
00086 for ( i = nInputs+1; (i < Fraig_ManReadNodeNum( pMan ))
00087 && (nMaxNodes > Fraig_ManReadNodeNum( pMan )); ++i )
00088 {
00089
00090
00091
00092 pNode = Fraig_ManReadIthNode( pMan, i );
00093 assert ( pNode );
00094
00095 pRepr = pNode->pRepr ? pNode->pRepr : pNode;
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 pX = Fraig_NodeReadOne(pNode);
00110 pC = Fraig_NodeReadTwo(pNode);
00111 if (Fraig_NodeIsAnd(pX) && !Fraig_IsComplement(pX))
00112 {
00113 pA = Fraig_NodeReadOne(Fraig_Regular(pX));
00114 pB = Fraig_NodeReadTwo(Fraig_Regular(pX));
00115
00116
00117
00118
00119
00120 if (fShortCut)
00121 {
00122 pT = Fraig_NodeAnd(pMan, pB, pC);
00123 if ( !pT->pRepr )
00124 {
00125 pN = Fraig_NodeAnd(pMan, pA, pT);
00126
00127 }
00128 }
00129 else
00130 pN = Fraig_NodeAnd(pMan, pA, Fraig_NodeAnd(pMan, pB, pC));
00131
00132
00133
00134 if (fShortCut)
00135 {
00136 pT = Fraig_NodeAnd(pMan, pA, pC);
00137 if ( !pT->pRepr )
00138 {
00139 pN = Fraig_NodeAnd(pMan, pB, pT);
00140
00141 }
00142 }
00143 else
00144 pN = Fraig_NodeAnd(pMan, pB, Fraig_NodeAnd(pMan, pA, pC));
00145
00146 }
00147
00148
00149
00150 pA = Fraig_NodeReadOne(pNode);
00151 pX = Fraig_NodeReadTwo(pNode);
00152 if (Fraig_NodeIsAnd(pX) && !Fraig_IsComplement(pX))
00153 {
00154 pB = Fraig_NodeReadOne(Fraig_Regular(pX));
00155 pC = Fraig_NodeReadTwo(Fraig_Regular(pX));
00156
00157
00158
00159
00160
00161 if (fShortCut)
00162 {
00163 pT = Fraig_NodeAnd(pMan, pA, pB);
00164 if ( !pT->pRepr )
00165 {
00166 pN = Fraig_NodeAnd(pMan, pC, pT);
00167
00168 }
00169 }
00170 else
00171 pN = Fraig_NodeAnd(pMan, Fraig_NodeAnd(pMan, pA, pB), pC);
00172
00173
00174 if (fShortCut)
00175 {
00176 pT = Fraig_NodeAnd(pMan, pA, pC);
00177 if ( !pT->pRepr )
00178 {
00179 pN = Fraig_NodeAnd(pMan, pB, pT);
00180
00181 }
00182 }
00183 else
00184 pN = Fraig_NodeAnd(pMan, Fraig_NodeAnd(pMan, pA, pC), pB);
00185
00186 }
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 if ( i % 1000 == 0 )
00220 {
00221 sprintf( Buffer, "Adding choice %6d...", i - nNodesBefore );
00222
00223 }
00224 }
00225
00226
00227
00228 Fraig_ManCheckConsistency( pMan );
00229
00230 nNodesAfter = Fraig_ManReadNodeNum( pMan );
00231 printf ( "Nodes before = %6d. Nodes with associative choices = %6d. Increase = %4.2f %%.\n",
00232 nNodesBefore, nNodesAfter, ((float)(nNodesAfter - nNodesBefore)) * 100.0/(nNodesBefore - nInputs) );
00233 printf ( "Distributive = %d\n", nDistributive );
00234
00235 }
00236
00240
00241