Search code examples
simulationanylogic

AnyLogic agent based sorting algorithm with agent parameters


In my model I simulate the cutting of large metal plates into smaller ones. By using a split block, the agent (metal plate) is divided into several small plates. Each large metal plate has a parameter par_serialNumber. The serial number remains the same when it is cut. The large metal plate can be seen as one order.

Let's say the large metal plate is cut into 4 smaller pieces. After the split block, each of these 4 smaller plates goes through different processes and accordingly do not arrive at the end of the model at the same time.

However, at the end of the model, I want to know when the order (large metal plate) is finished processing. That is, the time when all 4 plates are finished being processed.

So I need a sorting algorithm that sorts incoming agents by the parameter agent.par_serialNumber, so that agents with the same parameter are freed at the end at the same time. This way it is possible to understand when an order is completed.

Here on SOW there are some approaches with wait block or pickup/dropoff with dummy agent, but I didn`t find the right code nor the right method for my problem.


Solution

  • Tons of different options. One way:

    Create a LinkedHashMap<Integer, Integer> partsFinished where the key is the part number (assuming it is an int) and the value is the number of sheets that finished from that part.

    In the split-block, you prepare a new entry: partsFinished.put(par_serialNumber, 0)

    When the cut sheets are done, they register it as well:

    int numFinishedAlready = partsFinished.get(par_serialNumber);
    partsFinished.put(par_serialNumber, numFinishedAlready +1); // one more finished
    

    Now, you should know how many parts belong to any part number so that:

    if (partsFinished.get(par_serialNumber) >= numRequired) {
        // free all agents with this serial number from your Wait block
    }
    

    So yes, a "Wait" block is a good idea after all :)