Search code examples
anylogic

Function not comparing values with agent parameters


I wrote an 'IF ELSE' function to compare the value of a parameter with 3 predefined values, being these the types of trucks available. My agent is a population of stores with ID, location and type of truck allowed that are based on the data in the table below. The 'IF function' will check what is the truck allowed in the store and send a message to its agent with the order so that the truck will leave the distribution center and deliver the order.

Table with data

Java Code of IF Function

Agent's Parameters

We checked each of the stores and they seem to have the values correctly atributed from the table. However, the 'IF function' doesnt seem to work as no truck is leaving the distributor. We have tried to change how we call the parameter but nothing seems to work. Maybe we arent trying the correct way.


Solution

  • what you need to do is the following

    1. this.vehicleLimit.equals("SR33") you use == only with primitives like double int and boolean you use .equals with objects to see if they have the same value

    2. add an else after your last else if and write the following

      error("none of the ifs was used");

    in general ALWAYS put an else after all the if else with an error to be sure your model is behaving as you expect

    1. check if truck value is null before each send

      if(truck==null) error("truck is null");

    2. check in your connections object, in the truck agent, if the message is really received.

    3. if all of the prevoius things don't work, you might be doing something wrong with your truck agent, which you decided not to show us.