示例#1
0
        private (List <int>, List <int>) getSeasonIndexLists(SubtypeDataEntity subtypeData)
        {
            List <int> HotIndexList  = new List <int>();
            List <int> ColdIndexList = new List <int>();

            for (int i = 0; i < Tour.Count(); i++)
            {
                PlaceEntity el = Tour.ElementAt(i);
                if (el is AttractionEntity)
                {
                    if (subtypeData.season.ContainsKey(((AttractionEntity)el).Subtype[0]["name"]))
                    {
                        if (subtypeData.season[((AttractionEntity)el).Subtype[0]["name"]] == "hot")
                        {
                            HotIndexList.Add(i);
                        }
                        else if (subtypeData.season[((AttractionEntity)el).Subtype[0]["name"]] == "cold")
                        {
                            ColdIndexList.Add(i);
                        }
                    }
                }
            }
            return(HotIndexList, ColdIndexList);
        }
示例#2
0
        private List <int> getOutdoorIndexList(SubtypeDataEntity subtypeData)
        {
            List <int> indexList = new List <int>();

            for (int i = 0; i < Tour.Count(); i++)
            {
                PlaceEntity el = Tour.ElementAt(i);
                if (el is AttractionEntity)
                {
                    if (subtypeData.is_outdoor.ContainsKey(((AttractionEntity)el).Subtype[0]["name"]))
                    {
                        if (subtypeData.is_outdoor[((AttractionEntity)el).Subtype[0]["name"]])
                        {
                            indexList.Add(i);
                        }
                    }
                    else
                    {
                        indexList.Add(i);
                    }
                }
            }
            return(indexList);
        }
示例#3
0
        public double GetRatingOf(PlaceEntity place)
        {
            IEnumerable <PlaceEntity> resp = Tour.Where(p => p.Name == place.Name).ToList();

            return(double.Parse(resp.ElementAt(0).Rating, System.Globalization.CultureInfo.InvariantCulture));
        }
示例#4
0
        public TourModel GetNRandomPlaces(int maxTime, int[] timeList, WeatherEntity weather, SubtypeDataEntity subtypeData, bool addRestaurant, string savedPlaces)
        {
            List <PlaceEntity> newTourList = new List <PlaceEntity>();

            bool addedRestaurant = false;

            if (savedPlaces != null)
            {
                var places = new List <string>(savedPlaces.Split(','));
                for (int i = 0; i < places.Count(); i++)
                {
                    places[i] = places[i].Trim('"', '[', ']');
                }
                foreach (string name in places)
                {
                    PlaceEntity place = Tour.Where(i => i.Name == name).FirstOrDefault();
                    if (place != null)
                    {
                        newTourList.Add(place);
                        maxTime -= 45;
                        Tour     = Tour.Where(u => u.Name != place.Name).ToList();
                    }
                }
                if (addedRestaurant)
                {
                    bool             found      = false;
                    RestaurantEntity restaurant = new RestaurantEntity();
                    foreach (string name in places)
                    {
                        restaurant = Restaurants.Where(i => i.Name == name).FirstOrDefault();
                        if (restaurant != null)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        newTourList.Add(restaurant);
                        Restaurants     = Restaurants.Where(u => u.Name != restaurant.Name).ToList();
                        addedRestaurant = true;
                    }
                }
            }

            if (!addedRestaurant)
            {
                if (addRestaurant)
                {
                    double[] restaurantRatings = new double[Restaurants.Count()];
                    for (int i = 0; i < Restaurants.Count(); i++)
                    {
                        restaurantRatings[i] = double.Parse(Tour.ElementAt(i).Rating, System.Globalization.CultureInfo.InvariantCulture);
                    }

                    int restaurant_index = GetRandomRestaurantIndex(restaurantRatings);

                    newTourList.Add(Restaurants.ElementAt(restaurant_index));

                    Restaurants = Restaurants.Where(u => u.Name != Restaurants.ElementAt(restaurant_index).Name).ToList();
                }
            }

            double[] ratings = new double[Tour.Count()];

            for (int i = 0; i < Tour.Count(); i++)
            {
                if (Tour.ElementAt(i).Rating != null)
                {
                    ratings[i] = double.Parse(Tour.ElementAt(i).Rating, System.Globalization.CultureInfo.InvariantCulture);
                }
                else
                {
                    ratings[i] = 3;
                }
            }

            List <int> index_list = GetRandomIndexList(ratings, timeList, maxTime, weather, subtypeData);

            foreach (int i in index_list)
            {
                newTourList.Add(Tour.ElementAt(i));
            }



            int[] index_array = index_list.ToArray();

            foreach (int i in index_array)
            {
                Tour = Tour.Where(u => u.Name != Tour.ElementAt(i).Name).ToList();

                for (int j = 0; j < index_array.Length; j++)
                {
                    if (index_array[j] > i)
                    {
                        index_array[j] -= 1;
                    }
                }
            }

            return(new TourModel(newTourList));
        }
示例#5
0
        public void Remove(PlaceEntity place)
        {
            IEnumerable <PlaceEntity> modified = Tour.Where(p => p.Name != place.Name).ToList();

            Tour = modified;
        }