Exemplo n.º 1
0
        public double GetOverallSurvivalRate(ref List <RubisStation> stationList, RubisStation movedStation)
        {
            InitRubisStation(ref stationList, ref cellList, ref movedStation);

            // Calculates the survival rate for each cell
            double overallSum   = AsyncContext.Run(() => ComputeSurvivalRate(cellList));
            double survivalRate = overallSum / cellList.Count;

            return(survivalRate);
        }
Exemplo n.º 2
0
        private int GetNearestStation(List <RubisStation> rStationList, ref Counter counter, OHCAEvent e)
        {
            int n = rStationList.Count;

            int[]    index    = new int[n];
            double[] distance = new double[n];

            for (int i = 0; i < n; i++)
            {
                RubisStation s = rStationList[i];
                index[i]    = i;
                distance[i] = pathPlanner.CalculateFlightTime(s.lat, s.lon, e.lat, e.lon);

                for (int j = i; j > 0; j--)
                {
                    if (distance[j] < distance[j - 1])
                    {
                        int temp = index[j];
                        index[j]     = index[j - 1];
                        index[j - 1] = temp;
                        double tem = distance[j];
                        distance[j]     = distance[j - 1];
                        distance[j - 1] = tem;
                    }
                }
            }

            bool isReachable = false;
            int  k           = 0;

            for (; k < n; k++)
            {
                if (distance[k] <= Utils.GOLDEN_TIME)
                {
                    isReachable = true;
                    if (counter.whenReady[index[k]].Count < rStationList[index[k]].droneList.Count)
                    {
                        break;
                    }
                }
            }

            if (k == n)
            {
                return(isReachable ? -1 : -2);
            }

            return(index[k]);
        }
Exemplo n.º 3
0
        private double ComputeSurvivalRateDoWork(WorkObject workObject)
        {
            double sum = 0.0;

            foreach (RubisCell cell in workObject.cellList)
            {
                double pSum = 0.0;
                foreach (StationDistancePair pair in cell.stations)
                {
                    RubisStation s    = pair.station;
                    double       prob = (1 - pSum) * ProbabilityMassFunction(s.droneList.Count - 1, s.pdfSum);
                    pSum = pSum + prob;
                    cell.survivalRate = cell.survivalRate + (prob * CalculateSurvivalRate(pair.distance));
                }
                sum += cell.survivalRate;
            }
            return(sum);
        }
        public RubisStation(RubisStation s)
        {
            this.stationID  = s.stationID;
            this.lat        = s.lat;
            this.lon        = s.lon;
            this.pixelRow   = s.pixelRow;
            this.pixelCol   = s.pixelCol;
            this.eventCount = s.eventCount;

            droneList = new List <Drone>();
            for (int i = 0; i < s.droneList.Count; i++)
            {
                this.droneList.Add(new Drone(s.stationID));
            }

            cellList = new List <RubisCell>();
            foreach (RubisCell c in s.cellList)
            {
                this.cellList.Add(new RubisCell(c));
            }
            pdfSum = s.pdfSum;
        }
Exemplo n.º 5
0
        private double ComputeSurvivalRateDoWork(WorkObject workObject)
        {
            double sum = 0.0;

            foreach (RubisCell cell in workObject.cellList)
            {
                double pSum = 0.0;
                foreach (StationDistancePair pair in cell.stations)
                {
                    RubisStation s     = pair.station;
                    int          index = rStationList.IndexOf(s);
                    if (workObject.ready[index] > 0)
                    {
                        double prob = (1 - pSum) * ProbabilityMassFunction(workObject.ready[index] - 1, Utils.DRONE_REST_TIME * 60 * s.pdfSum);
                        pSum += prob;
                        cell.survivalRate = cell.survivalRate + (prob * CalculateSurvivalRate(pair.distance));
                    }
                }
                sum += cell.survivalRate;
            }
            return(sum);
        }
Exemplo n.º 6
0
        private double GetOverallSurvivalRate(RubisStation targetStation, Counter counter, bool dispatch)
        {
            RubisStation tempStation = new RubisStation(targetStation);

            int[] ready = new int[rStationList.Count];
            for (int i = 0; i < rStationList.Count; i++)
            {
                ready[i] = rStationList[i].droneList.Count - counter.whenReady[i].Count;
            }

            if (dispatch == true)
            {
                int index = rStationList.IndexOf(tempStation);
                ready[index]--;
            }

            // Calculates the survival rate for each cell
            double overallSum   = AsyncContext.Run(() => ComputeSurvivalRate(tempStation.cellList, ready));
            double survivalRate = overallSum / tempStation.cellList.Count;

            return(survivalRate);
        }
Exemplo n.º 7
0
        private void InitRubisStation(ref List <RubisStation> stationList, ref List <RubisCell> cellList, ref RubisStation movedStation)
        {
            foreach (RubisCell cell in movedStation.cellList)
            {
                int index = -1;
                for (int i = 0; i < cell.stations.Count; i++)
                {
                    StationDistancePair pair = cell.stations[i];
                    if (pair.station.lat == movedStation.lat && pair.station.lon == movedStation.lon)
                    {
                        index = i;
                    }
                }
                if (index != -1)
                {
                    cell.stations.RemoveAt(index);
                }
            }

            movedStation.pdfSum = 0.0;
            movedStation.cellList.Clear();

            foreach (RubisCell cell in cellList)
            {
                cell.survivalRate = 0.0;
                double time = simulator.GetPathPlanner().CalculateFlightTime(cell.lat, cell.lon, movedStation.lat, movedStation.lon);
                if (time <= Utils.GOLDEN_TIME)
                {
                    cell.stations.Add(new StationDistancePair(movedStation, time));
                    movedStation.cellList.Add(cell);
                }
            }

            // Sorts stationList ordered by distance
            foreach (RubisCell cell in movedStation.cellList)
            {
                cell.stations.Sort((a, b) => a.distance >= b.distance ? 1 : -1);
            }

            // Calculates the average probabilty of including cells for each station
            foreach (RubisCell cell in movedStation.cellList)
            {
                movedStation.pdfSum += cell.pdf;
            }
        }
Exemplo n.º 8
0
 public StationDistancePair(RubisStation station, double distance)
 {
     this.station  = station;
     this.distance = distance;
 }