GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/decision/decision_engine_old.h Lines: 10 15 66.7 %
Date: 2021-08-16 Branches: 9 26 34.6 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Kshitij Bansal, Andrew Reynolds, Morgan Deters
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
 * Old implementation of the decision engine
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__DECISION__DECISION_ENGINE_OLD_H
19
#define CVC5__DECISION__DECISION_ENGINE_OLD_H
20
21
#include "base/output.h"
22
#include "context/cdo.h"
23
#include "decision/decision_engine.h"
24
#include "decision/decision_strategy.h"
25
#include "expr/node.h"
26
#include "prop/cnf_stream.h"
27
#include "prop/sat_solver.h"
28
#include "prop/sat_solver_types.h"
29
#include "util/result.h"
30
31
using namespace cvc5::prop;
32
using namespace cvc5::decision;
33
34
namespace cvc5 {
35
36
class DecisionEngineOld : public decision::DecisionEngine
37
{
38
 public:
39
  // Necessary functions
40
41
  /** Constructor */
42
  DecisionEngineOld(context::Context* sc,
43
                    context::UserContext* uc,
44
                    ResourceManager* rm);
45
46
  /** Destructor, currently does nothing */
47
4
  ~DecisionEngineOld()
48
4
  {
49
2
    Trace("decision") << "Destroying decision engine" << std::endl;
50
4
  }
51
52
  /**
53
   * This is called by SmtEngine, at shutdown time, just before
54
   * destruction.  It is important because there are destruction
55
   * ordering issues between some parts of the system.
56
   */
57
  void shutdown();
58
59
  // Interface for External World to use our services
60
61
  /** Gets the next decision based on strategies that are enabled */
62
  SatLiteral getNextInternal(bool& stopSearch) override;
63
64
  /** Is the DecisionEngineOld in a state where it has solved everything? */
65
118
  bool isDone() override
66
  {
67
236
    Trace("decision") << "DecisionEngineOld::isDone() returning "
68
236
                      << (d_result != SAT_VALUE_UNKNOWN)
69
236
                      << (d_result != SAT_VALUE_UNKNOWN ? "true" : "false")
70
118
                      << std::endl;
71
118
    return (d_result != SAT_VALUE_UNKNOWN);
72
  }
73
74
  /** */
75
  Result getResult()
76
  {
77
    switch (d_result.get())
78
    {
79
      case SAT_VALUE_TRUE: return Result(Result::SAT);
80
      case SAT_VALUE_FALSE: return Result(Result::UNSAT);
81
      case SAT_VALUE_UNKNOWN:
82
        return Result(Result::SAT_UNKNOWN, Result::UNKNOWN_REASON);
83
      default: Assert(false) << "d_result is garbage";
84
    }
85
    return Result();
86
  }
87
88
  /** */
89
  void setResult(SatValue val) { d_result = val; }
90
91
  // External World helping us help the Strategies
92
93
  /**
94
   * Notify this class that assertion is an (input) assertion, not corresponding
95
   * to a skolem definition.
96
   */
97
  void addAssertion(TNode assertion) override;
98
  /**
99
   * Notify this class  that lem is the skolem definition for skolem, which is
100
   * a part of the current assertions.
101
   */
102
  void addSkolemDefinition(TNode lem, TNode skolem) override;
103
104
  // Interface for Strategies to use stuff stored in Decision Engine
105
  // (which was possibly requested by them on initialization)
106
107
  // Interface for Strategies to get information about External World
108
109
  bool hasSatLiteral(TNode n) { return d_cnfStream->hasLiteral(n); }
110
  SatLiteral getSatLiteral(TNode n) { return d_cnfStream->getLiteral(n); }
111
  SatValue getSatValue(SatLiteral l) { return d_satSolver->value(l); }
112
  SatValue getSatValue(TNode n) { return getSatValue(getSatLiteral(n)); }
113
  Node getNode(SatLiteral l) { return d_cnfStream->getNode(l); }
114
115
 private:
116
  // Disable creating decision engine without required parameters
117
  DecisionEngineOld();
118
119
  // Does decision engine know the answer?
120
  context::CDO<SatValue> d_result;
121
122
  // init/shutdown state
123
  unsigned d_engineState;  // 0=pre-init; 1=init,pre-shutdown; 2=shutdown
124
  /** The ITE decision strategy we have allocated */
125
  std::unique_ptr<ITEDecisionStrategy> d_enabledITEStrategy;
126
  /** Whether we are using stop only */
127
  bool d_decisionStopOnly;
128
129
}; /* DecisionEngineOld class */
130
131
}  // namespace cvc5
132
133
#endif /* CVC5__DECISION__DECISION_ENGINE_H */