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 |
742 |
void Constraints::addConstraint(const poly::Polynomial& lhs, |
32 |
|
poly::SignCondition sc, |
33 |
|
Node n) |
34 |
|
{ |
35 |
742 |
d_constraints.emplace_back(lhs, sc, n); |
36 |
742 |
sortConstraints(); |
37 |
742 |
} |
38 |
|
|
39 |
742 |
void Constraints::addConstraint(Node n) |
40 |
|
{ |
41 |
1484 |
auto c = as_poly_constraint(n, d_varMapper); |
42 |
742 |
addConstraint(c.first, c.second, n); |
43 |
742 |
sortConstraints(); |
44 |
742 |
} |
45 |
|
|
46 |
201 |
const Constraints::ConstraintVector& Constraints::getConstraints() const |
47 |
|
{ |
48 |
201 |
return d_constraints; |
49 |
|
} |
50 |
|
|
51 |
47 |
void Constraints::reset() { d_constraints.clear(); } |
52 |
|
|
53 |
1484 |
void Constraints::sortConstraints() |
54 |
|
{ |
55 |
|
using Tpl = std::tuple<poly::Polynomial, poly::SignCondition, Node>; |
56 |
1484 |
std::sort(d_constraints.begin(), |
57 |
|
d_constraints.end(), |
58 |
46430 |
[](const Tpl& at, const Tpl& bt) { |
59 |
|
// Check if a is smaller than b |
60 |
46430 |
const poly::Polynomial& a = std::get<0>(at); |
61 |
46430 |
const poly::Polynomial& b = std::get<0>(bt); |
62 |
46430 |
bool ua = is_univariate(a); |
63 |
46430 |
bool ub = is_univariate(b); |
64 |
46430 |
if (ua != ub) return ua; |
65 |
36347 |
std::size_t tda = poly_utils::totalDegree(a); |
66 |
36347 |
std::size_t tdb = poly_utils::totalDegree(b); |
67 |
36347 |
if (tda != tdb) return tda < tdb; |
68 |
23014 |
return degree(a) < degree(b); |
69 |
|
}); |
70 |
18660 |
for (auto& c : d_constraints) |
71 |
|
{ |
72 |
17176 |
auto* p = std::get<0>(c).get_internal(); |
73 |
17176 |
lp_polynomial_set_external(p); |
74 |
|
} |
75 |
1484 |
} |
76 |
|
|
77 |
|
} // namespace cad |
78 |
|
} // namespace nl |
79 |
|
} // namespace arith |
80 |
|
} // namespace theory |
81 |
28191 |
} // namespace cvc5 |
82 |
|
|
83 |
|
#endif |