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