1ea172d1106a7ded5f96f373781405b7f5a51bb9
1 /********************* */
2 /*! \file constraints.cpp
4 ** Top contributors (to current version):
6 ** This file is part of the CVC4 project.
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.\endverbatim
12 ** \brief Implements a container for CAD constraints.
14 ** Implements a container for CAD constraints.
17 #include "theory/arith/nl/cad/constraints.h"
23 #include "theory/arith/nl/poly_conversion.h"
24 #include "util/poly_util.h"
32 void Constraints::addConstraint(const poly::Polynomial
& lhs
,
33 poly::SignCondition sc
,
36 d_constraints
.emplace_back(lhs
, sc
, n
);
40 void Constraints::addConstraint(Node n
)
42 auto c
= as_poly_constraint(n
, d_varMapper
);
43 addConstraint(c
.first
, c
.second
, n
);
47 const Constraints::ConstraintVector
& Constraints::getConstraints() const
52 void Constraints::reset() { d_constraints
.clear(); }
54 void Constraints::sortConstraints()
56 using Tpl
= std::tuple
<poly::Polynomial
, poly::SignCondition
, Node
>;
57 std::sort(d_constraints
.begin(),
59 [](const Tpl
& at
, const Tpl
& bt
) {
60 // Check if a is smaller than b
61 const poly::Polynomial
& a
= std::get
<0>(at
);
62 const poly::Polynomial
& b
= std::get
<0>(bt
);
63 bool ua
= is_univariate(a
);
64 bool ub
= is_univariate(b
);
65 if (ua
!= ub
) return ua
;
66 std::size_t tda
= poly_utils::totalDegree(a
);
67 std::size_t tdb
= poly_utils::totalDegree(b
);
68 if (tda
!= tdb
) return tda
< tdb
;
69 return degree(a
) < degree(b
);
71 for (auto& c
: d_constraints
)
73 auto* p
= std::get
<0>(c
).get_internal();
74 lp_polynomial_set_external(p
);