示例#1
0
 public IDatabaseIterator <Route> GetRoutesFrom(City from)
 {
     if (hasRestaurant)
     {
         return(new HasRestaurantIterator(database.GetRoutesFrom(from)));
     }
     return(database.GetRoutesFrom(from));
 }
示例#2
0
        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)
            {
                var it = graph.GetRoutesFrom(minCity);
                while (it.Get() != null)
                {
                    Route route = it.Get();                     /* Change to current Route*/
                    it.Next();                                  // my line

                    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 IIterator <Route> GetRoutesFrom(City from)
 {
     if (condition.IsTrueFor(from))
     {
         return(new FilteredRouteIterator(database.GetRoutesFrom(from), condition));
     }
     else
     {
         return(new ListIterator <Route>(new List <Route>()));
     }
 }
        public override Iterator <Route> GetRoutesFrom(City from)
        {
            Iterator <Route> toRet = base.GetRoutesFrom(from);
            Iterator <Route> toAdd = toMerge.GetRoutesFrom(from);

            if (toAdd.IsEmpty() || !yes)
            {
                return(toRet);
            }
            for (Route curr = toAdd.Next(); curr != null; curr = toAdd.Next())
            {
                toRet.Add(curr);
            }
            return(toRet);
        }
示例#5
0
        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...
                 */
                Iterator <Route> i = graph.GetRoutesFrom(city);
                if (i.IsEmpty())
                {
                    continue;
                }
                for (Route curr = i.Next(); curr != null; curr = i.Next())
                {
                    Route route = curr;                     /* 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);
        }
示例#6
0
 public void Merging(IGraphDatabase another)
 {
     foreach (var item in cityDictionary)
     {
         City city = another.GetByName(item.Key);
         if (city != null)
         {
             foreach (Route route in another.GetRoutesFrom(city))
             {
                 if (!routes[city].Contains(route))
                 {
                     AddRoute(route.From, route.To, route.Cost, route.TravelTime, route.VehicleType);
                 }
             }
         }
     }
 }
示例#7
0
        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();

                /*
                 * For each outgoing route from city...
                 */
                var it = graph.GetRoutesFrom(city);
                it.Start();
                while (it.IsNextExist())
                {
                    Route route = it.Next;                     /* 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);
        }
示例#8
0
        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();
                IIterator <Route> iterator = graph.GetRoutesFrom(city);
                while (!iterator.IsDone())
                {
                    Route route = iterator.GetNext();
                    if (route == null)
                    {
                        continue;
                    }

                    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);
        }
示例#9
0
        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();
                // ======
                var it = graph.GetRoutesFrom(city);
                while (it.Get() != null)
                {
                    Route route = it.Get();        /* Change to current Route*/
                    it.Next();                     // moja linijka

                    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 IDatabaseIterator <Route> GetRoutesFrom(City from)
 {
     return(new PopulationIterator(database.GetRoutesFrom(from), minPopulation));
 }
        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...
                 */
                for (var it = graph.GetRoutesFrom(minCity); it.Current != null; it.Next())
                {
                    Route route = it.Current; /* 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)

                //since foreach in dictionary returns a key-value pair instead of a tuple in .NET framework 4.7.1,
                //I replaced the original foreach statement with an equivalent
                foreach (var pair in distances)
                {
                    var city  = pair.Key;
                    var dist  = pair.Value.dist;
                    var route = pair.Value.last;
                    //end of replacement

                    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);
        }
示例#12
0
 public IDatabaseItterator GetRoutesFrom(City from)
 {
     return(new FilteredItterator(database.GetRoutesFrom(from), filter));
 }
 public virtual Iterator <Route> GetRoutesFrom(City from)
 {
     return(graphDatabase.GetRoutesFrom(from));
 }
 public virtual IIterator GetRoutesFrom(City from)
 {
     return(database.GetRoutesFrom(from));
 }