Beispiel #1
0
 Answer EMModule<Settings>::checkCore()
 {
     auto receivedFormula = firstUncheckedReceivedSubformula();
     while (receivedFormula != rReceivedFormula().end()) {
         FormulaT formula = receivedFormula->formula();
         if (receivedFormula->formula().propertyHolds(carl::PROP_CONTAINS_NONLINEAR_POLYNOMIAL)) {
             formula = mVisitor.visitResult(receivedFormula->formula(), eliminateEquationFunction);
         }
         if (formula.isFalse()) {
             receivedFormulasAsInfeasibleSubset(receivedFormula);
             return UNSAT;
         }
         if (!formula.isTrue()) {
             addSubformulaToPassedFormula(formula, receivedFormula->formula());
         }
         ++receivedFormula;
     }
     Answer ans = runBackends();
     if (ans == UNSAT)
         getInfeasibleSubsets();
     return ans;
 }
Beispiel #2
0
    Answer CNFerModule::checkCore()
    {
        auto receivedSubformula = firstUncheckedReceivedSubformula();
        while( receivedSubformula != rReceivedFormula().end() )
        {
            /*
             * Add the currently considered formula of the received constraint as clauses
             * to the passed formula.
             */
            FormulaT formulaToAssertInCnf = receivedSubformula->formula().toCNF( true, true, true );
            if( formulaToAssertInCnf.getType() == TRUE )
            {
                // No need to add it.
            }
            else if( formulaToAssertInCnf.getType() == FALSE )
            {
                receivedFormulasAsInfeasibleSubset( receivedSubformula );
                return UNSAT;
            }
            else
            {
                if( formulaToAssertInCnf.getType() == AND )
                {
                    for( const FormulaT& subFormula : formulaToAssertInCnf.subformulas()  )
                    {
                        #ifdef SMTRAT_DEVOPTION_Statistics
                        mpStatistics->addClauseOfSize( subFormula.size() );
                        #endif
                        addSubformulaToPassedFormula( subFormula, receivedSubformula->formula() );
                    }
                }
                else
                {
                    #ifdef SMTRAT_DEVOPTION_Statistics
                    mpStatistics->addClauseOfSize( receivedSubformula->formula().size() );
                    #endif
                    addSubformulaToPassedFormula( formulaToAssertInCnf, receivedSubformula->formula() );
                }
            }
            ++receivedSubformula;
        }
        //No given formulas is SAT but only if no other run was before
        if( rPassedFormula().empty() && solverState() == UNKNOWN )
        {
            return SAT;
        }
        else
        {
            #ifdef SMTRAT_DEVOPTION_Statistics
            carl::Variables avars;
            rPassedFormula().arithmeticVars( avars );
            mpStatistics->nrOfArithVariables() = avars.size();
            carl::Variables bvars;
            rPassedFormula().booleanVars( bvars );
            mpStatistics->nrOfBoolVariables() = bvars.size();
            #endif
            Answer a = runBackends();

            if( a == UNSAT )
            {
                getInfeasibleSubsets();
            }
            return a;
        }
    }
Beispiel #3
0
 Answer CubeLIAModule<Settings>::checkCore()
 {
     #ifdef DEBUG_CUBELIAMODULE
     print();
     #endif
     Answer ans;
     if( !rReceivedFormula().isRealConstraintConjunction() )
     {
         #ifdef DEBUG_CUBELIAMODULE
         std::cout << "Call internal LRAModule:" << std::endl;
         mLRA.print();
         #endif
         mLRA.clearLemmas();
         mLRAFormula->updateProperties();
         ans = mLRA.check( false, mFullCheck, mMinimizingCheck );
         switch( ans )
         {
             case SAT:
             {
                 clearModel();
                 // Get the model of mLRA
                 mLRA.updateModel();
                 const Model& relaxedModel = mLRA.model();
                 auto iter = mRealToIntVarMap.begin();
                 for( auto& ass : relaxedModel )
                 {
                     assert( iter != mRealToIntVarMap.end() );
                     // Round the result to the next integer
                     mModel.emplace_hint( mModel.end(), iter->second, carl::round( ass.second.asRational() ) );
                     ++iter;
                 }
                 // Check if the rounded model satisfies the received formula
                 bool receivedFormulaSatisfied = true;
                 for( const FormulaWithOrigins& fwo : rReceivedFormula() )
                 {
                     unsigned res = satisfies( mModel, fwo.formula() );
                     switch( res )
                     {
                         case 0:
                         case 2:
                             receivedFormulaSatisfied = false;
                         default:
                             break;
                     }
                     if( !receivedFormulaSatisfied )
                         break;
                 }
                 // If we found a model, we know that the formula is satisfiable, otherwise, we have to call the backends on the received formula
                 if( receivedFormulaSatisfied )
                 {
                     mModelUpdated = true;
                     return SAT;
                 }
                 clearModel();
                 break;
             }
             case UNSAT:
             {
                 if( Settings::exclude_unsatisfiable_cube_space )
                 {
                     // Exclude the space for which mLRA has detected unsatisfiability
                     for( auto& infsubset : mLRA.infeasibleSubsets() )
                     {
                         FormulasT formulas;
                         for( auto& formula : infsubset )
                             formulas.push_back( formula.negated() );
                         addLemma( FormulaT( carl::FormulaType::OR, formulas ) );
                     }
                 }
                 break;
             }
             default:
                 assert( false );
         }
     }
     #ifdef DEBUG_CUBELIAMODULE
     std::cout << "Call Backends:" << std::endl;
     #endif
     // Run backends on received formula
     ans = runBackends();
     if( ans == UNSAT )
         getInfeasibleSubsets();
     else if( ans == SAT )
         mModelUpdated = false;
     return ans;
 }