Search code examples
anylogicagent

Error code while accessing custom parameter values from excel file


I am tryig to build a discrete agent based model. I have a set of agents with custom parameters, these parameters are loaded via an excel file (this part works, I can view the agents). All agents are created at once at the model start-up.

Now I want the agents to move through the system based on these parameters. I have build a dummy-model with a selectOutputIn and two SelectOutputOut blocks and a function. I want the agent to move to selectOutputOutBasic if a string-parameter has a certain value.

The function code is:

if (agent.variation == "Basic")
    return selectOutputOutBasic;
else return selectOutputOut;    

Anylogic builds the model, but when I try to run it, I get the following error corde:

Exception during discrete event execution:
class com.anylogic.engine.Agent cannot be cast to class test.Order (com.anylogic.engine.Agent and test.Order are in unnamed module of loader 'app')
java.lang.ClassCastException: class com.anylogic.engine.Agent cannot be cast to class test.Order (com.anylogic.engine.Agent and test.Order are in unnamed module of loader 'app')
    at test.Main$1.choice(Main.java:1)
    at com.anylogic.libraries.processmodeling.SelectOutputIn.b(Unknown Source)
    at com.anylogic.libraries.processmodeling.SelectOutputIn.b(Unknown Source)
    at com.anylogic.libraries.processmodeling.SelectOutputIn$1.outputBlock(Unknown Source)
    at com.anylogic.libraries.processmodeling.InputBlock$1.a(Unknown Source)
    at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
    at com.anylogic.libraries.processmodeling.OutPort.b(Unknown Source)
    at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
    at com.anylogic.libraries.processmodeling.OutputBlock.a(Unknown Source)
    at com.anylogic.libraries.processmodeling.OutputBlock.a(Unknown Source)
    at com.anylogic.libraries.processmodeling.OutputBlock$2.a(Unknown Source)
    at com.anylogic.libraries.processmodeling.OutputBlock$2.action(Unknown Source)
    at com.anylogic.libraries.processmodeling.AsynchronousExecutor_xjal$a.execute(Unknown Source)
    at com.anylogic.engine.LibraryEventHandler$b.execute(Unknown Source)
    at com.anylogic.engine.Engine.m(Unknown Source)
    at com.anylogic.engine.Engine.jj(Unknown Source)
    at com.anylogic.engine.Engine.c(Unknown Source)
    at com.anylogic.engine.Engine$b.run(Unknown Source)

Solution

  • Turns out, those who can read have an advantage...

    I found the solution to my problem in this post, thanks @ Dat Boi!

    Try going to the service properties. Under the "Advanced" tab, is Agent Type selected as "MyAgent" or as "Agent"? Similarly, go to the source properties and check the tab Agent and make sure "MyAgent" is selected.

    enter image description here