Example #1
0
        public List <Lit> CalcReason(Solver s, Lit p)
        {
            List <Lit> x = new List <Lit>();

            for (int i = (p == Lit.LIT_UNDEF ? 0 : 1); i < this.lits.Count; i++)
            {
                //x.Add(this.lits[i]);
                x.Add(Lit.NegativeLit(this.lits[i]));
            }

            return(x);
        }
Example #2
0
        // Page 15
        private void Analyze(Clause confl, out List <Lit> out_learnt, out int btlevel)
        {
            int        counter = 0;
            Lit        p       = Lit.LIT_UNDEF;
            List <Lit> p_reason;
            List <int> seen = new List <int>(); // May need to optimize this

            btlevel    = 0;
            out_learnt = new List <Lit>();
            out_learnt.Add(Lit.LIT_UNDEF); // Reserve space for lits[0]

            do
            {
                p_reason = confl.CalcReason(this, p);
                foreach (Lit q in p_reason)
                {
                    if (!seen.Contains(q.Var))
                    {
                        seen.Add(q.Var);
                        if (this.level[q.Var] == this.DecisionLevel)
                        {
                            ++counter;
                        }
                        else if (this.level[q.Var] > 0)
                        {
                            //out_learnt.Add(Lit.LitFromVal(q.Val));
                            out_learnt.Add(Lit.NegativeLit(q));
                            btlevel = Math.Max(btlevel, this.level[q.Var]);
                        }
                    }
                }

                do
                {
                    p     = Lit.LitFromVal(this.trail.Peek());
                    confl = this.reason[p.Var];
                    this.UndoOne();
                } while (!seen.Contains(p.Var));

                --counter;
            } while(counter > 0);

            out_learnt[0] = Lit.NegativeLit(p);
        }