Exemplo n.º 1
0
        private void Propagate(Variable var, IList <IDemon> itemList)
        {
            if (m_IsViolated)
            {
                return;
            }

            if (itemList.Count == 0)
            {
                return;
            }

            for (int idx = 0; idx < itemList.Count; ++idx)
            {
                IDemon item = itemList[idx];

                item.Update(var);

                ++item.CountUpdate;

                if (m_IsViolated)
                {
                    ++item.CountFail;
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public void Enqueue(IList <IDemon> itemList)
        {
            for (int idx = 0; idx < itemList.Count; ++idx)
            {
                IDemon item = itemList[idx];

                if (!item.InQueue)
                {
                    item.InQueue = true;

                    m_Queue.Enqueue(item);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Propagate all the variables in the queue.
        /// If FailOnFirstViolation == true then the method will return on the first
        /// violation encountered, otherwise it'll keep propagating until the queue
        /// is empty.
        /// </summary>
        public void Propagate()
        {
            if (!m_IsPropagating)
            {
                m_IsPropagating = true;

                while (!m_IsViolated &&
                       m_Queue.Count > 0)
                {
                    IDemon item = m_Queue.Dequeue();

                    item.InQueue = false;

                    item.Update();

                    ++item.CountUpdate;

                    if (m_IsViolated)
                    {
                        ++item.CountFail;
                    }
                }

                if (m_Queue.Count > 0)
                {
                    foreach (IDemon item in m_Queue)
                    {
                        item.InQueue = false;
                    }

                    m_Queue.Clear();
                }

                m_IsPropagating = false;
            }
        }