예제 #1
0
        private void button_StartSeries_Click(object sender, EventArgs e)
        {
            int consumersFrom = Convert.ToInt32(numericUpDown_ConsumersCountFrom.Value);
            int consumersTo = Convert.ToInt32(numericUpDown_ConsumersCountTo.Value);
            int consumersStep = Convert.ToInt32(numericUpDown_ConsumersCountStep.Value);

            int volumeFrom = Convert.ToInt32(numericUpDown_GeneratingVolumeFrom.Value);
            int volumeTo = Convert.ToInt32(numericUpDown_GeneratingVolumeTo.Value);

            int startsCount = Convert.ToInt32(numericUpDown_StartsInSeriesCount.Value);
            int modelsCount = Convert.ToInt32(numericUpDown_ModelsCount.Value);

            bool currentModel = checkBox_CurrentModel.Checked;

            int algorithmsCount = checkedListBox_AlgorithmType.CheckedIndices.Count;

            int seriesCount = currentModel ? 1 : (consumersTo - consumersFrom) / consumersStep + 1;

            string logFileName = textBox_LogFileName.Text;

            if (currentModel)
            {
                modelsCount = 1;
            }

            QuickAppendToFile(logFileName,
                              string.Format(
                                  "\n\n\n----- Series start. Clusters limit: {0}. Capacity limit: {1}. " +
                                  "Starts in each series: {2}. Models count: {3}. " +
                                  "Current model: {4}. Kilometer cost: {5:0.000}. Consumers count: {6}. Time: {7}",
                                  Convert.ToInt32(numericUpDown_ClustersCount.Value),
                                  Convert.ToInt32(numericUpDown_ClusterCapacityLimit.Value),
                                  startsCount, modelsCount, currentModel,
                                  KilometerCost,
                                  TaskController.ConsumersCount,
                                  DateTime.Now));

            for (int i = 0; i != seriesCount; i++)
            {
                int consumersCount = consumersFrom + i * consumersStep;

                if (!currentModel)
                {
                    QuickAppendToFile(logFileName,
                                      string.Format(
                                          "--- Series #{0} start. New models generate. Consumers count: {1}. Time: {2}",
                                          i,
                                          consumersCount,
                                          DateTime.Now));
                }
                else
                {
                    QuickAppendToFile(logFileName, string.Format("--- Series start. Time: {0}", DateTime.Now));
                }

                double[] valuesAvr = new double[algorithmsCount];
                double[] timesAvr = new double[algorithmsCount];

                for (int k = 0; k != algorithmsCount; k++)
                {
                    valuesAvr[k] = 0;
                    timesAvr[k] = 0;
                }

                for (int j = 0; j != modelsCount; j++)
                {
                    if (!currentModel)
                    {
                        TaskController.CreateNewModel();
                        GenerateNodes(consumersCount, volumeFrom, volumeTo, true);
                    }

                    for (int k = 0; k != algorithmsCount; k++)
                    {
                        checkedListBox_AlgorithmType.SelectedIndex = checkedListBox_AlgorithmType.CheckedIndices[k];

                        //QuickAppendToFile(logFileName,
                        //                  string.Format("Starting model series for algorithm {0}. Time: {1}",
                        //                                GetAlgorithmName(k),
                        //                                DateTime.Now));

                        List<double> values = new List<double>();
                        List<double> times = new List<double>();

                        for (int l = 0; l != startsCount; l++)
                        {
                            StartAlgorithm();
                            TaskController.Algorithm.LogFileName = "";

                            double time = IterateToStop() + CalculateTsp();

                            values.Add(TaskController.Algorithm.Value);
                            times.Add(time);

                            //QuickAppendToFile(logFileName,
                            //                  string.Format(
                            //                      "Start #{0} completed. Result: {1:0.00}. During the: {2:0.00} s. Time: {3}",
                            //                      l,
                            //                      values[l],
                            //                      times[l],
                            //                      DateTime.Now));
                        }

                        valuesAvr[k] += values.Average();
                        timesAvr[k] += times.Average();

                        //QuickAppendToFile(logFileName,
                        //                  string.Format(
                        //                      "Model series completed. Avr result: {0:0.00}. Avr time: {1:0.00} s. Time: {2}",
                        //                      values.Average(), times.Average(), DateTime.Now));
                    }
                }

                for (int k = 0; k != algorithmsCount; k++)
                {
                    valuesAvr[k] /= modelsCount;
                    timesAvr[k] /= modelsCount;

                    QuickAppendToFile(logFileName,
                                      string.Format("Algorithm {0}. Avr result: {1:0.00}. Avr time: {2:0.00} s",
                                                    GetAlgorithmName(checkedListBox_AlgorithmType.CheckedIndices[k]),
                                                    valuesAvr[k],
                                                    timesAvr[k]));
                }

                QuickAppendToFile(logFileName, string.Format("--- Series #{0} completed. Time: {1}", i, DateTime.Now));
            }

            QuickAppendToFile(logFileName,
                              string.Format(
                                  "----- All series completed. Time: {0}", DateTime.Now));
        }