public void Init()
		{
			string[] rows = new string[] {	"....X..",
											"...XX.X",
											".......",
											"...XXX.",
											"X.X.X.X",
											"XXXXXXX" };
			bool [,] activeSites = Bool.Make2DimArray(rows, "X");
			mixedGrid = new DataGrid<bool>(activeSites);
			mixedMap = new ActiveSiteMap(mixedGrid);

			bool found_1stActive = false;
			bool found_1stInactive = false;
			for (uint row = 1; row <= mixedGrid.Rows; ++row) {
				for (uint column = 1; column <= mixedGrid.Columns; ++column) {
					if (mixedGrid[row, column]) {
						if (! found_1stActive) {
							mixed_1stActive = new Location(row, column);
							found_1stActive = true;
						}		
					}
					else {
						if (! found_1stInactive) {
							mixed_1stInactive = new Location(row, column);
							found_1stInactive = true;
						}		
					}
				}
			}
		}
		public void Grid4x0()
		{
			bool[,] array = new bool[4,0];
			DataGrid<bool> grid = new DataGrid<bool>(array);
			ActiveSiteMap map = new ActiveSiteMap(grid);

			Assert.AreEqual(0, map.Count);
			int iterations = 0;
			foreach (ActiveSiteMap.Entry entry in map)
				iterations++;
			Assert.AreEqual(map.Count, iterations);
		}
Esempio n. 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;
        }
		public void Init()
		{
			string[] rows = new string[] {	"....X..",
											"...XX.X",
											".......",
											"...XXX.",
											"X.X.X.X",
											"XXXXXXX" };
			bool [,] activeSites = Bool.Make2DimArray(rows, "X");
			mixedGrid = new DataGrid<bool>(activeSites);
			mixedMap = new ActiveSiteMap(mixedGrid);
		}
		public void Grid1x0()
		{
			bool[,] array = new bool[1,0];
			DataGrid<bool> grid = new DataGrid<bool>(array);
			ActiveSiteMap map = new ActiveSiteMap(grid);

			Assert.AreEqual(0, map.Count);
			int iterations = 0;
			foreach (LocationAndIndex entry in map)
				iterations++;
			Assert.AreEqual(map.Count, iterations);

			Assert.IsNull(map.FirstActive);
			Assert.IsNull(map.FirstInactive);
		}
        //---------------------------------------------------------------------

        internal ActiveSiteEnumerator(ILandscape landscape,
                                      ActiveSiteMap activeSiteMap)
        {
            locationAndIndex = new LocationAndIndex();
            mapEtor          = activeSiteMap.GetEnumerator();
            mapEtor.UseForCurrentEntry(locationAndIndex);

            if (landscape.ActiveSiteCount > 0)
            {
                //	Get location of first active site so we have a valid
                //	location for mutable active site ctor.
                mapEtor.MoveNext();
                currentSite = new MutableActiveSite(landscape, locationAndIndex);
                mapEtor.Reset();
            }
        }
		public void Init()
		{
			string path = Path.Combine(Data.Directory, "mixed.txt");
			bool[,] array = Bool.Read2DimArray(path);
			grid = new DataGrid<bool>(array);
			map = new ActiveSiteMap(grid);

			path = Path.Combine(Data.Directory,
			                    "true-locs-in-mixed.txt");
			activeSites = Data.ReadLocations(path);
		}
		public void Grid5x3False()
		{
			bool[,] array = new bool[,] { {false, false, false},
										  {false, false, false},
										  {false, false, false},
										  {false, false, false},
										  {false, false, false} };
			DataGrid<bool> grid = new DataGrid<bool>(array);
			ActiveSiteMap map = new ActiveSiteMap(grid);

			Assert.AreEqual(0, map.Count);

			int index = 0;
			foreach (LocationAndIndex entry in map) {
				index++;
				Assert.IsTrue(index <= map.Count);
			}
			Assert.AreEqual(map.Count, index);

			Assert.IsNull(map.FirstActive);
			Assert.AreEqual(new Location(1,1), map.FirstInactive.Location);
			Assert.AreEqual(ActiveSiteMap.InactiveSiteDataIndex,
			                map.FirstInactive.Index);
		}
		public void Grid5x3True()
		{
			bool[,] array = new bool[,] { {true, true, true},
										  {true, true, true},
										  {true, true, true},
										  {true, true, true},
										  {true, true, true} };
			DataGrid<bool> grid = new DataGrid<bool>(array);
			ActiveSiteMap map = new ActiveSiteMap(grid);

			Assert.AreEqual(grid.Count, map.Count);

			int index = 0;
			Location location = new Location(1,1);
			foreach (LocationAndIndex entry in map) {
				index++;
				Assert.IsTrue(index <= map.Count);
				Assert.AreEqual(location, entry.Location);
				Assert.AreEqual((uint) index, entry.Index);
				location = RowMajor.Next(location, grid.Columns);
			}
			Assert.AreEqual(map.Count, index);

			Assert.AreEqual(new Location(1,1), map.FirstActive.Location);
			Assert.AreEqual(1, map.FirstActive.Index);
			Assert.IsNull(map.FirstInactive);
		}
Esempio n. 10
0
        //---------------------------------------------------------------------

        internal ActiveSiteMapEnumerator(ActiveSiteMap map)
        {
            this.map               = map;
            this.atEnd             = (map.Count == 0);
            this.moveNextNotCalled = true;
        }
		public void Grid1x1False()
		{
			bool[,] array = new bool[,] { {false} };
			DataGrid<bool> grid = new DataGrid<bool>(array);
			ActiveSiteMap map = new ActiveSiteMap(grid);

			Assert.AreEqual(0, map.Count);

			int index = 0;
			foreach (LocationAndIndex entry in map) {
				Assert.IsTrue(index < map.Count);
				index++;
			}
			Assert.AreEqual(map.Count, index);

			Assert.IsFalse(map.FirstActive.HasValue);
			Assert.IsTrue(map.FirstInactive.HasValue);
			Assert.AreEqual(new Location(1,1), map.FirstInactive.Value);
		}
		public void Grid1x1True()
		{
			bool[,] array = new bool[,] { {true} };
			DataGrid<bool> grid = new DataGrid<bool>(array);
			ActiveSiteMap map = new ActiveSiteMap(grid);

			Assert.AreEqual(grid.Count, map.Count);

			int index = 0;
			Location location = new Location(1,1);
			foreach (ActiveSiteMap.Entry entry in map) {
				Assert.IsTrue(index < map.Count);
				Assert.AreEqual(location, entry.Location);
				Assert.AreEqual((uint) index, entry.Index);
				index++;
				location = RowMajor.Next(location, grid.Columns);
			}
			Assert.AreEqual(map.Count, index);
		}
		public void Grid5x3False()
		{
			bool[,] array = new bool[,] { {false, false, false},
										  {false, false, false},
										  {false, false, false},
										  {false, false, false},
										  {false, false, false} };
			DataGrid<bool> grid = new DataGrid<bool>(array);
			ActiveSiteMap map = new ActiveSiteMap(grid);

			Assert.AreEqual(0, map.Count);

			int index = 0;
			foreach (ActiveSiteMap.Entry entry in map) {
				Assert.IsTrue(index < map.Count);
				index++;
			}
			Assert.AreEqual(map.Count, index);
		}