private static List <int> nearestNeighborIndexes = new List <int>(); // List that stores nearest neighbor indexes of neighbors #endregion #region ClusterComputer Main Computer public static void Start(GPSAS_DestinationsForm _instance, String _workingDirectory, String _fileName) { // Assign parent form instance GPSAS_DestinationsFormInstance = _instance; // Set working directory workingDirectory = _workingDirectory; // Load data point list into an array arrData = DataPoints.ToArray(); Logger.Log("Number of valid data points: " + arrData.Length.ToString()); // Displose of datapoint list DataPoints.Clear(); // Log parameters logParameters(); // Run main computer function try { computeClusters(); } catch (Exception ex) { Logger.Log("Unable to compute clusters for file: " + _fileName); Logger.Log(ex.ToString()); if (ex is OutOfMemoryException) { MessageBox.Show("OutOfMemoryException. Computations are too large for this machine.", "Failure"); } else if (ex is OverflowException) { MessageBox.Show("OverflowException. Bounds of types have been exceeded. Parameters must be reduced to compute.", "Failure"); } else { MessageBox.Show("Parse failed.", "Failure"); } return; } // Identify instance cluster times Dictionary <int, Double> clusterTimes = identifyClustersTimes(); // Identify total times in area clusters Dictionary <int, Double> areaTimes = identifyAreaTimes(clusterTimes); // Write the results writeResults(_fileName, clusterTimes, areaTimes); }
/// <summary> /// Reads the provided excel file into a data set. /// </summary> /// <param name="parentInstance">Instance of parent form</param> /// <param name="fileName">File name to be parsed.</param> public static void ReadData(GPSAS_DestinationsForm parentInstance, String fileName) { parentInstance.SetStatusText("Reading file"); // Create file stream FileStream stream = File.Open(fileName, FileMode.Open, FileAccess.Read); // Create excel reader instance IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); // Column names ARE in first row, but they are needed to determine column names excelReader.IsFirstRowAsColumnNames = false; // Assign data to DataSet DataSet dataSet = excelReader.AsDataSet(); // Clean up excelReader.Close(); stream.Close(); // Parse data parseDataSet(dataSet); }
/// <summary> /// Constructor. /// </summary> /// <param name="_path">Working directory to save report.</param> /// <param name="_arrData">Array of cluster data.</param> /// <param name="_numClusters">Number of clusters.</param> /// <param name="_instance">Instance of parent form.</param> public ExcelWriter(String _path, DataPoint[] _arrData, Dictionary <int, Double> _clusterTimes, Dictionary <int, Double> _areaTimes, GPSAS_DestinationsForm _instance) { this.path = _path; this.arrData = _arrData; this.instance = _instance; this.clusterTimes = _clusterTimes; this.areaTimes = _areaTimes; this.app = new Application(); this.workBook = workBook = app.Workbooks.Add(System.Reflection.Missing.Value); // Generate report generateReport(); // Select sheet and save workbook workBook.Application.ActiveWorkbook.Sheets[1].Select(); workBook.SaveAs(this.path, XlFileFormat.xlWorkbookDefault); // Release memory, close writer ReleaseObject(workBook); ReleaseObject(workSheet); app.Quit(); ReleaseObject(app); }