1 /********************* */
2 /*! \file decision_engine.cpp
4 ** Top contributors (to current version):
5 ** Kshitij Bansal, Tim King, Andres Noetzli
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2019 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.\endverbatim
12 ** \brief Decision engine
16 #include "decision/decision_engine.h"
18 #include "decision/decision_attributes.h"
19 #include "decision/justification_heuristic.h"
20 #include "expr/node.h"
21 #include "options/decision_options.h"
22 #include "options/smt_options.h"
28 DecisionEngine::DecisionEngine(context::Context
* sc
,
29 context::UserContext
* uc
,
31 : d_enabledITEStrategy(nullptr),
33 d_relevancyStrategy(nullptr),
39 d_result(sc
, SAT_VALUE_UNKNOWN
),
43 Trace("decision") << "Creating decision engine" << std::endl
;
46 void DecisionEngine::init()
48 Assert(d_engineState
== 0);
51 Trace("decision-init") << "DecisionEngine::init()" << std::endl
;
52 Trace("decision-init") << " * options->decisionMode: "
53 << options::decisionMode() << std:: endl
;
54 Trace("decision-init") << " * options->decisionStopOnly: "
55 << options::decisionStopOnly() << std::endl
;
57 if (options::decisionMode() == options::DecisionMode::JUSTIFICATION
)
59 d_enabledITEStrategy
.reset(new decision::JustificationHeuristic(
60 this, d_userContext
, d_satContext
));
61 d_needIteSkolemMap
.push_back(d_enabledITEStrategy
.get());
65 void DecisionEngine::shutdown()
67 Trace("decision") << "Shutting down decision engine" << std::endl
;
69 Assert(d_engineState
== 1);
71 d_enabledITEStrategy
.reset(nullptr);
72 d_needIteSkolemMap
.clear();
75 SatLiteral
DecisionEngine::getNext(bool& stopSearch
)
77 d_resourceManager
->spendResource(ResourceManager::Resource::DecisionStep
);
78 Assert(d_cnfStream
!= nullptr)
79 << "Forgot to set cnfStream for decision engine?";
80 Assert(d_satSolver
!= nullptr)
81 << "Forgot to set satSolver for decision engine?";
83 return d_enabledITEStrategy
== nullptr
85 : d_enabledITEStrategy
->getNext(stopSearch
);
88 bool DecisionEngine::isRelevant(SatVariable var
)
90 Debug("decision") << "isRelevant(" << var
<<")" << std::endl
;
91 if (d_relevancyStrategy
!= nullptr)
93 //Assert(d_cnfStream->hasNode(var));
94 return d_relevancyStrategy
->isRelevant( d_cnfStream
->getNode(SatLiteral(var
)) );
102 SatValue
DecisionEngine::getPolarity(SatVariable var
)
104 Debug("decision") << "getPolarity(" << var
<<")" << std::endl
;
105 if (d_relevancyStrategy
!= nullptr)
107 Assert(isRelevant(var
));
108 return d_relevancyStrategy
->getPolarity( d_cnfStream
->getNode(SatLiteral(var
)) );
112 return SAT_VALUE_UNKNOWN
;
116 void DecisionEngine::addAssertions(
117 const preprocessing::AssertionPipeline
& assertions
)
119 // new assertions, reset whatever result we knew
120 d_result
= SAT_VALUE_UNKNOWN
;
122 for (const Node
& assertion
: assertions
)
124 d_assertions
.push_back(assertion
);
127 for(unsigned i
= 0; i
< d_needIteSkolemMap
.size(); ++i
)
129 d_needIteSkolemMap
[i
]->addAssertions(assertions
);
133 }/* CVC4 namespace */