Facility Agent

Last updated on 22nd April 2024

Introduction

The toolkit exposes a new Facility agent class that you are free to extend. This class is the main agent class that can be used to represent all different kinds of facilities.

A sample model has been provided in the Supply Chain Toolkit Overview that gives a specific usage example for reference.

The Facility agent contains abstract functions in the super class that must be implemented in your extended class.

Facility class

When you create a new Facility agent you will need to implement the following methods.

 @Override
protected void processOutboundLoadingBay() {
    
}

@Override
protected void departTransport() {

}

@Override
protected void receiveInboundTransport(){
    
}

@Override
protected void processInboundLoadingBay(){

}

These methods provide the basic functionality required to handle the sending and receiving of TransportMessage messages carrying units / products between facility agents. They must be called from an Action and can be ignored if other mechanisms for departing transport are desired.

The receiveInboundTransport() method also has a function in the super class for receiving TransportMessage messages automatically.

@Override
protected void receiveInboundTransport(){
    super.receiveInboundTransport();
}

When calling departTransport(), you can add your custom logic for determining how you will depart trucks and by calling the receiveInboundTransport() function in the super class immediately afterwards in the run sequence, the TransportMessage messages will be placed in the LoadingBay.TransportQueue.

An example from the sample model use case can be found below:

public static Action<FacilityTypeA> departOutboundTransport =
            Action.create(FacilityTypeA.class, FacilityTypeA::departTransport);

Loading Bays

As many LoadingBay classes as desired can be added to your Facility classes. They can be either initialized during the setup() phase, it could be done during an firstStep() run sequence, or new ones could be added during the simulation.

More on the LoadingBay class can be found in the Loading Bay docs.

Multithreaded Processing

A common challenge when simulating supply chains with massive throughput is the simulation time required for dealing with processing and filtering through millions, even 100s of millions of units travelling through facilities.

One way to handle this and speed up these operations is by using ParallelStreams, ConcurrentList, and ConcurrentHashmap.

By using these structure it's possible to parallelize the operations across massive lists and maps while not running in to concurrent modification exceptions.

More information can be found in the java.util.Concurrent & java.util.Collection libraries linked below:

  1. Java Concurrent
  2. Java Parallel Streams