Esempio n. 1
0
        private void ReadSimulatedEvents()
        {
            StreamReader reader = new StreamReader("simulationEvents.csv");
            string       line   = reader.ReadLine();

            while (line != null)
            {
                string[] values        = line.Split(',');
                double   lat           = double.Parse(values[0]);
                double   lon           = double.Parse(values[1]);
                DateTime occurenceTime = DateTime.Parse(values[2]);
                simulatedEventList.Add(new OHCAEvent(lat, lon, occurenceTime));
                line = reader.ReadLine();
            }
            reader.Close();

            StreamWriter file = new StreamWriter("events.csv");

            for (int i = 0; i < simulatedEventList.Count; i++)
            {
                OHCAEvent e = simulatedEventList[i];
                file.Write(e.lat + "," + e.lon + "," + e.occurrenceTime + "\n");
            }
            file.Close();
        }
 public OHCAEvent(OHCAEvent e)
 {
     this.lat            = e.lat;
     this.lon            = e.lon;
     this.pixelRow       = e.pixelRow;
     this.pixelCol       = e.pixelCol;
     this.occurrenceTime = e.occurrenceTime;
     this.eventID        = e.eventID;
 }
        private void ReadEventData()
        {
            Excel.Application excelApp = null;
            Excel.Workbook    wb       = null;
            Excel.Worksheet   ws       = null;

            try
            {
                excelApp = new Excel.Application();
                wb       = excelApp.Workbooks.Open(Environment.CurrentDirectory.ToString() + "\\data.xls");
                ws       = wb.Worksheets.get_Item(1) as Excel.Worksheet;
                Excel.Range rng = ws.UsedRange;
                // Excel.Range rng = ws.Range[ws.Cells[2, 1], ws.Cells[5, 3]];

                object[,] data = rng.Value;
                for (int r = 2; r <= data.GetLength(0); r++)
                {
                    try
                    { // TODO
                        double    lat            = double.Parse(data[r, 15].ToString());
                        double    lon            = double.Parse(data[r, 16].ToString());
                        DateTime  occurrenceTime = DateTime.Parse(data[r, 19].ToString());
                        OHCAEvent e = new OHCAEvent(lat, lon, occurrenceTime);
                        eventList.Add(e);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                }
                wb.Close(true);
                excelApp.Quit();
            }
            finally
            {
                ReleaseExcelObject(ws);
                ReleaseExcelObject(wb);
                ReleaseExcelObject(excelApp);
            }
        }
Esempio n. 4
0
        private static double[][] ConvertEntities <T>(T[] items)
        {
            var type = typeof(T);
            var data = new List <double[]>();

            // If the type is an array type
            if (type.IsArray && type.IsAssignableFrom(typeof(double[])))
            {
                foreach (var item in items)
                {
                    var val = item as double[];
                    data.Add(val);
                }
                return(data.ToArray());
            }

            var getters = new List <MethodInfo>();

            // Iterate over the type and extract all the properties that have the KMeansValueAttribute set and use them as attributes
            var attribType = typeof(KMeansValueAttribute);

            foreach (var property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                var attribs = property.GetCustomAttributes(attribType, false).OfType <KMeansValueAttribute>().ToArray();
                if (attribs.Length <= 0)
                {
                    continue;
                }

                var getter = property.GetGetMethod();
                if (getter == null)
                {
                    throw new InvalidOperationException("No public getter for property '" + property.Name + "'. All properties marked with the KMeansValueAttribute must have a public getter");
                }

                if (!property.PropertyType.IsAssignableFrom(typeof(double)) &&
                    !property.PropertyType.IsAssignableFrom(typeof(int)) &&
                    !property.PropertyType.IsAssignableFrom(typeof(float)) &&
                    !property.PropertyType.IsAssignableFrom(typeof(long)) &&
                    !property.PropertyType.IsAssignableFrom(typeof(decimal)) &&
                    !property.PropertyType.IsAssignableFrom(typeof(short)))
                {
                    throw new InvalidOperationException("Property type '" + property.PropertyType.Name + "' for property '" + property.Name + "' cannot be assigned to System.Double. ");
                }

                getters.Add(getter);
            }

            foreach (var item in items)
            {
                //List<double> values = new List<double>(getters.Count);
                //foreach (var getter in getters)
                //    values.Add(Convert.ToDouble(getter.Invoke(item, null)));
                //data.Add(values.ToArray());

                OHCAEvent e = item as OHCAEvent;
                data.Add(new double[] { e.lat, e.lon });
            }

            return(data.ToArray());
        }
Esempio n. 5
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]);
        }