From: Nick C. <nic...@ve...> - 2004-10-28 13:39:11
|
Hendy, The idea here, I think, is that the space in which the life CA's operate is a sparse matrix. This sparse matrix is backed by a hashtable. If we want to use integer indexes to the hastable then we need to insure that the indexes are with the limits of an int. The sqrt gives us the row / col dimensions of a matrix and the -1 is for saftey in case of any rounding irregularities. This way we can be sure that if we multiply the largest row index by the largest col index we get a valid int. The int index ... line below calculates the key into the sparse matrix. Nick -----Original Message----- From: rep...@li... [mailto:rep...@li...]On Behalf Of Hendy Gunawan Sent: Wednesday, October 27, 2004 7:38 AM To: RePast Subject: [Repast-interest] Question for Conway's Life Project Hi RePast community, I am a new member in RePast member. I'm studying in TU Delft and new to agent based modeling. I try RePast and look at the codes of the demos and actually, I like it. I'm also quite new in Java programming and usually using Dsol (another free simulation language from Sourceforge). I have questions regarding the reason(s) behind several programming line from Life demo project. In class InfiniteLifeSpace: public static final int MAX = (int)Math.sqrt(Integer.MAX_VALUE) - 1; Is there any specific reason why the programmer used sqrt method and -1 for example? for (int j = y - yTop; j <= y + yBottom; j++) { for (int i = x - xLeft; i <= x + xRight; i++) { if (!(j == y && i == x)) { int index = j * MAX + i; if (!checkedSpace.containsKey(index)) { if (isEmptyAt(i, j) && getNumNeighbors(i, j) == 3) { model.addAgent(new LifeAgent(i, j, this)); checkedSpace.put(index, dummy); I cannot figure out the reasons behind the above bolded lines. I appreciate any help or comments even partlyJ Best regards, Hendy Gunawan |