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; }
public CityRoad(ICityPlace firstPlace, ICityPlace secondPlace, RoadRank rank) { FirstPlace = firstPlace; SecondPlace = secondPlace; Rank = rank; CityRoadValidator.Instance.ValidateAndThrow(this); }
public DijkstraVertex(ICityPlace cityPlace) { CityPlace = cityPlace; IsVisited = false; EdgesWeightSum = double.MaxValue; PreviousCityPlace = null; }
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); }
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 })); }
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)); }
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)); }
public static DijkstraVertex GetDijkstraVertex(this IEnumerable <DijkstraVertex> vertexes, ICityPlace cityPlace) { return(vertexes.First(x => x.CityPlace == cityPlace)); }
public SelfWeightedCityRoad(ICityPlace firstPlace, ICityPlace secondPlace, double weight) { FirstPlace = firstPlace; SecondPlace = secondPlace; Weight = weight; }