I am struggling to write an irrigation model. I want turtles to take values from CSV file with the ticks. There are 100 values in the list. I want 10 turtles to pick first (let us say 20) value turn by turn ie., turtle 0, 1,2 3 .. will take first value in the list turn by turn (with every tick) and after the 10th ticks all turtles will take 2nd value (as 22) so on and so forth. Concept is related to water demand which is fixed and will change after 10 days for every turtle. 100 values will be consumed in 1000 ticks
Any help in this regard will be highly appreciated.
Thanks
Here is some code that might get you started. I've abstracted from the CSV file by simply creating a list, demand-list, of random demand numbers - you would read them in from the CSV file at the beginning of your simulation. From that point, ten turtles are created with a turtles-own variable, demand, and put into a list sorted by who number.
The go procedure uses the current tick and the floor operator to find which element of the demand-list is the proper one for this set of ten ticks, and the mod operator determines which turtle (consumer) in the consumer list should, at this tick, take that value for its demand. The show simply shows the demand of each turtle at the end of each tick.
globals [demand-list consumer-list]
turtles-own [demand]
to setup
clear-all
set demand-list n-values 100 [random 50]
create-turtles 10 [set demand 0]
set consumer-list sort turtles
reset-ticks
end
to go
let list-element floor ticks / 10
let chosen-consumer ticks mod 10
ask item chosen-consumer consumer-list [set demand item list-element demand-list]
show map [c -> [demand] of c] consumer-list
tick
end
If you are asking a new question, it really should be asked as a new question, not as an add-on to an old one. But let me answer it here. I've taken your code above and made some changes. First, I've taken the setxy asks out of the create-farmers block. Anything in that block is executed by each of the created farmers so, in this case, it is executed 10 times. Next, try if at all you can to avoid who numbers. You almost never need them. In particular, farmers-list contains the sorted list of farmers and you can simply use it to ask the proper farmer directly to set its demand. Also, you don't need each farmer to set list-element as it is the same for all farmers in any given tick. You have two tick commands - you only want one. And, finally, you see that I've simplified your file-read command. In your case, file-read returns a single value, which you can just add to the list.
Breed [farmers farmer]
globals [demand-list IWR-perday farmers-list]
farmers-own [current-demand irrigation-turn ]
to setup
clear-all
create-farmers 10 [ set irrigation-turn [0] ]
ask farmer 0 [ setxy min-pxcor + 1 0]
ask farmer 1 [ setxy min-pxcor + 3 0]
ask farmer 2 [ setxy min-pxcor + 5 0]
ask farmer 3 [ setxy min-pxcor + 7 0]
ask farmer 4 [ setxy min-pxcor + 9 0]
ask farmer 5 [ setxy min-pxcor + 11 0]
ask farmer 6 [ setxy min-pxcor + 13 0]
ask farmer 7 [ setxy min-pxcor + 15 0]
ask farmer 8 [ setxy min-pxcor + 17 0]
ask farmer 9 [ setxy min-pxcor + 19 0]
set farmers-list sort turtles
import-data
reset-ticks
end
to go
let list-element floor ticks / 10
ask item (ticks mod 10) farmers-list [
set current-demand item list-element IWR-perday
]
show map [c -> [current-demand] of c] farmers-list
tick
end
to import-data
;; Import water demand
ifelse ( file-exists? "IWR-perday.txt" )
[
set IWR-perday []
file-open "IWR-perday.txt"
while [ not file-at-end? ]
[
set IWR-perday lput file-read IWR-perday
]
file-close
show IWR-perday
]
[ user-message "There is no IWR-perday.txt file in current directory!" ]
end
I think if you run this with your data file, which I did to check it out, you will see that within each set of ten ticks, the demand of the ten turtles is set one by one. With over 1000 values in IWR-perday, that will go on for over 10,000 ticks!
IWR-perday is a CSV file. I want to ask if I don't sort and don't write farmer's list! How this will be shown in show map to see if codes are working fine.
Breed [farmers farmer]
globals [demand-list IWR-perday farmers-list]
farmers-own [current-demand irrigation-turn ]
to setup
clear-all
create-farmers 10 [ set irrigation-turn [0]
ask farmer 0 [ setxy min-pxcor + 1 0]
ask farmer 1 [ setxy min-pxcor + 3 0]
ask farmer 2 [ setxy min-pxcor + 5 0]
ask farmer 3 [ setxy min-pxcor + 7 0]
ask farmer 4 [ setxy min-pxcor + 9 0]
ask farmer 5 [ setxy min-pxcor + 11 0]
ask farmer 6 [ setxy min-pxcor + 13 0]
ask farmer 7 [ setxy min-pxcor + 15 0]
ask farmer 8 [ setxy min-pxcor + 17 0]
ask farmer 9 [ setxy min-pxcor + 19 0]]
set farmers-list sort turtles
import-data
reset-ticks
end
to go
foreach [0 1 2 3 4 5 6 7 8 9 ] [ ?1 ->
ask farmers with [who = ?1] [let list-element floor ticks / 10
set current-demand item list-element IWR-perday]]
show map [c -> [current-demand] of c] farmers-list
tick
tick
end
to import-data
;; Import water demand
ifelse ( file-exists? "IWR-perday.txt" )
[
set IWR-perday []
file-open "IWR-perday.txt"
while [ not file-at-end? ]
[
*set IWR-perday sentence IWR-perday (list file-read)
]
file-close
]
[ user-message "There is no IWR-perday.txt file in current directory!" ]
end*
Related
This is my code so far. I only want the turtles to follow the green lines, however they just continue forever in the random direction they are facing when I setup the model.
Code:
extensions [gis]
breed [observer]
turtles-own [ vision-distance vision-width steps green-steps gray-steps attr-prob]
patches-own [land nearest-patch]
to setup
clear-all
create-turtles 10
set-default-shape turtles "butterfly"
ask turtles [set size 25
if pxcor = min-pxcor [die]]
reset-ticks
let view gis:load-dataset "City_Plan_Boundary.shp"
gis:set-world-envelope gis:envelope-of view
foreach gis:feature-list-of view
[
gis:set-drawing-color green
gis:draw ? 1.0
]
end
to go
ask turtles [
count-steps
pen-down
let green_target turtles
let perceived_patches patches in-cone vision-distance vision-width
let patch-under-me patch-here set green_target perceived_patches with [ (pcolor = green and self != patch-under-me) or (pcolor = black and self != patch-under-me)]
ifelse count green_target != 0 [
let target min-one-of green_target[ distance myself ]
let target_heading towards target
move-to patch-at-heading-and-distance target_heading 1 ]
[ fd 1]
]
end
to count-steps
set steps steps + 1
ifelse land = green [set green-steps green-steps + 1][set gray-steps gray-steps + 1] ;;Does not currently account for CYAN Park squares
end
First, your foreach loop that applies your GIS layer is only creating lines in the drawing layer of NetLogo, not actually changing the patches themselves. You'll have to assign some component of the shapefile to the patches themselves for turtles to be able to assess them- look at the "GIS General Examples" model in the Models Library.
Second, pathfinding can be accomplished in a variety of ways, and it really depends on what behaviour you're trying to model. For a few examples, check out the "Look Ahead" example in the Models library, or look at the below toy model for a very simplistic approach:
to setup
ca
ask patch min-pxcor 0 [
set pcolor green
sprout 1 [
set color red
pd
]
spread-right
]
reset-ticks
end
to spread-right
if pxcor < max-pxcor [
ask one-of neighbors with [ pxcor = [pxcor] of myself + 1] [
set pcolor green
spread-right
]
]
end
to go
ask turtles [
let target one-of neighbors in-cone 1.5 90 with [ pcolor = green ]
ifelse target != nobody [
face target
move-to target
] [
rt one-of [ 45 -45 ]
]
]
tick
end
This is a follow-up question related to a previous post LinkI have data related to 16 laptop consumers' review ratings which are either satisfied (16 people) or dissatisfied (6 people). They are defined as turtles and they are distinguishable by asking if the boolean variable satisfied? or dissatisfied? is true.
The dataset is read as follows:
extensions [csv matrix array nw]
globals
[
rowcounter
csv
ii
Sc-headings Bat-headings Pr-headings income-headings average-headings;
Sc-set
Bat-set
Pr-set
prodcount ;num of producer agents
]
turtles-own [
turtle-Sc-list
turtle-Bat-list
turtle-Pr-list
turtle-income-list
turtle-average-list
review-set
satisfied?
dissatisfied?
LapUtl-set
ScPWU
BatPWU
PrPWU
]
to setup
clear-all
file-close-all
set rowcounter 1
proddata
readdataset
reset-ticks
end
breed [ producers producer ]
to go
Reviewrating
end
to intlz
set Sc-set []
set Bat-set []
set Pr-set []
end
Reading the dataset:
to readdataset
file-close-all ; close all open files
file-open "turtle_details.csv"
let headings csv:from-row file-read-line ;header is read
; Splitting headings of the csv file into 5 categories representing screen
; size data, battery charge data, Price data, income data, max age of an owner
set Sc-headings sublist headings 2 7
set Bat-headings sublist headings 7 12
set Pr-headings sublist headings 12 17
set income-headings sublist headings 17 18
set average-headings sublist headings 18 length headings
while [ not file-at-end? ] [
let data csv:from-row file-read-line
create-turtles 1 [
set shape "person"
set size 2.5
ifelse rowcounter < 11
[
set color 125
set satisfied? true
set dissatisfied? false ;
]
;else
[
set color 65
set satisfied? false
set dissatisfied? true ;
]
setxy random-xcor random-ycor
; hide-turtle
set turtle-Sc-list sublist data 2 7
set turtle-Bat-list sublist data 7 12
set turtle-Pr-list sublist data 12 17
set turtle-income-list sublist data 17 18
set turtle-averageage-list sublist data 18 length data
]
set rowcounter rowcounter + 1
]
file-close-all
end
There are 3 producers who have some attribute levels for the screen, battery, price.
Sc Bat Pr
24 10 18000
18 6 22000
30 8 26000
to proddata
file-close-all ; close all open files
if not file-exists? "Prodinitattr.csv" [
user-message "No file 'Prodinitattr.csv' exists!"
stop
]
file-open "Prodinitattr.csv" ; open the file with the producers' initial attributes
let headings csv:from-row file-read-line
while [ not file-at-end? ] [
let data csv:from-row file-read-line
create-producers 1 [
hide-turtle
set producer? true ; this agent is a producer
set satisfied? false ; this agent is not a referrer ; REFERRERS
set dissatisfied? false ; this agent is not a pbuyer
set prodcount prodcount + 1
; set shape "house"
setxy random-xcor random-ycor
]
set Sc-set lput item 0 data Sc-set
set Bat-set lput item 1 data Bat-set
set Pr-set lput item 2 data Pr-set
]
file-close-all
end
The thing that should be extracted from the data set is the evaluation of consumers (reviews). Each consumer has a review-set which is at first an empty set ,[].Then it will keep thee values which corresponds to the three review values for each of the three producers.
to reviewrating
ask turtles [
set review-set []
]
ask turtles [
set ii 0
while [ii < 3 ][
set ScPWU turtle-Sc-rating item ii Sc-set
set BatPWU turtle-Bat-rating item ii Bat-set
set PrPWU turtle-Pr-rating item ii Pr-set
set LapUtl-set lput (ScPWU + BatPWU + PrPWU) LapUtl-set
set ii ii + 1
] ; while
];ask
end
to-report turtle-Sc-rating [Sc]
let pos position Sc Sc-headings
if is-number? position Sc Sc-headings
[
let turt-Sc-rate-value item pos turtle-Sc-list
report turt-Sc-rate-value
]
end
to-report turtle-Bat-rating [Bat]
let pos position Bat Bat-headings
if is-number? position Bat Bat-headings
[
let turt-Bat-rate-value item pos turtle-Bat-list
report turt-Bat-rate-value
]
;***************
end
to-report turtle-Pr-rating [Pr]
let pos position Pr Pr-headings
if is-number? position Pr Pr-headings
[
let turt-Pr-rate-value item pos turtle-Pr-list
report turt-Pr-rate-value
]
end
The problem is I cannot see consumers' LapUtl vector because of the error. I had reported another error previously here, but I changed where the "go" procedure was written, and now the error is marking this line :
let turt-Sc-rate-value **item** pos turtle-Sc-list
How can I resolve tihs?
Thank you,
I suspect you are not correctly reporting the error. I suspect the error is ERROR: ITEM expected this input to be a string or list, but got a number instead. Here is an example of a way to produce this error: item 0 0. If I am right, then you are running the code let turt-Sc-rate-value item pos turtle-Sc-list while turtle-Sc-list has a value of 0. In order to confirm this, replace this code with
ifelse (is-list? turtle-Sc-list)
[let turt-Sc-rate-value item pos turtle-Sc-list]
[error (word "turtle-Sc-list is not a list.")]
Now run your code. If it raises the error "turtle-Sc-list is not a list.", then you are ready to search for how you failed to initialize this variable correctly.
I have data related to 100 consumers as turtles who have rated laptops' features. The laptops have 2 kinds of features : size of the screen and battery life. Each has some levels. For example battery life has 5 hours, 12 hours, 24 hours, 30 hours. Data is stored in a csv file. For simplicity, here you see 2 consumers.
size12 size13.5 size14 size15 Battery5 Battery12 Battery24 Battery30
1 1 *2* 1 3 2 2 *4* 5
2 4 3 3 2 1 1 2 3
We access the data set to sum the rates of 2 levels of feature. For example for consumer 1 , what is:
The sum of rates of screen size of 13.5 + rate of battery life 24
Using the code below, this is achieved :
to CalculateSumRates
ca
reset-ticks
file-close-all
file-open "turtle_details.csv"
let headings csv:from-row file-read-line
set screen-headings sublist headings 0 4
set battery-headings sublist headings 4 length headings
let screen-to-evaluate 13.5
let battery-to-evaluate 24
while [ not file-at-end? ] [
let data csv:from-row file-read-line
create-turtles 1 [
set turtle-screen-list sublist data 0 4
set turtle-battery-list sublist data 4 length data
set turtle-screen-eval turtle-screen-rating screen-to-evaluate
set turtle-bat-eval turtle-battery-rating battery-to-evaluate
set turtle-sum-eval turtle-screen-eval + turtle-bat-eval
]
]
file-close-all
end
to-report turtle-screen-rating [sc]
let pos position sc screen-headings
let turt-screen-rate-value item pos turtle-screen-list
report turt-screen-rate-value
end
to-report turtle-battery-rating [bc]
let pos position bc battery-headings
let turt-bat-rate-value item pos turtle-battery-list
report turt-bat-rate-value
end
Now I want to do something more. I need to consider a time interval. For example, in 20 years, how consumers change their ratings of some laptop features. To illustrate more, consumer 1 who has expressed her total ranking of size 13.5 and battery of 24, in year 2 (ticks = 2) got her laptop improved, so now we would like to know :
The sum of rates of screen size of 13.5 + rate of battery life **30**
I first created my go like this :
to setup
CalculateSumRates
end
to go
repeat 20 [
{ screen-to-evaluate changes and is no longer 13.5}
{ battery-to-evaluate also changes and is no longer 24}
; EDIT
set turtle-screen-eval turtle-screen-rating screen-to-evaluate
set turtle-bat-eval turtle-battery-rating battery-to-evaluate
set turtle-sum-eval turtle-screen-eval + turtle-bat-eval
; EDIT
tick
]
end
What is making trouble here is that, each time CalculateSumRates is called, it goes to this line :
create-turtles 1 [
So every year, 100 consumers are created from scratch while I need to monitor the behvavior of those 100 consumers at the beginning.
I then wrote 2 CalculateSumRates functions, called one in the set up. Renamed the function and put the other in the go. In order not to create an excess of consumers, I substituted create-turtles 1 [ with ask consumers [, hoping that now the csv is again read, but row by row is read when I say ask consumers, so I can find different values from the dataset. However, it is executing weirdly. I do not know how to modify that to avoid creating new consumers and losing the previous ones?
By adding the lines in the edit, I encounter an error telling me that I cannot use go in an observer context; go is turtle only!!
Thanks,
To give an example of what I meant in the comment above, check out this modified version of the setup that I suggested here.
extensions [ csv ]
globals [ screen-headings battery-headings ]
turtles-own [
turtle-screen-list
turtle-battery-list
turtle-screen-eval
turtle-bat-eval
turtle-sum-eval
turtle-row-number
;; New:
rating-each-year
]
to setup
ca
reset-ticks
file-close-all
file-open "turtle_details.csv"
let headings csv:from-row file-read-line
set screen-headings sublist headings 0 4
set battery-headings sublist headings 4 length headings
while [ not file-at-end? ] [
let data csv:from-row file-read-line
create-turtles 1 [
set turtle-screen-list sublist data 0 4
set turtle-battery-list sublist data 4 length data
set rating-each-year []
]
]
file-close-all
ask turtles [
update-vals 12 5
set rating-each-year lput turtle-sum-eval rating-each-year
]
end
It's more or less the same, but there are some important changes like a new list called rating-each-year that is intended to let the turtles keep track of their rating each tick.
The reporters are mostly unchanged as well, except that update-vals is now a turtle-specific procedure so it must be called by ask turtles (or similar). Additionally, it takes two variables, one called screen? and one called battery?. You can then call the reporter by asking a turtle to: update-vals 12 24, and that turtle will then update its values for a screen size of 12 and a battery life of 24. I include all three reporters for completeness, but the other two have not changed from my answer to your other question:
to update-vals [ screen? battery? ]
set turtle-screen-eval turtle-screen-rating screen?
set turtle-bat-eval turtle-battery-rating battery?
set turtle-sum-eval turtle-screen-eval + turtle-bat-eval
end
to-report turtle-screen-rating [sc]
let pos position sc screen-headings
let turt-screen-rate-value item pos turtle-screen-list
report turt-screen-rate-value
end
to-report turtle-battery-rating [bc]
let pos position bc battery-headings
let turt-bat-rate-value item pos turtle-battery-list
report turt-bat-rate-value
end
So now, your turtles can at any time update their summed rating value according to the screen and battery combination that you have assigned them or that they have bought, however you are setting that up. Here is an example go procedure that every tick has them choose a random possible screen size and battery life to evaluate, then they add that summed rating value to their rating-each-year list. When 20 ticks go by, the procedure stops and the turtles show their lists in the command center (21 items long, since they include the value from setup as well).
to go
ifelse ticks < 20 [
ask turtles [
let screen-this-year one-of screen-headings
let battery-this-year one-of battery-headings
update-vals screen-this-year battery-this-year
set rating-each-year lput turtle-sum-eval rating-each-year
]
]
[
ask turtles [
show rating-each-year
]
stop
]
tick
end
In your model, you probably wouldn't have them randomly pick values of course- this was more to show what they're actually doing. I should also mention that "turtle_details.csv" is the same as the one I used for an example in the last question.
My question is a bit long. I really appreciate it if you could please read it all and I'd be very grateful for any piece of advice.
I have data related to 2 consumers as turtles who have rated laptops' features. The laptops have 2 kinds of features : size of the screen and battery life. Each has some levels. For example battery life has 5 hours, 12 hours, 24 hours, 30 hours. Data is stored in a csv file.
12 13.5 14 15 5 12 24 30
1 1 2 1 3 2 2 4 5
2 4 3 1 2 1 1 2 3
I want to sum the rates of 2 levels of feature. For example for consumer 1 and 2, what is:
sum rate of screen size of 13.5 + rate of battery life 24
Since 13.5 and 24 may change later and I want to know for example the sum of rates of size of 14 and battery life of 5, I defined two functions using "to-reports" . Also since for example the value "12" is in the header row twice and represents both a size and a battery life, I made 2 subsets of the csv file one for screen size , the other for battery.
12 13.5 14 15
1 1 2 1 3
2 4 3 1 2
5 12 24 30
1 2 2 4 5
2 1 1 2 3
First in the main program, the csv file is read and a turtle is assigned to each row, expecting to have two consumers.
to setup
ca
reset-ticks
file-close-all
file-open "turtle_details.csv"
let headerrow csv:from-row file-read-line
set Sc 13.5 ; at the beginning I want the rate of this screen size
set Bat 24
while [ not file-at-end? ] [
let data csv:from-row file-read-line
create-consumers 1 [
set shape "person"
set k k + 1
print obtain-Sc (Sc) + obtain-Bat (Bat)
]
]
file-close-all
end
I assumed, first, row one is read and a consumer is generated. Now it goes to to-report to find obtain-Screen(13.5) which is 2, but I thought next time that obrain_Screen is called, again the csv opens and the cursor would still be at the beginning, but I want it to read the second row. And to extend it, I might need it to go further and further. To solve this, I defined a counter k that for example the first time this condition is checked : idx = 0 < k =1 so the first row is read. Then idx = idx + 1 , so nothing else is done.
to-report obtain-Screen[Sc]
file-close-all ; close all open files
file-open "turtle_detailsSc.csv"
let headings csv:from-row file-read-line
ifelse is-number? position Sc headings
[
while [idx < k ]
[ set fdata csv:from-row file-read-line
set idx idx + 1
]
report item position Sc headings fdata
]
[report 0.000000009]
Something similar for Bat. But it does not work and has errors. Any ideas how to improve to-reports?
Thanks
Edit
Considering the data set to be like this :
size12 size13.5 size14 size15 Battery5 Battery12 Battery24 Battery30
1 1 *2* 1 3 2 2 *4* 5
2 4 3 3 2 1 1 2 3
I can now access the data set and for each consumer find their evaluation of a laptop they have purchased. For example, consumer 1 has a laptop with size of 13.5 and battery life 24.
Consumer 1 evaluation of size 13.5 = 2
Consumer 1 evaluation of battery 24 = 4
Overall evaluation of laptop = 2 + 4 = 6
I have defined a procedure "Find Eval" that when I need to know the evaluation of different consumers, it enables me to access the dataset and find the values.
To explain the data in the table more, a consumer has a laptop so can evaluate it pretty well, but for other features like how he evaluates a laptop with the screen size of 15, he might have some exposure or just by hearing from others he has filled in the table.
I want to keep these 2 consumers and monitor their attitudes about laptop features during 20 years. In year 2, consumer 1 possibly updated his system, so now his battery life is 30. This time what I need to do is to access the dataset and calculate
Consumer 1 evaluation of size 13.5 = 2
plus
Consumer 1 evaluation of battery 30 = 5
Overall evaluation of laptop = 2 + 5 = 7
This time, I need to go to find the value for battery 30.
I think when I repeat my code for 20 years, create-consumer will be repeated each time that I want to work with the dataset, so instead of keeping 2 consumers, each year, some new consumers will be created and the previous ones will be totally replaced.
The question is how I can create consumers once, but can access any data point in the data set for many times?
Thanks a lot,
In response to your comment- got it, thought that might be the case. I will present an alternative approach that may or may not suit you, but it's probably how I would tackle this. The main difference is that I would store the lists for screen and battery ratings in a turtle variable, so you can easily access them after the fact without having to track counters. Given these variable declarations:
extensions [ csv ]
globals [ screen-headings battery-headings]
turtles-own [
turtle-screen-list
turtle-battery-list
turtle-screen-eval
turtle-bat-eval
turtle-sum-eval
turtle-row-number
]
I would split headings of the csv file to the screen-headings and battery-headings globals.
Then, I would iterate through the next lines of the csv, as you did below, and split the lines in a similar way but into the turtles-own variables turtle-screen-list and turtle-battery-list. That way, each turtle is aware of its own ratings for each screen and battery so you can modify your evaluated screen or battery as needed.
Set the screen and battery of interest with screen-to-evaluate and battery-to-evaluate (or use a Chooser on the interface), then use a reporter (similar to what you had set up) that checks the position of the battery and screen of interest to return the current turtle's rating for each- this will set turtle-screen-eval and turtle-bat-eval. Finally, sum those last two values.
to setup
ca
reset-ticks
file-close-all
file-open "turtle_details.csv"
let headings csv:from-row file-read-line
set screen-headings sublist headings 0 4
set battery-headings sublist headings 4 length headings
let screen-to-evaluate 13.5
let battery-to-evaluate 24
while [ not file-at-end? ] [
let data csv:from-row file-read-line
create-turtles 1 [
set turtle-screen-list sublist data 0 4
set turtle-battery-list sublist data 4 length data
set turtle-screen-eval turtle-screen-rating screen-to-evaluate
set turtle-bat-eval turtle-battery-rating battery-to-evaluate
set turtle-sum-eval turtle-screen-eval + turtle-bat-eval
]
]
file-close-all
end
to-report turtle-screen-rating [sc]
let pos position sc screen-headings
let turt-screen-rate-value item pos turtle-screen-list
report turt-screen-rate-value
end
to-report turtle-battery-rating [bc]
let pos position bc battery-headings
let turt-bat-rate-value item pos turtle-battery-list
report turt-bat-rate-value
end
Of course, you can condense some of this as needed. I tested this setup with 4 rows (patterned after your example data) and it seemed to work ok. If you have a huge number of rows it might not work so well.
Edit:
If you end up replacing screen-to-evaluate and battery-to-evaluate with interface choosers (which I recommend- it allows you to quickly see the different values), you can update to the new values with something like:
to update-vals
ask turtles [
set turtle-screen-eval turtle-screen-rating scrn
set turtle-bat-eval turtle-battery-rating batr
set turtle-sum-eval turtle-screen-eval + turtle-bat-eval
]
end
where scrn and batr are the names of the choosers.
Or, if you want them to dynamically update, you can make an interface monitor that reports the following reporter :
to-report update
ask turtles [
set turtle-screen-eval turtle-screen-rating scrn
set turtle-bat-eval turtle-battery-rating batr
set turtle-sum-eval turtle-screen-eval + turtle-bat-eval
]
report "Dynamically updating."
end
With that one, as soon as you change the Chooser value, the turtles should immediately update their turtle-bat-eval, turtle-screen-eval, and turtle-sum-eval. Fun!
Edit 2
If your csv includes a column for row numbers like this:
row 12 13.5 14 15 5 12 24 30
1 1 2.0 1 3 2 2 4 5
2 4 3.0 1 2 1 1 2 3
I would recommend creating a turtle variable to store the row number used. I've now included one called turtle-row-number. Then, you would just have to include a line to update that variable from the first item in the list, which is the row number, and then modify your sublist values accordingly, to something like:
to setup-row-nums
ca
reset-ticks
file-close-all
file-open "turtle_details_2.csv"
let headings csv:from-row file-read-line
set screen-headings sublist headings 1 5
set battery-headings sublist headings 5 length headings
while [ not file-at-end? ] [
let data csv:from-row file-read-line
create-turtles 1 [
set turtle-row-number first data
set turtle-screen-list sublist data 1 5
set turtle-battery-list sublist data 5 length data
]
]
update-vals
file-close-all
end
Where update-vals is as shown above.
I have animals walk around and a line then connects all the locations that they walked to. The line forms a closed polygon. I also used the graphics extension to fill the polygon for visual purposes. But I don't know how to have all of the patches that fall within the polygon become the territory of the owner (i.e., the animal that formed the polygon). It is possible for patches to be owned by multiple animals. The code below illustrates overlapping polygons. I'd really appreciate any help on this. Thanks!
extensions [graphics]
breed [animals animal]
breed [homeranges homerange]
animals-own
[
Name
X
Y
]
patches-own
[
owner
]
homeranges-own
[
Name
]
to setup
clear-all
random-seed 4
ask patches
[
set owner nobody
set pcolor grey
]
let $colors [brown orange violet sky lime]
let $Name ["t6" "t7" "t8" "t9" "t10"]
ask n-of 5 patches with [(pycor < 10 and pycor > -10) and (pxcor < 10 and pxcor > -10)]
[
sprout-animals 1
[
set shape "circle"
set color item who $colors
set pcolor color
set X (list xcor)
set Y (list ycor)
set Name item who $Name
set owner self
]
]
graphics:initialize min-pxcor max-pycor patch-size
reset-ticks
end
to go
repeat 5
[
ask animals
[
rt 45
fd 2
set X lput pxcor X
set Y lput pycor Y
set pcolor [color] of self
]
]
ask animals
[
pen-up
let tempXY (map [list ?1 ?2] X Y)
graphics:fill-polygon tempXY
; create a turtle, which draws the homerange boundary
hatch-homeranges 1
[
hide-turtle
set Name [Name] of myself
set color [color] of myself
]
; draw the homerange boundary
foreach tempXY
[
ask homeranges with [Name = [Name] of myself]
[
move-to patch (item 0 ?) (item 1 ?)
pen-down
]
]
; connect the last point of the homerange with the first one, to close the polygon
ask homeranges with [Name = [Name] of myself]
[
let lastpoint first tempXY
move-to patch (item 0 lastpoint) (item 1 lastpoint)
]
]
end
If you look at http://netlogo-users.18673.x6.nabble.com/Netlogo-Point-in-Polygon-td4980030.html you'll find a past (2012) discussion of solutions to this problem.
At the end of the thread, Jim Lyons posts a link to a model on the Modeling Commons, but the model doesn't seem to exist there anymore. He's here on Stack Overflow if you want to ask him about it.
An answer was provided in this post: NetLogo - misalignment with imported GIS shapefiles. The polygons are exported as a GIS shapefile and imported back in using the GIS extension. Then the gis:intersecting was used to give a variable to those patches that fall within the GIS-imported polygons.