This page was automatically generated by NetLogo 5.0.2.
The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher. Windows and Linux users may obtain the latest Java from Oracle's Java site.
In order for this to work, this file, your model file (metapop.nlogo), and the files NetLogoLite.jar and NetLogoLite.jar.pack.gz must all be in the same directory. (You can copy NetLogoLite.jar and NetLogoLite.jar.pack.gz from the directory where you installed NetLogo.)
The applet will also need access to the gis extension. Copy the entire directory for each required extension into the same directory as the applet.
On some systems, you can test the applet locally on your computer before uploading it to a web server. It doesn't work on all systems, though, so if it doesn't work from your hard drive, please try uploading it to a web server.
You don't need to include everything in this file in your page. If you want, you can just take the HTML code beginning with <applet> and ending with </applet>, and paste it into any HTML file you want. It's even OK to put multiple <applet> tags on a single page.
If the NetLogoLite files and your model are in different directories, you must modify the archive= and value= lines in the HTML code to point to their actual locations. (For example, if you have multiple applets in different directories on the same web server, you may want to put a single copy of the NetLogoLite files in one central place and change the archive= lines of all the HTML files to point to that one central copy. This will save disk space for you and download time for your users.)
powered by NetLogo
view/download model file: metapop.nlogo
This is a very simple implementation of a Levins type metapopulation.
All patches are assumed to be homogeneous with respect to extinction risk when occupied (ext_prob expressed as % in the interface)
If an unoccupied patch has any linked patch which is occupied it can be recolonised with a certain probability (col_prob expressed as % in the interface)
Centroids are loaded using the GIS extension. However in this version the links are provided by loading a file containing linestrings of known length that represents the shortest edge to edge distance between patches. This layer has been built using a query in PostGIS.
http://duncanjg.wordpress.com/2012/09/23/edge-to-edge-distance-using-postgis/
This greatly improves the way the model handles connectivity. The improvement can best be seen when the vector polygons are added, as the model will connect large patches much better than the more simplistic version using distances between centroids.
As the model stands it is still only useful for teaching the concept.
Sensitivity could be analysed using the behaviour space tool. While the model is too simplistic to represent any real situation it is paramaterised using real GIS data and therefore can be related to a known landscape. In this case, the New Forest, but other vector layers can easily be used.
The model does not take into account the area of the habitat when evaluating extinction risk.
Notice that the grey links are between centroids as before. Their “distance” property however is determined edge to edge. So long lines may in fact represent short distances. The reverse of the tube map!
Change any of the parameters.
Watch the ouptut in order to see on which parts of the network the populations persist.
Many more realistic elements could be built from here.
As the habitat nodes do know about their area this could fairly easily be incorporated in the model True interpatch distances are also known, so dispersal could be made more realistic. If cost surfaces were included it would probably be better to use an individual based ABM rather than patch based.
Note the simplicity of the code for actually making the model run.
This is a very similar little model in R.
http://duncanjg.wordpress.com/2008/02/07/simple-source-sink-model/
Duncan Golicher
extensions [ gis ];;This makes the gis extension available. ;; It is provided by default in netlogo 5 ;; ;;The netlogo lists into which the gis layers are loaded have to be defined as ;; globals. So we have "wood" for the polygons and centroids ;; There is also a global scale factor that is used to translate meters into ;; Netlogo units. It took me a while to see why this was necessary, as I assumed ;; it was all taken care of in the "setup-gis-world" function ;;In fact it is very important to get this right when loading rasters and setting patch variables from them. globals [path bbox edge2edge centroids scale_factor clustern] ;; The global variables include the names that the GIS layers will have when imported ;; The scale_factor is the ratio between the width of a netlogo patch and the unit of ;; measurement (m) in the GIS layer. breed [habitats habitat] ;; The nodes are habitats. They are given a breed name habitats-own [gid area perimeter occupied? cluster] ;;The properties of the habitats could be extended in a more detailed model links-own [dist] ;; Links may own the property of distance, if measured. In a model with edge-edge distance this ;; will become very important. to startup clear-all set clustern 1 set scale_factor 100 ;; Do not forget the scale factor! 1 km will be 10 units in the model. ;; Import the polygons set bbox gis:load-dataset "bbox.shp" set edge2edge gis:load-dataset ("edge_to_edge2000.shp") set centroids gis:load-dataset "NFAnWood_Centroids.shp" ;;Import the centroids setup-gis-world gis:envelope-of bbox 1.8 ;; The line above is vital. Check the setup-world-function below for more details. gis:draw centroids 2 ;; This does what it says. The centroids are now drawn on the interface. But they may be ;; overwritten once they have been converted into "turtles" of the habitat breed using the ;; code below. ;; Notice that we need to cycle through the feature list. Each member of this list ;; coincides with a row in the vector layer attributes table. foreach gis:feature-list-of centroids [ ;; In this case there should only be one vertex, but use the code in the conventional ;; Gis extension example for safety. let location gis:location-of (first (first (gis:vertex-lists-of ?))) ;; Now simply place a habitat turtle at each position and set all its attributes- ;; Some of these are read from the vector layer. create-habitats 1 [ set shape "circle" set color green set xcor item 0 location set ycor item 1 location set gid gis:property-value ? "gid" set area gis:property-value ? "area" set size 3 set occupied? FALSE set perimeter gis:property-value ? "perimeter" ]] end to setup make-network reset-ticks clear-plot clear-all-plots end to go run-a-step tick if count habitats with [occupied? = TRUE] = 0 [stop] end to-report sdistances foreach gis:feature-list-of edge2edge [ let to_gid gis:property-value ? "to_gid" let from_gid gis:property-value ? "from_gid" let dist gis:property-value ? "distance" show dist ] end to make-network ask habitats [ set cluster 0] clear-links foreach gis:find-less-than edge2edge "distance" sep_dist [ let to_gid gis:property-value ? "to_gid" let from_gid gis:property-value ? "from_gid" let dist gis:property-value ? "distance" if to_gid != from_gid [ ask one-of habitats with [gid = from_gid] [create-link-with one-of other habitats with [gid = to_gid ] [set dist dist set thickness 1 set color black] ]]] find-clusters start-metapop end to setup-gis-world [env patchsize] ;; The bounding box is read from the gis layer that is passed to this function. See the call in "setup". let gis-width item 1 env - item 0 env ;; Find the width of the box in GIS units (probably meters) let gis-height item 3 env - item 2 env ;; Find the height in GIS units. resize-world 0 gis-width / scale_factor 0 gis-height / scale_factor ;; This is VITAL: The underlying coordinate system is resized. This is not explicit in the examples provided. ;; It is necessary to ensure that when a call is made to a function such as "in-radius" there is a clear ;; reltionship between the units used by netlogo and the GIS units. In this case the scale factor of 100 results in ;; a corrspondence of 1 unit in netlogo space to 100 m in gis space. This is not obvious in examples ;; which do not mix the two. It is particularly important when rasters are imported, as this is all related to resolution ;; and grain size. set-patch-size patchsize ;; The patch size could be derived automatically, but here it is set in the function call. ;; Again be careful here. This controls the grain size of the diplay. ask patches [set pcolor white] gis:set-world-envelope env end to start-metapop ask n-of 50 habitats [set color red set occupied? TRUE ] end to run-a-step ask habitats [ if random 100 < ext_prob [ set occupied? FALSE set color green] if any? link-neighbors with [occupied? = TRUE] AND random 100 < col_prob [set occupied? TRUE set color red] ] end to add-google import-drawing "newforest.png" end to add-sat import-drawing "newforestsat.png" end to find-clusters ;; This is taken from one of the code examples in the model library ask habitats[ loop [ let seed one-of habitats with [cluster = 0] ;; if we can't find one, then we're done! if seed = nobody [ stop ] ;; otherwise, make the habitat the "leader" of a new cluster ;; by assigning itself to its own cluster, then call ;; grow-cluster to find the rest of the cluster ask seed [ set clustern clustern + 1 set cluster clustern grow-cluster ] ] ] end to grow-cluster if any? link-neighbors with [cluster = 0] [ ask link-neighbors with [cluster = 0] [ set cluster clustern ;;set color cluster grow-cluster ] ] end to-report max-size let clusterids (remove-duplicates [cluster] of habitats with [occupied? = TRUE]) let cluster-counts map [ count habitats with [ cluster = ? and occupied? = TRUE ] ] clusterids ifelse length cluster-counts > 0 [report max cluster-counts] [report 0] end to-report nmetas report length remove-duplicates [cluster] of habitats with [occupied? = TRUE] end to-report nclusters report length remove-duplicates [cluster] of habitats end to-report npops report count habitats with [occupied? = TRUE] end