Ejemplo n.º 1
0
        private void loadDataButton_Click(object sender, EventArgs e)
        {
            StreamReader reader = new StreamReader(File.Open("input.dat", FileMode.Open));
            List <int[]> col    = new List <int[]>();
            int          i      = 0;

            while (!reader.EndOfStream)
            {
                string[] str = reader.ReadLine().Split(' ');
                col.Add(new int[str.Length]);
                for (int j = 0; j < str.Length; j++)
                {
                    col[i][j] = Convert.ToInt32(str[j]);
                }
                i++;
            }
            reader.Close();

            if (!EqualLenthes(col))
            {
                MessageBox.Show("Столбцы имееют разное количество элементов");
                return;
            }
            columns = col.ToArray();

            newColumns   = new int[columns.Length][];
            downtimes    = new int[columns.Length][];
            newDowntimes = new int[columns.Length][];
            for (i = 0; i < columns.Length; i++)
            {
                newColumns[i]   = Algorithm.copyMassive(columns[i]);
                downtimes[i]    = new int[columns[0].Length];
                newDowntimes[i] = new int[columns[0].Length];
                for (int j = 0; j < columns[0].Length; j++)
                {
                    downtimes[i][j]    = 0;
                    newDowntimes[i][j] = 0;
                }
            }

            AddToList1();

            if (columns.Length == 2)
            {
                Algorithm.JohnsonsAlgorithm(newColumns[0], newColumns[1]);
            }

            if (columns.Length == 3)
            {
                Algorithm.JohnsonsAlgorithm(newColumns[0], newColumns[1], newColumns[2]);
            }

            AddToList2();

            Algorithm.CountDowntimes(columns, downtimes);
            Algorithm.CountDowntimes(newColumns, newDowntimes);

            answerLabel1.Text = "Время: " + (Algorithm.summ(columns[columns.Length - 1]) + Algorithm.summ(downtimes[downtimes.Length - 1])).ToString();
            answerLabel2.Text = "Время: " + (Algorithm.summ(newColumns[newColumns.Length - 1]) + Algorithm.summ(newDowntimes[newDowntimes.Length - 1])).ToString();
        }