Search code examples
javaanylogic

How to make a transporter that releases an item and always take it back right after?


I am working on a model that works like that: there is a agent (uld) coming and brings 10 items. these items are then moved by a transporter (forklift) to a particular zone. In that zone (in theory), they drop the item, wait a few seconds, and take it back and place it in a storage zone.

Originally, I wanted the forklift to not drop the item, just go in the node, wait a bit and go to the final location. I couldn't figure out how to make it happen without releasing the item, so I let the release happen. Now, in most case, it works fine: the forklift drops the item, wait, takes it back and stores it. But sometimes, when too many uld are coming and drop too many items, it seems like the forklift goes straight for a new one instead of storing the item first.

Is there a way, either to make it like the items aren't released, or is there a way that the same forklift always retake its item?

here is the zone where the forklifts are supposed to drop and retake the item

here is the logic I used for the movement of the forklift to the zone

here is the moveby logic

here is the store logic


Solution

  • Originally, i wanted the forklift to not drop the item, just go in the node, wait a bit and go to the final location. I couldn't figure out how to make it happen without releasing the item

    You can do it if you have a MoveByTransporter1-Delay-MoveByTransporter2 flow, where you don't release the transporter in MoveByTransporter1 and don't seize one in MoveByTransporter2.

    But since you're using a Store block afterwards, which currently cannot work with already seized transporters, I suggest using the Link to agents. This way your forklift and item can stay connected even after release and they can "find eachother" again. For this example, let's call your agent types Uld and Forklift. (You need custom agent types to be able to use Links)

    1. Create a bidirectional single link between your Uld and Forklift agents. Name them myForklift and myItem.
    2. You want to seize a free forklift, which does not have a connected item. In your MoveByTransporter blocks, enable Customize transporter choice and write this condition into Transporter choice condition: ((Forklift)unit).myItem.isConnected()==false. To connect the item and forklift, put this line into On seize transporter of the same block: agent.myForklift.connectTo((Forklift)unit)
    3. To use the same forklift for storing the item, enable Customize transporter choice in your Store blocks too, and write the following code into Transporter choice condition: agent.myForklift.getConnectedAgent().equals(unit). Too free up the forklift after it finished the task, write this line into On release transporter of the Store block: ((Forklift)unit).myItem.disconnect()