GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/fc_simplex.h Lines: 1 38 2.6 %
Date: 2021-03-22 Branches: 0 26 0.0 %

Line Exec Source
1
/*********************                                                        */
2
/*! \file fc_simplex.h
3
 ** \verbatim
4
 ** Top contributors (to current version):
5
 **   Tim King, Morgan Deters, Mathias Preiner
6
 ** This file is part of the CVC4 project.
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.\endverbatim
11
 **
12
 ** \brief This is an implementation of the Simplex Module for the Simplex for
13
 ** DPLL(T)decision procedure.
14
 **
15
 ** This implements the Simplex module for the Simpelx for DPLL(T) decision
16
 ** procedure.
17
 ** See the Simplex for DPLL(T) technical report for more background.(citation?)
18
 ** This shares with the theory a Tableau, and a PartialModel that:
19
 **  - satisfies the equalities in the Tableau, and
20
 **  - the assignment for the non-basic variables satisfies their bounds.
21
 ** This is required to either produce a conflict or satisifying PartialModel.
22
 ** Further, we require being told when a basic variable updates its value.
23
 **
24
 ** During the Simplex search we maintain a queue of variables.
25
 ** The queue is required to contain all of the basic variables that voilate
26
 ** their bounds.
27
 ** As elimination from the queue is more efficient to be done lazily,
28
 ** we do not maintain that the queue of variables needs to be only basic
29
 ** variables or only variables that satisfy their bounds.
30
 **
31
 ** The simplex procedure roughly follows Alberto's thesis. (citation?)
32
 ** There is one round of selecting using a heuristic pivoting rule.
33
 ** (See PreferenceFunction Documentation for the available options.)
34
 ** The non-basic variable is the one that appears in the fewest pivots.
35
 ** (Bruno says that Leonardo invented this first.)
36
 ** After this, Bland's pivot rule is invoked.
37
 **
38
 ** During this proccess, we periodically inspect the queue of variables to
39
 ** 1) remove now extraneous extries,
40
 ** 2) detect conflicts that are "waiting" on the queue but may not be detected
41
 **    by the current queue heuristics, and
42
 ** 3) detect multiple conflicts.
43
 **
44
 ** Conflicts are greedily slackened to use the weakest bounds that still
45
 ** produce the conflict.
46
 **
47
 ** Extra things tracked atm: (Subject to change at Tim's whims)
48
 ** - A superset of all of the newly pivoted variables.
49
 ** - A queue of additional conflicts that were discovered by Simplex.
50
 **   These are theory valid and are currently turned into lemmas
51
 **/
52
53
#include "cvc4_private.h"
54
55
#pragma once
56
57
#include "theory/arith/error_set.h"
58
#include "theory/arith/linear_equality.h"
59
#include "theory/arith/simplex.h"
60
#include "theory/arith/simplex_update.h"
61
#include "util/dense_map.h"
62
#include "util/statistics_registry.h"
63
64
namespace CVC4 {
65
namespace theory {
66
namespace arith {
67
68
8992
class FCSimplexDecisionProcedure : public SimplexDecisionProcedure{
69
public:
70
  FCSimplexDecisionProcedure(LinearEqualityModule& linEq, ErrorSet& errors, RaiseConflict conflictChannel, TempVarMalloc tvmalloc);
71
72
  Result::Sat findModel(bool exactResult) override;
73
74
  // other error variables are dropping
75
  WitnessImprovement dualLikeImproveError(ArithVar evar);
76
  WitnessImprovement primalImproveError(ArithVar evar);
77
78
  // dual like
79
  // - found conflict
80
  // - satisfied error set
81
  Result::Sat dualLike();
82
83
private:
84
  static const uint32_t PENALTY = 4;
85
  DenseMultiset d_scores;
86
  void decreasePenalties(){ d_scores.removeOneOfEverything(); }
87
  uint32_t penalty(ArithVar x) const { return d_scores.count(x); }
88
  void setPenalty(ArithVar x, WitnessImprovement w){
89
    if(improvement(w)){
90
      if(d_scores.count(x) > 0){
91
        d_scores.removeAll(x);
92
      }
93
    }else{
94
      d_scores.setCount(x, PENALTY);
95
    }
96
  }
97
98
  /** The size of the focus set. */
99
  uint32_t d_focusSize;
100
101
  /** The current error focus variable. */
102
  ArithVar d_focusErrorVar;
103
104
  /**
105
   * The signs of the coefficients in the focus set.
106
   * This is empty until this has been loaded.
107
   */
108
  DenseMap<const Rational*> d_focusCoefficients;
109
110
  /**
111
   * Loads the signs of the coefficients of the variables on the row d_focusErrorVar
112
   * into d_focusSgns.
113
   */
114
  void loadFocusSigns();
115
116
  /** Unloads the information from d_focusSgns. */
117
  void unloadFocusSigns();
118
119
  /**
120
   * The signs of a variable in the row of d_focusErrorVar.
121
   * d_focusSgns must be loaded.
122
   */
123
  const Rational& focusCoefficient(ArithVar nb) const;
124
125
  int32_t d_pivotBudget;
126
  // enum PivotImprovement {
127
  //   ErrorDropped,
128
  //   NonDegenerate,
129
  //   HeuristicDegenerate,
130
  //   BlandsDegenerate
131
  // };
132
133
  WitnessImprovement d_prevWitnessImprovement;
134
  uint32_t d_witnessImprovementInARow;
135
136
  uint32_t degeneratePivotsInARow() const;
137
138
  static const uint32_t s_focusThreshold = 6;
139
  static const uint32_t s_maxDegeneratePivotsBeforeBlandsOnLeaving = 100;
140
  static const uint32_t s_maxDegeneratePivotsBeforeBlandsOnEntering = 10;
141
142
  DenseMap<uint32_t> d_leavingCountSinceImprovement;
143
  void increaseLeavingCount(ArithVar x){
144
    if(!d_leavingCountSinceImprovement.isKey(x)){
145
      d_leavingCountSinceImprovement.set(x,1);
146
    }else{
147
      (d_leavingCountSinceImprovement.get(x))++;
148
    }
149
  }
150
  LinearEqualityModule::UpdatePreferenceFunction selectLeavingFunction(ArithVar x){
151
    bool useBlands = d_leavingCountSinceImprovement.isKey(x) &&
152
      d_leavingCountSinceImprovement[x] >= s_maxDegeneratePivotsBeforeBlandsOnEntering;
153
    if(useBlands) {
154
      return &LinearEqualityModule::preferWitness<false>;
155
    } else {
156
      return &LinearEqualityModule::preferWitness<true>;
157
    }
158
  }
159
160
  bool debugDualLike(WitnessImprovement w, std::ostream& out,
161
                     int instance,
162
                     uint32_t prevFocusSize, uint32_t prevErrorSize) const;
163
164
  void debugPrintSignal(ArithVar updated) const;
165
166
  ArithVarVec d_sgnDisagreements;
167
168
  //static PivotImprovement pivotImprovement(const UpdateInfo& selected, bool useBlands = false);
169
170
  void logPivot(WitnessImprovement w);
171
172
  void updateAndSignal(const UpdateInfo& selected, WitnessImprovement w);
173
174
  UpdateInfo selectPrimalUpdate(ArithVar error,
175
                                LinearEqualityModule::UpdatePreferenceFunction upf,
176
                                LinearEqualityModule::VarPreferenceFunction bpf);
177
178
179
  UpdateInfo selectUpdateForDualLike(ArithVar basic){
180
    TimerStat::CodeTimer codeTimer(d_statistics.d_selectUpdateForDualLike);
181
182
    LinearEqualityModule::UpdatePreferenceFunction upf =
183
      &LinearEqualityModule::preferWitness<true>;
184
    LinearEqualityModule::VarPreferenceFunction bpf =
185
      &LinearEqualityModule::minVarOrder;
186
    return selectPrimalUpdate(basic, upf, bpf);
187
  }
188
189
  UpdateInfo selectUpdateForPrimal(ArithVar basic, bool useBlands){
190
    TimerStat::CodeTimer codeTimer(d_statistics.d_selectUpdateForPrimal);
191
192
    LinearEqualityModule::UpdatePreferenceFunction upf;
193
    if(useBlands) {
194
      upf = &LinearEqualityModule::preferWitness<false>;
195
    } else {
196
      upf = &LinearEqualityModule::preferWitness<true>;
197
    }
198
199
    LinearEqualityModule::VarPreferenceFunction bpf = useBlands ?
200
      &LinearEqualityModule::minVarOrder :
201
      &LinearEqualityModule::minRowLength;
202
203
    return selectPrimalUpdate(basic, upf, bpf);
204
  }
205
  WitnessImprovement selectFocusImproving() ;
206
207
  WitnessImprovement focusUsingSignDisagreements(ArithVar basic);
208
  WitnessImprovement focusDownToLastHalf();
209
  WitnessImprovement adjustFocusShrank(const ArithVarVec& drop);
210
  WitnessImprovement focusDownToJust(ArithVar v);
211
212
213
  void adjustFocusAndError(const UpdateInfo& up, const AVIntPairVec& focusChanges);
214
215
  /**
216
   * This is the main simplex for DPLL(T) loop.
217
   * It runs for at most maxIterations.
218
   *
219
   * Returns true iff it has found a conflict.
220
   * d_conflictVariable will be set and the conflict for this row is reported.
221
   */
222
  bool searchForFeasibleSolution(uint32_t maxIterations);
223
224
  bool initialProcessSignals(){
225
    TimerStat &timer = d_statistics.d_initialSignalsTime;
226
    IntStat& conflictStat  = d_statistics.d_initialConflicts;
227
    bool res = standardProcessSignals(timer, conflictStat);
228
    d_focusSize = d_errorSet.focusSize();
229
    return res;
230
  }
231
232
  static bool debugCheckWitness(const UpdateInfo& inf, WitnessImprovement w, bool useBlands);
233
234
  /** These fields are designed to be accessible to TheoryArith methods. */
235
  class Statistics {
236
  public:
237
    TimerStat d_initialSignalsTime;
238
    IntStat d_initialConflicts;
239
240
    IntStat d_fcFoundUnsat;
241
    IntStat d_fcFoundSat;
242
    IntStat d_fcMissed;
243
244
    TimerStat d_fcTimer;
245
    TimerStat d_fcFocusConstructionTimer;
246
247
    TimerStat d_selectUpdateForDualLike;
248
    TimerStat d_selectUpdateForPrimal;
249
250
    ReferenceStat<uint32_t> d_finalCheckPivotCounter;
251
252
    Statistics(uint32_t& pivots);
253
    ~Statistics();
254
  } d_statistics;
255
};/* class FCSimplexDecisionProcedure */
256
257
}/* CVC4::theory::arith namespace */
258
}/* CVC4::theory namespace */
259
}/* CVC4 namespace */