Exemple #1
0
        /* Maybe we want theese ...
         * public void addTClause(Clause c) {
         *      clauses.Add(c);
         * }*/

        public bool addSATClause(Clause c)
        {
            if (c.Literals.Count == 1)
            {
                //TODO Can be removed when Locked is removed
                if (c.Literals[0].Var.Locked && c.Literals[0].Sign != c.Literals[0].Var.Assignment)
                {
                    return(false);
                }


                ///////////
                ///////////
                /////////// AAAAAAAAAAAAAAAAm Ende von DL 0 muss das sein! oO
                ///////////
                ///////////

                /*if(decisionLevelNull.Level-1 > decisions.Count) decisions.Add(c.Literals[0].Var);
                 * else
                 *      decisions.Insert(decisionLevelNull.Level-1, c.Literals[0].Var);				*/
                /*if(DecisionLevel.Count>1)decisions.Insert(DecisionLevel[1].Level-1, c.Literals[0].Var);
                 * else
                 *      decisions.Add(c.Literals[0].Var);*/
                decisions.Insert(decisionLevelNull.Level, c.Literals[0].Var);
                //decisions.Insert(0, c.Literals[0].Var);
                c.Literals[0].Var.DecisionLevel = this.decisionLevel[0];
                c.Literals[0].Var.Assignment    = c.Literals[0].Sign;
                c.Literals[0].Var.Reason        = null;
                c.Literals[0].Var.Locked        = true;
                foreach (DecisionLevel l in this.decisionLevel)
                {
                    l.Level++;
                }
                return(true);
            }
            Watcher w1 = new Watcher(c.Literals[0], c);
            Watcher w2 = new Watcher(c.Literals[c.Literals.Count - 1], c);

            c.watcher[0] = w1;
            c.watcher[1] = w2;
            satClauses.Add(c);

            return(true);
        }
Exemple #2
0
        public bool addBasicClause(Clause c)
        {
            if (c.Literals.Count == 0)
            {
                return(false);
            }

            if (c.Literals.Count > 1)
            {
                Watcher w1 = new Watcher(c.Literals[0], c);
                Watcher w2 = new Watcher(c.Literals[1], c);
                c.watcher[0] = w1;
                c.watcher[1] = w2;
                clauses.Add(c);

                /*foreach(Lit l in c.Literals) {
                 *      if(l.Sign == Assignment.True) l.Var.Activity++;
                 *      else l.Var.NegActivity++;
                 * }*/
            }
            else
            {
                if (c.Literals[0].Var.Assignment != Assignment.Unassigned &&
                    c.Literals[0].Var.Assignment != c.Literals[0].Sign)
                {
                    return(false);
                }

                c.Literals[0].Var.Assignment    = c.Literals[0].Sign;
                c.Literals[0].Var.DecisionLevel = this.decisionLevelNull;
                c.Literals[0].Var.Reason        = null;

                //TODO check this!!!
                decisions.Add(c.Literals[0].Var);
                c.Literals[0].Var.Locked = true;
                clauses.Add(c);
            }

            return(true);
        }
Exemple #3
0
        public Clause propagate()
        {
            int lLevel = 0;

            if (decisionLevel.Count > 1)
            {
                lLevel = decisionLevel[decisionLevel.Count - 1].Level;
            }

            for (int i = lLevel; i < decisions.Count; i++)
            {
                List <Watcher> watchList = decisions[i].WatchList;

                for (int j = 0; j < watchList.Count; j++)
                {
                    Watcher w = watchList[j];
#if (CNSatDebug)
                    decisions[i].Print();
                    Console.Write(" -> ");
                    w.Clause.Print();
#endif
                    if (w.Clause.Satisfied)
                    {
                        continue;
                    }
                    if (w.Lit.Satisfied())
                    {
                        w.Clause.Satisfied = true;
                        continue;
                    }
                    //TODO Do we need this?
                    if (w.Lit.Var.Assignment == Assignment.Unassigned)
                    {
                        continue;
                    }

                    //This can be optimized !?
                    Clause c = w.Clause;

                    //Search for new Watch
                    int oWId = (c.watcher[0] == w) ? 1 : 0;
                    if (c.watcher[oWId].Lit.Satisfied())
                    {
                        //TODO: Do we need this?
                        w.Clause.Satisfied = true;
                        continue;
                    }
                    bool found = false;
                    foreach (Lit l in c.Literals)
                    {
                        if (c.watcher[oWId].Lit.Var != l.Var && (l.Var.Assignment == Assignment.Unassigned || l.Satisfied()))
                        {
                            w.Lit.Var.WatchList.Remove(w);
                            j--;
                            w.Lit = l;
                            l.Var.WatchList.Add(w);
                            found = true;
                            if (l.Satisfied())
                            {
                                w.Clause.Satisfied = true;
                            }
                            break;
                        }
                    }
                    if (!found)
                    {
                        c.Activity++;
                        //TODO Handle Watcher here ... do not return -> faster
                        Watcher w2 = c.watcher[oWId];
                        if (w2.Lit.Var.Assignment == Assignment.Unassigned)
                        {
                            w2.Lit.Var.Assignment    = w2.Lit.Sign;
                            w2.Clause.Satisfied      = true;
                            w2.Lit.Var.DecisionLevel = decisionLevel[decisionLevel.Count - 1];
                            decisions.Add(w2.Lit.Var);
                            w2.Lit.Var.Reason = c;

                            foreach (Watcher wi in w2.Lit.Var.WatchList)
                            {
                                wi.Clause.LastModVar = w2.Lit.Var;
                            }
                        }
                        else
                        {
                            return(c);
                        }
                    }
                }
            }

            return(null);
        }