blob: 31797ba5e88a45d9bf4645a9b11b65176978eb66 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/******************************************************************************
* Top contributors (to current version):
* Andrew Reynolds
*
* This file is part of the cvc5 project.
*
* Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
* in the top-level source directory and their institutional affiliations.
* All rights reserved. See the file COPYING in the top-level source
* directory for licensing information.
* ****************************************************************************
*
* Implementation of module for processing the difficulty of input assumptions
* based on proof nodes.
*/
#include "smt/difficulty_post_processor.h"
#include "smt/env.h"
#include "util/rational.h"
using namespace cvc5::kind;
using namespace cvc5::theory;
namespace cvc5 {
namespace smt {
DifficultyPostprocessCallback::DifficultyPostprocessCallback()
: d_currDifficulty(0)
{
}
bool DifficultyPostprocessCallback::setCurrentDifficulty(Node d)
{
if (d.isConst() && d.getType().isInteger()
&& d.getConst<Rational>().sgn() >= 0
&& d.getConst<Rational>().getNumerator().fitsUnsignedInt())
{
d_currDifficulty = d.getConst<Rational>().getNumerator().toUnsignedInt();
return true;
}
return false;
}
bool DifficultyPostprocessCallback::shouldUpdate(std::shared_ptr<ProofNode> pn,
const std::vector<Node>& fa,
bool& continueUpdate)
{
PfRule r = pn->getRule();
if (r == PfRule::ASSUME)
{
Trace("difficulty-debug")
<< " found assume: " << pn->getResult() << std::endl;
d_accMap[pn->getResult()] += d_currDifficulty;
}
else if (r == PfRule::MACRO_SR_EQ_INTRO || r == PfRule::MACRO_SR_PRED_INTRO)
{
// premise is just a substitution, ignore
continueUpdate = false;
return false;
}
return true;
}
void DifficultyPostprocessCallback::getDifficultyMap(
std::map<Node, Node>& dmap) const
{
Assert(dmap.empty());
NodeManager* nm = NodeManager::currentNM();
for (const std::pair<const Node, uint64_t>& d : d_accMap)
{
dmap[d.first] = nm->mkConst(CONST_RATIONAL, Rational(d.second));
}
}
} // namespace smt
} // namespace cvc5
|