Ejemplo n.º 1
0
        public void testFIFOQueue()
        {
            FIFOQueue<String> queue = new FIFOQueue<String>();
            Assert.IsTrue(queue.isEmpty());

            queue.push("Hello");
            Assert.AreEqual(1, queue.Count);
            Assert.IsFalse(queue.isEmpty());

            queue.push("Hi");
            Assert.AreEqual(2, queue.Count);
            Assert.IsFalse(queue.isEmpty());

            String s = queue.pop();
            Assert.AreEqual("Hello", s);
            Assert.AreEqual(1, queue.Count);
            Assert.AreEqual("Hi", queue.Peek());

            queue.push("bonjour");
            queue.push("salaam alaikum");
            Assert.AreEqual(3, queue.Count);
            Assert.AreEqual("Hi", queue.pop());
            Assert.AreEqual("bonjour", queue.pop());
            Assert.AreEqual("salaam alaikum", queue.pop());

            Assert.AreEqual(0, queue.Count);
        }
Ejemplo n.º 2
0
        public void testFIFOQueue()
        {
            FIFOQueue <String> queue = new FIFOQueue <String>();

            Assert.IsTrue(queue.isEmpty());

            queue.push("Hello");
            Assert.AreEqual(1, queue.Count);
            Assert.IsFalse(queue.isEmpty());

            queue.push("Hi");
            Assert.AreEqual(2, queue.Count);
            Assert.IsFalse(queue.isEmpty());

            String s = queue.pop();

            Assert.AreEqual("Hello", s);
            Assert.AreEqual(1, queue.Count);
            Assert.AreEqual("Hi", queue.Peek());

            queue.push("bonjour");
            queue.push("salaam alaikum");
            Assert.AreEqual(3, queue.Count);
            Assert.AreEqual("Hi", queue.pop());
            Assert.AreEqual("bonjour", queue.pop());
            Assert.AreEqual("salaam alaikum", queue.pop());

            Assert.AreEqual(0, queue.Count);
        }
Ejemplo n.º 3
0
 private void reduceDomains(FIFOQueue <Variable> queue, CSP csp,
                            DomainRestoreInfo info)
 {
     while (!queue.isEmpty())
     {
         Variable var = queue.pop();
         foreach (Constraint constraint in csp.getConstraints(var))
         {
             if (constraint.getScope().Count == 2)
             {
                 Variable neighbor = csp.getNeighbor(var, constraint);
                 if (revise(neighbor, var, constraint, csp, info))
                 {
                     if (csp.getDomain(neighbor).isEmpty())
                     {
                         info.setEmptyDomainFound(true);
                         return;
                     }
                     queue.push(neighbor);
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
 private void reduceDomains(FIFOQueue<Variable> queue, CSP csp,
         DomainRestoreInfo info)
 {
     while (!queue.isEmpty())
     {
         Variable var = queue.pop();
         foreach (Constraint constraint in csp.getConstraints(var))
         {
             if (constraint.getScope().Count == 2)
             {
                 Variable neighbor = csp.getNeighbor(var, constraint);
                 if (revise(neighbor, var, constraint, csp, info))
                 {
                     if (csp.getDomain(neighbor).isEmpty())
                     {
                         info.setEmptyDomainFound(true);
                         return;
                     }
                     queue.push(neighbor);
                 }
             }
         }
     }
 }