How to move all turtles from region to region in Net Logo?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am trying to create a simulation to model rotational grazing in agriculture. I used the Many Regions Example from GitHub to create the regions, and created the basic turtle movement and grass regrowth. However, I am having trouble making the cows go from region 1 to region 2, region 2 to region 3 etc. after a fixed period "rotation-time". I want the cows to maintain the same "health" and the grass to continue regrowing when they rotate regions. Any ideas on how to write the "to-rotate"?



breed [cows cow]
globals [
region-boundaries
]
turtles-own [ health]

patches-own [ energy region ]

to setup
clear-all
setup-regions number-of-regions
color-regions
setup-turtles
reset-ticks
end

to setup-regions [ num-regions ]
foreach region-divisions num-regions draw-region-division
set region-boundaries calculate-region-boundaries num-regions
let region-numbers (range 1 (num-regions + 1))
(foreach region-boundaries region-numbers [ [boundaries region-number] ->
ask patches with [ pxcor >= first boundaries and pxcor <= last boundaries ] [
set region region-number
]
])
end

to-report calculate-region-boundaries [ num-regions ]
let divisions region-divisions num-regions
report (map [ [d1 d2] -> list (d1 + 1) (d2 - 1) ] (but-last divisions) (but-first divisions))
end

to-report region-divisions [ num-regions ]
report n-values (num-regions + 1) [ n ->
[ pxcor ] of patch (min-pxcor + (n * ((max-pxcor - min-pxcor) / num-regions))) 0
]
end

to draw-region-division [ x ]
ask patches with [ pxcor = x ] [
set pcolor grey + 1.5
]
create-turtles 1 [
setxy x max-pycor
set heading 0
set color grey - 3
pen-down
forward world-height
set xcor xcor + 1 / patch-size
right 180
set color grey + 3
forward world-height
die
]
end

to color-regions
ask patches with [ region != 0 ] [
set pcolor green
ifelse show-region?
[set plabel region]
[set plabel ""]
]
end

to setup-turtles
set-default-shape cows "cow"
foreach (range 1 (length region-boundaries + 1)) [ region-number ->
let region-patches patches with [ region = region-number ]
create-cows number-of-turtles-per-region [
set color brown
set size 1.5
move-to one-of region-patches
ifelse region = 1
[ ]
[ die ]
] ]
end

to go
ask turtles [ move eat ]
regrow-grass
tick
if ticks = rotation-time
[ rotate ]
end

to rotate



end

to move
let current-region region
right random 360
forward 1
set health health - 6
keep-in-region current-region
if ticks = 100
[set current-region = current-region + 1]
end


to eat
ifelse pcolor = black
[ ]
[ ifelse pcolor = green [
set pcolor pcolor + 2
set health health + 10
set energy energy - 10
]
[ ifelse pcolor = 57
[
set pcolor 59
set health health + 10
set energy energy - 10
]
[
set pcolor black
set health health + 10
set energy energy - 10
] ]
ifelse show-health?
[ set label health ]
[ set label "" ]
]
end

to regrow-grass
ask patches [
ifelse pcolor = black
[ if random 100 < grass-growth-rate
[set pcolor green
set energy energy + 30
]]
[ ]
]
end



to keep-in-region [ which-region ]
if region != which-region [
let region-min-pxcor first item (which-region - 1) region-boundaries
let region-max-pxcor last item (which-region - 1) region-boundaries
let region-width (region-max-pxcor - region-min-pxcor) + 1
ifelse xcor < region-min-pxcor [
set xcor xcor + region-width
] [
if xcor > region-max-pxcor [
set xcor xcor - region-width
]
]
]

end

to-report energy-sum
report sum [energy] of patches
end









share|improve this question

























  • do you want them to walk towards the region, or to instantly jump to the new region?

    – JenB
    Nov 25 '18 at 12:51


















0















I am trying to create a simulation to model rotational grazing in agriculture. I used the Many Regions Example from GitHub to create the regions, and created the basic turtle movement and grass regrowth. However, I am having trouble making the cows go from region 1 to region 2, region 2 to region 3 etc. after a fixed period "rotation-time". I want the cows to maintain the same "health" and the grass to continue regrowing when they rotate regions. Any ideas on how to write the "to-rotate"?



breed [cows cow]
globals [
region-boundaries
]
turtles-own [ health]

patches-own [ energy region ]

to setup
clear-all
setup-regions number-of-regions
color-regions
setup-turtles
reset-ticks
end

to setup-regions [ num-regions ]
foreach region-divisions num-regions draw-region-division
set region-boundaries calculate-region-boundaries num-regions
let region-numbers (range 1 (num-regions + 1))
(foreach region-boundaries region-numbers [ [boundaries region-number] ->
ask patches with [ pxcor >= first boundaries and pxcor <= last boundaries ] [
set region region-number
]
])
end

to-report calculate-region-boundaries [ num-regions ]
let divisions region-divisions num-regions
report (map [ [d1 d2] -> list (d1 + 1) (d2 - 1) ] (but-last divisions) (but-first divisions))
end

to-report region-divisions [ num-regions ]
report n-values (num-regions + 1) [ n ->
[ pxcor ] of patch (min-pxcor + (n * ((max-pxcor - min-pxcor) / num-regions))) 0
]
end

to draw-region-division [ x ]
ask patches with [ pxcor = x ] [
set pcolor grey + 1.5
]
create-turtles 1 [
setxy x max-pycor
set heading 0
set color grey - 3
pen-down
forward world-height
set xcor xcor + 1 / patch-size
right 180
set color grey + 3
forward world-height
die
]
end

to color-regions
ask patches with [ region != 0 ] [
set pcolor green
ifelse show-region?
[set plabel region]
[set plabel ""]
]
end

to setup-turtles
set-default-shape cows "cow"
foreach (range 1 (length region-boundaries + 1)) [ region-number ->
let region-patches patches with [ region = region-number ]
create-cows number-of-turtles-per-region [
set color brown
set size 1.5
move-to one-of region-patches
ifelse region = 1
[ ]
[ die ]
] ]
end

to go
ask turtles [ move eat ]
regrow-grass
tick
if ticks = rotation-time
[ rotate ]
end

to rotate



end

to move
let current-region region
right random 360
forward 1
set health health - 6
keep-in-region current-region
if ticks = 100
[set current-region = current-region + 1]
end


to eat
ifelse pcolor = black
[ ]
[ ifelse pcolor = green [
set pcolor pcolor + 2
set health health + 10
set energy energy - 10
]
[ ifelse pcolor = 57
[
set pcolor 59
set health health + 10
set energy energy - 10
]
[
set pcolor black
set health health + 10
set energy energy - 10
] ]
ifelse show-health?
[ set label health ]
[ set label "" ]
]
end

to regrow-grass
ask patches [
ifelse pcolor = black
[ if random 100 < grass-growth-rate
[set pcolor green
set energy energy + 30
]]
[ ]
]
end



to keep-in-region [ which-region ]
if region != which-region [
let region-min-pxcor first item (which-region - 1) region-boundaries
let region-max-pxcor last item (which-region - 1) region-boundaries
let region-width (region-max-pxcor - region-min-pxcor) + 1
ifelse xcor < region-min-pxcor [
set xcor xcor + region-width
] [
if xcor > region-max-pxcor [
set xcor xcor - region-width
]
]
]

end

to-report energy-sum
report sum [energy] of patches
end









share|improve this question

























  • do you want them to walk towards the region, or to instantly jump to the new region?

    – JenB
    Nov 25 '18 at 12:51














0












0








0








I am trying to create a simulation to model rotational grazing in agriculture. I used the Many Regions Example from GitHub to create the regions, and created the basic turtle movement and grass regrowth. However, I am having trouble making the cows go from region 1 to region 2, region 2 to region 3 etc. after a fixed period "rotation-time". I want the cows to maintain the same "health" and the grass to continue regrowing when they rotate regions. Any ideas on how to write the "to-rotate"?



breed [cows cow]
globals [
region-boundaries
]
turtles-own [ health]

patches-own [ energy region ]

to setup
clear-all
setup-regions number-of-regions
color-regions
setup-turtles
reset-ticks
end

to setup-regions [ num-regions ]
foreach region-divisions num-regions draw-region-division
set region-boundaries calculate-region-boundaries num-regions
let region-numbers (range 1 (num-regions + 1))
(foreach region-boundaries region-numbers [ [boundaries region-number] ->
ask patches with [ pxcor >= first boundaries and pxcor <= last boundaries ] [
set region region-number
]
])
end

to-report calculate-region-boundaries [ num-regions ]
let divisions region-divisions num-regions
report (map [ [d1 d2] -> list (d1 + 1) (d2 - 1) ] (but-last divisions) (but-first divisions))
end

to-report region-divisions [ num-regions ]
report n-values (num-regions + 1) [ n ->
[ pxcor ] of patch (min-pxcor + (n * ((max-pxcor - min-pxcor) / num-regions))) 0
]
end

to draw-region-division [ x ]
ask patches with [ pxcor = x ] [
set pcolor grey + 1.5
]
create-turtles 1 [
setxy x max-pycor
set heading 0
set color grey - 3
pen-down
forward world-height
set xcor xcor + 1 / patch-size
right 180
set color grey + 3
forward world-height
die
]
end

to color-regions
ask patches with [ region != 0 ] [
set pcolor green
ifelse show-region?
[set plabel region]
[set plabel ""]
]
end

to setup-turtles
set-default-shape cows "cow"
foreach (range 1 (length region-boundaries + 1)) [ region-number ->
let region-patches patches with [ region = region-number ]
create-cows number-of-turtles-per-region [
set color brown
set size 1.5
move-to one-of region-patches
ifelse region = 1
[ ]
[ die ]
] ]
end

to go
ask turtles [ move eat ]
regrow-grass
tick
if ticks = rotation-time
[ rotate ]
end

to rotate



end

to move
let current-region region
right random 360
forward 1
set health health - 6
keep-in-region current-region
if ticks = 100
[set current-region = current-region + 1]
end


to eat
ifelse pcolor = black
[ ]
[ ifelse pcolor = green [
set pcolor pcolor + 2
set health health + 10
set energy energy - 10
]
[ ifelse pcolor = 57
[
set pcolor 59
set health health + 10
set energy energy - 10
]
[
set pcolor black
set health health + 10
set energy energy - 10
] ]
ifelse show-health?
[ set label health ]
[ set label "" ]
]
end

to regrow-grass
ask patches [
ifelse pcolor = black
[ if random 100 < grass-growth-rate
[set pcolor green
set energy energy + 30
]]
[ ]
]
end



to keep-in-region [ which-region ]
if region != which-region [
let region-min-pxcor first item (which-region - 1) region-boundaries
let region-max-pxcor last item (which-region - 1) region-boundaries
let region-width (region-max-pxcor - region-min-pxcor) + 1
ifelse xcor < region-min-pxcor [
set xcor xcor + region-width
] [
if xcor > region-max-pxcor [
set xcor xcor - region-width
]
]
]

end

to-report energy-sum
report sum [energy] of patches
end









share|improve this question
















I am trying to create a simulation to model rotational grazing in agriculture. I used the Many Regions Example from GitHub to create the regions, and created the basic turtle movement and grass regrowth. However, I am having trouble making the cows go from region 1 to region 2, region 2 to region 3 etc. after a fixed period "rotation-time". I want the cows to maintain the same "health" and the grass to continue regrowing when they rotate regions. Any ideas on how to write the "to-rotate"?



breed [cows cow]
globals [
region-boundaries
]
turtles-own [ health]

patches-own [ energy region ]

to setup
clear-all
setup-regions number-of-regions
color-regions
setup-turtles
reset-ticks
end

to setup-regions [ num-regions ]
foreach region-divisions num-regions draw-region-division
set region-boundaries calculate-region-boundaries num-regions
let region-numbers (range 1 (num-regions + 1))
(foreach region-boundaries region-numbers [ [boundaries region-number] ->
ask patches with [ pxcor >= first boundaries and pxcor <= last boundaries ] [
set region region-number
]
])
end

to-report calculate-region-boundaries [ num-regions ]
let divisions region-divisions num-regions
report (map [ [d1 d2] -> list (d1 + 1) (d2 - 1) ] (but-last divisions) (but-first divisions))
end

to-report region-divisions [ num-regions ]
report n-values (num-regions + 1) [ n ->
[ pxcor ] of patch (min-pxcor + (n * ((max-pxcor - min-pxcor) / num-regions))) 0
]
end

to draw-region-division [ x ]
ask patches with [ pxcor = x ] [
set pcolor grey + 1.5
]
create-turtles 1 [
setxy x max-pycor
set heading 0
set color grey - 3
pen-down
forward world-height
set xcor xcor + 1 / patch-size
right 180
set color grey + 3
forward world-height
die
]
end

to color-regions
ask patches with [ region != 0 ] [
set pcolor green
ifelse show-region?
[set plabel region]
[set plabel ""]
]
end

to setup-turtles
set-default-shape cows "cow"
foreach (range 1 (length region-boundaries + 1)) [ region-number ->
let region-patches patches with [ region = region-number ]
create-cows number-of-turtles-per-region [
set color brown
set size 1.5
move-to one-of region-patches
ifelse region = 1
[ ]
[ die ]
] ]
end

to go
ask turtles [ move eat ]
regrow-grass
tick
if ticks = rotation-time
[ rotate ]
end

to rotate



end

to move
let current-region region
right random 360
forward 1
set health health - 6
keep-in-region current-region
if ticks = 100
[set current-region = current-region + 1]
end


to eat
ifelse pcolor = black
[ ]
[ ifelse pcolor = green [
set pcolor pcolor + 2
set health health + 10
set energy energy - 10
]
[ ifelse pcolor = 57
[
set pcolor 59
set health health + 10
set energy energy - 10
]
[
set pcolor black
set health health + 10
set energy energy - 10
] ]
ifelse show-health?
[ set label health ]
[ set label "" ]
]
end

to regrow-grass
ask patches [
ifelse pcolor = black
[ if random 100 < grass-growth-rate
[set pcolor green
set energy energy + 30
]]
[ ]
]
end



to keep-in-region [ which-region ]
if region != which-region [
let region-min-pxcor first item (which-region - 1) region-boundaries
let region-max-pxcor last item (which-region - 1) region-boundaries
let region-width (region-max-pxcor - region-min-pxcor) + 1
ifelse xcor < region-min-pxcor [
set xcor xcor + region-width
] [
if xcor > region-max-pxcor [
set xcor xcor - region-width
]
]
]

end

to-report energy-sum
report sum [energy] of patches
end






netlogo






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 16:38







Jessica Shi

















asked Nov 24 '18 at 3:31









Jessica ShiJessica Shi

11




11













  • do you want them to walk towards the region, or to instantly jump to the new region?

    – JenB
    Nov 25 '18 at 12:51



















  • do you want them to walk towards the region, or to instantly jump to the new region?

    – JenB
    Nov 25 '18 at 12:51

















do you want them to walk towards the region, or to instantly jump to the new region?

– JenB
Nov 25 '18 at 12:51





do you want them to walk towards the region, or to instantly jump to the new region?

– JenB
Nov 25 '18 at 12:51












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454934%2fhow-to-move-all-turtles-from-region-to-region-in-net-logo%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454934%2fhow-to-move-all-turtles-from-region-to-region-in-net-logo%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings