[Aptitude-svn-commit] r4104 - in branches/aptitude-0.3/aptitude: . src/generic/problemresolver tests

Daniel Burrows dburrows at costa.debian.org
Sun Sep 18 02:36:55 UTC 2005


Author: dburrows
Date: Sun Sep 18 02:36:52 2005
New Revision: 4104

Removed:
   branches/aptitude-0.3/aptitude/src/generic/problemresolver/conflictset.h
Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h
   branches/aptitude-0.3/aptitude/tests/test_resolver.cc
Log:
Back out the conflictset stuff.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Sun Sep 18 02:36:52 2005
@@ -1,3 +1,12 @@
+2005-09-17  Daniel Burrows  <dburrows at debian.org>
+
+	* src/generic/problemresolver/conflictset.h, src/generic/problemresolver/problemresolver.h, tests/test_resolver.cc:
+
+	  Back out the conflictset class, since it didn't speed anything
+	  up and may have slowed stuff down.  Also, I have a better
+	  high-level idea about cutting back on the cost of conflict
+	  testing.
+
 2005-09-16  Daniel Burrows  <dburrows at debian.org>
 
 	* src/generic/problemresolver/conflictset.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	Sun Sep 18 02:36:52 2005
@@ -49,11 +49,11 @@
 
 #include <iostream>
 
-#include "conflictset.h"
 #include "dump_universe.h"
 #include "exceptions.h"
 #include "solution.h"
 
+#include "../dense_setset.h"
 #include "../threads.h"
 
 /** A dummy iterator that's always an "end" iterator. */
@@ -364,10 +364,12 @@
     */
    std::set<solution, solution_contents_compare> deferred;
 
+   typedef dense_mapset<package, action, ExtractPackageId> conflictset;
+
    /** Stores conflicts: sets of installations that have been
     *  determined to be mutually incompatible.
     */
-   conflictset<PackageUniverse> conflicts;
+   conflictset conflicts;
 
    /** The initial set of broken dependencies.  Kept here for use in
     *  the stupid-elimination algorithm.
@@ -399,22 +401,73 @@
    std::ostream &dump_conflict(std::ostream &out, const imm::map<package, action> &conflict) const;
    std::ostream &dump_conflict(std::ostream &out, const action &act) const;
 
+
+   /** \param conflictorpair a (package, action) pair contained in a conflict.
+    *  \param apair a (package, action) pair from a solution or a conflict.
+    *
+    *  \return \b true if the given conflictor matches a.  This relation
+    *          is transitive, so if c1 matches c2 and c2 matches a,
+    *          then c1 matches a.
+    */
+   static bool conflictor_matches(const std::pair<package, action> &conflictorpair,
+				  const std::pair<package, action> &apair)
+     {
+       const action &conflictor = conflictorpair.second;
+       const action &a = apair.second;
+
+       if(a.ver != conflictor.ver)
+	 return false;
+
+       if(!conflictor.from_dep_source)
+	 return true;
+       else
+	 return a.from_dep_source && a.d == conflictor.d;
+     }
+
+   /** \return \b true if each element of pc2 is matched by an element
+    *  in pc1.
+    */
+   static bool conflict_matches(const typename imm::map<package, action> &c,
+				const typename imm::map<package, action> &acts)
+   {
+     typename imm::map<package, action>::const_iterator ci = c.begin();
+     typename imm::map<package, action>::const_iterator ai = acts.begin();
+
+     while(ci != c.end() &&
+	   ai != acts.end())
+       {
+	 if(ai->first < ci->first)
+	   ++ai;
+	 else if(ci->first < ai->first)
+	   return false;
+	 else if(!(conflictor_matches(ci->second, ai->second)))
+	   return false;
+	 else
+	   {
+	     ++ci;
+	     ++ai;
+	   }
+       }
+
+     return (ci == c.end());
+   }
+
    /** Test whether the given partial conflict subsumes an existing
     *  conflict.
     *
     *  \return a conflict matched by m, or conflicts.end() if no such
     *  conflict exists.
     */
-   typename conflictset<PackageUniverse>::const_iterator
+   typename conflictset::const_iterator
    find_matching_conflict(const imm::map<package, action> &m) const
    {
-     return conflicts.find_matching_conflict(m);
+     return conflicts.find_submap(m, &conflictor_matches);
    }
 
    /** Test whether the given solution contains a conflict. */
    bool contains_conflict(const solution &s) const
    {
-     typename conflictset<PackageUniverse>::const_iterator
+     typename conflictset::const_iterator
        found = find_matching_conflict(s.get_actions());
      bool rval = (found != conflicts.end());
 
@@ -437,7 +490,7 @@
     */
    void add_conflict(const imm::map<package, action> &conflict)
    {
-     typename conflictset<PackageUniverse>::const_iterator
+     typename conflictset::const_iterator
        found = find_matching_conflict(conflict);
 
      if(found != conflicts.end())
@@ -1603,7 +1656,7 @@
 	 imm::map<package, action> new_acts = s.get_actions();
 	 new_acts.put(v.get_package(), act);
 
-	 typename conflictset<PackageUniverse>::const_iterator
+	 typename conflictset::const_iterator
 	   found = find_matching_conflict(new_acts);
 
 	 if(found == conflicts.end())
@@ -1863,7 +1916,8 @@
       minimum_score(-infinity), max_successors(_max_successors),
       universe(_universe), finished(false), deferred_dirty(false),
       debug(false), remove_stupid(true),
-      solver_executing(false), solver_cancelled(false)
+      solver_executing(false), solver_cancelled(false),
+      conflicts(_universe.get_package_count())
   {
     // Find all the broken deps.
     for(typename PackageUniverse::broken_dep_iterator bi=universe.broken_begin();

Modified: branches/aptitude-0.3/aptitude/tests/test_resolver.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/tests/test_resolver.cc	(original)
+++ branches/aptitude-0.3/aptitude/tests/test_resolver.cc	Sun Sep 18 02:36:52 2005
@@ -19,7 +19,6 @@
 //
 // A test of the generic resolver layer.
 
-#include <src/generic/problemresolver/conflictset.h>
 #include <src/generic/problemresolver/dummy_universe.h>
 #include <src/generic/problemresolver/problemresolver.h>
 
@@ -84,17 +83,10 @@
   CPPUNIT_TEST(testActionCompare);
   CPPUNIT_TEST(testSolutionCompare);
   CPPUNIT_TEST(testRejections);
-  CPPUNIT_TEST(testConflictSet);
 
   CPPUNIT_TEST_SUITE_END();
 
 private:
-  typedef dummy_universe_ref::dep dep;
-  typedef dummy_universe_ref::package package;
-  typedef dummy_universe_ref::version version;
-  typedef generic_solution<dummy_universe_ref> solution;
-  typedef solution::action action;
-
   static dummy_universe_ref parseUniverse(const std::string &s)
   {
     std::istringstream in(s);
@@ -306,72 +298,6 @@
 	CPPUNIT_FAIL("Expected at least one solution, got none.");
       }
   }
-
-  void testConflictSet()
-  {
-    dummy_universe_ref u = parseUniverse(dummy_universe_1);
-
-    conflictset<dummy_universe_ref> conflicts;
-
-    imm::map<package, action> cf1;
-    imm::map<package, action> cf2;
-    imm::map<package, action> cf3;
-
-    package a = u.find_package("a");
-    package b = u.find_package("b");
-    package c = u.find_package("c");
-
-    version av1 = a.version_from_name("v1");
-    version av2 = a.version_from_name("v2");
-    version av3 = a.version_from_name("v3");
-
-    version bv1 = b.version_from_name("v1");
-    version bv2 = b.version_from_name("v2");
-    version bv3 = b.version_from_name("v3");
-
-    version cv1 = c.version_from_name("v1");
-    version cv2 = c.version_from_name("v2");
-    version cv3 = c.version_from_name("v3");
-
-    cf1.put(a,  action(av1, dep(), false, 0));
-
-    cf2.put(a, action(av2, dep(), false, 0));
-    cf2.put(b, action(bv3, dep(), false, 0));
-
-    cf3.put(a, action(av2, dep(), false, 0));
-    cf3.put(c, action(cv1, dep(), false, 0));
-
-    conflicts.insert(cf1);
-    conflicts.insert(cf2);
-    conflicts.insert(cf3);
-
-    conflicts.dump(std::cerr);
-    CPPUNIT_ASSERT_EQUAL((size_t) 3, conflicts.size());
-
-    imm::map<package, action> s;
-    s.put(a, action(av3, dep(), false, 0));
-    s.put(b, action(bv2, dep(), false, 0));
-    s.put(c, action(cv1, dep(), false, 0));
-
-    CPPUNIT_ASSERT(conflicts.find_matching_conflict(s) == conflicts.end());
-
-    s.put(a, action(av2, dep(), false, 0));
-    CPPUNIT_ASSERT(conflicts.find_matching_conflict(s) != conflicts.end());
-    CPPUNIT_ASSERT(*conflicts.find_matching_conflict(s) == cf3);
-
-    s.put(a, action(av1, dep(), false, 0));
-    CPPUNIT_ASSERT(conflicts.find_matching_conflict(s) != conflicts.end());
-    CPPUNIT_ASSERT(*conflicts.find_matching_conflict(s) == cf1);
-
-    s.put(c, action(cv3, dep(), false, 0));
-    s.put(a, action(av2, dep(), false, 0));
-
-    CPPUNIT_ASSERT(conflicts.find_matching_conflict(s) == conflicts.end());
-
-    s.put(b, action(bv3, dep(), false, 0));
-    CPPUNIT_ASSERT(conflicts.find_matching_conflict(s) != conflicts.end());
-    CPPUNIT_ASSERT(*conflicts.find_matching_conflict(s) == cf2);
-  }
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(ResolverTest);



More information about the Aptitude-svn-commit mailing list