BAE23
BAE23

Reputation: 19

How to select trucks based on location in anylogic?

We are modelling a supply chain in AnyLogic. First Location is India, then the goods are shipped via ship to Germany.

Since the test version limits the agents numbers we have to use ONE agentpopuplation for all our trucks.

How can we chose, when placing an order, the trucks in the country/those nearby to avoid trucks are coming from the other side of the world to pick up the goods?

Cheers and thank you already!

Benj

Upvotes: 1

Views: 82

Answers (1)

Yashar Ahmadov
Yashar Ahmadov

Reputation: 1636

Depending on your model structure, Truck nearestTruck = this.getNearestAgent(main.Truck); will give you the closest truck.

If you are looking for the closest idle truck, you might use this structure:

This will give you the list of idle trucks. List idleTrucks = filter( trucks, t -> t.inState(Idle) );

This will give you the nearest idle truck.

List <Truck> truckList=sortAscending( trucks, h -> h.distanceTo(yourAgent) );
Truck nearestIdleTruck=truckList.get(0);

Upvotes: 1

Related Questions