I am using the table extension as variable owned by a breed of agents.
The content of this table contains values referred to agents of another agent-set (events).
As table keys, I use e-ids a list with the who numbers of each agent in events breed.
The following procedure initializes the tables:
to setup-tables
ask walkers [
set we-tfound table:make
set we-interest table:make
foreach e-ids [ [?] -> table:put we-tfound ? 0
table:put we-interest ? 1 ] ]
ask links [
set popularity table:make
foreach e-ids [ [?] -> table:put popularity ? 0 ] ]
end
The answer to others posts recommends not to use who numbers and iterate over agents by using, for example, construct ask agents [...].
However, I do not know how could be the best way to iterate over table:keys using agents or someway better than whos ids.
Thank you very much for your help
Since agents can't be used as keys in tables, using who numbers is perfectly reasonable. The danger here is that if a turtle dies, you end up with an entry that doesn't actually correspond to an existing turtle. (This is also the reason agents are not allowed as keys in tables.) You can do is-turtle? turtle key to see if key corresponds to an existing turtle.
To convert table:keys back to an agentset, you can do:
turtle-set map turtle table:keys my-table
Thus, to ask all the turtles that are keys in a table, you do:
ask turtle-set map turtle table:keys my-table [ do-stuff ]
map turtle table:keys converts the list of who numbers to a list of turtles. turtle-set then converts that to an agentset.
Related
I have a population of agents (called products) that has multiple parameters of different types. The parameters are "amount" of type int and the other is "location" which is a location on the GIS map. Now I would like to store these agents in a collection when they enter an enter block. Does anyone know how to do this? What type of collection could I use and how do I define the elements?
Drag in a collection, keep the default ArrayList type and set the content type to your agent type.
In the Enter block's "on enter", write myCollection.add(agent)
That is all :)
Hi I am trying to find a search solution where I can assign a weight (x point) to an attribute if its value is greater or smaller then some value ( Y value)
Like if the price is greater then 10 USD then assign 5 points to the item, and I am assigning points on multiple attribute, then get the list of item on the bases of total points in asc or desc order, how can i do this in algolia
Algolia doesn't work with weights, but with a tie-breaking strategy that decides how to rank results based on their attributes. This strategy is static, and set at indexing time.
In your case, you're willing to rank results by a multitude of criteria, including by price. The easiest way to do this is to use the customRanking attribute and set each attribute that should play a role in the ranking strategy. For example, if you want more expensive items to be ranked higher, you can do the following (JavaScript example, but you have a choice between 11 different languages):
index.setSettings({
customRanking: [
'desc(price)'
]
});
Notice the customRanking property takes an array. You can pass several criteria for your custom ranking, and they will be taken into account in the defined order, if the engine can't break the tie.
Since you're working with prices, you may end up in a case where two prices are so close that it makes no sense to break the tie on them; and you'll want to move on to the next criterion. In this case, you can add a new attribute with a rounded price and use this one as the custom ranking attribute. There's a guide in the documentation on that topic.
Suppose I have 2 agents and I want to make tables for them use table extension. Instead of one table to store their values, I want to ask each agent to create, say, table_0 for the first agent (which has 0 for the who variable, hence the name), and table_1 for the other one, so the first agent won't bother the second agent's table and vice versa.
Is that possible?
This is what turtle attributes are for. You don't need to have different names for each table, a turtle keeps track of its own copy of any attribute. So just have something like:
turtles-own
[ my-table
]
I have a population of agents as employees. They have a salary which has a formula to be calculated, so I defined it as dynamic variable, "salary". I want to know the average of the salaries, so I went to the statistics and defined:
Name: AvgSalary
Type: Average
Expression : item.Salary
The question is that I may need to assign this number to a variable so that it can be used in other formulas in other stages of my evaluation. How is that possible?
Many thanks in advance,
Your statistic object AvgSalary is already an object you can access. You defined it in the properties of the agent population so you can access it by baccling myAgentPopulation.AvgSalary() and it will always return the current value.
Hope this helps
I am just starting with Anylogic & Java. Could you please help me with my simple issue?
I have two windows: Main & Trucks
The trucks are entities generated on my model using a "source" within "Main".
I asked the model to create 10 trucks at the same time. It creates the trucks and then they move to another defined point at different speeds. When they arrive at the final point I want to know which truck arrived first (1, 2, ... or 10).
So... I am assuming that there is a way to assign a number to each truck when they are created. And I am also assuming I can read this number at the final point to know which one arrived first.
How can I do this?
Yes it is possible. Use a parameter. Truck is an agent and it can have multiple parameters. The easiest way to use parameters is to drag them from the Agent pallet into the Truck window. You define its name and type (in your case will be integer). When the truck is generated at the source you can give the parameter the value you want. If you want to have a sequential number, create a variable in your main window called ID with initial value 1 and then, in the source object, on the On Exit code area you type something like:
Agent.parameter = ID++;
Note that "parameter" should be the name of the parameter you created in Truck window.
Hope that helps.