Example #1
0
 public InitialConditionsDistributionMap(InitialConditionsDistributionCollection icd)
 {
     foreach (InitialConditionsDistribution t in icd)
     {
         this.AddICD(t);
     }
 }
Example #2
0
        private void AddICD(InitialConditionsDistribution order)
        {
            InitialConditionsDistributionCollection l = this.m_Map.GetItemExact(order.Iteration);

            if (l == null)
            {
                l = new InitialConditionsDistributionCollection();
                this.m_Map.AddItem(order.Iteration, l);
            }

            l.Add(order);

            this.m_HasItems = true;
        }
Example #3
0
        /// <summary>
        /// Get a collection of InitialConditionDistribution objects for the specified Iteration
        /// </summary>
        /// <param name="iteration"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public InitialConditionsDistributionCollection GetForIteration(int?iteration)
        {
            InitialConditionsDistributionCollection icds = new InitialConditionsDistributionCollection();

            foreach (InitialConditionsDistribution icd in this)
            {
                if (Nullable.Equals(icd.Iteration, iteration))
                {
                    icds.Add(icd);
                }
            }

            return(icds);
        }
Example #4
0
        /// <summary>
        /// Get a Filtered Collection of InitialConditionsDistribution for specified parameter
        /// </summary>
        /// <returns>A Collection of InitialConditionsDistribution</returns>
        /// <remarks></remarks>
        public InitialConditionsDistributionCollection GetFiltered(Cell cell)
        {
            InitialConditionsDistributionCollection ICDCollection = new InitialConditionsDistributionCollection();

            foreach (InitialConditionsDistribution icd in this)
            {
                if (cell.StratumId != icd.StratumId)
                {
                    continue;
                }

                if (cell.StateClassId != Spatial.DefaultNoDataValue)
                {
                    if (cell.StateClassId != icd.StateClassId)
                    {
                        continue;
                    }
                }

                if (cell.SecondaryStratumId != Spatial.DefaultNoDataValue)
                {
                    if (cell.SecondaryStratumId != icd.SecondaryStratumId)
                    {
                        continue;
                    }
                }

                if (cell.TertiaryStratumId != Spatial.DefaultNoDataValue)
                {
                    if (cell.TertiaryStratumId != icd.TertiaryStratumId)
                    {
                        continue;
                    }
                }

                if (cell.Age != Spatial.DefaultNoDataValue)
                {
                    if (cell.Age < icd.AgeMin || cell.Age > icd.AgeMax)
                    {
                        continue;
                    }
                }

                // Passed all the tests, so we'll take this one
                ICDCollection.Add(icd);
            }

            return(ICDCollection);
        }
Example #5
0
        public InitialConditionsDistributionCollection GetICDs(int?iteration)
        {
            if (!this.m_HasItems)
            {
                return(null);
            }

            InitialConditionsDistributionCollection l = this.m_Map.GetItem(iteration);

            if (l == null)
            {
                return(null);
            }

            Debug.Assert(l.Count > 0);
            return(l);
        }
Example #6
0
        /// <summary>
        /// Calculates the sum of the Non Spatial Initial Conditions relative amount
        /// </summary>
        /// <remarks></remarks>
        private double CalcSumOfRelativeAmount(int?iteration)
        {
            double sumOfRelativeAmount = 0.0;

            InitialConditionsDistributionCollection icds = this.m_InitialConditionsDistributionMap.GetICDs(iteration);

            foreach (InitialConditionsDistribution sis in icds)
            {
                sumOfRelativeAmount += sis.RelativeAmount;
            }

            if (sumOfRelativeAmount <= 0.0)
            {
                ExceptionUtils.ThrowArgumentException("The sum of the relative amount cannot be zero.");
            }

            return(sumOfRelativeAmount);
        }
Example #7
0
        /// <summary>
        /// Initializes all simulations cells in Non-Raster mode
        /// </summary>
        /// <param name="iteration">The current iteration</param>
        /// <remarks></remarks>
        private void InitializeCellsNonRasterNoCalcFromDist(int iteration)
        {
            Debug.Assert(!this.IsSpatial);
            Debug.Assert(this.m_Cells.Count > 0);

#if DEBUG
            Dictionary <int, Cell> dict = new Dictionary <int, Cell>();
#endif

            InitialConditionsDistributionCollection icds = this.m_InitialConditionsDistributionMap.GetICDs(iteration);
            double sumOfRelativeAmountForIteration       = CalcSumOfRelativeAmount(iteration);

            foreach (Cell c in this.m_Cells)
            {
                double Rand = this.m_RandomGenerator.GetNextDouble();
                double CumulativeProportion = 0.0;

                foreach (InitialConditionsDistribution icd in icds)
                {
                    CumulativeProportion += (icd.RelativeAmount / sumOfRelativeAmountForIteration);

                    if (Rand < CumulativeProportion)
                    {
#if DEBUG
                        dict.Add(c.CellId, c);
#endif

                        Cell tempVar = c;
                        this.InitializeCellNonRaster(ref tempVar, icd, iteration);
                        this.PostInitializeCellNonRaster(c, iteration);

                        break;
                    }
                }
            }

#if DEBUG
            Debug.Assert(dict.Count == this.m_Cells.Count);
#endif

            CellsInitialized?.Invoke(this, new CellEventArgs(null, iteration, this.m_TimestepZero));
        }
Example #8
0
        /// <summary>
        /// Initializes all simulations cells in Non-Raster mode
        /// </summary>
        /// <param name="iteration">The current iteration</param>
        /// <remarks></remarks>
        private void InitializeCellsNonRasterCalcFromDist(int iteration)
        {
            // Fetch the number of cells from the NS IC setting
            DataRow drrc     = this.ResultScenario.GetDataSheet(Strings.DATASHEET_NSIC_NAME).GetDataRow();
            int     numCells = Convert.ToInt32(drrc[Strings.DATASHEET_NSIC_NUM_CELLS_COLUMN_NAME], CultureInfo.InvariantCulture);

            Debug.Assert(!this.IsSpatial);
            Debug.Assert(this.m_Cells.Count > 0);

            InitialConditionsDistributionCollection icds = this.m_InitialConditionsDistributionMap.GetICDs(iteration);
            double sumOfRelativeAmountForIteration       = CalcSumOfRelativeAmount(iteration);

            int CellIndex = 0;

#if DEBUG
            Dictionary <int, Cell> dict = new Dictionary <int, Cell>();
#endif
            bool ExceededNumCells = false;

            foreach (InitialConditionsDistribution icd in icds)
            {
                if (ExceededNumCells)
                {
                    break;
                }

                // DEVNOTE:To support multiple iterations, use relativeAmount / sum For Iteration as scale of total number of cells.
                // Number of cells determined by 1st iteration specified. Otherwise, there's too much likelyhood that Number of cells
                //will vary per iteration, which we can't/won't support.

                double Rounded        = Math.Round(icd.RelativeAmount / sumOfRelativeAmountForIteration * numCells);
                int    numCellsForICD = Convert.ToInt32(Rounded);

                for (int i = 0; i < numCellsForICD; i++)
                {
                    Cell c = this.Cells[CellIndex];

#if DEBUG
                    dict.Add(c.CellId, c);
#endif

                    this.InitializeCellNonRaster(ref c, icd, iteration);
                    this.PostInitializeCellNonRaster(c, iteration);

                    CellIndex += 1;

                    if (CellIndex >= this.Cells.Count)
                    {
                        ExceededNumCells = true;
                        break;
                    }
                }
            }

#if DEBUG
            Debug.Assert(dict.Count == this.m_Cells.Count);
            Debug.Assert(CellIndex == this.Cells.Count);
#endif

            CellsInitialized?.Invoke(this, new CellEventArgs(null, iteration, this.m_TimestepZero));
        }