예제 #1
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance from an input grid of boolean values.
        /// </summary>
        /// <param name="activeSites">
        /// An input grid of boolean values where true values indicates active
        /// sites.
        /// </param>
        public Array2D(IInputGrid <bool> activeSites)
            : base(activeSites.Dimensions)
        {
            int rows    = activeSites.Rows;
            int columns = activeSites.Columns;

            indexes = new uint[rows, columns];
            uint count = 0;

            for (int row = 0; row < rows; ++row)
            {
                for (int column = 0; column < columns; ++column)
                {
                    uint dataIndex = InactiveSite.DataIndex;
                    if (activeSites.ReadValue())
                    {
                        count++;
                        dataIndex = count;
                    }
                    indexes[row, column] = dataIndex;
                }
            }
            ActiveLocationCount   = count;
            InactiveLocationCount = (rows * columns) - ActiveLocationCount;

#if LOG4NET
            if (isDebugEnabled)
            {
                log.Debug("Active Site Locations");
                log.Debug("");
                log.DebugFormat("Grid dimensions: {0}", activeSites.Dimensions);
                log.Debug("");

                StringBuilder line = new StringBuilder(8 * (int)columns);
                line.Append("Column:");
                for (int column = 1; column <= columns; column++)
                {
                    line.Append('\t').Append(column);
                }
                log.Debug(line.ToString());

                log.Debug("Row");
                for (int row = 0; row < rows; row++)
                {
                    line.Remove(0, line.Length);
                    line.Append(row + 1);
                    for (int column = 0; column < columns; column++)
                    {
                        line.Append('\t').Append(indexes[row, column]);
                    }
                    log.Debug(line.ToString());
                }
            }
#endif
        }
예제 #2
0
        //---------------------------------------------------------------------

        private void Initialize(IInputGrid <bool> activeSites)
        {
            if (Count > int.MaxValue)
            {
                string mesg = string.Format("Landscape dimensions are too big; maximum # of sites = {0:#,###}",
                                            int.MaxValue);
                throw new System.ApplicationException(mesg);
            }
            dataIndexes = new Landscapes.DataIndexes.Array2D(activeSites);
            activeSites.Close();
            inactiveSiteCount = SiteCount - (int)dataIndexes.ActiveLocationCount;
        }
예제 #3
0
        //---------------------------------------------------------------------

        private void Initialize(IInputGrid <bool> activeSites)
        {
            if (Count > int.MaxValue)
            {
                string mesg = string.Format("Landscape dimensions are too big; maximum # of sites = {0:#,###}",
                                            int.MaxValue);
                throw new System.ApplicationException(mesg);
            }
            activeSiteMap = new ActiveSiteMap(activeSites);
            activeSites.Close();
            inactiveSiteCount = SiteCount - (int)activeSiteMap.Count;
            if (inactiveSiteCount > 0)
            {
                inactiveSiteDataIndex = (int)activeSiteMap.Count;
            }
        }
        //---------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance from an input grid of boolean values.
        /// </summary>
        /// <param name="activeSites">
        /// An input grid of boolean values where true values indicates active
        /// sites.
        /// </param>
        public Array2D(IInputGrid<bool> activeSites)
            : base(activeSites.Dimensions)
        {
            int rows = activeSites.Rows;
            int columns = activeSites.Columns;

            indexes = new uint[rows, columns];
            uint count = 0;
            for (int row = 0; row < rows; ++row) {
                for (int column = 0; column < columns; ++column) {
                    uint dataIndex = InactiveSite.DataIndex;
                    if (activeSites.ReadValue()) {
                        count++;
                        dataIndex = count;
                    }
                    indexes[row, column] = dataIndex;
                }
            }
            ActiveLocationCount = count;
            InactiveLocationCount = (rows * columns) - ActiveLocationCount;

            #if LOG4NET
            if (isDebugEnabled) {
                log.Debug("Active Site Locations");
                log.Debug("");
                log.DebugFormat("Grid dimensions: {0}", activeSites.Dimensions);
                log.Debug("");

                StringBuilder line = new StringBuilder(8 * (int) columns);
                line.Append("Column:");
                for (int column = 1; column <= columns; column++)
                    line.Append('\t').Append(column);
                log.Debug(line.ToString());

                log.Debug("Row");
                for (int row = 0; row < rows; row++) {
                    line.Remove(0, line.Length);
                    line.Append(row + 1);
                    for (int column = 0; column < columns; column++)
                        line.Append('\t').Append(indexes[row, column]);
                    log.Debug(line.ToString());
                }
            }
            #endif
        }
예제 #5
0
        public void Map8Bit()
        {
            Map map = new Map(path8Bit, dataset);

            using (IInputGrid <bool> inputGrid = map.OpenAsInputGrid()) {
                Assert.AreEqual(dims8Bit.Rows, inputGrid.Dimensions.Rows);
                Assert.AreEqual(dims8Bit.Columns, inputGrid.Dimensions.Columns);

                for (int row = 0; row < dims8Bit.Rows; ++row)
                {
                    for (int column = 0; column < dims8Bit.Columns; ++column)
                    {
                        IEcoregion ecoregion = dataset.Find(ecoregions8Bit[row, column]);
                        Assert.AreEqual(ecoregion.Active, inputGrid.ReadValue());
                    }
                }
            }
        }
예제 #6
0
        public void Map16Bit()
        {
            Map map = new Map(path16Bit, dataset, rasterDriverMgr);

            using (IInputGrid <EcoregionCode> inputGrid = map.OpenAsInputGrid()) {
                Assert.AreEqual(dims16Bit.Rows, inputGrid.Dimensions.Rows);
                Assert.AreEqual(dims16Bit.Columns, inputGrid.Dimensions.Columns);

                for (int row = 0; row < dims16Bit.Rows; ++row)
                {
                    for (int column = 0; column < dims16Bit.Columns; ++column)
                    {
                        ushort        mapCode       = ecoregions16Bit[row, column];
                        IEcoregion    ecoregion     = dataset.Find(mapCode);
                        EcoregionCode ecoregionCode = inputGrid.ReadValue();
                        Assert.AreEqual(mapCode, (int)ecoregionCode);
                        Assert.AreEqual(ecoregion.Active, ecoregionCode.IsActive);
                    }
                }
            }
        }
예제 #7
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance using an input grid of active sites.
        /// </summary>
        /// <param name="activeSites">
        /// A grid that indicates which sites are active.
        /// </param>
        public Landscape(IInputGrid <bool> activeSites)
            : base(activeSites.Dimensions)
        {
            Initialize(activeSites);
        }
		//---------------------------------------------------------------------

		private void Initialize(IInputGrid<bool> activeSites)
		{
			this.rowIntervals    = new List<Interval>();
			this.activeRows      = new List<ActiveRow>();
			this.columnIntervals = new List<Interval>();

			bool inRowInterval = false;
			Interval rowInterval = new Interval();
			for (uint row = 1; row <= activeSites.Rows; ++row) {
				uint colIntervalCount = 0;
				uint firstColIntervalIndex = 0;
				bool inColumnInterval = false;
				Interval columnInterval = new Interval();
				for (uint column = 1; column <= activeSites.Columns; ++column) {
					if (activeSites.ReadValue()) {
						this.count++;
						if (inColumnInterval) {
							//  extend column interval
							columnInterval.End = column;
						}
						else {
							//  start a new column interval
							columnInterval = new Interval(column, column,
							                              count - 1);
							inColumnInterval = true;
							colIntervalCount++;
							if (colIntervalCount == 1)
								firstColIntervalIndex = (uint)
														columnIntervals.Count;
						}
					}
					else {
						// current site is inactive
						if (inColumnInterval) {
							//  end of current column interval
							this.columnIntervals.Add(columnInterval);
							inColumnInterval = false;
						}
					}
				}  // for each column

				// at end of current row
				if (colIntervalCount > 0) {
					//  current row is an active row
					if (inColumnInterval) {
						//  last column was active, so add its interval
						this.columnIntervals.Add(columnInterval);
					}
					this.activeRows.Add(new ActiveRow(colIntervalCount,
					                             	  firstColIntervalIndex));
					if (inRowInterval) {
						//  extend row interval
						rowInterval.End = row;
					}
					else {
						//	start a new row interval
						rowInterval = new Interval(row, row,
						                           (uint)(activeRows.Count-1));
						inRowInterval = true;
					}
				}
				else {
					//	current row is not an active row
					if (inRowInterval) {
						this.rowIntervals.Add(rowInterval);
						inRowInterval = false;
					}
				}
			}  // for each row

			if (inRowInterval) {
				//	last row was an active row, so add its row interval
				this.rowIntervals.Add(rowInterval);
			}
		}
		//---------------------------------------------------------------------

		/// <summary>
		/// Initializes a new instance using an input data grid.
		/// </summary>
		public ActiveSiteMap(IInputGrid<bool> activeSites)
		{
			Initialize(activeSites);
		}
예제 #10
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Runs a model scenario.
        /// </summary>
        public void Run(string scenarioPath, IUserInterface ui)
        {
            this.ui = ui;

            siteVarRegistry.Clear();

            Scenario scenario = LoadScenario(scenarioPath);

            startTime      = scenario.StartTime;
            endTime        = scenario.EndTime;
            timeSinceStart = 0;
            currentTime    = startTime;
            InitializeRandomNumGenerator(scenario.RandomNumberSeed);

            LoadSpecies(scenario.Species);
            LoadEcoregions(scenario.Ecoregions);

            ui.WriteLine("Initializing landscape from ecoregions map \"{0}\" ...", scenario.EcoregionsMap);
            Ecoregions.Map ecoregionsMap = new Ecoregions.Map(scenario.EcoregionsMap,
                                                              ecoregions,
                                                              rasterFactory);
            // -- ProcessMetadata(ecoregionsMap.Metadata, scenario);
            cellLength = scenario.CellLength.Value;
            cellArea   = (float)((cellLength * cellLength) / 10000);
            ui.WriteLine("Cell length = {0} m, cell area = {1} ha", cellLength, cellArea);

            using (IInputGrid <bool> grid = ecoregionsMap.OpenAsInputGrid()) {
                ui.WriteLine("Map dimensions: {0} = {1:#,##0} cell{2}", grid.Dimensions,
                             grid.Count, (grid.Count == 1 ? "" : "s"));
                // landscape = new Landscape(grid);
                landscape = landscapeFactory.CreateLandscape(grid);
            }
            ui.WriteLine("Sites: {0:#,##0} active ({1:p1}), {2:#,##0} inactive ({3:p1})",
                         landscape.ActiveSiteCount, (landscape.Count > 0 ? ((double)landscape.ActiveSiteCount) / landscape.Count : 0),
                         landscape.InactiveSiteCount, (landscape.Count > 0 ? ((double)landscape.InactiveSiteCount) / landscape.Count : 0));

            ecoregionSiteVar = ecoregionsMap.CreateSiteVar(landscape);

            disturbAndOtherExtensions = new List <ExtensionMain>();

            try {
                ui.WriteLine("Loading {0} extension ...", scenario.Succession.Info.Name);
                succession = Loader.Load <SuccessionMain>(scenario.Succession.Info);
                succession.LoadParameters(scenario.Succession.InitFile, this);
                succession.Initialize();

                ExtensionMain[] disturbanceExtensions = LoadExtensions(scenario.Disturbances);
                InitExtensions(disturbanceExtensions);

                ExtensionMain[] otherExtensions = LoadExtensions(scenario.OtherExtensions);
                InitExtensions(otherExtensions);


                //  Perform 2nd phase of initialization for non-succession extensions.
                foreach (ExtensionMain extension in disturbanceExtensions)
                {
                    extension.InitializePhase2();
                }
                foreach (ExtensionMain extension in otherExtensions)
                {
                    extension.InitializePhase2();
                }

                //  Run output extensions for TimeSinceStart = 0 (time step 0)
                foreach (ExtensionMain extension in otherExtensions)
                {
                    if (extension.Type.IsMemberOf("output"))
                    {
                        Run(extension);
                    }
                }

                //******************// for Rob
                //  Main time loop  //
                //******************//

                for (currentTime++, timeSinceStart++;
                     currentTime <= endTime;
                     currentTime++, timeSinceStart++)
                {
                    bool isSuccTimestep = IsExtensionTimestep(succession);

                    List <ExtensionMain> distExtensionsToRun;
                    distExtensionsToRun = GetExtensionsToRun(disturbanceExtensions);
                    bool isDistTimestep = distExtensionsToRun.Count > 0;

                    List <ExtensionMain> otherExtensionsToRun;
                    otherExtensionsToRun = GetExtensionsToRun(otherExtensions);

                    if (!isSuccTimestep && !isDistTimestep &&
                        otherExtensionsToRun.Count == 0)
                    {
                        continue;
                    }

                    ui.WriteLine("Current time: {0}", currentTime);

                    if (isDistTimestep)
                    {
                        if (scenario.DisturbancesRandomOrder)
                        {
                            distExtensionsToRun = shuffle(distExtensionsToRun);
                        }
                        foreach (ExtensionMain distExtension in distExtensionsToRun)
                        {
                            Run(distExtension);
                        }
                    }

                    if (isSuccTimestep || isDistTimestep)
                    {
                        Run(succession);
                    }

                    foreach (ExtensionMain otherExtension in otherExtensionsToRun)
                    {
                        Run(otherExtension);
                    }
                }  // main time loop
            }
            finally {
                foreach (ExtensionMain extension in disturbAndOtherExtensions)
                {
                    extension.CleanUp();
                }
            }
            ui.WriteLine("Model run is complete.");
        }
예제 #11
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Runs a model scenario.
        /// </summary>
        public void Run(string scenarioPath)
        {
            siteVarRegistry.Clear();

            Scenario scenario = LoadScenario(scenarioPath);

            startTime      = scenario.StartTime;
            endTime        = scenario.EndTime;
            timeSinceStart = 0;
            currentTime    = startTime;
            InitializeRandomNumGenerator(scenario.RandomNumberSeed);

            LoadSpecies(scenario.Species);
            LoadEcoregions(scenario.Ecoregions);

            UI.WriteLine("Initializing landscape from ecoregions map \"{0}\" ...", scenario.EcoregionsMap);
            Ecoregions.Map ecoregionsMap = new Ecoregions.Map(scenario.EcoregionsMap,
                                                              ecoregions,
                                                              rasterDriverMgr);
            ProcessMetadata(ecoregionsMap.Metadata, scenario);
            using (IInputGrid <EcoregionCode> grid = ecoregionsMap.OpenAsInputGrid()) {
                UI.WriteLine("Map dimensions: {0} = {1:#,##0} cell{2}", grid.Dimensions,
                             grid.Count, (grid.Count == 1 ? "" : "s"));
                landscape = new Landscape(grid, scenario.BlockSize.HasValue ? scenario.BlockSize.Value : 1);
            }
            UI.WriteLine("Sites: {0:#,##0} active ({1:p1}), {2:#,##0} inactive ({3:p1})",
                         landscape.ActiveSiteCount, (landscape.Count > 0 ? ((double)landscape.ActiveSiteCount) / landscape.Count : 0),
                         landscape.InactiveSiteCount, (landscape.Count > 0 ? ((double)landscape.InactiveSiteCount) / landscape.Count : 0));

            ecoregionSiteVar = ecoregionsMap.CreateSiteVar(landscape);

            plugInsWith2PhaseInit = new List <PlugIns.I2PhaseInitialization>();
            plugInsWithCleanUp    = new List <PlugIns.ICleanUp>();

            try {
                UI.WriteLine("Loading {0} plug-in ...", scenario.Succession.Info.Name);
                succession = Loader.Load <SuccessionPlugIn>(scenario.Succession.Info);
                succession.Initialize(scenario.Succession.InitFile, this);
                succession.InitializeSites(scenario.InitialCommunities,
                                           scenario.InitialCommunitiesMap);

                PlugIn[] disturbancePlugIns = LoadAndInitPlugIns(scenario.Disturbances);
                PlugIn[] otherPlugIns       = LoadAndInitPlugIns(scenario.OtherPlugIns);

                //    Perform 2nd phase of initialization for those plug-ins
                //    that have it.
                foreach (PlugIns.I2PhaseInitialization plugIn in plugInsWith2PhaseInit)
                {
                    plugIn.InitializePhase2();
                }

                //  Run output plug-ins for TimeSinceStart = 0 (time step 0)
                foreach (PlugIn plugIn in otherPlugIns)
                {
                    if (plugIn.PlugInType.IsMemberOf("output"))
                    {
                        Run(plugIn);
                    }
                }

                //******************// for Rob
                //  Main time loop  //
                //******************//

                for (currentTime++, timeSinceStart++;
                     currentTime <= endTime;
                     currentTime++, timeSinceStart++)
                {
                    bool isSuccTimestep = IsPlugInTimestep(succession);

                    List <PlugIn> distPlugInsToRun;
                    distPlugInsToRun = GetPlugInsToRun(disturbancePlugIns);
                    bool isDistTimestep = distPlugInsToRun.Count > 0;

                    List <PlugIn> otherPlugInsToRun;
                    otherPlugInsToRun = GetPlugInsToRun(otherPlugIns);

                    if (!isSuccTimestep && !isDistTimestep &&
                        otherPlugInsToRun.Count == 0)
                    {
                        continue;
                    }

                    UI.WriteLine("Current time: {0}", currentTime);

                    if (isDistTimestep)
                    {
                        if (scenario.DisturbancesRandomOrder)
                        {
                            Util.Random.Shuffle(distPlugInsToRun);
                        }
                        foreach (PlugIn distPlugIn in distPlugInsToRun)
                        {
                            Run(distPlugIn);
                        }
                    }

                    if (isSuccTimestep || isDistTimestep)
                    {
                        Run(succession);
                    }

                    foreach (PlugIn otherPlugIn in otherPlugInsToRun)
                    {
                        Run(otherPlugIn);
                    }
                }  // main time loop
            }
            finally {
                foreach (PlugIns.ICleanUp plugIn in plugInsWithCleanUp)
                {
                    plugIn.CleanUp();
                }
            }
        }
        //---------------------------------------------------------------------

        private void Initialize(IInputGrid <bool> activeSites)
        {
            this.firstActive   = null;
            this.firstInactive = null;

            this.rowIntervals    = new List <Interval>();
            this.activeRows      = new List <ActiveRow>();
            this.columnIntervals = new List <Interval>();

            bool     inRowInterval = false;
            Interval rowInterval   = new Interval();

            for (uint row = 1; row <= activeSites.Rows; ++row)
            {
                uint     colIntervalCount      = 0;
                uint     firstColIntervalIndex = 0;
                bool     inColumnInterval      = false;
                Interval columnInterval        = new Interval();
                for (uint column = 1; column <= activeSites.Columns; ++column)
                {
                    if (activeSites.ReadValue())
                    {
                        this.count++;
                        if (!this.firstActive.HasValue)
                        {
                            this.firstActive = new Location(row, column);
                        }

                        if (inColumnInterval)
                        {
                            //  extend column interval
                            columnInterval.End = column;
                        }
                        else
                        {
                            //  start a new column interval
                            columnInterval = new Interval(column, column,
                                                          count - 1);
                            inColumnInterval = true;
                            colIntervalCount++;
                            if (colIntervalCount == 1)
                            {
                                firstColIntervalIndex = (uint)
                                                        columnIntervals.Count;
                            }
                        }
                    }
                    else
                    {
                        // current site is inactive
                        if (!this.firstInactive.HasValue)
                        {
                            this.firstInactive = new Location(row, column);
                        }

                        if (inColumnInterval)
                        {
                            //  end of current column interval
                            this.columnIntervals.Add(columnInterval);
                            inColumnInterval = false;
                        }
                    }
                }                  // for each column

                // at end of current row
                if (colIntervalCount > 0)
                {
                    //  current row is an active row
                    if (inColumnInterval)
                    {
                        //  last column was active, so add its interval
                        this.columnIntervals.Add(columnInterval);
                    }
                    this.activeRows.Add(new ActiveRow(colIntervalCount,
                                                      firstColIntervalIndex));
                    if (inRowInterval)
                    {
                        //  extend row interval
                        rowInterval.End = row;
                    }
                    else
                    {
                        //	start a new row interval
                        rowInterval = new Interval(row, row,
                                                   (uint)(activeRows.Count - 1));
                        inRowInterval = true;
                    }
                }
                else
                {
                    //	current row is not an active row
                    if (inRowInterval)
                    {
                        this.rowIntervals.Add(rowInterval);
                        inRowInterval = false;
                    }
                }
            }              // for each row

            if (inRowInterval)
            {
                //	last row was an active row, so add its row interval
                this.rowIntervals.Add(rowInterval);
            }

            if (logger.IsDebugEnabled)
            {
                LogDebug("Active Site Map");
                LogDebug("");
                LogDebug("Input Grid: {0}", activeSites.Dimensions);
                LogDebug("");
                LogDebug("Row Intervals");
                LogDebug("  index: start to end (index of start row in active rows");
                for (int i = 0; i < rowIntervals.Count; i++)
                {
                    Interval interval = rowIntervals[i];
                    LogDebug("  {0}: {1} to {2} ({3})", i, interval.Start, interval.End, interval.StartOffset);
                }

                LogDebug("");
                LogDebug("Active Rows");
                LogDebug("  index: # column intervals, index of 1st column interval");
                for (int i = 0; i < activeRows.Count; i++)
                {
                    ActiveRow activeRow = ActiveRows[i];
                    LogDebug("  {0}: {1}, {2}", i, activeRow.IntervalCount, activeRow.FirstIntervalOffset);
                }

                LogDebug("");
                LogDebug("Column Intervals");
                LogDebug("  index: start to end (data index of start column");
                for (int i = 0; i < columnIntervals.Count; i++)
                {
                    Interval interval = columnIntervals[i];
                    LogDebug("  {0}: {1} to {2} ({3})", i, interval.Start, interval.End, interval.StartOffset);
                }
            }
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance using an input data grid.
        /// </summary>
        public ActiveSiteMap(IInputGrid <bool> activeSites)
        {
            Initialize(activeSites);
        }
예제 #14
0
        //---------------------------------------------------------------------

        private void Initialize(IInputGrid <bool> activeSites)
        {
            this.rowIntervals    = new List <Interval>();
            this.activeRows      = new List <ActiveRow>();
            this.columnIntervals = new List <Interval>();

            bool     inRowInterval = false;
            Interval rowInterval   = new Interval();

            for (uint row = 1; row <= activeSites.Rows; ++row)
            {
                uint     colIntervalCount      = 0;
                uint     firstColIntervalIndex = 0;
                bool     inColumnInterval      = false;
                Interval columnInterval        = new Interval();
                for (uint column = 1; column <= activeSites.Columns; ++column)
                {
                    if (activeSites.ReadValue())
                    {
                        this.count++;
                        if (inColumnInterval)
                        {
                            //  extend column interval
                            columnInterval.End = column;
                        }
                        else
                        {
                            //  start a new column interval
                            columnInterval = new Interval(column, column,
                                                          count - 1);
                            inColumnInterval = true;
                            colIntervalCount++;
                            if (colIntervalCount == 1)
                            {
                                firstColIntervalIndex = (uint)
                                                        columnIntervals.Count;
                            }
                        }
                    }
                    else
                    {
                        // current site is inactive
                        if (inColumnInterval)
                        {
                            //  end of current column interval
                            this.columnIntervals.Add(columnInterval);
                            inColumnInterval = false;
                        }
                    }
                }                  // for each column

                // at end of current row
                if (colIntervalCount > 0)
                {
                    //  current row is an active row
                    if (inColumnInterval)
                    {
                        //  last column was active, so add its interval
                        this.columnIntervals.Add(columnInterval);
                    }
                    this.activeRows.Add(new ActiveRow(colIntervalCount,
                                                      firstColIntervalIndex));
                    if (inRowInterval)
                    {
                        //  extend row interval
                        rowInterval.End = row;
                    }
                    else
                    {
                        //	start a new row interval
                        rowInterval = new Interval(row, row,
                                                   (uint)(activeRows.Count - 1));
                        inRowInterval = true;
                    }
                }
                else
                {
                    //	current row is not an active row
                    if (inRowInterval)
                    {
                        this.rowIntervals.Add(rowInterval);
                        inRowInterval = false;
                    }
                }
            }              // for each row

            if (inRowInterval)
            {
                //	last row was an active row, so add its row interval
                this.rowIntervals.Add(rowInterval);
            }
        }
		//---------------------------------------------------------------------

		private void Initialize(IInputGrid<bool> activeSites)
		{
			this.firstActive = null;
			this.firstInactive = null;

			this.rowIntervals    = new List<Interval>();
			this.activeRows      = new List<ActiveRow>();
			this.columnIntervals = new List<Interval>();

			bool inRowInterval = false;
			Interval rowInterval = new Interval();
			for (uint row = 1; row <= activeSites.Rows; ++row) {
				uint colIntervalCount = 0;
				uint firstColIntervalIndex = 0;
				bool inColumnInterval = false;
				Interval columnInterval = new Interval();
				for (uint column = 1; column <= activeSites.Columns; ++column) {
					if (activeSites.ReadValue()) {
						this.count++;
						if (! this.firstActive.HasValue)
							this.firstActive = new Location(row, column);

						if (inColumnInterval) {
							//  extend column interval
							columnInterval.End = column;
						}
						else {
							//  start a new column interval
							columnInterval = new Interval(column, column,
							                              count - 1);
							inColumnInterval = true;
							colIntervalCount++;
							if (colIntervalCount == 1)
								firstColIntervalIndex = (uint)
														columnIntervals.Count;
						}
					}
					else {
						// current site is inactive
						if (! this.firstInactive.HasValue)
							this.firstInactive = new Location(row, column);

						if (inColumnInterval) {
							//  end of current column interval
							this.columnIntervals.Add(columnInterval);
							inColumnInterval = false;
						}
					}
				}  // for each column

				// at end of current row
				if (colIntervalCount > 0) {
					//  current row is an active row
					if (inColumnInterval) {
						//  last column was active, so add its interval
						this.columnIntervals.Add(columnInterval);
					}
					this.activeRows.Add(new ActiveRow(colIntervalCount,
					                             	  firstColIntervalIndex));
					if (inRowInterval) {
						//  extend row interval
						rowInterval.End = row;
					}
					else {
						//	start a new row interval
						rowInterval = new Interval(row, row,
						                           (uint)(activeRows.Count-1));
						inRowInterval = true;
					}
				}
				else {
					//	current row is not an active row
					if (inRowInterval) {
						this.rowIntervals.Add(rowInterval);
						inRowInterval = false;
					}
				}
			}  // for each row

			if (inRowInterval) {
				//	last row was an active row, so add its row interval
				this.rowIntervals.Add(rowInterval);
			}

			if (logger.IsDebugEnabled) {
				LogDebug("Active Site Map");
				LogDebug("");
				LogDebug("Input Grid: {0}", activeSites.Dimensions);
				LogDebug("");
				LogDebug("Row Intervals");
				LogDebug("  index: start to end (index of start row in active rows");
				for (int i = 0; i < rowIntervals.Count; i++) {
					Interval interval = rowIntervals[i];
					LogDebug("  {0}: {1} to {2} ({3})", i, interval.Start, interval.End, interval.StartOffset);
				}

				LogDebug("");
				LogDebug("Active Rows");
				LogDebug("  index: # column intervals, index of 1st column interval");
				for (int i = 0; i < activeRows.Count; i++) {
					ActiveRow activeRow = ActiveRows[i];
					LogDebug("  {0}: {1}, {2}", i, activeRow.IntervalCount, activeRow.FirstIntervalOffset);
				}

				LogDebug("");
				LogDebug("Column Intervals");
				LogDebug("  index: start to end (data index of start column");
				for (int i = 0; i < columnIntervals.Count; i++) {
					Interval interval = columnIntervals[i];
					LogDebug("  {0}: {1} to {2} ({3})", i, interval.Start, interval.End, interval.StartOffset);
				}
			}
		}
		//---------------------------------------------------------------------

		private void Initialize(IInputGrid<bool> activeSites)
		{
			this.firstActive = null;
			this.firstInactive = null;

			this.rows = activeSites.Rows;
			this.columns = activeSites.Columns;
			this.indexes = new uint[this.rows, this.columns];
			this.count = 0;

			for (uint row = 0; row < this.rows; ++row) {
				for (uint column = 0; column < this.columns; ++column) {
					if (activeSites.ReadValue()) {
						this.count++;
						this.indexes[row, column] = this.count;
						if (this.firstActive == null)
							this.firstActive = new LocationAndIndex(new Location(row+1, column+1), this.count);
					}
					else {
						if (this.firstInactive == null)
							this.firstInactive = new LocationAndIndex(new Location(row+1, column+1), InactiveSiteDataIndex);
					}
				}  // for each column
			}  // for each row

			if (logger.IsDebugEnabled) {
				LogDebug("Active Site Map");
				LogDebug("");
				LogDebug("Input Grid: {0}", activeSites.Dimensions);
				LogDebug("");

				if (firstActive == null)
					LogDebug("First Active: null");
				else
					LogDebug("First Active: {0} {1}", firstActive.Location, firstActive.Index);
				if (firstInactive == null)
					LogDebug("First Inactive: null");
				else
					LogDebug("First Inactive: {0} {1}", firstInactive.Location, firstInactive.Index);
				LogDebug("");

				StringBuilder line = new StringBuilder(8 * (int) this.columns);
				line.Append("Column:");
				for (int column = 1; column <= this.columns; column++)
					line.Append('\t').Append(column);
				LogDebug(line.ToString());

				LogDebug("Row");
				for (int row = 0; row < this.rows; row++) {
					line.Remove(0, line.Length);
					line.Append(row + 1);
					for (int column = 0; column < this.columns; column++)
						line.Append('\t').Append(indexes[row, column]);
					LogDebug(line.ToString());
				}
			}
		}
예제 #17
0
 /// <summary>
 /// Creates a new landscape using an input grid of active sites.
 /// </summary>
 /// <param name="activeSites">
 /// A grid that indicates which sites are active.
 /// </param>
 public ILandscape CreateLandscape(IInputGrid <bool> activeSites)
 {
     return(new Landscape(activeSites));
 }
 /// <summary>
 /// Creates a new landscape using an input grid of active sites.
 /// </summary>
 /// <param name="activeSites">
 /// A grid that indicates which sites are active.
 /// </param>
 public ILandscape CreateLandscape(IInputGrid<bool> activeSites)
 {
     return new Landscape(activeSites);
 }
예제 #19
0
        //---------------------------------------------------------------------

        private void Initialize(IInputGrid <bool> activeSites)
        {
            this.firstActive   = null;
            this.firstInactive = null;

            this.rows    = activeSites.Rows;
            this.columns = activeSites.Columns;
            this.indexes = new uint[this.rows, this.columns];
            this.count   = 0;

            for (uint row = 0; row < this.rows; ++row)
            {
                for (uint column = 0; column < this.columns; ++column)
                {
                    if (activeSites.ReadValue())
                    {
                        this.count++;
                        this.indexes[row, column] = this.count;
                        if (this.firstActive == null)
                        {
                            this.firstActive = new LocationAndIndex(new Location(row + 1, column + 1), this.count);
                        }
                    }
                    else
                    {
                        if (this.firstInactive == null)
                        {
                            this.firstInactive = new LocationAndIndex(new Location(row + 1, column + 1), InactiveSiteDataIndex);
                        }
                    }
                }          // for each column
            }              // for each row

            if (logger.IsDebugEnabled)
            {
                LogDebug("Active Site Map");
                LogDebug("");
                LogDebug("Input Grid: {0}", activeSites.Dimensions);
                LogDebug("");

                if (firstActive == null)
                {
                    LogDebug("First Active: null");
                }
                else
                {
                    LogDebug("First Active: {0} {1}", firstActive.Location, firstActive.Index);
                }
                if (firstInactive == null)
                {
                    LogDebug("First Inactive: null");
                }
                else
                {
                    LogDebug("First Inactive: {0} {1}", firstInactive.Location, firstInactive.Index);
                }
                LogDebug("");

                StringBuilder line = new StringBuilder(8 * (int)this.columns);
                line.Append("Column:");
                for (int column = 1; column <= this.columns; column++)
                {
                    line.Append('\t').Append(column);
                }
                LogDebug(line.ToString());

                LogDebug("Row");
                for (int row = 0; row < this.rows; row++)
                {
                    line.Remove(0, line.Length);
                    line.Append(row + 1);
                    for (int column = 0; column < this.columns; column++)
                    {
                        line.Append('\t').Append(indexes[row, column]);
                    }
                    LogDebug(line.ToString());
                }
            }
        }