public List <MapViewModel> GetMaps() { List <Map> maps = _repository.GetItems(); List <MapViewModel> mapViewModels = _mapper.Map <List <MapViewModel> >(maps); return(mapViewModels); }
private void CreateGraphs() { List <Map> maps = _mapRepository.GetItems(); List <Distance> distances = repository.GetItems(); List <Point> points = _pointRepository.GetItems(); List <DistanceViewModel> distanceViewModels = _mapper.Map <List <DistanceViewModel> >(distances); List <PointViewModel> pointViewModels = _mapper.Map <List <PointViewModel> >(points); List <MapViewModel> mapViewModels = _mapper.Map <List <MapViewModel> >(maps); allIndexes = new Dictionary <int, Dictionary <int, int> >(); graphs = new Dictionary <int, double[, ]>(); algorithms = new Dictionary <int, DijkstrasAlgorithm>(); foreach (var map in mapViewModels) { List <PointViewModel> currentPoints = pointViewModels.Where(p => p.MapId == map.Id).ToList(); if (currentPoints.Count == 0) { return; } List <int> pointsId = currentPoints.Select(p => p.Id).ToList(); Dictionary <int, int> indexes = new Dictionary <int, int>(); for (int i = 0; i < pointsId.Count; ++i) { indexes.Add(i, pointsId[i]); } allIndexes.Add(map.Id, indexes); int n = currentPoints.Count; double[,] graph = new double[n, n]; foreach (DistanceViewModel distance in distanceViewModels) { int i = indexes.FirstOrDefault(k => k.Value == distance.FromPointId).Key; int j = indexes.FirstOrDefault(k => k.Value == distance.ToPointId).Key; graph[i, j] = distance.Weight; graph[j, i] = distance.Weight; } graphs.Add(map.Id, graph); algorithms.Add(map.Id, new DijkstrasAlgorithm(graph)); } }