I am trying to update my model to NL 6 because the automatic update failed (mostly due to syntax for anonymous procedures). My model uses the rnd extension which now apparently comes bundled with NetLogo, but the example from the manual still mentions this:
extensions[rnd]
to go
let pairs [ [ "A" 0.2 ] [ "B" 0.8 ] ]
repeat 25 [
; report the first item of the pair selected using
; the second item (i.e., `last ?`) as the weight
type first rnd:weighted-one-of-list pairs [ last ? ]
]
end
This results in an error because "nothing named ? has been defined". I have been able to convert other things like foreach and n-values, but I am struggling with this example to the new notation required by NetLogo 6. Can someone help?
We missed a few cases when converting the rnd extension manual for bundling it with NetLogo. This will be fixed in NetLogo 6.0.1. In the meanwhile, you can refer to the most current version of the manual on GitHub:
https://github.com/NetLogo/Rnd-Extension/blob/hexy/README.md
In your specific case, the NetLogo 6 syntax would be:
rnd:weighted-one-of-list pairs [ [p] -> last p ]
Related
With the use of the myself primitive, I want a patch with a certain land use to make buildings of that type in a specific radius, but it's not working. Here is the code:
patches-own [land-use] ;land-use can take many types: "residential", "industrial", "commercial"
...
to grow
ask patches with [land-use = "residential"]
[ask other patches in-radius 10 [
if [land-use = "residential"] of myself [build-house]]]
end
How can this be fixed?
The problem there is not myself but the use of of. Two things to fix:
of requires the reporter to be in square brackets. Only the reporter that of refers to, not the whole condition being tested (as in your case where you are testing a condition).
You should not specify the value of the variable but just its name. Just as in normal language: you wouldn't say "If your hair colour equals my blonde", but you would say "If your hair colour equals my hair colour".
The resulting syntax is:
if (land-use = [land-use] of myself) [
build-house
]
Parentheses surrounding the condition are optional, I use them as a stylistic choice.
PS Regarding point 2 above... of course you could keep the value of the variable (i.e. "residential") instead of the name of the variable (i.e. land-use), and in that case drop of myself.
You would have:
if (land-use = "residential") [
build-house
]
And as of now it would work because the patches starting this process are just those with land-use = "residential"... but this doesn't look like great code, as it is not extendable to other variable's values and it contains more hard-coding than necessary.
Im having trouble including a formula in the input box into my model and hoped someone could help. In short I want the global variable "subsidy_absolute_threshold" to be read as "100 + m2 / 1600". So that wherever that variable is implemented, that code is implemented instead. The current code reads something like
turtles-own [m2 subsidy_eligible]
globals [subsidy_absolute_threshold]
[...]
set subsidy_absolute_threshold "100 + m2 / 1600"
[...]
ask turtles [
if ambition < read-from-string subsidy_absolute_threshold [set subsidy_eligible true]
]
Technically the global value is an input box set as a string, but it should be functionally the same thing. The error message I get is "Extra characters after literal." which I struggle to understand.
I have tried all the "types" of input boxes, but none work. I have also tried directly writing in the formula, as in replacing subsidy_absolute_threshold with 100 + m2 / 1600, which works.
Use the native command runresult instead of read-from-string.
I'm somewhat unsure exactly why read-from-string does not work, so if someone wants to present an explanation please do.
I have a simulation for a fire-evacuation, and the fire starts form different sources.
I want to simulate the exit with the least number of injuries, while having 3 exits it's 3 scénarios.
But my issue, is that the simulate each exit with different fire sources. How can I fix the same scenario for three simulations ?
Here is the code :
to run-all
clear-all
let temp (list ("left") ("right") ("top"))
foreach temp [
[a] ->
setup
set finished 1
if a = "left" [
while [finished = 1] [
go-to-left
]
]
if a = "right" [
while [finished = 1] [
go-to-right
]
]
if a = "top" [
while [finished = 1] [
go-to-top
]
]
]
end
I don't think that you need to change the code you posted here. The place to look is in your "setup" code, which you did not post.
Probably in your setup code you use "random" to create places for people to stand, so what you need is to have "random" generate the exact same locations for each of many different passes, so you can compare the different exits with the same starting conditions.
The way to do that is to set the "seed" that "random" will use ( secretly ) to exactly the same seed at the start of each pass you want to be identical.
Then if you want a new series of runs with different random locations, change the seed to a different number and use that at the start of each run
The command to do that is described in the User dictionary under "random-seed", where it also tells you See the Random Numbers section of the Programming Guide for more details.
From each of the turtle's perspectives, I have to run a function for a turtle to decide which turtle it will assign as it's "buddy".
Right now I have the code below but it doesn't achieve the effect.
foreach sort other turtles [
ask ? [
if Smin < Sim myself ? and self != ? [
]
]
]
In C/Java it would've been simple, just a simple for loop and then that's it. Apparently I am having a hard time understanding NetLogo's foreach function and the integration of '?' in looping. How can I do this?
It's unclear from the code sample you posted what exactly you are trying to do.
Some things that may help:
Unless you want to address your turtles in a specific order, it's usually not necessary to use foreach. Just doing ask other turtles [ ... ] can replace the whole foreach sort other turtles [ ask ? [ ... ] ].
Given that you are inside an ask ? block, self != ? will always be false, and thus, so will the and clause of your if. The code inside your inner block is never reached.
myself refers the agent from an "outer" ask block (e.g., in ask x [ ask y [ ... ] ], self would be y and myself would be x). Neither myself nor self is affected by foreach, and ? is not affected by ask.
My guess is that maybe you just want:
ask other turtles [
if Smin < Sim myself self [
]
]
But I can't know for sure, especially since I have no idea what Smin and Sim are. If you post more detail, maybe we can help you further.
Finally: NetLogo code usually ends up being much simpler than the equivalent C/Java code, but you must learn to embrace the "NetLogo way". Thinking in Java/C and then trying to translate in NetLogo will usually lead one astray.
I am implementing an evacuation simulation of a lecture hall.And i have two types of students those who sit on tables and extra students who allocated randomly inside the class.So i created two sliders in order to allocate the students at the desired numbers.The sliders are named extrastudents and standarstudents. When the simulation starts i want all the students (both in tables and extras students) to go to the nearest exit ( i have two exits ) .So i implemented that for only the students that are seating down :
ask standarstudents [
ifelse pycor > 0
[ set target one-of nexits]
[ set target one-of sexits]
face target
]
Nexits is the north exit.
Sexits is the south exit.
The problem is that i get this error and i can move on :
ASK expected input to be an agent or agentset but got the number 3 instead.
error while observer running ASK.(The number 3 derives from the slider that user is pick)
called by procedure SETUP
called by Button 'setup'
org.nlogo.nvm.ArgumentTypeException: ASK expected input to be an agent or agentset but got the number 3 instead.
any ideas?
Well, if you have sliders named extrastudents and standarstudents, those two variables are numeric values representing how many students of each kind you want, not the students themselves. Like the error message says, the ask primitive works with agentsets that represent "who you are asking".
Have you actually created your students? Putting sliders on the interface won't do anything by itself. I would suggest renaming your sliders to something like num-extrastudents and num-standarstudents and then using code like this to initialize your population:
breed [ extrastudents extrastudent ]
breed [ standarstudents standarstudent ]
to setup
create-standarstudents num-standarstudents
create-extrastudents num-extrastudents
end
Then, the code you have posted would work because extrastudents and standarstudents would be breeds of turtles, and thus, agentsets.