summaryrefslogtreecommitdiff
path: root/src/theory/rr_candidate_generator.cpp
blob: a2e895c7f5402c836fb8946f619697d38bdb5b2f (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
/*********************                                                        */
/*! \file rr_candidate_generator.cpp
 ** \verbatim
 ** Original author: ajreynol
 ** Major contributors: bobot
 ** 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 Implementation of rr candidate generator class
 **/

#include "theory/rr_candidate_generator.h"
#include "theory/theory_engine.h"
#include "theory/uf/theory_uf.h"
#include "theory/quantifiers/term_database.h"

using namespace std;
using namespace CVC4;
using namespace CVC4::kind;
using namespace CVC4::context;
using namespace CVC4::theory;
using namespace CVC4::theory::rrinst;

GenericCandidateGeneratorClasses::GenericCandidateGeneratorClasses(QuantifiersEngine * qe){
  for(TheoryId i = THEORY_FIRST; i < theory::THEORY_LAST; ++i){
    if(qe->getInstantiator(i) != NULL)
      d_can_gen[i] = qe->getInstantiator(i)->getRRCanGenClasses();
    else d_can_gen[i] = NULL;
  }
}

GenericCandidateGeneratorClasses::~GenericCandidateGeneratorClasses(){
  for(TheoryId i = THEORY_FIRST; i < theory::THEORY_LAST; ++i){
    delete(d_can_gen[i]);
  }
}

void GenericCandidateGeneratorClasses::resetInstantiationRound(){
  for(TheoryId i = THEORY_FIRST; i < theory::THEORY_LAST; ++i){
    if(d_can_gen[i] != NULL) d_can_gen[i]->resetInstantiationRound();
  }
  d_can_gen_id=THEORY_FIRST;
}

void GenericCandidateGeneratorClasses::reset(TNode eqc){
  Assert(eqc.isNull());
  for(TheoryId i = THEORY_FIRST; i < theory::THEORY_LAST; ++i){
    if(d_can_gen[i] != NULL) d_can_gen[i]->reset(eqc);
  }
  d_can_gen_id=THEORY_FIRST;
  lookForNextTheory();
}

TNode GenericCandidateGeneratorClasses::getNextCandidate(){
  Assert(THEORY_FIRST <= d_can_gen_id && d_can_gen_id <= THEORY_LAST);
  /** No more */
  if(d_can_gen_id == THEORY_LAST) return TNode::null();
  /** Try with this theory */
  TNode cand = d_can_gen[d_can_gen_id]->getNextCandidate();
  if( !cand.isNull() ) return cand;
  lookForNextTheory();
  return getNextCandidate();
}

void GenericCandidateGeneratorClasses::lookForNextTheory(){
  do{ /* look for the next available generator */
    ++d_can_gen_id;
  } while( d_can_gen_id < THEORY_LAST && d_can_gen[d_can_gen_id] == NULL);
}

GenericCandidateGeneratorClass::GenericCandidateGeneratorClass(QuantifiersEngine * qe): d_qe(qe) {
  for(TheoryId i = THEORY_FIRST; i < theory::THEORY_LAST; ++i){
    if(d_qe->getInstantiator(i) != NULL)
      d_can_gen[i] = d_qe->getInstantiator(i)->getRRCanGenClass();
    else d_can_gen[i] = NULL;
  }
}

GenericCandidateGeneratorClass::~GenericCandidateGeneratorClass(){
  for(TheoryId i = THEORY_FIRST; i < theory::THEORY_LAST; ++i){
    delete(d_can_gen[i]);
  }
}

void GenericCandidateGeneratorClass::resetInstantiationRound(){
  for(TheoryId i = THEORY_FIRST; i < theory::THEORY_LAST; ++i){
    if(d_can_gen[i] != NULL) d_can_gen[i]->resetInstantiationRound();
  }
  d_can_gen_id=THEORY_FIRST;
}

void GenericCandidateGeneratorClass::reset(TNode eqc){
  for(TheoryId i = THEORY_FIRST; i < theory::THEORY_LAST; ++i){
    if(d_can_gen[i] != NULL) d_can_gen[i]->reset(eqc);
  }
  d_can_gen_id=THEORY_FIRST;
  d_node = eqc;
  lookForNextTheory();
}

TNode GenericCandidateGeneratorClass::getNextCandidate(){
  Assert(THEORY_FIRST <= d_can_gen_id && d_can_gen_id <= THEORY_LAST);
  /** No more */
  if(d_can_gen_id == THEORY_LAST) return TNode::null();
  /** Try with this theory */
  TNode cand = d_can_gen[d_can_gen_id]->getNextCandidate();
  if( !cand.isNull() ) return cand;
  lookForNextTheory();
  return getNextCandidate();
}

void GenericCandidateGeneratorClass::lookForNextTheory(){
  do{ /* look for the next available generator, where the element is */
    ++d_can_gen_id;
  } while(
          d_can_gen_id < THEORY_LAST &&
          (d_can_gen[d_can_gen_id] == NULL ||
           !d_qe->getInstantiator( d_can_gen_id )->hasTerm( d_node ))
          );
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback