LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory/arith/nl/ext - constraint.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 57 59 96.6 %
Date: 2026-03-19 10:41:11 Functions: 4 4 100.0 %
Branches: 30 44 68.2 %

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * This file is part of the cvc5 project.
       3                 :            :  *
       4                 :            :  * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS
       5                 :            :  * in the top-level source directory and their institutional affiliations.
       6                 :            :  * All rights reserved.  See the file COPYING in the top-level source
       7                 :            :  * directory for licensing information.
       8                 :            :  * ****************************************************************************
       9                 :            :  *
      10                 :            :  * Implementation of utilities for non-linear constraints.
      11                 :            :  */
      12                 :            : 
      13                 :            : #include "theory/arith/nl/ext/constraint.h"
      14                 :            : 
      15                 :            : #include "theory/arith/arith_msum.h"
      16                 :            : #include "theory/arith/arith_utilities.h"
      17                 :            : #include "theory/arith/nl/ext/monomial.h"
      18                 :            : 
      19                 :            : using namespace cvc5::internal::kind;
      20                 :            : 
      21                 :            : namespace cvc5::internal {
      22                 :            : namespace theory {
      23                 :            : namespace arith {
      24                 :            : namespace nl {
      25                 :            : 
      26                 :      33052 : ConstraintDb::ConstraintDb(MonomialDb& mdb) : d_mdb(mdb) {}
      27                 :            : 
      28                 :     249790 : void ConstraintDb::registerConstraint(Node atom)
      29                 :            : {
      30                 :     249790 :   if (std::find(d_constraints.begin(), d_constraints.end(), atom)
      31         [ +  + ]:     499580 :       != d_constraints.end())
      32                 :            :   {
      33                 :     199670 :     return;
      34                 :            :   }
      35                 :      50120 :   d_constraints.push_back(atom);
      36         [ +  - ]:      50120 :   Trace("nl-ext-debug") << "Register constraint : " << atom << std::endl;
      37                 :      50120 :   std::map<Node, Node> msum;
      38         [ +  - ]:      50120 :   if (ArithMSum::getMonomialSumLit(atom, msum))
      39                 :            :   {
      40         [ +  - ]:      50120 :     Trace("nl-ext-debug") << "got monomial sum: " << std::endl;
      41         [ -  + ]:      50120 :     if (TraceIsOn("nl-ext-debug"))
      42                 :            :     {
      43                 :          0 :       ArithMSum::debugPrintMonomialSum(msum, "nl-ext-debug");
      44                 :            :     }
      45                 :      50120 :     unsigned max_degree = 0;
      46                 :      50120 :     std::vector<Node> all_m;
      47                 :      50120 :     std::vector<Node> max_deg_m;
      48         [ +  + ]:     155949 :     for (std::map<Node, Node>::iterator itm = msum.begin(); itm != msum.end();
      49                 :     105829 :          ++itm)
      50                 :            :     {
      51         [ +  + ]:     105829 :       if (!itm->first.isNull())
      52                 :            :       {
      53                 :      81776 :         all_m.push_back(itm->first);
      54                 :      81776 :         d_mdb.registerMonomial(itm->first);
      55         [ +  - ]:     163552 :         Trace("nl-ext-debug2")
      56                 :      81776 :             << "...process monomial " << itm->first << std::endl;
      57                 :      81776 :         unsigned d = d_mdb.getDegree(itm->first);
      58         [ +  + ]:      81776 :         if (d > max_degree)
      59                 :            :         {
      60                 :      60894 :           max_degree = d;
      61                 :      60894 :           max_deg_m.clear();
      62                 :            :         }
      63         [ +  + ]:      81776 :         if (d >= max_degree)
      64                 :            :         {
      65                 :      81061 :           max_deg_m.push_back(itm->first);
      66                 :            :         }
      67                 :            :       }
      68                 :            :     }
      69                 :            :     // isolate for each maximal degree monomial
      70         [ +  + ]:     131896 :     for (unsigned i = 0; i < all_m.size(); i++)
      71                 :            :     {
      72                 :      81776 :       Node m = all_m[i];
      73                 :      81776 :       Node rhs, coeff;
      74                 :      81776 :       int res = ArithMSum::isolate(m, msum, coeff, rhs, atom.getKind());
      75         [ +  + ]:      81776 :       if (res != 0)
      76                 :            :       {
      77                 :      81772 :         Kind type = atom.getKind();
      78         [ +  + ]:      81772 :         if (res == -1)
      79                 :            :         {
      80                 :      18394 :           type = reverseRelationKind(type);
      81                 :            :         }
      82         [ +  - ]:      81772 :         Trace("nl-ext-constraint") << "Constraint : " << atom << " <=> ";
      83         [ +  + ]:      81772 :         if (!coeff.isNull())
      84                 :            :         {
      85         [ +  - ]:       3790 :           Trace("nl-ext-constraint") << coeff << " * ";
      86                 :            :         }
      87         [ +  - ]:     163544 :         Trace("nl-ext-constraint")
      88                 :      81772 :             << m << " " << type << " " << rhs << std::endl;
      89                 :      81772 :         ConstraintInfo& ci = d_c_info[atom][m];
      90                 :      81772 :         ci.d_rhs = rhs;
      91                 :      81772 :         ci.d_coeff = coeff;
      92                 :      81772 :         ci.d_type = type;
      93                 :            :       }
      94                 :      81776 :     }
      95         [ +  + ]:     119262 :     for (unsigned i = 0; i < max_deg_m.size(); i++)
      96                 :            :     {
      97                 :      69142 :       Node m = max_deg_m[i];
      98                 :      69142 :       d_c_info_maxm[atom][m] = true;
      99                 :      69142 :     }
     100                 :      50120 :   }
     101                 :            :   else
     102                 :            :   {
     103         [ -  - ]:          0 :     Trace("nl-ext-debug") << "...failed to get monomial sum." << std::endl;
     104                 :            :   }
     105                 :      50120 : }
     106                 :            : 
     107                 :            : const std::map<Node, std::map<Node, ConstraintInfo> >&
     108                 :       2766 : ConstraintDb::getConstraints()
     109                 :            : {
     110                 :       2766 :   return d_c_info;
     111                 :            : }
     112                 :            : 
     113                 :     429577 : bool ConstraintDb::isMaximal(Node atom, Node x) const
     114                 :            : {
     115                 :            :   std::map<Node, std::map<Node, bool> >::const_iterator itcm =
     116                 :     429577 :       d_c_info_maxm.find(atom);
     117 [ -  + ][ -  + ]:     429577 :   Assert(itcm != d_c_info_maxm.end());
                 [ -  - ]
     118                 :     429577 :   return itcm->second.find(x) != itcm->second.end();
     119                 :            : }
     120                 :            : 
     121                 :            : }  // namespace nl
     122                 :            : }  // namespace arith
     123                 :            : }  // namespace theory
     124                 :            : }  // namespace cvc5::internal

Generated by: LCOV version 1.14