00001
00021 #include "msatInt.h"
00022
00026
00027 static int Msat_SolverSortCompare( Msat_Clause_t ** ppC1, Msat_Clause_t ** ppC2 );
00028
00029
00030 static double drand(double seed) {
00031 int q;
00032 seed *= 1389796;
00033 q = (int)(seed / 2147483647);
00034 seed -= (double)q * 2147483647;
00035 return seed / 2147483647; }
00036
00037
00038 static int irand(double seed, int size) {
00039 return (int)(drand(seed) * size); }
00040
00041 static void Msat_SolverSort( Msat_Clause_t ** array, int size, double seed );
00042
00046
00058 void Msat_SolverSortDB( Msat_Solver_t * p )
00059 {
00060 Msat_ClauseVec_t * pVecClauses;
00061 Msat_Clause_t ** pLearned;
00062 int nLearned;
00063
00064 pVecClauses = Msat_SolverReadLearned( p );
00065 nLearned = Msat_ClauseVecReadSize( pVecClauses );
00066 pLearned = Msat_ClauseVecReadArray( pVecClauses );
00067
00068
00069
00070
00071 Msat_SolverSort( pLearned, nLearned, 91648253 );
00072
00073
00074
00075
00076
00077
00078
00079
00080 }
00081
00093 int Msat_SolverSortCompare( Msat_Clause_t ** ppC1, Msat_Clause_t ** ppC2 )
00094 {
00095 float Value1 = Msat_ClauseReadActivity( *ppC1 );
00096 float Value2 = Msat_ClauseReadActivity( *ppC2 );
00097 if ( Value1 < Value2 )
00098 return -1;
00099 if ( Value1 > Value2 )
00100 return 1;
00101 return 0;
00102 }
00103
00104
00116 void Msat_SolverSortSelection( Msat_Clause_t ** array, int size )
00117 {
00118 Msat_Clause_t * tmp;
00119 int i, j, best_i;
00120 for ( i = 0; i < size-1; i++ )
00121 {
00122 best_i = i;
00123 for (j = i+1; j < size; j++)
00124 {
00125 if ( Msat_ClauseReadActivity(array[j]) < Msat_ClauseReadActivity(array[best_i]) )
00126 best_i = j;
00127 }
00128 tmp = array[i]; array[i] = array[best_i]; array[best_i] = tmp;
00129 }
00130 }
00131
00144 void Msat_SolverSort( Msat_Clause_t ** array, int size, double seed )
00145 {
00146 if (size <= 15)
00147 Msat_SolverSortSelection( array, size );
00148 else
00149 {
00150 Msat_Clause_t * pivot = array[irand(seed, size)];
00151 Msat_Clause_t * tmp;
00152 int i = -1;
00153 int j = size;
00154
00155 for(;;)
00156 {
00157 do i++; while( Msat_ClauseReadActivity(array[i]) < Msat_ClauseReadActivity(pivot) );
00158 do j--; while( Msat_ClauseReadActivity(pivot) < Msat_ClauseReadActivity(array[j]) );
00159
00160 if ( i >= j ) break;
00161
00162 tmp = array[i]; array[i] = array[j]; array[j] = tmp;
00163 }
00164 Msat_SolverSort(array , i , seed);
00165 Msat_SolverSort(&array[i], size-i, seed);
00166 }
00167 }
00168
00172
00173