Dave
Dave

Reputation: 143

Visual Enhancement for Pick-Up & Drop-off Functions in AnyLogic

I'm trying to replicate a truck pickup and delivery demo. I know that I can use these functions to do the job, but the agents I pick up (that have their destination and other detail embedded) don't appear "on" the truck (assume an open flat-bed truck).

The pickup and drop-off function correctly retain the boxes' information, so that's all good.

Does anyone have any suggestions to show the boxes on the truck? I was thinking I could create dummy boxes within the truck agent as boxes get "loaded", but that doesn't seem like the best option.

This follows from a 5-year old post: Moving one agent within another agent in Anylogic

Ideally I'd like to be able to locate the box agents by local x-y coordinates.

Thanks for your help. Cheers.

Upvotes: 1

Views: 378

Answers (2)

Jaco-Ben Vosloo
Jaco-Ben Vosloo

Reputation: 3975

One option would be to simply have a collection of Type Box inside your truck agent and based on the number of boxes inside the collection either show or hide some boxes that you created on the truck animation

enter image description here

enter image description here

If you have a significant number of boxes you might not want to draw them all by hand and set the visible properties for each. Then you can use a single box, add it to a group, and then set the box as a replicated shape with custom x and Y coordinates. The coordinates will be with reference to the group we created.

enter image description here In this example, I have replicated the box shapes equal to the size of the collection. The coordinates of each box will be unique. The x coordinates use the remainder division index%10, thus it will be 0,1,2,3...9,0,1,2...9 etc thus we will have 10 columns of boxes on the truck. The y coordinates will use the integer division, (index/10), thus the value will be 0 for index 0->9 and then 1 for index 10->19 and so on. Thus if we have 50 boxes on the truck there will be 10 columns (as always) and 5 rows.

The 5 at the end of each formula is just so that each new coordinate for x and y is 5 pixels apart.

If you want to stack boxes on top of each other you might want to add another formula for the Z coordinate, e.g if for every 50 boxes you go to the next level your z coordinate will be (index/50)*5. You will then need to adjust your other formulas to start over again for each 50 boxes thus they need to change to

x = (index%50)%10*5

y = (index%50)/10*5

Using this approach you can get the x,y and z coordinates of the boxes, as per your question. Just note that it will be with reference to the group we created, so you need to add the x and y coordinates of the groups to the coordinates of the individual box in order to get the coordinates from the origin on the agent.

What is great about this approach is that you will keep a reference to the boxes inside the truck and you can enable some logic when a user clicks on a box or if you want to output some data. e.g.

enter image description here

You should not use a population of boxes inside the truck since calling add_MyBoxPopulation() will create a brand new box agents inside the agent and you rather want to keep the original box agent.

You can easily add and remove the boxes to the collection inside the action code of the pickup drop-off function

enter image description here

enter image description here

Upvotes: 1

Benjamin
Benjamin

Reputation: 12640

One suggestion: Literally "load" the box agent into the truck agent. Create an empty Box population within truck.

When it comes to loading, you remove your box agent from whereever it normally lives and add_MyBoxPopulation() inside the truck. This will add a presentation of the box agent at the 0,0 coordinates of the truck and it will drive around with it.

Might be overkill though. Having a simple box visible/hidden inside the truck is good enough if you just want to demo and animate

Upvotes: 0

Related Questions