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

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