summaryrefslogtreecommitdiff
path: root/src/theory/arith/ordered_set.h
blob: e44ba8687c1be0a21964c5d602acf85db7780b31 (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
#include <map>
#include <set>
#include "expr/kind.h"
#include "expr/node.h"
#include "util/Assert.h"
#include "theory/arith/arith_utilities.h"


namespace CVC4 {
namespace theory {
namespace arith {

inline const Rational& rightHandRational(TNode ineq){
  Assert(ineq.getKind() == kind::LEQ
         || ineq.getKind() == kind::GEQ
         || ineq.getKind() == kind::EQUAL);
  TNode righthand = ineq[1];
  Assert(righthand.getKind() == kind::CONST_RATIONAL);
  return righthand.getConst<Rational>();
}

class BoundValueEntry {
private:
  const Rational& value;
  TNode d_leq, d_geq;

  BoundValueEntry(const Rational& v, TNode l, TNode g):
    value(v),
    d_leq(l),
    d_geq(g)
  {}

public:
  Node getLeq() const{
    Assert(hasLeq());
    return d_leq;
  }
  Node getGeq() const{
    Assert(hasGeq());
    return d_geq;
  }

  static BoundValueEntry mkFromLeq(TNode leq){
    Assert(leq.getKind() == kind::LEQ);
    return BoundValueEntry(rightHandRational(leq), leq, TNode::null());
  }

  static BoundValueEntry mkFromGeq(TNode geq){
    Assert(geq.getKind() == kind::GEQ);
    return BoundValueEntry(rightHandRational(geq), TNode::null(), geq);
  }

  void addLeq(TNode leq){
    Assert(leq.getKind() == kind::LEQ);
    Assert(rightHandRational(leq) == getValue());
    // [MGD] With context-dependent pre-registration, we could get the
    // same one twice
    Assert(!hasLeq() || d_leq == leq);
    d_leq = leq;
  }

  void addGeq(TNode geq){
    Assert(geq.getKind() == kind::GEQ);
    Assert(rightHandRational(geq) == getValue());
    // [MGD] With context-dependent pre-registration, we could get the
    // same one twice
    Assert(!hasGeq() || d_geq == geq);
    d_geq = geq;
  }

  bool hasGeq() const { return d_geq != TNode::null(); }
  bool hasLeq() const { return d_leq != TNode::null(); }


  const Rational& getValue() const{
    return value;
  }

  bool operator<(const BoundValueEntry& other){
    return value < other.value;
  }
};

typedef std::map<Rational, BoundValueEntry> BoundValueSet;

typedef std::set<TNode, RightHandRationalLT> EqualValueSet;

// struct SetCleanupStrategy{
//   static void cleanup(OrderedSet* l){
//     Debug("arithgc") << "cleaning up  " << l << "\n";
//     delete l;
//   }
// };

}/* CVC4::theory::arith namespace */
}/* CVC4::theory namespace */
}/* CVC4 namespace */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback