GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/nl/ext/constraint.cpp Lines: 53 55 96.4 %
Date: 2021-09-07 Branches: 87 178 48.9 %

Line Exec Source
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
5208
ConstraintDb::ConstraintDb(MonomialDb& mdb) : d_mdb(mdb) {}
30
31
51189
void ConstraintDb::registerConstraint(Node atom)
32
{
33
153567
  if (std::find(d_constraints.begin(), d_constraints.end(), atom)
34
153567
      != d_constraints.end())
35
  {
36
38179
    return;
37
  }
38
13010
  d_constraints.push_back(atom);
39
13010
  Trace("nl-ext-debug") << "Register constraint : " << atom << std::endl;
40
26020
  std::map<Node, Node> msum;
41
13010
  if (ArithMSum::getMonomialSumLit(atom, msum))
42
  {
43
13010
    Trace("nl-ext-debug") << "got monomial sum: " << std::endl;
44
13010
    if (Trace.isOn("nl-ext-debug"))
45
    {
46
      ArithMSum::debugPrintMonomialSum(msum, "nl-ext-debug");
47
    }
48
13010
    unsigned max_degree = 0;
49
26020
    std::vector<Node> all_m;
50
26020
    std::vector<Node> max_deg_m;
51
41043
    for (std::map<Node, Node>::iterator itm = msum.begin(); itm != msum.end();
52
         ++itm)
53
    {
54
28033
      if (!itm->first.isNull())
55
      {
56
23064
        all_m.push_back(itm->first);
57
23064
        d_mdb.registerMonomial(itm->first);
58
46128
        Trace("nl-ext-debug2")
59
23064
            << "...process monomial " << itm->first << std::endl;
60
23064
        unsigned d = d_mdb.getDegree(itm->first);
61
23064
        if (d > max_degree)
62
        {
63
15749
          max_degree = d;
64
15749
          max_deg_m.clear();
65
        }
66
23064
        if (d >= max_degree)
67
        {
68
22923
          max_deg_m.push_back(itm->first);
69
        }
70
      }
71
    }
72
    // isolate for each maximal degree monomial
73
36074
    for (unsigned i = 0; i < all_m.size(); i++)
74
    {
75
46128
      Node m = all_m[i];
76
46128
      Node rhs, coeff;
77
23064
      int res = ArithMSum::isolate(m, msum, coeff, rhs, atom.getKind());
78
23064
      if (res != 0)
79
      {
80
23064
        Kind type = atom.getKind();
81
23064
        if (res == -1)
82
        {
83
5931
          type = reverseRelationKind(type);
84
        }
85
23064
        Trace("nl-ext-constraint") << "Constraint : " << atom << " <=> ";
86
23064
        if (!coeff.isNull())
87
        {
88
732
          Trace("nl-ext-constraint") << coeff << " * ";
89
        }
90
46128
        Trace("nl-ext-constraint")
91
23064
            << m << " " << type << " " << rhs << std::endl;
92
23064
        ConstraintInfo& ci = d_c_info[atom][m];
93
23064
        ci.d_rhs = rhs;
94
23064
        ci.d_coeff = coeff;
95
23064
        ci.d_type = type;
96
      }
97
    }
98
32796
    for (unsigned i = 0; i < max_deg_m.size(); i++)
99
    {
100
39572
      Node m = max_deg_m[i];
101
19786
      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
741
ConstraintDb::getConstraints()
112
{
113
741
  return d_c_info;
114
}
115
116
93207
bool ConstraintDb::isMaximal(Node atom, Node x) const
117
{
118
  std::map<Node, std::map<Node, bool> >::const_iterator itcm =
119
93207
      d_c_info_maxm.find(atom);
120
93207
  Assert(itcm != d_c_info_maxm.end());
121
93207
  return itcm->second.find(x) != itcm->second.end();
122
}
123
124
}  // namespace nl
125
}  // namespace arith
126
}  // namespace theory
127
29502
}  // namespace cvc5