I am coding a traffic simulation and I want to plot a property of the patches against time.
Can you help me with the coding?
I am trying to introduce an if clause that a monitor (representing budget) will produce a certain amount of money when the IRI or USER COST reaches a certain number.
Please, I will be glad if you could help me with this.
Hope to hear from you soon.
Kind regards,
Jephunneh Bonsafo-Bawuah.
I tried creating a monitor it reports the amount once and that's all but I wanted it to report continuously.
I tried using a code but that didn't also work
to budget
ifelse IRI > 220
[ set budget 20000 ]
[set usercost 0]
end
the error message says
set expects two inputs
Related
Looking for a way to store a turtle length of stay in the model after they have left the model. My model runs for several months and a few thousand turtles enter, undergo process then leave the area. It's complicate model (it's a hybrid DES and ABM) so I've tried to reproduce the simple bit below.
Turtles will be created at every tick and given a random length of stay but will only be able to begin process when they move to the right area (area-name) and when their time is up they leave the area. Their time-in-system reflects the wait for the area and the length-of-stay which I want to save once they're complete. If I leave them in the model it starts to break down after a couple of months and I suspect this is because the model has too many turtles still in the system for calculation and is inefficient.
go
create turtles 2
[
set time-in-system 0
set length-of-stay ceiling ((random-normal 48 4) + ticks)]
set shape "person"
if any? area-name with [not any? turtles-here]
[move-to one-of area-name]
]
undergo-process
end
to-undergo-process
ask turtles with [shape = "person"]
[
set time-in-system time-in-system + 1
]
ask turtles-on area-name
[if ticks = length-of-stay
[set shape "dot"
move-to exit-door]
end
I can then plot and see in realtime to make sure it is working
histogram time-in-system of turtles with [shape = "dot"]
but can't seem to figure out how to store them as unique values for plotting after the model has run and I have a dataset of outcomes without keeping them alive in the model. The real-time plot isn't necessary as long as I can store the unique values after they have left
If I ask them to die then I lose the unique values in the histogram. I don't want a tally of all values but each turtle's unique value at the end of the process after they left - at the moment the only solution I have to storing them is as an agent-set that stays alive in the exit-door patch but this takes up a lot of calculation power as the model progresses for months...
There may be a really simple command for this but I've been going round in circles through the programming manual trying to find it. Any tips appreciated
You should create a list storing the values of turtles that left.
Isolating only the code that is relevant for this purpose, it would be something like:
globals [
times
]
to setup
set times (list)
end
to leave-simulation ; This being executed by turtles.
set times lput (time-in-system times)
die
end
If your program is going to run for actual months, I recommend you use the file-write command to store your data. This way the data is preserved if the program halts for any reason; it gives you much more freedom to do the analysis you want without running the full simulation again.
If you write to a .csv (comma separated value) file, you can use almost any program (excel, R, matlab, python, C# or back to netlogo) to plot a histogram.
I'm working with a NetLogo model on EV charging behaviour. All (500) agents monitor their my-charging-demand per tick and I want to find out what happens to this emergent behaviour when I change the policy intervention that is active (costs of electricity in this case). I am trying to show changes in charging characteristics such as charging-duration, charging power etc.
What is the best way to create data on the agents' my-charging-demand in time?
Right now I am plotting all their data in one graph using the following code:
ask adopters
[ create-temporary-plot-pen (word-who)
set-plot-pen-color color
plotxy ticks my-charging-demand
]
It works, but unfortunately it also made the model incredibly slow, as 500 pens are to be updated every tick. The model needs 105120 ticks before a whole year/run is completed, as each tick in the model represents 5 minutes. Therefore, speed does matter :-)
Is there a more efficient way to keep track / create data of one variable all agents have?
If I have understood this correctly, you want each agent to remember the value of its variable my-charging-demand across all time. If so, the easiest way (but I don't know if it's more efficient) is to have the list as a turtle variable. So, modify your turtles-own to add another variable:
adopters-own
[ ....
my-charging-demand
my-charging-demand-series
]
And wherever you have the code for calculating demand, add the result to the list
ask adopters
[ ...
set my-charging-demand ...
set my-charging-demand lput my-charging-demand my-charging-demand-series
...
]
I can't imagine a plot with 500 lines is readable. The plot should do something like the average of my-charging-demand or the proportion of turtles with my-charging-demand greater than some threshold.
I am trying to model a stock market. I am trying to give agents a certain kind of behaviour to base their prediction of the prices on.
So basically, every agent predicts the price of the share. In the Setup procedure, a random predicted price is assigned to each agent. As the time passes, the predicted price is supposed to be calculated as follows:
total of predicted price of the last 3 periods / 3
I don't know how to approach this issue. I tried using the last command but it does not work. I was thinking about making a sort of vector but I couldn't do so. Any leads?
This is what I have tried so far:
ask turtles [
set pre-price (pre-price + last [pre-price] of turtles + last [last [pre-price] of turtles] of turtles) / 3 ]
end
The last command does not work as I want it to work because I have tried to manually calculate the results and they don't reconcile with this command. Any idea on how to go about it?
Thank you!
This is actually a very interesting bug.
The issue is that inside your turtle call, you assume all the turtles "pre-price" is static; however, with each agent, they are assigning the variable.
I'd suggest to introduce another variable which explicitly stores the pre-prices for each tick (using a matrix/nested list)
I want to add a slider that shows the chance to spread the message to "Communication T-T Example" on Netlogo.
It's supposed to show the probability of the second turtle to receive the message from the first one who has the message, and it should be adjustable by the user.
Yet I don't know how I should modify the code in such a case.
I couldn't find any similar question in previous ones, I would appreciate your recommendations and helps, thank you.
Suppose you define your slider like this:
then it's just a matter of adding a simple condition to the communicate procedure:
to communicate
if any? other turtles-here with [ message? ]
and random 100 < transmission-probability
[ set message? true ]
end
You could also define your probability to be from 0 to 1 and use random-float 1.0 instead of random 100.
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.