1 /********************* */
2 /*! \file inst_strategy_cbqi.h
4 ** Top contributors (to current version):
5 ** Andrew Reynolds, Morgan Deters, Tim King
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2017 by the authors listed in the file AUTHORS
8 ** in the top-level source directory) and their institutional affiliations.
9 ** All rights reserved. See the file COPYING in the top-level source
10 ** directory for licensing information.\endverbatim
12 ** \brief counterexample-guided quantifier instantiation
16 #include "cvc4_private.h"
18 #ifndef __CVC4__INST_STRATEGY_CBQI_H
19 #define __CVC4__INST_STRATEGY_CBQI_H
21 #include "theory/arith/arithvar.h"
22 #include "theory/quantifiers/cegqi/ceg_instantiator.h"
23 #include "theory/quantifiers/ematching/instantiation_engine.h"
24 #include "util/statistics_registry.h"
33 namespace quantifiers
{
35 class InstStrategyCbqi
: public QuantifiersModule
{
36 typedef context::CDHashSet
<Node
, NodeHashFunction
> NodeSet
;
37 typedef context::CDHashMap
< Node
, int, NodeHashFunction
> NodeIntMap
;
40 bool d_cbqi_set_quant_inactive
;
41 bool d_incomplete_check
;
42 /** whether we have added cbqi lemma */
43 NodeSet d_added_cbqi_lemma
;
44 /** whether we have added cbqi lemma */
45 NodeSet d_elim_quants
;
47 std::map
< Node
, std::vector
< Node
> > d_parent_quant
;
48 std::map
< Node
, std::vector
< Node
> > d_children_quant
;
49 std::map
< Node
, bool > d_active_quant
;
50 /** Whether cegqi handles each quantified formula. */
51 std::map
<Node
, CegHandledStatus
> d_do_cbqi
;
52 /** register ce lemma */
53 bool registerCbqiLemma( Node q
);
54 virtual void registerCounterexampleLemma( Node q
, Node lem
);
55 /** has added cbqi lemma */
56 bool hasAddedCbqiLemma( Node q
) { return d_added_cbqi_lemma
.find( q
)!=d_added_cbqi_lemma
.end(); }
57 /** get next decision request with dependency checking */
58 Node
getNextDecisionRequestProc( Node q
, std::map
< Node
, bool >& proc
);
59 /** process functions */
60 virtual void processResetInstantiationRound( Theory::Effort effort
) = 0;
61 virtual void process( Node q
, Theory::Effort effort
, int e
) = 0;
67 std::map
< Node
, Node
> d_nested_qe
;
68 //mark ids on quantifiers
69 Node
getIdMarkedQuantNode( Node n
, std::map
< Node
, Node
>& visited
);
71 std::map
< Node
, Node
> d_id_to_ce_quant
;
72 std::map
< Node
, Node
> d_ce_quant_to_id
;
73 //do nested quantifier elimination recursive
74 Node
doNestedQENode( Node q
, Node ceq
, Node n
, std::vector
< Node
>& inst_terms
, bool doVts
);
75 Node
doNestedQERec( Node q
, Node n
, std::map
< Node
, Node
>& visited
, std::vector
< Node
>& inst_terms
, bool doVts
);
76 //elimination information (for delayed elimination)
79 NestedQEInfo() : d_doVts(false){}
82 std::vector
< Node
> d_inst_terms
;
85 std::map
< Node
, NestedQEInfo
> d_nested_qe_info
;
86 NodeIntMap d_nested_qe_waitlist_size
;
87 NodeIntMap d_nested_qe_waitlist_proc
;
88 std::map
< Node
, std::vector
< Node
> > d_nested_qe_waitlist
;
91 //do nested quantifier elimination
92 Node
doNestedQE( Node q
, std::vector
< Node
>& inst_terms
, Node lem
, bool doVts
);
95 InstStrategyCbqi( QuantifiersEngine
* qe
);
97 /** whether to do CBQI for quantifier q */
98 bool doCbqi( Node q
);
99 /** process functions */
100 bool needsCheck(Theory::Effort e
) override
;
101 QEffort
needsModel(Theory::Effort e
) override
;
102 void reset_round(Theory::Effort e
) override
;
103 void check(Theory::Effort e
, QEffort quant_e
) override
;
104 bool checkComplete() override
;
105 bool checkCompleteFor(Node q
) override
;
106 void preRegisterQuantifier(Node q
) override
;
107 void registerQuantifier(Node q
) override
;
108 /** get next decision request */
109 Node
getNextDecisionRequest(unsigned& priority
) override
;
112 //generalized counterexample guided quantifier instantiation
114 class InstStrategyCegqi
;
116 class CegqiOutputInstStrategy
: public CegqiOutput
{
118 CegqiOutputInstStrategy( InstStrategyCegqi
* out
) : d_out( out
){}
119 InstStrategyCegqi
* d_out
;
120 bool doAddInstantiation(std::vector
<Node
>& subs
) override
;
121 bool isEligibleForInstantiation(Node n
) override
;
122 bool addLemma(Node lem
) override
;
125 class InstStrategyCegqi
: public InstStrategyCbqi
{
127 CegqiOutputInstStrategy
* d_out
;
128 std::map
< Node
, CegInstantiator
* > d_cinst
;
131 bool d_check_vts_lemma_lc
;
132 /** process functions */
133 void processResetInstantiationRound(Theory::Effort effort
) override
;
134 void process(Node f
, Theory::Effort effort
, int e
) override
;
135 /** register ce lemma */
136 void registerCounterexampleLemma(Node q
, Node lem
) override
;
139 InstStrategyCegqi( QuantifiersEngine
* qe
);
140 ~InstStrategyCegqi() override
;
142 bool doAddInstantiation( std::vector
< Node
>& subs
);
143 bool isEligibleForInstantiation( Node n
);
144 bool addLemma( Node lem
);
146 std::string
identify() const override
{ return std::string("Cegqi"); }
148 //get instantiator for quantifier
149 CegInstantiator
* getInstantiator( Node q
);
150 //register quantifier
151 void registerQuantifier(Node q
) override
;
153 void presolve() override
;