I am writing a piece of code in which investment simulations for different types of factories are run. To calculate if an investment is worth the try, the to-be-build factory (say, steel-factory) is analyzed for revenues and costs in the future. To do that, the turtle (e.g. a company) calculating the investment needs to know the production capacity of the steel-factory.
to test
let future-steel-production ([max-processing-capacity * operational-time] of one-of steel-factories
end
But if no steel-factory is build yet (i.e. created), I get the error code:
OF expected input to be an agent or agentset but got NOBODY instead.
Is there any way to access an agent's variable, when the agent hasn't been created yet?
Is there any way to access an agent's variable, when the agent hasn't been created yet?
No. That's a logical impossibility.
But that doesn't mean that you can't figure out the future values of these variables.
You need to ask yourself how you would initialize these variables if you were to actually create the agent. These values (max-processing-capacity and operational-time) have to come from somewhere, right? Do you some have some definition of factory types stored in a file? Accessed via a reporter or some global variable?
If you were to create a factory with something like:
create-factories 1 [
set max-processing-capacity ???
set operational-time ???
]
...what would you replace ??? with? That's your answer. You need to use whatever you would use at factory creation time when calculating future steel production.
Related
I have two populations of agents (only one of which I want to control) and I want to program one agent's actions based on the distance to the agents in the other population. I can get the location of each agent in their own population by using getX() and getY(). However, once these values are stored in a variable, they are not able to be communicated to a different population. Also, using distanceTo (agent other) does not seem to work for agents in a different population. Another issue I am having is how to call up location information for a specific agent (i.e., agent 1 in a population of X agents). When I print the agent names during a model simulation run, I see the agents listed as root.agent[0], etc., however, this syntax does not seem to work for calling up that specific agent when trying to code specific actions based on that agent (i.e., when this agent is so close, do something).
I tried storing locations using getX() and getY() into separate variables. Then using those variables to perform distance calculations. However, these variables, when stored in agent1 agent type, they cannot be communicated to agent2 agent type for variable use. I tried this for distanceTo() as well and got similar errors. I also try calling root.agents[0], root.agent[0] and agent[0] to use for distance calculations (both in and out of that agent's agent type) and get errors for "variable root not recognized" and "variable agent not recognized."
I understand this may be a beginning level programming question, but I cannot find literature on how to solve this problem in AnyLogic help sites online, nor have I been able to find a specific tutorial that works with this type of issue. Thank you for the help.
I am trying to figure out which are the main default attributes of agents in Anylogic, e.g., the Id, the position and the index. So far I haven't found them in the help or at stackoverflow.
1) Do you know where this can be found or can you summarize the main you know? For instance the id used as unique identifier or the index used as the position inside of the population.
2) Are there any attributes regarding the agent history? For example time stamps as the creation time or the blocks it has passed through?
3) Is it possible to change the default id attribute of an agent? Can two agents have the same id?
4) As the split block doesn't copy any of the parameters or variables values to the copy, what is the proper way to copy an agent? I noticed in other publication Benjamin mentioned using agent.set_MyParam(original.MyParam). What would be "MyParam" in this code? Would this copy the value of parameters, variables and the current state in the statechart? Is it possible to make a copy and initialize its current state in the statechart as the original agent's current state?
Thank you for your help.
There are many things that are generated when you generate an agent... the best you can do is to check the api for the agent here: agent api
You can only see these things on the log if you activate it, but not from the API
the id is a unique identifier and i've never been in a situation where i need to change it,but if you want to change it, you can use the setId method, in which case, 2 or more agents may have the same id.
you can only use set_MyParam if the MyParam is a parameter, you can't do the same with variables. Nevertheless, if you want to copy an agent, you need to do it variable by variable, state by state, everything from scratch. There's no magical way to copy the exact same agent with all its current values and states and connections etc
I have a pool of 25 agents (Operators). When an Order is generated, I seize a few Operators and move them to one of many different ProductionSuites as determined by a parameter in the Order.
Within the ProductionSuite, I have a variable of type ResourcePool that I would like to use to have these Operators perform tasks.
In the main window, I put this code in the "On seize unit:" code box:
agent.assignedSuite.suiteOperatorPool.addAgentToContents(unit);
but this triggers a NullPointerException error. Am I using the addAgentToContents method incorrectly?
You have not initialized your suiteOperatorPool variable, it's "initial value" field is empty. Hence, this is just an empty shell of type ResourcePool that cannot do anything, including adding agents to it.
You would need to initialize it properly using the ResourcePool API, but I don't think that is possible.
Also, you cannot have resources be part of 2 resource pools, as you are trying to do. You should think of a different way to solve your problem. Maybe rephrase the issue so we can think of alternatives. You might not need a RP at all but just use pure agent functionality...?
how is it possible that the sourceof a process model only creates the agents out of a population and in best case at once? In my model the source is creating more agents than the size of the population.
thx in advance
Using a Source it is not possible to output already existing Agents of a population from it, as the source is always creating them at the time of output.
You have two possibilities:
Instead of a Source, use the Process Modelling element Enter at
the start of your process flow. Using the function
enter.take(myPopulation.get(index)) you can input your already
existing population members. This way you can also input them "at once".
In the Source properties under Advanced - Population select your
custom population. Whenever the source creates a new Agent, it will
get added to this population. Note: The Agent type of the population
must be the same as the Agent type defined in the Source.
Is there any way to re-run a Netlogo model exactly as before? (i.e. effectively press Go again and have the run be exactly the same as the last one.)
As I understand it, all you would need to be able to do this is to find out the random seed that was used in the last run - can this be done? Then all you would need to do is include the code "random-seed xxx" in the setup.
This feature would be really useful, so if it can't be done, maybe it could be implemented in future versions.
Thanks.
I'm assuming here you still want each run of your model to be different (change the random seed each time). According to the NetLogo Programming Guide:
If you don't set the random seed yourself, NetLogo sets it to a value based on the current date and time. There is no way to find out what random seed it chose, so if you want your model run to be reproducible, you must set the random seed yourself ahead of time.
So we can do this, we just need to handle "remembering" the random seed ourselves. Assuming you've got a standard setup procedure that has to be executed before the model runs:
globals [ run-seed ]
to setup
set run-seed new-seed ; get a random seed to use for our run
random-seed run-seed
; do the rest of our normal setup
end
Now when your model run is done you can show run-seed in the command center, or print it out in code to record it. Then you can use that seed instead of the new-seed in the setup procedure to reproduce the model run exactly in the future.