1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds |
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 module for processing the difficulty of input assumptions |
14 |
|
* based on proof nodes. |
15 |
|
*/ |
16 |
|
|
17 |
|
#include "smt/difficulty_post_processor.h" |
18 |
|
|
19 |
|
#include "smt/env.h" |
20 |
|
#include "util/rational.h" |
21 |
|
|
22 |
|
using namespace cvc5::kind; |
23 |
|
using namespace cvc5::theory; |
24 |
|
|
25 |
|
namespace cvc5 { |
26 |
|
namespace smt { |
27 |
|
|
28 |
|
DifficultyPostprocessCallback::DifficultyPostprocessCallback() |
29 |
|
: d_currDifficulty(0) |
30 |
|
{ |
31 |
|
} |
32 |
|
|
33 |
|
bool DifficultyPostprocessCallback::setCurrentDifficulty(Node d) |
34 |
|
{ |
35 |
|
if (d.isConst() && d.getType().isInteger() |
36 |
|
&& d.getConst<Rational>().sgn() >= 0 |
37 |
|
&& d.getConst<Rational>().getNumerator().fitsUnsignedInt()) |
38 |
|
{ |
39 |
|
d_currDifficulty = d.getConst<Rational>().getNumerator().toUnsignedInt(); |
40 |
|
return true; |
41 |
|
} |
42 |
|
return false; |
43 |
|
} |
44 |
|
|
45 |
|
bool DifficultyPostprocessCallback::shouldUpdate(std::shared_ptr<ProofNode> pn, |
46 |
|
const std::vector<Node>& fa, |
47 |
|
bool& continueUpdate) |
48 |
|
{ |
49 |
|
PfRule r = pn->getRule(); |
50 |
|
if (r == PfRule::ASSUME) |
51 |
|
{ |
52 |
|
Trace("difficulty-debug") |
53 |
|
<< " found assume: " << pn->getResult() << std::endl; |
54 |
|
d_accMap[pn->getResult()] += d_currDifficulty; |
55 |
|
} |
56 |
|
else if (r == PfRule::MACRO_SR_EQ_INTRO || r == PfRule::MACRO_SR_PRED_INTRO) |
57 |
|
{ |
58 |
|
// premise is just a substitution, ignore |
59 |
|
continueUpdate = false; |
60 |
|
return false; |
61 |
|
} |
62 |
|
return true; |
63 |
|
} |
64 |
|
|
65 |
|
void DifficultyPostprocessCallback::getDifficultyMap( |
66 |
|
std::map<Node, Node>& dmap) const |
67 |
|
{ |
68 |
|
Assert(dmap.empty()); |
69 |
|
NodeManager* nm = NodeManager::currentNM(); |
70 |
|
for (const std::pair<const Node, uint64_t>& d : d_accMap) |
71 |
|
{ |
72 |
|
dmap[d.first] = nm->mkConst(Rational(d.second)); |
73 |
|
} |
74 |
|
} |
75 |
|
|
76 |
|
} // namespace smt |
77 |
29502 |
} // namespace cvc5 |