GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/strings/strings_fmf.cpp Lines: 40 43 93.0 %
Date: 2021-05-21 Branches: 48 90 53.3 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Tianyi Liang, 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 a finite model finding decision strategy for strings.
14
 */
15
16
#include "theory/strings/strings_fmf.h"
17
18
using namespace std;
19
using namespace cvc5::context;
20
using namespace cvc5::kind;
21
22
namespace cvc5 {
23
namespace theory {
24
namespace strings {
25
26
8954
StringsFmf::StringsFmf(context::Context* c,
27
                       context::UserContext* u,
28
                       Valuation valuation,
29
8954
                       TermRegistry& tr)
30
    : d_sslds(nullptr),
31
      d_satContext(c),
32
      d_userContext(u),
33
      d_valuation(valuation),
34
8954
      d_termReg(tr)
35
{
36
8954
}
37
38
8954
StringsFmf::~StringsFmf() {}
39
40
63
void StringsFmf::presolve()
41
{
42
126
  d_sslds.reset(new StringSumLengthDecisionStrategy(
43
126
      d_satContext, d_userContext, d_valuation));
44
126
  Trace("strings-dstrat-reg")
45
63
      << "presolve: register decision strategy." << std::endl;
46
63
  const NodeSet& ivars = d_termReg.getInputVars();
47
126
  std::vector<Node> inputVars;
48
193
  for (NodeSet::const_iterator itr = ivars.begin(); itr != ivars.end(); ++itr)
49
  {
50
130
    inputVars.push_back(*itr);
51
  }
52
63
  d_sslds->initialize(inputVars);
53
63
}
54
55
63
DecisionStrategy* StringsFmf::getDecisionStrategy() const
56
{
57
63
  return d_sslds.get();
58
}
59
60
63
StringsFmf::StringSumLengthDecisionStrategy::StringSumLengthDecisionStrategy(
61
63
    context::Context* c, context::UserContext* u, Valuation valuation)
62
63
    : DecisionStrategyFmf(c, valuation), d_inputVarLsum(u)
63
{
64
63
}
65
66
bool StringsFmf::StringSumLengthDecisionStrategy::isInitialized()
67
{
68
  return !d_inputVarLsum.get().isNull();
69
}
70
71
63
void StringsFmf::StringSumLengthDecisionStrategy::initialize(
72
    const std::vector<Node>& vars)
73
{
74
63
  if (d_inputVarLsum.get().isNull() && !vars.empty())
75
  {
76
58
    NodeManager* nm = NodeManager::currentNM();
77
116
    std::vector<Node> sum;
78
188
    for (const Node& v : vars)
79
    {
80
130
      sum.push_back(nm->mkNode(STRING_LENGTH, v));
81
    }
82
116
    Node sumn = sum.size() == 1 ? sum[0] : nm->mkNode(PLUS, sum);
83
58
    d_inputVarLsum.set(sumn);
84
  }
85
63
}
86
87
276
Node StringsFmf::StringSumLengthDecisionStrategy::mkLiteral(unsigned i)
88
{
89
276
  if (d_inputVarLsum.get().isNull())
90
  {
91
    return Node::null();
92
  }
93
276
  NodeManager* nm = NodeManager::currentNM();
94
552
  Node lit = nm->mkNode(LEQ, d_inputVarLsum.get(), nm->mkConst(Rational(i)));
95
276
  Trace("strings-fmf") << "StringsFMF::mkLiteral: " << lit << std::endl;
96
276
  return lit;
97
}
98
63489
std::string StringsFmf::StringSumLengthDecisionStrategy::identify() const
99
{
100
63489
  return std::string("string_sum_len");
101
}
102
103
}  // namespace strings
104
}  // namespace theory
105
27735
}  // namespace cvc5