public static void usageExample1(String graphFilename, String source, String target, int k)
    {
        /* Read graph from file */
        Console.WriteLine("Reading data from file... ");
        Graph graph = new Graph(graphFilename);

        Console.WriteLine("complete.");
        printGraph(graph);
        /* Compute the K shortest paths and record the completion time */
        Console.WriteLine("Computing the " + k + " shortest paths from [" + source + "] to [" + target + "] ");
        Console.WriteLine("using Yen's algorithm... ");
        IList <Path> ksp;
        long         timeStart    = 0;// TODO System.currentTimeMillis();
        Yen          yenAlgorithm = new Yen();

        ksp = yenAlgorithm.Ksp(graph, source, target, k);
        long timeFinish = 0;// TODO SystemJ.currentTimeMillis();

        Console.WriteLine("complete.");
        Console.WriteLine("Operation took " + (timeFinish - timeStart) / 1000.0 + " seconds.");
        /* Output the K shortest paths */
        Console.WriteLine("k) cost: [path]");
        int n = 0;

        foreach (Path p in ksp)
        {
            Console.WriteLine(++n + ") " + p);
        }
    }
Пример #2
0
 protected PathFinderBsmockGenerics(
     GraphGenerics <E, V, W> graph,
     PathFactory <P, E, V, W> pathFactory
     ) : base(graph, pathFactory)
 {
     this.yenAlgorithm = new Yen();
     this.graphAdaptee = new edu.ufl.cise.bsmock.graph.Graph();
     PopulateGraphAdapteeWithEdges();
 }
Пример #3
0
        static void Main(string[] args)
        {
            Won    won    = new Won(1000);
            Dollar dollar = new Dollar(1);
            Yen    yen    = new Yen(100);

            Won won1 = yen;
            Won won2 = (Won)yen;
            Won won3 = (Won)dollar;

            Console.WriteLine(won1);
            Console.WriteLine(won2);
            Console.WriteLine(won3);

            //won = yen;  // yen과 won의 타입이 다르기 때문에 컴파일 시에 오류 발생
        }
Пример #4
0
        static void Main(string[] args)
        {
            Won    won    = new Won(1000);
            Dollar dollar = new Dollar(1);
            Yen    yen    = new Yen(100);

            //won = dollar;   // 부모, 자식 관계가 아닌 클래스끼리는 형변환이 불가능하다.
            dollar = yen;         // 형변환 연산자를 implicit으로 오버로딩 했으므로 묵시적 형변환이 발생한다.
            dollar = (Dollar)yen; // 명시적으로 해도 상관없다.
            //yen = won;      // 형변환 연산자를 explicit으로 오버로딩 했으므로 명시적 형변환을 해야한다.
            yen = (Yen)won;

            Console.WriteLine(won);
            Console.WriteLine(dollar);
            Console.WriteLine(yen);
        }
Пример #5
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));
        }