GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/nl/ext/constraint.cpp Lines: 53 55 96.4 %
Date: 2021-05-22 Branches: 87 180 48.3 %

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