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