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

Daniel Burrows dburrows@costa.debian.org
Fri, 22 Apr 2005 13:10:22 +0000


Author: dburrows
Date: Fri Apr 22 13:10:18 2005
New Revision: 3040

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h
Log:
Allow problem-resolver debugging to be switched on and off
(it's off by default).

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Fri Apr 22 13:10:18 2005
@@ -1,3 +1,10 @@
+2005-04-22  Daniel Burrows  <dburrows@debian.org>
+
+	* src/generic/problemresolver/problemresolver.h:
+
+	  Add a flag to enable or disable debugging; debugging is disabled
+	  by default.
+
 2005-04-21  Daniel Burrows  <dburrows@debian.org>
 
 	* src/broken_indicator.cc:

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 13:10:18 2005
@@ -323,7 +323,6 @@
 
   void dump(std::ostream &out) const
   {
-    out << "<";
     for(typename std::map<package, action>::const_iterator i=get_actions().begin();
 	i!=get_actions().end(); ++i)
       {
@@ -466,9 +465,6 @@
    */
   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;
 
@@ -477,6 +473,11 @@
    */
   int *version_scores;
 
+  /** If \b true, we have exhausted the list of solutions. */
+  bool finished:1;
+
+  bool debug:1;
+
   /** The working queue: */
   std::priority_queue<solution, std::vector<solution>, solution_goodness_compare> open;
 
@@ -581,17 +582,23 @@
 
     if(closed.find(s2) == closed.end())
       {
-	std::cout << "Enqueuing ";
-	s2.dump(std::cout);
-	std::cout << std::endl;
+	if(debug)
+	  {
+	    std::cout << "Enqueuing ";
+	    s2.dump(std::cout);
+	    std::cout << std::endl;
+	  }
 
 	open.push(s2);
       }
     else
       {
-	std::cout << "Dropping closed solution ";
-	s2.dump(std::cout);
-	std::cout << std::endl;
+	if(debug)
+	  {
+	    std::cout << "Dropping closed solution ";
+	    s2.dump(std::cout);
+	    std::cout << std::endl;
+	  }
       }
   }
 
@@ -636,7 +643,8 @@
 	    !vi.end(); ++vi)
 	  if(*vi != source_version)
 	    {
-	      std::cout << "  Trying to resolve " << d << " by installing " << (*vi).get_package().get_name() << " version " << (*vi).get_name() << std::endl;
+	      if(debug)
+		std::cout << "  Trying to resolve " << d << " by installing " << (*vi).get_package().get_name() << " version " << (*vi).get_name() << std::endl;
 	      try_install(s, *vi);
 	    }
       }
@@ -655,7 +663,8 @@
 	if(sol_ver != sol_ver.get_package().current_version() &&
 	   s.get_actions().find(sol_ver.get_package())==s.get_actions().end())
 	  {
-	    std::cout << "  Trying to resolve " << d << " by installing " << (*si).get_package().get_name() << " version " << (*si).get_name() << std::endl;
+	    if(debug)
+	      std::cout << "  Trying to resolve " << d << " by installing " << (*si).get_package().get_name() << " version " << (*si).get_name() << std::endl;
 	    try_install(s, *si);
 	  }
       }
@@ -681,7 +690,7 @@
   generic_problem_resolver(int step_penalty, int broken_penalty,
 			    const PackageUniverse &_universe)
     :step_score(-step_penalty), broken_score(-broken_penalty),
-     finished(false), universe(_universe)
+     universe(_universe), finished(false), debug(false)
   {
     version_scores=new int[universe.get_version_count()];
     for(size_t i=0; i<universe.get_version_count(); ++i)
@@ -693,6 +702,14 @@
     delete[] version_scores;
   }
 
+  /** Enables or disables debugging.  Debugging is initially
+   *  disabled.
+   */
+  void set_debug(bool new_debug)
+  {
+    debug=new_debug;
+  }
+
   /** 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.
@@ -791,26 +808,33 @@
 
 	if(closed.find(s) != closed.end())
 	  {
-	    std::cout << "Dropping closed solution ";
-	    s.dump(std::cout);
-	    std::cout << std::endl;
+	    if(debug)
+	      {
+		std::cout << "Dropping closed solution ";
+		s.dump(std::cout);
+		std::cout << std::endl;
+	      }
 	    continue;
 	  }
 
 	closed.insert(s);
 
-	std::cout << "Processing ";
-
-	s.dump(std::cout);
-
-	std::cout << std::endl;
+	if(debug)
+	  {
+	    std::cout << "Processing ";
+	    s.dump(std::cout);
+	    std::cout << std::endl;
+	  }
 
 	// If all dependencies are satisfied, we found a solution.
 	if(s.get_broken().empty())
 	  {
-	    std::cout << " --- Found solution ";
-	    s.dump(std::cout);
-	    std::cout << std::endl;
+	    if(debug)
+	      {
+		std::cout << " --- Found solution ";
+		s.dump(std::cout);
+		std::cout << std::endl;
+	      }
 	    return s;
 	  }
 	// Nope, let's go enqueue successor nodes.