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