Ejemplo n.º 1
0
        private Point[] GetCycle(int x, int y)
        {
            Point   Beg = new Point(x, y);
            FindWay fw  = new FindWay(x, y, true, Allowed, Beg, null);

            fw.BuildTree();
            Point[] Way = Array.FindAll <Point>(Allowed, delegate(Point p) { return((p.X != -1) && (p.Y != -1)); });
            return(Way);
        }
Ejemplo n.º 2
0
        // Метод минимального элемента
        public float[,] MinEl( )
        {
            float[] Ahelp = this.dilers;
            float[] Bhelp = this.customers;
            int     i     = 0;
            int     j     = 0;
            float   min   = float.MaxValue;

            float[,] outArr = new float[this.dilersCount, this.customersCount];
            bool[,] pArr    = new bool[this.dilersCount, this.customersCount];
            for (i = 0; i < this.dilersCount; i++)
            {
                for (j = 0; j < this.customersCount; j++)
                {
                    pArr[i, j] = true;
                }
            }
            i = 0;
            j = 0;
            int k;
            int count = 0;

            while (!this.isEmpty(Ahelp) || !this.isEmpty(Bhelp))
            {
                min = this.findMin(this.transportationPrices, pArr, out i, out j);
                float Dif = Math.Min(Ahelp[i], Bhelp[j]);
                outArr[i, j] += Dif; count++;
                Ahelp[i]     -= Dif;
                Bhelp[j]     -= Dif;
                if (Ahelp[i] == 0f)
                {
                    k = 0;
                    while (k < this.customersCount)
                    {
                        pArr[i, k] = false;
                        k++;
                    }
                }
                if (Bhelp[j] == 0f)
                {
                    for (k = 0; k < this.dilersCount; k++)
                    {
                        pArr[k, j] = false;
                    }
                }
            }
            this.NanToEmpty(outArr);

            // Нуль-загрузка
            int difference = (dilersCount + customersCount - 1) - count;

            for (int l = 0; l < difference; l++)
            {
                //выбираем непустые
                Allowed = new Point[count + 1];
                k       = 0;
                for (i = 0; i < dilersCount; i++)
                {
                    for (j = 0; j < customersCount; j++)
                    {
                        if (outArr[i, j] == outArr[i, j])
                        {
                            Allowed[k] = new Point(i, j);
                            k++;
                        }
                    }
                }
                // ищем куда загрузить
                Boolean p  = true;
                Point   Nl = new Point(0, 0);
                for (i = 0; (i < dilersCount) && p; i++)
                {
                    for (j = 0; (j < customersCount) && p; j++)
                    {
                        Nl = Allowed[9] = new Point(i, j);
                        FindWay fw = new FindWay(i, j, true, Allowed, new Point(i, j), null);
                        p = fw.BuildTree();
                    }
                }
                if (!p)
                {
                    outArr[Nl.X, Nl.Y] = 0;
                }
            }

            return(outArr);
        }