Exemplo n.º 1
0
        public void start(bool dbg, out String s)
        {
            s = "";
            Task tsk;
            int[][] x;
            double f;
            int i = 1;

            if (dbg)
            {
                s += "Начальные оценки: \n";
                s += "x*: \n";
                s += printOptimalMatrix(_x, _n);
                s += String.Format("f* = {0}\n", _f);
                s += "\n";
            }
            while (_taskList.Count > 0)
            {
                if (dbg)
                {
                    s += String.Format("Число задач в списке S: {0}.\n", _taskList.Count);
                    s += String.Format("Итерация № {0}\n", i);
                    i++;
                }
                tsk = _taskList.Dequeue();
                if (dbg)
                    s += "Решается задача: \n" + tsk.ToString();

                VengerAlgorithm va = new VengerAlgorithm(tsk.toVengerMatrix());
                va.start(false, out x, out f);
                if (dbg)
                {
                    s += "x: \n";
                    s += printOptimalMatrix(x, _n);
                    s += String.Format("f = {0} \n", f);
                }

                // полученное значение целевой функции меньше текущего?
                if (f < _f)
                {
                    List<Loop> loops = getSubLoops(x);
                    if (loops.Count == 1)
                    {
                        _f = f;
                        _x = x;
                        if (dbg)
                        {
                            s += "Полученное решение является полным подциклом; \n";
                            s += String.Format("x* = x, f* = {0}\n", _f);
                            s += "\n";
                        }
                    }
                    else
                    {
                        if (dbg)
                        {
                            s += "Подциклы: ";
                            foreach (Loop l in loops)
                                s += l.ToString() + ";";
                            s += "\n\n";
                        }
                        Loop min = getMinLoops(loops);
                        addNewTasks(min, tsk);
                    }
                }
            }
            if (dbg)
                s += "Список задач S пуст.\n";
            s += "============================================\n";
            s += "Итоговое решение задачи: \n";
            s += "x*:\n";
            s += printOptimalMatrix(_x, _n);
            s += String.Format("f* = {0} \n", _f);
        }
Exemplo n.º 2
0
        public int[][] start(out double cost)
        {
            Task tsk;
            int[][] x;
            double f;
            int i = 1;

            while (_taskList.Count > 0)
            {
                tsk = _taskList.Dequeue();

                VengerAlgorithm va = new VengerAlgorithm(tsk.toVengerMatrix());
                va.start(false, out x, out f);

                // полученное значение целевой функции меньше текущего?
                if (f < _f)
                {
                    List<Loop> loops = getSubLoops(x);
                    if (loops.Count == 1)
                    {
                        _f = f;
                        _x = x;
                    }
                    else
                    {
                        Loop min = getMinLoops(loops);
                        addNewTasks(min, tsk);
                    }
                }
            }
            cost = _f;
            return _x;
        }