public ITrip CreateTrip() { Random random = new Random(); IAccomodation hotel; ITrip trip = new Trip(random.Next(1, 5)); for (int i = 0; i < trip.DaysCount; i++) { if (bookingIterator.HasNext()) { hotel = bookingIterator.GetCurrent(); } else { bookingIterator.Reset(); if (!bookingIterator.HasNext()) { trip.Hotels.Add(new Hotel()); continue; } hotel = bookingIterator.GetCurrent(); } hotel.Price = bookingDescrambler.Handle(hotel.Price); hotel.Rating = bookingDescrambler.Handle(hotel.Rating); trip.Hotels.Add(hotel); } return(trip); }
public IReview CreateReview() { if (oysteIterator.HasNext()) { return(oysteIterator.GetCurrent()); } oysteIterator.Reset(); if (!oysteIterator.HasNext()) { return(new Review()); } return(oysteIterator.GetCurrent()); }
public IPhoto CreatePhoto() { IPhoto photo; if (stockIterator.HasNext()) { photo = stockIterator.GetCurrent(); } else { stockIterator.Reset(); if (!stockIterator.HasNext()) { return(new Photo()); } photo = stockIterator.GetCurrent(); } photo.WidthPx = stockDescrambler.Handle(photo.WidthPx); photo.HeightPx = stockDescrambler.Handle(photo.HeightPx); return(photo); }
public ITrip CreateTrip() { ITrip trip = travelAgency.CreateTrip(); trip.Country = "Poland"; IAttraction attraction; for (int i = 0; i < trip.DaysCount; i++) { for (int j = 0; j < 3; j++) { do { if (tripAdvisorIterator.HasNext()) { attraction = tripAdvisorIterator.GetCurrent(); attraction.Rating = tripAdvisorDescrambler.Handle(attraction.Rating); attraction.Price = tripAdvisorDescrambler.Handle(attraction.Price); } else { tripAdvisorIterator.Reset(); if (!tripAdvisorIterator.HasNext()) { attraction = new Attraction(); break; } attraction = tripAdvisorIterator.GetCurrent(); attraction.Rating = tripAdvisorDescrambler.Handle(attraction.Rating); attraction.Price = tripAdvisorDescrambler.Handle(attraction.Price); } } while (attraction.Country != "Poland"); trip.Attractions[i].Add(attraction); } } return(trip); }
public IEnumerable <Route> Solve(IGraphDatabase graph, City from, City to) { Dictionary <City, Route> routes = new Dictionary <City, Route>(); routes[from] = null; Queue <City> queue = new Queue <City>(); queue.Enqueue(from); do { City city = queue.Dequeue(); /* * For each outgoing route from city... */ IDatabaseIterator <Route> iter = graph.GetRoutesFrom(city); while (iter.HasNext()) { Route route = iter.GetCurrent(); /* Change to current Route*/ if (routes.ContainsKey(route.To)) { continue; } routes[route.To] = route; if (route.To == to) { break; } queue.Enqueue(route.To); } } while (queue.Count > 0); if (!routes.ContainsKey(to)) { return(null); } List <Route> result = new List <Route>(); for (Route route = routes[to]; route != null; route = routes[route.From]) { result.Add(route); } result.Reverse(); return(result); }
public IEnumerable <Route> Solve(IGraphDatabase graph, City from, City to) { Dictionary <City, Route> routes = new Dictionary <City, Route>(); routes[from] = null; Stack <City> stack = new Stack <City>(); stack.Push(from); do { City city = stack.Pop(); IDatabaseIterator <Route> iter = graph.GetRoutesFrom(city); while (iter.HasNext()) { Route route = iter.GetCurrent(); /* Change to current Route*/ if (routes.ContainsKey(route.To)) { continue; } routes[route.To] = route; if (route.To == to) { break; } stack.Push(route.To); } } while (stack.Count > 0); if (!routes.ContainsKey(to)) { return(null); } List <Route> result = new List <Route>(); for (Route route = routes[to]; route != null; route = routes[route.From]) { result.Add(route); } result.Reverse(); return(result); }
public IEnumerable <Route> Solve(IGraphDatabase graph, City from, City to) { Dictionary <City, (double dist, Route last)> distances = new Dictionary <City, (double dist, Route last)>(); HashSet <City> visitedCitites = new HashSet <City>(); distances[from] = (0, null); City minCity = from; while (minCity != to) { /* * For each outgoing route from minCity... */ IDatabaseIterator <Route> iter = graph.GetRoutesFrom(minCity); while (iter.HasNext()) { Route route = iter.GetCurrent(); /* Change to current Route*/ if (visitedCitites.Contains(route.To)) { continue; } double dist = distances[minCity].dist + OptimizingValueFunc(route); if (!distances.ContainsKey(route.To)) { distances[route.To] = (dist, route); } else { if (dist < distances[route.To].dist) { distances[route.To] = (dist, route); } } } visitedCitites.Add(minCity); minCity = null; foreach (var(city, (dist, route)) in distances) { if (visitedCitites.Contains(city)) { continue; } if (minCity == null || dist < distances[city].dist) { minCity = city; } } if (minCity == null) { return(null); } } List <Route> result = new List <Route>(); for (Route route = distances[to].last; route != null; route = distances[route.From].last) { result.Add(route); } result.Reverse(); return(result); }
public Route GetCurrent() { return(iter.GetCurrent()); }