GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/nl/cad/constraints.cpp Lines: 29 29 100.0 %
Date: 2021-08-16 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
790
void Constraints::addConstraint(const poly::Polynomial& lhs,
32
                                poly::SignCondition sc,
33
                                Node n)
34
{
35
790
  d_constraints.emplace_back(lhs, sc, n);
36
790
  sortConstraints();
37
790
}
38
39
764
void Constraints::addConstraint(Node n)
40
{
41
1528
  auto c = as_poly_constraint(n, d_varMapper);
42
764
  addConstraint(c.first, c.second, n);
43
764
  sortConstraints();
44
764
}
45
46
311
const Constraints::ConstraintVector& Constraints::getConstraints() const
47
{
48
311
  return d_constraints;
49
}
50
51
50
void Constraints::reset() { d_constraints.clear(); }
52
53
1554
void Constraints::sortConstraints()
54
{
55
  using Tpl = std::tuple<poly::Polynomial, poly::SignCondition, Node>;
56
1554
  std::sort(d_constraints.begin(),
57
            d_constraints.end(),
58
46740
            [](const Tpl& at, const Tpl& bt) {
59
              // Check if a is smaller than b
60
46740
              const poly::Polynomial& a = std::get<0>(at);
61
46740
              const poly::Polynomial& b = std::get<0>(bt);
62
46740
              bool ua = is_univariate(a);
63
46740
              bool ub = is_univariate(b);
64
46740
              if (ua != ub) return ua;
65
36521
              std::size_t tda = poly_utils::totalDegree(a);
66
36521
              std::size_t tdb = poly_utils::totalDegree(b);
67
36521
              if (tda != tdb) return tda < tdb;
68
23136
              return degree(a) < degree(b);
69
            });
70
18952
  for (auto& c : d_constraints)
71
  {
72
17398
    auto* p = std::get<0>(c).get_internal();
73
17398
    lp_polynomial_set_external(p);
74
  }
75
1554
}
76
77
}  // namespace cad
78
}  // namespace nl
79
}  // namespace arith
80
}  // namespace theory
81
29340
}  // namespace cvc5
82
83
#endif