GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/strings/strings_fmf.cpp Lines: 38 41 92.7 %
Date: 2021-09-29 Branches: 49 90 54.4 %

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
#include "util/rational.h"
19
20
using namespace std;
21
using namespace cvc5::context;
22
using namespace cvc5::kind;
23
24
namespace cvc5 {
25
namespace theory {
26
namespace strings {
27
28
6271
StringsFmf::StringsFmf(Env& env, Valuation valuation, TermRegistry& tr)
29
6271
    : EnvObj(env), d_sslds(nullptr), d_valuation(valuation), d_termReg(tr)
30
{
31
6271
}
32
33
6268
StringsFmf::~StringsFmf() {}
34
35
55
void StringsFmf::presolve()
36
{
37
55
  d_sslds.reset(new StringSumLengthDecisionStrategy(d_env, d_valuation));
38
110
  Trace("strings-dstrat-reg")
39
55
      << "presolve: register decision strategy." << std::endl;
40
55
  const NodeSet& ivars = d_termReg.getInputVars();
41
110
  std::vector<Node> inputVars;
42
165
  for (NodeSet::const_iterator itr = ivars.begin(); itr != ivars.end(); ++itr)
43
  {
44
110
    inputVars.push_back(*itr);
45
  }
46
55
  d_sslds->initialize(inputVars);
47
55
}
48
49
55
DecisionStrategy* StringsFmf::getDecisionStrategy() const
50
{
51
55
  return d_sslds.get();
52
}
53
54
55
StringsFmf::StringSumLengthDecisionStrategy::StringSumLengthDecisionStrategy(
55
55
    Env& env, Valuation valuation)
56
55
    : DecisionStrategyFmf(env, valuation), d_inputVarLsum(userContext())
57
{
58
55
}
59
60
bool StringsFmf::StringSumLengthDecisionStrategy::isInitialized()
61
{
62
  return !d_inputVarLsum.get().isNull();
63
}
64
65
55
void StringsFmf::StringSumLengthDecisionStrategy::initialize(
66
    const std::vector<Node>& vars)
67
{
68
55
  if (d_inputVarLsum.get().isNull() && !vars.empty())
69
  {
70
52
    NodeManager* nm = NodeManager::currentNM();
71
104
    std::vector<Node> sum;
72
162
    for (const Node& v : vars)
73
    {
74
110
      sum.push_back(nm->mkNode(STRING_LENGTH, v));
75
    }
76
104
    Node sumn = sum.size() == 1 ? sum[0] : nm->mkNode(PLUS, sum);
77
52
    d_inputVarLsum.set(sumn);
78
  }
79
55
}
80
81
266
Node StringsFmf::StringSumLengthDecisionStrategy::mkLiteral(unsigned i)
82
{
83
266
  if (d_inputVarLsum.get().isNull())
84
  {
85
    return Node::null();
86
  }
87
266
  NodeManager* nm = NodeManager::currentNM();
88
532
  Node lit = nm->mkNode(LEQ, d_inputVarLsum.get(), nm->mkConst(Rational(i)));
89
266
  Trace("strings-fmf") << "StringsFMF::mkLiteral: " << lit << std::endl;
90
266
  return lit;
91
}
92
121891
std::string StringsFmf::StringSumLengthDecisionStrategy::identify() const
93
{
94
121891
  return std::string("string_sum_len");
95
}
96
97
}  // namespace strings
98
}  // namespace theory
99
22746
}  // namespace cvc5