GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/nl/ext/constraint.cpp Lines: 53 55 96.4 %
Date: 2021-08-16 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
5145
ConstraintDb::ConstraintDb(MonomialDb& mdb) : d_mdb(mdb) {}
30
31
30802
void ConstraintDb::registerConstraint(Node atom)
32
{
33
92406
  if (std::find(d_constraints.begin(), d_constraints.end(), atom)
34
92406
      != d_constraints.end())
35
  {
36
21009
    return;
37
  }
38
9793
  d_constraints.push_back(atom);
39
9793
  Trace("nl-ext-debug") << "Register constraint : " << atom << std::endl;
40
19586
  std::map<Node, Node> msum;
41
9793
  if (ArithMSum::getMonomialSumLit(atom, msum))
42
  {
43
9793
    Trace("nl-ext-debug") << "got monomial sum: " << std::endl;
44
9793
    if (Trace.isOn("nl-ext-debug"))
45
    {
46
      ArithMSum::debugPrintMonomialSum(msum, "nl-ext-debug");
47
    }
48
9793
    unsigned max_degree = 0;
49
19586
    std::vector<Node> all_m;
50
19586
    std::vector<Node> max_deg_m;
51
30941
    for (std::map<Node, Node>::iterator itm = msum.begin(); itm != msum.end();
52
         ++itm)
53
    {
54
21148
      if (!itm->first.isNull())
55
      {
56
17056
        all_m.push_back(itm->first);
57
17056
        d_mdb.registerMonomial(itm->first);
58
34112
        Trace("nl-ext-debug2")
59
17056
            << "...process monomial " << itm->first << std::endl;
60
17056
        unsigned d = d_mdb.getDegree(itm->first);
61
17056
        if (d > max_degree)
62
        {
63
11882
          max_degree = d;
64
11882
          max_deg_m.clear();
65
        }
66
17056
        if (d >= max_degree)
67
        {
68
16922
          max_deg_m.push_back(itm->first);
69
        }
70
      }
71
    }
72
    // isolate for each maximal degree monomial
73
26849
    for (unsigned i = 0; i < all_m.size(); i++)
74
    {
75
34112
      Node m = all_m[i];
76
34112
      Node rhs, coeff;
77
17056
      int res = ArithMSum::isolate(m, msum, coeff, rhs, atom.getKind());
78
17056
      if (res != 0)
79
      {
80
17056
        Kind type = atom.getKind();
81
17056
        if (res == -1)
82
        {
83
4045
          type = reverseRelationKind(type);
84
        }
85
17056
        Trace("nl-ext-constraint") << "Constraint : " << atom << " <=> ";
86
17056
        if (!coeff.isNull())
87
        {
88
457
          Trace("nl-ext-constraint") << coeff << " * ";
89
        }
90
34112
        Trace("nl-ext-constraint")
91
17056
            << m << " " << type << " " << rhs << std::endl;
92
17056
        ConstraintInfo& ci = d_c_info[atom][m];
93
17056
        ci.d_rhs = rhs;
94
17056
        ci.d_coeff = coeff;
95
17056
        ci.d_type = type;
96
      }
97
    }
98
24369
    for (unsigned i = 0; i < max_deg_m.size(); i++)
99
    {
100
29152
      Node m = max_deg_m[i];
101
14576
      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
524
ConstraintDb::getConstraints()
112
{
113
524
  return d_c_info;
114
}
115
116
56341
bool ConstraintDb::isMaximal(Node atom, Node x) const
117
{
118
  std::map<Node, std::map<Node, bool> >::const_iterator itcm =
119
56341
      d_c_info_maxm.find(atom);
120
56341
  Assert(itcm != d_c_info_maxm.end());
121
56341
  return itcm->second.find(x) != itcm->second.end();
122
}
123
124
}  // namespace nl
125
}  // namespace arith
126
}  // namespace theory
127
29340
}  // namespace cvc5