public Dictionary <int, Dictionary <int, double> > GenerateDistanceMatrix(Cluster clusterA, Cluster clusterB, bool isNonEvenMatrix) { Dictionary <int, Dictionary <int, double> > distanceMatrix = new Dictionary <int, Dictionary <int, double> >(); int idValue = 0; for (int id = 0; id < clusterA.dataPoints.Count; id++) { if (isNonEvenMatrix) { idValue = id; } else { idValue = 0; } Dictionary <int, double> distancesToOthers = new Dictionary <int, double>(); for (int otherID = idValue; otherID < clusterB.dataPoints.Count; otherID++) { double distance = distanceCalculator.CalculateDistance(clusterA.dataPoints[id].offers, clusterB.dataPoints[otherID].offers); distancesToOthers.Add(otherID, distance); } distanceMatrix.Add(id, distancesToOthers); } return(distanceMatrix); }
public IActionResult Create([Bind] DepartureInputModel departureInput) { if (!ModelState.IsValid) { TempData["msg"] = "Model is not valid!"; return(Create()); } Departure newDeparture = new Departure { CityFrom = _cityService.GetByName(departureInput.CityFrom), CityTo = _cityService.GetByName(departureInput.CityTo), Carrier = _carrierService.GetByName(departureInput.Carrier), PaymentCategory = _paymentCategoryService.GetByName(departureInput.PaymentCategory), Vehicle = _vehicleService.GetByRegistration(departureInput.VehicleRegistration) }; if (_cityService.IsSameCity(newDeparture.CityFrom, newDeparture.CityTo)) { TempData["msg"] = "Departure must be between two different cities!"; return(Create()); } newDeparture.Distance = _distanceService.CalculateDistance(newDeparture.CityFrom, newDeparture.CityTo); //TODO: create service for calculate price of card newDeparture.PriceOfCard = _priceService.CalculatePrice(newDeparture.Distance.DistanceBetween, newDeparture.PaymentCategory.Price); //TODO: get number of seats by vehicle newDeparture.NumberOfSeats = newDeparture.Vehicle.Capacity; if (_deparatureService.Add(newDeparture)) { TempData["msg"] = "Departure is created!"; } else { TempData["msg"] = "Departure is not created!"; } return(RedirectToPage("/Index")); }