GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/strings/strings_fmf.cpp Lines: 38 41 92.7 %
Date: 2021-09-18 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
9940
StringsFmf::StringsFmf(Env& env, Valuation valuation, TermRegistry& tr)
29
9940
    : EnvObj(env), d_sslds(nullptr), d_valuation(valuation), d_termReg(tr)
30
{
31
9940
}
32
33
9937
StringsFmf::~StringsFmf() {}
34
35
78
void StringsFmf::presolve()
36
{
37
78
  d_sslds.reset(new StringSumLengthDecisionStrategy(d_env, d_valuation));
38
156
  Trace("strings-dstrat-reg")
39
78
      << "presolve: register decision strategy." << std::endl;
40
78
  const NodeSet& ivars = d_termReg.getInputVars();
41
156
  std::vector<Node> inputVars;
42
232
  for (NodeSet::const_iterator itr = ivars.begin(); itr != ivars.end(); ++itr)
43
  {
44
154
    inputVars.push_back(*itr);
45
  }
46
78
  d_sslds->initialize(inputVars);
47
78
}
48
49
78
DecisionStrategy* StringsFmf::getDecisionStrategy() const
50
{
51
78
  return d_sslds.get();
52
}
53
54
78
StringsFmf::StringSumLengthDecisionStrategy::StringSumLengthDecisionStrategy(
55
78
    Env& env, Valuation valuation)
56
78
    : DecisionStrategyFmf(env, valuation), d_inputVarLsum(userContext())
57
{
58
78
}
59
60
bool StringsFmf::StringSumLengthDecisionStrategy::isInitialized()
61
{
62
  return !d_inputVarLsum.get().isNull();
63
}
64
65
78
void StringsFmf::StringSumLengthDecisionStrategy::initialize(
66
    const std::vector<Node>& vars)
67
{
68
78
  if (d_inputVarLsum.get().isNull() && !vars.empty())
69
  {
70
70
    NodeManager* nm = NodeManager::currentNM();
71
140
    std::vector<Node> sum;
72
224
    for (const Node& v : vars)
73
    {
74
154
      sum.push_back(nm->mkNode(STRING_LENGTH, v));
75
    }
76
140
    Node sumn = sum.size() == 1 ? sum[0] : nm->mkNode(PLUS, sum);
77
70
    d_inputVarLsum.set(sumn);
78
  }
79
78
}
80
81
302
Node StringsFmf::StringSumLengthDecisionStrategy::mkLiteral(unsigned i)
82
{
83
302
  if (d_inputVarLsum.get().isNull())
84
  {
85
    return Node::null();
86
  }
87
302
  NodeManager* nm = NodeManager::currentNM();
88
604
  Node lit = nm->mkNode(LEQ, d_inputVarLsum.get(), nm->mkConst(Rational(i)));
89
302
  Trace("strings-fmf") << "StringsFMF::mkLiteral: " << lit << std::endl;
90
302
  return lit;
91
}
92
123906
std::string StringsFmf::StringSumLengthDecisionStrategy::identify() const
93
{
94
123906
  return std::string("string_sum_len");
95
}
96
97
}  // namespace strings
98
}  // namespace theory
99
29574
}  // namespace cvc5