summaryrefslogtreecommitdiff
path: root/src/theory/arith/arith_prop_manager.h
blob: 82f58c7a012ce5bcc675e5d82399d2ed2b574b4b (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
151
152
153
154
155
156
/*********************                                                        */
/*! \file arith_prop_manager.h
 ** \verbatim
 ** Original author: taking
 ** Major contributors: none
 ** Minor contributors (to current version): none
 ** This file is part of the CVC4 prototype.
 ** Copyright (c) 2009, 2010, 2011  The Analysis of Computer Systems Group (ACSys)
 ** Courant Institute of Mathematical Sciences
 ** New York University
 ** See the file COPYING in the top-level source directory for licensing
 ** information.\endverbatim
 **
 ** \brief [[ Add one-line brief description here ]]
 **
 ** [[ Add lengthier description here ]]
 ** \todo document this file
 **/

#include "cvc4_private.h"

#ifndef __CVC4__THEORY__ARITH__ARITH_PROP_MANAGER_H
#define __CVC4__THEORY__ARITH__ARITH_PROP_MANAGER_H

#include "theory/valuation.h"
#include "theory/arith/arith_utilities.h"
#include "theory/arith/arithvar_node_map.h"
#include "theory/arith/atom_database.h"
#include "theory/arith/delta_rational.h"
#include "context/context.h"
#include "context/cdlist.h"
#include "context/cdmap.h"
#include "context/cdo.h"

#include "util/stats.h"

namespace CVC4 {
namespace theory {
namespace arith {

class PropManager {
private:
  context::CDList<TNode> d_propagated;
  context::CDO<uint32_t> d_propagatedPos;
  typedef context::CDMap<TNode, TNode, TNodeHashFunction> ExplainMap;

  ExplainMap d_explanationMap;

  context::CDList<Node> d_reasons;

public:

  PropManager(context::Context* c):
    d_propagated(c),
    d_propagatedPos(c, 0),
    d_explanationMap(c),
    d_reasons(c)
  { }

  bool isPropagated(TNode n) const {
    return d_explanationMap.find(n) != d_explanationMap.end();
  }

  void propagate(TNode n, Node reason) {
    Assert(!isPropagated(n));
    Assert(reason.getKind() == kind::AND);

    d_explanationMap.insert(n, reason);

    d_reasons.push_back(reason);
    d_propagated.push_back(n);

    Debug("ArithPropManager") << n  << std::endl << "<="<< reason<< std::endl;
  }

  bool hasMorePropagations() const {
    return d_propagatedPos < d_propagated.size();
  }

  TNode getPropagation() {
    Assert(hasMorePropagations());
    TNode prop = d_propagated[d_propagatedPos];
    d_propagatedPos = d_propagatedPos + 1;
    return prop;
  }

  TNode explain(TNode n) const {
    Assert(isPropagated(n));
    ExplainMap::iterator p = d_explanationMap.find(n);
    return (*p).second;
  }

};/* class PropManager */

class ArithPropManager : public PropManager {
private:
  const ArithVarNodeMap& d_arithvarNodeMap;
  const ArithAtomDatabase& d_atomDatabase;
  Valuation d_valuation;

public:
  ArithPropManager(context::Context* c,
                   const ArithVarNodeMap& map,
                   const ArithAtomDatabase& db,
                   Valuation v):
    PropManager(c), d_arithvarNodeMap(map), d_atomDatabase(db), d_valuation(v)
  {}

  /**
   * Returns true if the node has a value in sat solver in the current context.
   * In debug mode this fails an Assert() if the node has a negative assignment.
   */
  bool isAsserted(TNode n) const;

  /** Returns true if a bound was added. */
  bool propagateArithVar(bool upperbound, ArithVar var, const DeltaRational& b, TNode reason);

  Node boundAsNode(bool upperbound, ArithVar var, const DeltaRational& b) const;

  Node strictlyWeakerLowerBound(TNode n) const{
    return d_atomDatabase.getWeakerImpliedLowerBound(n);
  }
  Node strictlyWeakerUpperBound(TNode n) const{
    return d_atomDatabase.getWeakerImpliedUpperBound(n);
  }

  Node strictlyWeakerAssertedUpperBound(ArithVar v, const DeltaRational& b) const;

  Node strictlyWeakerAssertedLowerBound(ArithVar v, const DeltaRational& b) const;

  Node getBestImpliedLowerBound(ArithVar v, const DeltaRational& b) const;
  Node getBestImpliedUpperBound(ArithVar v, const DeltaRational& b) const;

  bool containsLiteral(TNode n) const {
    return d_atomDatabase.containsLiteral(n);
  }

private:
  class Statistics {
  public:
    IntStat d_propagateArithVarCalls;
    IntStat d_addedPropagation;
    IntStat d_alreadySetSatLiteral;
    IntStat d_alreadyPropagatedNode;

    Statistics();
    ~Statistics();
  };
  Statistics d_statistics;
};

}/* CVC4::theory::arith namespace */
}/* CVC4::theory namespace */
}/* CVC4 namespace */

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