Exemple #1
0
 public Route(ICityPlace start, ICityPlace end, IReadOnlyCollection <ICityRoad> roads)
 {
     Start = start;
     End   = end;
     Roads = roads;
     new RouteValidator().ValidateAndThrow(this);
 }
 public DijkstraResolve(ISet <DijkstraVertex> dijkstraVertices,
                        ICityMap cityMap, ICityPlace startPlace)
 {
     _dijkstraVertices = dijkstraVertices;
     CityMap           = cityMap;
     StartPlace        = startPlace;
 }
Exemple #3
0
 public CityRoad(ICityPlace firstPlace, ICityPlace secondPlace, RoadRank rank)
 {
     FirstPlace  = firstPlace;
     SecondPlace = secondPlace;
     Rank        = rank;
     CityRoadValidator.Instance.ValidateAndThrow(this);
 }
Exemple #4
0
        public DijkstraVertex(ICityPlace cityPlace)
        {
            CityPlace = cityPlace;

            IsVisited         = false;
            EdgesWeightSum    = double.MaxValue;
            PreviousCityPlace = null;
        }
Exemple #5
0
        public ICityRoad GetRoadBetween(ICityPlace firstCityPlace, ICityPlace secondCityPlace)
        {
            var road = Roads.FirstOrDefault(x =>
                                            x.FirstPlace == firstCityPlace && x.SecondPlace == secondCityPlace ||
                                            x.FirstPlace == secondCityPlace && x.SecondPlace == firstCityPlace);

            return(road);
        }
Exemple #6
0
        public IEnumerable <ICityPlace> GetNeighborCityPlaces(ICityPlace cityPlace)
        {
            var roads = GetRoadsFrom(cityPlace).ToArray();

            return(roads.Select(x => x.SecondPlace)
                   .Union(roads.Select(x => x.FirstPlace))
                   .Distinct()
                   .Except(new[] { cityPlace }));
        }
Exemple #7
0
        public IEnumerable <ICityRoad> GetRoadsFrom(ICityPlace cityPlace)
        {
            if (!Places.Contains(cityPlace))
            {
                throw new ArgumentException("Местоположение не принадлжеит городу.");
            }

            return(Roads
                   .Where(x => x.FirstPlace == cityPlace || x.SecondPlace == cityPlace)
                   .Distinct());
        }
        /// <summary>
        /// Находит ближайший путь до указанного местоположения.
        /// </summary>
        /// <param name="cityPlace">Местоположение до которого необходимо получить ближайший путь.</param>
        /// <returns>Путь <see cref="IRoute"/>.</returns>
        public IRoute FindShortRouteTo(ICityPlace cityPlace)
        {
            if (!CityMap.Places.Contains(cityPlace))
            {
                throw new ArgumentException("Местоположение не относится к текущему городу.");
            }

            var roads = new List <ICityRoad>();

            var vertex = _dijkstraVertices.GetDijkstraVertex(cityPlace);

            while (vertex.CityPlace != StartPlace)
            {
                var road = CityMap.GetRoadBetween(vertex.CityPlace, vertex.PreviousCityPlace);
                roads.Add(road);
                vertex = _dijkstraVertices.GetDijkstraVertex(vertex.PreviousCityPlace);
            }

            roads.Reverse();
            return(new Route(StartPlace, cityPlace, roads));
        }
Exemple #9
0
        public DijkstraResolve Resolve(ICityMap cityMap, ICityPlace startPoint)
        {
            _cityMap  = cityMap;
            _vertexes = InitDijkstraVertexes(cityMap.Places);

            _vertexes
            .First(x => x.CityPlace == startPoint)
            .EdgesWeightSum = 0;

            while (true)
            {
                var current = FindUnvisitedVertexWithMinSum();
                if (current == null)
                {
                    break;
                }

                SetOptimalWaysForNeighbor(current);
            }

            return(new DijkstraResolve(_vertexes, cityMap, startPoint));
        }
Exemple #10
0
 public static DijkstraVertex GetDijkstraVertex(this IEnumerable <DijkstraVertex> vertexes,
                                                ICityPlace cityPlace)
 {
     return(vertexes.First(x => x.CityPlace == cityPlace));
 }
Exemple #11
0
 public SelfWeightedCityRoad(ICityPlace firstPlace, ICityPlace secondPlace, double weight)
 {
     FirstPlace  = firstPlace;
     SecondPlace = secondPlace;
     Weight      = weight;
 }