1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Tim King, Aina Niemetz |
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 |
|
* Implementation of utilities for non-linear constraints. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "theory/arith/nl/ext/constraint.h" |
17 |
|
|
18 |
|
#include "theory/arith/arith_msum.h" |
19 |
|
#include "theory/arith/arith_utilities.h" |
20 |
|
#include "theory/arith/nl/ext/monomial.h" |
21 |
|
|
22 |
|
using namespace cvc5::kind; |
23 |
|
|
24 |
|
namespace cvc5 { |
25 |
|
namespace theory { |
26 |
|
namespace arith { |
27 |
|
namespace nl { |
28 |
|
|
29 |
5195 |
ConstraintDb::ConstraintDb(MonomialDb& mdb) : d_mdb(mdb) {} |
30 |
|
|
31 |
61253 |
void ConstraintDb::registerConstraint(Node atom) |
32 |
|
{ |
33 |
183759 |
if (std::find(d_constraints.begin(), d_constraints.end(), atom) |
34 |
183759 |
!= d_constraints.end()) |
35 |
|
{ |
36 |
45425 |
return; |
37 |
|
} |
38 |
15828 |
d_constraints.push_back(atom); |
39 |
15828 |
Trace("nl-ext-debug") << "Register constraint : " << atom << std::endl; |
40 |
31656 |
std::map<Node, Node> msum; |
41 |
15828 |
if (ArithMSum::getMonomialSumLit(atom, msum)) |
42 |
|
{ |
43 |
15828 |
Trace("nl-ext-debug") << "got monomial sum: " << std::endl; |
44 |
15828 |
if (Trace.isOn("nl-ext-debug")) |
45 |
|
{ |
46 |
|
ArithMSum::debugPrintMonomialSum(msum, "nl-ext-debug"); |
47 |
|
} |
48 |
15828 |
unsigned max_degree = 0; |
49 |
31656 |
std::vector<Node> all_m; |
50 |
31656 |
std::vector<Node> max_deg_m; |
51 |
49549 |
for (std::map<Node, Node>::iterator itm = msum.begin(); itm != msum.end(); |
52 |
|
++itm) |
53 |
|
{ |
54 |
33721 |
if (!itm->first.isNull()) |
55 |
|
{ |
56 |
27337 |
all_m.push_back(itm->first); |
57 |
27337 |
d_mdb.registerMonomial(itm->first); |
58 |
54674 |
Trace("nl-ext-debug2") |
59 |
27337 |
<< "...process monomial " << itm->first << std::endl; |
60 |
27337 |
unsigned d = d_mdb.getDegree(itm->first); |
61 |
27337 |
if (d > max_degree) |
62 |
|
{ |
63 |
19135 |
max_degree = d; |
64 |
19135 |
max_deg_m.clear(); |
65 |
|
} |
66 |
27337 |
if (d >= max_degree) |
67 |
|
{ |
68 |
27130 |
max_deg_m.push_back(itm->first); |
69 |
|
} |
70 |
|
} |
71 |
|
} |
72 |
|
// isolate for each maximal degree monomial |
73 |
43165 |
for (unsigned i = 0; i < all_m.size(); i++) |
74 |
|
{ |
75 |
54674 |
Node m = all_m[i]; |
76 |
54674 |
Node rhs, coeff; |
77 |
27337 |
int res = ArithMSum::isolate(m, msum, coeff, rhs, atom.getKind()); |
78 |
27337 |
if (res != 0) |
79 |
|
{ |
80 |
27329 |
Kind type = atom.getKind(); |
81 |
27329 |
if (res == -1) |
82 |
|
{ |
83 |
6990 |
type = reverseRelationKind(type); |
84 |
|
} |
85 |
27329 |
Trace("nl-ext-constraint") << "Constraint : " << atom << " <=> "; |
86 |
27329 |
if (!coeff.isNull()) |
87 |
|
{ |
88 |
797 |
Trace("nl-ext-constraint") << coeff << " * "; |
89 |
|
} |
90 |
54658 |
Trace("nl-ext-constraint") |
91 |
27329 |
<< m << " " << type << " " << rhs << std::endl; |
92 |
27329 |
ConstraintInfo& ci = d_c_info[atom][m]; |
93 |
27329 |
ci.d_rhs = rhs; |
94 |
27329 |
ci.d_coeff = coeff; |
95 |
27329 |
ci.d_type = type; |
96 |
|
} |
97 |
|
} |
98 |
39245 |
for (unsigned i = 0; i < max_deg_m.size(); i++) |
99 |
|
{ |
100 |
46834 |
Node m = max_deg_m[i]; |
101 |
23417 |
d_c_info_maxm[atom][m] = true; |
102 |
|
} |
103 |
|
} |
104 |
|
else |
105 |
|
{ |
106 |
|
Trace("nl-ext-debug") << "...failed to get monomial sum." << std::endl; |
107 |
|
} |
108 |
|
} |
109 |
|
|
110 |
|
const std::map<Node, std::map<Node, ConstraintInfo> >& |
111 |
743 |
ConstraintDb::getConstraints() |
112 |
|
{ |
113 |
743 |
return d_c_info; |
114 |
|
} |
115 |
|
|
116 |
107542 |
bool ConstraintDb::isMaximal(Node atom, Node x) const |
117 |
|
{ |
118 |
|
std::map<Node, std::map<Node, bool> >::const_iterator itcm = |
119 |
107542 |
d_c_info_maxm.find(atom); |
120 |
107542 |
Assert(itcm != d_c_info_maxm.end()); |
121 |
107542 |
return itcm->second.find(x) != itcm->second.end(); |
122 |
|
} |
123 |
|
|
124 |
|
} // namespace nl |
125 |
|
} // namespace arith |
126 |
|
} // namespace theory |
127 |
29511 |
} // namespace cvc5 |