GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/theory_arith_private.h Lines: 27 32 84.4 %
Date: 2021-09-29 Branches: 15 42 35.7 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Tim King, Andrew Reynolds, Alex Ozdemir
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 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.
11
 * ****************************************************************************
12
 *
13
 * [[ Add one-line brief description here ]]
14
 *
15
 * [[ Add lengthier description here ]]
16
 * \todo document this file
17
 */
18
19
#pragma once
20
21
#include <map>
22
#include <vector>
23
24
#include "context/cdhashset.h"
25
#include "context/cdinsert_hashmap.h"
26
#include "context/cdlist.h"
27
#include "context/cdqueue.h"
28
#include "expr/kind.h"
29
#include "expr/node.h"
30
#include "expr/node_builder.h"
31
#include "proof/trust_node.h"
32
#include "theory/arith/arith_static_learner.h"
33
#include "theory/arith/arith_utilities.h"
34
#include "theory/arith/arithvar.h"
35
#include "theory/arith/attempt_solution_simplex.h"
36
#include "theory/arith/branch_and_bound.h"
37
#include "theory/arith/congruence_manager.h"
38
#include "theory/arith/constraint.h"
39
#include "theory/arith/delta_rational.h"
40
#include "theory/arith/dio_solver.h"
41
#include "theory/arith/dual_simplex.h"
42
#include "theory/arith/error_set.h"
43
#include "theory/arith/fc_simplex.h"
44
#include "theory/arith/infer_bounds.h"
45
#include "theory/arith/linear_equality.h"
46
#include "theory/arith/matrix.h"
47
#include "theory/arith/normal_form.h"
48
#include "theory/arith/partial_model.h"
49
#include "theory/arith/proof_checker.h"
50
#include "theory/arith/soi_simplex.h"
51
#include "theory/arith/theory_arith.h"
52
#include "theory/valuation.h"
53
#include "util/dense_map.h"
54
#include "util/integer.h"
55
#include "util/rational.h"
56
#include "util/result.h"
57
#include "util/statistics_stats.h"
58
59
namespace cvc5 {
60
61
class EagerProofGenerator;
62
63
namespace theory {
64
65
class TheoryModel;
66
67
namespace arith {
68
69
class BranchCutInfo;
70
class TreeLog;
71
class ApproximateStatistics;
72
73
class ArithEntailmentCheckParameters;
74
class ArithEntailmentCheckSideEffects;
75
namespace inferbounds {
76
  class InferBoundAlgorithm;
77
}
78
class InferBoundsResult;
79
80
/**
81
 * Implementation of QF_LRA.
82
 * Based upon:
83
 * http://research.microsoft.com/en-us/um/people/leonardo/cav06.pdf
84
 */
85
class TheoryArithPrivate : protected EnvObj
86
{
87
 private:
88
  static const uint32_t RESET_START = 2;
89
90
  TheoryArith& d_containing;
91
92
  /**
93
   * Whether we encountered non-linear arithmetic at any time during solving.
94
   */
95
  bool d_foundNl;
96
97
  BoundInfoMap d_rowTracking;
98
  /** Branch and bound utility */
99
  BranchAndBound& d_bab;
100
  // For proofs
101
  /** Manages the proof nodes of this theory. */
102
  ProofNodeManager* d_pnm;
103
  /** Checks the proof rules of this theory. */
104
  ArithProofRuleChecker d_checker;
105
  /** Stores proposition(node)/proof pairs. */
106
  std::unique_ptr<EagerProofGenerator> d_pfGen;
107
108
  /**
109
   * The constraint database associated with the theory.
110
   * This must be declared before ArithPartialModel.
111
   */
112
  ConstraintDatabase d_constraintDatabase;
113
114
  enum Result::Sat d_qflraStatus;
115
  // check()
116
  //   !done() -> d_qflraStatus = Unknown
117
  //   fullEffort(e) -> simplex returns either sat or unsat
118
  //   !fullEffort(e) -> simplex returns either sat, unsat or unknown
119
  //                     if unknown, save the assignment
120
  //                     if unknown, the simplex priority queue cannot be emptied
121
  int d_unknownsInARow;
122
123
  bool d_replayedLemmas;
124
125
  /**
126
   * This counter is false if nothing has been done since the last cut.
127
   * This is used to break an infinite loop.
128
   */
129
  bool d_hasDoneWorkSinceCut;
130
131
  /** Static learner. */
132
  ArithStaticLearner d_learner;
133
134
  //std::vector<ArithVar> d_pool;
135
public:
136
  void releaseArithVar(ArithVar v);
137
3405583
  void signal(ArithVar v){ d_errorSet.signalVariable(v); }
138
139
140
private:
141
  // t does not contain constants
142
  void entailmentCheckBoundLookup(std::pair<Node, DeltaRational>& tmp, int sgn, TNode tp) const;
143
  void entailmentCheckRowSum(std::pair<Node, DeltaRational>& tmp, int sgn, TNode tp) const;
144
145
  /**
146
   * Infers either a new upper/lower bound on term in the real relaxation.
147
   * Either:
148
   * - term is malformed (see below)
149
   * - a maximum/minimum is found with the result being a pair
150
   * -- <dr, exp> where
151
   * -- term <?> dr is implies by exp
152
   * -- <?> is <= if inferring an upper bound, >= otherwise
153
   * -- exp is in terms of the assertions to the theory.
154
   * - No upper or lower bound is inferrable in the real relaxation.
155
   * -- Returns <0, Null()>
156
   * - the maximum number of rounds was exhausted:
157
   * -- Returns <v, term> where v is the current feasible value of term
158
   * - Threshold reached:
159
   * -- If theshold != NULL, and a feasible value is found to exceed threshold
160
   * -- Simplex stops and returns <threshold, term>
161
   */
162
  //std::pair<DeltaRational, Node> inferBound(TNode term, bool lb, int maxRounds = -1, const DeltaRational* threshold = NULL);
163
164
private:
165
  static bool decomposeTerm(Node term, Rational& m, Node& p, Rational& c);
166
  static bool decomposeLiteral(Node lit, Kind& k, int& dir, Rational& lm,  Node& lp, Rational& rm, Node& rp, Rational& dm, Node& dp, DeltaRational& sep);
167
  static void setToMin(int sgn, std::pair<Node, DeltaRational>& min, const std::pair<Node, DeltaRational>& e);
168
169
  /**
170
   * The map between arith variables to nodes.
171
   */
172
  //ArithVarNodeMap d_arithvarNodeMap;
173
174
  typedef ArithVariables::var_iterator var_iterator;
175
1180761
  var_iterator var_begin() const { return d_partialModel.var_begin(); }
176
1180761
  var_iterator var_end() const { return d_partialModel.var_end(); }
177
178
  NodeSet d_setupNodes;
179
public:
180
2932867
  bool isSetup(Node n) const {
181
2932867
    return d_setupNodes.find(n) != d_setupNodes.end();
182
  }
183
245931
  void markSetup(Node n){
184
245931
    Assert(!isSetup(n));
185
245931
    d_setupNodes.insert(n);
186
245931
  }
187
private:
188
  void setupVariable(const Variable& x);
189
  void setupVariableList(const VarList& vl);
190
  void setupPolynomial(const Polynomial& poly);
191
public:
192
  void setupAtom(TNode atom);
193
private:
194
  void cautiousSetupPolynomial(const Polynomial& p);
195
196
  /**
197
   * A superset of all of the assertions that currently are not the literal for
198
   * their constraint do not match constraint literals. Not just the witnesses.
199
   */
200
  context::CDInsertHashMap<Node, ConstraintP>
201
      d_assertionsThatDoNotMatchTheirLiterals;
202
203
  /** Returns true if x is of type Integer. */
204
11597510
  inline bool isInteger(ArithVar x) const {
205
11597510
    return d_partialModel.isInteger(x);
206
  }
207
208
209
  /** Returns true if the variable was initially introduced as an auxiliary variable. */
210
1671007
  inline bool isAuxiliaryVariable(ArithVar x) const{
211
1671007
    return d_partialModel.isAuxiliary(x);
212
  }
213
214
518581799
  inline bool isIntegerInput(ArithVar x) const
215
  {
216
518581799
    return d_partialModel.isIntegerInput(x)
217
1037163598
           && d_preregisteredNodes.contains(d_partialModel.asNode(x));
218
  }
219
220
  /**
221
   * On full effort checks (after determining LA(Q) satisfiability), we
222
   * consider integer vars, but we make sure to do so fairly to avoid
223
   * nontermination (although this isn't a guarantee).  To do it fairly,
224
   * we consider variables in round-robin fashion.  This is the
225
   * round-robin index.
226
   */
227
  ArithVar d_nextIntegerCheckVar;
228
229
  /**
230
   * Queue of Integer variables that are known to be equal to a constant.
231
   */
232
  context::CDQueue<ArithVar> d_constantIntegerVariables;
233
234
  Node callDioSolver();
235
  /**
236
   * Produces lemmas of the form (or (>= f 0) (<= f 0)),
237
   * where f is a plane that the diophantine solver is interested in.
238
   *
239
   * More precisely, produces lemmas of the form (or (>= lc -c) (<= lc -c))
240
   * where lc is a linear combination of variables, c is a constant, and lc + c
241
   * is the plane.
242
   */
243
  TrustNode dioCutting();
244
245
  Comparison mkIntegerEqualityFromAssignment(ArithVar v);
246
247
  /**
248
   * List of all of the disequalities asserted in the current context that are not known
249
   * to be satisfied.
250
   */
251
  context::CDQueue<ConstraintP> d_diseqQueue;
252
253
  /**
254
   * Constraints that have yet to be processed by proagation work list.
255
   * All of the elements have type of LowerBound, UpperBound, or
256
   * Equality.
257
   *
258
   * This is empty at the beginning of every check call.
259
   *
260
   * If head()->getType() == LowerBound or UpperBound,
261
   * then d_cPL[1] is the previous constraint in d_partialModel for the
262
   * corresponding bound.
263
   * If head()->getType() == Equality,
264
   * then d_cPL[1] is the previous lowerBound in d_partialModel,
265
   * and d_cPL[2] is the previous upperBound in d_partialModel.
266
   */
267
  std::deque<ConstraintP> d_currentPropagationList;
268
269
  context::CDQueue<ConstraintP> d_learnedBounds;
270
271
  /**
272
   * Contains all nodes that have been preregistered
273
   */
274
  context::CDHashSet<Node> d_preregisteredNodes;
275
276
  /**
277
   * Manages information about the assignment and upper and lower bounds on
278
   * variables.
279
   */
280
  ArithVariables d_partialModel;
281
282
  /** The set of variables in error in the partial model. */
283
  ErrorSet d_errorSet;
284
285
  /**
286
   * The tableau for all of the constraints seen thus far in the system.
287
   */
288
  Tableau d_tableau;
289
290
  /**
291
   * Maintains the relationship between the PartialModel and the Tableau.
292
   */
293
  LinearEqualityModule d_linEq;
294
295
  /**
296
   * A Diophantine equation solver.  Accesses the tableau and partial
297
   * model (each in a read-only fashion).
298
   */
299
  DioSolver d_diosolver;
300
301
  /** Counts the number of notifyRestart() calls to the theory. */
302
  uint32_t d_restartsCounter;
303
304
  /**
305
   * Every number of restarts equal to s_TABLEAU_RESET_PERIOD,
306
   * the density of the tableau, d, is computed.
307
   * If d >= s_TABLEAU_RESET_DENSITY * d_initialDensity, the tableau
308
   * is set to d_initialTableau.
309
   */
310
  bool d_tableauSizeHasBeenModified;
311
  double d_tableauResetDensity;
312
  uint32_t d_tableauResetPeriod;
313
  static const uint32_t s_TABLEAU_RESET_INCREMENT = 5;
314
315
316
  /** This is only used by simplex at the moment. */
317
  context::CDList<std::pair<ConstraintCP, InferenceId>> d_conflicts;
318
319
  /** This is only used by simplex at the moment. */
320
  context::CDO<Node> d_blackBoxConflict;
321
  /** For holding the proof of the above conflict node. */
322
  context::CDO<std::shared_ptr<ProofNode>> d_blackBoxConflictPf;
323
324
  bool isProofEnabled() const;
325
326
 public:
327
  /**
328
   * This adds the constraint a to the queue of conflicts in d_conflicts.
329
   * Both a and ~a must have a proof.
330
   */
331
  void raiseConflict(ConstraintCP a, InferenceId id);
332
333
  // inline void raiseConflict(const ConstraintCPVec& cv){
334
  //   d_conflicts.push_back(cv);
335
  // }
336
337
  // void raiseConflict(ConstraintCP a, ConstraintCP b);
338
  // void raiseConflict(ConstraintCP a, ConstraintCP b, ConstraintCP c);
339
340
  /** This is a conflict that is magically known to hold. */
341
  void raiseBlackBoxConflict(Node bb, std::shared_ptr<ProofNode> pf = nullptr);
342
  /**
343
   * Returns true iff a conflict has been raised. This method is public since
344
   * it is needed by the ArithState class to know whether we are in conflict.
345
   */
346
  bool anyConflict() const;
347
348
 private:
349
10958180
  inline bool conflictQueueEmpty() const {
350
10958180
    return d_conflicts.empty();
351
  }
352
353
  /**
354
   * Outputs the contents of d_conflicts onto d_out.
355
   * The conditions of anyConflict() must hold.
356
   */
357
  void outputConflicts();
358
359
  /**
360
   * A copy of the tableau.
361
   * This is equivalent  to the original tableau if d_tableauSizeHasBeenModified
362
   * is false.
363
   * The set of basic and non-basic variables may differ from d_tableau.
364
   */
365
  Tableau d_smallTableauCopy;
366
367
  /**
368
   * Returns true if all of the basic variables in the simplex queue of
369
   * basic variables that violate their bounds in the current tableau
370
   * are basic in d_smallTableauCopy.
371
   *
372
   * d_tableauSizeHasBeenModified must be false when calling this.
373
   * Simplex's priority queue must be in collection mode.
374
   */
375
  bool safeToReset() const;
376
377
  /** This keeps track of difference equalities. Mostly for sharing. */
378
  ArithCongruenceManager d_congruenceManager;
379
  context::CDO<bool> d_cmEnabled;
380
381
  /** This implements the Simplex decision procedure. */
382
  DualSimplexDecisionProcedure d_dualSimplex;
383
  FCSimplexDecisionProcedure d_fcSimplex;
384
  SumOfInfeasibilitiesSPD d_soiSimplex;
385
  AttemptSolutionSDP d_attemptSolSimplex;
386
387
  bool solveRealRelaxation(Theory::Effort effortLevel);
388
389
  /* Returns true if this is heuristically a good time to try
390
   * to solve the integers.
391
   */
392
  bool attemptSolveInteger(Theory::Effort effortLevel, bool emmmittedLemmaOrSplit);
393
  bool replayLemmas(ApproximateSimplex* approx);
394
  void solveInteger(Theory::Effort effortLevel);
395
  bool safeToCallApprox() const;
396
  SimplexDecisionProcedure& selectSimplex(bool pass1);
397
  SimplexDecisionProcedure* d_pass1SDP;
398
  SimplexDecisionProcedure* d_otherSDP;
399
  /* Sets d_qflraStatus */
400
  void importSolution(const ApproximateSimplex::Solution& solution);
401
  bool solveRelaxationOrPanic(Theory::Effort effortLevel);
402
  context::CDO<int> d_lastContextIntegerAttempted;
403
  bool replayLog(ApproximateSimplex* approx);
404
405
  class ModelException : public Exception {
406
   public:
407
    ModelException(TNode n, const char* msg);
408
    ~ModelException() override;
409
  };
410
411
  /**
412
   * Computes the delta rational value of a term from the current partial
413
   * model. This returns the delta value assignment to the term if it is in the
414
   * partial model. Otherwise, this is computed recursively for arithmetic terms
415
   * from each subterm.
416
   *
417
   * This throws a DeltaRationalException if the value cannot be represented as
418
   * a DeltaRational. This throws a ModelException if there is a term is not in
419
   * the partial model and is not a theory of arithmetic term.
420
   *
421
   * precondition: The linear abstraction of the nodes must be satisfiable.
422
   */
423
  DeltaRational getDeltaValue(TNode term) const
424
      /* throw(DeltaRationalException, ModelException) */;
425
 public:
426
  TheoryArithPrivate(TheoryArith& containing, Env& env, BranchAndBound& bab);
427
  ~TheoryArithPrivate();
428
429
  //--------------------------------- initialization
430
  /**
431
   * Returns true if we need an equality engine, see
432
   * Theory::needsEqualityEngine.
433
   */
434
  bool needsEqualityEngine(EeSetupInfo& esi);
435
  /** finish initialize */
436
  void finishInit();
437
  //--------------------------------- end initialization
438
439
  /**
440
   * Does non-context dependent setup for a node connected to a theory.
441
   */
442
  void preRegisterTerm(TNode n);
443
444
  void propagate(Theory::Effort e);
445
  TrustNode explain(TNode n);
446
447
  Rational deltaValueForTotalOrder() const;
448
449
  bool collectModelInfo(TheoryModel* m);
450
  /**
451
   * Collect model values. This is the main method for extracting information
452
   * about how to construct the model. This method relies on the caller for
453
   * processing the map, which is done so that other modules (e.g. the
454
   * non-linear extension) can modify arithModel before it is sent to the model.
455
   *
456
   * @param termSet The set of relevant terms
457
   * @param arithModel Mapping from terms (of real type) to their values. The
458
   * caller should assert equalities to the model for each entry in this map.
459
   */
460
  void collectModelValues(const std::set<Node>& termSet,
461
                          std::map<Node, Node>& arithModel);
462
463
  void shutdown(){ }
464
465
  void presolve();
466
  void notifyRestart();
467
  Theory::PPAssertStatus ppAssert(TrustNode tin,
468
                                  TrustSubstitutionMap& outSubstitutions);
469
  void ppStaticLearn(TNode in, NodeBuilder& learned);
470
471
  std::string identify() const { return std::string("TheoryArith"); }
472
473
  EqualityStatus getEqualityStatus(TNode a, TNode b);
474
475
  /** Called when n is notified as being a shared term with TheoryArith. */
476
  void notifySharedTerm(TNode n);
477
478
  Node getModelValue(TNode var);
479
480
481
  std::pair<bool, Node> entailmentCheck(TNode lit, const ArithEntailmentCheckParameters& params, ArithEntailmentCheckSideEffects& out);
482
483
  //--------------------------------- standard check
484
  /** Pre-check, called before the fact queue of the theory is processed. */
485
  bool preCheck(Theory::Effort level);
486
  /** Pre-notify fact. */
487
  void preNotifyFact(TNode atom, bool pol, TNode fact);
488
  /**
489
   * Post-check, called after the fact queue of the theory is processed. Returns
490
   * true if a conflict or lemma was emitted.
491
   */
492
  bool postCheck(Theory::Effort level);
493
  //--------------------------------- end standard check
494
  /**
495
   * Found non-linear? This returns true if this solver ever encountered
496
   * any non-linear terms that were unhandled. Note that this class is not
497
   * responsible for handling non-linear arithmetic. If the owner of this
498
   * class does not handle non-linear arithmetic in another way, then
499
   * setIncomplete should be called on the output channel of TheoryArith.
500
   */
501
  bool foundNonlinear() const;
502
503
  /** get the proof checker of this theory */
504
  ArithProofRuleChecker* getProofChecker();
505
506
 private:
507
  /** The constant zero. */
508
  DeltaRational d_DELTA_ZERO;
509
510
  /** propagates an arithvar */
511
  void propagateArithVar(bool upperbound, ArithVar var );
512
513
  /**
514
   * Using the simpleKind return the ArithVar associated with the assertion.
515
   */
516
  ArithVar determineArithVar(const Polynomial& p) const;
517
  ArithVar determineArithVar(TNode assertion) const;
518
519
  /**
520
   * Splits the disequalities in d_diseq that are violated using lemmas on demand.
521
   * returns true if any lemmas were issued.
522
   * returns false if all disequalities are satisfied in the current model.
523
   */
524
  bool splitDisequalities();
525
526
  /** A Difference variable is known to be 0.*/
527
  void zeroDifferenceDetected(ArithVar x);
528
529
530
  /**
531
   * Looks for the next integer variable without an integer assignment in a
532
   * round-robin fashion. Changes the value of d_nextIntegerCheckVar.
533
   *
534
   * This returns true if all integer variables have integer assignments.
535
   * If this returns false, d_nextIntegerCheckVar does not have an integer
536
   * assignment.
537
   */
538
  bool hasIntegerModel();
539
540
  /**
541
   * Looks for through the variables starting at d_nextIntegerCheckVar
542
   * for the first integer variable that is between its upper and lower bounds
543
   * that has a non-integer assignment.
544
   *
545
   * If assumeBounds is true, skip the check that the variable is in bounds.
546
   *
547
   * If there is no such variable, returns ARITHVAR_SENTINEL;
548
   */
549
  ArithVar nextIntegerViolation(bool assumeBounds) const;
550
551
  /**
552
   * Issues branches for non-auxiliary integer variables with non-integer assignments.
553
   * Returns a cut for a lemma.
554
   * If there is an integer model, this returns Node::null().
555
   */
556
  TrustNode roundRobinBranch();
557
558
877
  bool proofsEnabled() const { return d_pnm; }
559
560
 public:
561
  /**
562
   * This requests a new unique ArithVar value for x.
563
   * This also does initial (not context dependent) set up for a variable,
564
   * except for setting up the initial.
565
   *
566
   * If aux is true, this is an auxiliary variable.
567
   * If internal is true, x might not be unique up to a constant multiple.
568
   */
569
  ArithVar requestArithVar(TNode x, bool aux, bool internal);
570
571
public:
572
  const BoundsInfo& boundsInfo(ArithVar basic) const;
573
574
575
private:
576
  /** Initial (not context dependent) sets up for a variable.*/
577
  void setupBasicValue(ArithVar x);
578
579
  /** Initial (not context dependent) sets up for a new auxiliary variable.*/
580
  void setupAuxiliary(TNode left);
581
582
583
  /**
584
   * Assert*(n, orig) takes an bound n that is implied by orig.
585
   * and asserts that as a new bound if it is tighter than the current bound
586
   * and updates the value of a basic variable if needed.
587
   *
588
   * orig must be a literal in the SAT solver so that it can be used for
589
   * conflict analysis.
590
   *
591
   * x is the variable getting the new bound,
592
   * c is the value of the new bound.
593
   *
594
   * If this new bound is in conflict with the other bound,
595
   * a node describing this conflict is returned.
596
   * If this new bound is not in conflict, Node::null() is returned.
597
   */
598
  bool AssertLower(ConstraintP constraint);
599
  bool AssertUpper(ConstraintP constraint);
600
  bool AssertEquality(ConstraintP constraint);
601
  bool AssertDisequality(ConstraintP constraint);
602
603
  /** Tracks the bounds that were updated in the current round. */
604
  DenseSet d_updatedBounds;
605
606
  /** Tracks the basic variables where propagation might be possible. */
607
  DenseSet d_candidateBasics;
608
  DenseSet d_candidateRows;
609
610
1853948
  bool hasAnyUpdates() { return !d_updatedBounds.empty(); }
611
  void clearUpdates();
612
613
  void revertOutOfConflict();
614
615
  void propagateCandidatesNew();
616
  void dumpUpdatedBoundsToRows();
617
  bool propagateCandidateRow(RowIndex rid);
618
  bool propagateMightSucceed(ArithVar v, bool ub) const;
619
  /** Attempt to perform a row propagation where there is at most 1 possible variable.*/
620
  bool attemptSingleton(RowIndex ridx, bool rowUp);
621
  /** Attempt to perform a row propagation where every variable is a potential candidate.*/
622
  bool attemptFull(RowIndex ridx, bool rowUp);
623
  bool tryToPropagate(RowIndex ridx, bool rowUp, ArithVar v, bool vUp, const DeltaRational& bound);
624
  bool rowImplicationCanBeApplied(RowIndex ridx, bool rowUp, ConstraintP bestImplied);
625
  //void enqueueConstraints(std::vector<ConstraintCP>& out, Node n) const;
626
  //ConstraintCPVec resolveOutPropagated(const ConstraintCPVec& v, const std::set<ConstraintCP>& propagated) const;
627
  void resolveOutPropagated(std::vector<ConstraintCPVec>& confs, const std::set<ConstraintCP>& propagated) const;
628
  void subsumption(std::vector<ConstraintCPVec>& confs) const;
629
630
  Node cutToLiteral(ApproximateSimplex*  approx, const CutInfo& cut) const;
631
  Node branchToNode(ApproximateSimplex* approx, const NodeLog& cut) const;
632
633
  void propagateCandidates();
634
  void propagateCandidate(ArithVar basic);
635
  bool propagateCandidateBound(ArithVar basic, bool upperBound);
636
637
1020
  inline bool propagateCandidateLowerBound(ArithVar basic){
638
1020
    return propagateCandidateBound(basic, false);
639
  }
640
726
  inline bool propagateCandidateUpperBound(ArithVar basic){
641
726
    return propagateCandidateBound(basic, true);
642
  }
643
644
  /**
645
   * Performs a check to see if it is definitely true that setup can be avoided.
646
   */
647
  bool canSafelyAvoidEqualitySetup(TNode equality);
648
649
  /**
650
   * Handles the case splitting for check() for a new assertion.
651
   * Returns a conflict if one was found.
652
   * Returns Node::null if no conflict was found.
653
   *
654
   * @param assertion The assertion that was just popped from the fact queue
655
   * of TheoryArith and given to this class via preNotifyFact.
656
   */
657
  ConstraintP constraintFromFactQueue(TNode assertion);
658
  bool assertionCases(ConstraintP c);
659
660
  /**
661
   * Returns the basic variable with the shorted row containing a non-basic variable.
662
   * If no such row exists, return ARITHVAR_SENTINEL.
663
   */
664
  ArithVar findShortestBasicRow(ArithVar variable);
665
666
  /**
667
   * Debugging only routine!
668
   * Returns true iff every variable is consistent in the partial model.
669
   */
670
  bool entireStateIsConsistent(const std::string& locationHint);
671
  bool unenqueuedVariablesAreConsistent();
672
673
  bool isImpliedUpperBound(ArithVar var, Node exp);
674
  bool isImpliedLowerBound(ArithVar var, Node exp);
675
676
  void internalExplain(TNode n, NodeBuilder& explainBuilder);
677
678
  void asVectors(const Polynomial& p,
679
                 std::vector<Rational>& coeffs,
680
                 std::vector<ArithVar>& variables);
681
682
  /** Routine for debugging. Print the assertions the theory is aware of. */
683
  void debugPrintAssertions(std::ostream& out) const;
684
  /** Debugging only routine. Prints the model. */
685
  void debugPrintModel(std::ostream& out) const;
686
687
1175392
  inline bool done() const { return d_containing.done(); }
688
  inline TNode get() { return d_containing.get(); }
689
211255
  inline bool isLeaf(TNode x) const { return d_containing.isLeaf(x); }
690
846651
  inline TheoryId theoryOf(TNode x) const { return d_containing.theoryOf(x); }
691
  inline void debugPrintFacts() const { d_containing.debugPrintFacts(); }
692
  bool outputTrustedLemma(TrustNode lem, InferenceId id);
693
  bool outputLemma(TNode lem, InferenceId id);
694
  void outputTrustedConflict(TrustNode conf, InferenceId id);
695
  void outputConflict(TNode lit, InferenceId id);
696
  void outputPropagate(TNode lit);
697
  void outputRestart();
698
699
  inline bool isSatLiteral(TNode l) const {
700
    return (d_containing.d_valuation).isSatLiteral(l);
701
  }
702
  inline Node getSatValue(TNode n) const {
703
    return (d_containing.d_valuation).getSatValue(n);
704
  }
705
706
  /** Used for replaying approximate simplex */
707
  context::CDQueue<TrustNode> d_approxCuts;
708
  /** Also used for replaying approximate simplex. "approximate cuts temporary storage" */
709
  std::vector<TrustNode> d_acTmp;
710
711
  /** Counts the number of fullCheck calls to arithmetic. */
712
  uint32_t d_fullCheckCounter;
713
  std::vector<ArithVar> cutAllBounded() const;
714
  TrustNode branchIntegerVariable(ArithVar x) const;
715
  void branchVector(const std::vector<ArithVar>& lemmas);
716
717
  context::CDO<unsigned> d_cutCount;
718
  context::CDHashSet<ArithVar, std::hash<ArithVar> > d_cutInContext;
719
720
  context::CDO<bool> d_likelyIntegerInfeasible;
721
722
723
  context::CDO<bool> d_guessedCoeffSet;
724
  ArithRatPairVec d_guessedCoeffs;
725
726
727
  TreeLog* d_treeLog;
728
  TreeLog& getTreeLog();
729
730
731
  ArithVarVec d_replayVariables;
732
  std::vector<ConstraintP> d_replayConstraints;
733
  DenseMap<Rational> d_lhsTmp;
734
735
  /* Approximate simpplex solvers are given a copy of their stats */
736
  ApproximateStatistics* d_approxStats;
737
  ApproximateStatistics& getApproxStats();
738
  context::CDO<int32_t> d_attemptSolveIntTurnedOff;
739
  void turnOffApproxFor(int32_t rounds);
740
  bool getSolveIntegerResource();
741
742
  void tryBranchCut(ApproximateSimplex* approx, int nid, BranchCutInfo& bl);
743
  std::vector<ConstraintCPVec> replayLogRec(ApproximateSimplex* approx, int nid, ConstraintP bc, int depth);
744
745
  std::pair<ConstraintP, ArithVar> replayGetConstraint(const CutInfo& info);
746
  std::pair<ConstraintP, ArithVar> replayGetConstraint(
747
      ApproximateSimplex* approx, const NodeLog& nl);
748
  std::pair<ConstraintP, ArithVar> replayGetConstraint(const DenseMap<Rational>& lhs, Kind k, const Rational& rhs, bool branch);
749
750
  void replayAssert(ConstraintP c);
751
752
  static ConstraintCP vectorToIntHoleConflict(const ConstraintCPVec& conflict);
753
  static void intHoleConflictToVector(ConstraintCP conflicting, ConstraintCPVec& conflict);
754
755
  // Returns true if the node contains a literal
756
  // that is an arithmetic literal and is not a sat literal
757
  // No caching is done so this should likely only
758
  // be called carefully!
759
  bool hasFreshArithLiteral(Node n) const;
760
761
  int32_t d_dioSolveResources;
762
  bool getDioCuttingResource();
763
764
  uint32_t d_solveIntMaybeHelp, d_solveIntAttempts;
765
766
  RationalVector d_farkasBuffer;
767
768
  //---------------- during check
769
  /** Whether there were new facts during preCheck */
770
  bool d_newFacts;
771
  /** The previous status, computed during preCheck */
772
  Result::Sat d_previousStatus;
773
  //---------------- end during check
774
775
  /** These fields are designed to be accessible to TheoryArith methods. */
776
  class Statistics {
777
  public:
778
    IntStat d_statAssertUpperConflicts, d_statAssertLowerConflicts;
779
780
    IntStat d_statUserVariables, d_statAuxiliaryVariables;
781
    IntStat d_statDisequalitySplits;
782
    IntStat d_statDisequalityConflicts;
783
    TimerStat d_simplifyTimer;
784
    TimerStat d_staticLearningTimer;
785
786
    TimerStat d_presolveTime;
787
788
    TimerStat d_newPropTime;
789
790
    IntStat d_externalBranchAndBounds;
791
792
    IntStat d_initialTableauSize;
793
    IntStat d_currSetToSmaller;
794
    IntStat d_smallerSetToCurr;
795
    TimerStat d_restartTimer;
796
797
    TimerStat d_boundComputationTime;
798
    IntStat d_boundComputations, d_boundPropagations;
799
800
    IntStat d_unknownChecks;
801
    IntStat d_maxUnknownsInARow;
802
    AverageStat d_avgUnknownsInARow;
803
804
    IntStat d_revertsOnConflicts;
805
    IntStat d_commitsOnConflicts;
806
    IntStat d_nontrivialSatChecks;
807
808
    IntStat d_replayLogRecCount,
809
      d_replayLogRecConflictEscalation,
810
      d_replayLogRecEarlyExit,
811
      d_replayBranchCloseFailures,
812
      d_replayLeafCloseFailures,
813
      d_replayBranchSkips,
814
      d_mirCutsAttempted,
815
      d_gmiCutsAttempted,
816
      d_branchCutsAttempted,
817
      d_cutsReconstructed,
818
      d_cutsReconstructionFailed,
819
      d_cutsProven,
820
      d_cutsProofFailed,
821
      d_mipReplayLemmaCalls,
822
      d_mipExternalCuts,
823
      d_mipExternalBranch;
824
825
    IntStat d_inSolveInteger,
826
      d_branchesExhausted,
827
      d_execExhausted,
828
      d_pivotsExhausted,
829
      d_panicBranches,
830
      d_relaxCalls,
831
      d_relaxLinFeas,
832
      d_relaxLinFeasFailures,
833
      d_relaxLinInfeas,
834
      d_relaxLinInfeasFailures,
835
      d_relaxLinExhausted,
836
      d_relaxOthers;
837
838
    IntStat d_applyRowsDeleted;
839
    TimerStat d_replaySimplexTimer;
840
841
    TimerStat d_replayLogTimer,
842
      d_solveIntTimer,
843
      d_solveRealRelaxTimer;
844
845
    IntStat d_solveIntCalls,
846
      d_solveStandardEffort;
847
848
    IntStat d_approxDisabled;
849
    IntStat d_replayAttemptFailed;
850
851
    IntStat d_cutsRejectedDuringReplay;
852
    IntStat d_cutsRejectedDuringLemmas;
853
854
    HistogramStat<uint32_t> d_satPivots;
855
    HistogramStat<uint32_t> d_unsatPivots;
856
    HistogramStat<uint32_t> d_unknownPivots;
857
858
    IntStat d_solveIntModelsAttempts;
859
    IntStat d_solveIntModelsSuccessful;
860
    TimerStat d_mipTimer;
861
    TimerStat d_lpTimer;
862
863
    IntStat d_mipProofsAttempted;
864
    IntStat d_mipProofsSuccessful;
865
866
    IntStat d_numBranchesFailed;
867
868
    Statistics(StatisticsRegistry& reg, const std::string& name);
869
  };
870
871
872
  Statistics d_statistics;
873
}; /* class TheoryArithPrivate */
874
875
}  // namespace arith
876
}  // namespace theory
877
}  // namespace cvc5