Example #1
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());
        }
Example #2
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);
        }