1

In the setup I would create a command that generate a random number of cluster with a random dimension. Each cluster it would be managed by an agent (farmer). Every single patch represent a potential crop that farmer can cultivate with a different type of seeds. It would be worth use the function in-radius? If you need more details ask me.

Thank you very much for your answers, it's exactly what I need! Now I've another question, I implemented the program as you suggest and now I displaying a world like your, but I don't know how to make my agent (the farmer) act on every patch of their farm-size. In my simulation farmer act only on one patch the one they are on. I tried in a different way to extend the action of my agent (function patch-set, ) but everytime I got an error during the running of the procedure. As suggested in the previous post by Marzy I include the code of my model. The main problem is to extend the procedure "to cultivate" (at the bottom of the code) to each patches who belongs-to a farmer.

Thank you very much

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

 ]

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 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 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

     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 pcolor green set profit-from-food  food-sell-price * (((food-yeld ) ^ (1 - alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma)) ^ alfa)) 
    ]

  [
  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 pcolor red  
   set profit-from-fuel fuel-sell-price * (((fuel-yeld ) ^ (1 - alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma)) ^ alfa)) 
   ]

  [
    set pcolor green 
    set profit-from-food food-sell-price * (((food-yeld ) ^ (1 - alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma)) ^ alfa)) 
    ]

]



end

new version_______----

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)) 
 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)) 
   set fuel 1 
    ] 
   [
  set profit-from-food food-sell-price * (((food-yeld ) ^ (1 - alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma)) ^ alfa)) 
   set food 1
 ]
  ]
  ask farm [
  if food = 1 [set pcolor green]
  if fuel = 1 [set pcolor red]
 ]
  end
  • 1
    Its better to include some code and ask what exactly is the problem in-radius can be good but what kind of cluster do you need? – Marzy Jan 17 '14 at 00:15
  • 1
    this seems very similar to http://stackoverflow.com/questions/20533159/spacing-agents-in-netlogo-based-on-territory-size and http://stackoverflow.com/questions/20831832/define-home-area-turtles/ and http://stackoverflow.com/questions/19326781/adding-patch-clusters-in-a-landscape and http://stackoverflow.com/questions/20336364/how-to-create-cluster-patches-that-do-not-overlap-between-them. I'd suggest looking at those; they should help you solve your problem and/or formulate a more specific question. note that on Stack Overflow you can edit your own question to improve it and add more details. – Seth Tisue Jan 17 '14 at 04:27
  • 1
    Just as a side note, you should call `reset-ticks` at the end of `setup`, and `tick` at the end of `go`. – Seth Tisue Jan 20 '14 at 23:21

2 Answers2

0

As Seth said its similar to other questions in stackoverflow, here is more related answer:

turtles-own [farm farm-size]
patches-own [belongs-to]

to setup
  clear-all
  ask patches [set belongs-to nobody]
  create-turtles 9
  [
    set farm-size random 5 + 1
    set label farm-size
  ]
  ask turtles
  [ 
    set-farm-in-radius farm-size
  ]
  ask patch -8 14 [set plabel "set-farm-in-radius"]
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 8 + 21
  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 8 + 21
  ask farm [set pcolor c]
end

enter image description here

And using distance results in following design, I have set the varibele belongs_to of each patch which shows who owns that patch in plabel so you can see it better.

enter image description here

Update: When you want to make a change on every patch of a farm you should ask farm []

to cultivate


  ifelse land-sustainability < 2.1 or water-level = 1
  [ 
    ask farm [
    set pcolor green 
    ]
    set profit-from-food  food-sell-price * (((food-yeld ) ^ (1 - alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma)) ^ alfa)) 

  ]
  [
  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
  [ ask farm [
    set pcolor red  
  ]
   set profit-from-fuel fuel-sell-price * (((fuel-yeld ) ^ (1 - alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma)) ^ alfa)) 

  ]
  [
    ask farm [
    set pcolor green ]
    set profit-from-food food-sell-price * (((food-yeld ) ^ (1 - alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma)) ^ alfa)) 
    ]

]



end

Update:

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 [
      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 [
        set fuel 1 


      ]
    ]
    [

      set profit-from-food food-sell-price * (((food-yeld ) ^ (1 - alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma)) ^ alfa)) 

      ask farm [
        set food 1

      ]

    ]
  ]



end

to recolor-farm
      if food = 1 [set pcolor green ]
      if fuel = 1 [set pcolor red]
end

Add ask farm [recolor-farm] after Cultivate

Marzy
  • 1,884
  • 16
  • 24
  • I tried to make the agent manage the patch they own, but with my code the agent act only on the patch where they are on. I put my code in the original comment, how can I implement the code in a manner that the agent can manage (decide which type of farming) all the patches that they own? – user3204387 Jan 20 '14 at 21:23
  • 1
    `to cultivate ... ask farm [ ... ] ...` – Seth Tisue Jan 20 '14 at 23:21
  • Thank you very much, now I see the whole patches componing the farm become of the same color. I tried to find out the way to make every single patch of the farm with a different color. I thought at model where every single farmer decide which kind of product cultivate for every single field (patch) of his own farm. Ask me if you need more details. – user3204387 Jan 21 '14 at 17:54
  • I think you need a patch variable for this, then when you ask farm to set pColor related to that variable . – Marzy Jan 21 '14 at 20:37
  • I created another two patches varaibes "food" and ""fuel" they are valued in the procedure "cultiate" at the end of each condition of the function "ifelse", then I put a condition in the go procedure and if food = 1 set pcolor green and if fuel = 1 set pcolor red; but it doesn't works, in this way only the patches where there is farmer change color... I pasted the new version of the model in the orignal post. – user3204387 Jan 22 '14 at 21:17
  • They should be inside ask farm [] – Marzy Jan 22 '14 at 21:23
  • In your code I still dont see the ask farm [] in cultivate procedure – Marzy Jan 22 '14 at 21:26
  • now I put the ask farm in the cultivate procedure, but the results are the same, only the patches where there is upon an agent change their color. – user3204387 Jan 22 '14 at 21:36
  • you should include set food or set fuel inside ask farm not outside – Marzy Jan 22 '14 at 21:44
  • in this way: ask farm [ set food 1 if food = 1 [set pcolor green ]] the model change the color of the whole patches of the farm. – user3204387 Jan 22 '14 at 21:55
  • You have to include a condition for changing feul to 1 or food to one and then ask patches to recolor based on their value – Marzy Jan 22 '14 at 22:03
  • and you should check the condition inside the ask farm [] – Marzy Jan 22 '14 at 22:03
  • At the end of the condition in the procedure cultivate I set the value of food or fuel to 1. At the end of this procedure I ask the farm to set pcolor red if fuel = 1 or green if food = 1, but the only patches changed were those where there is a farmer upon.. – user3204387 Jan 23 '14 at 06:13
0

Your answer for second part:

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 
[
 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
[
   set fuel 1 ]
    ] 
   [
  set profit-from-food food-sell-price * (((food-yeld ) ^ (1 - alfa)) * (((water-level) ^ (1 - gamma)) * ((land-sustainability) ^ (gamma)) ^ alfa)) 

    ask farm [
       set food 1]

 ]
  ]
  ask farm [
  if food = 1 [set pcolor green]
  if fuel = 1 [set pcolor red]
 ]
  end
Marzy
  • 1,884
  • 16
  • 24
  • Hi, I tried with the new procedure, but the result is the same... If a farmer decides which kind of plant cultivate he turns all the patches of his farm in the same color. Maybe I'm missing something in my explanation, if you need more details about the model ask me. Thank you very much for your time. – user3204387 Jan 23 '14 at 17:46
  • Your condition for setting values for food and fuel is not related to each single patch, they only consider some profit for the farmer, you should put a condition to change the value of food or fuel based on that condition related to patches not to the farmer. – Marzy Jan 23 '14 at 18:14
  • Ok, so I need to move variable of profit-from-food and profit-from-fuel in a patches-own context? – user3204387 Jan 23 '14 at 19:28
  • Is it reasonable that patches have their own profit value (both: fuel and food) based on other variables, and the farmers decide which use based on their expectetion on the price of the final goods? In this case I only have to change the cultivate procedure? – user3204387 Jan 23 '14 at 19:46
  • I've made some in changes in my model but I still have problem in the management of the range of action of my turtles I don't know how to extend their action to other patches. I've created a two new variables yield-from-food and yield-from-fuel, they are setted at the beginnig of the go procedure. – user3204387 Jan 25 '14 at 18:07
  • When in the "cultivate" procedure the agents decide which kind of crops cultivate they act only on the patch where they are on. – user3204387 Jan 25 '14 at 18:10
  • One thing you should remember is that you can ask a group of patches with their common property for example if you ask farm they are all belong to same person you can ask farm with [some condition] and if you dont ask anything the change only applies to current patch which agent is on. – Marzy Jan 25 '14 at 22:22