Search code examples
javaanylogic

Type mismatch: cannot convert from Agent to Fellow


In my model, various practitioners go to see patients multiple times in one visit. I am trying to ensure the same fellow is used to see a patient over multiple visits after being seized and released multiple times. I continue to receive this Type mismatch. Type Patient is the agent being pushed through the model and type Fellow belongs to a resource pool of 3 fellows.

ResourcePool params Main code Error


Solution

  • A few notes

    1. Your screenshot is of the resource pool named Fellows - yet you market the Unit type as Patient - it should be Fellow if you want the resource pool to contain agents of type Fellow and have patients flow through the process flow and seize Fellows

    enter image description here

    1. In the on seize code you have two local variables you can use

    enter image description here

    Unit - is the Fellow, the resource unit from this pool agent - the agent that seized the unit (can be literally anything) so you need to cast it to what you think it is going to be.. AnyLogic cant do it or you as it has no idea what agent type will seize it

    enter image description here

    1. Your custom resource choice will then also change

    We again need to cast the agent to a Patient again

    enter image description here


    NB - remember that this logic will throw a cast class exception error if any other agent than a Patient seizes a fellow.