Пример #1
0
        public void TestAllCubeDistance()
        {
            BookitDB db = new BookitDB();
            var allCubes = db.Cubes;
            IMapRepository mapRep = new MapDBRepository();
            DijikstraPathFinder sfinder = new DijikstraPathFinder(mapRep.Map);
            var allRooms = db.MeetingRooms.Select(mr => mr as MapNode).ToList();

            using (var fs = File.Open(@"C:\result.txt", FileMode.OpenOrCreate))
            {
                using (var sw = new StreamWriter(fs))
                {
                    sw.Write(string.Format("CUBE,"));
                    foreach (var mr in allRooms)
                        sw.Write(mr.Name + ",");
                    sw.WriteLine();

                    foreach (var cube in allCubes)
                    {
                        var island = mapRep.GetIsland(cube.Name);
                        var nodeWithDistance = sfinder.GetDistance(island, allRooms);
                        sw.Write(cube.Name + ",");

                        foreach (var mr in allRooms)
                        {
                            sw.Write(nodeWithDistance[mr] + ",");
                        }
                        sw.WriteLine();
                    }
                }
            }
        }
Пример #2
0
        public void GetDistanceTest()
        {
            Map map = CreateChaoYang();
            DijikstraPathFinder target = new DijikstraPathFinder(map);
            MapNode source = new CubeIsland() { Id = 0, Name = "ChaoYang-Island7" };

            var g1 = new Gateway() { Id = 0, Name = "ChaoYang-G-W" };
            var g2 = new Gateway() { Id = 0, Name = "ChaoYang-G-N" };
            var g3 = new MeetingRoom { Id = 0, Name = "Tian Tan" };
            var g4 = new MeetingRoom { Id = 0, Name = "Wang Fu Jing" };
            var g5 = new CubeIsland { Id = 0, Name = "ChaoYang-Island10" };
            var g6 = new CubeIsland { Id = 0, Name = "ChaoYang-Island12" };
            var g7 = new CubeIsland { Id = 0, Name = "ChaoYang-Island13" };

            IList<MapNode> dest = new List<MapNode>() { g1, g2, g3, g4, g4, g5, g6, g7 };
            IDictionary<MapNode, double> expected = new Dictionary<MapNode, double>();

            expected.Add(g1, 11);
            expected.Add(g2, 3);
            expected.Add(g3, 7);
            expected.Add(g4, 5);

            IDictionary<MapNode, double> actual = target.GetDistance(source, dest);
            Assert.AreEqual(expected, actual);
        }
Пример #3
0
 public ShortestPathFinder(IMapRepository mapRep, IRoomFinder innerFinder)
 {
     this.mapRep = mapRep;
     sfinder = new DijikstraPathFinder(mapRep.Map);
     this.innerFinder = innerFinder;
 }