Next, there are trucks that deliver products from the distributor to retailers.
Let us create the whole fleet at once as a population.
In our model, all trucks initially reside at the distributor's location, where they wait for orders to be processed.
Run the model. The trucks will appear at the distributor's location.
You will see that the truck shapes are rather big.
To decrease the truck size, open the Vehicle agent diagram by double-clicking Vehicle in the Projects view, then zoom in the diagram and then decrease the size of the truck shape.
Now let us define the truck's movement logic. We will define it using a statechart. Statechart is one of the most powerful and easy-to-use AnyLogic tools that allows users to define the object's behavior as a sequence of states. For instance, for the equipment it could be Busy and Idle.
In our case the statechart will define the truck's movement logic. Since we are creating not a real complex supply chain, but just a simple toy model to show you the most important agent-based AnyLogic tools, the logic in this one will be significantly simpler than in real life.
The trucks in our model initially wait for orders at the distributor's location. Once the order is assigned, the truck moves to the retailer that placed this order. On reaching the retailer, the truck begins the unloading process, whereupon it moves back to the distributor to fulfil the next order (if any).
To relocate the transition's trigger icon, select the transition and drag the icon to a new place.
Right now we are creating a simple model where trucks will start their movement to a randomly chosen retailer. Transitions may be triggered by events of various types: on timeout expiry, with the specified occurrence rate, on agent arrival to the destination, etc. By default Timeout is the trigger type of any transition, that is why it has a clock icon: . We will change the transition's trigger type to Rate.
In the Action
edit box, write Java code as shown on the screenshot above: moveTo( main.retailers.random() );
This action will send the truck containing this statechart to a randomly selected retailer.
moveTo( ) is a function that initiates the agent movement. Using the function argument, we define the movement destination. You can make an agent move to another agent, a node, or even a geographic location. In our case we send the truck to a randomly selected retailer. In this model retailers are defined as the retailers agent population living in Main agent. Trucks are defined in the similar way - as vehicles agent population. As you understand, both populations live on the same level of the model hierarchy, which means that to access an agent of another population, we first access the upper-level agent of the Main agent type as main, and then we access its internal field by putting the dot: main.retailers. This way we get access to the retailers population. To get one randomly selected agent from the population, we use the population's function random(): main.retailers.random(). The semicolon at the end marks the end of the Java statement.
For this transition, type moveTo(main.distributor); in the Action field.
Having reached the retailer, the truck will change its state to MovingToDistributor, since this transition is set up to be triggered by agent arrival. The function called in the Action field of this transition initiates the truck to further move from the retailer to the distributor.
Reference model: Supply Chain GIS - Phase 3
Phase 2. Creating retailersPhase 4. Modeling product orders