Esempio n. 1
0
        /// <summary>
        /// Consume up to requested amount
        /// </summary>
        /// <param name="demandCell">The Cell making the request</param>
        /// <param name="requested">Th requested amount</param>
        /// <returns>The amount consumed</returns>
        public float Consume(Cell demandCell, float requested)
        {
            int   i        = Demands.IndexOf(demandCell);
            float consumed = 0.0f;

            if (i >= 0)
            {
                for (int j = 0; j < Stocks.Count; j++)
                {
                    float conso = AllocationTable[i, j];
                    if (consumed + conso > requested)
                    {
                        conso = requested - consumed; // Do not consume more than requested
                    }
                    if (conso > Stocks[j][ResourceId])
                    {
                        conso = Stocks[j][ResourceId]; // Do not consume more than available
                    }
                    Stocks[j][ResourceId] -= conso;
                    consumed += conso;
                }
            }

            return(consumed);
        }
Esempio n. 2
0
        /// <summary>
        /// Return the amount that was allocated to this cell and for this Resource
        /// </summary>
        /// <param name="demandCell"></param>
        /// <returns></returns>
        public float GetAllocation(Cell demandCell)
        {
            int   i         = Demands.IndexOf(demandCell);
            float allocated = 0.0f;

            if (i >= 0)
            {
                for (int j = 0; j < Stocks.Count; j++)
                {
                    allocated += AllocationTable[i, j];
                }
            }

            return(allocated);
        }