1 /********************* */
2 /*! \file callbacks.cpp
3 ** \verbatim
4 ** Top contributors (to current version):
5 ** Tim King
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2019 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
11 **
12 ** \brief [[ Add one-line brief description here ]]
13 **
14 ** [[ Add lengthier description here ]]
15 ** \todo document this file
16 **/
17
18 #include "theory/arith/callbacks.h"
19 #include "theory/arith/theory_arith_private.h"
20
21 namespace CVC4 {
22 namespace theory {
23 namespace arith {
24
SetupLiteralCallBack(TheoryArithPrivate & ta)25 SetupLiteralCallBack::SetupLiteralCallBack(TheoryArithPrivate& ta)
26 : d_arith(ta)
27 {}
operator ()(TNode lit)28 void SetupLiteralCallBack::operator()(TNode lit){
29 TNode atom = (lit.getKind() == kind::NOT) ? lit[0] : lit;
30 if(!d_arith.isSetup(atom)){
31 d_arith.setupAtom(atom);
32 }
33 }
34
DeltaComputeCallback(const TheoryArithPrivate & ta)35 DeltaComputeCallback::DeltaComputeCallback(const TheoryArithPrivate& ta)
36 : d_ta(ta)
37 {}
operator ()() const38 Rational DeltaComputeCallback::operator()() const{
39 return d_ta.deltaValueForTotalOrder();
40 }
41
TempVarMalloc(TheoryArithPrivate & ta)42 TempVarMalloc::TempVarMalloc(TheoryArithPrivate& ta)
43 : d_ta(ta)
44 {}
request()45 ArithVar TempVarMalloc::request(){
46 Node skolem = mkRealSkolem("tmpVar");
47 return d_ta.requestArithVar(skolem, false, true);
48 }
release(ArithVar v)49 void TempVarMalloc::release(ArithVar v){
50 d_ta.releaseArithVar(v);
51 }
52
BasicVarModelUpdateCallBack(TheoryArithPrivate & ta)53 BasicVarModelUpdateCallBack::BasicVarModelUpdateCallBack(TheoryArithPrivate& ta)
54 : d_ta(ta)
55 {}
operator ()(ArithVar x)56 void BasicVarModelUpdateCallBack::operator()(ArithVar x){
57 d_ta.signal(x);
58 }
59
RaiseConflict(TheoryArithPrivate & ta)60 RaiseConflict::RaiseConflict(TheoryArithPrivate& ta)
61 : d_ta(ta)
62 {}
63
raiseConflict(ConstraintCP c) const64 void RaiseConflict::raiseConflict(ConstraintCP c) const{
65 Assert(c->inConflict());
66 d_ta.raiseConflict(c);
67 }
68
FarkasConflictBuilder()69 FarkasConflictBuilder::FarkasConflictBuilder()
70 : d_farkas()
71 , d_constraints()
72 , d_consequent(NullConstraint)
73 , d_consequentSet(false)
74 {
75 reset();
76 }
77
underConstruction() const78 bool FarkasConflictBuilder::underConstruction() const{
79 return d_consequent != NullConstraint;
80 }
81
consequentIsSet() const82 bool FarkasConflictBuilder::consequentIsSet() const{
83 return d_consequentSet;
84 }
85
reset()86 void FarkasConflictBuilder::reset(){
87 d_consequent = NullConstraint;
88 d_constraints.clear();
89 d_consequentSet = false;
90 PROOF(d_farkas.clear());
91 Assert(!underConstruction());
92 }
93
94 /* Adds a constraint to the constraint under construction. */
addConstraint(ConstraintCP c,const Rational & fc)95 void FarkasConflictBuilder::addConstraint(ConstraintCP c, const Rational& fc){
96 Assert(!PROOF_ON() ||
97 (!underConstruction() && d_constraints.empty() && d_farkas.empty()) ||
98 (underConstruction() && d_constraints.size() + 1 == d_farkas.size()));
99 Assert(PROOF_ON() || d_farkas.empty());
100 Assert(c->isTrue());
101
102
103 if(d_consequent == NullConstraint){
104 d_consequent = c;
105 } else {
106 d_constraints.push_back(c);
107 }
108 PROOF(d_farkas.push_back(fc););
109 Assert(!PROOF_ON() || d_constraints.size() + 1 == d_farkas.size());
110 Assert(PROOF_ON() || d_farkas.empty());
111 }
112
addConstraint(ConstraintCP c,const Rational & fc,const Rational & mult)113 void FarkasConflictBuilder::addConstraint(ConstraintCP c, const Rational& fc, const Rational& mult){
114 Assert(!mult.isZero());
115 if(PROOF_ON() && !mult.isOne()){
116 Rational prod = fc * mult;
117 addConstraint(c, prod);
118 }else{
119 addConstraint(c, fc);
120 }
121 }
122
makeLastConsequent()123 void FarkasConflictBuilder::makeLastConsequent(){
124 Assert(!d_consequentSet);
125 Assert(underConstruction());
126
127 if(d_constraints.empty()){
128 // no-op
129 d_consequentSet = true;
130 } else {
131 Assert(d_consequent != NullConstraint);
132 ConstraintCP last = d_constraints.back();
133 d_constraints.back() = d_consequent;
134 d_consequent = last;
135 PROOF( std::swap( d_farkas.front(), d_farkas.back() ) );
136 d_consequentSet = true;
137 }
138
139 Assert(! d_consequent->negationHasProof() );
140 Assert(d_consequentSet);
141 }
142
143 /* Turns the vector under construction into a conflict */
commitConflict()144 ConstraintCP FarkasConflictBuilder::commitConflict(){
145 Assert(underConstruction());
146 Assert(!d_constraints.empty());
147 Assert(!PROOF_ON() ||
148 (!underConstruction() && d_constraints.empty() && d_farkas.empty()) ||
149 (underConstruction() && d_constraints.size() + 1 == d_farkas.size()));
150 Assert(PROOF_ON() || d_farkas.empty());
151 Assert(d_consequentSet);
152
153 ConstraintP not_c = d_consequent->getNegation();
154 RationalVectorCP coeffs = NULLPROOF(&d_farkas);
155 not_c->impliedByFarkas(d_constraints, coeffs, true );
156
157 reset();
158 Assert(!underConstruction());
159 Assert( not_c->inConflict() );
160 Assert(!d_consequentSet);
161 return not_c;
162 }
163
RaiseEqualityEngineConflict(TheoryArithPrivate & ta)164 RaiseEqualityEngineConflict::RaiseEqualityEngineConflict(TheoryArithPrivate& ta)
165 : d_ta(ta)
166 {}
167
168 /* If you are not an equality engine, don't use this! */
raiseEEConflict(Node n) const169 void RaiseEqualityEngineConflict::raiseEEConflict(Node n) const{
170 d_ta.raiseBlackBoxConflict(n);
171 }
172
173
BoundCountingLookup(TheoryArithPrivate & ta)174 BoundCountingLookup::BoundCountingLookup(TheoryArithPrivate& ta)
175 : d_ta(ta)
176 {}
177
boundsInfo(ArithVar basic) const178 const BoundsInfo& BoundCountingLookup::boundsInfo(ArithVar basic) const{
179 return d_ta.boundsInfo(basic);
180 }
181
atBounds(ArithVar basic) const182 BoundCounts BoundCountingLookup::atBounds(ArithVar basic) const{
183 return boundsInfo(basic).atBounds();
184 }
hasBounds(ArithVar basic) const185 BoundCounts BoundCountingLookup::hasBounds(ArithVar basic) const {
186 return boundsInfo(basic).hasBounds();
187 }
188
189 }/* CVC4::theory::arith namespace */
190 }/* CVC4::theory namespace */
191 }/* CVC4 namespace */
192