コード例 #1
0
        /// <summary>
        /// Determina se o objecto proporcionado é igual à instância corrente.
        /// </summary>
        /// <param name="obj">O objecto.</param>
        /// <returns>
        /// Verdadeiro caso o objecto seja igual e falso caso contrário.
        /// </returns>
        public override bool Equals(object obj)
        {
            TransportationMaxDoubleNumberField objToCompare = obj as TransportationMaxDoubleNumberField;

            if (objToCompare == null)
            {
                return(base.Equals(obj));
            }
            else
            {
                return(this.MaximumComponent == objToCompare.MaximumComponent &&
                       this.FiniteComponent == objToCompare.FiniteComponent);
            }
        }
コード例 #2
0
        /// <summary>
        /// Aplica a incialização de Russels.
        /// </summary>
        private void ApplyRussels()
        {
            TransportationMaxDoubleNumberField[] largestRowsCosts    = new TransportationMaxDoubleNumberField[supplyNumber];
            TransportationMaxDoubleNumberField[] largestColumnsCosts = new TransportationMaxDoubleNumberField[demandNumber];
            bool[] isRowEliminated    = new bool[this.supplyNumber];
            bool[] isColumnEliminated = new bool[this.demandNumber];
            TransportationMaxDoubleNumberField temporary;

            for (int i = 0; i < this.supplyNumber; ++i)
            {
                largestRowsCosts[i] = new TransportationMaxDoubleNumberField(this.transportationCost[i, 0]);
            }

            for (int i = 0; i < this.demandNumber; ++i)
            {
                largestColumnsCosts[i] = new TransportationMaxDoubleNumberField(this.transportationCost[0, i]);
            }

            for (int i = 0; i < this.supplyNumber; ++i)
            {
                for (int j = 0; j < this.demandNumber; ++j)
                {
                    if (largestRowsCosts[i] < this.transportationCost[i, j])
                    {
                        largestRowsCosts[i] = new TransportationMaxDoubleNumberField(this.transportationCost[i, j]);
                    }

                    if (largestColumnsCosts[j] < this.transportationCost[i, j])
                    {
                        largestColumnsCosts[j] = new TransportationMaxDoubleNumberField(this.transportationCost[i, j]);
                    }
                }
            }

            int chosenLine   = -1;
            int chosenColumn = -1;
            TransportationMaxDoubleNumberField minimumDelta = new TransportationMaxDoubleNumberField(this.transportationCost[0, 0]);

            for (int i = 0; i < this.supplyNumber; ++i)
            {
                for (int j = 0; j < this.demandNumber; ++j)
                {
                    temporary = this.transportationCost[i, j] - largestColumnsCosts[j] - largestRowsCosts[i];
                    if (temporary < minimumDelta)
                    {
                        minimumDelta = temporary;
                        chosenLine   = i;
                        chosenColumn = j;
                    }
                }
            }

            int  numberOfRemainingRows    = this.supplyNumber;
            int  numberOfRemainingColumns = this.demandNumber;
            bool state = true;

            while (state)
            {
                bool rowHasBeenEliminated = true;
                if (this.supply[chosenLine] <= this.demand[chosenColumn])
                {
                    this.resultMatrix[chosenLine, chosenColumn] = this.supply[chosenLine];
                    this.demand[chosenColumn]  -= this.supply[chosenLine];
                    this.supply[chosenLine]     = 0;
                    isRowEliminated[chosenLine] = true;
                    --numberOfRemainingRows;
                }
                else
                {
                    this.resultMatrix[chosenLine, chosenColumn] = this.demand[chosenColumn];
                    this.supply[chosenLine]         -= this.demand[chosenColumn];
                    isColumnEliminated[chosenColumn] = true;
                    --numberOfRemainingColumns;
                    rowHasBeenEliminated = false;
                }

                if (numberOfRemainingRows == 0)
                {
                    state = false;
                }
                else if (numberOfRemainingColumns == 0)
                {
                    state = false;
                }
                else if (rowHasBeenEliminated)
                {
                    int i = 0;
                    int j = 0;
                    while (isRowEliminated[i])
                    {
                        ++i;
                    }
                    while (isColumnEliminated[j])
                    {
                        ++j;
                    }
                    for (; j < this.demandNumber; ++j)
                    {
                        if (!isColumnEliminated[j])
                        {
                            largestColumnsCosts[j] = new TransportationMaxDoubleNumberField(this.transportationCost[i, j]);
                        }
                    }
                }
                else
                {
                    int i = 0;
                    int j = 0;
                    while (isRowEliminated[i])
                    {
                        ++i;
                    }
                    while (isColumnEliminated[j])
                    {
                        ++j;
                    }
                    for (; i < this.supplyNumber; ++i)
                    {
                        if (!isRowEliminated[i])
                        {
                            largestRowsCosts[i] = new TransportationMaxDoubleNumberField(this.transportationCost[i, j]);
                        }
                    }
                }

                for (int i = 0; i < this.supplyNumber; ++i)
                {
                    if (!isRowEliminated[i])
                    {
                        for (int j = 0; j < this.demandNumber; ++j)
                        {
                            if (!isColumnEliminated[j])
                            {
                                if (largestRowsCosts[i] < this.transportationCost[i, j])
                                {
                                    largestRowsCosts[i] = new TransportationMaxDoubleNumberField(this.transportationCost[i, j]);
                                }

                                if (largestColumnsCosts[j] < this.transportationCost[i, j])
                                {
                                    largestColumnsCosts[j] = new TransportationMaxDoubleNumberField(this.transportationCost[i, j]);
                                }
                            }
                        }
                    }
                }

                chosenLine   = -1;
                chosenColumn = -1;
                minimumDelta = new TransportationMaxDoubleNumberField(double.MaxValue);
                for (int i = 0; i < this.supplyNumber; ++i)
                {
                    if (!isRowEliminated[i])
                    {
                        for (int j = 0; j < this.demandNumber; ++j)
                        {
                            if (!isColumnEliminated[j])
                            {
                                temporary = this.transportationCost[i, j] - largestColumnsCosts[j] - largestRowsCosts[i];
                                if (temporary < minimumDelta)
                                {
                                    minimumDelta = temporary;
                                    chosenLine   = i;
                                    chosenColumn = j;
                                }
                            }
                        }
                    }
                }
            }  //While
        }