summaryrefslogtreecommitdiff
path: root/src/decision/decision_engine_old.h
blob: 4e7bde4b53178ee957a3871aa484b2979689bc1d (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/******************************************************************************
 * Top contributors (to current version):
 *   Kshitij Bansal, Andrew Reynolds, Morgan Deters
 *
 * 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.
 * ****************************************************************************
 *
 * Old implementation of the decision engine
 */

#include "cvc5_private.h"

#ifndef CVC5__DECISION__DECISION_ENGINE_OLD_H
#define CVC5__DECISION__DECISION_ENGINE_OLD_H

#include "base/output.h"
#include "context/cdo.h"
#include "decision/decision_strategy.h"
#include "expr/node.h"
#include "prop/cnf_stream.h"
#include "prop/sat_solver.h"
#include "prop/sat_solver_types.h"
#include "util/result.h"

using namespace cvc5::prop;
using namespace cvc5::decision;

namespace cvc5 {

class DecisionEngineOld
{
 public:
  // Necessary functions

  /** Constructor */
  DecisionEngineOld(context::Context* sc, context::UserContext* uc);

  /** Destructor, currently does nothing */
  ~DecisionEngineOld()
  {
    Trace("decision") << "Destroying decision engine" << std::endl;
  }

  void setSatSolver(CDCLTSatSolverInterface* ss)
  {
    // setPropEngine should not be called more than once
    Assert(d_satSolver == NULL);
    Assert(ss != NULL);
    d_satSolver = ss;
  }

  void setCnfStream(CnfStream* cs)
  {
    // setPropEngine should not be called more than once
    Assert(d_cnfStream == NULL);
    Assert(cs != NULL);
    d_cnfStream = cs;
  }

  /**
   * This is called by SmtEngine, at shutdown time, just before
   * destruction.  It is important because there are destruction
   * ordering issues between some parts of the system.
   */
  void shutdown();

  // Interface for External World to use our services

  /** Gets the next decision based on strategies that are enabled */
  SatLiteral getNext(bool& stopSearch);

  /** Is the DecisionEngineOld in a state where it has solved everything? */
  bool isDone()
  {
    Trace("decision") << "DecisionEngineOld::isDone() returning "
                      << (d_result != SAT_VALUE_UNKNOWN)
                      << (d_result != SAT_VALUE_UNKNOWN ? "true" : "false")
                      << std::endl;
    return (d_result != SAT_VALUE_UNKNOWN);
  }

  /** */
  Result getResult()
  {
    switch (d_result.get())
    {
      case SAT_VALUE_TRUE: return Result(Result::SAT);
      case SAT_VALUE_FALSE: return Result(Result::UNSAT);
      case SAT_VALUE_UNKNOWN:
        return Result(Result::SAT_UNKNOWN, Result::UNKNOWN_REASON);
      default: Assert(false) << "d_result is garbage";
    }
    return Result();
  }

  /** */
  void setResult(SatValue val) { d_result = val; }

  // External World helping us help the Strategies

  /**
   * Notify this class that assertion is an (input) assertion, not corresponding
   * to a skolem definition.
   */
  void addAssertion(TNode assertion);
  /**
   * Notify this class  that lem is the skolem definition for skolem, which is
   * a part of the current assertions.
   */
  void addSkolemDefinition(TNode lem, TNode skolem);

  // Interface for Strategies to use stuff stored in Decision Engine
  // (which was possibly requested by them on initialization)

  // Interface for Strategies to get information about External World

  bool hasSatLiteral(TNode n) { return d_cnfStream->hasLiteral(n); }
  SatLiteral getSatLiteral(TNode n) { return d_cnfStream->getLiteral(n); }
  SatValue getSatValue(SatLiteral l) { return d_satSolver->value(l); }
  SatValue getSatValue(TNode n) { return getSatValue(getSatLiteral(n)); }
  Node getNode(SatLiteral l) { return d_cnfStream->getNode(l); }

 private:
  // Disable creating decision engine without required parameters
  DecisionEngineOld();

  CnfStream* d_cnfStream;
  CDCLTSatSolverInterface* d_satSolver;

  context::Context* d_satContext;
  context::UserContext* d_userContext;

  // Does decision engine know the answer?
  context::CDO<SatValue> d_result;

  // init/shutdown state
  unsigned d_engineState;  // 0=pre-init; 1=init,pre-shutdown; 2=shutdown
  /** The ITE decision strategy we have allocated */
  std::unique_ptr<ITEDecisionStrategy> d_enabledITEStrategy;

}; /* DecisionEngineOld class */

}  // namespace cvc5

#endif /* CVC5__DECISION__DECISION_ENGINE_H */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback