I am new to programming and using netlogo so this question is probably too simple.
I am creating a model in which households decide their farming area each year (changing the location every year). I need to make them change the type of vegetation of n patches, according to the size they decided previously.
I know primitives like in-radius, neighbor and neighbor4 but all of them don't give me the freedom to change the exact number I want. For example, if the farming area is 3 hectares, how can i make one household change 3 patches vegetation type? How can I do that?
Thanks
How about:
n-of 3 neighbors
That would give you three random patches among the patche's neighbors, which may or may not be what you want, but your question isn't precise enough to say...
Let us know if that works for you. If not, give us a bit more detail.
Related
Sorry for long post. I am newbie in agent-based modelling. So please accept my apology in advance if my question sounds stupid. I am trying to model a scenario where framer (i.e. agent) decides which type of crop should be harvest in different types of fields to increase the profit. The farmer agent has a budget i.e. the amount of money that can be spent on farming each time step equal to $100.
The farmer operates a farm that is subdivided into nine fields, which are arranged in a 3x3
cellular grid. Each field is of the same size. Water availability varies spatially across the fields with a rating of either 1 (driest), 2 (moderate),
or 3 (wettest). The manner in which water availability varies across the fields (i.e. randomly).
The farmer must choose among three crops. As initial parameter settings, the crops have the
following characteristics:
Yield Price Costs Minimum Water Req.
Crop 1 300 20 15 3
Crop 2 200 12 10 2
Crop 3 100 7 5 1
Each crop requires a certain amount of water to grow. Crop yields will only be realized if the crop is
planted in a field with at least the crop’s minimum water requirement.
Now the problem is that I couldn't find any function in Netlogo that calculates the permutation or combination of crop, field, and water requirements to calculate the expected profit. Any help would be high appreciated.
I believe you describe a linear programming problem.
Useful functions for solving Simplex Linear Programming problems are in NumAnal extension, which does not come bundled with NetLogo but which you can get as follows:
In NetLogo, under Tools / Extensions ... you can find NumAnal, probably with no green check-mark. Select it. On the right, you have buttons to install it, and then one to add it to your code. When you click those, it should now get a green checkmark and you should have a new line in your code "extensions [ numanal ]", and you are now able to use those commands, with the "numanal:" prefix, for example, numanal:simplex.
The documentation for it is in the folder where it was installed. But where is that?
Sadly, the documentation for where extensions are downloaded is not current.
https://ccl.northwestern.edu/netlogo/docs/extensions.html#where-extensions-are-located
After exhaustive search by date-modified, I actually found the folder on my Windows 10 laptop here: c:\Users\condor\AppData\Roaming\NetLogo\6.1\extensions
( Note the "\Roaming\" ).
That folder has a README.md text file, and a pdf document named "NumAnal-v3.4.0" explaining how to use it, and an examples folder with code. It is a little dense.
Here's a link to the basics of how to describe a Linear Programming problem, which is beyond the scope of StackOverflow. You can find help via Google.
Here's one 8 minute video ( as of 24-Nov-2019) that might help you figure out if this is what you need.
Simplex Algorithm Explanation (How to Solve a Linear Program)
https://www.youtube.com/watch?v=RO5477EKlXE
I have a NetLogo model, simplified to this:
to setup
clear-all
create-turtles 1000 [
fd 100
]
end
When I add a monitor widget to the UI, with a reporter like mean [xcor] of turtles and then run setup, the values in the monitor change a slight bit constantly. It might show 0.2305090322262271 one moment then 0.2305090322262268 the next, and then another similar number on and on.
What is making my monitor widget flicker or flash like this? How can I prevent it?
This is caused by a combination of a few things:
NetLogo's use of floating point numbers, which can produce small accuracy issues. See Floating point accuracy in the NetLogo programming guide: https://ccl.northwestern.edu/netlogo/docs/programming.html#math
Agentsets such as turtles are always returned in a random order.
Monitors re-run their reporter calculation constantly, even when you are not running any model code with a forever button or through the command center.
So the monitor constantly re-runs its mean [xcor] of turtles reporter, but the turtles agentset gives the turtles in a random order, and so the floating-point inaccuracies for mean will accumulate in a slightly different way each time due to the order differences. The end result is you see very slightly different numbers flashing through the monitor widget while nothing is happening.
You would see the same problem doing sum [xcor] of turtles or variance [xcor] of turtles - anytime you're reducing a bunch of floating point numbers from an agentset into a single value. You can also see the problem running your reporter code directly in the command center repeatedly, without a monitor widget at all.
The fixes are fortunately pretty easy:
Sort your numbers before you calculate: mean sort [xcor] of turtles, sum sort [xcor] of turtles, variance sort [xcor] of turtles. If the numbers are in the same order you'll still have small floating-point inaccuracies, but they'll be the the same every time so you won't see the values change. This is probably the best solution, but it can be slow if you have a really large agentset.
Change the Decimal places setting of your monitors to a number where you don't notice the changing values. Since the differences in results should be small, this is usually possible.
I am trying to create a netlogo program in which turtles move around randomly and create links with each other when they cross the same patch. I would like to implement the average path length of the network after a certain number of ticks.
I have got as far as the turtles creating links but am unsure how to implement an average minimum path length. How would I go about implementing this and showing it on a monitor?
Look at the networks extension and, in particular, the nw:mean-path-length primitive. Calculating mean path length is computationally expensive, don't write your own procedure.
Here I give you my problem and my code.
Problem:
Each agent i attaches to each position m (each m has a fixed amount of food, but some are worse, some are better) a score U_im that is updated in the course of time. Initially the scores are set to zero. Every time a player is chosen to access resources, with probability epsilon he choses a position at random, otherwise he choses positions sequentially in order of the highest score registered so far.
For every position visited, the score is updated as U_im -> U_im - c (the cost) if the position is found occupied
and U_im -> U_im + u_mi if it is found free.
How can I create this array u_mi? (that saves the best resources (=the ones with more food) that I have visited so far)
EDIT//: Ok, I did it!
If anyone needs this kind of code, feel free to contact me :)
that's very impressive code for one day's experience !
yes, the list of payoff-memory as a nomads_own variable is how I would do it. But you will have to keep both the position and the payoff or you won't be able to sort them. You may want to limit the memory (eg only last 5 or best 5 or similar) if it starts slowing down too much because you are basically asking every turtle to keep a list of all patches.
On the question of 'not doing anything' - it is possible your while loop is stuck if there aren't any available locations. Try doing it this way (which is likely better anyway as it only has to select once):
to move-to-empty-one-of [locations] ;; nomads procedure
let candidates locations with [not any? nomads-here]
if any? candidates [ move-to one-of candidates ]
end
NOTE: not tested
I am modeling tax evasion. My initial thought was to led a random number of patches be "businesses" and have wandering turtles that chose to shop at the business that can offer the best price within a given range of the turtle.
I need to somehow store the total transactions (turnover) of each business (random patches).
In addition, each business will either chose to report all income to the tax authority, or choose to evade a certain amount, which in turn will depend on each business' profile - some are willing to evade if the competition is to high, some always evade, and some never evade.
So my question is; can I assign each business-patch a different "personality", store the sum of transactions, and make them report their income? Or can these kinds of variables only be stored in a turtle? In other words, should I make a model with several breeds of turtles in stead, where some are customers and some are stationary businesses?
Patches can have patches-own variables just like turtles can have turtles-own variables. See: http://ccl.northwestern.edu/netlogo/docs/programming.html#variables
If your businesses really are stationary, it makes sense to model them as patches.
Modeling them as turtles does give you a bit more flexibility, however. You could set shape "house" for visual effect. You could have them enter in a network eventually. You could change their size according to some relevant variable. Etc.