コード例 #1
0
ファイル: solver.c プロジェクト: xxyzzzq/open-wbo
int autarky_stamp( const int nrval )
{
	int i, *tImp, lit1, lit2, flag = 0;

	tImp = TernaryImp[ -nrval ];
	for( i = tmpTernaryImpSize[ -nrval ]; i--; )
	{
	    lit1 = *(tImp++);
	    lit2 = *(tImp++);
		
	    if( IS_NOT_FIXED(lit1) && IS_NOT_FIXED(lit2) )
	    {
		flag = 1;
		if( VeqDepends[ NR(lit1) ] == DUMMY )
		    autarky_stamp( lit1 );
		else
		    TernaryImpReduction[ lit1 ]++;

		if( VeqDepends[ NR(lit2) ] == DUMMY )
		    autarky_stamp( lit2 );
		else
		TernaryImpReduction[ lit2 ]++;
	    }
	}
	return flag;
}
コード例 #2
0
ファイル: solver.c プロジェクト: xxyzzzq/open-wbo
int analyze_autarky( )
{
#ifdef LOOKAHEAD_ON_DUMMIES
	int *tImp, lit1, lit2;
#endif
	int i, j, nrval, twice;
	int new_bImp_flag, _depth, *_rstackp;

	if( depth == 0 ) return 0;

        for( i = 1; i <= nrofvars; i++ )
        {
            TernaryImpReduction[  i ] = 0;
            TernaryImpReduction[ -i ] = 0;
        }

	new_bImp_flag = 0;
	_rstackp      = rstackp;
	for( _depth = depth; _depth > 0; _depth-- )
	{
	  for( twice = 1 ; twice <= 2; twice++ )	    
	    while( *(--_rstackp) != STACK_BLOCK )
	    {
		nrval = *(_rstackp);
#ifndef LOOKAHEAD_ON_DUMMIES
		if( autarky_stamp( nrval ) == 1 )
		    new_bImp_flag = 1;
#else
		tImp = TernaryImp[ -nrval ];
		for( i = tmpTernaryImpSize[ -nrval ]; i--; )
		{
		    lit1 = *(tImp++);
		    lit2 = *(tImp++);
		
		    if( IS_NOT_FIXED(lit1) && IS_NOT_FIXED(lit2) )
		    {
			new_bImp_flag = 1;
			TernaryImpReduction[ lit1 ]++;
			TernaryImpReduction[ lit2 ]++;
		    }
		}
#endif
	        for( j = 1; j < tmpEqImpSize[NR(nrval)]; j++ )
	        {
	            int ceqsubst = Veq[NR(nrval)][j];
	    	    for( i = 0; Ceq[ceqsubst][i] != NR(nrval); i++ )
		    {
			new_bImp_flag = 1;
			//printf("%i (%i)", Ceq[ ceqsubst][i], _depth );
	   	        TernaryImpReduction[ Ceq[ceqsubst][i] ]++;
		    }
	        }
	    }
	  if( new_bImp_flag == 1 ) break;
	}
	return _depth;
}
コード例 #3
0
inline int look_fix_big_clauses( const int nrval )
{
	int lit, *literals;
	int clause_index;

        int *clauseSet = clause_set[ -nrval ];
        while( *clauseSet != LAST_CLAUSE )
        {
            clause_index = *(clauseSet++);
            clause_length[ clause_index ]--;
#ifndef EVAL_VAR
	    new_binaries++;
#endif
#ifndef HIDIFF
	    weighted_new_binaries += size_diff[ clause_length[ clause_index ] ];
#endif
	    if( clause_length[ clause_index ] <= 1 )
	    {
            	literals = clause_list[ clause_index ];
                while( *literals != LAST_LITERAL )
                {
		    lit = *(literals)++;
                    if( IS_NOT_FIXED( lit ) )
		    {
		        if( add_hyper_binary( lit, 0 ) == SAT )
			    goto next_clause;
			break;
		    }
		    else if( !FIXED_ON_COMPLEMENT(lit) )
			goto next_clause;
		}
		while( *clauseSet != LAST_CLAUSE )
            	    clause_length[ *(clauseSet++) ]--;

		return UNSAT;
	    }

	    next_clause:;
	}
#ifdef HIDIFF
	weighted_new_binaries += hiSum[ -nrval ];
#endif
#ifdef EVAL_VAR
	    new_binaries++;
#endif
	return SAT;
}
コード例 #4
0
ファイル: solver.c プロジェクト: xxyzzzq/open-wbo
int checkSolution( )
{
	int i, *sizes;

//	printf("c checking solution %i\n", nodeCount );

	if( kSAT_flag ) sizes = big_occ;
	else 		sizes = TernaryImpSize;

	for ( i = 1; i <= original_nrofvars; i++ )
	    if( IS_NOT_FIXED( i ) )
	    {
	        if( sizes[  i ] > 0 ) { return UNSAT; }
	        if( sizes[ -i ] > 0 ) { return UNSAT; }
	        if( BinaryImp[  i ][ 0 ] > bImp_satisfied[  i ] ){ return UNSAT; }
	        if( BinaryImp[ -i ][ 0 ] > bImp_satisfied[ -i ] ){ return UNSAT; }
	    }

	return SAT;
}
コード例 #5
0
ファイル: solver.c プロジェクト: xxyzzzq/open-wbo
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;
}
コード例 #6
0
ファイル: lookahead.c プロジェクト: xxyzzzq/open-wbo
void ComputeDiffWeights( )
{
        int i, j, index, *Reductions, accuracy;
        int *tImp, *bImp, iteration_count = 1;
	float *tmpfloat;
	float pos, neg;
	float sum = 0.0, wnorm, factor, fsquare;

	diff     = _diff;
	diff_tmp = _diff_tmp;

	if( kSAT_flag )	Reductions = big_occ;
	else		Reductions = TernaryImpSize;

#ifdef EQ
        if( non_tautological_equivalences )
	{
            for( i = freevars - 1; i >= 0; i-- )
            {
	        sum = 0.0; 
            	index = freevarsArray[ i ];
		if( Veq[ index ][ 0 ] > 1 )
		    for( j = Veq[ index ][ 0 ] - 1; j > 0; j-- )
			sum += 2 * lengthWeight[ CeqSizes[ Veq[ index ][ j ] ] - 1 ];

		EqDiff[  index ] = sum + Reductions[  index ];
		EqDiff[ -index ] = sum + Reductions[ -index ];
	    }
	}
	else 
#endif
	if( (non_tautological_equivalences == 0 ) && (kSAT_flag == 0) && 
		(depth > ROOTSIZE) && (depth <= RECORDSIZE) )
	{   
	    diff = diff_depth[ depth - 1 ]; 
	    sum  = 2.0 * freevars;
	}
	else 
	{
	    sum = 0.0; 
            for( i = freevars - 1; i >= 0; i-- )
            {
         	index = freevarsArray[ i ];
#ifdef EQ
		if( non_tautological_equivalences )
		{
		    pos = 1 + EqDiff[ index ]; bImp = BinaryImp[ index ] + 2;
		    for(j = bImp[ -2 ] - 1; --j; ) pos += EqDiff[ -*(bImp++) ];
		    neg = 1 + EqDiff[ -index ]; bImp = BinaryImp[ -index ] + 2;
		    for(j = bImp[ -2 ] - 1; --j; ) neg += EqDiff[ -*(bImp++) ];
		}
		else
#endif
		if( kSAT_flag )
		{
#ifdef HIDIFF
		    pos = 1 + hiSum[ index ]; bImp = BinaryImp[ index ] + 2;
		    for(j = bImp[ -2 ] - 1; --j; ) pos += hiSum[ -*(bImp++) ];
		    neg = 1 + hiSum[ -index ]; bImp = BinaryImp[ -index ] + 2;
		    for(j = bImp[ -2 ] - 1; --j; ) neg += hiSum[ -*(bImp++) ];
#else
		    pos = 1 + Reductions[ index ]; bImp = BinaryImp[ index ] + 2;
		    for(j = bImp[ -2 ] - 1; --j; ) pos += Reductions[ -*(bImp++) ];
		    neg = 1 + Reductions[ -index ]; bImp = BinaryImp[ -index ] + 2;
		    for( j = bImp[ -2 ] - 1; --j; ) neg += Reductions[ -*(bImp++) ];
#endif
		    Rank[ index ] = 1024 * pos * neg + pos + neg + 1;
//		    assert( Rank[ index ] > 0 );
		}
		else
		{
	            pos = 0.1 + (Reductions[ -index ] + 
			DIFF_WEIGHT * (BinaryImp[  index ][ 0 ] - bImp_satisfied[  index ]));
	            neg = 0.1 + (Reductions[  index ] + 
			DIFF_WEIGHT * (BinaryImp[ -index ][ 0 ] - bImp_satisfied[ -index ]));

		    if( non_tautological_equivalences ) Rank[ index ] = 1024 * pos * neg + 1;
		    else
		    {   sum += pos + neg; diff[ index ] = pos; diff[ -index ] = neg; }
		}
	    }
	}

        if( non_tautological_equivalences | kSAT_flag ) return;

	dist_acc_flag = dist_acc_flag > 0;

	if( depth <= ROOTSIZE )	accuracy = ROOTACC;
	else			accuracy = ACCURACY;

    if( depth <= RECORDSIZE )
    {	
	while( iteration_count < (accuracy+ dist_acc_flag) )
	{
	    factor  = 2.0 * freevars / sum;
	    fsquare = factor * factor;
	    wnorm   = DIFF_WEIGHT / factor;

	    tmpfloat = diff_tmp;
	    diff_tmp = diff;
	    diff     = tmpfloat;

	    if( iteration_count == 2 ) diff = _diff;

	    sum = 0.0;
            for( i = freevars - 1; i >= 0; i-- )
            {
            	index = freevarsArray[ i ];

	        pos = 0.0; bImp = BIMP_START( -index );
                for( j = BIMP_ELEMENTS; --j; )
	        {  if( IS_NOT_FIXED(*bImp) ) pos += diff_tmp[ *bImp ]; bImp++; }
	    	pos *= wnorm;

//		if( kSAT_flag) pos += EqDiff[ index ] + big_occ[  index ] / 2;
//		else 
		{ tImp = TernaryImp[ index ];
                for( j = TernaryImpSize[ index ]; j > 0; j-- )
                {  pos += diff_tmp[ tImp[0] ] * diff_tmp[ tImp[1] ]; tImp += 2;  } }

	        neg = 0.0; bImp = BIMP_START( index );
                for( j = BIMP_ELEMENTS; --j; )
	        {  if( IS_NOT_FIXED(*bImp) ) neg += diff_tmp[ *bImp ]; bImp++; }
	        neg *= wnorm;

//		if( kSAT_flag )	neg += EqDiff[ index ] + big_occ[ -index ] / 2;
//		else 
		{ tImp = TernaryImp[ -index ];
                for( j = TernaryImpSize[ -index ]; j > 0; j-- )
                {  neg += diff_tmp[ tImp[0] ] * diff_tmp[ tImp[1] ]; tImp += 2;  } }

	        diff[ -index ] = fsquare * pos;
	        diff[  index ] = fsquare * neg;

		if( diff[ -index ] > 25 ) diff[ -index ] = 25;
		if( diff[  index ] > 25 ) diff[  index ] = 25;

		if( diff[ -index ] < 0.1 ) diff[ -index ] = 0.1;
		if( diff[  index ] < 0.1 ) diff[  index ] = 0.1;

	        sum += diff[ index ] + diff[ -index ];
	    }
	    iteration_count++;
	}
    }


	diff_tmp = diff;
	if( depth < RECORDSIZE ) diff = diff_depth[ depth ];
	else	 	  	 diff = _diff;

	factor = 2.0 * freevars / sum;
	wnorm = DIFF_WEIGHT / factor;

        for( i = freevars - 1; i >= 0; i-- )
        {
            index = freevarsArray[ i ];

	    diff[  index ] = diff_tmp[  index ] * factor;
	    diff[ -index ] = diff_tmp[ -index ] * factor;

	    Rank[ index ] = 1024 * diff[ index ] * diff[ -index ];
	}
	
	dist_acc_flag = 0;
	
	return;
}