modelinganylogicagent-based-modelingstatechart

Specifying agent properties when using .inject()


For logic testing purposes, I am using a clickable button triggering "source.inject()." The preceding logic for the agents is dependent on agent characteristics. Thus, it is preferable to have control over which characteristics they get during initiation when testing the model logic. Searching the AnyLogic documentation on the source block's inject()-function does not show any way to mandate the initial characteristics.

enter image description here enter image description here

I have tried using "add_patients();" this allows for the creation of agents, and I can specify the characteristics inside the parentheses as I like. However, the agents will not enter the statechart if I use this function.


Solution

  • instead of using a source, use a enter block, then you can control the parameters of your agent. So instead of source.inject() you will do:

    Patient patient=add_patients(a,b,c,d);
    enter.take(patient);
    

    Or course you will need a population of patients defined somewhere to do that.

    If you don't have a population of agents then you can do

    Patient patient=new Patient(a,b,c,d);
    enter.take(patient);