Exemple #1
0
        /*    Побудова  опорного плану методом
         * північно-західного кута,   */
        private void SupportingPlanNW()
        {
            int        i1  = 0;
            int        j1  = 0;
            List <int> mA1 = CopyElement.CopyVector(mA);
            List <int> mB1 = CopyElement.CopyVector(mB);

            int k = n + m - 1;
            int t = 0;

            for (int i = 0; i < k; i++)
            {
                t = Math.Min(mA1[i1], mB1[j1]);

                plan[i1][j1] = t;
                mA1[i1]     -= t;
                mB1[j1]     -= t;
                if (mA1[i1] >= mB1[j1] && j1 < m - 1)
                {
                    j1++;
                }
                else if (mA1[i1] <= mB1[j1] && i1 < n - 1)
                {
                    i1++;
                }
            }
        }
Exemple #2
0
 /* Конструктор шага, */
 public Step(List <List <int> > a1, List <List <int> > plan1)
 {
     a    = CopyElement.CopyMatrix(a1);
     plan = CopyElement.CopyMatrix(plan1);
     n    = plan.Count;
     m    = plan[0].Count;
     CreatePotentials();
     CreateMatrixPotentials();
 }
Exemple #3
0
        /*   Конструктор, який приймає задачу
         * і вид  методу складання опорного плану,  */
        public TransportTask(Task a1, int number)
        {
            if (!a1.IsClose)
            {
                a1.ToClose();
                information =
                    "Задача приведена до закритої задачі. \r\n";
            }
            mA = CopyElement.CopyVector(a1.mA);
            mB = CopyElement.CopyVector(a1.mB);
            a  = CopyElement.CopyMatrix(a1.a);
            n  = a.Count;
            m  = a[0].Count;
            List <int> a2 = new List <int>();

            plan = new List <List <int> >();
            for (int i = 0; i < n; i++)
            {
                a2 = new List <int>();
                for (int j = 0; j < m; j++)
                {
                    a2.Add(-1);
                }
                plan.Add(a2);
            }
            plan1 = CopyElement.CopyMatrix(plan);
            int    i1 = 0;
            Random r  = new Random();

            i1 = r.Next(10) % 3;
            if (number == 1 || number == 0 && i1 == 0)
            {
                SupportingPlanNW();
                supportPlanString = "Опорный план побудований методом " +
                                    "північно-західного кута, ";
            }
            else if (number == 2 || number == 0 && i1 == 1)
            {
                SupportingPlanMinElement();
                supportPlanString = "Опорний план побудований методом " +
                                    "мінімального елементу, ";
            }
            else
            {
                SupportingPlanFogel();
                supportPlanString = "Опорний план побудований методом" +
                                    "апроксимації  Фогеля, ";
            }
            information = string.Format("{0}{1}",
                                        information, supportPlanString);
            plan1 = CopyElement.CopyMatrix(plan);
            step  = new Step(a, plan);
            steps.Add(step);
            Solution();
        }
Exemple #4
0
        /*      Побудова опорного плану методом
         *   апроксимації  Фогеля,               */
        private void SupportingPlanFogel()
        {
            List <int>         mA1 = CopyElement.CopyVector(mA);
            List <int>         mB1 = CopyElement.CopyVector(mB);
            List <int>         mA2 = new List <int>();
            List <int>         mB2 = new List <int>();
            List <List <int> > a1  = CopyElement.CopyMatrix(a);
            List <int>         a2  = new List <int>();

            plan = new List <List <int> >();
            for (int i = 0; i < n; i++)
            {
                a2 = new List <int>();
                for (int j = 0; j < m; j++)
                {
                    a2.Add(-1);
                }
                plan.Add(a2);
            }
            for (int i = 0; i < n; i++)
            {
                mA2.Add(1);
            }
            for (int i = 0; i < m; i++)
            {
                mB2.Add(1);
            }
            int k = n + m - 1;
            int t = 0;
            Tuple <int, int> t1;

            for (int i = 0; i < k; i++)
            {
                t1 = NewElement(a1, mA2, mB2);
                t  = Math.Min(mA1[t1.Item1], mB1[t1.Item2]);
                plan[t1.Item1][t1.Item2] = t;
                mA1[t1.Item1]           -= t;
                mB1[t1.Item2]           -= t;
                if (mA1[t1.Item1] >= mB1[t1.Item2] && mB2[t1.Item2] > 0)
                {
                    mB2[t1.Item2] = 0;
                }
                else
                {
                    mA2[t1.Item1] = 0;
                }
            }
        }
Exemple #5
0
        /*    Побудова опорного плану методом
         * мінімального елементу,   */
        private void SupportingPlanMinElement()
        {
            List <int>         mA1 = CopyElement.CopyVector(mA);
            List <int>         mB1 = CopyElement.CopyVector(mB);
            List <List <int> > a1  = CopyElement.CopyMatrix(a);

            List <int> a2 = new List <int>();

            plan = new List <List <int> >();
            for (int i = 0; i < n; i++)
            {
                a2 = new List <int>();
                for (int j = 0; j < m; j++)
                {
                    a2.Add(-1);
                }
                plan.Add(a2);
            }
            int k = n + m - 1;
            int t = 0;
            Tuple <int, int> t1;
            int s = Max(a1) + 10;

            for (int i = 0; i < k; i++)
            {
                t1 = Min(a1);
                t  = Math.Min(mA1[t1.Item1], mB1[t1.Item2]);
                plan[t1.Item1][t1.Item2] = t;
                mA1[t1.Item1]           -= t;
                mB1[t1.Item2]           -= t;
                if (mA1[t1.Item1] >= mB1[t1.Item2])
                {
                    for (int j = 0; j < n; j++)
                    {
                        a1[j][t1.Item2] = s;
                    }
                }
                else
                {
                    for (int j = 0; j < m; j++)
                    {
                        a1[t1.Item1][j] = s;
                    }
                }
            }
        }