LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory/arith/linear - fc_simplex.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 37 0.0 %
Date: 2026-02-23 11:51:46 Functions: 0 8 0.0 %
Branches: 0 14 0.0 %

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

Generated by: LCOV version 1.14