For the model posted below I'm wondering how to get mean of the variable "land-suitability" for each farm. I would like to put a plot or a monitor in the interface to display the mean of land-suitability. I've tried with a monitor with this function in the reporter -- mean [land-suitability] of turtles -- but I get the mean land-suitability only of the patches where the turtle is on, not of the all farm... How can I write a report for this purpose?
turtles-own [
profit-from-fuel
profit-from-food
expected-fuel-sell-price
expected-food-sell-price
profit
farm
farm-size
]
patches-own [
fuel-yeld
`enter code here`food-yeld
land-sustainability
water-level
belongs-to
food
fuel
]
globals [
fuel-sell-price
food-sell-price
governs
]
to setup
clear-all
clear-all-plots
create-farmers
setup-land
reset-ticks
ask turtles
[ set-farm-in-radius farm-size ]
set fuel-sell-price 184 + random 55 + random -55
set food-sell-price 184 + random 55 + random -55
end
to create-farmers
create-turtles 30
[
set shape "person farmer"
setxy random-pxcor random-pycor
set profit-from-fuel 0 ; indicizzazione del profitto iniziale a 0
set profit-from-food 0 ; indicizzazione del profitto iniziale a 0
set farm-size random 5 + 1
set label farm-size
]
end
to setup-land
ask patches [set belongs-to nobody]
ask patches
[
set pcolor 3
set food-yeld 13000
set fuel-yeld 13000
set land-sustainability random-float 0.9 + 0.1 ; per creare un moltiplicatore che vada da 0.1 a 1
set water-level random 3 * 1000
if water-level = 0 [set water-level 1000]
]
end
to set-farm-in-radius [d]
move-to one-of patches with [not any? other patches in-radius d with [belongs-to != nobody]]
set farm patches in-radius farm-size
ask farm [set belongs-to myself]
let c random 6 + 61
ask farm [set pcolor c]
end
to set-farm-distance [d]
move-to one-of patches with [not any? other patches with [belongs-to != nobody and distance myself < d]]
set farm patches with [distance myself < d]
ask farm [set belongs-to myself]
let c random 6 + 61
ask farm [set pcolor c]
end
to go
ask turtles [
set expected-fuel-sell-price fuel-sell-price + random 5 + random -5
if expected-fuel-sell-price < 0 [set expected-fuel-sell-price 1]
set expected-food-sell-price food-sell-price + random 5 + random -5
if expected-food-sell-price < 0 [set expected-food-sell-price 1]
set profit profit-from-fuel + profit-from-food
if profit = 0 [ set profit 1 ]
]
ask turtles [
cultivate
ask farm [recolor-farm]
set profit profit-from-food + profit-from-fuel
]
set fuel-sell-price fuel-sell-price + random 55 + random -55
if fuel-sell-price < 126 [set fuel-sell-price 126 ]
if fuel-sell-price > 245 [set fuel-sell-price 245] ; è corretta come assunzione? su un arco di 30 anni è ragionevole suppore che il limite massimo del prezzo
set food-sell-price food-sell-price + random 55 + random -55 ; sia di soli 5 euro più alto rispetto al massimo delgi ultimi 10 anni
if food-sell-price < 126 [set food-sell-price 126]
if food-sell-price > 245 [set food-sell-price 245]
if ticks = Duration [ stop ]
if ticks > Duration [stop]
ask patches
[ set food 0
set fuel 0
if land-sustainability < 0.1 [set land-sustainability 0.1] ; all'interno del modello la land susitability varia in base alle colture utilizzate
if land-sustainability > 1 [set land-sustainability 1 ] ; ma questa non può comunque essere inferiore a 0.1 o maggiore di 1
]
tick
end
to cultivate
let r risk-attitude
let e-f expected-fuel-sell-price
let e-food expected-food-sell-price
ask farm [
ifelse land-sustainability < 0.35 or water-level < 1100 ; 0.35 è un valore arbitrario che può essere modificato vedere i documenti FAO
[ ask myself [set profit-from-food sum [food-sell-price * (((food-yeld ) ^ (alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma))))] of farm
]
set food 2
set fuel 0
set land-sustainability land-sustainability + 0.1 ; la scelta di coltivare prodotti destinati alla produzione di cibo incrementa il livello l-s del terreno così coltivato
set pcolor 52.5
]
[
if land-sustainability >= 0.35 or water-level = 0
[
let utility-from-food e-food * ((food-yeld ) ^ (alfa)) * ((water-level) ^ (gamma)) * ((land-sustainability) ^ (beta)) ; da riscrivere la nuova formula con l'utilità di
let utility-from-fuel e-f *(( fuel-yeld) ^ (alfa) * ((water-level) ^ (1 - gamma) * (land-sustainability) ^ (gamma) ))
ifelse utility-from-food < utility-from-fuel
[
ask myself [set profit-from-fuel sum [fuel-sell-price * (((fuel-yeld ) ^ (alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma))))] of farm ] ; ricominciare da qui cobb-douglas
set fuel 1
set food 0
set land-sustainability land-sustainability - 1
]
[ ask myself [set profit-from-food sum [food-sell-price * (((food-yeld ) ^ (alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma))))] of farm ]
set food 1
set fuel 0
set land-sustainability land-sustainability + 0.5
]
]
]
]
end
to recolor-farm
if (food = 1 and fuel = 0 ) [set pcolor green ]
if (fuel = 1 and food = 0 )[set pcolor yellow]
if (fuel = 1 and food = 1) [set pcolor pink] ; check
if (fuel = 0 and food = 0) [set pcolor blue] ; check
end
mean [land-sustainability] of farm will give it to you for a particular farmer (turtle). mean [ land-sustainability of patches with [ belongs-to != nobody ] will give it to you for all farm patches, I believe.
Each of your turtles has a farm variable that contains the set of patches that constitutes the farm of this turtle. You want the mean land sustainability of the farms of the turtles:
[ mean [ land-sustainability ] of farm ] of turtles
Related
I'm trying to set up firms (turtles) in an industry (world) by assigning them different sizes according to their income (firms-own). The distinction between small, medium and large size should be dependent on the percentage of income in relation to the total income.
More specifically, dependent on their income I want the firms with the 30% lowest income to be of size 0.5, the firms with the 60% middle income to be of size 1, and the firms with the 10% highest income to be of size 1.5.
So far I have:
breed [ firms firm ]
firms-own [
income
]
to setup
create-firms number-of-firms [ ;; number of firms to be defined through slider
set income random 100
if income = "low" [ set size 0.5 ] ;; firms with low output are of a small size
if income = "medium" [ set size 1 ] ;; firms with medium output are of a medium size
if income = "high" [ set size 1.5 ] ;; firms with high output are of a large size
end
I know the code does not work because I have not told the firms when to set their firms-own to "low", "medium", or "high". But I don't know how to get them to set it by percentage of the total income.
Thanks for your input here!
If you only have the three classes, you could probably get away with a nested ifelse statement:
breed [ firms firm ]
firms-own [
income
income-class
]
to setup
ca
create-firms 10 [
while [ any? other turtles-here ] [
move-to one-of neighbors
]
set income random 100
]
let firm-incomes sort [income] of firms
print firm-incomes
ask firms [
ifelse income < item ( length firm-incomes / 3 ) firm-incomes [
set income-class "low"
set size 0.5
] [
ifelse income < item ( length firm-incomes * 9 / 10 ) firm-incomes [
set income-class "medium"
set size 1
] [
set income-class "high"
set size 1.5
]
]
]
; Just to check output:
foreach sort-on [ income ] turtles [
t ->
ask t [
show income
show income-class
]
]
reset-ticks
end
Outputs something like:
[16 20 20 47 52 58 69 83 88 97]
(firm 9): 16
(firm 9): "low"
(firm 0): 20
(firm 0): "low"
(firm 3): 20
(firm 3): "low"
(firm 5): 47
(firm 5): "medium"
(firm 7): 52
(firm 7): "medium"
(firm 4): 58
(firm 4): "medium"
(firm 2): 69
(firm 2): "medium"
(firm 1): 83
(firm 1): "medium"
(firm 6): 88
(firm 6): "medium"
(firm 8): 97
(firm 8): "high
Luke Cs answer is pretty good, thumbs up! In case of only 3 income classes, you could also work max-n-of for the 10 % highest income firms and with min-n-of for 30 % lowest income firms. Everything else could be considered medium, but please check the example code below:
breed [ firms firm ]
firms-own [
income
income-class
]
to setup
clear-all
create-firms number-of-firms [ ;; number of firms to be defined through slider
set income random 100
set color red
setxy random-xcor random-ycor
]
ask ( max-n-of ( number-of-firms * 0.1 ) firms [income] ) [ set income-class "high" set size 1.5] ;; the 10% firms with the highest value of income
ask ( min-n-of ( number-of-firms * 0.3 ) firms [income] ) [ set income-class "low" set size 0.5] ;; the 30% firms with the lowest value of income
ask firms with [income-class = 0 ] [set income-class "medium" set size 1] ;; all firms who have no income-class yet are set to "medium"
end
I'm trying to fix the problem of no text when I run rstudio at my gentoo.
My gentoo is configured with the necessary use flags to be almost pure QT5 desktop.
I have tested from rstudio-0.98.1091 (qt4) to rstudio-0.99.879(qt5)
My graphic card is GT-610 and I have installed the latest nvidia drivers for my distribution 361.28-r2.
I have set the opengl acceleration to the nvidia drivers and qt graphic system to native (hw acceleration), as well as the glx info shows direct rendering yes.
So I don't think that the problem is about opengl or graphic card,it must be a problem with some dependency.
capture of rstudio, check the red square
I have the following packages installed about qt:
[IP-] [ ] app-eselect/eselect-qtgraphicssystem-1.1.1:0
[IP-] [ ] dev-libs/libdbusmenu-qt-0.9.3_pre20140619-r1:0
[IP-] [ ] dev-libs/libqtxdg-1.3.0:0
[IP-] [ ] dev-qt/qtchooser-0_p20151008:0
[IP-] [ ] dev-qt/qtconcurrent-5.5.1:5
[IP-] [ ] dev-qt/qtcore-4.8.7-r1:4
[IP-] [ ] dev-qt/qtcore-5.5.1-r1:5
[IP-] [ ] dev-qt/qtdbus-4.8.7:4
[IP-] [ ] dev-qt/qtdbus-5.5.1:5
[IP-] [ ] dev-qt/qtdeclarative-5.5.1-r1:5
[IP-] [ ] dev-qt/qtgui-4.8.7:4
[IP-] [ ] dev-qt/qtgui-5.5.1-r1:5
[IP-] [ ] dev-qt/qtlockedfile-2.4.1_p20150629:0
[IP-] [ ] dev-qt/qtnetwork-5.5.1:5
[IP-] [ ] dev-qt/qtopengl-5.5.1:5
[IP-] [ ] dev-qt/qtpositioning-5.5.1-r1:5
[IP-] [ ] dev-qt/qtprintsupport-5.5.1:5
[IP-] [ ] dev-qt/qtquick1-5.5.1-r1:5
[IP-] [ ] dev-qt/qtquickcontrols-5.5.1-r1:5
[IP-] [ ] dev-qt/qtscript-4.8.7:4
[IP-] [ ] dev-qt/qtscript-5.5.1-r1:5
[IP-] [ ] dev-qt/qtsensors-5.5.1-r1:5
[IP-] [ ] dev-qt/qtsingleapplication-2.6.1_p20150629:0
[IP-] [ ] dev-qt/qtsql-5.5.1:5
[IP-] [ ] dev-qt/qtsvg-5.5.1-r1:5
[IP-] [ ] dev-qt/qttest-5.5.1:5
[IP-] [ ] dev-qt/qttranslations-4.8.7:4
[IP-] [ ] dev-qt/qtwebkit-5.5.1-r1:5
[IP-] [ ] dev-qt/qtwidgets-5.5.1-r1:5
[IP-] [ ] dev-qt/qtx11extras-5.5.1:5
[IP-] [ ] dev-qt/qtxml-5.5.1:5
[IP-] [ ] dev-qt/qtxmlpatterns-4.8.7:4
[IP-] [ ] dev-qt/qtxmlpatterns-5.5.1-r1:5
[IP-] [ ] lxqt-base/liblxqt-0.10.0:0
[IP-] [ ] lxqt-base/lxqt-about-0.10.0:0
[IP-] [ ] lxqt-base/lxqt-admin-0.10.0:0
[IP-] [ ] lxqt-base/lxqt-common-0.10.0:0
[IP-] [ ] lxqt-base/lxqt-config-0.10.0:0
[IP-] [ ] lxqt-base/lxqt-globalkeys-0.10.0:0
[IP-] [ ] lxqt-base/lxqt-meta-0.10.0:0
[IP-] [ ] lxqt-base/lxqt-notificationd-0.10.0:0
[IP-] [ ] lxqt-base/lxqt-panel-0.10.0-r1:0
[IP-] [ ] lxqt-base/lxqt-policykit-0.10.0:0
[IP-] [ ] lxqt-base/lxqt-powermanagement-0.10.0:0
[IP-] [ ] lxqt-base/lxqt-qtplugin-0.10.0:0
[IP-] [ ] lxqt-base/lxqt-runner-0.10.0:0
[IP-] [ ] lxqt-base/lxqt-session-0.10.0:0
[IP-] [ ] lxqt-base/lxqt-sudo-0.10.0:0
[IP-] [ ] media-gfx/lximage-qt-0.4.0:0
[IP-] [ ] sys-auth/polkit-qt-0.112.0-r1:0
[IP-] [ ] x11-libs/qtermwidget-0.6.0:0
[IP-] [ ] x11-misc/obconf-qt-0.9.0_p20150729:0
[IP-] [ ] x11-misc/pcmanfm-qt-0.10.0:0
[IP-] [ ] x11-terms/qterminal-0.6.0:0
And here are my use flags:
fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 \
ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc -gdbm cairo aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat epb pln pts dtherm egl eglfs evdev -spell -lightdm sddm admin lximage powermanagement tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm xsaveopt cqm_llc -adns -tcmalloc webgl cqm_occup_llc nsplugin uvm additions experimental bindist dri -sna udev uxa -xvmc -vaapi opengl intel -llvm -embedded -gpm -profile -berkdb -tiff -mariadb mysql -kerberos -rdoc nvidia pcre16 -gcj -objc* fuse archive gphoto2 mtp -cap -filecaps librsync-bundled -upower xscreensaver -mono fortran -test -webdav -client -ant vdpau acpi -laptop threads lm_sensors pmu apm -java alsa avi jpeg vba -system-wine lapack -exceptions -ipv6 -kde mp3 mpeg ogg -wifi xvid x264 aac faac usb X -arts -gtk -gtk2 -gtk3 ssl -netapi -gnome -doc qt -qt3 -qt4 qt5 -qt3support xlib-xcb minimal dbus lock policykit rar session -server sudo -subunit -ruby startup-notification thunar -cups -xa libkms curl -viaregtool -ads -acl -espeak -opencl -samba -winbind -smbclient -bluetooth dhcpcd -ppp -modemmanager -networkmanager icu minizip -sqlite -python symlink -wext -system-jsoncpp network-uri -boundschecks -https -system-ffmpeg -opus openvg webkit wxwidgets -xscreensaver ldap -sandbox ffmpeg ntfs -instrospection pdf -ppp pam -sendmail -kernel_linux -hangouts -geoloc svg -polkit consolekit introspection gallium classic webcam -video_cards_vmware -video_cards_nouveau -video_cards_radeon -video_cards_r128 -video_cards_tdfx -video_cards_vesa -video_cards_savage -video_cards_mach64 -video_cards_openchrome -video_cards_intel -video_cards_fbdev -video_cards_dummy -video_cards_trident -video_cards_mga video_cards_nvidia -video_cards_via -video_cards_glint -video_cards_v4l -video_cards_nouveau -video_cards_nv -video_cards_virtualbox animation-rtl -gnome-keyring cpuload colorpicker dom sensors worldclock
Any Help is much appreciated.
UPDATE: The problem is still present almost a year later , with rstudio-1.0.136 and QT 5.7.1...
during the execution of this code the model run in the error reported in the object. In a previous model where the variable land-sustainability was setting from 1 to 6 I
didn't incurred in this kind of error. I listed the code below reporting the portion of the code highlithed by the error at the end:
turtles-own [
profit-from-fuel
profit-from-food
expected-fuel-sell-price
expected-food-sell-price
profit
farm
farm-size
]
patches-own [
fuel-yeld
food-yeld
land-sustainability
water-level
belongs-to
food
fuel
]
globals [
fuel-sell-price
food-sell-price
governs
]
to setup
clear-all
clear-all-plots
create-farmers
setup-land
reset-ticks
ask turtles
[ set-farm-in-radius farm-size ]
set fuel-sell-price 184 + random 55 + random -55
set food-sell-price 184 + random 55 + random -55
end
to create-farmers
create-turtles 30
[
set shape "person farmer"
setxy random-pxcor random-pycor
set profit-from-fuel 0 ; indicizzazione del profitto iniziale a 0
set profit-from-food 0 ; indicizzazione del profitto iniziale a 0
set farm-size random 5 + 1
set label farm-size
]
end
to setup-land
ask patches [set belongs-to nobody]
ask patches
[
set pcolor 3
set food-yeld 13000
set fuel-yeld 13000
set land-sustainability random-float 0.9 + 0.1 ; per creare un moltiplicatore che vada da 0.1 a 1
set water-level random 3 * 1000
if water-level = 0 [set water-level 1000]
]
end
to set-farm-in-radius [d]
move-to one-of patches with [not any? other patches in-radius d with [belongs-to != nobody]]
set farm patches in-radius farm-size
ask farm [set belongs-to myself]
let c random 6 + 61
ask farm [set pcolor c]
end
to set-farm-distance [d]
move-to one-of patches with [not any? other patches with [belongs-to != nobody and distance myself < d]]
set farm patches with [distance myself < d]
ask farm [set belongs-to myself]
let c random 6 + 61
ask farm [set pcolor c]
end
to go
ask turtles [
set expected-fuel-sell-price fuel-sell-price + random 5 + random -5
if expected-fuel-sell-price < 0 [set expected-fuel-sell-price 1]
set expected-food-sell-price food-sell-price + random 5 + random -5
if expected-food-sell-price < 0 [set expected-food-sell-price 1]
set profit profit-from-fuel + profit-from-food
if profit = 0 [ set profit 1 ]
]
ask turtles [
cultivate
ask farm [recolor-farm]
set profit profit-from-food + profit-from-fuel
]
set fuel-sell-price fuel-sell-price + random 55 + random -55
if fuel-sell-price < 126 [set fuel-sell-price 126 ]
if fuel-sell-price > 245 [set fuel-sell-price 245] ; è corretta come assunzione? su un arco di 30 anni è ragionevole suppore che il limite massimo del prezzo
set food-sell-price food-sell-price + random 55 + random -55 ; sia di soli 5 euro più alto rispetto al massimo delgi ultimi 10 anni
if food-sell-price < 126 [set food-sell-price 126]
if food-sell-price > 245 [set food-sell-price 245]
if ticks = Duration [ stop ]
if ticks > Duration [stop]
ask patches
[ set food 0
set fuel 0
if land-sustainability < 0.1 [set land-sustainability 0.1] ; all'interno del modello la land susitability varia in base alle colture utilizzate
if land-sustainability > 1 [set land-sustainability 1 ] ; ma questa non può comunque essere inferiore a 0.1 o maggiore di 1
]
tick
end
to cultivate
let r risk-attitude
let e-f expected-fuel-sell-price
let e-food expected-food-sell-price
ask farm [
ifelse land-sustainability < 0.35 or water-level < 1100 ; 0.35 è un valore arbitrario che può essere modificato vedere i documenti FAO
[ ask myself [set profit-from-food sum [food-sell-price * (((food-yeld ) ^ (alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma))))] of farm
]
set food 2
set fuel 0
set land-sustainability land-sustainability + 0.1 ; la scelta di coltivare prodotti destinati alla produzione di cibo incrementa il livello l-s del terreno così coltivato
set pcolor 52.5
]
[
if land-sustainability >= 0.35 or water-level = 0
[
let utility-from-food e-food * ((food-yeld ) ^ (alfa)) * ((water-level) ^ (gamma)) * ((land-sustainability) ^ (beta)) ; da riscrivere la nuova formula con l'utilità di
let utility-from-fuel e-f *(( fuel-yeld) ^ (alfa) * ((water-level) ^ (1 - gamma) * (land-sustainability) ^ (gamma) ))
ifelse utility-from-food < utility-from-fuel
[
ask myself [set profit-from-fuel sum [fuel-sell-price * (((fuel-yeld ) ^ (alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma))))] of farm ] ; ricominciare da qui cobb-douglas
set fuel 1
set food 0
set land-sustainability land-sustainability - 1
]
[ ask myself [set profit-from-food sum [food-sell-price * (((food-yeld ) ^ (alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma))))] of farm ]
set food 1
set fuel 0
set land-sustainability land-sustainability + 0.5
]
]
]
]
end
to recolor-farm
if (food = 1 and fuel = 0 ) [set pcolor green ]
if (fuel = 1 and food = 0 )[set pcolor yellow]
if (fuel = 1 and food = 1) [set pcolor pink] ; check
if (fuel = 0 and food = 0) [set pcolor blue] ; check
end
[ ask myself [set profit-from-food sum [food-sell-price * (((food-yeld ) ^ (alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma))))] of farm
a ^ b will produce this error message if a is negative and b is fractional, so for example if you try to take the square root of -1:
observer> show -1 ^ 0.5
ERROR: Runtime error: math operation produced a non-number
Trying adding show land-sustainability and show gamma before the set profit-from-food ... line, to see what the bad values are, exactly, that you're trying to exponentiate. Then you'll have some debugging to do to figure out where those bad values are coming from.
Probably you're letting land-sustainability become negative.
How can I write a code that permit to an agent to change a value of a variables of a patches,where the agent is not above? It is the case of a farmer, in a previous question I asked how to create the farm. Is it possible that an agent could change a variable of different patches during the same tick? thank you very much for your help.
After 1 tick
After 30 tick
It is a special feature of NetLogo that an agent can directly change the value of a variable of the patch it is directly over (i.e., ask turtle 0 [ set pcolor blue ] will turn the patch under turtle 0 to blue), but any turtle can ask any patch to change one of its variables.
For example:
ask turtles [
ask patch-ahead 1 [
set pcolor green
]
]
will tell all turtles to change to color of the patch ahead of them (not directly under) to green.
They can also ask multiple patches to do stuff, like in the in-radius example found in the user manual:
ask turtles [
ask patches in-radius 3 [
set pcolor red
]
]
If this is related to your Farmer question you can use following:
When you want to make changes on a group of patches with a common property you should filter them with their common property , for example if the belong so same Farmer just ask Farm if you want to make changes on a patches from a farm which has food = 1 you can ask
ask farm with [food = 1]
In summary, I think you should include these kind of condition in your cultivate procedure to filter which patch is being changed.
ask farm with [land-sustainability < 2.1 or water-level = 1]
[
set food 1
set pcolor green
]
ask farm with [The condition which they should set fuel to 1]
[
set fuel 1
set pcolor red
]
UPDATE
turtles-own [
profit-from-fuel
profit-from-food
expected-fuel-sell-price
expected-food-sell-price
profit
farm
farm-size
;risk-attitude-food
;risk-attitude-fuel
]
patches-own [
fuel-yeld
food-yeld
land-sustainability
water-level
belongs-to
food
fuel
]
globals [
fuel-sell-price
food-sell-price
governs
]
to setup
clear-all
clear-all-plots
create-farmers
setup-land
reset-ticks
ask turtles
[ set-farm-in-radius farm-size ]
set fuel-sell-price 30 ;+ random 2 + random -2
set food-sell-price 30 ;+ random 2 + random -2
end
to create-farmers
create-turtles 30
[
set shape "person"
setxy random-pxcor random-pycor
set profit-from-fuel 0 ; indicizzazione del profitto iniziale a 0
set profit-from-food 0 ; indicizzazione del profitto iniziale a 0
set farm-size random 5 + 1
set label farm-size
]
end
to setup-land
ask patches [set belongs-to nobody]
ask patches
[
set pcolor 3
set food-yeld 10000
set fuel-yeld 10000
set land-sustainability random 5
set water-level random 3
]
end
to set-farm-in-radius [d]
move-to one-of patches with [not any? other patches in-radius d with [belongs-to != nobody]]
set farm patches in-radius farm-size
ask farm [set belongs-to myself]
let c random 6 + 61
ask farm [set pcolor c]
end
to set-farm-distance [d]
move-to one-of patches with [not any? other patches with [belongs-to != nobody and distance myself < d]]
set farm patches with [distance myself < d]
ask farm [set belongs-to myself]
let c random 6 + 61
ask farm [set pcolor c]
end
to go
tick
ask turtles [
set expected-fuel-sell-price fuel-sell-price + random 5 + random -5
if expected-fuel-sell-price < 0 [set expected-fuel-sell-price 1]
set expected-food-sell-price food-sell-price + random 5 + random -5
if expected-food-sell-price < 0 [set expected-food-sell-price 1]
set profit profit-from-fuel + profit-from-food
if profit = 0 [ set profit 1 ]
]
set fuel-sell-price fuel-sell-price + random 5 + random -5
if fuel-sell-price < 0 or fuel-sell-price = 0 [set fuel-sell-price 1 ]
set food-sell-price food-sell-price + random 5 + random -5
if food-sell-price < 0 or food-sell-price = 0 [set food-sell-price 1]
ask turtles [
cultivate
ask farm [recolor-farm]
set profit profit-from-food + profit-from-fuel
;if water-level > 0.95 [ set profit profit - (profit * ( 2 / profit )) ] valutare se inserire anche una failing probability
]
if ticks = Duration [ stop ]
if ticks > Duration [stop]
end
to cultivate
ifelse land-sustainability < 2.1 or water-level = 1
[
set profit-from-food food-sell-price * (((food-yeld ) ^ (1 - alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma)) ^ alfa))
ask farm with [land-sustainability < 2.1 or water-level = 1]
[
set food 1
]
]
[
let utility-from-food ((food-yeld * expected-food-sell-price * land-sustainability) ^ risk-attitude ) / risk-attitude
let utility-from-fuel ((food-yeld * expected-fuel-sell-price * land-sustainability) ^ (1 - risk-attitude) ) / ( 1 - risk-attitude)
ifelse utility-from-food < utility-from-fuel
[
set profit-from-fuel fuel-sell-price * (((fuel-yeld ) ^ (1 - alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma)) ^ alfa))
ask farm with [land-sustainability >= 2.1 or water-level != 1][
set fuel 1
]
]
[
set profit-from-food food-sell-price * (((food-yeld ) ^ (1 - alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma)) ^ alfa))
ask farm with [land-sustainability >= 2.1 or water-level != 1] [
set food 1
]
]
]
end
to recolor-farm
if food = 1 [set pcolor green ]
if fuel = 1 [set pcolor red]
end
This is another way that you can do it:
turtles-own [
profit-from-fuel
profit-from-food
expected-fuel-sell-price
expected-food-sell-price
profit
farm
farm-size
;risk-attitude-food
;risk-attitude-fuel
]
patches-own [
fuel-yeld
food-yeld
land-sustainability
water-level
belongs-to
food
fuel
]
globals [
fuel-sell-price
food-sell-price
governs
]
to setup
clear-all
clear-all-plots
create-farmers
setup-land
reset-ticks
ask turtles
[ set-farm-in-radius farm-size ]
set fuel-sell-price 30 ;+ random 2 + random -2
set food-sell-price 30 ;+ random 2 + random -2
end
to create-farmers
create-turtles 30
[
set shape "person"
setxy random-pxcor random-pycor
set profit-from-fuel 0 ; indicizzazione del profitto iniziale a 0
set profit-from-food 0 ; indicizzazione del profitto iniziale a 0
set farm-size random 5 + 1
set label farm-size
]
end
to setup-land
ask patches [set belongs-to nobody]
ask patches
[
set pcolor 3
set food-yeld 10000
set fuel-yeld 10000
set land-sustainability random 5
set water-level random 3
]
end
to set-farm-in-radius [d]
move-to one-of patches with [not any? other patches in-radius d with [belongs-to != nobody]]
set farm patches in-radius farm-size
ask farm [set belongs-to myself]
let c random 6 + 61
ask farm [set pcolor c]
end
to set-farm-distance [d]
move-to one-of patches with [not any? other patches with [belongs-to != nobody and distance myself < d]]
set farm patches with [distance myself < d]
ask farm [set belongs-to myself]
let c random 6 + 61
ask farm [set pcolor c]
end
to go
tick
ask turtles [
set expected-fuel-sell-price fuel-sell-price + random 5 + random -5
if expected-fuel-sell-price < 0 [set expected-fuel-sell-price 1]
set expected-food-sell-price food-sell-price + random 5 + random -5
if expected-food-sell-price < 0 [set expected-food-sell-price 1]
set profit profit-from-fuel + profit-from-food
if profit = 0 [ set profit 1 ]
]
set fuel-sell-price fuel-sell-price + random 5 + random -5
if fuel-sell-price < 0 or fuel-sell-price = 0 [set fuel-sell-price 1 ]
set food-sell-price food-sell-price + random 5 + random -5
if food-sell-price < 0 or food-sell-price = 0 [set food-sell-price 1]
ask turtles [
cultivate
ask farm [recolor-farm]
set profit profit-from-food + profit-from-fuel
;if water-level > 0.95 [ set profit profit - (profit * ( 2 / profit )) ] valutare se inserire anche una failing probability
]
if ticks = Duration [ stop ]
if ticks > Duration [stop]
end
to cultivate
let r risk-attitude
let e-f expected-fuel-sell-price
let e-food expected-food-sell-price
ask farm [
ifelse land-sustainability < 2.1 or water-level = 1
[ ask myself [set profit-from-food food-sell-price * (((sum [food-yeld] of farm ) ^ (1 - alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma)) ^ alfa))
]set food 1
]
[
if land-sustainability >= 2.1 or water-level = 0
[
let utility-from-food (( food-yeld * e-food * land-sustainability) ^ r ) / r
let utility-from-fuel (( fuel-yeld * e-f * land-sustainability) ^ (1 - r) ) / ( 1 - r)
ifelse utility-from-food < utility-from-fuel
[
ask myself [set profit-from-fuel fuel-sell-price * (((fuel-yeld ) ^ (1 - alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma)) ^ alfa)) ]
set fuel 1
]
[ ask myself [set profit-from-food food-sell-price * (((food-yeld ) ^ (1 - alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma)) ^ alfa)) ]
set food 1
]
]
]
]
end
to recolor-farm
if food = 1 [set pcolor green ]
if fuel = 1 [set pcolor red]
end
and this is after first tick:
This is final view:
I'm new to this language and I'm suppose to create a graph, so far I've done very basic structure (nodes). I'd like to assign a different value to each node, this value should be taken from a list (like [1 2 3 4]) and this list should be made automaticly.
I've read this command somewhere else [n-values <number> [self]] But i don't really understand what [self] stands for. What I'd like my program to do is to create n nodes (n is taken from the slider value) and then for each node assign values (1 2 3 4 5...n) respectively.
My code so far:
breed [nodes node] ;;Hacemos 'especies'(Clases) de tortugas, el objeto nodes será de una especie node.
nodes-own [info]
to setup
ca ;clear all shortage
ask patches [set pcolor white] ;;hacemos todas las parcelas blancas
create-nodes num-nodes [ ;creamos tantos nodos como el slider diga
set shape "circle" ;con forma de circulo
setxy random-pxcor random-pycor ;;en cualquier lugar.
]
ask nodes [set info 9] ;;<<<ALL nodes have value 9 I'd like to change this!!!
reset-ticks
end
to layout
layout-spring nodes links .5 .5 .5
end
Thanks in advice!
Also: is there a better way to make a graph? (I'm going to work with flow networks!)
I am not sure why you need n-value <number> self
what N-value does is to repeat the reporter in brackets n times , for example if you :
ask nodes [print n-values info [self]]
each node will print its own name for example (node 1) info times.
best place to start is NetLogo Models Library examples there are plenty examples which use nodes and links for graphs such as Small Worlds, Team Assembly, virus network and ...
http://ccl.northwestern.edu/netlogo/models/
or just from netlogo choose file / Models library
This is your code with a few changes, by adding a list to choose the value of info from, however , if you think info should be assigned to the link not to the node you can add it to link-own
breed [nodes node] ;;Hacemos 'especies'(Clases) de tortugas, el objeto nodes será de una especie node.
nodes-own [info]
globals
[My-Num-List]
links-own [msg]
to setup
ca ;clear all shortage
ask patches [set pcolor white] ;;hacemos todas las parcelas blancas
set My-Num-List [ 1 2 3 4 5 6 7 8 9 10] ; or any other list you need
create-nodes num-of-nodes [ ;creamos tantos nodos como el slider diga
set shape "circle" ;con forma de circulo
setxy random-pxcor random-pycor ;;en cualquier lugar
set label-color black
set info one-of My-Num-List
set label info
]
;;<<<ALL nodes have value 9 I'd like to change this!!!
reset-ticks
end
to layout
crtlinks
layout-spring nodes links .5 .5 .5
end
to crtlinks
ask turtles
[
create-links-with n-of 2 other turtles
[
set msg one-of [ "C" "A" "B"]
set label msg
set label-color black
set thickness 0.2
]
]