Hi,

There are a couple of things I noticed in your code. For the isolation procedure, you ask all turtles at each tick, which is why they are moving around. Once a turtle becomes isolated, it shouldn't be asked to be isolated again. You can address this in a couple of ways. I've written some pseudo-code, which may help.

To isolation

Ask turtles with [isolation? = false] [

Whatever Conditions that determine isolation [

Set isolation? TRUE]

]

end

The other thing I noticed is that you ask turtles then you ask breeds nested within the ask turtle call. You don't need to do this. When you ask turtles, you ask all turtles including breeds. For example, in GO when you call the isolation procedure you ask turtles, then you ask passengers and workers inside the ISOLATE procedure. You also have a lot of unnecessary ask statements. Think about how to consolidate them. This will speed up your model.

-----Original Message-----

From:

[hidden email] [mailto:

[hidden email]]

Sent: Friday, November 17, 2017 10:05 AM

To:

[hidden email]
Subject: [EXTERNAL] [netlogo-users] Cruise Ship Sickness - unwanted turtle movement

Hello,

I'm trying to create a model of sickness spreading on a cruise ship. My

current problem is that when the turtles (passengers or workers) are sick

and isolated, they continue to set a new random position on each go. To

solve this, I tried to create a confine function so that once isolated, the

turtles would stay on their patch. However, the built-in stop function does

not appear to be working how I thought. What is the best way to keep turtles

on the same patch? Or is it possible to have them return to their set-up

patch once sick and isolated?

I've included our code below.

Thank you for your help!

Amanda

breed [passengers passenger]

breed [workers worker]

globals

[

%infected_p ; percent infected passengers

%infected_w ; percent infected workers

%total_infected ; total percent of all on board infected

time-hour ; hour of each day

day-count ; length of cruise

number-workers ; 1 worker for every 3 passengers

]

patches-own

[

patch-deck?

patch-common?

patch-cabin?

]

turtles-own

[

steps ; number of movements per tick

sick? ; if true, they are sick

isolated? ; if true, they are sick and go to cabin

infectious? ; if true, they are sick and contagious

incubation ; time since they were infected

confine? ; once isolated, they are sick, not infectious and confined to

cabin

; isolation-tendency ; chance that person will self-isolate

]

to setup

clear-all

initialise-time

setup-ship

setup-passengers

setup-workers

set day-count 1

reset-ticks

end

to initialise-time ; day starts at midnight

set time-hour 0

end

to setup-ship

ask patches with [(pycor >= 9 and pycor <= max-pycor)]

[

set patch-deck? true

set pcolor sky

]

ask patches with [(pycor >= 0 and pycor <= 8)]

[

set patch-common? true

set pcolor gray + 1

]

ask patches with [(pycor >= -13 and pycor <= 0)]

[

set patch-cabin? true

set pcolor black

]

; set border_1 patches with [abs (pxcor) >= 0 and pycor = 9]

; ask border_1 [set pcolor yellow]

;

; set border_2 patches with [abs (pxcor) >= 0 and pycor = 2]

; ask border_2 [set pcolor yellow]

;

end

to setup-passengers

create-passengers number-passengers

[ setxy random-xcor (- 11 + random-float 10) set color lime set shape

"person" ]

ask passengers [set sick? false set infectious? false set isolated? false

set confine? false ]

ask n-of 1 passengers ; sickness starts in one passenger

[ get-sick incubate ]

ask passengers [

let empty-patches neighbors with [not any? turtles-here]

if any? empty-patches

[ let target one-of empty-patches

face target

move-to target ]

]

end

to setup-workers

set number-workers (number-passengers / 3) ; 1 worker to every 3

passengers

create-workers number-workers

[ setxy random-xcor ( - 15 + random-float 3 ) set color yellow set shape

"person" set isolated? false]

ask workers [set sick? false set infectious? false set isolated? false set

confine? false ]

ask workers [

let empty-patches neighbors with [not any? turtles-here]

if any? empty-patches

[ let target one-of empty-patches

face target

move-to target ]

]

end

to go

ask turtles

[ if not isolated?

[ move ] ]

ask turtles

[ if sick? and not isolated?

[ incubate move ] ]

ask turtles

[ if isolated? [ isolate ] ]

ask turtles

[ if confine? [ confine ] ]

update-global-variables

update-time

tick

end

to update-global-variables ; for plot

if count turtles > 0

[ set %infected_p (count passengers with [ sick? ] / count passengers) *

100

set %infected_w (count workers with [ sick? ] / count workers) * 100

set %total_infected (( count passengers with [sick?] + count workers

with [sick?])/(count passengers + count workers)) * 100 ]

end

to update-time ; keeps track of hour of each day and number of days

set time-hour (time-hour + 1)

if time-hour = 25 [ initialise-time ; at end of 24 hrs, day resets

set day-count day-count + 1 ]

end

to move

; from midnight - 6 am, everyone sleeps

; if 1 <= time-hour and time-hour <= 6 [

; ask passengers [stop]

; ask workers [stop]

; ]

; at 7am, workers go to common area

if time-hour = 7 [

ask passengers [stop]

ask workers [ setxy random-xcor (1 + random-float 8) ]

]

; at 8am, passengers go to eat breakfast

if time-hour = 8 and day-count = 1 [ ask passengers [ if isolated? [ set

isolated? false ] ] ]

if time-hour = 8 [

set steps 5

ask passengers [ setxy random-xcor (1 + random-float 8) ]

ask passengers [ rt random-float 1

lt random-float 1 set steps steps - 1 ]

ask passengers [ if steps = 0

[ stop ] ]

ask workers [ setxy random-xcor (1 + random-float 8) ]

ask workers [ rt random-float 1 lt random-float 1 set steps steps - 1]

ask workers [ if steps = 0 [ stop ] ]

]

; at 9am, passengers go back to cabin + workers stay in common area

if 9 <= time-hour and time-hour <= 12 [

set steps 5

ask passengers [ setxy random-xcor (- 11 + random-float 10) ]

ask passengers [ rt random-float 1

lt random-float 1 set steps steps - 1 ]

ask passengers [ if steps = 0

[ stop ] ]

ask workers [ setxy random-xcor (1 + random-float 8) ]

ask workers [ rt random-float 1 lt random-float 1 set steps steps - 1]

ask workers [ if steps = 0 [ stop ] ]

]

; at 1pm, passengers go eat lunch

if time-hour = 13 [

set steps 5

ask passengers [ setxy random-xcor (1 + random-float 8) ]

ask passengers [ rt random-float 1

lt random-float 1 set steps steps - 1 ]

ask passengers [ if steps = 0

[ stop ] ]

ask workers [ setxy random-xcor (1 + random-float 8) ]

ask workers [ rt random-float 1 lt random-float 1 set steps steps - 1]

ask workers [ if steps = 0 [ stop ] ]

]

; at 2pm, passengers go to pool deck + workers stay in common area

if 14 <= time-hour and time-hour <= 17

;when close-deck switch on, passengers return to cabin while workers

remain in common area

[ifelse close-deck?

[ask passengers [ setxy random-xcor (- 11 + random-float 10) ]

set steps 5

ask workers [ setxy random-xcor (1 + random-float 8) ]

ask workers [ rt random-float 1 lt random-float 1 set steps steps - 1]

ask workers [ if steps = 0 [ stop ] ]

][

set steps 5

ask passengers [ setxy random-xcor (9 + random-float 7) ]

; ask passengers [ set xcor random-xcor set ycor 9]

ask passengers [ rt random-float 1

lt random-float 1 set steps steps - 1 ]

ask passengers [ if steps = 0

[ stop ] ]

ask workers [ setxy random-xcor (1 + random-float 8) ]

ask workers [ rt random-float 1 lt random-float 1 set steps steps - 1]

ask workers [ if steps = 0 [ stop ] ]

]]

; at 6pm, passengers go to dinner

if time-hour = 18 [

set steps 5

ask passengers [ setxy random-xcor (1 + random-float 8) ]

ask passengers [ rt random-float 1

lt random-float 1 set steps steps - 1]

ask passengers [ if steps = 0

[ stop ] ]

ask workers [ setxy random-xcor (1 + random-float 8) ]

ask workers [ rt random-float 1 lt random-float 1 set steps steps - 1]

ask workers [ if steps = 0 [ stop ] ]

]

; at 7pm, passengers go to cabin and workers stay in common area

if time-hour = 19 [

ask passengers [ setxy random-xcor (- 11 + random-float 10) ]

set steps 5

ask workers [ setxy random-xcor (1 + random-float 8) ]

ask workers [ rt random-float 1 lt random-float 1 set steps steps - 1]

ask workers [ if steps = 0 [ stop ] ]

]

; at 8pm, workers go to cabin and sleep

if time-hour = 20 [

; ask passengers [stop]

ask workers [ setxy random-xcor (- 15 + random-float 3 ) ]

]

; from 9pm - midnight, everyone sleeps

; if 21 <= time-hour and time-hour <= 24 [

; ask passengers [stop]

; ask workers [stop]

; ]

end

; Turtle gets sick

to get-sick

set sick? true

set color red

set incubation 0

end

; Sets sickness incubation time, when turtle is infectious and then when

they isolate themselves in their cabin

to incubate

set incubation (incubation + 1)

if 8 <= incubation and incubation <= 20 [

set infectious? true

infect ]

if incubation >= 21 [

set isolated? true

ask passengers [ isolate ]

ask workers [ isolate ]

]

end

; Sickness spreads when turtles are on the same patch

to infect

ask other turtles-here with [ not sick? ]

;when on, PSAs reduce infectiousness by 15%

[ifelse enable-PSAs?

[ if random-float 100 < (infectiousness * 0.85 )

[get-sick] ]

[ if random-float 100 < infectiousness

[get-sick] ]]

end

; Turtles isolate themself in their cabin

to isolate

ask passengers [ set ycor (- 11 + random-float 10) ]

ask workers [ set ycor (- 15 + random-float 3) ]

set infectious? false

set confine? true

set patch-cabin? true

end

; Turtle stays in their cabin for the duration of the cruise

to confine

ask passengers [ stop ]

ask workers [ stop ]

end

to stop-model

ask passengers [ stop ]

ask workers [ stop ]

end

--

Sent from: Blockedhttp://netlogo-users.18673.x6.nabble.com/