int DPLL_add_binary_implications( int lit1, int lit2 ) { int i, *bImp; if( IS_FIXED(lit1) ) { if( !FIXED_ON_COMPLEMENT(lit1) ) return SAT; else if( IS_FIXED(lit2) ) return( !FIXED_ON_COMPLEMENT(lit2) ); else return look_fix_binary_implications(lit2); } else if( IS_FIXED(lit2) ) { if( !FIXED_ON_COMPLEMENT(lit2) ) return SAT; else return look_fix_binary_implications(lit1); } #ifdef BIEQ while( (VeqDepends[ NR(lit1) ] != INDEPENDENT) && (VeqDepends[ NR(lit1) ] != EQUIVALENT) ) lit1 = VeqDepends[ NR(lit1) ] * SGN(lit1); while( (VeqDepends[ NR(lit2) ] != INDEPENDENT) && (VeqDepends[ NR(lit2) ] != EQUIVALENT) ) lit2 = VeqDepends[ NR(lit2) ] * SGN(lit2); if( lit1 == -lit2 ) return SAT; if( lit1 == lit2 ) return look_fix_binary_implications(lit1); #endif STAMP_IMPLICATIONS( -lit1 ); if( bImp_stamps[ -lit2 ] == current_bImp_stamp ) return look_fix_binary_implications( lit1 ); if( bImp_stamps[lit2] != current_bImp_stamp ) { int _result; bImp_stamps[ BinaryImp[-lit1][ BinaryImp[-lit1][0] - 1] ] = current_bImp_stamp; _result = DPLL_add_compensation_resolvents( lit1, lit2 ); if( _result != UNKNOWN ) return _result; STAMP_IMPLICATIONS( -lit2 ); if( bImp_stamps[ -lit1 ] == current_bImp_stamp ) return look_fix_binary_implications( lit2 ); _result = DPLL_add_compensation_resolvents( lit2, lit1 ); if( _result != UNKNOWN ) return _result; ADD_BINARY_IMPLICATIONS( lit1, lit2 ); } return SAT; }
inline int DPLL_add_compensation_resolvents( const int lit1, const int lit2 ) { int i, lit, *bImp = BIMP_START(lit2); CHECK_NODE_STAMP( -lit1 ); CHECK_BIMP_UPPERBOUND( -lit1, BinaryImp[ lit2 ][ 0 ] ); for (i = BIMP_ELEMENTS; --i; ) { lit = *(bImp++); if( IS_FIXED(lit) ) continue; if( bImp_stamps[ -lit ] == current_bImp_stamp ) return look_fix_binary_implications( lit1 ); #ifdef COMPENSATION_RESOLVENTS if( bImp_stamps[ lit ] != current_bImp_stamp ) { CHECK_NODE_STAMP( -lit ); CHECK_BIMP_BOUND ( -lit ); ADD_BINARY_IMPLICATIONS( lit, lit1 ); } #endif } return UNKNOWN; }
int look_IFIUP( const int nrval ) { int *local_stackp; /* reset counters and stacks */ new_binaries = 0; weighted_new_binaries = 0.0; if( kSAT_flag ) look_backtrack(); else end_fixstackp = look_fixstackp; local_stackp = end_fixstackp; look_resstackp = look_resstack; if( look_fix_binary_implications(nrval) == UNSAT ) { end_fixstackp = local_stackp; return UNSAT; } return look_IUP( nrval, local_stackp ); }
int IFIUP( const int nrval, const int forced_or_branch_flag ) { int i, *_forced_literal_array, _forced_literals, *local_fixstackp; local_fixstackp = rstackp; end_fixstackp = rstackp; currentTimeStamp = BARY_MAX; current_bImp_stamp = 1; for( i = nrofvars; i >= 1; i-- ) { bImp_stamps[ i ] = 0; bImp_stamps[ -i ] = 0; } if( forced_or_branch_flag == FIX_FORCED_LITERALS ) { get_forced_literals( &_forced_literal_array, &_forced_literals ); for( i = 0; i < _forced_literals; i++ ) if( look_fix_binary_implications(*(_forced_literal_array++)) == UNSAT ) { MainDead( local_fixstackp ); return UNSAT; } } #ifdef DISTRIBUTION else if( forced_or_branch_flag == FIX_RECORDED_LITERALS ) { get_recorded_literals( &_forced_literal_array, &_forced_literals ); for( i = 0; i < _forced_literals; i++ ) if( look_fix_binary_implications(*(_forced_literal_array++)) == UNSAT ) { MainDead( local_fixstackp ); return UNSAT; } } #endif else { if( look_fix_binary_implications( nrval ) == UNSAT ) { MainDead( local_fixstackp ); return UNSAT; } } while( local_fixstackp < end_fixstackp ) if( DPLL_update_datastructures(*(local_fixstackp++)) == UNSAT ) { MainDead( local_fixstackp ); return UNSAT; } rstackp = end_fixstackp; return SAT; }
/* inline void compensate_for_reduction( const int nrval ) { int i, lit1, lit2, *tImp = TernaryImp[ nrval ]; for( i = TernaryImpSize[ nrval ]; i > 0; i-- ) { lit1 = *(tImp++); lit2 = *(tImp++); if( IS_FIXED(lit1) ) { if( !IS_FIXED(lit2) && FIXED_ON_COMPLEMENT(lit1) ) { new_binaries--; weighted_new_binaries -= diff[ nrval ] * diff[ lit2 ]; } } if( IS_FIXED(lit2) && FIXED_ON_COMPLEMENT(lit2) ) { new_binaries--; weighted_new_binaries -= diff[ nrval ] * diff[ lit1 ]; } } } */ inline int add_constraint_resolvent( const int nrval ) { #ifdef ADD_CONSTRAINT_RESOLVENTS *( look_resstackp++ ) = nrval; #endif // compensate_for_reduction( nrval ); return look_fix_binary_implications( nrval ); }
inline int add_hyper_binary( const int nrval, const int dominator ) { #ifdef ADD_HYPER_BINARIES hyper_bins++; if( (hyper_bins % 100000) == 0 ) printf("c found hyper binary resolvent %i in node %i with literal %i\n", hyper_bins, nodeCount, nrval ); *( look_resstackp++ ) = nrval; #endif return look_fix_binary_implications( nrval ); }
int DPLL_propagate_binary_equivalence( const int bieq ) { int i, j, ceqsubst; int lit1, lit2; int value; lit1 = Ceq[ bieq ][ 0 ]; lit2 = Ceq[ bieq ][ 1 ]; value = CeqValues[ bieq ]; for( i = 1; i < Veq[ lit1 ][ 0 ]; i++ ) { ceqsubst = Veq[ lit1 ][ i ]; for( j = 1; j < Veq[ lit2 ][ 0 ]; j++ ) { if( (ceqsubst == Veq[ lit2 ][ j ]) ) { fixEq( lit1, i, 1); PUSH( sub, lit1 ); fixEq( lit2, j, value); PUSH( sub, lit2 * value ); if( CeqSizes[ ceqsubst ] == 0 ) if (CeqValues[ ceqsubst ] == -1 ) return UNSAT; if( CeqSizes[ ceqsubst ] == 1 ) if( !look_fix_binary_implications(Ceq[ceqsubst][0] * CeqValues[ceqsubst]) ) return UNSAT; if( CeqSizes[ ceqsubst ] == 2 ) PUSH( newbi, ceqsubst ); i--; break; } } } if( (DPLL_add_binary_implications( lit1, -lit2 * value ) && DPLL_add_binary_implications( -lit1, lit2 * value )) == UNSAT ) return UNSAT; return SAT; }
inline int DPLL_update_datastructures( const int nrval ) { int i, *bImp; #ifdef EQ int nr, ceqidx; nr = NR( nrval ); PUSH( sub, STACK_BLOCK ); #endif // printf("FIXING %i\n", nrval ); FIX( nrval, NARY_MAX ); // diff[ nrval ] = 0; // diff[ -nrval ] = 0; #ifdef TIMEOUT if( (int) clock() > CLOCKS_PER_SEC * TIMEOUT ) return SAT; #endif unitResolveCount++; reduce_freevars( nrval ); bImp = BIMP_START(-nrval); for( i = BIMP_ELEMENTS; --i; ) bImp_satisfied[ -(*(bImp++)) ]++; // Update eager datastructures if( kSAT_flag == 0 ) { #ifdef GLOBAL_AUTARKY int lit1, lit2; int *tImp = TernaryImp[ nrval ] + 2 * TernaryImpSize[ nrval ]; for( i = TernaryImpLast[ nrval ] - TernaryImpSize[ nrval ]; i--; ) { lit1 = *(tImp++); lit2 = *(tImp++); if( IS_REDUCED_TIMP( lit1, lit2 ) ) TernaryImpReduction[ lit1 ]--; else if( IS_REDUCED_TIMP( lit2, lit1 ) ) TernaryImpReduction[ lit2 ]--; } #endif remove_satisfied_implications( nrval ); remove_satisfied_implications( -nrval ); #ifdef GLOBAL_AUTARKY tImp = TernaryImp[ -nrval ]; for( i = tmpTernaryImpSize[ -nrval ]; i--; ) { TernaryImpReduction[ *(tImp++) ]++; TernaryImpReduction[ *(tImp++) ]++; } #endif } else { int *clauseSet, clause_index; // REMOVE SATISFIED CLAUSES clauseSet = clause_set[ nrval ]; while( *clauseSet != LAST_CLAUSE ) { clause_index = *(clauseSet++); // if clause is not satisfied if( clause_length[ clause_index ] < SAT_INCREASE - 2 ) { #ifdef GLOBAL_AUTARKY // if clause is already been reduced if( clause_reduction[ clause_index ] > 0 ) { int *literals = clause_list[ clause_index ]; while( *literals != LAST_LITERAL ) TernaryImpReduction[ *(literals++) ]--; } clause_SAT_flag[ clause_index ] = 1; #endif reduce_big_occurences( clause_index, nrval ); } clause_length[ clause_index ] += SAT_INCREASE; } #ifdef GLOBAL_AUTARKY for( i = 0; i < btb_size[ nrval ]; ++i ) { // decrease literal reduction int *literals = clause_list[ big_to_binary[ nrval ][ i ] ], flag = 0; while( *literals != LAST_LITERAL ) { if( timeAssignments[ *(literals++) ] == NARY_MAX ) { if( flag == 1 ) { flag = 0; break; } flag = 1; } } if( flag == 1 ) { clause_SAT_flag[ big_to_binary[ nrval ][ i ] ] = 1; literals = clause_list[ big_to_binary[ nrval ][ i ] ]; while( *literals != LAST_LITERAL ) TernaryImpReduction[ *(literals++) ]--; } } #endif } #ifdef GLOBAL_AUTARKY #ifdef EQ tmpEqImpSize[ nr ] = Veq[ nr ][ 0 ]; for( i = 1; i < Veq[ nr ][0]; i++ ) { int j; ceqidx = Veq[ nr ][i]; for( j = 0; j < CeqSizes[ ceqidx ]; j++ ) TernaryImpReduction[ Ceq[ceqidx][j] ]++; } #endif #endif if( kSAT_flag ) { int UNSAT_flag, *clauseSet, clause_index; int first_lit, *literals, lit; // REMOVE UNSATISFIED LITERALS UNSAT_flag = 0; clauseSet = clause_set[ -nrval ]; while( *clauseSet != LAST_CLAUSE ) { clause_index = *(clauseSet++); #ifdef GLOBAL_AUTARKY // if clause is for the first time reduced if( clause_reduction[ clause_index ] == 0 ) { int *literals = clause_list[ clause_index ]; while( *literals != LAST_LITERAL ) TernaryImpReduction[ *(literals++) ]++; clause_red_depth[ clause_index ] = depth; } clause_reduction[ clause_index ]++; #endif clause_length[ clause_index ]--; #ifdef HIDIFF HiRemoveLiteral( clause_index, nrval ); #endif if( clause_length[ clause_index ] == 2 ) { #ifdef GLOBAL_AUTARKY literals = clause_list[ clause_index ]; while( *literals != LAST_LITERAL ) { lit = *(literals)++; if( timeAssignments[ lit ] < NARY_MAX ) big_to_binary[ lit ][ btb_size[ lit ]++ ] = clause_index; } #endif reduce_big_occurences( clause_index, -nrval ); clause_length[ clause_index ] = SAT_INCREASE; if( UNSAT_flag == 0 ) { first_lit = 0; literals = clause_list[ clause_index ]; while( *literals != LAST_LITERAL ) { lit = *(literals)++; if( IS_NOT_FIXED( lit ) ) { if( first_lit == 0 ) first_lit = lit; else { UNSAT_flag = !DPLL_add_binary_implications( first_lit, lit ); goto next_clause; } } else if( !FIXED_ON_COMPLEMENT(lit) ) goto next_clause; } if( first_lit != 0 ) UNSAT_flag = !look_fix_binary_implications( first_lit ); else UNSAT_flag = 1; } next_clause:; } } if( UNSAT_flag ) return UNSAT; } if( kSAT_flag == 0 ) { int *tImp = TernaryImp[ -nrval ]; for( i = tmpTernaryImpSize[ -nrval ] - 1; i >= 0; i-- ) { int lit1 = *(tImp++); int lit2 = *(tImp++); if( DPLL_add_binary_implications( lit1, lit2 ) == UNSAT ) return UNSAT; } } #ifdef EQ while( Veq[ nr ][ 0 ] > 1 ) { ceqidx = Veq[ nr ][ 1 ]; fixEq( nr, 1, SGN(nrval)); PUSH( sub, nrval ); if( CeqSizes[ ceqidx ] == 2 ) { if ( DPLL_propagate_binary_equivalence( ceqidx ) == UNSAT ) return UNSAT; } else if( CeqSizes[ ceqidx ] == 1 ) { if( look_fix_binary_implications(Ceq[ceqidx][0]*CeqValues[ceqidx]) == UNSAT ) return UNSAT; } } while( newbistackp != newbistack ) { POP( newbi, ceqidx ); if( CeqSizes[ ceqidx ] == 2 ) if ( DPLL_propagate_binary_equivalence( ceqidx ) == UNSAT ) return UNSAT; } #endif return SAT; }