示例#1
0
        public void updateStationDict()
        {
            stationOverlay.Markers.Clear();

            stationOverlay.Polygons.Clear();

            stationDict = simulator.getStationDict();

            foreach (KeyValuePair <string, DroneStation> dict in stationDict)
            {
                DroneStation stationElement = dict.Value;
                string       name           = stationElement.name;
                double       latitude       = stationElement.stationLat;
                double       longitude      = stationElement.stationLng;
                double       coverRange     = stationElement.coverRange;
                drawStationPoint(stationElement);
            }
            stationMap.Overlays.Add(stationOverlay);
            stationMap.Zoom = 9;
            stationMap.SetPositionByKeywords("Seoul, Korea");


            textBox1.Text = simulator.getEventList().Count.ToString();
            textBox2.Text = stationDict.Count.ToString();

            int droneCnt = 0;

            foreach (KeyValuePair <string, DroneStation> dict in stationDict)
            {
                DroneStation stationElement = dict.Value;
                droneCnt += stationElement.drones.Count;
            }

            textBox3.Text = droneCnt.ToString();
        }
示例#2
0
        public void stationArrival(Event ev)
        {
            DroneStation station    = ev.getStation();
            int          droneIndex = ev.getDroneIndex();
            Drone        drone      = station.drones[droneIndex];

            drone.setStatus(Drone.droneType.D_CHARGING);
            drone.setChargeStartTime(ev.getOccuredDate());
        }
        public Tuple <string, int> findAvailableDrone()
        {
            DateTime currentTime = e.getOccuredDate();

            foreach (KeyValuePair <string, DroneStation> dict in stationDict)
            {
                DroneStation st       = dict.Value;
                double       distance = getDistanceFromRecentEvent(st.stationLat, st.stationLng);

                if (st.coverRange > distance)
                {
                    availableStation a = new availableStation();
                    a.name     = dict.Key;
                    a.distance = distance;
                    availableStations.Add(a);
                }
            }
            if (availableStations.Count == 0)
            {
                Console.WriteLine("No available stations (coverage problem)");
                e.setResult(Event.eventResult.FAILURE);
                e.setReason(Event.failReason.COVERAGE_PROBLEM);
                return(new Tuple <string, int>("", -1));
            }
            else
            {
                availableStations = availableStations.OrderBy(n => n.distance).ToList();
                foreach (availableStation ast in availableStations)
                {
                    DroneStation s = stationDict[ast.name];

                    s.updateChargingDrones(currentTime);
                    if (s.drones.Count == 0)
                    {
                        continue;
                    }
                    else
                    {
                        foreach (Drone droneElement in s.drones)
                        {
                            double distance = getDistanceFromRecentEvent(s.stationLat, s.stationLng);

                            if (droneElement.returnStatus() != Drone.droneType.D_FLYING && droneElement.returnAvailDist() > 2 * distance)
                            {
                                return(new Tuple <string, int>(s.name, s.drones.IndexOf(droneElement)));
                            }
                        }
                    }
                }
                Console.WriteLine("No available drones in available stations");
                e.setResult(Event.eventResult.FAILURE);
                e.setReason(Event.failReason.NO_DRONE);
                return(new Tuple <string, int>("", -1));
            }
        }
示例#4
0
        public Event(double _lat, double _lng, DateTime _oDate, DateTime _ambulDate, eventType _type)
        {
            lat = _lat;
            lng = _lng;

            occuredDate = _oDate;
            ambulDate   = _ambulDate;
            droneDate   = new DateTime();
            type        = _type;
            result      = 0;
            station     = null;
        }
示例#5
0
        private void drawStationPoint(DroneStation droneStation)
        {
            string name       = droneStation.name;
            double lat        = droneStation.stationLat;
            double lng        = droneStation.stationLng;
            double coverRange = droneStation.coverRange;

            GMarkerGoogle stationMarker = new GMarkerGoogle(new PointLatLng(lat, lng), GMarkerGoogleType.blue_small);

            stationMarker.ToolTipText = name;
            stationMarker.ToolTipMode = MarkerTooltipMode.OnMouseOver;
            stationOverlay.Markers.Add(stationMarker);
        }
示例#6
0
        public Event(double _lat, double _lng, DateTime _oDate, DateTime _ambulDate, eventType _type, Address _addr, double[] _weather, bool[] _b_weather)
        {
            lat = _lat;
            lng = _lng;

            occuredDate = _oDate;
            ambulDate   = _ambulDate;
            droneDate   = new DateTime();
            type        = _type;
            result      = 0;
            station     = null;
            addr        = _addr;
            weather     = _weather;
            b_weather   = _b_weather;
        }
        private void eventTable_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            int ind = e.RowIndex;

            eventDetailTable.Rows.Clear();
            initGMapControl();
            if (ind < 0 || ind >= eventTable.RowCount - 1)
            {
                return;
            }
            if (eventList[ind].getResult() != Event.eventResult.SUCCESS)
            {
                return;
            }

            string msg = "";

            for (int i = 0; i < 6; i++)
            {
                msg += eventTable.Rows[ind].Cells[i].Value.ToString() + " / ";
            }

            double lat = eventList[ind].getCoordinates().Item1;
            double lng = eventList[ind].getCoordinates().Item2;

            DateTime occuredTime = eventList[ind].getOccuredDate();
            DateTime droneTime   = eventList[ind].getDroneDate();
            DateTime ambulTime   = eventList[ind].getAmbulDate();

            double droneSec = Math.Round((droneTime - occuredTime).TotalSeconds);
            double ambulSec = (ambulTime - occuredTime).TotalSeconds;

            string droneGap = "" + (int)(droneSec / 60) + "' " + (droneSec % 60) + "\"";
            string ambulGap = "" + (int)(ambulSec / 60) + "' " + (ambulSec % 60) + "\"";

            DroneStation station = eventList[ind].getStation();

            eventDetailTable.Rows.Clear();
            eventDetailTable.Rows.Add(station.name, station.stationLat, station.stationLng, droneGap, ambulGap);
            stationOverlay.Markers.Clear();
            eventMap.Overlays.Clear();

            drawEventPoint(lat, lng);
            drawStationPoint(station);
        }
 private void PopulateDataGridView()
 {
     try
     {
         foreach (KeyValuePair <string, DroneStation> dict in stationDict)
         {
             DroneStation stationElement = dict.Value;
             string       name           = stationElement.name;
             double       latitude       = stationElement.stationLat;
             double       longitude      = stationElement.stationLng;
             int          droneCnt       = stationElement.droneCnt;
             stationName.DataGridView.Rows.Add(name, latitude, longitude, droneCnt);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void drawStationPoint(DroneStation droneStation)
        {
            string name       = droneStation.name;
            double lat        = droneStation.stationLat;
            double lng        = droneStation.stationLng;
            double coverRange = droneStation.coverRange;

            PointLatLng p = new PointLatLng(lat, lng);

            drawCircle(p, coverRange);

            GMarkerGoogle stationMarker = new GMarkerGoogle(p, GMarkerGoogleType.blue_small);

            stationMarker.ToolTipText = name;
            stationMarker.ToolTipMode = MarkerTooltipMode.OnMouseOver;
            stationOverlay.Markers.Add(stationMarker);

            eventMap.Overlays.Add(stationOverlay);

            eventMap.Position = p;
            eventMap.Zoom     = 12;
        }
        private void applyButton_Click(object sender, EventArgs e)
        {
            stationDict.Clear();
            for (int i = 0; i < stationTable.RowCount; i++)
            {
                string       name         = (string)stationTable.Rows[i].Cells[0].Value;
                double       latitude     = (double)stationTable.Rows[i].Cells[1].Value;
                double       longitude    = (double)stationTable.Rows[i].Cells[2].Value;
                int          droneCnt     = (int)stationTable.Rows[i].Cells[3].Value;
                Address      addr         = new Address(latitude, longitude);
                DroneStation droneStation = new DroneStation(name, latitude, longitude, simulator.maxDistance / 2, addr);
                droneStation.droneCnt = droneCnt;
                stationDict.Add(name, droneStation);
            }

            stationTable.Rows.Clear();
            PopulateDataGridView();
            drawStations();
            clearTextBox();
            selectStation(0);
            drawSelectedStation(0);
        }
示例#11
0
        public void eventArrived(Event ev)
        {
            //time to return to the Drone Station
            PathPlanner pathPlanner = PathPlanner.getInstance();
            double      calculatedTime;
            double      eventLat = ev.getCoordinates().Item1;
            double      eventLng = ev.getCoordinates().Item2;

            double[] weather   = ev.getWeather();
            bool[]   b_weather = ev.get_b_weather();

            DroneStation station    = ev.getStation();
            int          droneIndex = ev.getDroneIndex();
            Drone        drone      = station.drones[droneIndex];
            double       stationLat = station.stationLat;
            double       stationLng = station.stationLng;

            calculatedTime = pathPlanner.calcTravelTime(eventLat, eventLng, stationLat, stationLng, maxSpeed, weather);

            //time when drone reach the station
            DateTime droneArrivalTime = ev.getOccuredDate().AddSeconds(calculatedTime);

            //battery consumption
            DroneStationFinder f        = new DroneStationFinder(ev);
            double             distance = f.getDistanceFromRecentEvent(stationLat, stationLng);

            drone.fly(distance);

            //event of arriving
            Event.eventType type = Event.eventType.E_STATION_ARRIVAL;
            Event           e    = new Event(eventLat, eventLng, droneArrivalTime, droneArrivalTime, type);

            e.setStationDroneIdx(station, droneIndex);

            eventSet.Add(e, e);
        }
示例#12
0
 public void setStationDroneIdx(DroneStation _station, int _droneIndex)
 {
     station    = _station;
     droneIndex = _droneIndex;
 }
示例#13
0
        public void eventOccured(Event ev)
        {
            Tuple <double, double> coordinates = ev.getCoordinates();
            DateTime occuredTime = ev.getOccuredDate();

            double[] weather   = ev.getWeather();
            bool[]   b_weather = ev.get_b_weather();

            ev.setResult(Event.eventResult.FAILURE);

            // temp, rain, wind, snow, sight, light
            if (w_temp_high < weather[0] || weather[0] < w_temp_low || (weather[0] < 0 && !p_subzero))
            {
                ev.setReason(Event.failReason.WEAHTER);
                ev.setWthFailRsn(0);
            }
            if (b_weather[1] && (!p_rain || w_rain < weather[1]))
            {
                ev.setReason(Event.failReason.WEAHTER);
                ev.setWthFailRsn(1);
            }
            if (w_winds < weather[2])
            {
                ev.setReason(Event.failReason.WEAHTER);
                ev.setWthFailRsn(2);
            }
            if (b_weather[3] && (!p_snow || weather[4] > w_snow))
            {
                ev.setReason(Event.failReason.WEAHTER);
                ev.setWthFailRsn(3);
            }
            if (weather[5] < w_sight && weather[5] > 0)
            {
                ev.setReason(Event.failReason.WEAHTER);
                ev.setWthFailRsn(4);
            }
            if (b_weather[2] && !p_light)
            {
                ev.setReason(Event.failReason.WEAHTER);
                ev.setWthFailRsn(5);
            }

            if (ev.getReason() == Event.failReason.WEAHTER)
            {
                return;
            }

            //find stations and drone
            DroneStationFinder  finder          = new DroneStationFinder(ev);
            Tuple <string, int> stationDroneIdx = finder.findAvailableDrone();

            if (stationDroneIdx.Item1.Length == 0)
            {
                return;
            }

            DroneStation s     = stationDict[stationDroneIdx.Item1];
            Drone        drone = s.drones[stationDroneIdx.Item2];

            double distance = finder.getDistanceFromRecentEvent(s.stationLat, s.stationLng);

            //calculate time
            PathPlanner pathPlanner = PathPlanner.getInstance();
            double      calculatedTime;

            calculatedTime = pathPlanner.calcTravelTime(s.stationLat, s.stationLng, coordinates.Item1, coordinates.Item2, maxSpeed, weather);

            DateTime droneArrivalTime = ev.getOccuredDate().AddSeconds(calculatedTime);

            ev.setDroneDate(droneArrivalTime);
            ev.setResult(Event.eventResult.SUCCESS);
            ev.setStationDroneIdx(s, stationDroneIdx.Item2);
            //battery consumption
            drone.fly(distance);
            drone.setStatus(Drone.droneType.D_FLYING);

            //declare coming event
            Event.eventType type = Event.eventType.E_EVENT_ARRIVAL;
            Event           e    = new Event(coordinates.Item1, coordinates.Item2, droneArrivalTime, droneArrivalTime, type, ev.getAddress(), weather, b_weather);

            e.setStationDroneIdx(s, stationDroneIdx.Item2);

            eventSet.Add(e, e);
        }
示例#14
0
        public string getStationsFromCSV(string fpath)
        {
            try
            {
                if (stationDict.Count != 0)
                {
                    stationDict.Clear();
                }
                Encoding encode = System.Text.Encoding.GetEncoding("ks_c_5601-1987");
                System.IO.StreamReader readFile = new System.IO.StreamReader(fpath);

                /*
                 * string filePath = @"../../StationAddress.csv";
                 * StringBuilder sb = new StringBuilder();
                 */
                while (!readFile.EndOfStream)
                {
                    var line   = readFile.ReadLine();
                    var record = line.Split(',');
                    if (record.Length != 4)
                    {
                        throw new Exception("Inappropriate CSV format\nCannot be read");
                    }

                    string name       = record[0];
                    double latitude   = System.Convert.ToDouble(record[1]);
                    double longitude  = System.Convert.ToDouble(record[2]);
                    int    droneCnt   = System.Convert.ToInt32(record[3]);
                    double coverRange = maxDistance / 2;

                    DroneStation s = new DroneStation(name, latitude, longitude, coverRange, droneCnt);
                    for (int i = 0; i < droneCnt; i++)
                    {
                        s.drones.Add(new Drone(maxDistance, 20));
                    }
                    stationDict.Add(name, s);

                    /*
                     * Address addr = new Address(latitude, longitude);
                     * string[] rec = addr.ToString().Split(new string[] { " " }, StringSplitOptions.None);
                     * Console.WriteLine(addr.ToString());
                     * stationDict.Add(name, new DroneStation(name, latitude, longitude, coverRange, addr));
                     *
                     * sb.AppendLine(string.Join(",", rec));
                     */
                }

                /*
                 * File.WriteAllText(filePath, sb.ToString(), Encoding.Default);
                 */
                readFile.Close();

                String path = Application.StartupPath + @"\StationAddress.csv";
                System.IO.StreamReader readStationAddressFile = new System.IO.StreamReader(path, encode);

                foreach (DroneStation s in stationDict.Values)
                {
                    var line   = readStationAddressFile.ReadLine();
                    var record = line.Split(',');
                    if (record.Length < 4)
                    {
                        throw new Exception("Too Short Address");
                    }

                    string premise = "";
                    for (int i = 4; i < record.Length; i++)
                    {
                        premise += record[i] + " ";
                    }

                    Address addr = new Address(record[0], record[1], record[2], record[3], premise);
                    s.setStationAddress(addr);
                }
                readStationAddressFile.Close();
            }
            catch (Exception e)
            {
                return(e.ToString());
            }
            return(null);
        }