[Aptitude-devel] r3032 - in branches/aptitude-0.3/aptitude: . src/generic/problemresolver

Daniel Burrows dburrows@costa.debian.org
Fri, 22 Apr 2005 00:43:44 +0000


Author: dburrows
Date: Fri Apr 22 00:43:41 2005
New Revision: 3032

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h
Log:
Require users to explicitly reset a solver after all solutions
are examined.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Fri Apr 22 00:43:41 2005
@@ -2,6 +2,13 @@
 
 	* src/generic/problemresolver/problemresolver.h:
 
+	  Once a resolver examines all possible solutions, it now returns
+	  "no more solutions" permanently until you call a "reset" method
+	  (which clears out all scores and empties the open and closed
+	  queues).
+
+	* src/generic/problemresolver/problemresolver.h:
+
 	  Lift the "solution" class out of the generic_problem_resolver
 	  class so I can forward-declare it (and hence declare pointers
 	  and references to it in aptcache.h).

Modified: branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h	Fri Apr 22 00:43:41 2005
@@ -466,6 +466,9 @@
    */
   int step_score, broken_score;
 
+  /** If \b true, we have exhausted the list of solutions. */
+  bool finished;
+
   /** The universe in which we are solving problems. */
   const PackageUniverse &universe;
 
@@ -678,7 +681,7 @@
   generic_problem_resolver(int step_penalty, int broken_penalty,
 			    const PackageUniverse &_universe)
     :step_score(-step_penalty), broken_score(-broken_penalty),
-     universe(_universe)
+     finished(false), universe(_universe)
   {
     version_scores=new int[universe.get_version_count()];
     for(size_t i=0; i<universe.get_version_count(); ++i)
@@ -690,6 +693,20 @@
     delete[] version_scores;
   }
 
+  /** Clears all the internal state of the solver, discards solutions,
+   *  zeroes out scores.  Call this routine after changing the state
+   *  of packages to avoid inconsistent results.
+   */
+  void reset()
+  {
+    finished=false;
+    open.clear();
+    closed.clear();
+
+    for(size_t i=0; i<universe.get_version_count(); ++i)
+      version_scores[i]=0;
+  }
+
   /** Tells the resolver how highly to value a particular package
    *  version.  All scores are relative, and a higher score will
    *  result in a bias towards that version appearing in the final
@@ -742,6 +759,9 @@
    */
   solution find_next_solution(int max_steps)
   {
+    if(finished)
+      throw NoMoreSolutions();
+
     // If the open queue is empty, then we're between searches and
     // should enqueue a new root node.
     if(open.empty())
@@ -801,6 +821,7 @@
 
     assert(open.empty());
 
+    finished=true;
     throw NoMoreSolutions();
   }