66936

Distance-based mortality model in netlogo

Question:

I am calculating cumulative turtle mortality in netlogo as a function of distance moved by turtles (100 of them) from the origin (start-patch) in the netlogo interface world. In the code below the 'Pass-Away' procedure is linked to a global interface switch called "space-death" which when switched on yields said distance-based mortality undertaken by the procedure called "Pass-Away-Space", otherwise maintains regular per-time-step (tick) mortality undertaken by the procedure called "Pass-Away-Time":

to Pass-Away-Time ask turtles [ let chances 1 - exp( -1 * mortality * ticks ) if chances >= 1 [die set dead-count dead-count + 1 ] ] end to Pass-Away-Space ask turtles [ let chances 1 - exp( -1 * mortality * [distance start-patch] of turtles) if chances >= 1 [die set dead-count dead-count + 1 ] ] end to Pass-Away ask turtles [ ifelse space-death [ Pass-Away-Space][ Pass-Away-Time ] ] end

I get two errors doing this, both likely due to issues with the coding of the "Pass-Away-Space" procedure. The first is <em>Only the observer can ASK the set of all turtles.</em> Then when I move the let chances 1 - exp( -1 * mortality * [distance start-patch] of turtles) outside of the ask turtles[] brackets this error is resolved only yield another that says ** expected input to be a number but got the list* followed by a sequence of numbers. Perhaps due to the fact that the section of the mortality equation that reads * [distance start-patch] of turtles is invoked for multiple turtles (which is exactly what I want to achieve - have each random-walking turtle use its distance from the origin to calculate its cumulative per-step mortality and die above a threshold - an event that occurs at different times for different turtles at different distances). Any thoughts on how to resolve this?

Answer1:

The first error is because you are asking all turtles to ask all turtles. Starting with your Pass-Away procedure and assuming space-death is set to TRUE. What happens? You ask all turtles to run the Pass-Away-Space procedure. That is, each turtle will run that procedure in turn. The first step of that procedure is to ask turtles [ ]. So a turtle is asking all turtles to do something. Hence the error.

To fix it, you need to rewrite the Pass-Away-Space procedure so it runs whatever code needs to be run for a SINGLE turtle (and similarly for Pass-Away-Time). You probably want something like:

to Pass-Away-Space if exp( -1 * mortality * [distance start-patch]) < 0 [ die set dead-count dead-count + 1 ] end

Answer2:

So the first issue here is the nested use of the ask turtles [ ... ] command, which we can disambiguate by removing it from the to Pass-Away procedure or alternatively, from both of the other two (preceding) functions nested within it, as seen below (demonstrating the later of the aforementioned means.

let start-patch patch 0 0 to Pass-Away-Time ask turtles [ let chances 1 - exp( -1 * mortality * ticks ) if chances >= 1 [die set dead-count dead-count + 1 ] ] end to Pass-Away-Space ask turtles [ ; let chances 1 - exp( -1 * mortality * [distance start-patch] of turtles) let chances 1 - exp( -1 * mortality * (distance start-patch)) if chances >= 1 [die set dead-count dead-count + 1 ] ] end to Pass-Away ifelse space-death [ Pass-Away-Space][ Pass-Away-Time ] end

The second error can be resolved by switching the line of code commented (;) out in the to Pass-Away-Space procedure withe the immediate succeeding line so that when each turtle attempts to execute chances, cumulative per-distance (from origin) mortality is not calculated as an array of turtle chances with the use of the [distance start-patch] of turtles command, but rather per individual turtle with (distance start-patch) whenever the procedure is called by the nesting to Pass-Away procedure.

Recommend

  • Request and session in Servlet
  • Alternative to Lock.tryLock() in Java 1.4
  • How do I selecting a date range (like onClick but drag/select)
  • Why is my database not being updated when someone visits my website?
  • Google Street View container inside Shiny Application
  • Apply kurtosis to a distribution in python
  • What is the logic behind d3.js nice() ticks
  • Installing Flash Player on an Android Emulator
  • Individual Preferences for each item in a ListView?
  • Verbose log abbriviations meaning in SVC, scikit-learn
  • Making a panel persist despite click on page opened in browser
  • double precision error when converting to scientific notation
  • Is creating a new version of an object in AWS S3 eventually consistent or read-after-write consisten
  • Passing parameter through “window.location.href”
  • Raphael.js function getBBox give back NAN/NAN/NAN in IE8
  • matching similar elements in between two lists
  • JSON - slashes not escaping
  • IE10 strips out hashtag from the URL
  • Create a link to a web page that runs a Javascript function on the page
  • PDO error when wrong host name
  • Randomizing -and remembering that randomisation- multiple choice questions in php
  • Using Sax parsing to edit and write XML in VB6
  • SetWindowsHookEx does not react on media keys
  • Create Instant using a negative year
  • Django: Count of Group Elements
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Sending data from AppleScript to FileMaker records
  • MySQL WHERE-condition in procedure ignored
  • jQuery tmpl and DataLink beta
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • Qt: Run a script BEFORE make
  • How can I remove ASP.NET Designer.cs files?
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • reshape alternating columns in less time and using less memory
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?