public void Put(double priority, Location loc)
 {
     if (!priorityList.ContainsValue(loc))
     {
         priorityList.Add(priority, loc);
     }
 }
 public Battery GetBatteryByTypeAndLocation(BatteryType batteryType, Location location)
 {
     return (from batteryStation in this.context.BatteryStations
             from battery in batteryStation.Batteries
             where battery.BatteryType == batteryType && batteryStation.ID == location.ID
             select battery).AsNoTracking().FirstOrDefault();
 }
Beispiel #3
0
 public Boolean RemoveLocation(Location l)
 {
     Boolean res = false;
     if (l != null)
     {
         res = this.Locations.Remove(l.ID);
     }
     return res;
 }
Beispiel #4
0
        public void AddLocation(Location location)
        {
            if (this.Locations == null)
            {
                this.Locations = new Dictionary<int, Location>();
            }

            this.Locations.Add(location.ID, location);
            this.NumberOfLocations++;
        }
        public Location CreateLocation(int id, double longitude, double latitude, int type)
        {
            var location = new Location
            {
                ID = id,
                Latitude = latitude,
                Longitude = longitude,
                Type = type,
            };

            this.locationRepository.InsertLocation(location);
            this.locationRepository.Save();
            return location;
        }
        public Route PlanRoute(int fromID, int toID, int batteryID)
        {
            LocationCtr locationCtr = new LocationCtr();
            this.From = locationCtr.FindLocation(fromID);
            this.To = locationCtr.FindLocation(toID);
            To.GeoCoordinate.Longitude = To.Longitude;
            To.GeoCoordinate.Latitude = To.Latitude;

            GenerateGraph();

            this.queue = new PriorityQueue(graph.Count());

            route.Range = new BatteryCtr().CalculateRange(batteryID);
            route.Path = CalculatePath();
            route.Distance = GetDistanceList(route.Path);

            return route;
        }
Beispiel #7
0
        public void AddConnection(Location from, Location to, double weight)
        {
            // Get the matching locations in this graph
            from = this.Locations[from.ID];
            to = this.Locations[to.ID];

            // 
            if (!from.Adjacents.ContainsKey(from.ID))
            {
                from.Adjacents.Add(to.ID, weight);
                NumberOfConnections++;
            }

            if (!to.Adjacents.ContainsKey(to.ID))
            {
                to.Adjacents.Add(from.ID, weight);
                NumberOfConnections++;
            }
        }
        public Route PlanRoute(int fromID, int toID, int batteryID)
        {
            BatteryCtr batteryCtr = new BatteryCtr();
            LocationCtr locationCtr = new LocationCtr();
            this.From = locationCtr.FindLocation(fromID);
            this.To = locationCtr.FindLocation(toID);

            // Initialize graph
            GenerateGraph();

            // Calculate distance the vehicle can travel before recharging
            route.Range = batteryCtr.CalculateRange(batteryID);

            // Determine shortest path using Dijsktras Shortest Path Algorithm
            route.Path = CalculatePath();

            route.Distance = GetDistanceList(route.Path);

            return route;
        }
 public void UpdateLocation(Location location)
 {
     this.locationRepository.UpdateLocation(location);
     this.locationRepository.Save();
 }
Beispiel #10
0
 public Dictionary<int, double> GetAdjacencies(Location l)
 {
     return l.Adjacents;
 }
 public void UpdateLocation(Location location)
 {
     this.context.Entry(location).State = EntityState.Modified;
 }
 public Connection(Location from, Location to, double distance)
 {
     this.From = from;
     this.To = to;
     this.Distance = distance;
 }
        private void Relax(Location current, Dictionary<int, double> adjacents, double minDistance, int fromId)
        {
            Console.WriteLine("[DEBUG MESSAGE]: Relax() Start");

            if (adjacents.Count > 0)
            {
                // Iterate over a key view set of the adjacents collection
                foreach (int i in adjacents.Keys)
                {
                    // Get the distance to the current adjacent vertex
                    double d = adjacents[i];

                    // Den korteste afstand til den nuværende node + afstanden til dens adjacent
                    // Check om denne afstand er bedre end den nuværende afstand fra start til i

                    // IF the shortest distance to current location (minDistance) plus the distance
                    // to its adjacent i, is less than the distance from current location to i
                    if (d + minDistance < Distance[i])
                    {
                        // Assign the lesser value to i
                        //Double currentDistance = d + minDistance;
                        Distance[i] = d + minDistance;
                        // Set i in Path to the location ID, indicating this vertex will be traversed.
                        Path[i] = fromId;

                        Console.WriteLine("[DEBUG MESSAGE]: Relax(): i: {2}, Distance[i]: {0}, Path[i]: {1}", Distance[i], Path[i], i);
                    }
                }
            }
            Console.WriteLine("[DEBUG MESSAGE]: Relax() End");
        }
        public void ReadChargingStations()
        {
            string locations = @".\..\..\chargingstations.xml";
            reader = XmlReader.Create(locations);

            Location loc = null;
            this.chargingStationList = new List<Location>();

            while (reader.Read())
            {
                if ((reader.NodeType == XmlNodeType.Element))
                {
                    string switchCase = reader.Name;
                    switch (switchCase)
                    {
                        case "RECORD":
                            loc = new Location();
                            chargingStationList.Add(loc);
                            break;

                        case "longitude":
                            reader.Read();
                            string longitude = reader.Value;
                            loc.Longitude = Convert.ToDouble(reader.Value, System.Globalization.CultureInfo.InvariantCulture);
                            //Console.WriteLine(loc.Longitude);
                            break;

                        case "latitude":
                            reader.Read();
                            loc.Latitude = Convert.ToDouble(reader.Value, System.Globalization.CultureInfo.InvariantCulture);
                            //Console.WriteLine(loc.Latitude);
                            break;

                        case "id":
                            reader.Read();
                            loc.ID = Convert.ToInt16(reader.Value);
                            //Console.WriteLine(loc.Id);
                            break;

                        case "type":
                            reader.Read();
                            loc.Type = Convert.ToInt16(reader.Value);
                            //Console.WriteLine(loc.Type);
                            break;
                    }
                }
            }
        }
        public void CalculatePath(Location from, Location to)
        {
            Console.WriteLine("[DEBUG MESSAGE]: CalculatePath() Start");

            if (from != null && null != to)
            {
                // Set distance to start point. Set distance to all other vertices to 0.
                // Initialize graph, setting all vertices to default (0).
                InitializeShortestPath(from);

                while (graph.Count() > 0)
                {
                    // Retrieve the location with the shortest distance
                    Location current = GetNodeWithMinWeight();
                    Console.WriteLine("[DEBUG MESSAGE]: CalculatePath() Current Location: {0}", current);

                    // IF the retrieved location is not the destination
                    // THEN get that distance, along with the retrieved locations
                    // adjacents. Relax these.
                    if (!current.Equals(to))
                    {
                        // Get the distance from the 'closest' vertex
                        double minDistance = Distance[current.ID];
                        Console.WriteLine("[DEBUG MESSAGE]: CalculatePath() Minimum Distance: {0}", minDistance);
                        // Get all adjacents from the 'closest' vertex
                        Dictionary<int, double> adjacents = current.Adjacents;
                        // Determine shortest path to the 'closest' object's adjacents.
                        // Update Distance with the new distances.
                        Relax(current, adjacents, minDistance, current.ID);
                    }
                    else
                    {
                        // Empty the graph as we have what we need now.
                        graph.Clear();
                    }
                }
            }
            else
            {
                throw new ArgumentNullException("Locations has to be initialized.");
            }
            Console.WriteLine("[DEBUG MESSAGE]: CalculatePath() End");
        }
        private void InitializeShortestPath(Location from)
        {
            Console.WriteLine("[DEBUG MESSAGE]: InitializeShortestPath() Start");

            // Iterate over a location collection key view.
            // for each key in graph.Locations.Keys
            // DO: Set the distance to all vertices from startpoint to positive infinity
            // DO: Add key to the path collection with value 0. Above 0 indicates a vertice is
            // travelled through.
            foreach (int i in graph.Locations.Keys)
            {
                // Set distance to i to positive infinity
                Distance[i] = Double.PositiveInfinity;
                // Add i to path with the value 0 (not traversed in path)
                Path[i] = 0;
            }

            // Set euclidian distance to start vertex to previously
            // determined distance.
            Distance[from.ID] = MinDistanceToStart;

            Console.WriteLine("[DEBUG MESSAGE]: InitializeShortestPath() End");
        }
 public Battery GetBatteryByTypeAndLocation(BatteryType batteryType, Location loc)
 {
     return this.batteryRepository.GetBatteryByTypeAndLocation(batteryType, loc);
 }
 public void UpdateLocation(Location location)
 {
     controller.UpdateLocation(location);
 }
 public void InsertLocation(Location location)
 {
     this.context.Locations.Add(location);
 }
 /// <summary>
 /// Initializes the Path and Distance properties and fills them with starting values.
 /// </summary>
 private void Initialize(Location from)
 {
     foreach (int i in graph.Locations.Keys)
     {
         Distance[i] = double.PositiveInfinity;
         Path[i] = 0;
     }
     Distance[From.ID] = 0;
     queue.Put(0, from);
 }
Beispiel #21
0
 public bool ContainsLocation(Location l)
 {
     throw new NotImplementedException();
 }