Search code examples
anylogicinject

AnyLogic inject() doesn't accept type


I am trying to inject with a function objects from a population into a source block.

In the function I used this inject() function:

for (mp_lkw mp : mplkws) 
{

    if (dateToTime(mp.ankunft) <= time()) {
        remove_mplkws(mp);
        source1.inject(mp);
    }
}

Now my source should accept that injection, but an error occurs, that it is only applicable for Integers

Unresolved compilation problem: 
    The method inject(int) in the type Source<mp_lkw> is not applicable for the arguments (mp_lkw)

I wonder why it doesnt accept my agent type even though the settings in source for "New agent:" and "Agent type:" are set to my agent "mp_lkw"


Solution

  • This is not how the inect() method works. It only lets you specify the number of agents that the Source block creates when you call it. But the details of the agents themselves are set by the Source block.

    In your case (where an agent already exists and just needs to start a new flow chart), you replace the Source block with an "Enter" block.

    In the code, you call myEnterBlock.take(mp);