LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory/arith/nl/coverings - constraints.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 28 28 100.0 %
Date: 2026-03-05 11:40:39 Functions: 6 6 100.0 %
Branches: 6 6 100.0 %

           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                 :            :  * Implements a container for coverings constraints.
      11                 :            :  */
      12                 :            : 
      13                 :            : #include "theory/arith/nl/coverings/constraints.h"
      14                 :            : 
      15                 :            : #ifdef CVC5_POLY_IMP
      16                 :            : 
      17                 :            : #include <algorithm>
      18                 :            : 
      19                 :            : #include "theory/arith/nl/poly_conversion.h"
      20                 :            : #include "util/poly_util.h"
      21                 :            : 
      22                 :            : namespace cvc5::internal {
      23                 :            : namespace theory {
      24                 :            : namespace arith {
      25                 :            : namespace nl {
      26                 :            : namespace coverings {
      27                 :            : 
      28                 :       5881 : void Constraints::addConstraint(const poly::Polynomial& lhs,
      29                 :            :                                 poly::SignCondition sc,
      30                 :            :                                 Node n)
      31                 :            : {
      32                 :       5881 :   d_constraints.emplace_back(lhs, sc, n);
      33                 :       5881 :   sortConstraints();
      34                 :       5881 : }
      35                 :            : 
      36                 :       5863 : void Constraints::addConstraint(Node n)
      37                 :            : {
      38                 :       5863 :   auto c = as_poly_constraint(n, d_varMapper);
      39                 :       5863 :   addConstraint(c.first, c.second, n);
      40                 :       5863 :   sortConstraints();
      41                 :       5863 : }
      42                 :            : 
      43                 :       3297 : const Constraints::ConstraintVector& Constraints::getConstraints() const
      44                 :            : {
      45                 :       3297 :   return d_constraints;
      46                 :            : }
      47                 :            : 
      48                 :        282 : void Constraints::reset() { d_constraints.clear(); }
      49                 :            : 
      50                 :      11744 : void Constraints::sortConstraints()
      51                 :            : {
      52                 :            :   using Tpl = std::tuple<poly::Polynomial, poly::SignCondition, Node>;
      53                 :      11744 :   std::sort(d_constraints.begin(),
      54                 :            :             d_constraints.end(),
      55                 :     849293 :             [](const Tpl& at, const Tpl& bt) {
      56                 :            :               // Check if a is smaller than b
      57                 :     849293 :               const poly::Polynomial& a = std::get<0>(at);
      58                 :     849293 :               const poly::Polynomial& b = std::get<0>(bt);
      59                 :     849293 :               bool ua = is_univariate(a);
      60                 :     849293 :               bool ub = is_univariate(b);
      61         [ +  + ]:     849293 :               if (ua != ub) return ua;
      62                 :     637447 :               std::size_t tda = poly_utils::totalDegree(a);
      63                 :     637447 :               std::size_t tdb = poly_utils::totalDegree(b);
      64         [ +  + ]:     637447 :               if (tda != tdb) return tda < tdb;
      65                 :     431326 :               return degree(a) < degree(b);
      66                 :            :             });
      67         [ +  + ]:     238743 :   for (auto& c : d_constraints)
      68                 :            :   {
      69                 :     226999 :     auto* p = std::get<0>(c).get_internal();
      70                 :     226999 :     lp_polynomial_set_external(p);
      71                 :            :   }
      72                 :      11744 : }
      73                 :            : 
      74                 :            : }  // namespace coverings
      75                 :            : }  // namespace nl
      76                 :            : }  // namespace arith
      77                 :            : }  // namespace theory
      78                 :            : }  // namespace cvc5::internal
      79                 :            : 
      80                 :            : #endif

Generated by: LCOV version 1.14