An association between objects can often be worked out using a formula. For example, you can work out that pairs of grid squares are next to each other (“the 'next-to' association between grid squares”) knowing the row and column of each square. However, sometimes this is difficult or simply impossible. For example, you may want to represent which person is friends with another person: all you can do is provide data on the pairs of people that are friends with each other.
This model shows how to specify such an association. The particular context is that of spatial paches, and the association we are representing is that of one patch being a neighbour of another. However, you should be able to apply the solution to analogous problems, such as the 'friendship' one above, the trade connections between countries, or a network of towns connected by roads.
Note that this model doesn’t actually do anything: it’s only job is to show you how to specify the association from data. In reality, you will probably want to put dynamics into each patch, and to pass information from one patch to its neighbours - there’s no point in representing which are neighbours unless you do this.
This model makes use of two data files. The main one is a CSV (comma-separated value) file, which can either be edited by hand, or exported from a spreadsheet. This contains two columns of data, with headers. The following is an example:
ID1,ID2
1,2
1,4
2,5
3,4
3,5
4,5
Equations in Patch
ID = index(1)
Equations in Neighbour
condition = (any(ID1 == [ID1]and ID2 == [ID2]) or any(ID1 == [ID2]and ID2 == [ID1]))
where: ID1 = Patch/ID (from Patch in role1) ID2 = Patch/ID (from Patch in role2) [ID1] = Neighbour data/ID1 [ID2] = Neighbour data/ID2
Equations in Neighbour data
ID1: read from .csv file
ID2: read from .csv file
in submodel /Neighbour
at time 0
Sun Feb 26 19:57:04 +0000 2012
Maxlevel=2
1 2 "true" 4 "true"
2 1 "true" 5 "true"
3 4 "true" 5 "true"
4 1 "true" 3 "true" 5 "true"
5 2 "true" 3 "true" 4 "true"
Attachment | Size |
---|---|
assoc_from_data1.csv | 37 bytes |
assoc_from_data1.sml | 66.44 KB |