Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I'm learning ABM from a book called Agent-Based and Individual-Based Modeling by Railsback and Grimm. According to the book, the first complete model they walk through looks like this:
globals
turtles-own
[
time-since-last-found
]
num-clusters
]
[
time-since-last-found
]
[
num-clusters
]
to setup
clear-all
set num-clusters 4
ask n-of 4 patches
[
ask n-of 20 patches in-radius 5
[
set pcolor red
]
]
create-turtles 2
[
set size 2
set color yellow
set time-since-last-found 999
]
end
to go
ask turtles [search]
to search
if-else time-since-last-found <= 20
[right (random 181) -90]
[right (random 21) -10]
forward 1
ifelse pcolor = red
[
set time-since-last-found 0
set pcolor yellow
]
[
set time-since-last-found time-since-last-found + 1
]
end
The book says I should be able to to run the simple Mushroom Hunt model. But, instead, I keep getting an error message that says I need an extra [, "Expected [".
I have no idea where I need to put it. What's more, it really does seem to me that I don't need it and I don't understand why it's saying I do.
Thanks!
It might be helpful to check out the Netlogo Programming Guide as you read through Railsback and Grimm. It helps outline proper syntax and explains in a different way what code needs to go in what place.
With your code above, there are several problems- for example, review Globals and Turtles-own. Note how square brackets should contain the variables in each of those blocks. Next, look at how procedures all start with to and finish with end - you should see that there is a "search" procedure nested in your "go" procedure above.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I want to get the sum of values parameters and multiply by 3,
{
"timestamps": "2021-04-15T11:39:00Z",
"properties": [{
"values": [1, 2, 3, 4],
"name": "Value.Restricted",
"type": "Long"
}],
"progress": 100.0
}
Kindly see attached file for your reference. Thank you so much in advance
Screenshot
To get the sum of these values attribute you can use JSON JMESPath Extractor, example query:
sum(properties[0].values)
Demo:
If you want to multiply it by 3 - it can be done using i.e. __jexl3() function:
${__jexl3((${sum} * 3),)}
it will return floating point number like 10.0 if you need just 10 - call intValue() chain function
${__jexl3((${sum} * 3).intValue(),)}
This one stumping me...
I have an ABM which generates new patients arriving to a hospital unit by random-poisson on a single patch (spout procedure). Each patient is assigned an area to go to and a time to spend in the unit according to the area and other assigned variables. When I created this with the distributions embedded in the procedures or reporters it worked fine every time, but when I code the random variables into the set up to make it easier to manipulate it regularly generates grossly abnormally low/high values (ranges not seen when run in original format) and sometimes the creation of new patients doesn't happen at all though the model still ticks on... The only things changed are the placement of the variables in set up and and not in the body of the code.
I can't figure out why it would randomly have no patients entering the system which makes me mistrusting of anything else it generates. Is this just a formatting style that Netlogo doesn't like? Or am I missing something?
Thanks for any advice/help in solving this one
original code:
if ticks = 1000 [stop]
ask arrivals
[
assess
crowding-check
relocate
]
end
to assess
sprout-patients random-poisson 1.5
[set time_arrived ticks
set condition random-float 1.0
set NEWS2 random-float 7.0
set shape "person"
]
end
to-report AEC_treatment_time ;; gamma dist
let result random-gamma 3.478 0.525
if result < 2 [ report 2 ]
if result > 20 [ report 20]
report result
end
to-report AMU_treatment_time ; gamma dist
let result random-gamma 5.7716 0.3
if result < 4 [ report 4]
if result > 48 [ report 48]
report result
end
new code:
ca
set new-patients random-poisson 1.5
set AEC-los random-gamma 3.478 0.525
set AMU-los random-gamma 5.7716 0.3
reset-ticks
end
to go
if ticks = 1000 [stop]
ask arrivals
[
sprout-patients new-patients
assess
crowding-check
relocate
]
end
to assess
ask patients-here
[set time_arrived ticks
set condition random-float 1.0
set NEWS2 random-float 7.0
set shape "person"
]
end
...
to-report AEC_treatment_time ;; gamma dist
let los-AEC AEC-los
if los-AEC < 2 [ report 2 ]
if los-AEC > 20 [ report 20]
report los-AEC
end
to-report AMU_treatment_time ; gamma dist ;; reports treatment time for patients in AMU
let los-AMU AMU-los
if los-AMU < 4 [ report 4]
if los-AMU > 48 [ report 48]
report los-AMU
end
ps trying multiple iterations, it seems to be the random-poisson change that is the one causing the issues
It's pretty hard to see without the full code as it looks to be a problem with the way procedures connect, but your new structure has ask patients-here (at the start of the assess procedure) inside a loop through ask arrivals (go procedure). Is arrivals a breed?
Generally it is a bad thing to have nested ask turtles type structures because each turtle ask all turtles that satisfy the conditions so you can get subtle errors. Anyway, this will probably get you back to what you were doing before:
to go
if ticks = 1000 [stop]
ask arrivals
[ sprout-patients new-patients [assess]
crowding-check
relocate
]
end
to assess
set time_arrived ticks
set condition random-float 1.0
set NEWS2 random-float 7.0
set shape "person"
end
This structure makes the assess procedure into a procedure that runs from the turtle's perspective (or context) and has it run immediately as the turtle calling it is created.
i am trying to model the following hierarchical structur in Netlogo:
Imagine a typical company or a a brach of public administration. There is one boss (turtle) on top and a number of employees (turtles) below him/her. There are two variables: span-of-control soc (how many employees can one Boss overwatch) and depth-of-control doc (how many hierarchical levels do exist in the structure). The total number of employees equals soc^doc. The total number of turtles equals 1+soc^doc (1 is the boss).
There are two Choosers in the Netlogo-Interface: soc and doc (ranging from 1 to 4).
What I imagine to code: Depending on the Variables chosen, the structure should arrange itself automatically by the following rule: Create as many links to employees as there have been employees on the higher hierarchical level until the doc is reached.
Example: doc:3 soc:3 1 Boss (always 1 so it can be used like an anchor)
1. Level: 3 links (1*3)
2. Level: 9 Links (3*3)
3. Level: 27 Links (9*3)
4. Level: Over as doc is reached
To realise this, I need to make the turtles kind of read the doc and soc variables and make them create links accordingly but I dont know how.
Here is my code so far:
globals [
information
]
undirected-link-breed [ Informationflows Informationflow ]
breed [ Employees Employee ]
breed [ tasks task ]
breed [ Bosses Boss ]
;#########SETUP########
to setup
clear-all
create-Bosses 1 [ set color red
set size 2 ]
set-default-shape Bosses "person"
ask Bosses [ setxy 0 15 ]
ask patches [ set pcolor white ]
set-default-shape Employees "person"
create-Employees ( span-of-control ^ depth-of-control) [set color blue
set size 2 ] ; absolute Number of Employees
;ask Boss 0 [ create-Informationflow-with random Employee 8] ; IDEA
;ask Employees [ create-Informationflow-with one-of other Employees] ; IDEA
;ask Employees [ create-Informationflow-with Boss 0 ] ; IDEA
repeat 100 [ layout ]
ask Employees [
setxy 0.95 * xcor 0.95 * ycor ]
end
to-report value-of-span-of-control? ; Just an idea
report span-of-control
end
;##########LAYOUT##########
to layout
; layout-radial Employees Informationflows (Boss 0) ;Problem: Boss is fixed in the Center
layout-spring Employees Informationflows 0 10 2
end
If anybody could hint me in the right direction, I would be very thankful.
Kind regards,
Jon
Okay, general coding advice first - do ONE thing, test it and fix it before moving on to the next thing.
Your question about how to 'read' the doc and soc variables makes me think you are very new to NetLogo. If so, please go and do the tutorials that are at the NetLogo site. Creating a chooser with the name 'XYZ' creates a global variable named 'XYZ', there is no additional step to read it. Since you are choosing numbers, you might want to use a slider instead of a chooser.
Try replacing your commented out ask Boss line with this:
ask one-of Boss [ create-Informationflow-with n-of soc Employees ]
It's generally bad practice to use who numbers because turtles can die or be generated in a different order because you change some code and then the who numbers are different. So I used one-of to randomly select any boss (of which there is only one anyway). I similarly used n-of to select Employees to create links with and specified the number n in the n-of to be the value from the soc variable.
I'm trying to write a simple chat application in Rebol which is based on a single text file.
What would be the best way to read that file "real time"?
Right now I've got it working with this:
t1: text 600x300 wrap green black font-name font-fixed rate 1 feel[
engage: func [face action event][
if action = 'time [
face/text: read chatText
show face
]
]
]
The text field gets updated every second with the content of the file. That works, even with multiple users, but the whole file is read every second for every user.
Is there a better way to do this kind of thing?
Have a look on info? function.
You can do something like this:
REBOL []
chat-file: %file.txt
file-info: info? chat-file
update-date: file-info/date
view layout [
t1: text read chat-file 600x300 wrap green black font-name font-fixed rate 1 feel [
engage: func [face action event] [
if all [
action = 'time
file-info: info? chat-file
update-date < file-info/date
] [
update-date: file-info/date
face/text: read chat-file
show face
]
]
]
]
But you need to be careful if you will write to the file from multiple apps.
my agents set trade_Price than when they trade and they save their profit to their payoff variable. in ai process I have to code that my agents have to look around and choose the neighbor agent with the highest payoff. and than the agent has to give his decision value to this agent. I asked it before and got this code:
ask buyers [
let current-buyer self
ask sellers [
let current-seller self
let how-much 1
set decision ;some number
ask current-buyer [
set decision ;some number
]]]
but got something else what i wanted. Than I code it myself so:
ask sellers
[ let partner one-of buyers-here if partner != nobody
[ move-to one-of partner with-max [decision] of buyers]]
But there are also mistakes, could you give a tip or at least which code is the right way?
Revised in response to comment:
ask sellers [
let candidates (buyers-on neighbors)
ifelse any? candidates [
let partner one-of (candidates with-max [decision])
move-to partner
][
die ;; or whatever you want to do in this case
]
]