to draw-simple
let top-wall 0
let bottom-wall 0
ask patches [set pcolor 7]
repeat 81 [
ask patch top-wall ((horizontal-corridor-width + 1) / 2) [
set pcolor 0
]
set top-wall (top-wall + 1)
]
repeat 81 [
ask patch bottom-wall (-((horizontal-corridor-width + 1) / 2)) [
set pcolor 0
]
set bottom-wall (bottom-wall + 1)
]
endhorizontal-corridor-width is a slider from 1 to 20. The drawing is as follows.

I want to distribute my agents along the hallway without traspassing the walls. I have tried something like this.to create-pedestrians-simple
create-east-crowd num-pedestrians-east [
set color red
set size 1
setxy 40 0
set heading 270
]
create-west-crowd num-pedestrians-west [
set color blue
set size 1
setxy random-xcor random-ycor
set heading 90
]
end
east-crowd and west-crowd are breeds and the variables num-pedestrians-east and num-pedestrians-west are sliders from 0 to 1600 agents.
Hope to be clear enough.
Thank all of you, dear comunity.
--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/6a9d0c05-a675-4b2a-a27a-ad63b02ce7b0%40googlegroups.com.
Hi Mustafa,
Here is an answer to your question, along with a couple of suggestions.
Since a single agent in your model is a pedestrian, I suggest you use names similar to those below, which would be consistent with variable names such as num-pedestrians-west
It is custom, but not requirement to call the initialization function setup, and to clear values at the beginning.
Notice in create-corridor that it is possible to address a whole set of patches at once (although your method works too).
I use the function ceiling to identify the same patches you do. For example if horizontal-corridor-width is 20
patch 0 10.5 is the same as patch 11, and ceiling 10.5 = 11. while
patch 0 -10.5 is the same as patch -10, and ceiling -10.5 = 10
The question you were specifically asking is answered by the function
random-corridor-ycor
The approach is similar to that suggested by Pradeesh. I use random-float rather than random, in order to get non-integer values, and don’t treat agents above and below the x axis separately
Code:
breed [ pedestrians-east pedestrian-east ]
breed [ pedestrians-west pedestrian-west ]
to setup
clear-all
reset-ticks
create-corridor
create-pedestrians-east num-pedestrians-east [
set color red
set size 1
setxy random-xcor random-corridor-ycor
set heading 270
]
create-pedestrians-west num-pedestrians-west [
set color blue
set size 1
setxy random-xcor random-corridor-ycor
set heading 90
]
end
to create-corridor
ask patches [set pcolor 7]
ask patches with [ pycor = corridor-top or pycor = corridor-bottom ] [
set pcolor 0
]
end
to-report corridor-top
report ceiling ((horizontal-corridor-width + 1) / 2.0)
end
to-report corridor-bottom
report ceiling ((horizontal-corridor-width + 1) / -2.0)
end
to-report random-corridor-ycor
; The smallest y coordinate should be above the corridor bottom
; The size of the occupiable corridor space is horizontal-corridor-width - 1
report corridor-bottom + 1 + random-float (horizontal-corridor-width - 1)
end
Aaron Brandes, Software Developer
Center for Connected Learning and Computer-Based Modeling
From:
<netlog...@googlegroups.com> on behalf of Mustafa Ali Saba <alisaba...@gmail.com>
Date: Sunday, January 12, 2020 at 10:25 PM
To: netlogo-users <netlog...@googlegroups.com>
Subject: [netlogo-users] How to randomly allocate my agents?
Hi dear friends,
I have a world like this.
to draw-simple
let top-wall
0
let bottom-wall
0
ask patches [set
pcolor 7]
repeat 81
[
ask patch top-wall
((horizontal-corridor-width
+
1)
/
2)
[
set
pcolor 0
]
set
top-wall
(top-wall
+
1)
]
repeat 81
[
ask patch bottom-wall
(-((horizontal-corridor-width
+
1)
/
2))
[
set
pcolor 0
]
set
bottom-wall
(bottom-wall
+
1)
]
end
horizontal-corridor-width
is a slider from 1 to 20. The drawing is as follows.

I want to distribute my agents along the hallway without traspassing the walls. I have tried something like this.
to create-pedestrians-simple
create-east-crowd
num-pedestrians-east
[
set
color red
set
size 1
setxy 40
0
set
heading 270
]
create-west-crowd
num-pedestrians-west
[
set
color blue
set
size 1
setxy random-xcor
random-ycor
set
heading 90
]
end
east-crowd and west-crowd are breeds and the variables num-pedestrians-east and num-pedestrians-west are sliders from 0 to 1600 agents.
Hope to be clear enough.
Thank all of you, dear comunity.
--
--