- also check obsoletes when disabling update rules
[platform/upstream/libsolv.git] / src / solver.c
index af66605..f3826e4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Novell Inc.
+ * Copyright (c) 2007-2008, Novell Inc.
  *
  * This program is licensed under the BSD license, read LICENSE.BSD
  * for further information
 #include "util.h"
 #include "evr.h"
 #include "policy.h"
+#include "solverdebug.h"
 
-
+#define CODE10 0 /* set to '1' to enable patch atoms */
 
 #define RULES_BLOCK 63
 
+/********************************************************************
+ *
+ * dependency check helpers
+ *
+ */
+
+/*-------------------------------------------------------------------
+ * handle split provides
+ */
 
 int
 solver_splitprovides(Solver *solv, Id dep)
@@ -53,6 +63,11 @@ solver_splitprovides(Solver *solv, Id dep)
   return 0;
 }
 
+
+/*-------------------------------------------------------------------
+ * solver_dep_installed
+ */
+
 int
 solver_dep_installed(Solver *solv, Id dep)
 {
@@ -82,7 +97,13 @@ solver_dep_installed(Solver *solv, Id dep)
 }
 
 
-/* this mirrors solver_dep_fulfilled but uses map m instead of the decisionmap */
+/*-------------------------------------------------------------------
+ * Check if dependenc is possible
+ * 
+ * this mirrors solver_dep_fulfilled
+ * but uses map m instead of the decisionmap
+ */
+
 static inline int
 dep_possible(Solver *solv, Id dep, Map *m)
 {
@@ -111,111 +132,19 @@ dep_possible(Solver *solv, Id dep, Map *m)
   return 0;
 }
 
-/*-----------------------------------------------------------------*/
-
-/*
- * print rules
- */
-
-static void
-printruleelement(Solver *solv, int type, Rule *r, Id v)
-{
-  Pool *pool = solv->pool;
-  Solvable *s;
-  if (v < 0)
-    {
-      s = pool->solvables + -v;
-      POOL_DEBUG(type, "    !%s [%d]", solvable2str(pool, s), -v);
-    }
-  else
-    {
-      s = pool->solvables + v;
-      POOL_DEBUG(type, "    %s [%d]", solvable2str(pool, s), v);
-    }
-  if (r)
-    {
-      if (r->w1 == v)
-       POOL_DEBUG(type, " (w1)");
-      if (r->w2 == v)
-       POOL_DEBUG(type, " (w2)");
-    }
-  if (solv->decisionmap[s - pool->solvables] > 0)
-    POOL_DEBUG(type, " Install.level%d", solv->decisionmap[s - pool->solvables]);
-  if (solv->decisionmap[s - pool->solvables] < 0)
-    POOL_DEBUG(type, " Conflict.level%d", -solv->decisionmap[s - pool->solvables]);
-  POOL_DEBUG(type, "\n");
-}
-
-
-/*
- * print rule
- */
-
-static void
-printrule(Solver *solv, int type, Rule *r)
-{
-  Pool *pool = solv->pool;
-  int i;
-  Id v;
-
-  if (r >= solv->rules && r < solv->rules + solv->nrules)   /* r is a solver rule */
-    POOL_DEBUG(type, "Rule #%d:", (int)(r - solv->rules));
-  else
-    POOL_DEBUG(type, "Rule:");                /* r is any rule */
-  if (r && r->w1 == 0)
-    POOL_DEBUG(type, " (disabled)");
-  POOL_DEBUG(type, "\n");
-  for (i = 0; ; i++)
-    {
-      if (i == 0)
-         /* print direct literal */
-       v = r->p;
-      else if (r->d == ID_NULL)
-       {
-         if (i == 2)
-           break;
-         /* binary rule --> print w2 as second literal */
-         v = r->w2;
-       }
-      else
-         /* every other which is in d */
-       v = solv->pool->whatprovidesdata[r->d + i - 1];
-      if (v == ID_NULL)
-       break;
-      printruleelement(solv, type, r, v);
-    }
-  POOL_DEBUG(type, "    next rules: %d %d\n", r->n1, r->n2);
-}
-
-static void
-printruleclass(Solver *solv, int type, Rule *r)
-{
-  Pool *pool = solv->pool;
-  Id p = r - solv->rules;
-  assert(p >= 0);
-  if (p < solv->learntrules)
-    if (MAPTST(&solv->weakrulemap, p))
-      POOL_DEBUG(type, "WEAK ");
-  if (p >= solv->learntrules)
-    POOL_DEBUG(type, "LEARNT ");
-  else if (p >= solv->systemrules)
-    POOL_DEBUG(type, "SYSTEM ");
-  else if (p >= solv->jobrules)
-    POOL_DEBUG(type, "JOB ");
-  printrule(solv, type, r);
-}
-
-
-/*-----------------------------------------------------------------*/
-
-/*
+/********************************************************************
+ *
  * Rule handling
+ *
+ * - unify rules, remove duplicates
  */
 
 static Pool *unifyrules_sortcmp_data;
 
-/*
+/*-------------------------------------------------------------------
+ *
  * compare rules for unification sort
+ *
  */
 
 static int
@@ -257,8 +186,10 @@ unifyrules_sortcmp(const void *ap, const void *bp)
 }
 
 
-/*
+/*-------------------------------------------------------------------
+ *
  * unify rules
+ * go over all rules and remove duplicates
  */
 
 static void
@@ -297,6 +228,9 @@ unifyrules(Solver *solv)
   /* adapt rule buffer */
   solv->nrules = j;
   solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
+    /*
+     * debug: statistics
+     */
   IF_POOLDEBUG (SAT_DEBUG_STATS)
     {
       int binr = 0;
@@ -344,6 +278,10 @@ hashrule(Solver *solv, Id p, Id d, int n)
 #endif
 
 
+/*-------------------------------------------------------------------
+ * 
+ */
+
 /*
  * add rule
  *  p = direct literal; always < 0 for installed rpm rules
@@ -389,19 +327,25 @@ addrule(Solver *solv, Id p, Id d)
   int n = 0;                          /* number of literals in rule - 1
                                          0 = direct assertion (single literal)
                                          1 = binary rule
+                                         >1 = 
                                        */
 
   /* it often happenes that requires lead to adding the same rpm rule
    * multiple times, so we prune those duplicates right away to make
    * the work for unifyrules a bit easier */
 
-  if (solv->nrules && !solv->jobrules)
+  if (solv->nrules                      /* we already have rules */
+      && !solv->rpmrules_end)           /* but are not done with rpm rules */
     {
       r = solv->rules + solv->nrules - 1;   /* get the last added rule */
       if (r->p == p && r->d == d && d != 0)   /* identical and not user requested */
        return r;
     }
 
+    /*
+     * compute number of literals (n) in rule
+     */
+    
   if (d < 0)
     {
       /* always a binary rule */
@@ -414,12 +358,13 @@ addrule(Solver *solv, Id p, Id d)
       for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
        if (*dp == -p)
          return 0;                     /* rule is self-fulfilling */
-      if (n == 1)
+       
+      if (n == 1)   /* have single provider */
        d = dp[-1];                     /* take single literal */
     }
 
 #if 0
-  if (n == 0 && !solv->jobrules)
+  if (n == 0 && !solv->rpmrules_end)
     {
       /* this is a rpm rule assertion, we do not have to allocate it */
       /* it can be identified by a level of 1 and a zero reason */
@@ -435,19 +380,22 @@ addrule(Solver *solv, Id p, Id d)
     }
 #endif
 
-  if (n == 1 && p > d)
+  if (n == 1 && p > d && !solv->rpmrules_end)
     {
       /* smallest literal first so we can find dups */
-      n = p;
-      p = d;
-      d = n;
+      n = p; p = d; d = n;             /* p <-> d */
       n = 1;                          /* re-set n, was used as temp var */
     }
 
-  /* check if the last added rule is exactly the same as what we're looking for. */
+    /*
+     * check for duplicate
+     */
+    
+  /* check if the last added rule (r) is exactly the same as what we're looking for. */
   if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
     return r;  /* binary rule */
 
+    /* have n-ary rule with same first literal, check other literals */
   if (r && n > 1 && r->d && r->p == p)
     {
       /* Rule where d is an offset in whatprovidesdata */
@@ -462,14 +410,18 @@ addrule(Solver *solv, Id p, Id d)
        return r;
    }
 
-  /*
-   * allocate new rule
-   */
+    /*
+     * allocate new rule
+     */
 
   /* extend rule buffer */
   solv->rules = sat_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
   r = solv->rules + solv->nrules++;    /* point to rule space */
 
+    /*
+     * r = new rule
+     */
+    
   r->p = p;
   if (n == 0)
     {
@@ -497,32 +449,39 @@ addrule(Solver *solv, Id p, Id d)
   IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
     {
       POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "  Add rule: ");
-      printrule(solv, SAT_DEBUG_RULE_CREATION, r);
+      solver_printrule(solv, SAT_DEBUG_RULE_CREATION, r);
     }
 
   return r;
 }
 
+/*-------------------------------------------------------------------
+ * disable rule
+ */
+
 static inline void
 disablerule(Solver *solv, Rule *r)
 {
-  r->w1 = 0;
+  if (r->d >= 0)
+    r->d = -r->d - 1;
 }
 
+/*-------------------------------------------------------------------
+ * enable rule
+ */
+
 static inline void
 enablerule(Solver *solv, Rule *r)
 {
-  if (r->d == 0 || r->w2 != r->p)
-    r->w1 = r->p;
-  else
-    r->w1 = solv->pool->whatprovidesdata[r->d];
+  if (r->d < 0)
+    r->d = -r->d - 1;
 }
 
 
 /**********************************************************************************/
 
 /* a problem is an item on the solver's problem list. It can either be >0, in that
- * case it is a system (upgrade) rule, or it can be <0, which makes it refer to a job
+ * case it is a update rule, or it can be <0, which makes it refer to a job
  * consisting of multiple job rules.
  */
 
@@ -540,11 +499,15 @@ disableproblem(Solver *solv, Id v)
     }
   v = -(v + 1);
   jp = solv->ruletojob.elements;
-  for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
+  for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
     if (*jp == v)
       disablerule(solv, r);
 }
 
+/*-------------------------------------------------------------------
+ * enableproblem
+ */
+
 static void
 enableproblem(Solver *solv, Id v)
 {
@@ -554,54 +517,46 @@ enableproblem(Solver *solv, Id v)
 
   if (v > 0)
     {
+      if (v >= solv->featurerules && v < solv->featurerules_end)
+       {
+         /* do not enable feature rule if update rule is enabled */
+         r = solv->rules + (v - solv->featurerules + solv->updaterules);
+         if (r->d >= 0)
+           return;
+       }
       enablerule(solv, solv->rules + v);
+      if (v >= solv->updaterules && v < solv->updaterules_end)
+       {
+         /* disable feature rule when enabling update rule */
+         r = solv->rules + (v - solv->updaterules + solv->featurerules);
+         if (r->p)
+           disablerule(solv, r);
+       }
       return;
     }
   v = -(v + 1);
   jp = solv->ruletojob.elements;
-  for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
+  for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
     if (*jp == v)
       enablerule(solv, r);
 }
 
-static void
-printproblem(Solver *solv, Id v)
-{
-  Pool *pool = solv->pool;
-  int i;
-  Rule *r;
-  Id *jp;
-
-  if (v > 0)
-    printrule(solv, SAT_DEBUG_SOLUTIONS, solv->rules + v);
-  else
-    {
-      v = -(v + 1);
-      POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "JOB %d\n", v);
-      jp = solv->ruletojob.elements;
-      for (i = solv->jobrules, r = solv->rules + i; i < solv->systemrules; i++, r++, jp++)
-       if (*jp == v)
-         {
-           POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "- ");
-           printrule(solv, SAT_DEBUG_SOLUTIONS, r);
-         }
-      POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "ENDJOB\n");
-    }
-}
-
-
 
 /************************************************************************/
 
-/* go through system and job rules and add direct assertions
+/*
+ * make assertion rules into decisions
+ * 
+ * go through update and job rules and add direct assertions
  * to the decisionqueue. If we find a conflict, disable rules and
  * add them to problem queue.
  */
+
 static void
 makeruledecisions(Solver *solv)
 {
   Pool *pool = solv->pool;
-  int i, ri;
+  int i, ri, ii;
   Rule *r, *rr;
   Id v, vv;
   int decisionstart;
@@ -609,21 +564,25 @@ makeruledecisions(Solver *solv)
   POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions ; size decisionq: %d -----\n",solv->decisionq.count);
 
   decisionstart = solv->decisionq.count;
-  /* rpm rules don't have assertions, so we can start with the job
-   * rules (rpm assertions are not resulting in a rule, but cause a
-   * immediate decision) */
-  /* nowadays they can be weak, so start with rule 1 */
-  for (ri = 1, r = solv->rules + ri; ri < solv->nrules; ri++, r++)
+  for (ii = 0; ii < solv->ruleassertions.count; ii++)
     {
-      if (!r->w1 || r->w2)     /* disabled or no assertion */
+      ri = solv->ruleassertions.elements[ii];
+      r = solv->rules + ri;
+       
+      if (r->d < 0 || !r->p || r->w2)  /* disabled, dummy or no assertion */
        continue;
       /* do weak rules in phase 2 */
       if (ri < solv->learntrules && MAPTST(&solv->weakrulemap, ri))
        continue;
+       
       v = r->p;
       vv = v > 0 ? v : -v;
-      if (!solv->decisionmap[vv])
+       
+      if (!solv->decisionmap[vv])          /* if not yet decided */
        {
+           /*
+            * decide !
+            */
          queue_push(&solv->decisionq, v);
          queue_push(&solv->decisionq_why, r - solv->rules);
          solv->decisionmap[vv] = v > 0 ? 1 : -1;
@@ -637,11 +596,23 @@ makeruledecisions(Solver *solv)
            }
          continue;
        }
-      if (v > 0 && solv->decisionmap[vv] > 0)
+       /*
+        * check previous decision: is it sane ?
+        */
+       
+      if (v > 0 && solv->decisionmap[vv] > 0)    /* ok to install */
        continue;
-      if (v < 0 && solv->decisionmap[vv] < 0)
+      if (v < 0 && solv->decisionmap[vv] < 0)    /* ok to remove */
        continue;
-      /* found a conflict! */
+       
+        /*
+        * found a conflict!
+        * 
+        * The rule (r) we're currently processing says something
+        * different (v = r->p) than a previous decision (decisionmap[abs(v)])
+        * on this literal
+        */
+       
       if (ri >= solv->learntrules)
        {
          /* conflict with a learnt rule */
@@ -651,19 +622,27 @@ makeruledecisions(Solver *solv)
          disablerule(solv, r);
          continue;
        }
-      /* only job and system rules left in the decisionq */
-      /* find the decision which is the "opposite" of the jobrule */
+       
+        /*
+        * find the decision which is the "opposite" of the rule
+        */
+       
       for (i = 0; i < solv->decisionq.count; i++)
        if (solv->decisionq.elements[i] == -v)
          break;
-      assert(i < solv->decisionq.count);
+      assert(i < solv->decisionq.count);         /* assert that we found it */
+       
+       /*
+        * conflict with system solvable ?
+        */
+       
       if (v == -SYSTEMSOLVABLE) {
        /* conflict with system solvable */
        queue_push(&solv->problems, solv->learnt_pool.count);
         queue_push(&solv->learnt_pool, ri);
        queue_push(&solv->learnt_pool, 0);
        POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
-       if (ri < solv->systemrules)
+       if  (ri >= solv->jobrules && ri < solv->jobrules_end)
          v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
        else
          v = ri;
@@ -672,8 +651,14 @@ makeruledecisions(Solver *solv)
        disableproblem(solv, v);
        continue;
       }
+       
       assert(solv->decisionq_why.elements[i]);
-      if (solv->decisionq_why.elements[i] < solv->jobrules)
+       
+        /*
+        * conflict with an rpm rule ?
+        */
+       
+      if (solv->decisionq_why.elements[i] < solv->rpmrules_end)
        {
          /* conflict with rpm rule assertion */
          queue_push(&solv->problems, solv->learnt_pool.count);
@@ -682,7 +667,7 @@ makeruledecisions(Solver *solv)
          queue_push(&solv->learnt_pool, 0);
          assert(v > 0 || v == -SYSTEMSOLVABLE);
          POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
-         if (ri < solv->systemrules)
+         if (ri >= solv->jobrules && ri < solv->jobrules_end)
            v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
          else
            v = ri;
@@ -692,36 +677,52 @@ makeruledecisions(Solver *solv)
          continue;
        }
 
-      /* conflict with another job or system rule */
+        /*
+        * conflict with another job or update/feature rule
+        */
+       
       /* record proof */
       queue_push(&solv->problems, solv->learnt_pool.count);
       queue_push(&solv->learnt_pool, ri);
       queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
       queue_push(&solv->learnt_pool, 0);
 
-      POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflicting system/job assertions over literal %d\n", vv);
+      POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "conflicting update/job assertions over literal %d\n", vv);
 
-      /* push all of our rules asserting this literal on the problem stack */
-      for (i = solv->jobrules, rr = solv->rules + i; i < solv->nrules; i++, rr++)
+        /*
+        * push all of our rules (can only be feature or job rules)
+        * asserting this literal on the problem stack
+        */
+       
+      for (i = solv->featurerules, rr = solv->rules + i; i < solv->learntrules; i++, rr++)
        {
-         if (!rr->w1 || rr->w2)
-           continue;
-         if (rr->p != vv && rr->p != -vv)
+         if (rr->d < 0                          /* disabled */
+             || rr->w2)                         /*  or no assertion */
            continue;
-         if (i >= solv->learntrules)
+         if (rr->p != vv                        /* not affecting the literal */
+             && rr->p != -vv)
            continue;
-         if (MAPTST(&solv->weakrulemap, i))
+         if (MAPTST(&solv->weakrulemap, i))     /* weak: silently ignore */
            continue;
+           
          POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
+           
+          solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, solv->rules + i);
+           
          v = i;
-         if (i < solv->systemrules)
+           /* is is a job rule ? */
+         if (i >= solv->jobrules && i < solv->jobrules_end)
            v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
+           
          queue_push(&solv->problems, v);
          disableproblem(solv, v);
        }
       queue_push(&solv->problems, 0);
 
-      /* start over */
+       /*
+       * start over
+       * (back up from decisions)
+       */
       while (solv->decisionq.count > decisionstart)
        {
          v = solv->decisionq.elements[--solv->decisionq.count];
@@ -729,19 +730,26 @@ makeruledecisions(Solver *solv)
          vv = v > 0 ? v : -v;
          solv->decisionmap[vv] = 0;
        }
-      ri = solv->jobrules - 1;
-      r = solv->rules + ri;
+      ii = -1; /* restarts loop at 0 */
     }
 
-  /* phase 2: now do the weak assertions */
-  for (ri = 1, r = solv->rules + ri; ri < solv->learntrules; ri++, r++)
+    /*
+     * phase 2: now do the weak assertions
+     */
+  for (ii = 0; ii < solv->ruleassertions.count; ii++)
     {
-      if (!r->w1 || r->w2)     /* disabled or no assertion */
+      ri = solv->ruleassertions.elements[ii];
+      r = solv->rules + ri;
+      if (r->d < 0 || r->w2)                    /* disabled or no assertion */
        continue;
-      if (!MAPTST(&solv->weakrulemap, ri))
+      if (!MAPTST(&solv->weakrulemap, ri))       /* skip non-weak */
        continue;
       v = r->p;
       vv = v > 0 ? v : -v;
+       /*
+        * decide !
+        * (if not yet decided)
+        */
       if (!solv->decisionmap[vv])
        {
          queue_push(&solv->decisionq, v);
@@ -757,19 +765,26 @@ makeruledecisions(Solver *solv)
            }
          continue;
        }
+       /*
+        * previously decided, sane ?
+        */
       if (v > 0 && solv->decisionmap[vv] > 0)
        continue;
       if (v < 0 && solv->decisionmap[vv] < 0)
        continue;
+       
       POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
-      printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
+      solver_printrule(solv, SAT_DEBUG_UNSOLVABLE, r);
       disablerule(solv, r);
     }
   
   POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- makeruledecisions end; size decisionq: %d -----\n",solv->decisionq.count);
 }
 
-/*
+
+/*-------------------------------------------------------------------
+ * enable/disable learnt rules 
+ *
  * we have enabled or disabled some of our rules. We now reenable all
  * of our learnt rules but the ones that were learnt from rules that
  * are now disabled.
@@ -788,30 +803,26 @@ enabledisablelearntrules(Solver *solv)
       whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
       while ((why = *whyp++) != 0)
        {
-#if 0
-         if (why < 0)
-           continue;           /* rpm assertion */
-#endif
-         assert(why < i);
-         if (!solv->rules[why].w1)
+         assert(why > 0 && why < i);
+         if (solv->rules[why].d < 0)
            break;
        }
       /* why != 0: we found a disabled rule, disable the learnt rule */
-      if (why && r->w1)
+      if (why && r->d >= 0)
        {
          IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
            {
              POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "disabling ");
-             printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
+             solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
            }
           disablerule(solv, r);
        }
-      else if (!why && !r->w1)
+      else if (!why && r->d < 0)
        {
          IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
            {
              POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "re-enabling ");
-             printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
+             solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
            }
           enablerule(solv, r);
        }
@@ -819,15 +830,44 @@ enabledisablelearntrules(Solver *solv)
 }
 
 
+/*-------------------------------------------------------------------
+ * enable weak rules
+ * 
+ * Enable all rules, except learnt rules, which are
+ * - disabled and weak (set in weakrulemap)
+ * 
+ */
+
+static void
+enableweakrules(Solver *solv)
+{
+  int i;
+  Rule *r;
+
+  for (i = 1, r = solv->rules + i; i < solv->learntrules; i++, r++)
+    {
+      if (r->d >= 0) /* skip non-direct literals */
+       continue;
+      if (!MAPTST(&solv->weakrulemap, i))
+       continue;
+      enablerule(solv, r);
+    }
+}
+
+
 /* FIXME: bad code ahead, replace as soon as possible */
 /* FIXME: should probably look at SOLVER_INSTALL_SOLVABLE_ONE_OF */
 
+/*-------------------------------------------------------------------
+ * disable update rules
+ */
+
 static void
 disableupdaterules(Solver *solv, Queue *job, int jobidx)
 {
   Pool *pool = solv->pool;
   int i, j;
-  Id name, how, what, p, *pp;
+  Id how, what, p, *pp;
   Solvable *s;
   Repo *installed;
   Rule *r;
@@ -853,10 +893,10 @@ disableupdaterules(Solver *solv, Queue *job, int jobidx)
     }
   /* go through all enabled job rules */
   MAPZERO(&solv->noupdate);
-  for (i = solv->jobrules; i < solv->systemrules; i++)
+  for (i = solv->jobrules; i < solv->jobrules_end; i++)
     {
       r = solv->rules + i;
-      if (!r->w1)      /* disabled? */
+      if (r->d < 0)    /* disabled? */
        continue;
       j = solv->ruletojob.elements[i - solv->jobrules];
       if (j == lastjob)
@@ -868,9 +908,25 @@ disableupdaterules(Solver *solv, Queue *job, int jobidx)
        {
        case SOLVER_INSTALL_SOLVABLE:                   /* install specific solvable */
          s = pool->solvables + what;
+         if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, what))
+           break;
+         if (s->obsoletes)
+           {
+             Id obs, *obsp;
+             obsp = s->repo->idarraydata + s->obsoletes;
+             while ((obs = *obsp++) != 0)
+               FOR_PROVIDES(p, pp, obs)
+                 {
+                   if (pool->solvables[p].repo != installed)
+                     continue;
+                   if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
+                     continue;
+                   MAPSET(&solv->noupdate, p - installed->start);
+                 }
+           }
          FOR_PROVIDES(p, pp, s->name)
            {
-             if (pool->solvables[p].name != s->name)
+             if (!solv->implicitobsoleteusesprovides && pool->solvables[p].name != s->name)
                continue;
              if (pool->solvables[p].repo == installed)
                MAPSET(&solv->noupdate, p - installed->start);
@@ -883,15 +939,9 @@ disableupdaterules(Solver *solv, Queue *job, int jobidx)
          break;
        case SOLVER_ERASE_SOLVABLE_NAME:                  /* remove by capability */
        case SOLVER_ERASE_SOLVABLE_PROVIDES:
-         name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
-         while (ISRELDEP(name))
-           {
-             Reldep *rd = GETRELDEP(pool, name);
-             name = rd->name;
-           }
          FOR_PROVIDES(p, pp, what)
            {
-             if (name && pool->solvables[p].name != name)
+             if (how == SOLVER_ERASE_SOLVABLE_NAME && !pool_match_nevr(pool, pool->solvables + p, what))
                continue;
              if (pool->solvables[p].repo == installed)
                MAPSET(&solv->noupdate, p - installed->start);
@@ -903,9 +953,6 @@ disableupdaterules(Solver *solv, Queue *job, int jobidx)
     }
 
   /* fixup update rule status */
-  if (solv->allowuninstall)
-    return;            /* no update rules at all */
-
   if (jobidx != -1)
     {
       /* we just disabled job #jobidx. enable all update rules
@@ -916,22 +963,46 @@ disableupdaterules(Solver *solv, Queue *job, int jobidx)
        {
        case SOLVER_INSTALL_SOLVABLE:
          s = pool->solvables + what;
+         if (s->obsoletes)
+           {
+             Id obs, *obsp;
+             obsp = s->repo->idarraydata + s->obsoletes;
+             while ((obs = *obsp++) != 0)
+               FOR_PROVIDES(p, pp, obs)
+                 {
+                   if (pool->solvables[p].repo != installed)
+                     continue;
+                   if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
+                     continue;
+                   if (MAPTST(&solv->noupdate, p - installed->start))
+                     continue;
+                   r = solv->rules + solv->updaterules + (p - installed->start);
+                   if (r->d >= 0)
+                     continue;
+                   enablerule(solv, r);
+                   IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
+                     {
+                       POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
+                       solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
+                     }
+                 }
+           }
          FOR_PROVIDES(p, pp, s->name)
            {
-             if (pool->solvables[p].name != s->name)
+             if (!solv->implicitobsoleteusesprovides && pool->solvables[p].name != s->name)
                continue;
              if (pool->solvables[p].repo != installed)
                continue;
              if (MAPTST(&solv->noupdate, p - installed->start))
                continue;
-             r = solv->rules + solv->systemrules + (p - installed->start);
-             if (r->w1)
+             r = solv->rules + solv->updaterules + (p - installed->start);
+             if (r->d >= 0)
                continue;
              enablerule(solv, r);
              IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
                {
                  POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
-                 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
+                 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
                }
            }
          break;
@@ -941,40 +1012,34 @@ disableupdaterules(Solver *solv, Queue *job, int jobidx)
            break;
          if (MAPTST(&solv->noupdate, what - installed->start))
            break;
-         r = solv->rules + solv->systemrules + (what - installed->start);
-         if (r->w1)
+         r = solv->rules + solv->updaterules + (what - installed->start);
+         if (r->d >= 0)
            break;
          enablerule(solv, r);
          IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
            {
              POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
-             printrule(solv, SAT_DEBUG_SOLUTIONS, r);
+             solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
            }
          break;
        case SOLVER_ERASE_SOLVABLE_NAME:                  /* remove by capability */
        case SOLVER_ERASE_SOLVABLE_PROVIDES:
-         name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
-         while (ISRELDEP(name))
-           {
-             Reldep *rd = GETRELDEP(pool, name);
-             name = rd->name;
-           }
          FOR_PROVIDES(p, pp, what)
            {
-             if (name && pool->solvables[p].name != name)
-               continue;
+             if (how == SOLVER_ERASE_SOLVABLE_NAME && !pool_match_nevr(pool, pool->solvables + p, what))
+               continue;
              if (pool->solvables[p].repo != installed)
                continue;
              if (MAPTST(&solv->noupdate, p - installed->start))
                continue;
-             r = solv->rules + solv->systemrules + (p - installed->start);
-             if (r->w1)
+             r = solv->rules + solv->updaterules + (p - installed->start);
+             if (r->d >= 0)
                continue;
              enablerule(solv, r);
              IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
                {
                  POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
-                 printrule(solv, SAT_DEBUG_SOLUTIONS, r);
+                 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
                }
            }
          break;
@@ -986,58 +1051,35 @@ disableupdaterules(Solver *solv, Queue *job, int jobidx)
 
   for (i = 0; i < installed->nsolvables; i++)
     {
-      r = solv->rules + solv->systemrules + i;
-      if (r->w1 && MAPTST(&solv->noupdate, i))
+      r = solv->rules + solv->updaterules + i;
+      if (r->d >= 0 && MAPTST(&solv->noupdate, i))
+        disablerule(solv, r);  /* was enabled, need to disable */
+      r = solv->rules + solv->featurerules + i;
+      if (r->d >= 0 && MAPTST(&solv->noupdate, i))
         disablerule(solv, r);  /* was enabled, need to disable */
     }
 }
 
-#if 0
-static void
-addpatchatomrequires(Solver *solv, Solvable *s, Id *dp, Queue *q, Map *m)
-{
-  Pool *pool = solv->pool;
-  Id fre, *frep, p, *pp, ndp;
-  Solvable *ps;
-  Queue fq;
-  Id qbuf[64];
-  int i, used = 0;
-
-  queue_init_buffer(&fq, qbuf, sizeof(qbuf)/sizeof(*qbuf));
-  queue_push(&fq, -(s - pool->solvables));
-  for (; *dp; dp++)
-    queue_push(&fq, *dp);
-  ndp = pool_queuetowhatprovides(pool, &fq);
-  frep = s->repo->idarraydata + s->freshens;
-  while ((fre = *frep++) != 0)
-    {
-      FOR_PROVIDES(p, pp, fre)
-       {
-         ps = pool->solvables + p;
-         addrule(solv, -p, ndp);
-         used = 1;
-         if (!MAPTST(m, p))
-           queue_push(q, p);
-       }
-    }
-  if (used)
-    {
-      for (i = 1; i < fq.count; i++)
-       {
-         p = fq.elements[i];
-         if (!MAPTST(m, p))
-           queue_push(q, p);
-       }
-    }
-  queue_free(&fq);
-}
-#endif
 
 
-/*
+/*-------------------------------------------------------------------
+ * 
  * add (install) rules for solvable
+ * 
+ * s: Solvable for which to add rules
+ * m: m[s] = 1 for solvables which have rules, prevent rule duplication
+ * 
+ * Algorithm: 'visit all nodes of a graph'. The graph nodes are
+ *  solvables, the edges their dependencies.
+ *  Starting from an installed solvable, this will create all rules
+ *  representing the graph created by the solvables dependencies.
+ * 
  * for unfulfilled requirements, conflicts, obsoletes,....
  * add a negative assertion for solvables that are not installable
+ * 
+ * It will also create rules for all solvables referenced by 's'
+ *  i.e. descend to all providers of requirements of 's'
+ *
  */
 
 static void
@@ -1045,59 +1087,70 @@ addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
 {
   Pool *pool = solv->pool;
   Repo *installed = solv->installed;
-  Queue q;
-  Id qbuf[64];
+
+  /* 'work' queue. keeps Ids of solvables we still have to work on.
+     And buffer for it. */
+  Queue workq;
+  Id workqbuf[64];
+    
   int i;
+    /* if to add rules for broken deps ('rpm -V' functionality)
+     * 0 = yes, 1 = no
+     */
   int dontfix;
+#if CODE10
   int patchatom;
+#endif
+    /* Id var and pointer for each dependency
+     * (not used in parallel)
+     */
   Id req, *reqp;
   Id con, *conp;
   Id obs, *obsp;
   Id rec, *recp;
   Id sug, *sugp;
+    /* var and ptr for loops */
   Id p, *pp;
+    /* ptr to 'whatprovides' */
   Id *dp;
+    /* Id for current solvable 's' */
   Id n;
 
   POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable -----\n");
 
-  queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
-  queue_push(&q, s - pool->solvables); /* push solvable Id */
+  queue_init_buffer(&workq, workqbuf, sizeof(workqbuf)/sizeof(*workqbuf));
+  queue_push(&workq, s - pool->solvables);     /* push solvable Id to work queue */
 
-  while (q.count)
+  /* loop until there's no more work left */
+  while (workq.count)
     {
       /*
        * n: Id of solvable
        * s: Pointer to solvable
        */
 
-      n = queue_shift(&q);
-      if (MAPTST(m, n))                       /* continue if already done */
+      n = queue_shift(&workq);             /* 'pop' next solvable to work on from queue */
+      if (MAPTST(m, n))                           /* continue if already visited */
        continue;
 
-      MAPSET(m, n);
-      s = pool->solvables + n;        /* s = Solvable in question */
+      MAPSET(m, n);                        /* mark as visited */
+      s = pool->solvables + n;            /* s = Solvable in question */
 
       dontfix = 0;
-      if (installed                    /* Installed system available */
-         && !solv->fixsystem           /* NOT repair errors in rpm dependency graph */
-         && s->repo == installed)      /* solvable is installed? */
+      if (installed                       /* Installed system available */
+         && !solv->fixsystem              /* NOT repair errors in rpm dependency graph */
+         && s->repo == installed)         /* solvable is installed? */
       {
-       dontfix = 1;                   /* dont care about broken rpm deps */
+       dontfix = 1;                       /* dont care about broken rpm deps */
       }
 
-      if (!dontfix && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC && !pool_installable(pool, s))
+      if (!dontfix
+         && s->arch != ARCH_SRC
+         && s->arch != ARCH_NOSRC
+         && !pool_installable(pool, s))
        {
          POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", solvable2str(pool, s), (Id)(s - pool->solvables));
-         addrule(solv, -n, 0);         /* uninstallable */
-       }
-
-      patchatom = 0;
-      if (s->freshens && !s->supplements)
-       {
-         const char *name = id2str(pool, s->name);
-         if (name[0] == 'a' && !strncmp(name, "atom:", 5))
-           patchatom = 1;
+         addrule(solv, -n, 0);            /* uninstallable */
        }
 
       /*-----------------------------------------
@@ -1107,20 +1160,21 @@ addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
       if (s->requires)
        {
          reqp = s->repo->idarraydata + s->requires;
-         while ((req = *reqp++) != 0) /* go throw all requires */
+         while ((req = *reqp++) != 0)            /* go through all requires */
            {
              if (req == SOLVABLE_PREREQMARKER)   /* skip the marker */
                continue;
 
+             /* find list of solvables providing 'req' */
              dp = pool_whatprovides(pool, req);
 
-             if (*dp == SYSTEMSOLVABLE)        /* always installed */
+             if (*dp == SYSTEMSOLVABLE)          /* always installed */
                continue;
 
-#if 0
+#if CODE10
              if (patchatom)
                {
-                 addpatchatomrequires(solv, s, dp, &q, m);
+                 addpatchatomrequires(solv, s, dp, &workq, m);
                  continue;
                }
 #endif
@@ -1130,12 +1184,15 @@ addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
                    * that are already broken. so if we find one provider
                    * that was already installed, we know that the
                    * dependency was not broken before so we enforce it */
-                 for (i = 0; (p = dp[i]) != 0; i++)    /* for all providers */
+                
+                 /* check if any of the providers for 'req' is installed */
+                 for (i = 0; (p = dp[i]) != 0; i++)
                    {
                      if (pool->solvables[p].repo == installed)
                        break;          /* provider was installed */
                    }
-                 if (!p)               /* previously broken dependency */
+                 /* didn't find an installed provider: previously broken dependency */
+                 if (!p)
                    {
                      POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", dep2str(pool, req), solvable2str(pool, s));
                      continue;
@@ -1161,11 +1218,12 @@ addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
               /* rule: (-requestor|provider1|provider2|...|providerN) */
              addrule(solv, -n, dp - pool->whatprovidesdata);
 
-             /* descend the dependency tree */
-             for (; *dp; dp++)   /* loop through all providers */
+             /* descend the dependency tree
+                push all non-visited providers on the work queue */
+             for (; *dp; dp++)
                {
                  if (!MAPTST(m, *dp))
-                   queue_push(&q, *dp);
+                   queue_push(&workq, *dp);
                }
 
            } /* while, requirements of n */
@@ -1183,13 +1241,18 @@ addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
       if (s->conflicts)
        {
          conp = s->repo->idarraydata + s->conflicts;
+         /* foreach conflicts of 's' */
          while ((con = *conp++) != 0)
            {
+             /* foreach providers of a conflict of 's' */
              FOR_PROVIDES(p, pp, con)
                {
-                  /* dontfix: dont care about conflicts with already installed packs */
+                 /* dontfix: dont care about conflicts with already installed packs */
                  if (dontfix && pool->solvables[p].repo == installed)
                    continue;
+                 /* p == n: self conflict */
+                 if (p == n && !solv->allowselfconflicts)
+                   p = 0;      /* make it a negative assertion, aka 'uninstallable' */
                  /* rule: -n|-p: either solvable _or_ provider of conflict */
                  addrule(solv, -n, -p);
                }
@@ -1198,27 +1261,42 @@ addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
 
       /*-----------------------------------------
        * check obsoletes if not installed
+       * (only installation will trigger the obsoletes in rpm)
        */
       if (!installed || pool->solvables[n].repo != installed)
        {                              /* not installed */
-         if (s->obsoletes)
+         int noobs = solv->noobsoletes.size && MAPTST(&solv->noobsoletes, n);
+         if (s->obsoletes && !noobs)
            {
              obsp = s->repo->idarraydata + s->obsoletes;
+             /* foreach obsoletes */
              while ((obs = *obsp++) != 0)
                {
+                 /* foreach provider of an obsoletes of 's' */ 
                  FOR_PROVIDES(p, pp, obs)
-                   addrule(solv, -n, -p);
+                   {
+                     if (!solv->obsoleteusesprovides /* obsoletes are matched names, not provides */
+                         && !pool_match_nevr(pool, pool->solvables + p, obs))
+                       continue;
+                     addrule(solv, -n, -p);
+                   }
                }
            }
          FOR_PROVIDES(p, pp, s->name)
            {
-             if (s->name == pool->solvables[p].name)
-               addrule(solv, -n, -p);
+             Solvable *ps = pool->solvables + p;
+             /* we still obsolete packages with same nevra, like rpm does */
+             /* (actually, rpm mixes those packages. yuck...) */
+             if (noobs && (s->name != ps->name || s->evr != ps->evr || s->arch != ps->arch))
+               continue;
+             if (!solv->implicitobsoleteusesprovides && s->name != ps->name)
+               continue;
+             addrule(solv, -n, -p);
            }
        }
 
       /*-----------------------------------------
-       * add recommends to the rule list
+       * add recommends to the work queue
        */
       if (s->recommends)
        {
@@ -1227,7 +1305,7 @@ addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
            {
              FOR_PROVIDES(p, pp, rec)
                if (!MAPTST(m, p))
-                 queue_push(&q, p);
+                 queue_push(&workq, p);
            }
        }
       if (s->suggests)
@@ -1237,14 +1315,22 @@ addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
            {
              FOR_PROVIDES(p, pp, sug)
                if (!MAPTST(m, p))
-                 queue_push(&q, p);
+                 queue_push(&workq, p);
            }
        }
     }
-  queue_free(&q);
+  queue_free(&workq);
   POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable end -----\n");
 }
 
+
+/*-------------------------------------------------------------------
+ * 
+ * Add package rules for weak rules
+ *
+ * m: visited solvables
+ */
+
 static void
 addrpmrulesforweak(Solver *solv, Map *m)
 {
@@ -1254,30 +1340,29 @@ addrpmrulesforweak(Solver *solv, Map *m)
   int i, n;
 
   POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak -----\n");
+    /* foreach solvable in pool */
   for (i = n = 1; n < pool->nsolvables; i++, n++)
     {
-      if (i == pool->nsolvables)
+      if (i == pool->nsolvables)                 /* wrap i */
        i = 1;
-      if (MAPTST(m, i))
+      if (MAPTST(m, i))                          /* been there */
        continue;
+
       s = pool->solvables + i;
-      if (!pool_installable(pool, s))
+      if (!pool_installable(pool, s))            /* only look at installable ones */
        continue;
+
       sup = 0;
       if (s->supplements)
        {
+         /* find possible supplements */
          supp = s->repo->idarraydata + s->supplements;
          while ((sup = *supp++) != ID_NULL)
            if (dep_possible(solv, sup, m))
              break;
        }
-      if (!sup && s->freshens)
-       {
-         supp = s->repo->idarraydata + s->freshens;
-         while ((sup = *supp++) != ID_NULL)
-           if (dep_possible(solv, sup, m))
-             break;
-       }
+
+       /* if nothing found, check for enhances */
       if (!sup && s->enhances)
        {
          supp = s->repo->idarraydata + s->enhances;
@@ -1285,6 +1370,7 @@ addrpmrulesforweak(Solver *solv, Map *m)
            if (dep_possible(solv, sup, m))
              break;
        }
+       /* if nothing found, goto next solvables */
       if (!sup)
        continue;
       addrpmrulesforsolvable(solv, s, m);
@@ -1293,20 +1379,34 @@ addrpmrulesforweak(Solver *solv, Map *m)
   POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak end -----\n");
 }
 
+
+/*-------------------------------------------------------------------
+ * 
+ * add package rules for possible updates
+ * 
+ * s: solvable
+ * m: map of already visited solvables
+ * allow_all: 0 = dont allow downgrades, 1 = allow all candidates
+ */
+
 static void
-addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allowall)
+addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allow_all)
 {
   Pool *pool = solv->pool;
   int i;
+    /* queue and buffer for it */
   Queue qs;
   Id qsbuf[64];
 
   POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
 
   queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
-  policy_findupdatepackages(solv, s, &qs, allowall);
-  if (!MAPTST(m, s - pool->solvables)) /* add rule for s if not already done */
+    /* find update candidates for 's' */
+  policy_findupdatepackages(solv, s, &qs, allow_all);
+    /* add rule for 's' if not already done */
+  if (!MAPTST(m, s - pool->solvables))
     addrpmrulesforsolvable(solv, s, m);
+    /* foreach update candidate, add rule if not already done */
   for (i = 0; i < qs.count; i++)
     if (!MAPTST(m, qs.elements[i]))
       addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
@@ -1315,7 +1415,9 @@ addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allowall)
   POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
 }
 
-/*
+
+/*-------------------------------------------------------------------
+ * 
  * add rule for update
  *   (A|A1|A2|A3...)  An = update candidates for A
  *
@@ -1323,7 +1425,7 @@ addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allowall)
  */
 
 static void
-addupdaterule(Solver *solv, Solvable *s, int allowall)
+addupdaterule(Solver *solv, Solvable *s, int allow_all)
 {
   /* installed packages get a special upgrade allowed rule */
   Pool *pool = solv->pool;
@@ -1334,9 +1436,10 @@ addupdaterule(Solver *solv, Solvable *s, int allowall)
   POOL_DEBUG(SAT_DEBUG_SCHUBI, "-----  addupdaterule -----\n");
 
   queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
-  policy_findupdatepackages(solv, s, &qs, allowall);
+    /* find update candidates for 's' */
+  policy_findupdatepackages(solv, s, &qs, allow_all);
   if (qs.count == 0)                  /* no updaters found */
-    d = 0;
+    d = 0;  /* assertion (keep installed) */
   else
     d = pool_queuetowhatprovides(pool, &qs);   /* intern computed queue */
   queue_free(&qs);
@@ -1345,26 +1448,11 @@ addupdaterule(Solver *solv, Solvable *s, int allowall)
 }
 
 
-/*-----------------------------------------------------------------*/
+/********************************************************************/
 /* watches */
 
-/*
- * print watches
- *
- */
-
-static void
-printWatches(Solver *solv, int type)
-{
-  Pool *pool = solv->pool;
-  int counter;
-
-  POOL_DEBUG(type, "Watches: \n");
-  for (counter = -(pool->nsolvables - 1); counter < pool->nsolvables; counter++)
-    POOL_DEBUG(type, "    solvable [%d] -- rule [%d]\n", counter, solv->watches[counter + pool->nsolvables]);
-}
 
-/*
+/*-------------------------------------------------------------------
  * makewatches
  *
  * initial setup for all watches
@@ -1387,11 +1475,10 @@ makewatches(Solver *solv)
   for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
 #endif
     {
-      if (!r->w1                      /* rule is disabled */
-         || !r->w2)                   /* rule is assertion */
+      if (!r->w2)              /* assertions do not need watches */
        continue;
 
-      /* see addwatches(solv, r) */
+      /* see addwatches_rule(solv, r) */
       r->n1 = solv->watches[nsolvables + r->w1];
       solv->watches[nsolvables + r->w1] = r - solv->rules;
 
@@ -1401,12 +1488,16 @@ makewatches(Solver *solv)
 }
 
 
-/*
+/*-------------------------------------------------------------------
+ *
  * add watches (for rule)
+ * sets up watches for a single rule
+ * 
+ * see also makewatches()
  */
 
-static void
-addwatches(Solver *solv, Rule *r)
+static inline void
+addwatches_rule(Solver *solv, Rule *r)
 {
   int nsolvables = solv->pool->nsolvables;
 
@@ -1418,83 +1509,147 @@ addwatches(Solver *solv, Rule *r)
 }
 
 
-/*-----------------------------------------------------------------*/
-/* rule propagation */
+/********************************************************************/
+/*
+ * rule propagation
+ */
+
 
+/* shortcuts to check if a literal (positive or negative) assignment
+ * evaluates to 'true' or 'false'
+ */
 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
 #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
+#define DECISIONMAP_UNDEF(p) (decisionmap[(p) > 0 ? (p) : -(p)] == 0)
 
-/*
+/*-------------------------------------------------------------------
+ * 
  * propagate
  *
- * propagate decision to all rules
+ * make decision and propagate to all rules
+ * 
+ * Evaluate each term affected by the decision (linked through watches)
+ * If we find unit rules we make new decisions based on them
+ * 
+ * Everything's fixed there, it's just finding rules that are
+ * unit.
+ * 
  * return : 0 = everything is OK
- *          watched rule = there is a conflict
+ *          rule = conflict found in this rule
  */
 
 static Rule *
 propagate(Solver *solv, int level)
 {
   Pool *pool = solv->pool;
-  Id *rp, *nrp;
-  Rule *r;
-  Id p, pkg, ow;
+  Id *rp, *next_rp;           /* rule pointer, next rule pointer in linked list */
+  Rule *r;                    /* rule */
+  Id p, pkg, other_watch;
   Id *dp;
   Id *decisionmap = solv->decisionmap;
-  Id *watches = solv->watches + pool->nsolvables;
+    
+  Id *watches = solv->watches + pool->nsolvables;   /* place ptr in middle */
 
   POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate -----\n");
 
+  /* foreach non-propagated decision */
   while (solv->propagate_index < solv->decisionq.count)
     {
-      /* negate because our watches trigger if literal goes FALSE */
+       /*
+        * 'pkg' was just decided
+        * negate because our watches trigger if literal goes FALSE
+        */
       pkg = -solv->decisionq.elements[solv->propagate_index++];
+       
       IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
         {
          POOL_DEBUG(SAT_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
-         printruleelement(solv, SAT_DEBUG_PROPAGATE, 0, -pkg);
-         if (0)
-             printWatches(solv, SAT_DEBUG_SCHUBI);
+         solver_printruleelement(solv, SAT_DEBUG_PROPAGATE, 0, -pkg);
         }
 
-      for (rp = watches + pkg; *rp; rp = nrp)
+      /* foreach rule where 'pkg' is now FALSE */
+      for (rp = watches + pkg; *rp; rp = next_rp)
        {
          r = solv->rules + *rp;
+         if (r->d < 0)
+           {
+             /* rule is disabled, goto next */
+             if (pkg == r->w1)
+               next_rp = &r->n1;
+             else
+               next_rp = &r->n2;
+             continue;
+           }
 
          IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
            {
              POOL_DEBUG(SAT_DEBUG_PROPAGATE,"  watch triggered ");
-             printrule(solv, SAT_DEBUG_PROPAGATE, r);
+             solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
            }
 
+           /* 'pkg' was just decided (was set to FALSE)
+            * 
+            *  now find other literal watch, check clause
+            *   and advance on linked list
+            */
          if (pkg == r->w1)
            {
-             ow = r->w2; /* regard the second watchpoint to come to a solution */
-             nrp = &r->n1;
+             other_watch = r->w2;
+             next_rp = &r->n1;
            }
          else
            {
-             ow = r->w1; /* regard the first watchpoint to come to a solution */
-             nrp = &r->n2;
+             other_watch = r->w1;
+             next_rp = &r->n2;
            }
-         /* if clause is TRUE, nothing to do */
-         if (DECISIONMAP_TRUE(ow))
+           
+           /* 
+            * This term is already true (through the other literal)
+            * so we have nothing to do
+            */
+         if (DECISIONMAP_TRUE(other_watch))
            continue;
 
+           /*
+            * The other literal is FALSE or UNDEF
+            * 
+            */
+           
           if (r->d)
            {
-             /* not a binary clause, check if we need to move our watch */
-             /* search for a literal that is not ow and not false */
-             /* (true is also ok, in that case the rule is fulfilled) */
-             if (r->p && r->p != ow && !DECISIONMAP_TRUE(-r->p))
-               p = r->p;
-             else
-               for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
-                 if (p != ow && !DECISIONMAP_TRUE(-p))
-                   break;
+             /* Not a binary clause, try to move our watch.
+              * 
+              * Go over all literals and find one that is
+              *   not other_watch
+              *   and not FALSE
+              * 
+              * (TRUE is also ok, in that case the rule is fulfilled)
+              */
+             if (r->p                                /* we have a 'p' */
+                 && r->p != other_watch              /* which is not watched */
+                 && !DECISIONMAP_FALSE(r->p))        /* and not FALSE */
+               {
+                 p = r->p;
+               }
+             else                                    /* go find a 'd' to make 'true' */
+               {
+                 /* foreach p in 'd'
+                    we just iterate sequentially, doing it in another order just changes the order of decisions, not the decisions itself
+                  */
+                 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
+                   {
+                     if (p != other_watch              /* which is not watched */
+                         && !DECISIONMAP_FALSE(p))     /* and not FALSE */
+                       break;
+                   }
+               }
+
              if (p)
                {
-                 /* p is free to watch, move watch to p */
+                 /*
+                  * if we found some p that is UNDEF or TRUE, move
+                  * watch to it
+                  */
                  IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
                    {
                      if (p > 0)
@@ -1502,8 +1657,10 @@ propagate(Solver *solv, int level)
                      else
                        POOL_DEBUG(SAT_DEBUG_PROPAGATE,"    -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), solvable2str(pool, pool->solvables - p));
                    }
-                 *rp = *nrp;
-                 nrp = rp;
+                   
+                 *rp = *next_rp;
+                 next_rp = rp;
+                   
                  if (pkg == r->w1)
                    {
                      r->w1 = p;
@@ -1517,41 +1674,55 @@ propagate(Solver *solv, int level)
                  watches[p] = r - solv->rules;
                  continue;
                }
-           }
-          /* unit clause found, set other watch to TRUE */
-         if (DECISIONMAP_TRUE(-ow))
-           return r;           /* eek, a conflict! */
+             /* search failed, thus all unwatched literals are FALSE */
+               
+           } /* not binary */
+           
+            /*
+            * unit clause found, set literal other_watch to TRUE
+            */
+
+         if (DECISIONMAP_FALSE(other_watch))      /* check if literal is FALSE */
+           return r;                              /* eek, a conflict! */
+           
          IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
            {
              POOL_DEBUG(SAT_DEBUG_PROPAGATE, "   unit ");
-             printrule(solv, SAT_DEBUG_PROPAGATE, r);
+             solver_printrule(solv, SAT_DEBUG_PROPAGATE, r);
            }
-         if (ow > 0)
-            decisionmap[ow] = level;
+
+         if (other_watch > 0)
+            decisionmap[other_watch] = level;    /* install! */
          else
-            decisionmap[-ow] = -level;
-         queue_push(&solv->decisionq, ow);
+           decisionmap[-other_watch] = -level;  /* remove! */
+           
+         queue_push(&solv->decisionq, other_watch);
          queue_push(&solv->decisionq_why, r - solv->rules);
+
          IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
            {
-             Solvable *s = pool->solvables + (ow > 0 ? ow : -ow);
-             if (ow > 0)
+             Solvable *s = pool->solvables + (other_watch > 0 ? other_watch : -other_watch);
+             if (other_watch > 0)
                POOL_DEBUG(SAT_DEBUG_PROPAGATE, "    -> decided to install %s\n", solvable2str(pool, s));
              else
                POOL_DEBUG(SAT_DEBUG_PROPAGATE, "    -> decided to conflict %s\n", solvable2str(pool, s));
            }
-       }
-    }
+           
+       } /* foreach rule involving 'pkg' */
+       
+    } /* while we have non-decided decisions */
+    
   POOL_DEBUG(SAT_DEBUG_PROPAGATE, "----- propagate end-----\n");
 
   return 0;    /* all is well */
 }
 
 
-/*-----------------------------------------------------------------*/
+/********************************************************************/
 /* Analysis */
 
-/*
+/*-------------------------------------------------------------------
+ * 
  * analyze
  *   and learn
  */
@@ -1563,7 +1734,7 @@ analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
   Queue r;
   int rlevel = 1;
   Map seen;            /* global? */
-  Id v, vv, *dp, why;
+  Id d, v, vv, *dp, why;
   int l, i, idx;
   int num = 0, l1num = 0;
   int learnt_why = solv->learnt_pool.count;
@@ -1577,15 +1748,16 @@ analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
   for (;;)
     {
       IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
-       printruleclass(solv, SAT_DEBUG_ANALYZE, c);
+       solver_printruleclass(solv, SAT_DEBUG_ANALYZE, c);
       queue_push(&solv->learnt_pool, c - solv->rules);
-      dp = c->d ? pool->whatprovidesdata + c->d : 0;
+      d = c->d < 0 ? -c->d - 1 : c->d;
+      dp = d ? pool->whatprovidesdata + d : 0;
       /* go through all literals of the rule */
       for (i = -1; ; i++)
        {
          if (i == -1)
            v = c->p;
-         else if (c->d == 0)
+         else if (d == 0)
            v = i ? 0 : c->w2;
          else
            v = *dp++;
@@ -1600,84 +1772,49 @@ analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
          l = solv->decisionmap[vv];
          if (l < 0)
            l = -l;
-         if (l == 1)
-           {
-             /* a level 1 literal, mark it for later */
-             MAPSET(&seen, vv);        /* mark for scanning in level 1 phase */
-             l1num++;
-             continue;
-           }
          MAPSET(&seen, vv);
-         if (l == level)
+         if (l == 1)
+           l1num++;                    /* need to do this one in level1 pass */
+         else if (l == level)
            num++;                      /* need to do this one as well */
          else
            {
-             queue_push(&r, v);
+             queue_push(&r, v);        /* not level1 or conflict level, add to new rule */
              if (l > rlevel)
                rlevel = l;
            }
        }
-      assert(num > 0);
+l1retry:
+      if (!num && !--l1num)
+       break;  /* all level 1 literals done */
       for (;;)
        {
+         assert(idx > 0);
          v = solv->decisionq.elements[--idx];
          vv = v > 0 ? v : -v;
          if (MAPTST(&seen, vv))
            break;
        }
-      c = solv->rules + solv->decisionq_why.elements[idx];
       MAPCLR(&seen, vv);
-      if (--num == 0)
-       break;
-    }
-  *pr = -v;    /* so that v doesn't get lost */
-
-  /* add involved level 1 rules */
-  if (l1num)
-    {
-      POOL_DEBUG(SAT_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
-      idx++;
-      while (idx)
+      if (num && --num == 0)
        {
-         v = solv->decisionq.elements[--idx];
-         vv = v > 0 ? v : -v;
-         if (!MAPTST(&seen, vv))
-           continue;
-         why = solv->decisionq_why.elements[idx];
-         if (!why)
+         *pr = -v;     /* so that v doesn't get lost */
+         if (!l1num)
+           break;
+         POOL_DEBUG(SAT_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
+         for (i = 0; i < r.count; i++)
            {
-             queue_push(&solv->learnt_pool, -vv);
-             IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
-               {
-                 POOL_DEBUG(SAT_DEBUG_ANALYZE, "RPM ASSERT Rule:\n");
-                 printruleelement(solv, SAT_DEBUG_ANALYZE, 0, v);
-               }
-             continue;
-           }
-         queue_push(&solv->learnt_pool, why);
-         c = solv->rules + why;
-         dp = c->d ? pool->whatprovidesdata + c->d : 0;
-         IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
-           printruleclass(solv, SAT_DEBUG_ANALYZE, c);
-         for (i = -1; ; i++)
-           {
-             if (i == -1)
-               v = c->p;
-             else if (c->d == 0)
-               v = i ? 0 : c->w2;
-             else
-               v = *dp++;
-             if (v == 0)
-               break;
-             if (DECISIONMAP_TRUE(v))  /* the one true literal */
-               continue;
-             vv = v > 0 ? v : -v;
-             l = solv->decisionmap[vv];
-             if (l != 1 && l != -1)
-               continue;
-             MAPSET(&seen, vv);
+             v = r.elements[i];
+             MAPCLR(&seen, v > 0 ? v : -v);
            }
+         /* only level 1 marks left */
+         l1num++;
+         goto l1retry;
        }
+      why = solv->decisionq_why.elements[idx];
+      if (!why)                        /* just in case, maye for SYSTEMSOLVABLE */
+       goto l1retry;
+      c = solv->rules + why;
     }
   map_free(&seen);
 
@@ -1690,20 +1827,23 @@ analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
   IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
     {
       POOL_DEBUG(SAT_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
-      printruleelement(solv, SAT_DEBUG_ANALYZE, 0, *pr);
+      solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, *pr);
       for (i = 0; i < r.count; i++)
-        printruleelement(solv, SAT_DEBUG_ANALYZE, 0, r.elements[i]);
+        solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, r.elements[i]);
     }
   /* push end marker on learnt reasons stack */
   queue_push(&solv->learnt_pool, 0);
   if (whyp)
     *whyp = learnt_why;
+  solv->stats_learned++;
   return rlevel;
 }
 
 
-/*
+/*-------------------------------------------------------------------
+ * 
  * reset_solver
+ * 
  * reset the solver decisions to right after the rpm rules.
  * called after rules have been enabled/disabled
  */
@@ -1732,16 +1872,14 @@ reset_solver(Solver *solv)
   /* adapt learnt rule status to new set of enabled/disabled rules */
   enabledisablelearntrules(solv);
 
-  /* redo all job/system decisions */
+  /* redo all job/update decisions */
   makeruledecisions(solv);
   POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
-
-  /* recreate watch chains */
-  makewatches(solv);
 }
 
 
-/*
+/*-------------------------------------------------------------------
+ * 
  * analyze_unsolvable_rule
  */
 
@@ -1753,7 +1891,7 @@ analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp)
   Id why = r - solv->rules;
 
   IF_POOLDEBUG (SAT_DEBUG_UNSOLVABLE)
-    printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
+    solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
   if (solv->learntrules && why >= solv->learntrules)
     {
       for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
@@ -1765,10 +1903,10 @@ analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp)
     if (!*lastweakp || why > *lastweakp)
       *lastweakp = why;
   /* do not add rpm rules to problem */
-  if (why < solv->jobrules)
+  if (why < solv->rpmrules_end)
     return;
   /* turn rule into problem */
-  if (why >= solv->jobrules && why < solv->systemrules)
+  if (why >= solv->jobrules && why < solv->jobrules_end)
     why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
   /* return if problem already countains our rule */
   if (solv->problems.count)
@@ -1783,7 +1921,8 @@ analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp)
 }
 
 
-/*
+/*-------------------------------------------------------------------
+ * 
  * analyze_unsolvable
  *
  * return: 1 - disabled some rules, try again
@@ -1796,7 +1935,7 @@ analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
   Pool *pool = solv->pool;
   Rule *r;
   Map seen;            /* global to speed things up? */
-  Id v, vv, *dp, why;
+  Id d, v, vv, *dp, why;
   int l, i, idx;
   Id *decisionmap = solv->decisionmap;
   int oldproblemcount;
@@ -1804,6 +1943,7 @@ analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
   Id lastweak;
 
   POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
+  solv->stats_unsolvable++;
   oldproblemcount = solv->problems.count;
   oldlearntpoolcount = solv->learnt_pool.count;
 
@@ -1817,12 +1957,13 @@ analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
   queue_push(&solv->learnt_pool, r - solv->rules);
   lastweak = 0;
   analyze_unsolvable_rule(solv, r, &lastweak);
-  dp = r->d ? pool->whatprovidesdata + r->d : 0;
+  d = r->d < 0 ? -r->d - 1 : r->d;
+  dp = d ? pool->whatprovidesdata + d : 0;
   for (i = -1; ; i++)
     {
       if (i == -1)
        v = r->p;
-      else if (r->d == 0)
+      else if (d == 0)
        v = i ? 0 : r->w2;
       else
        v = *dp++;
@@ -1847,12 +1988,13 @@ analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
       queue_push(&solv->learnt_pool, why);
       r = solv->rules + why;
       analyze_unsolvable_rule(solv, r, &lastweak);
-      dp = r->d ? pool->whatprovidesdata + r->d : 0;
+      d = r->d < 0 ? -r->d - 1 : r->d;
+      dp = d ? pool->whatprovidesdata + d : 0;
       for (i = -1; ; i++)
        {
          if (i == -1)
            v = r->p;
-         else if (r->d == 0)
+         else if (d == 0)
            v = i ? 0 : r->w2;
          else
            v = *dp++;
@@ -1877,7 +2019,7 @@ analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
       solv->learnt_pool.count = oldlearntpoolcount;
       r = solv->rules + lastweak;
       POOL_DEBUG(SAT_DEBUG_UNSOLVABLE, "disabling ");
-      printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
+      solver_printruleclass(solv, SAT_DEBUG_UNSOLVABLE, r);
       disablerule(solv, r);
       reset_solver(solv);
       return 1;
@@ -1891,6 +2033,7 @@ analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
     {
       for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
         disableproblem(solv, solv->problems.elements[i]);
+      /* XXX: might want to enable all weak rules again */
       reset_solver(solv);
       return 1;
     }
@@ -1899,10 +2042,11 @@ analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
 }
 
 
-/*-----------------------------------------------------------------*/
+/********************************************************************/
 /* Decision revert */
 
-/*
+/*-------------------------------------------------------------------
+ * 
  * revert
  * revert decision at level
  */
@@ -1936,7 +2080,8 @@ revert(Solver *solv, int level)
 }
 
 
-/*
+/*-------------------------------------------------------------------
+ * 
  * watch2onhighest - put watch2 on literal with highest level
  */
 
@@ -1944,11 +2089,12 @@ static inline void
 watch2onhighest(Solver *solv, Rule *r)
 {
   int l, wl = 0;
-  Id v, *dp;
+  Id d, v, *dp;
 
-  if (!r->d)
+  d = r->d < 0 ? -r->d - 1 : r->d;
+  if (!d)
     return;    /* binary rule, both watches are set */
-  dp = solv->pool->whatprovidesdata + r->d;
+  dp = solv->pool->whatprovidesdata + d;
   while ((v = *dp++) != 0)
     {
       l = solv->decisionmap[v < 0 ? -v : v];
@@ -1963,11 +2109,14 @@ watch2onhighest(Solver *solv, Rule *r)
 }
 
 
-/*
+/*-------------------------------------------------------------------
+ * 
  * setpropagatelearn
  *
- * add free decision to decisionq, increase level and
- * propagate decision, return if no conflict.
+ * add free decision (solvable to install) to decisionq
+ * increase level and propagate decision
+ * return if no conflict.
+ *
  * in conflict case, analyze conflict rule, add resulting
  * rule to learnt rule set, make decision from learnt
  * rule (always unit) and re-propagate.
@@ -1981,7 +2130,7 @@ setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
 {
   Pool *pool = solv->pool;
   Rule *r;
-  Id p, d;
+  Id p = 0, d = 0;
   int l, why;
 
   if (decision)
@@ -2015,7 +2164,12 @@ setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
        {
          /* at least 2 literals, needs watches */
          watch2onhighest(solv, r);
-         addwatches(solv, r);
+         addwatches_rule(solv, r);
+       }
+      else
+       {
+         /* learnt rule is an assertion */
+          queue_push(&solv->ruleassertions, r - solv->rules);
        }
       solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
       queue_push(&solv->decisionq, p);
@@ -2023,22 +2177,26 @@ setpropagatelearn(Solver *solv, int level, Id decision, int disablerules)
       IF_POOLDEBUG (SAT_DEBUG_ANALYZE)
        {
          POOL_DEBUG(SAT_DEBUG_ANALYZE, "decision: ");
-         printruleelement(solv, SAT_DEBUG_ANALYZE, 0, p);
+         solver_printruleelement(solv, SAT_DEBUG_ANALYZE, 0, p);
          POOL_DEBUG(SAT_DEBUG_ANALYZE, "new rule: ");
-         printrule(solv, SAT_DEBUG_ANALYZE, r);
+         solver_printrule(solv, SAT_DEBUG_ANALYZE, r);
        }
     }
   return level;
 }
 
 
-/*
+/*-------------------------------------------------------------------
+ * 
+ * select and install
+ * 
  * install best package from the queue. We add an extra package, inst, if
  * provided. See comment in weak install section.
  *
  * returns the new solver level or 0 if unsolvable
  *
  */
+
 static int
 selectandinstall(Solver *solv, int level, Queue *dq, Id inst, int disablerules)
 {
@@ -2072,11 +2230,12 @@ selectandinstall(Solver *solv, int level, Queue *dq, Id inst, int disablerules)
 }
 
 
-/*-----------------------------------------------------------------*/
+/********************************************************************/
 /* Main solver interface */
 
 
-/*
+/*-------------------------------------------------------------------
+ * 
  * solver_create
  * create solver structure
  *
@@ -2107,6 +2266,7 @@ solver_create(Pool *pool, Repo *installed)
   queue_init(&solv->branches);
   queue_init(&solv->covenantq);
   queue_init(&solv->weakruleq);
+  queue_init(&solv->ruleassertions);
 
   map_init(&solv->recommendsmap, pool->nsolvables);
   map_init(&solv->suggestsmap, pool->nsolvables);
@@ -2122,7 +2282,8 @@ solver_create(Pool *pool, Repo *installed)
 }
 
 
-/*
+/*-------------------------------------------------------------------
+ * 
  * solver_free
  */
 
@@ -2140,25 +2301,25 @@ solver_free(Solver *solv)
   queue_free(&solv->branches);
   queue_free(&solv->covenantq);
   queue_free(&solv->weakruleq);
+  queue_free(&solv->ruleassertions);
 
   map_free(&solv->recommendsmap);
   map_free(&solv->suggestsmap);
   map_free(&solv->noupdate);
   map_free(&solv->weakrulemap);
+  map_free(&solv->noobsoletes);
 
   sat_free(solv->decisionmap);
   sat_free(solv->rules);
   sat_free(solv->watches);
-  sat_free(solv->weaksystemrules);
   sat_free(solv->obsoletes);
   sat_free(solv->obsoletes_data);
   sat_free(solv);
 }
 
 
-/*-------------------------------------------------------*/
-
-/*
+/*-------------------------------------------------------------------
+ * 
  * run_solver
  *
  * all rules have been set up, now actually run the solver
@@ -2168,7 +2329,8 @@ solver_free(Solver *solv)
 static void
 run_solver(Solver *solv, int disablerules, int doweak)
 {
-  Queue dq;
+  Queue dq;            /* local decisionqueue */
+  Queue dqs;           /* local decisionqueue for supplements */
   int systemlevel;
   int level, olevel;
   Rule *r;
@@ -2181,13 +2343,13 @@ run_solver(Solver *solv, int disablerules, int doweak)
     {
       POOL_DEBUG (SAT_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
       for (i = 1; i < solv->nrules; i++)
-       printruleclass(solv, SAT_DEBUG_RULE_CREATION, solv->rules + i);
+       solver_printruleclass(solv, SAT_DEBUG_RULE_CREATION, solv->rules + i);
     }
 
   POOL_DEBUG(SAT_DEBUG_STATS, "initial decisions: %d\n", solv->decisionq.count);
 
   IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
-    printdecisions(solv);
+    solver_printdecisions(solv);
 
   /* start SAT algorithm */
   level = 1;
@@ -2195,6 +2357,7 @@ run_solver(Solver *solv, int disablerules, int doweak)
   POOL_DEBUG(SAT_DEBUG_STATS, "solving...\n");
 
   queue_init(&dq);
+  queue_init(&dqs);
 
   /*
    * here's the main loop:
@@ -2225,6 +2388,60 @@ run_solver(Solver *solv, int disablerules, int doweak)
            }
        }
 
+     if (level < systemlevel)
+       {
+         POOL_DEBUG(SAT_DEBUG_STATS, "resolving job rules\n");
+         for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
+           {
+             Id l;
+             if (r->d < 0)             /* ignore disabled rules */
+               continue;
+             queue_empty(&dq);
+             FOR_RULELITERALS(l, dp, r)
+               {
+                 if (l < 0)
+                   {
+                     if (solv->decisionmap[-l] <= 0)
+                       break;
+                   }
+                 else
+                   {
+                     if (solv->decisionmap[l] > 0)
+                       break;
+                     if (solv->decisionmap[l] == 0)
+                       queue_push(&dq, l);
+                   }
+               }
+             if (l || !dq.count)
+               continue;
+             if (!solv->updatesystem && solv->installed && dq.count > 1)
+               {
+                 int j, k;
+                 for (j = k = 0; j < dq.count; j++)
+                   {
+                     Solvable *s = pool->solvables + dq.elements[j];
+                     if (s->repo == solv->installed)
+                       dq.elements[k++] = dq.elements[j];
+                   }
+                 if (k)
+                   dq.count = k;
+               }
+             olevel = level;
+             level = selectandinstall(solv, level, &dq, 0, disablerules);
+             if (level == 0)
+               {
+                 queue_free(&dq);
+                 return;
+               }
+             if (level <= olevel)
+               break;
+           }
+         systemlevel = level + 1;
+         if (i < solv->jobrules_end)
+           continue;
+       }
+
+
       /*
        * installed packages
        */
@@ -2233,19 +2450,30 @@ run_solver(Solver *solv, int disablerules, int doweak)
        {
          if (!solv->updatesystem)
            {
-             /* try to keep as many packages as possible */
-             POOL_DEBUG(SAT_DEBUG_STATS, "installing system packages\n");
+             /*
+              * Normal run (non-updating)
+              * Keep as many packages installed as possible
+              */
+             POOL_DEBUG(SAT_DEBUG_STATS, "installing old packages\n");
+               
              for (i = solv->installed->start; i < solv->installed->end; i++)
                {
                  s = pool->solvables + i;
+                   
+                   /* skip if not installed */
                  if (s->repo != solv->installed)
                    continue;
+                   
+                   /* skip if already decided */
                  if (solv->decisionmap[i] != 0)
                    continue;
+                   
                  POOL_DEBUG(SAT_DEBUG_PROPAGATE, "keeping %s\n", solvable2str(pool, s));
+                   
                  olevel = level;
                  level = setpropagatelearn(solv, level, i, disablerules);
-                 if (level == 0)
+
+                 if (level == 0)                /* unsolvable */
                    {
                      queue_free(&dq);
                      return;
@@ -2256,54 +2484,79 @@ run_solver(Solver *solv, int disablerules, int doweak)
              if (i < solv->installed->end)
                continue;
            }
-         if (solv->weaksystemrules)
+           
+         POOL_DEBUG(SAT_DEBUG_STATS, "resolving update/feature rules\n");
+           
+         for (i = solv->installed->start, r = solv->rules + solv->updaterules; i < solv->installed->end; i++, r++)
            {
-             POOL_DEBUG(SAT_DEBUG_STATS, "installing weak system packages\n");
-             for (i = solv->installed->start; i < solv->installed->end; i++)
+             Rule *rr;
+             Id d;
+             s = pool->solvables + i;
+               
+               /* skip if not installed (can't update) */
+             if (s->repo != solv->installed)
+               continue;
+               /* skip if already decided */
+             if (solv->decisionmap[i] > 0)
+               continue;
+               
+               /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
+             if (MAPTST(&solv->noupdate, i - solv->installed->start))
+               continue;
+               
+             queue_empty(&dq);
+             rr = r;
+             if (rr->d < 0)    /* disabled -> look at feature rule ? */
+               rr -= solv->installed->end - solv->installed->start;
+             if (!rr->p)       /* identical to update rule? */
+               rr = r;
+             d = (rr->d < 0) ? -rr->d - 1 : rr->d;
+             if (d == 0)
                {
-                 s = pool->solvables + i;
-                 if (s->repo != solv->installed)
-                   continue;
-                 if (solv->decisionmap[i] > 0 || (solv->decisionmap[i] < 0 && solv->weaksystemrules[i - solv->installed->start] == 0))
+                 if (!rr->w2 || solv->decisionmap[rr->w2] > 0)
                    continue;
-                 /* noupdate is set if a job is erasing the installed solvable or installing a specific version */
-                 if (MAPTST(&solv->noupdate, i - solv->installed->start))
-                   continue;
-                 queue_empty(&dq);
-                 if (solv->weaksystemrules[i - solv->installed->start])
+                   /* decide w2 if yet undecided */
+                 if (solv->decisionmap[rr->w2] == 0)
+                   queue_push(&dq, rr->w2);
+               }
+             else
+               {
+                 dp = pool->whatprovidesdata + d;
+                 while ((p = *dp++) != 0)
                    {
-                     dp = pool->whatprovidesdata + solv->weaksystemrules[i - solv->installed->start];
-                     while ((p = *dp++) != 0)
-                       {
-                         if (solv->decisionmap[p] > 0)
-                           break;
-                         if (solv->decisionmap[p] == 0)
-                           queue_push(&dq, p);
-                       }
-                     if (p)
-                       continue;       /* update package already installed */
+                     if (solv->decisionmap[p] > 0)
+                       break;
+                       /* decide p if yet undecided */
+                     if (solv->decisionmap[p] == 0)
+                       queue_push(&dq, p);
                    }
-                 if (!dq.count && solv->decisionmap[i] != 0)
+                 if (p)
                    continue;
-                 olevel = level;
-                 /* FIXME: i is handled a bit different because we do not want
-                  * to have it pruned just because it is not recommened.
-                  * we should not prune installed packages instead */
-                 level = selectandinstall(solv, level, &dq, (solv->decisionmap[i] ? 0 : i), disablerules);
-                 if (level == 0)
-                   {
-                     queue_free(&dq);
-                     return;
-                   }
-                 if (level <= olevel)
-                   break;
                }
-             if (i < solv->installed->end)
+             if (!dq.count && solv->decisionmap[i] != 0)
                continue;
+             olevel = level;
+             /* FIXME: it is handled a bit different because we do not want
+              * to have it pruned just because it is not recommened.
+              * we should not prune installed packages instead
+              */
+             level = selectandinstall(solv, level, &dq, (solv->decisionmap[i] ? 0 : i), disablerules);
+             if (level == 0)
+               {
+                 queue_free(&dq);
+                 return;
+               }
+             if (level <= olevel)
+               break;
            }
-         systemlevel = level;
+         systemlevel = level + 1;
+         if (i < solv->installed->end)
+           continue;
        }
 
+      if (level < systemlevel)
+        systemlevel = level;
+
       /*
        * decide
        */
@@ -2316,7 +2569,7 @@ run_solver(Solver *solv, int disablerules, int doweak)
          if (i == solv->nrules)
            i = 1;
          r = solv->rules + i;
-         if (!r->w1)   /* ignore disabled rules */
+         if (r->d < 0)         /* ignore disabled rules */
            continue;
          queue_empty(&dq);
          if (r->d == 0)
@@ -2372,7 +2625,7 @@ run_solver(Solver *solv, int disablerules, int doweak)
          IF_POOLDEBUG (SAT_DEBUG_PROPAGATE)
            {
              POOL_DEBUG(SAT_DEBUG_PROPAGATE, "unfulfilled ");
-             printruleclass(solv, SAT_DEBUG_PROPAGATE, r);
+             solver_printruleclass(solv, SAT_DEBUG_PROPAGATE, r);
            }
          /* dq.count < 2 cannot happen as this means that
           * the rule is unit */
@@ -2399,15 +2652,18 @@ run_solver(Solver *solv, int disablerules, int doweak)
 
          POOL_DEBUG(SAT_DEBUG_STATS, "installing recommended packages\n");
          queue_empty(&dq);
+         queue_empty(&dqs);
          for (i = 1; i < pool->nsolvables; i++)
            {
              if (solv->decisionmap[i] < 0)
                continue;
              if (solv->decisionmap[i] > 0)
                {
+                 /* installed, check for recommends */
                  Id *recp, rec, *pp, p;
                  s = pool->solvables + i;
-                 /* installed, check for recommends */
+                 if (solv->ignorealreadyrecommended && s->repo == solv->installed)
+                   continue;
                  /* XXX need to special case AND ? */
                  if (s->recommends)
                    {
@@ -2433,14 +2689,51 @@ run_solver(Solver *solv, int disablerules, int doweak)
              else
                {
                  s = pool->solvables + i;
-                 if (!s->supplements && !s->freshens)
+                 if (!s->supplements)
                    continue;
                  if (!pool_installable(pool, s))
                    continue;
-                 if (solver_is_supplementing(solv, s))
+                 if (!solver_is_supplementing(solv, s))
+                   continue;
+                 if (solv->ignorealreadyrecommended && solv->installed)
+                   queue_pushunique(&dqs, i);  /* needs filter */
+                 else
                    queue_pushunique(&dq, i);
                }
            }
+          if (solv->ignorealreadyrecommended && dqs.count)
+           {
+             /* turn off all new packages */
+             for (i = 0; i < solv->decisionq.count; i++)
+               {
+                 p = solv->decisionq.elements[i];
+                 if (p < 0)
+                   continue;
+                 s = pool->solvables + p;
+                 if (s->repo && s->repo != solv->installed)
+                   solv->decisionmap[p] = -solv->decisionmap[p];
+               }
+             /* filter out old supplements */
+             for (i = 0; i < dqs.count; i++)
+               {
+                 p = dqs.elements[i];
+                 s = pool->solvables + p;
+                 if (!s->supplements)
+                   continue;
+                 if (!solver_is_supplementing(solv, s))
+                   queue_pushunique(&dq, p);
+               }
+             /* undo turning off */
+             for (i = 0; i < solv->decisionq.count; i++)
+               {
+                 p = solv->decisionq.elements[i];
+                 if (p < 0)
+                   continue;
+                 s = pool->solvables + p;
+                 if (s->repo && s->repo != solv->installed)
+                   solv->decisionmap[p] = -solv->decisionmap[p];
+               }
+           }
          if (dq.count)
            {
              if (dq.count > 1)
@@ -2524,13 +2817,18 @@ run_solver(Solver *solv, int disablerules, int doweak)
        }
       break;
     }
+  POOL_DEBUG(SAT_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable\n", solv->stats_learned, solv->stats_unsolvable);
+
   POOL_DEBUG(SAT_DEBUG_STATS, "done solving.\n\n");
   queue_free(&dq);
+  queue_free(&dqs);
 }
 
 
-/*
+/*-------------------------------------------------------------------
+ * 
  * refine_suggestion
+ * 
  * at this point, all rules that led to conflicts are disabled.
  * we re-enable all rules of a problem set but rule "sug", then
  * continue to disable more rules until there as again a solution.
@@ -2542,7 +2840,6 @@ static void
 refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
 {
   Pool *pool = solv->pool;
-  Rule *r;
   int i, j;
   Id v;
   Queue disabled;
@@ -2555,14 +2852,14 @@ refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
        {
          if (problem[i] == sug)
            POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "=> ");
-         printproblem(solv, problem[i]);
+         solver_printproblem(solv, problem[i]);
        }
     }
   queue_init(&disabled);
   queue_empty(refined);
   queue_push(refined, sug);
 
-  /* re-enable all problem rules with the exception of "sug"(gests) */
+  /* re-enable all problem rules with the exception of "sug"(gestion) */
   revert(solv, 1);
   reset_solver(solv);
 
@@ -2572,21 +2869,21 @@ refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
 
   if (sug < 0)
     disableupdaterules(solv, job, -(sug + 1));
+  else if (sug >= solv->updaterules && sug < solv->updaterules_end)
+    {
+      /* enable feature rule */
+      Rule *r = solv->rules + solv->featurerules + (sug - solv->updaterules);
+      if (r->p)
+       enablerule(solv, r);
+    }
+
+  enableweakrules(solv);
 
   for (;;)
     {
-      /* re-enable as many weak rules as possible */
-      for (i = solv->jobrules, r = solv->rules + i; i < solv->learntrules; i++, r++)
-       {
-         if (r->w1)
-           continue;
-         if (!MAPTST(&solv->weakrulemap, i))
-           continue;
-         enablerule(solv, r);
-       }
-
+      int njob, nfeature, nupdate;
       queue_empty(&solv->problems);
-      revert(solv, 1);         /* XXX move to reset_solver? */
+      revert(solv, 1);         /* XXX no longer needed? */
       reset_solver(solv);
 
       if (!solv->problems.count)
@@ -2596,11 +2893,12 @@ refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
        {
          POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no more problems!\n");
          IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
-           printdecisions(solv);
+           solver_printdecisions(solv);
          break;                /* great, no more problems */
        }
       disabledcnt = disabled.count;
       /* start with 1 to skip over proof index */
+      njob = nfeature = nupdate = 0;
       for (i = 1; i < solv->problems.count - 1; i++)
        {
          /* ignore solutions in refined */
@@ -2612,6 +2910,12 @@ refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
              break;
          if (problem[j])
            continue;
+         if (v >= solv->featurerules && v < solv->featurerules_end)
+           nfeature++;
+         else if (v > 0)
+           nupdate++;
+         else
+           njob++;
          queue_push(&disabled, v);
        }
       if (disabled.count == disabledcnt)
@@ -2621,27 +2925,58 @@ refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
          refined->count = 0;
          break;
        }
+      if (!njob && nupdate && nfeature)
+       {
+         /* got only update rules, filter out feature rules */
+         POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "throwing away feature rules\n");
+         for (i = j = disabledcnt; i < disabled.count; i++)
+           {
+             v = disabled.elements[i];
+             if (v < solv->featurerules || v >= solv->featurerules_end)
+               disabled.elements[j++] = v;
+           }
+         disabled.count = j;
+         nfeature = 0;
+       }
       if (disabled.count == disabledcnt + 1)
        {
          /* just one suggestion, add it to refined list */
          v = disabled.elements[disabledcnt];
-         queue_push(refined, v);
+         if (!nfeature)
+           queue_push(refined, v);     /* do not record feature rules */
          disableproblem(solv, v);
+         if (v >= solv->updaterules && v < solv->updaterules_end)
+           {
+             Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
+             if (r->p)
+               enablerule(solv, r);    /* enable corresponding feature rule */
+           }
          if (v < 0)
            disableupdaterules(solv, job, -(v + 1));
        }
       else
        {
          /* more than one solution, disable all */
-         /* do not push anything on refine list */
+         /* do not push anything on refine list, as we do not know which solution to choose */
+         /* thus, the user will get another problem if he selects this solution, where he
+           * can choose the right one */
          IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
            {
              POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "more than one solution found:\n");
              for (i = disabledcnt; i < disabled.count; i++)
-               printproblem(solv, disabled.elements[i]);
+               solver_printproblem(solv, disabled.elements[i]);
            }
          for (i = disabledcnt; i < disabled.count; i++)
-           disableproblem(solv, disabled.elements[i]);
+           {
+             v = disabled.elements[i];
+             disableproblem(solv, v);
+             if (v >= solv->updaterules && v < solv->updaterules_end)
+               {
+                 Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
+                 if (r->p)
+                   enablerule(solv, r);
+               }
+           }
        }
     }
   /* all done, get us back into the same state as before */
@@ -2649,12 +2984,63 @@ refine_suggestion(Solver *solv, Queue *job, Id *problem, Id sug, Queue *refined)
   for (i = 0; i < disabled.count; i++)
     enableproblem(solv, disabled.elements[i]);
   /* disable problem rules again */
+
+  /* FIXME! */
   for (i = 0; problem[i]; i++)
-    disableproblem(solv, problem[i]);
+    enableproblem(solv, problem[i]);
   disableupdaterules(solv, job, -1);
+
+  /* disable problem rules again */
+  for (i = 0; problem[i]; i++)
+    disableproblem(solv, problem[i]);
   POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion end\n");
 }
 
+
+/*-------------------------------------------------------------------
+ * sorting helper for problems
+ */
+
+static int
+problems_sortcmp(const void *ap, const void *bp)
+{
+  Id a = *(Id *)ap, b = *(Id *)bp;
+  if (a < 0 && b > 0)
+    return 1;
+  if (a > 0 && b < 0)
+    return -1;
+  return a - b;
+}
+
+
+/*-------------------------------------------------------------------
+ * sort problems
+ */
+
+static void
+problems_sort(Solver *solv)
+{
+  int i, j;
+  if (!solv->problems.count)
+    return;
+  for (i = j = 1; i < solv->problems.count; i++)
+    {
+      if (!solv->problems.elements[i])
+       {
+         if (i > j + 1)
+           qsort(solv->problems.elements + j, i - j, sizeof(Id), problems_sortcmp);
+         if (++i == solv->problems.count)
+           break;
+         j = i + 1;
+       }
+    }
+}
+
+
+/*-------------------------------------------------------------------
+ * convert problems to solutions
+ */
+
 static void
 problems_to_solutions(Solver *solv, Queue *job)
 {
@@ -2664,10 +3050,11 @@ problems_to_solutions(Solver *solv, Queue *job)
   Queue solutions;
   Id *problem;
   Id why;
-  int i, j;
+  int i, j, nsol;
 
   if (!solv->problems.count)
     return;
+  problems_sort(solv);
   queue_clone(&problems, &solv->problems);
   queue_init(&solution);
   queue_init(&solutions);
@@ -2694,13 +3081,14 @@ problems_to_solutions(Solver *solv, Queue *job)
       if (!solution.count)
        continue;       /* this solution didn't work out */
 
+      nsol = 0;
       for (j = 0; j < solution.count; j++)
        {
          why = solution.elements[j];
-         /* must be either job descriptor or system rule */
-         assert(why < 0 || (why >= solv->systemrules && why < solv->learntrules));
+         /* must be either job descriptor or update rule */
+         assert(why < 0 || (why >= solv->updaterules && why < solv->updaterules_end));
 #if 0
-         printproblem(solv, why);
+         solver_printproblem(solv, why);
 #endif
          if (why < 0)
            {
@@ -2710,30 +3098,50 @@ problems_to_solutions(Solver *solv, Queue *job)
            }
          else
            {
-             /* system rule, find replacement package */
-             Id p, rp = 0;
-             p = solv->installed->start + (why - solv->systemrules);
-             if (solv->weaksystemrules && solv->weaksystemrules[why - solv->systemrules])
+             /* update rule, find replacement package */
+             Id p, d, *dp, rp = 0;
+             Rule *rr;
+             p = solv->installed->start + (why - solv->updaterules);
+             if (solv->decisionmap[p] > 0)
+               continue;       /* false alarm, turned out we can keep the package */
+             rr = solv->rules + solv->featurerules + (why - solv->updaterules);
+             if (!rr->p)
+               rr = solv->rules + why;
+             if (rr->w2)
                {
-                 Id *dp = pool->whatprovidesdata + solv->weaksystemrules[why - solv->systemrules];
-                 for (; *dp; dp++)
+                 d = rr->d < 0 ? -rr->d - 1 : rr->d;
+                 if (!d)
                    {
-                     if (*dp >= solv->installed->start && *dp < solv->installed->start + solv->installed->nsolvables)
-                       continue;
-                     if (solv->decisionmap[*dp] > 0)
+                     if (solv->decisionmap[rr->w2] > 0 && pool->solvables[rr->w2].repo != solv->installed)
+                       rp = rr->w2;
+                   }
+                 else
+                   {
+                     for (dp = pool->whatprovidesdata + d; *dp; dp++)
                        {
-                         rp = *dp;
-                         break;
+                         if (solv->decisionmap[*dp] > 0 && pool->solvables[*dp].repo != solv->installed)
+                           {
+                             rp = *dp;
+                             break;
+                           }
                        }
-                   }
+                   }
                }
              queue_push(&solutions, p);
              queue_push(&solutions, rp);
            }
+         nsol++;
        }
       /* mark end of this solution */
-      queue_push(&solutions, 0);
-      queue_push(&solutions, 0);
+      if (nsol)
+       {
+         queue_push(&solutions, 0);
+         queue_push(&solutions, 0);
+       }
+      else
+       {
+         POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "Oops, everything was fine?\n");
+       }
     }
   queue_free(&solution);
   queue_free(&problems);
@@ -2749,6 +3157,14 @@ problems_to_solutions(Solver *solv, Queue *job)
   queue_free(&solutions);
 }
 
+
+/*-------------------------------------------------------------------
+ * 
+ * problem iterator
+ * 
+ * advance to next problem
+ */
+
 Id
 solver_next_problem(Solver *solv, Id problem)
 {
@@ -2771,6 +3187,12 @@ solver_next_problem(Solver *solv, Id problem)
   return problem + 1;
 }
 
+
+/*-------------------------------------------------------------------
+ * 
+ * solution iterator
+ */
+
 Id
 solver_next_solution(Solver *solv, Id problem, Id solution)
 {
@@ -2789,6 +3211,12 @@ solver_next_solution(Solver *solv, Id problem, Id solution)
   return pp[0] || pp[1] ? solution : 0;
 }
 
+
+/*-------------------------------------------------------------------
+ * 
+ * solution element iterator
+ */
+
 Id
 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
 {
@@ -2803,207 +3231,49 @@ solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, I
 }
 
 
-/*
- * create obsoletesmap from solver decisions
- * required for decision handling
+/*-------------------------------------------------------------------
+ * 
+ * Retrieve information about a problematic rule
  *
- * for solvables in installed repo:
- *   0 - not obsoleted
- *   p - one of the packages that obsolete us
- * for all others:
- *   n - number of packages this package obsoletes
+ * this is basically the reverse of addrpmrulesforsolvable
  */
 
-Id *
-create_decisions_obsoletesmap(Solver *solv)
+SolverProbleminfo
+solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
 {
   Pool *pool = solv->pool;
   Repo *installed = solv->installed;
-  Id p, *obsoletesmap = NULL;
-  int i;
+  Rule *r;
   Solvable *s;
+  int dontfix = 0;
+  Id p, d, *pp, req, *reqp, con, *conp, obs, *obsp, *dp;
 
-  obsoletesmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
-  if (installed)
+  assert(rid > 0);
+  if (rid >= solv->jobrules && rid < solv->jobrules_end)
     {
-      for (i = 0; i < solv->decisionq.count; i++)
-       {
-         Id *pp, n;
-
-         n = solv->decisionq.elements[i];
-         if (n < 0)
-           continue;
-         if (n == SYSTEMSOLVABLE)
-           continue;
-         s = pool->solvables + n;
-         if (s->repo == installed)             /* obsoletes don't count for already installed packages */
-           continue;
-         FOR_PROVIDES(p, pp, s->name)
-           if (s->name == pool->solvables[p].name)
-             {
-               if (pool->solvables[p].repo == installed && !obsoletesmap[p])
-                 {
-                   obsoletesmap[p] = n;
-                   obsoletesmap[n]++;
-                 }
-             }
-       }
-      for (i = 0; i < solv->decisionq.count; i++)
-       {
-         Id obs, *obsp;
-         Id *pp, n;
 
-         n = solv->decisionq.elements[i];
-         if (n < 0)
-           continue;
-         if (n == SYSTEMSOLVABLE)
-           continue;
-         s = pool->solvables + n;
-         if (s->repo == installed)             /* obsoletes don't count for already installed packages */
-           continue;
-         if (!s->obsoletes)
-           continue;
-         obsp = s->repo->idarraydata + s->obsoletes;
-         while ((obs = *obsp++) != 0)
-           FOR_PROVIDES(p, pp, obs)
-             {
-               if (pool->solvables[p].repo == installed && !obsoletesmap[p])
-                 {
-                   obsoletesmap[p] = n;
-                   obsoletesmap[n]++;
-                 }
-             }
-       }
+      r = solv->rules + rid;
+      p = solv->ruletojob.elements[rid - solv->jobrules];
+      *depp = job->elements[p + 1];
+      *sourcep = p;
+      *targetp = job->elements[p];
+      d = r->d < 0 ? -r->d - 1 : r->d;
+      if (d == 0 && r->w2 == 0 && r->p == -SYSTEMSOLVABLE && job->elements[p] != SOLVER_INSTALL_SOLVABLE_ONE_OF)
+       return SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP;
+      return SOLVER_PROBLEM_JOB_RULE;
     }
-  return obsoletesmap;
-}
-
-/*
- * printdecisions
- */
-
-void
-printdecisions(Solver *solv)
-{
-  Pool *pool = solv->pool;
-  Repo *installed = solv->installed;
-  Id p, *obsoletesmap = create_decisions_obsoletesmap( solv );
-  int i;
-  Solvable *s;
-
-  IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
+  if (rid >= solv->updaterules && rid < solv->updaterules_end)
     {
-      POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions -----\n");
-      for (i = 0; i < solv->decisionq.count; i++)
-       {
-         p = solv->decisionq.elements[i];
-         printruleelement(solv, SAT_DEBUG_SCHUBI, 0, p);
-       }
-      POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions end -----\n");
-    }
-
-  /* print solvables to be erased */
-
-  if (installed)
-    {
-      FOR_REPO_SOLVABLES(installed, p, s)
-       {
-         if (solv->decisionmap[p] >= 0)
-           continue;
-         if (obsoletesmap[p])
-           continue;
-         POOL_DEBUG(SAT_DEBUG_RESULT, "erase   %s\n", solvable2str(pool, s));
-       }
-    }
-
-  /* print solvables to be installed */
-
-  for (i = 0; i < solv->decisionq.count; i++)
-    {
-      int j;
-      p = solv->decisionq.elements[i];
-      if (p < 0)
-       continue;
-      if (p == SYSTEMSOLVABLE)
-       continue;
-      s = pool->solvables + p;
-      if (installed && s->repo == installed)
-       continue;
-
-      if (!obsoletesmap[p])
-        {
-          POOL_DEBUG(SAT_DEBUG_RESULT, "install %s", solvable2str(pool, s));
-        }
-      else
-       {
-         POOL_DEBUG(SAT_DEBUG_RESULT, "update  %s", solvable2str(pool, s));
-          POOL_DEBUG(SAT_DEBUG_RESULT, "  (obsoletes");
-         for (j = installed->start; j < installed->end; j++)
-           if (obsoletesmap[j] == p)
-             POOL_DEBUG(SAT_DEBUG_RESULT, " %s", solvable2str(pool, pool->solvables + j));
-         POOL_DEBUG(SAT_DEBUG_RESULT, ")");
-       }
-      POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
-    }
-
-  sat_free(obsoletesmap);
-
-  if (solv->recommendations.count)
-    {
-      POOL_DEBUG(SAT_DEBUG_RESULT, "\nrecommended packages:\n");
-      for (i = 0; i < solv->recommendations.count; i++)
-       {
-         s = pool->solvables + solv->recommendations.elements[i];
-         POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
-       }
-    }
-
-  if (solv->suggestions.count)
-    {
-      POOL_DEBUG(SAT_DEBUG_RESULT, "\nsuggested packages:\n");
-      for (i = 0; i < solv->suggestions.count; i++)
-       {
-         s = pool->solvables + solv->suggestions.elements[i];
-         POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s));
-       }
-    }
-}
-
-
-/* this is basically the reverse of addrpmrulesforsolvable */
-SolverProbleminfo
-solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
-{
-  Pool *pool = solv->pool;
-  Repo *installed = solv->installed;
-  Rule *r;
-  Solvable *s;
-  int dontfix = 0;
-  Id p, *pp, req, *reqp, con, *conp, obs, *obsp, *dp;
-
-  assert(rid > 0);
-  if (rid >= solv->systemrules)
-    {
-      *depp = 0;
-      *sourcep = solv->installed->start + (rid - solv->systemrules);
-      *targetp = 0;
-      return SOLVER_PROBLEM_UPDATE_RULE;
-    }
-  if (rid >= solv->jobrules)
-    {
-
-      r = solv->rules + rid;
-      p = solv->ruletojob.elements[rid - solv->jobrules];
-      *depp = job->elements[p + 1];
-      *sourcep = p;
-      *targetp = job->elements[p];
-      if (r->d == 0 && r->w2 == 0 && r->p == -SYSTEMSOLVABLE && job->elements[p] != SOLVER_INSTALL_SOLVABLE_ONE_OF)
-       return SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP;
-      return SOLVER_PROBLEM_JOB_RULE;
+      *depp = 0;
+      *sourcep = solv->installed->start + (rid - solv->updaterules);
+      *targetp = 0;
+      return SOLVER_PROBLEM_UPDATE_RULE;
     }
+  assert(rid < solv->rpmrules_end);
   r = solv->rules + rid;
   assert(r->p < 0);
-  if (r->d == 0 && r->w2 == 0)
+  d = r->d < 0 ? -r->d - 1 : r->d;
+  if (d == 0 && r->w2 == 0)
     {
       /* a rpm rule assertion */
       s = pool->solvables - r->p;
@@ -3019,24 +3289,42 @@ solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep,
          return SOLVER_PROBLEM_NOT_INSTALLABLE;
        }
       /* check requires */
-      assert(s->requires);
-      reqp = s->repo->idarraydata + s->requires;
-      while ((req = *reqp++) != 0)
+      if (s->requires)
        {
-         if (req == SOLVABLE_PREREQMARKER)
-           continue;
-         dp = pool_whatprovides(pool, req);
-         if (*dp == 0)
-           break;
+         reqp = s->repo->idarraydata + s->requires;
+         while ((req = *reqp++) != 0)
+           {
+             if (req == SOLVABLE_PREREQMARKER)
+               continue;
+             dp = pool_whatprovides(pool, req);
+             if (*dp == 0)
+               break;
+           }
+         if (req)
+           {
+             *depp = req;
+             return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
+           }
+       }
+      if (!solv->allowselfconflicts && s->conflicts)
+       {
+         conp = s->repo->idarraydata + s->conflicts;
+         while ((con = *conp++) != 0)
+           FOR_PROVIDES(p, pp, con)
+             if (p == -r->p)
+               {
+                 *depp = con;
+                 return SOLVER_PROBLEM_SELF_CONFLICT;
+               }
        }
-      assert(req);
-      *depp = req;
-      return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP;
+      /* should never happen */
+      *depp = 0;
+      return SOLVER_PROBLEM_RPM_RULE;
     }
   s = pool->solvables - r->p;
   if (installed && !solv->fixsystem && s->repo == installed)
     dontfix = 1;
-  if (r->d == 0 && r->w2 < 0)
+  if (d == 0 && r->w2 < 0)
     {
       /* a package conflict */
       Solvable *s2 = pool->solvables - r->w2;
@@ -3047,12 +3335,18 @@ solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep,
 
       /* if both packages have the same name and at least one of them
        * is not installed, they conflict */
-      if (s->name == s2->name && (!installed || (s->repo != installed || s2->repo != installed)))
+      if (s->name == s2->name && !(installed && s->repo == installed && s2->repo == installed))
        {
-         *depp = 0;
-         *sourcep = -r->p;
-         *targetp = -r->w2;
-         return SOLVER_PROBLEM_SAME_NAME;
+         /* also check noobsoletes map */
+         if ((s->evr == s2->evr && s->arch == s2->arch) || !solv->noobsoletes.size
+               || ((!installed || s->repo != installed) && !MAPTST(&solv->noobsoletes, -r->p))
+               || ((!installed || s2->repo != installed) && !MAPTST(&solv->noobsoletes, -r->w2)))
+           {
+             *depp = 0;
+             *sourcep = -r->p;
+             *targetp = -r->w2;
+             return SOLVER_PROBLEM_SAME_NAME;
+           }
        }
 
       /* check conflicts in both directions */
@@ -3093,7 +3387,7 @@ solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep,
            }
        }
       /* check obsoletes in both directions */
-      if ((!installed || s->repo != installed) && s->obsoletes)
+      if ((!installed || s->repo != installed) && s->obsoletes && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -r->p)))
        {
          obsp = s->repo->idarraydata + s->obsoletes;
          while ((obs = *obsp++) != 0)
@@ -3102,6 +3396,8 @@ solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep,
                {
                  if (p != -r->w2)
                    continue;
+                 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
+                   continue;
                  *depp = obs;
                  *sourcep = -r->p;
                  *targetp = p;
@@ -3109,7 +3405,7 @@ solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep,
                }
            }
        }
-      if ((!installed || s2->repo != installed) && s2->obsoletes)
+      if ((!installed || s2->repo != installed) && s2->obsoletes && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -r->w2)))
        {
          obsp = s2->repo->idarraydata + s2->obsoletes;
          while ((obs = *obsp++) != 0)
@@ -3118,6 +3414,8 @@ solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep,
                {
                  if (p != -r->p)
                    continue;
+                 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
+                   continue;
                  *depp = obs;
                  *sourcep = -r->w2;
                  *targetp = p;
@@ -3125,36 +3423,78 @@ solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep,
                }
            }
        }
+      if (solv->implicitobsoleteusesprovides && (!installed || s->repo != installed) && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -r->p)))
+       {
+         FOR_PROVIDES(p, pp, s->name)
+           {
+             if (p != -r->w2)
+               continue;
+             *depp = s->name;
+             *sourcep = -r->p;
+             *targetp = p;
+             return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
+           }
+       }
+      if (solv->implicitobsoleteusesprovides && (!installed || s2->repo != installed) && !(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, -r->w2)))
+       {
+         FOR_PROVIDES(p, pp, s2->name)
+           {
+             if (p != -r->p)
+               continue;
+             *depp = s2->name;
+             *sourcep = -r->w2;
+             *targetp = p;
+             return SOLVER_PROBLEM_PACKAGE_OBSOLETES;
+           }
+       }
       /* all cases checked, can't happen */
-      assert(0);
+      *depp = 0;
+      *sourcep = -r->p;
+      *targetp = 0;
+      return SOLVER_PROBLEM_RPM_RULE;
     }
   /* simple requires */
-  assert(s->requires);
-  reqp = s->repo->idarraydata + s->requires;
-  while ((req = *reqp++) != 0)
+  if (s->requires)
     {
-      if (req == SOLVABLE_PREREQMARKER)
-       continue;
-      dp = pool_whatprovides(pool, req);
-      if (r->d == 0)
+      reqp = s->repo->idarraydata + s->requires;
+      while ((req = *reqp++) != 0)
        {
-         if (*dp == r->w2 && dp[1] == 0)
+         if (req == SOLVABLE_PREREQMARKER)
+           continue;
+         dp = pool_whatprovides(pool, req);
+         if (d == 0)
+           {
+             if (*dp == r->w2 && dp[1] == 0)
+               break;
+           }
+         else if (dp - pool->whatprovidesdata == d)
            break;
        }
-      else if (dp - pool->whatprovidesdata == r->d)
-       break;
+      if (req)
+       {
+         *depp = req;
+         *sourcep = -r->p;
+         *targetp = 0;
+         return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
+       }
     }
-  assert(req);
-  *depp = req;
+  /* all cases checked, can't happen */
+  *depp = 0;
   *sourcep = -r->p;
   *targetp = 0;
-  return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE;
+  return SOLVER_PROBLEM_RPM_RULE;
 }
 
+
+/*-------------------------------------------------------------------
+ * 
+ * find problem rule
+ */
+
 static void
 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
 {
-  Id rid;
+  Id rid, d;
   Id lreqr, lconr, lsysr, ljobr;
   Rule *r;
   int reqassert = 0;
@@ -3165,27 +3505,29 @@ findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp,
       assert(rid > 0);
       if (rid >= solv->learntrules)
        findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
-      else if (rid >= solv->systemrules)
-       {
-         if (!*sysrp)
-           *sysrp = rid;
-       }
-      else if (rid >= solv->jobrules)
+      else if (rid >= solv->jobrules && rid < solv->jobrules_end)
        {
          if (!*jobrp)
            *jobrp = rid;
        }
+      else if (rid >= solv->updaterules && rid < solv->updaterules_end)
+       {
+         if (!*sysrp)
+           *sysrp = rid;
+       }
       else
        {
+         assert(rid < solv->rpmrules_end);
          r = solv->rules + rid;
-         if (!r->d && r->w2 < 0)
+         d = r->d < 0 ? -r->d - 1 : r->d;
+         if (!d && r->w2 < 0)
            {
              if (!*conrp)
                *conrp = rid;
            }
          else
            {
-             if (r->d == 0 && r->w2 == 0 && !reqassert)
+             if (!d && r->w2 == 0 && !reqassert)
                {
                  /* prefer assertions (XXX: bad idea?) */
                  *reqrp = rid;
@@ -3213,11 +3555,16 @@ findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp,
     *sysrp = lsysr;
 }
 
-/*
+
+/*-------------------------------------------------------------------
+ * 
+ * find problem rule
+ *
  * search for a rule that describes the problem to the
  * user. A pretty hopeless task, actually. We currently
  * prefer simple requires.
  */
+
 Id
 solver_findproblemrule(Solver *solv, Id problem)
 {
@@ -3236,166 +3583,10 @@ solver_findproblemrule(Solver *solv, Id problem)
   assert(0);
 }
 
-void
-printprobleminfo(Solver *solv, Queue *job, Id problem)
-{
-  Pool *pool = solv->pool;
-  Id probr;
-  Id dep, source, target;
-  Solvable *s, *s2;
-
-  probr = solver_findproblemrule(solv, problem);
-  switch (solver_problemruleinfo(solv, job, probr, &dep, &source, &target))
-    {
-    case SOLVER_PROBLEM_UPDATE_RULE:
-      s = pool_id2solvable(pool, source);
-      POOL_DEBUG(SAT_DEBUG_RESULT, "problem with installed package %s\n", solvable2str(pool, s));
-      return;
-    case SOLVER_PROBLEM_JOB_RULE:
-      POOL_DEBUG(SAT_DEBUG_RESULT, "conflicting requests\n");
-      return;
-    case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP:
-      POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides requested %s\n", dep2str(pool, dep));
-      return;
-    case SOLVER_PROBLEM_NOT_INSTALLABLE:
-      s = pool_id2solvable(pool, source);
-      POOL_DEBUG(SAT_DEBUG_RESULT, "package %s is not installable\n", solvable2str(pool, s));
-      return;
-    case SOLVER_PROBLEM_NOTHING_PROVIDES_DEP:
-      s = pool_id2solvable(pool, source);
-      POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides %s needed by %s\n", dep2str(pool, dep), solvable2str(pool, s));
-      return;
-    case SOLVER_PROBLEM_SAME_NAME:
-      s = pool_id2solvable(pool, source);
-      s2 = pool_id2solvable(pool, target);
-      POOL_DEBUG(SAT_DEBUG_RESULT, "cannot install both %s and %s\n", solvable2str(pool, s), solvable2str(pool, s2));
-      return;
-    case SOLVER_PROBLEM_PACKAGE_CONFLICT:
-      s = pool_id2solvable(pool, source);
-      s2 = pool_id2solvable(pool, target);
-      POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
-      return;
-    case SOLVER_PROBLEM_PACKAGE_OBSOLETES:
-      s = pool_id2solvable(pool, source);
-      s2 = pool_id2solvable(pool, target);
-      POOL_DEBUG(SAT_DEBUG_RESULT, "package %s obsoletes %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
-      return;
-    case SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE:
-      s = pool_id2solvable(pool, source);
-      POOL_DEBUG(SAT_DEBUG_RESULT, "package %s requires %s, but none of the providers can be installed\n", solvable2str(pool, s), dep2str(pool, dep));
-      return;
-    }
-}
-
-void
-printsolutions(Solver *solv, Queue *job)
-{
-  Pool *pool = solv->pool;
-  int pcnt;
-  Id p, rp, how, what;
-  Id problem, solution, element;
-  Solvable *s, *sd;
-
-  POOL_DEBUG(SAT_DEBUG_RESULT, "Encountered problems! Here are the solutions:\n\n");
-  pcnt = 1;
-  problem = 0;
-  while ((problem = solver_next_problem(solv, problem)) != 0)
-    {
-      POOL_DEBUG(SAT_DEBUG_RESULT, "Problem %d:\n", pcnt++);
-      POOL_DEBUG(SAT_DEBUG_RESULT, "====================================\n");
-      printprobleminfo(solv, job, problem);
-      POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
-      solution = 0;
-      while ((solution = solver_next_solution(solv, problem, solution)) != 0)
-        {
-         element = 0;
-         while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
-           {
-             if (p == 0)
-               {
-                 /* job, rp is index into job queue */
-                 how = job->elements[rp - 1] & ~SOLVER_WEAK;
-                 what = job->elements[rp];
-                 switch (how)
-                   {
-                   case SOLVER_INSTALL_SOLVABLE:
-                     s = pool->solvables + what;
-                     if (solv->installed && s->repo == solv->installed)
-                       POOL_DEBUG(SAT_DEBUG_RESULT, "- do not keep %s installed\n", solvable2str(pool, s));
-                     else
-                       POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", solvable2str(pool, s));
-                     break;
-                   case SOLVER_ERASE_SOLVABLE:
-                     s = pool->solvables + what;
-                     if (solv->installed && s->repo == solv->installed)
-                       POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", solvable2str(pool, s));
-                     else
-                       POOL_DEBUG(SAT_DEBUG_RESULT, "- do not forbid installation of %s\n", solvable2str(pool, s));
-                     break;
-                   case SOLVER_INSTALL_SOLVABLE_NAME:
-                     POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", dep2str(pool, what));
-                     break;
-                   case SOLVER_ERASE_SOLVABLE_NAME:
-                     POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", dep2str(pool, what));
-                     break;
-                   case SOLVER_INSTALL_SOLVABLE_PROVIDES:
-                     POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install a solvable providing %s\n", dep2str(pool, what));
-                     break;
-                   case SOLVER_ERASE_SOLVABLE_PROVIDES:
-                     POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall all solvables providing %s\n", dep2str(pool, what));
-                     break;
-                   case SOLVER_INSTALL_SOLVABLE_UPDATE:
-                     s = pool->solvables + what;
-                     POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install most recent version of %s\n", solvable2str(pool, s));
-                     break;
-                   default:
-                     POOL_DEBUG(SAT_DEBUG_RESULT, "- do something different\n");
-                     break;
-                   }
-               }
-             else
-               {
-                 /* policy, replace p with rp */
-                 s = pool->solvables + p;
-                 sd = rp ? pool->solvables + rp : 0;
-                 if (sd)
-                   {
-                     int gotone = 0;
-                     if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr, EVRCMP_MATCH_RELEASE) > 0)
-                       {
-                         POOL_DEBUG(SAT_DEBUG_RESULT, "- allow downgrade of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
-                         gotone = 1;
-                       }
-                     if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(solv, s, sd))
-                       {
-                         POOL_DEBUG(SAT_DEBUG_RESULT, "- allow architecture change of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
-                         gotone = 1;
-                       }
-                     if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(solv, s, sd))
-                       {
-                         if (sd->vendor)
-                           POOL_DEBUG(SAT_DEBUG_RESULT, "- allow vendor change from '%s' (%s) to '%s' (%s)\n", id2str(pool, s->vendor), solvable2str(pool, s), id2str(pool, sd->vendor), solvable2str(pool, sd));
-                         else
-                           POOL_DEBUG(SAT_DEBUG_RESULT, "- allow vendor change from '%s' (%s) to no vendor (%s)\n", id2str(pool, s->vendor), solvable2str(pool, s), solvable2str(pool, sd));
-                         gotone = 1;
-                       }
-                     if (!gotone)
-                       POOL_DEBUG(SAT_DEBUG_RESULT, "- allow replacement of %s with %s\n", solvable2str(pool, s), solvable2str(pool, sd));
-                   }
-                 else
-                   {
-                     POOL_DEBUG(SAT_DEBUG_RESULT, "- allow deinstallation of %s\n", solvable2str(pool, s));
-                   }
-
-               }
-           }
-         POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
-        }
-    }
-}
-
 
-/* create reverse obsoletes map for installed solvables
+/*-------------------------------------------------------------------
+ * 
+ * create reverse obsoletes map for installed solvables
  *
  * for each installed solvable find which packages with *different* names
  * obsolete the solvable.
@@ -3417,22 +3608,24 @@ create_obsolete_index(Solver *solv)
   for (i = 1; i < pool->nsolvables; i++)
     {
       s = pool->solvables + i;
-      if (s->repo == installed)
-       continue;
       if (!s->obsoletes)
        continue;
       if (!pool_installable(pool, s))
        continue;
       obsp = s->repo->idarraydata + s->obsoletes;
       while ((obs = *obsp++) != 0)
-        FOR_PROVIDES(p, pp, obs)
-         {
-           if (pool->solvables[p].repo != installed)
-             continue;
-           if (pool->solvables[p].name == s->name)
-             continue;
-           obsoletes[p - installed->start]++;
-         }
+       {
+         FOR_PROVIDES(p, pp, obs)
+           {
+             if (pool->solvables[p].repo != installed)
+               continue;
+             if (pool->solvables[p].name == s->name)
+               continue;
+             if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
+               continue;
+             obsoletes[p - installed->start]++;
+           }
+       }
     }
   n = 0;
   for (i = 0; i < installed->nsolvables; i++)
@@ -3446,27 +3639,35 @@ create_obsolete_index(Solver *solv)
   for (i = pool->nsolvables - 1; i > 0; i--)
     {
       s = pool->solvables + i;
-      if (s->repo == installed)
-       continue;
       if (!s->obsoletes)
        continue;
       if (!pool_installable(pool, s))
        continue;
       obsp = s->repo->idarraydata + s->obsoletes;
       while ((obs = *obsp++) != 0)
-        FOR_PROVIDES(p, pp, obs)
-         {
-           if (pool->solvables[p].repo != installed)
-             continue;
-           if (pool->solvables[p].name == s->name)
-             continue;
-           p -= installed->start;
-           if (obsoletes_data[obsoletes[p]] != i)
-             obsoletes_data[--obsoletes[p]] = i;
-         }
+       {
+         FOR_PROVIDES(p, pp, obs)
+           {
+             if (pool->solvables[p].repo != installed)
+               continue;
+             if (pool->solvables[p].name == s->name)
+               continue;
+             if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
+               continue;
+             p -= installed->start;
+             if (obsoletes_data[obsoletes[p]] != i)
+               obsoletes_data[--obsoletes[p]] = i;
+           }
+       }
     }
 }
 
+
+/*-------------------------------------------------------------------
+ * 
+ * remove disabled conflicts
+ */
+
 static void
 removedisabledconflicts(Solver *solv, Queue *removed)
 {
@@ -3489,7 +3690,7 @@ removedisabledconflicts(Solver *solv, Queue *removed)
       why = solv->decisionq_why.elements[i];
       assert(why > 0);
       r = solv->rules + why;
-      if (!r->w1 && decisionmap[-p])
+      if (r->d < 0 && decisionmap[-p])
        {
          /* rule is now disabled, remove from decisionmap */
          POOL_DEBUG(SAT_DEBUG_STATS, "removing conflict for package %s[%d]\n", solvable2str(pool, pool->solvables - p), -p);
@@ -3510,7 +3711,7 @@ removedisabledconflicts(Solver *solv, Queue *removed)
          i = 1;
          r = solv->rules + i;
        }
-      if (!r->w1)
+      if (r->d < 0)
        continue;
       if (!r->w2)
        {
@@ -3557,28 +3758,35 @@ removedisabledconflicts(Solver *solv, Queue *removed)
        {
          POOL_DEBUG(SAT_DEBUG_STATS, "re-conflicting package %s[%d]\n", solvable2str(pool, pool->solvables - new), -new);
          decisionmap[-new] = -1;
+         new = 0;
          n = 0;        /* redo all rules */
        }
     }
 }
 
+
+/*-------------------------------------------------------------------
+ *
+ * weaken solvable dependencies
+ */
+
 static void
 weaken_solvable_deps(Solver *solv, Id p)
 {
   int i;
   Rule *r;
 
-  for (i = 1, r = solv->rules + i; i < solv->jobrules; i++, r++)
+  for (i = 1, r = solv->rules + i; i < solv->featurerules; i++, r++)
     {
       if (r->p != -p)
        continue;
-      if (r->d == 0 && r->w2 < 0)
+      if ((r->d == 0 || r->d == -1) && r->w2 < 0)
        continue;       /* conflict */
       queue_push(&solv->weakruleq, i);
     }
 }
 
-/*-----------------------------------------------------------------*/
+/********************************************************************/
 /* main() */
 
 /*
@@ -3595,10 +3803,10 @@ solver_solve(Solver *solv, Queue *job)
   int i;
   int oldnrules;
   Map addedmap;                       /* '1' == have rpm-rules for solvable */
-  Id how, what, weak, name, p, *pp, d;
+  Id how, what, weak, p, *pp, d;
   Queue q, redoq;
   Solvable *s;
-  int gotweak;
+  int goterase;
   Rule *r;
 
   /* create whatprovides if not already there */
@@ -3615,6 +3823,35 @@ solver_solve(Solver *solv, Queue *job)
    *
    */
 
+  /* create noobsolete map if needed */
+  for (i = 0; i < job->count; i += 2)
+    {
+      how = job->elements[i] & ~SOLVER_WEAK;
+      what = job->elements[i + 1];
+      switch(how)
+       {
+       case SOLVER_NOOBSOLETES_SOLVABLE:
+       case SOLVER_NOOBSOLETES_SOLVABLE_NAME:
+       case SOLVER_NOOBSOLETES_SOLVABLE_PROVIDES:
+         if (!solv->noobsoletes.size)
+           map_init(&solv->noobsoletes, pool->nsolvables);
+         if (how == SOLVER_NOOBSOLETES_SOLVABLE)
+           {
+             MAPSET(&solv->noobsoletes, what);
+             break;
+           }
+         FOR_PROVIDES(p, pp, what)
+           {
+             if (how == SOLVER_NOOBSOLETES_SOLVABLE_NAME && !pool_match_nevr(pool, pool->solvables + p, what))
+               continue;
+             MAPSET(&solv->noobsoletes, p);
+           }
+         break;
+       default:
+         break;
+       }
+    }
+
   map_init(&addedmap, pool->nsolvables);
   queue_init(&q);
 
@@ -3624,7 +3861,7 @@ solver_solve(Solver *solv, Queue *job)
   MAPSET(&addedmap, SYSTEMSOLVABLE);
   queue_push(&solv->decisionq, SYSTEMSOLVABLE);
   queue_push(&solv->decisionq_why, 0);
-  solv->decisionmap[SYSTEMSOLVABLE] = 1;
+  solv->decisionmap[SYSTEMSOLVABLE] = 1; /* installed at level '1' */
 
   /*
    * create rules for all package that could be involved with the solving
@@ -3645,6 +3882,11 @@ solver_solve(Solver *solv, Queue *job)
       POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
     }
 
+  /*
+   * create rules for all packages involved in the job
+   * (to be installed or removed)
+   */
+    
   POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for packages involved with a job ***\n");
   oldnrules = solv->nrules;
   for (i = 0; i < job->count; i += 2)
@@ -3659,16 +3901,10 @@ solver_solve(Solver *solv, Queue *job)
          break;
        case SOLVER_INSTALL_SOLVABLE_NAME:
        case SOLVER_INSTALL_SOLVABLE_PROVIDES:
-         name = (how == SOLVER_INSTALL_SOLVABLE_NAME) ? what : 0;
-         while (ISRELDEP(name))
-           {
-             Reldep *rd = GETRELDEP(pool, name);
-             name = rd->name;
-           }
          FOR_PROVIDES(p, pp, what)
            {
              /* if by name, ensure that the name matches */
-             if (name && pool->solvables[p].name != name)
+             if (how == SOLVER_INSTALL_SOLVABLE_NAME && !pool_match_nevr(pool, pool->solvables + p, what))
                continue;
              addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
            }
@@ -3689,6 +3925,10 @@ solver_solve(Solver *solv, Queue *job)
   POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** create rpm rules for recommended/suggested packages ***\n");
 
   oldnrules = solv->nrules;
+    
+    /*
+     * add rules for suggests, enhances
+     */
   addrpmrulesforweak(solv, &addedmap);
   POOL_DEBUG(SAT_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
 
@@ -3713,12 +3953,109 @@ solver_solve(Solver *solv, Queue *job)
    * as an empty system (remove all packages) is a valid solution
    */
 
-  unifyrules(solv);    /* remove duplicate rpm rules */
-  solv->directdecisions = solv->decisionq.count;
+  unifyrules(solv);                              /* remove duplicate rpm rules */
+
+  solv->rpmrules_end = solv->nrules;              /* mark end of rpm rules */
 
+  solv->directdecisions = solv->decisionq.count;
   POOL_DEBUG(SAT_DEBUG_STATS, "decisions so far: %d\n", solv->decisionq.count);
-  IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
-    printdecisions (solv);
+
+  /*
+   * create feature rules
+   * 
+   * foreach installed:
+   *   create assertion (keep installed, if no update available)
+   *   or
+   *   create update rule (A|update1(A)|update2(A)|...)
+   * 
+   * those are used later on to keep a version of the installed packages in
+   * best effort mode
+   */
+    
+  POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add feature rules ***\n");
+  solv->featurerules = solv->nrules;              /* mark start of feature rules */
+  if (installed)
+    {
+       /* foreach possibly installed solvable */
+      for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
+       {
+         if (s->repo != installed)
+           {
+             addrule(solv, 0, 0);      /* create dummy rule */
+             continue;
+           }
+         addupdaterule(solv, s, 1);    /* allow s to be updated */
+       }
+       /*
+        * assert one rule per installed solvable,
+        * either an assertion (A)
+        * or a possible update (A|update1(A)|update2(A)|...)
+        */
+      assert(solv->nrules - solv->featurerules == installed->end - installed->start);
+    }
+  solv->featurerules_end = solv->nrules;
+
+    /*
+     * Add update rules for installed solvables
+     * 
+     * almost identical to feature rules
+     * except that downgrades are allowed
+     */
+    
+  POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add update rules ***\n");
+  solv->updaterules = solv->nrules;
+
+  if (installed)
+    { /* foreach installed solvables */
+      /* we create all update rules, but disable some later on depending on the job */
+      for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
+       {
+         Rule *sr;
+
+         if (s->repo != installed)
+           {
+             addrule(solv, 0, 0);      /* create dummy rule */
+             continue;
+           }
+
+         addupdaterule(solv, s, 0);    /* allowall = 0: downgrades allowed */
+
+           /*
+            * check for and remove duplicate
+            */
+           
+         r = solv->rules + solv->nrules - 1;           /* r: update rule */
+         sr = r - (installed->end - installed->start); /* sr: feature rule */
+         unifyrules_sortcmp_data = pool;
+         if (!unifyrules_sortcmp(r, sr))
+           {
+             /* identical rule, kill unneeded rule */
+             if (solv->allowuninstall)
+               {
+                 /* keep feature rule */
+                 memset(r, 0, sizeof(*r));
+                 queue_push(&solv->weakruleq, sr - solv->rules);
+               }
+             else
+               {
+                 /* keep update rule */
+                 memset(sr, 0, sizeof(*sr));
+               }
+           }
+         else if (solv->allowuninstall)
+           {
+             /* make both feature and update rule weak */
+             queue_push(&solv->weakruleq, r - solv->rules);
+             queue_push(&solv->weakruleq, sr - solv->rules);
+           }
+         else
+           disablerule(solv, sr);
+       }
+      /* consistency check: we added a rule for _every_ installed solvable */
+      assert(solv->nrules - solv->updaterules == installed->end - installed->start);
+    }
+  solv->updaterules_end = solv->nrules;
+
 
   /*
    * now add all job rules
@@ -3727,7 +4064,6 @@ solver_solve(Solver *solv, Queue *job)
   POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add JOB rules ***\n");
 
   solv->jobrules = solv->nrules;
-
   for (i = 0; i < job->count; i += 2)
     {
       oldnrules = solv->nrules;
@@ -3760,16 +4096,10 @@ solver_solve(Solver *solv, Queue *job)
          if (how == SOLVER_INSTALL_SOLVABLE_PROVIDES)
            POOL_DEBUG(SAT_DEBUG_JOB, "job: %sinstall provides %s\n", weak ? "weak " : "", dep2str(pool, what));
          queue_empty(&q);
-         name = (how == SOLVER_INSTALL_SOLVABLE_NAME) ? what : 0;
-         while (ISRELDEP(name))
-           {
-             Reldep *rd = GETRELDEP(pool, name);
-             name = rd->name;
-           }
          FOR_PROVIDES(p, pp, what)
            {
               /* if by name, ensure that the name matches */
-             if (name && pool->solvables[p].name != name)
+             if (how == SOLVER_INSTALL_SOLVABLE_NAME && !pool_match_nevr(pool, pool->solvables + p, what))
                continue;
              queue_push(&q, p);
            }
@@ -3795,16 +4125,10 @@ solver_solve(Solver *solv, Queue *job)
            POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase name %s\n", weak ? "weak " : "", dep2str(pool, what));
          if (how == SOLVER_ERASE_SOLVABLE_PROVIDES)
            POOL_DEBUG(SAT_DEBUG_JOB, "job: %serase provides %s\n", weak ? "weak " : "", dep2str(pool, what));
-         name = (how == SOLVER_ERASE_SOLVABLE_NAME) ? what : 0;
-         while (ISRELDEP(name))
-           {
-             Reldep *rd = GETRELDEP(pool, name);
-             name = rd->name;
-           }
          FOR_PROVIDES(p, pp, what)
            {
              /* if by name, ensure that the name matches */
-             if (name && pool->solvables[p].name != name)
+             if (how == SOLVER_ERASE_SOLVABLE_NAME && !pool_match_nevr(pool, pool->solvables + p, what))
                continue;
              addrule(solv, -p, 0);  /* add 'remove' rule */
              queue_push(&solv->ruletojob, i);
@@ -3834,7 +4158,21 @@ solver_solve(Solver *solv, Queue *job)
          POOL_DEBUG(SAT_DEBUG_JOB, "job: weaken deps %s\n", solvable2str(pool, s));
          weaken_solvable_deps(solv, what);
          break;
+       case SOLVER_NOOBSOLETES_SOLVABLE:
+         POOL_DEBUG(SAT_DEBUG_JOB, "job: no obsolete %s\n", solvable2str(pool, pool->solvables + what));
+         break;
+       case SOLVER_NOOBSOLETES_SOLVABLE_NAME:
+         POOL_DEBUG(SAT_DEBUG_JOB, "job: no obsolete name %s\n", dep2str(pool, what));
+         break;
+       case SOLVER_NOOBSOLETES_SOLVABLE_PROVIDES:
+         POOL_DEBUG(SAT_DEBUG_JOB, "job: no obsolete provides %s\n", dep2str(pool, what));
+         break;
        }
+       
+       /*
+        * debug
+        */
+       
       IF_POOLDEBUG (SAT_DEBUG_JOB)
        {
          int j;
@@ -3843,65 +4181,18 @@ solver_solve(Solver *solv, Queue *job)
          for (j = oldnrules; j < solv->nrules; j++)
            {
              POOL_DEBUG(SAT_DEBUG_JOB, " - job ");
-             printrule(solv, SAT_DEBUG_JOB, solv->rules + j);
+             solver_printrule(solv, SAT_DEBUG_JOB, solv->rules + j);
            }
        }
     }
   assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
+  solv->jobrules_end = solv->nrules;
 
-  /*
-   * now add system rules
-   *
-   */
-
-  POOL_DEBUG(SAT_DEBUG_SCHUBI, "*** Add system rules ***\n");
-
-
-  solv->systemrules = solv->nrules;
-
-  /*
-   * create rules for updating installed solvables
-   *
-   */
-
-  if (installed && !solv->allowuninstall)
-    {                                 /* loop over all installed solvables */
-      /* we create all update rules, but disable some later on depending on the job */
-      for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
-       {
-         /* no system rules for patch atoms */
-         if (s->freshens && !s->supplements)
-           {
-             const char *name = id2str(pool, s->name);
-             if (name[0] == 'a' && !strncmp(name, "atom:", 5))
-               {
-                 addrule(solv, 0, 0);
-                 continue;
-               }
-           }
-         if (s->repo == installed)
-           addupdaterule(solv, s, 0);  /* allowall = 0 */
-         else
-           addrule(solv, 0, 0);        /* create dummy rule */
-       }
-      /* consistency check: we added a rule for _every_ system solvable */
-      assert(solv->nrules - solv->systemrules == installed->end - installed->start);
-    }
-
-  /* create special weak system rules */
-  /* those are used later on to keep a version of the installed packages in
-     best effort mode */
-  if (installed && installed->nsolvables)
-    {
-      solv->weaksystemrules = sat_calloc(installed->end - installed->start, sizeof(Id));
-      FOR_REPO_SOLVABLES(installed, p, s)
-       {
-         policy_findupdatepackages(solv, s, &q, 1);
-         if (q.count)
-           solv->weaksystemrules[p - installed->start] = pool_queuetowhatprovides(pool, &q);
-       }
-    }
-
+    /* all rules created
+     * --------------------------------------------------------------
+     * prepare for solving
+     */
+    
   /* free unneeded memory */
   map_free(&addedmap);
   queue_free(&q);
@@ -3917,10 +4208,16 @@ solver_solve(Solver *solv, Queue *job)
   /* all new rules are learnt after this point */
   solv->learntrules = solv->nrules;
 
-  /* disable system rules that conflict with our job */
+  /* create assertion index. it is only used to speed up
+   * makeruledecsions() a bit */
+  for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
+    if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
+      queue_push(&solv->ruleassertions, i);
+
+  /* disable update rules that conflict with our job */
   disableupdaterules(solv, job, -1);
 
-  /* make decisions based on job/system assertions */
+  /* make decisions based on job/update assertions */
   makeruledecisions(solv);
 
   /* create watches chains */
@@ -3928,35 +4225,44 @@ solver_solve(Solver *solv, Queue *job)
 
   POOL_DEBUG(SAT_DEBUG_STATS, "problems so far: %d\n", solv->problems.count);
 
-  /* solve! */
+  /*
+   * ********************************************
+   * solve!
+   * ********************************************
+   */
+    
   run_solver(solv, 1, solv->dontinstallrecommended ? 0 : 1);
 
   queue_init(&redoq);
-  gotweak = 0;
-  /* disable all weak erase rules for recommened/suggestes search */
-  for (i = 1, r = solv->rules + i; i < solv->learntrules; i++, r++)
+  goterase = 0;
+  /* disable all erase jobs (including weak "keep uninstalled" rules) */
+  for (i = solv->jobrules, r = solv->rules + i; i < solv->learntrules; i++, r++)
     {
-      if (!MAPTST(&solv->weakrulemap, i))
+      if (r->d < 0)    /* disabled ? */
        continue;
-      if (!r->w1)
+      if (r->p > 0)    /* install job? */
        continue;
       disablerule(solv, r);
-      gotweak++;
+      goterase++;
     }
-  if (gotweak)
+  
+  if (goterase)
     {
       enabledisablelearntrules(solv);
       removedisabledconflicts(solv, &redoq);
     }
 
-  /* find recommended packages */
-  /* if q.count == 0 we already found all recommended in the
+  /*
+   * find recommended packages
+   */
+    
+  /* if redoq.count == 0 we already found all recommended in the
    * solver run */
-  if (redoq.count || solv->dontinstallrecommended)
+  if (redoq.count || solv->dontinstallrecommended || !solv->dontshowinstalledrecommended || solv->ignorealreadyrecommended)
     {
       Id rec, *recp, p, *pp;
 
-      /* create map of all suggests that are still open */
+      /* create map of all recommened packages */
       solv->recommends_index = -1;
       MAPZERO(&solv->recommendsmap);
       for (i = 0; i < solv->decisionq.count; i++)
@@ -3974,7 +4280,15 @@ solver_solve(Solver *solv, Queue *job)
                    if (solv->decisionmap[p] > 0)
                      break;
                  if (p)
-                   continue;   /* p != 0: already fulfilled */
+                   {
+                     if (!solv->dontshowinstalledrecommended)
+                       {
+                         FOR_PROVIDES(p, pp, rec)
+                           if (solv->decisionmap[p] > 0)
+                             MAPSET(&solv->recommendsmap, p);
+                       }
+                     continue; /* p != 0: already fulfilled */
+                   }
                  FOR_PROVIDES(p, pp, rec)
                    MAPSET(&solv->recommendsmap, p);
                }
@@ -3982,7 +4296,9 @@ solver_solve(Solver *solv, Queue *job)
        }
       for (i = 1; i < pool->nsolvables; i++)
        {
-         if (solv->decisionmap[i] != 0)
+         if (solv->decisionmap[i] < 0)
+           continue;
+         if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
            continue;
          s = pool->solvables + i;
          if (!MAPTST(&solv->recommendsmap, i))
@@ -4003,7 +4319,10 @@ solver_solve(Solver *solv, Queue *job)
       policy_filter_unwanted(solv, &solv->recommendations, 0, POLICY_MODE_SUGGEST);
     }
 
-  /* find suggested packages */
+  /*
+   * find suggested packages
+   */
+    
   if (1)
     {
       Id sug, *sugp, p, *pp;
@@ -4026,7 +4345,15 @@ solver_solve(Solver *solv, Queue *job)
                    if (solv->decisionmap[p] > 0)
                      break;
                  if (p)
-                   continue;   /* already fulfilled */
+                   {
+                     if (!solv->dontshowinstalledrecommended)
+                       {
+                         FOR_PROVIDES(p, pp, sug)
+                           if (solv->decisionmap[p] > 0)
+                             MAPSET(&solv->suggestsmap, p);
+                       }
+                     continue; /* already fulfilled */
+                   }
                  FOR_PROVIDES(p, pp, sug)
                    MAPSET(&solv->suggestsmap, p);
                }
@@ -4034,7 +4361,9 @@ solver_solve(Solver *solv, Queue *job)
        }
       for (i = 1; i < pool->nsolvables; i++)
        {
-         if (solv->decisionmap[i] != 0)
+         if (solv->decisionmap[i] < 0)
+           continue;
+         if (solv->decisionmap[i] > 0 && solv->dontshowinstalledrecommended)
            continue;
          s = pool->solvables + i;
          if (!MAPTST(&solv->suggestsmap, i))
@@ -4058,6 +4387,9 @@ solver_solve(Solver *solv, Queue *job)
        solv->decisionmap[redoq.elements[i]] = redoq.elements[i + 1];
     }
 
+    /*
+     * if unsolvable, prepare solutions
+     */
 
   if (solv->problems.count)
     {
@@ -4084,10 +4416,18 @@ solver_solve(Solver *solv, Queue *job)
        }
       solv->recommendations.count = recocount;
     }
+
+  POOL_DEBUG(SAT_DEBUG_STATS, "final solver statistics: %d learned rules, %d unsolvable\n", solv->stats_learned, solv->stats_unsolvable);
   queue_free(&redoq);
 }
 
 /***********************************************************************/
+/* disk usage computations */
+
+/*-------------------------------------------------------------------
+ * 
+ * calculate DU changes
+ */
 
 void
 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
@@ -4099,6 +4439,12 @@ solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
   map_free(&installedmap);
 }
 
+
+/*-------------------------------------------------------------------
+ * 
+ * calculate changes in install size
+ */
+
 int
 solver_calc_installsizechange(Solver *solv)
 {
@@ -4111,3 +4457,4 @@ solver_calc_installsizechange(Solver *solv)
   return change;
 }
 
+/* EOF */