Alex
Alex

Reputation: 49

AnyLogic: Fill a pallet rack on simulation startup with agents

For a simulation of a pallet rack system, I want to prefill that system with agents (for example so that a fill grade of 80% is given). After that prefill the boxes should be spawned by different source blocks.

I think in theory I could use the command palletrack.put(int row, int position, int level, boolean leftAisle, Agent agent) in the main method to add an agent by hand.

However, I need to add thousands of agents on startup, which would be tedious to do by hand (especially if I want to start from different fill grade situations).

The data for those agents is available in an Excel-File.

Is there a way to implement the Excel-File as the startup situation? In the Excel file, I have all attributes for the agents that are needed including the row, position, level, and depth of their storage place.

Thanks a lot in advance.

Upvotes: 2

Views: 711

Answers (1)

Jaco-Ben Vosloo
Jaco-Ben Vosloo

Reputation: 3930

You have 2 options

Option 1: Excel file

Simply link an Excel file in your model, using the object from the connectivity palette

Then you can initialize all the items using code similar to below

int excelRow = 2;
String sheetName = "Sheet1!";
String cellName =  sheetName + "A" + excelRow;
while (excelFile.cellExists( cellName )) {
    int row = (int)excelFile.getCellNumericValue( sheetName + "A" +  excelRow);
    int position = (int)excelFile.getCellNumericValue( sheetName + "B" +  excelRow);
    int level = (int)excelFile.getCellNumericValue( sheetName + "C" +  excelRow);
    boolean leftAisle = excelFile.getCellBooleanValue( sheetName + "D" +  excelRow);
    MyAgent agent = add_myAgent();
    
    rackSystem.put(row, position, level, leftAisle, agent);
    
    excelRow ++; // Increase the row that we will lookup in the Excel
}

Just a while loop where you go from one excel line to the next as long as the line exists, and then create an agent and place it in the rack as needed

In this example we assume the columns A to D contains the relevant position data for the agents in the rack

Edit: Most of the time you will need to have the agents enter the process flow so that you can move them again (typically via a RackPick block), which you can use an Enter block for - see example below

you can simply call enter.take(Agent agent)

enter image description here

NB [Stuart Rossiter edit]: You can think of the put function for pallet racks putting the agent into a spatial node within the spatial network that the pallet rack is part of. However, if the agents weren't within the spatial network beforehand, they don't get 'fully' added to the network, and you'll get an "Agent is not in a network" error when you try to pick it from the rack. (I suspect that what actually happens internally is that each cell in the rack has in-the-network coordinates associated with it, but the agent is not explicitly in the network until the moment you pick it. Whatever the internals, the point is that the agent has to be 'told' that it's in the spatial network at some point before it is picked.)

You can allow for this in a few ways:

(i) Add an explicit setNetwork call after your put; e.g.,

rackSystem.put(row, position, level, leftAisle, agent);
agent.setNetwork(network);

(where network is the spatial network which your pallet rack is part of).

(ii) Have your agents in a population where the Initial Location is set to some arbitrary node in the same spatial network (so when you put them in the pallet rack they will already be in the network)

(iii) Have the Enter block (see above) set their initial location as some arbitrary node in the spatial network. (Same idea as (ii) above.)

(iv) Switch to use the new Storage elements and Store/Retrieve blocks from the Material Handling library (added in AnyLogic 8.7.7). These don't have the network-setting issue as above and supercede the Process Modeling library elements (which will never now be updated). You use the store function instead of put to programmatically add an agent to a Storage element.

Option 2: AnyLogic Internal DB

Simply import your excel sheet to the AnyLogic DB and then loop over the entries in the table using a for loop

List<Tuple> rows = selectFrom(db_table).list();

for (Tuple row : rows) {
    traceln(
        row.get( db_table.db_column )
    );
}

Upvotes: 2

Related Questions