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-03-23 10:24:23 Functions: 0 8 0.0 %
Branches: 0 14 0.0 %

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

Generated by: LCOV version 1.14