Esempio n. 1
0
        static void Main(string[] args)
        {
            IAlgorithm simon  = new ElMansouryAlgorithm();
            IAlgorithm greedy = new LutsenkoAlgorithm();

            const int matricesNum = 40;

            const int workers  = 7;
            const int workNum  = 18;
            const int maxValue = 3;

            var rand = new Random();

            var effMatrices = new List <List <List <int> > >();

            for (int z = 0; z < matricesNum; z++)
            {
                var data = new List <List <int> >();

                for (int i = 0; i < workers; i++)
                {
                    data.Add(new int[workNum].ToList());
                }

                for (int i = 0; i < workers; i++)
                {
                    for (int j = 0; j < workNum; j++)
                    {
                        data[i][j] = rand.Next(0, maxValue);
                    }
                }

                effMatrices.Add(data);
            }

            effMatrices.ForEach(e =>
            {
                var result = GetEff(e, simon.Handle(e));
                var luts   = GetEff(e, greedy.Handle(e));

                Console.WriteLine($"Simon: {result}\t Luts: {luts}\t Diff: {result - luts}");
                Console.WriteLine();

                //Console.WriteLine(result.OrderBy(e => e[1])
                //    .Aggregate("", (current, ints) =>
                //        current + $"Работник {ints[0] + 1} - работа {ints[1] + 1}\n"));
            });
        }
Esempio n. 2
0
        private void ProcessAlgorithm(Algorithm algorithm)
        {
            try
            {
                var data = new List <List <int> >();

                for (int i = 0; i < WorkersCount; i++)
                {
                    var list = new List <int>();
                    for (int j = 0; j < TasksCount; j++)
                    {
                        list.Add(Int32.Parse(Controls[i.ToString() + " " + j.ToString()].Text));
                    }
                    data.Add(list);
                }
                var dataCopy = data.Select(x => x.ToList()).ToList();

                IAlgorithm algorithmHandler = new ElMansouryAlgorithm();// null;
                var        dataCopy2        = data.Select(x => x.ToList()).ToList();

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                var result = algorithmHandler.Handle(data);


                stopwatch.Stop();

                var z = result.OrderBy(e => e[1]).Aggregate("",
                                                            (current, ints) => current + $"Работник {ints[0] + 1} - работа {ints[1] + 1}" + Environment.NewLine);

                Controls.Add(new TextBox
                {
                    Location  = new Point(395, 587),
                    Size      = new Size(350, 350),
                    Text      = z,
                    Multiline = true
                });

                Stopwatch stopwatch2 = new Stopwatch();
                stopwatch2.Start();

                var result2 = new GreedyAlgorithm().Handle(dataCopy2);

                stopwatch2.Stop();


                int cf = 0;
                for (int i = 0; i < result.Count; i++)
                {
                    Controls[result[i][0].ToString() + " " + result[i][1].ToString()].BackColor = Color.LimeGreen;
                    cf += dataCopy[result[i][0]][result[i][1]];
                }

                int cf2 = 0;
                for (int i = 0; i < result2.Count; i++)
                {
                    cf2 += dataCopy[result2[i][0]][result2[i][1]];
                }

                CreateCfControls(cf, cf2);

                DisableOutputButtons();

                CreateTimeControl(stopwatch.Elapsed, stopwatch2.Elapsed);

                ActiveControl = null;
            }
            catch (FormatException)
            {
                MessageBox.Show("Ефективність виконання задачі повинна бути числом.");
            }
        }