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