public static List <TourChiTietViewModel> Loc_CollaborativeFiltering(List <TourDaDatViewModel> cart, string maTourChon, int soLuongChon) { var dsTourGioHang = LayDSTourGioHang(cart); var bestCustomer = TimHoaDonTotNhat(dsTourGioHang, TimHD(maTourChon)); if (bestCustomer != null) { //Lay Ds rate bang duc lo Dictionary <string, double> ketQuaChiSoR = new Dictionary <string, double>(); foreach (var item in dsTourGioHang) { double sim; if (item.soluong == 0) { sim = bestCustomer.FirstOrDefault(t => t.matour == item.matour).soluong; } else { sim = item.soluong; } ketQuaChiSoR.Add(item.matour, sim); } //------------------------ var res = ketQuaChiSoR.OrderByDescending(t => t.Value).Select(t => t.Key).ToList(); int chiSoTourDangChon = res.FindIndex(t => t == maTourChon); res.RemoveAt(chiSoTourDangChon); var collection = res.Take(soLuongChon).ToList(); //Lay Chi tiet Tour List <TourChiTietViewModel> ketQua = new List <TourChiTietViewModel>(); if (collection.Count > 0) { foreach (var item in collection) { ketQua.Add(TourQueries.TimTour(item)); } } return(ketQua); } return(null); }