Phase 4. Modeling pallet delivery by trucks

In this part of our tutorial, we’ll add the trucks that deliver the pallets to the job shop. Let’s start by creating an agent type to represent them.

  1. On the Process Modeling Library palette, drag the Agent Type element onto the Main diagram.
  2. In the New agent wizard, do the following:
    1. In the Agent type name box, type Truck.
    2. Click Next.
    3. On the next page of the wizard, expand the Road Transport section in the list on the left, and then click the 3D animation figure Truck.
    4. Click Finish.

    Let’s add two more elements to our network: a node where the trucks will appear and the path that they will follow to the receiving dock.

  3. Open the Main diagram.
  4. Under the Space Markup palette, click the Point Node element and drag it on to the driveway entry.

  5. Name the node exitNode.
  6. Draw a Path to connect the exitNode to the receivingDock.

    Make sure all space markup elements connect to one network.

  7. Create another process flowchart to define the truck movement logic by connecting the Process Modeling Library blocks in the following order:

    Source MoveTo Delay MoveTo Sink.

  8. Name the Source block sourceDeliveryTrucks.
  9. In the sourceDeliveryTrucks block’s Properties area, do the following to have a new agent of the custom Truck type arrive to the driveway entry once per hour at a specific speed:
    1. In the Arrivals defined by list, click Interarrival time.
    2. In the Interarrival time box, type 1, and select hours from the list on the right.
    3. In the New agent list, click Truck.
    4. In the Location of arrival list, click Network/GIS node.
    5. In the Node list, click exitNode.
    6. In the Speed box, type 40, and select kilometers per hour from the list on the right.

  10. Name the first MoveTo block drivingToDock.
  11. In the drivingToDock block’s Properties area, in the Node list, click receivingDock to set the agent’s destination.

  12. Rename the Delay block to unloading.
  13. In the unloading block’s Properties area, do the following:
    1. In the Type area, click Until stopDelay() is called.
    2. In the Agent location list, click receivingDock.

    The operation’s duration depends on how quickly the pallets are unloaded and removed by forklift trucks. We’ll consider this operation complete when the RackStore block has finished storing pallets, and we’ll model this by changing the Delay block’s operating mode.

Programmatically controlling the delay time

You’ll typically specify a Delay time for the Delay block’s operation. It can be a fixed duration such as five minutes or a stochastic expression that produces a delay time such as triangular(1, 2, 6).

You can also programmatically control the operation’s duration and stop the delay when necessary by calling the block’s corresponding function. If you need to stop waiting for all agents that are in the Delay, call the block’s function stopDelayForAll(). Another function - stopDelay(agent) - ends the operation and releases the specified agent.

  1. Name the second MoveTo block drivingToExit.
  2. In the drivingToExit block's Properties area, in the Node list, click exitNode to set the destination node.

    Our model’s two Source blocks generate two agent types: the trucks that appear each hour and the pallet that is generated every five minutes. Since we want pallets to appear when the truck unloads, we’ll change the arrival mode for the Source block that generates them.

Controlling agent generation

You can have the Source block generate agents at set intervals by setting the block’s Arrivals defined by parameter to Calls of inject() function. You’ll be able to control the agent creation at runtime by calling the block’s function inject(int n).

This function generates the given number of agents at the time the call occurs. You set the number of agents that the block will generate by using a function argument such as sourcePallets.inject(12);.

  1. In the sourcePallets block's Properties area, in the Arrivals defined by list, click Calls of inject() function.

  2. Do the following to have the sourcePallets block generate pallets when a truck enters the unloading block:
    1. In the unloading block’s Properties area, expand the Actions section.
    2. In the On enter box, type the following:


      This Java function will ensure our model generates 16 pallets each time a truck starts to unload.

Now that we’ve added trucks to our model, let’s make the first delivery truck appear on the model startup so we don’t have to wait for an hour of model time to elapse.

  1. In the Main agent type’s Properties area, expand the Agent actions section and then type the following Java function in the On startup box:


Model startup code

The model’s Startup code executes at the model initialization's final stage after the model's blocks are constructed, connected, and initialized. This is a place for additional initialization and starting agent activities such as events.
  1. In the storeRawMaterial block’s Properties area, expand the Actions section, and in the On exit box, type the following:

    if( self.queueSize() == 0 )

    In this example, self is a shortcut we use to refer to the block storeRawMaterial from its own action.

    If there are no pallets in the storage queue, the unloading block’s delay time ends (in other words, stopDelayForAll() is called), and the truck leaves the unloading block and enters the next flowchart block, drivingToExit.

  2. Run the model.
  3. If the truck is aligned incorrectly as in the figure below, do the following to fix it.

    1. In the Projects tree, double-click the Truck agent type to open its diagram and view the truck animation figure.
    2. In the graphical editor, select the truck shape and then use the round handle or the Rotation Z,� property in the shape’s Position properties area to rotate the truck to -180 degrees.

    We’ve changed the truck figure’s position, but we’ll also need to change AnyLogic’s default setting to make sure the program doesn’t rotate it a second time.

  4. Do the following to change AnyLogic’s default setting:
    1. In the Projects area, click Truck.
    2. On the Truck agent type’s Properties area, click the arrow to expand the Dimensions and movement area.
    3. Clear the Rotate animation towards movement check box.

  5. Open the Main diagram.
  6. To ensure the pallets are correctly positioned in the receivingDock network node, open the Space Markup palette, and drag an Attractor into receivingDock. Let it face the entrance.

Attractors in nodes

Attractors allow us to control agent location inside a node.

Attractors also define the agent animation’s orientation while the agent waits inside the node. Here we use attractor for this particular purpose. You can add attractors by dragging them individually onto the Main diagram, but if attractors form a regular structure, you should use the special wizard to add several attractors at the same time. The wizard offers several different creation modes as well as the option to clear all attractors, and you can display it by clicking the Attractors button in a node’s Properties area.

  1. Run the model to check the truck behavior.

    The animation should work as we expect.

Reference model: Job Shop - Phase 4

Phase 3. Creating 3D animation

Phase 5. Modeling CNC machines