Merge branch '1.2.x'
[cvc5.git] / src / theory / rep_set.h
1 /********************* */
2 /*! \file rep_set.h
3 ** \verbatim
4 ** Original author: Andrew Reynolds
5 ** Major contributors: Morgan Deters
6 ** Minor contributors (to current version): none
7 ** This file is part of the CVC4 project.
8 ** Copyright (c) 2009-2013 New York University and The University of Iowa
9 ** See the file COPYING in the top-level source directory for licensing
10 ** information.\endverbatim
11 **
12 ** \brief Representative set class and utilities
13 **/
14
15 #include "cvc4_private.h"
16
17 #ifndef __CVC4__THEORY__REP_SET_H
18 #define __CVC4__THEORY__REP_SET_H
19
20 #include "expr/node.h"
21 #include <map>
22
23 namespace CVC4 {
24 namespace theory {
25
26 class QuantifiersEngine;
27
28 /** this class stores a representative set */
29 class RepSet {
30 public:
31 RepSet(){}
32 ~RepSet(){}
33 std::map< TypeNode, std::vector< Node > > d_type_reps;
34 std::map< TypeNode, bool > d_type_complete;
35 std::map< Node, int > d_tmap;
36 /** clear the set */
37 void clear();
38 /** has type */
39 bool hasType( TypeNode tn ) const { return d_type_reps.find( tn )!=d_type_reps.end(); }
40 /** get cardinality for type */
41 int getNumRepresentatives( TypeNode tn ) const;
42 /** add representative for type */
43 void add( Node n );
44 /** returns index in d_type_reps for node n */
45 int getIndexFor( Node n ) const;
46 /** complete all values */
47 void complete( TypeNode t );
48 /** debug print */
49 void toStream(std::ostream& out);
50 };/* class RepSet */
51
52 //representative domain
53 typedef std::vector< int > RepDomain;
54
55 /** this class iterates over a RepSet */
56 class RepSetIterator {
57 private:
58 enum {
59 ENUM_DOMAIN_ELEMENTS,
60 ENUM_RANGE,
61 };
62
63 //initialize function
64 bool initialize(QuantifiersEngine * qe, Node f);
65 //enumeration type?
66 std::vector< int > d_enum_type;
67 //for enum ranges
68 std::map< int, Node > d_lower_bounds;
69 //domain size
70 int domainSize( int i );
71 public:
72 RepSetIterator( RepSet* rs );
73 ~RepSetIterator(){}
74 //set that this iterator will be iterating over instantiations for a quantifier
75 bool setQuantifier( QuantifiersEngine * qe, Node f );
76 //set that this iterator will be iterating over the domain of a function
77 bool setFunctionDomain( QuantifiersEngine * qe, Node op );
78 public:
79 //pointer to model
80 RepSet* d_rep_set;
81 //index we are considering
82 std::vector< int > d_index;
83 //types we are considering
84 std::vector< TypeNode > d_types;
85 //domain we are considering
86 std::vector< RepDomain > d_domain;
87 //are we only considering a strict subset of the domain of the quantifier?
88 bool d_incomplete;
89 //ordering for variables we are indexing over
90 // for example, given reps = { a, b } and quantifier forall( x, y, z ) P( x, y, z ) with d_index_order = { 2, 0, 1 },
91 // then we consider instantiations in this order:
92 // a/x a/y a/z
93 // a/x b/y a/z
94 // b/x a/y a/z
95 // b/x b/y a/z
96 // ...
97 std::vector< int > d_index_order;
98 //variables to index they are considered at
99 // for example, if d_index_order = { 2, 0, 1 }
100 // then d_var_order = { 0 -> 1, 1 -> 2, 2 -> 0 }
101 std::map< int, int > d_var_order;
102 public:
103 /** set index order */
104 void setIndexOrder( std::vector< int >& indexOrder );
105 /** set domain */
106 //void setDomain( std::vector< RepDomain >& domain );
107 /** increment the iterator at index=counter */
108 void increment2( int counter );
109 /** increment the iterator */
110 void increment();
111 /** is the iterator finished? */
112 bool isFinished();
113 /** get the i_th term we are considering */
114 Node getTerm( int i );
115 /** get the number of terms we are considering */
116 int getNumTerms() { return (int)d_index_order.size(); }
117 /** debug print */
118 void debugPrint( const char* c );
119 void debugPrintSmall( const char* c );
120 };/* class RepSetIterator */
121
122 }/* CVC4::theory namespace */
123 }/* CVC4 namespace */
124
125 #endif /* __CVC4__THEORY__REP_SET_H */