2

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.

Jaco-Ben Vosloo
  • 3,770
  • 2
  • 16
  • 33
Alex
  • 49
  • 4
  • You can easily load Excel data and loop across it to fill your pallet programmatically at the start. Check the help and example models, there is a ton of information how to load xls data and apply it. – Benjamin Aug 20 '21 at 10:55

1 Answers1

2

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 )
    );
}

Stuart Rossiter
  • 2,432
  • 1
  • 17
  • 20
Jaco-Ben Vosloo
  • 3,770
  • 2
  • 16
  • 33
  • Thanks a lot, it worked as intended. However, I have two more questions regarding the agents I created: - The agents are logically placed in the pallet rack as intended but they aren’t visually placed in the 3D-animation of the pallet rack. Is there a way to fix that? - When I want to pick one of the pallets, once the pallet reaches the RackPick block, I get an Error Message, that the agent is not in an network. How can I manually asses the network the agent should be placed in to each agent? – Alex Sep 07 '21 at 11:30
  • 1
    Thank you for the feedback @Alex. The 3D issue is not part of the original question so I will answer it here. In the RackSystem object check under the advanced section, there you can choose the option do `Draw stored agents:` and choose `At the default position`. For ensuring the agents enter the network after creating them programmatically please use the enter block as per my updated answer (FMI - what did you do previously to get the agents we created back into the flow chart?) – Jaco-Ben Vosloo Sep 08 '21 at 06:11
  • Thanks a lot again. I tried both suggestions you made earlier already, however, I made small mistakes, which led to the program not working. But after careful inspection and your help I got it running correctly. To answer your question: Up until now I ran the model without the startup creation of the agents. I created them in the source block and delayed the "useful" part of my experiment until the last one of the boxes had been placed. However, the startup trick reduces the simulation time to get useful results, so I will definitely stick to that. So thanks again for your kind and fast help. – Alex Sep 09 '21 at 07:25
  • @Jaco-BenVosloo This is the right solution but it doesn't work due to some quirks of how pallet racks behave when you explicitly add agents via `put`. Although `put` effectively makes them live in a (hidden) node within the space markup of the pallet rack (that is in the spatial network), the agent is not actually *in* the network in another respect so you have to explicitly call `setNetwork` on the agent to add it to the network that the pallet rack is part of. The Enter block is needed to add them into the *process* (so they are pickable as you say) but doesn't solve the network part. – Stuart Rossiter Sep 23 '21 at 13:32
  • None of that is documented in the AL help and I'd call it a bug since `put` on the rack does seem to be the canonical/only way you can add agents to racks at startup AFAIK. I don't know how the OP got it to work without that... (Did you test it yourself with the Enter block?) I can suggest an edit if you like.... – Stuart Rossiter Sep 23 '21 at 13:36
  • @StuartRossiter be my guest! Thank you for the review. Yes, I did test it with the enter block and got it to work. Hence my edit to the question – Jaco-Ben Vosloo Sep 24 '21 at 14:56
  • I suspect you only tested the *loading* without trying to pick the agents later. You'll *always* get an "Agent is not in a network" errors (as the OP did, though they claim to have since got it working) without this 'internal' setting of the network. Note that example models which do this initial loading (e.g., Distribution Center) just cheat and use a RackStore with a ridiculous agent speed so it happens 'instantaneously', which is a non-purist way of doing it. I'll add all those details as a suggested edit when I have a minute.... I'll also report the behaviour to AL since it's a bug IMO. – Stuart Rossiter Sep 27 '21 at 16:22
  • @StuartRossiter I tested my mini model as per my screenshot again and the model worked 100% as expected... After the random delay I put in the agent exited the rack through the rackPick object I used, was further delayed and then exited the model using the sink object... please advise – Jaco-Ben Vosloo Oct 04 '21 at 12:35
  • 1
    OK made a suggested edit which hopefully explains it. (I know I could add a separate answer or even edit the answer to be a community wiki, but better IMO if we agree to have a single edited answer given the nature of the edit. (I put my name in the edit for 'traceability'.) – Stuart Rossiter Oct 13 '21 at 18:05
  • I accepted your edits, thank you! – Jaco-Ben Vosloo Oct 14 '21 at 07:15
  • Added another small bit now that AL 8.7.7 is out. (Storage elements don't have the network-setting issue and Pallet Racks are now deprecated.) – Stuart Rossiter Oct 15 '21 at 15:51