Exemple #1
0
        public bool Equals(Path path2)
        {
            if (path2 == null)
            {
                return(false);
            }

            java.util.LinkedList <Edge> edges2 = path2.GetEdges();

            int numEdges1 = edges.size();
            int numEdges2 = edges2.size();

            if (numEdges1 != numEdges2)
            {
                return(false);
            }

            for (int i = 0; i < numEdges1; i++)
            {
                Edge edge1 = edges.get(i);
                Edge edge2 = edges2.get(i);
                if (!edge1.GetFromNode().Equals(edge2.GetFromNode()))
                {
                    return(false);
                }
                if (!edge1.GetToNode().Equals(edge2.GetToNode()))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #2
0
        /**
         * Binary search is exploited to find the right position
         * of the new element.
         * @param weight
         * @return the position of the new element
         */
        private int BinLocatePos(double weight, bool isIncremental)
        {
            int mid  = 0;
            int low  = 0;
            int high = elementWeightPairList.size() - 1;

            //
            while (low <= high)
            {
                mid = (low + high) / 2;
                if (elementWeightPairList.get(mid).GetWeight() == weight)
                {
                    return(mid + 1);
                }

                if (isIncremental)
                {
                    if (elementWeightPairList.get(mid).GetWeight() < weight)
                    {
                        high = mid - 1;
                    }
                    else
                    {
                        low = mid + 1;
                    }
                }
                else
                {
                    if (elementWeightPairList.get(mid).GetWeight() > weight)
                    {
                        high = mid - 1;
                    }
                    else
                    {
                        low = mid + 1;
                    }
                }
            }
            return(low);
        }
Exemple #3
0
        public void YenKShortestPathsTest()
        {
            const double deltaValue = 0.0000001;

            var graph = new Graph();

            graph.AddEdge("A", "B", 5);
            graph.AddEdge("A", "C", 6);
            graph.AddEdge("B", "C", 7);
            graph.AddEdge("B", "D", 8);
            graph.AddEdge("C", "D", 9);

            Yen          yenAlgorithm = new Yen();
            IList <Path> paths        = yenAlgorithm.Ksp(graph, "A", "D", 5);

            Assert.AreEqual(3, paths.Count);

            Path path1 = paths[0];
            Path path2 = paths[1];
            Path path3 = paths[2];

            Assert.AreEqual(13, path1.GetTotalCost(), deltaValue);
            Assert.AreEqual(15, path2.GetTotalCost(), deltaValue);
            Assert.AreEqual(21, path3.GetTotalCost(), deltaValue);

            java.util.LinkedList <String> nodes1 = path1.GetNodes();
            Assert.AreEqual(3, nodes1.size());
            Assert.AreEqual("A", nodes1.get(0));
            Assert.AreEqual("B", nodes1.get(1));
            Assert.AreEqual("D", nodes1.get(2));

            java.util.LinkedList <String> nodes2 = path2.GetNodes();
            Assert.AreEqual(3, nodes2.size());
            Assert.AreEqual("A", nodes2.get(0));
            Assert.AreEqual("C", nodes2.get(1));
            Assert.AreEqual("D", nodes2.get(2));

            java.util.LinkedList <String> nodes3 = path3.GetNodes();
            Assert.AreEqual(4, nodes3.size());
            Assert.AreEqual("A", nodes3.get(0));
            Assert.AreEqual("B", nodes3.get(1));
            Assert.AreEqual("C", nodes3.get(2));
            Assert.AreEqual("D", nodes3.get(3));
        }
Exemple #4
0
        public void Test_ForEach_LinkedList()
        {
            java.lang.SystemJ.outJ.println("LinkedList foreach test");


            java.util.LinkedList <String> testArray = new java.util.LinkedList <String>();
            testArray.add("VampireAPI");
            testArray.add("supports");
            testArray.add("foreach statements");
            testArray.add("! Yeah!!!");

            // for count loop
            java.lang.SystemJ.outJ.println("for count loop: ");
            for (int i = 0; i < testArray.size(); i++)
            {
                java.lang.SystemJ.outJ.print(testArray.get(i));
                java.lang.SystemJ.outJ.print(" ");
            }
            java.lang.SystemJ.outJ.println();

            // for iterator loop
            java.lang.SystemJ.outJ.println("for iterator loop: ");
            for (java.util.Iterator <String> it = testArray.iterator(); it.hasNext();)
            {
                java.lang.SystemJ.outJ.print(it.next());
                java.lang.SystemJ.outJ.print(" ");
            }
            java.lang.SystemJ.outJ.println();

            // foreach loop
            java.lang.SystemJ.outJ.println("foreach loop: ");
            foreach (String text in testArray)
            {
                java.lang.SystemJ.outJ.print(text);
                java.lang.SystemJ.outJ.print(" ");
            }
            java.lang.SystemJ.outJ.println();


            Assert.True(true, "compiler OK");
        }
Exemple #5
0
        // Disabled method because never used
        //public void addLastNode(String nodeLabel) {
        //    String lastNode = edges.getLast().getToNode();
        //    edges.addLast(new Edge(lastNode, nodeLabel,0));
        //}

        public int Size()
        {
            return(edges.size());
        }