Пример #1
0
        void solver_NewGeneration(int generation, int stagnation_count, Population<List<int>, GeneticProblem, Fitness> population)
        {
            ProgressStatus status = new ProgressStatus();
            if(population[0].Fitness.Weight < _latest_fitness)
            {
                _latest_fitness = population[0].Fitness.Weight;

                status.CurrentNumber = stagnation_count + 1;
                status.TotalNumber = _stagnation_count;
                status.Message = string.Format("Found new {0}!", population[0].Fitness.Weight);
                status.Status = ProgressStatus.ProgressStatusEnum.Busy;
            }
            else
            {
                status.CurrentNumber = stagnation_count + 1;
                status.TotalNumber = _stagnation_count;
                status.Message = string.Format("Searching...", generation, stagnation_count + 1);
                status.Status = ProgressStatus.ProgressStatusEnum.Busy;
            }

            this.ReportProgress(status);
        }
Пример #2
0
 private void ReportProgress(ProgressStatus status)
 {
     if (_registered_progress_reporter != null)
     {
         _registered_progress_reporter.Report(status);
     }
 }
Пример #3
0
        /// <summary>
        /// Writes a delimited file using the given format.
        /// </summary>
        /// <param name="reporter"></param>
        /// <param name="data"></param>
        /// <param name="writer"></param>
        /// <param name="delimiter_type"></param>
        /// <param name="format"></param>
        public static void WriteDelimitedFile(
            IProgressReporter reporter,
            string[][] data,
            TextWriter writer,
            DelimiterType delimiter_type,
            IDelimitedFormat format)
        {
            // get the delimiter character
            char delimiter = GetDelimiterChar(delimiter_type);

            // initialize the progress status.
            ProgressStatus status = new ProgressStatus();
            if (reporter != null)
            {
                status.TotalNumber = data.Length;
                status.Status = ProgressStatus.ProgressStatusEnum.Busy;
                status.CurrentNumber = 0;
                status.Message = "Creating File...";

                // report the status.
                reporter.Report(status);
            }

            // export data
            if (reporter != null)
            {
                status.Message = "Exporting... {progress}!";
            }
            for (int idx = 0; idx < data.Length; idx++)
            {
                string[] line = data[idx];
                if (line != null &&
                    line.Length > 0)
                {
                    for (int col_idx = 0; col_idx < line.Length; col_idx++)
                    {
                        if (format.DoExport(idx))
                        {
                            object field_data = line[col_idx];
                            string field_data_string = format.ConvertValue(col_idx, field_data);
                            writer.Write(field_data_string);
                            // only delimiter at the end
                            if (col_idx < line.Length - 1)
                            {
                                writer.Write(delimiter);
                            }
                        }
                    }
                }
                if (reporter != null)
                {
                    status.CurrentNumber = idx + 1;
                    reporter.Report(status);
                }
                writer.WriteLine();
            }

            // report done
            if (reporter != null)
            {
                status.Message = "Exporting Done!";
                status.Status = ProgressStatus.ProgressStatusEnum.Succeeded;
                reporter.Report(status);
            }
        }
Пример #4
0
        /// <summary>
        /// Reads a delimited file.
        /// </summary>
        /// <param name="reporter"></param>
        /// <param name="file"></param>
        /// <param name="delimiter"></param>
        /// <param name="firstRowHasHeaders"></param>
        /// <returns></returns>
        public static string[][] ReadDelimitedFile(
            IProgressReporter reporter, 
            FileInfo file, 
            DelimiterType delimiter, 
            bool firstRowHasHeaders)
        {
            if (reporter == null)
            {
                reporter = EmptyProgressReporter.Instance;
            }

            char delimiterChar = DelimitedFileHandler.GetDelimiterChar(delimiter);

            List<string[]> delimited_data_set;
            //int iCounter = 0;
            ProgressStatus status;
            if (!file.Exists)
            {
                throw new FileNotFoundException(string.Format("Input file {0} not found!", file.FullName));
            }
            else
            {
                // Build dataset
                delimited_data_set = new List<string[]>();
                //Add the table               'Read the delimited file

                System.Text.Encoding enc = null;
                enc = System.Text.Encoding.GetEncoding("iso-8859-1");
                FileStream fileStream = new FileStream(file.FullName,
                    FileMode.Open, FileAccess.Read, FileShare.Read);
                StringBuilder strBuild = new StringBuilder(Convert.ToInt32(fileStream.Length));

                // report the status.
                status = new ProgressStatus();
                status.Status = ProgressStatus.ProgressStatusEnum.Busy;
                status.CurrentNumber = 0;
                status.Message = "Opening file...";

                reporter.Report(status);

                for (int i = 0; i <= Convert.ToInt32(fileStream.Length) - 1; i++)
                {
                    byte[] bytes = new byte[] {Convert.ToByte(fileStream.ReadByte())};
                    strBuild.Append(enc.GetString(bytes, 0, bytes.Length));
                }

                fileStream.Close();
                string str = strBuild.ToString();
                StringReader strReader = new StringReader(str);
                List<string> lines = new List<string>();
                while ((strReader.Peek() > -1)) {
                    lines.Add(strReader.ReadLine());
                }

                // Now add in the Rows
                // report the status.
                status = new ProgressStatus();
                status.Status = ProgressStatus.ProgressStatusEnum.Busy;
                status.CurrentNumber = 0;
                status.Message = "Reading file...";
                reporter.Report(status);

                int startLine = 0;
                if (firstRowHasHeaders)
                {
                    startLine = 1;
                }

                //Loop while there are rows in the delimited file
                for (int l = startLine; l < lines.Count; l++) {
                    string line = lines[l];

                    //Add the items to the DataSet
                    delimited_data_set.Add(line.Split(delimiterChar));

                    // report the status.
                    status = new ProgressStatus();
                    status.Status = ProgressStatus.ProgressStatusEnum.Busy;
                    status.CurrentNumber = l;
                    status.TotalNumber = lines.Count - 1;
                    status.Message = "Reading file...";
                    reporter.Report(status);
                }
            }

            // report the status.
            status = new ProgressStatus();
            status.Status = ProgressStatus.ProgressStatusEnum.Succeeded;
            status.CurrentNumber = 0;
            status.Message = "Reading file...";
            reporter.Report(status);

            return delimited_data_set.ToArray<string[]>();
        }
Пример #5
0
 /// <summary>
 /// Reports progress to this reporter.
 /// </summary>
 /// <param name="status"></param>
 public void Report(ProgressStatus status)
 {
 }