GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/nl/cad/constraints.cpp Lines: 29 29 100.0 %
Date: 2021-09-15 Branches: 15 24 62.5 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Gereon Kremer
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 * in the top-level source directory and their institutional affiliations.
9
 * All rights reserved.  See the file COPYING in the top-level source
10
 * directory for licensing information.
11
 * ****************************************************************************
12
 *
13
 * Implements a container for CAD constraints.
14
 */
15
16
#include "theory/arith/nl/cad/constraints.h"
17
18
#ifdef CVC5_POLY_IMP
19
20
#include <algorithm>
21
22
#include "theory/arith/nl/poly_conversion.h"
23
#include "util/poly_util.h"
24
25
namespace cvc5 {
26
namespace theory {
27
namespace arith {
28
namespace nl {
29
namespace cad {
30
31
1020
void Constraints::addConstraint(const poly::Polynomial& lhs,
32
                                poly::SignCondition sc,
33
                                Node n)
34
{
35
1020
  d_constraints.emplace_back(lhs, sc, n);
36
1020
  sortConstraints();
37
1020
}
38
39
994
void Constraints::addConstraint(Node n)
40
{
41
1988
  auto c = as_poly_constraint(n, d_varMapper);
42
994
  addConstraint(c.first, c.second, n);
43
994
  sortConstraints();
44
994
}
45
46
347
const Constraints::ConstraintVector& Constraints::getConstraints() const
47
{
48
347
  return d_constraints;
49
}
50
51
60
void Constraints::reset() { d_constraints.clear(); }
52
53
2014
void Constraints::sortConstraints()
54
{
55
  using Tpl = std::tuple<poly::Polynomial, poly::SignCondition, Node>;
56
2014
  std::sort(d_constraints.begin(),
57
            d_constraints.end(),
58
62172
            [](const Tpl& at, const Tpl& bt) {
59
              // Check if a is smaller than b
60
62172
              const poly::Polynomial& a = std::get<0>(at);
61
62172
              const poly::Polynomial& b = std::get<0>(bt);
62
62172
              bool ua = is_univariate(a);
63
62172
              bool ub = is_univariate(b);
64
62172
              if (ua != ub) return ua;
65
49075
              std::size_t tda = poly_utils::totalDegree(a);
66
49075
              std::size_t tdb = poly_utils::totalDegree(b);
67
49075
              if (tda != tdb) return tda < tdb;
68
30888
              return degree(a) < degree(b);
69
            });
70
25236
  for (auto& c : d_constraints)
71
  {
72
23222
    auto* p = std::get<0>(c).get_internal();
73
23222
    lp_polynomial_set_external(p);
74
  }
75
2014
}
76
77
}  // namespace cad
78
}  // namespace nl
79
}  // namespace arith
80
}  // namespace theory
81
29577
}  // namespace cvc5
82
83
#endif