Simulation, Modeling, and Monte Carlo Methods in Archaeology

Keith Kintigh

Assignment 7 - Gravity Model

Alden (1979) has argued that a gravity model of interaction can be used to predict boundaries between political systems. The idea here is that the interaction between units within a system is greater than that between units of different systems. He suggests that interaction can be predicted by a gravity model:

       Pa*Pb
Iab=_____
       (dab)e

Assume that there are two types of sites, centers and villages. For each site we have East and North locational coordinates, and an estimated population. Our task is to assign villages to the centers with which they are predicted to be most closely allied, given the model.

First read in data for the sites from the file GravityIn.txt. For each site, this file has integer E and N locational coordinates (in GravityIn.txt they are restricted to 1-80 in the x direction and 1 to 24 in the Y direction), a site type (1 for center and 2 for village), and a population size (between 1 and 10000). The first line of the file specifies the number of sites (186) and the number of variables (4). Thus, a data line might be

17 11 2 110

for E 17, N 11, village, pop 110. The sites do not overlap spatially.

To read the data you will want to use the methods KWK.readFile, KWK.getInt, and KWK.closeBufferedReader in the newly revised KWK.java. Before readFile you will need to declare an input stream. getInt reads the next integer from the input stream, ignoring blanks, commas, carriage returns and the like. Thus, to read the first two values from the file and close it you can use the code below. Having read those two values you know how many sites to read the 4 values for (be sure not to read past the end of the file):

int sites,vars;
BufferedReader streamIn=null;
streamIn=KWK.readFile("Input File","GravityIn.txt");
sites=KWK.getInt(streamIn);
vars=KWK.getInt(streamIn);
// your code to read the rest of the site data here
closeBufferedReader(streamIn);

There will be no more than 200 sites, at most 10 of which will be centers. Read this data into a set of arrays (XC, YC, PopC) for centers and a set of arrays for villages (XV, YV, PopV). Then, get from the user (using readDouble if you like) the exponent e for the distance function. This exponent must be between 0 and 10, but may be fractional, e.g. 1.5.

Calculate for each village the its interaction with each center, and assign the village to the center with which it has the greatest interaction. Note that distance is calculated as follows:

dij=sqrt((xi-xj)²+(yi-yj)²)

To compute a power of the distance, i.e. de, you can use Math.pow:

distfn=Math.pow(b,e);

will give you b to the eth power. In any event, use a method with 5 parameters x1,y1,x2,y2,e to compute the distance function.

Finally create a printed map of the area with the centers plotted with capital letters, e.g. A, B, C (in order of appearance) and all of the villages assigned to A plotted as a, all of them assigned B as b and so forth. What you will want to do is set up a two dimensional character array (e.g., 80x24) that you initially set to blanks. You then plot the sites by changing the blank at the appropriate place to a letter. To get a capital letter associated with an integer number n, you can use (char)(64+n) where n=1 plots to A, 2 to B etc. For lower case use (char)(96+n). Note that when you print out this character array, you will be starting at the top left, not at 1,1.

int center;
map[e][n]=(char)(center+64)

When you are finished loop back to read in a new distance exponent.

Once you have this working, describe how the exponent of the distance function affects the boundary of the territory, where the boundary is simply defined by the sites attached to each center. Usual powers in geography are in the range 1-3. Plot settlement configurations for a number of distance exponents within the range 0-5 and describe how this variable affects the results.

Good luck. For what it is worth, my program for this is about 115 lines.