private void simulateButton_Click(object sender, RoutedEventArgs e)
        {
            //Method();// true 3
            //Channel.duplex = false;
            //Method();// false 3
            //SystemVertex.maxChannels = 1;
            //Method();// false 1
            //Channel.duplex = true;
            //Method();// true 1
            //return;
            //generateButton_Click(null, null);
            if (!CheckTaskGraph())
            {
                MessageBox.Show("There is a cycle in this graph", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (!CheckSystemGraph(vm.Graph2))
            {
                MessageBox.Show("Some vertices are not reachable", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            scheduler = new Scheduler(vm, this);
            int critRoot = list4[list4.Count - 1].TimeFromStart;
            stats.Text += "Critical root for this graph is " + critRoot + Environment.NewLine;

            int W = 0;
            foreach (var item in vm.Graph.Vertices)
            {
                W += int.Parse(item.Weight);
            }
            int Nmin = W / critRoot;
            Nmin = W % critRoot > 0 ? Nmin + 1 : Nmin;
            stats.Text += "Time on one kernel is " + W + Environment.NewLine;
            stats.Text += "Nmin = " + Nmin + Environment.NewLine;
            stats.Text += new string('-', 50) + Environment.NewLine;

            int time = scheduler.Simulate(list2, data11, scheduler.GetRandomProcessor);
            double Ku = W / (double)time;
            stats.Text += "Variant 1.1; T = " + time + Environment.NewLine;
            stats.Text += "Variant 1.1; Ku = " + Ku + Environment.NewLine;
            stats.Text += "Variant 1.1; Ke = " + (Ku / vm.Graph2.VertexCount) + Environment.NewLine;
            stats.Text += "Variant 1.1; Kp = " + (critRoot / (double)time) + Environment.NewLine;
            stats.Text += new string('-', 50) + Environment.NewLine;

            time = scheduler.Simulate(list3, data12, scheduler.GetRandomProcessor);
            Ku = W / (double)time;
            stats.Text += "Variant 1.2; T = " + time + Environment.NewLine;
            stats.Text += "Variant 1.2; Ku = " + Ku + Environment.NewLine;
            stats.Text += "Variant 1.2; Ke = " + (Ku / vm.Graph2.VertexCount) + Environment.NewLine;
            stats.Text += "Variant 1.2; Kp = " + (critRoot / (double)time) + Environment.NewLine;
            stats.Text += new string('-', 50) + Environment.NewLine;

            time = scheduler.Simulate(list4, data13, scheduler.GetRandomProcessor);
            Ku = W / (double)time;
            stats.Text += "Variant 1.3; T = " + time + Environment.NewLine;
            stats.Text += "Variant 1.3; Ku = " + Ku + Environment.NewLine;
            stats.Text += "Variant 1.3; Ke = " + (Ku / vm.Graph2.VertexCount) + Environment.NewLine;
            stats.Text += "Variant 1.3; Kp = " + (critRoot / (double)time) + Environment.NewLine;
            stats.Text += new string('-', 50) + Environment.NewLine;

            time = scheduler.Simulate(list2, data21, scheduler.GetBestProcessor);
            Ku = W / (double)time;
            stats.Text += "Variant 2.1; T = " + time + Environment.NewLine;
            stats.Text += "Variant 2.1; Ku = " + Ku + Environment.NewLine;
            stats.Text += "Variant 2.1; Ke = " + (Ku / vm.Graph2.VertexCount) + Environment.NewLine;
            stats.Text += "Variant 2.1; Kp = " + (critRoot / (double)time) + Environment.NewLine;
            stats.Text += new string('-', 50) + Environment.NewLine;

            time = scheduler.Simulate(list3, data22, scheduler.GetBestProcessor);
            Ku = W / (double)time;
            stats.Text += "Variant 2.2; T = " + time + Environment.NewLine;
            stats.Text += "Variant 2.2; Ku = " + Ku + Environment.NewLine;
            stats.Text += "Variant 2.2; Ke = " + (Ku / vm.Graph2.VertexCount) + Environment.NewLine;
            stats.Text += "Variant 2.2; Kp = " + (critRoot / (double)time) + Environment.NewLine;
            stats.Text += new string('-', 50) + Environment.NewLine;

            time = scheduler.Simulate(list4, data23, scheduler.GetBestProcessor);
            Ku = W / (double)time;
            stats.Text += "Variant 2.3; T = " + time + Environment.NewLine;
            stats.Text += "Variant 2.3; Ku = " + Ku + Environment.NewLine;
            stats.Text += "Variant 2.3; Ke = " + (Ku / vm.Graph2.VertexCount) + Environment.NewLine;
            stats.Text += "Variant 2.3; Kp = " + (critRoot / (double)time) + Environment.NewLine;
            stats.Text += new string('-', 50) + Environment.NewLine;

            MessageBox.Show("OK", "", MessageBoxButton.OK);
        }
        void Method()
        {
            double[] time, Ku, Ke, Kp;
            time = new double[6];
            Ku = new double[6];
            Ke = new double[6];
            Kp = new double[6];
            for (int i = 0; i < 1; i++)
            {
                //generateButton_Click(null, null);
                if (!CheckTaskGraph())
                {
                    MessageBox.Show("There is a cycle in this graph", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                scheduler = new Scheduler(vm, this);
                int critRoot = list4[list4.Count - 1].TimeFromStart;
                stats.Text += "Critical root for this graph is " + critRoot + Environment.NewLine;

                int W = 0;
                foreach (var item in vm.Graph.Vertices)
                {
                    W += int.Parse(item.Weight);
                }
                int Nmin = W / critRoot;
                Nmin = W % critRoot > 0 ? Nmin + 1 : Nmin;
                stats.Text += "Time on one kernel is " + W + Environment.NewLine;
                stats.Text += "Nmin = " + Nmin + Environment.NewLine;
                stats.Text += new string('-', 50) + Environment.NewLine;
                double t = 0;

                //t = scheduler.Simulate(list2, data11, scheduler.GetRandomProcessor);
                //time[0] += t;
                //Ku[0] += W / t;
                //Ke[0] += W / t / vm.Graph2.VertexCount;
                //Kp[0] += critRoot / t;

                //t = scheduler.Simulate(list3, data12, scheduler.GetRandomProcessor);
                //time[1] += t;
                //Ku[1] += W / t;
                //Ke[1] += W / t / vm.Graph2.VertexCount;
                //Kp[1] += critRoot / t;

                //t = scheduler.Simulate(list4, data13, scheduler.GetRandomProcessor);
                //time[2] += t;
                //Ku[2] += W / t;
                //Ke[2] += W / t / vm.Graph2.VertexCount;
                //Kp[2] += critRoot / t;

                //t = scheduler.Simulate(list2, data21, scheduler.GetBestProcessor);
                //time[3] += t;
                //Ku[3] += W / t;
                //Ke[3] += W / t / vm.Graph2.VertexCount;
                //Kp[3] += critRoot / t;

                //t = scheduler.Simulate(list3, data22, scheduler.GetBestProcessor);
                //time[4] += t;
                //Ku[4] += W / t;
                //Ke[4] += W / t / vm.Graph2.VertexCount;
                //Kp[4] += critRoot / t;

                t = scheduler.Simulate(list4, data23, scheduler.GetBestProcessor);
                time[5] += t;
                Ku[5] += W / t;
                Ke[5] += W / t / vm.Graph2.VertexCount;
                Kp[5] += critRoot / t;
            }
            for (int i = 5; i < 6; i++)
            {
                stats.Text += string.Format("{0} {1} {2} {3}\n", time[i], Ku[i], Ke[i], Kp[i]);
            }
            MessageBox.Show("OK", "", MessageBoxButton.OK);
        }