private void RunFromFile_Click(object sender, RoutedEventArgs e)
        {
            var problem = FileProcessing.ReadProblemFromFile(_filename);

            if (problem == null)
            {
                ExceptionLabel.Foreground = Brushes.DarkRed;
                ExceptionLabel.Content    = Properties.Resources.ExceptionLabelIncorrectFileFormat;
                return;
            }
            ExceptionLabel.Content = "";
            var solution = problem.Run();
            var window   = new SolutionWindow(solution, problem);

            window.Show();
        }
Ejemplo n.º 2
0
        private void RunButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!int.TryParse(SizeBox.Text, out int N))
                {
                    throw new Exception(Properties.Resources.ExceptionLabelIntegerN);
                }
                if (N <= 0)
                {
                    throw new Exception(Properties.Resources.ExceptionLabelPositiveN);
                }

                if (!int.TryParse(RBox.Text, out int R))
                {
                    throw new Exception(Properties.Resources.ExceptionLabelIntegerR);
                }
                if (R <= 0)
                {
                    throw new Exception(Properties.Resources.ExceptionLabelPositiveR);
                }
                if (DistributionComboBox.SelectedItem == null)
                {
                    throw new Exception(Properties.Resources.ExceptionLabelDistributionCNOTChosen);
                }
                if (DistributionComboBoxAB.SelectedItem == null)
                {
                    throw new Exception(Properties.Resources.ExceptionLabelDistributionABNOTChosen);
                }
                if (DistributionComboBoxL.SelectedItem == null)
                {
                    throw new Exception(Properties.Resources.ExceptionLabelDistributionLNOTChosen);
                }


                double delay, deviation, a, b;

                (double, double)paramsC;
                (double, double)paramsAB;
                (double, double)paramsL;
                (string, string, string)distribution;

                var item = (ComboBoxItem)DistributionComboBox.SelectedItem;
                switch (item.Name)
                {
                case "exp":
                    if (!double.TryParse(DelayMeanBox.Text, out delay))
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelDelayNumeric);
                    }
                    if (delay <= 0)
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelDelayPositive);
                    }
                    deviation          = -1.0;
                    a                  = -1.0;
                    b                  = -1.0;
                    distribution.Item1 = "Exponential";
                    paramsC            = (delay, delay);
                    break;

                case "norm":
                    if (!double.TryParse(DelayMeanBox.Text, out delay))
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelDelayNumeric);
                    }
                    if (delay <= 0)
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelDelayPositive);
                    }
                    if (!double.TryParse(DeviationBox.Text, out deviation))
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelDeviationNumeric);
                    }
                    if (deviation <= 0)
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelDeviationPositive);
                    }
                    a = -1.0;
                    b = -1.0;
                    distribution.Item1 = "Normal";
                    paramsC            = (delay, deviation);
                    break;

                default:
                    if (!double.TryParse(DelayMeanBox.Text, out a) || !double.TryParse(DeviationBox.Text, out b))
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelRangeNumbers);
                    }
                    if (b - a < 0)
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelRangePositive);
                    }
                    if (a < 0)
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelRangeStartsInPositive);
                    }
                    delay              = -1.0;
                    deviation          = -1.0;
                    distribution.Item1 = "Uniform";
                    paramsC            = (a, b);
                    break;
                }

                var itemAB = (ComboBoxItem)DistributionComboBoxAB.SelectedItem;
                switch (itemAB.Name)
                {
                case "exp1":
                    if (!double.TryParse(DelayMeanBoxAB.Text, out delay))
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelDelayNumeric);
                    }
                    if (delay <= 0)
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelDelayPositive);
                    }
                    deviation          = -1.0;
                    a                  = -1.0;
                    b                  = -1.0;
                    distribution.Item2 = "Exponential";
                    paramsAB           = (delay, delay);
                    break;

                case "norm1":
                    if (!double.TryParse(DelayMeanBoxAB.Text, out delay))
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelDelayNumeric);
                    }
                    if (delay <= 0)
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelDelayPositive);
                    }
                    if (!double.TryParse(DeviationBoxAB.Text, out deviation))
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelDeviationNumeric);
                    }
                    if (deviation <= 0)
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelDeviationPositive);
                    }
                    a = -1.0;
                    b = -1.0;
                    distribution.Item2 = "Normal";
                    paramsAB           = (delay, deviation);
                    break;

                default:
                    if (!double.TryParse(DelayMeanBoxAB.Text, out a) || !double.TryParse(DeviationBoxAB.Text, out b))
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelRangeNumbers);
                    }
                    if (b - a < 0)
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelRangePositive);
                    }
                    if (a < 0)
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelRangeStartsInPositive);
                    }
                    delay              = -1.0;
                    deviation          = -1.0;
                    distribution.Item2 = "Uniform";
                    paramsAB           = (a, b);
                    break;
                }

                var itemL = (ComboBoxItem)DistributionComboBoxL.SelectedItem;
                switch (itemL.Name)
                {
                case "exp2":
                    if (!double.TryParse(DelayMeanBoxL.Text, out delay))
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelDelayNumeric);
                    }
                    if (delay <= 0)
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelDelayPositive);
                    }
                    deviation          = -1.0;
                    a                  = -1.0;
                    b                  = -1.0;
                    distribution.Item3 = "Exponential";
                    paramsL            = (delay, delay);
                    break;

                case "norm2":
                    if (!double.TryParse(DelayMeanBoxL.Text, out delay))
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelDelayNumeric);
                    }
                    if (delay <= 0)
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelDelayPositive);
                    }
                    if (!double.TryParse(DeviationBoxL.Text, out deviation))
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelDeviationNumeric);
                    }
                    if (deviation <= 0)
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelDeviationPositive);
                    }
                    a = -1.0;
                    b = -1.0;
                    distribution.Item3 = "Normal";
                    paramsL            = (delay, deviation);
                    break;

                default:
                    if (!double.TryParse(DelayMeanBoxL.Text, out a) || !double.TryParse(DeviationBoxL.Text, out b))
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelRangeNumbers);
                    }
                    if (b - a < 0)
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelRangePositive);
                    }
                    if (a < 0)
                    {
                        throw new Exception(Properties.Resources.ExceptionLabelRangeStartsInPositive);
                    }
                    delay              = -1.0;
                    deviation          = -1.0;
                    distribution.Item3 = "Uniform";
                    paramsL            = (a, b);
                    break;
                }

                ExceptionLabel.Content = "";
                var     generator = new GeneratorTaskCondition(distribution, paramsC, paramsAB, paramsL);
                Problem problem   = new Problem(N, R, generator, CChangeParameters.Default);
                var     solution  = problem.Run();
                var     window    = new SolutionWindow(solution, problem);
                window.Show();
            }
            catch (Exception ex)
            {
                ExceptionLabel.Content = ex.Message;
            }
        }