0

In anylogic, I have modelled trucks to go to multiple delivery locations. The trucks moves to the first location in the collection using the code

moveTo(order.orderLocation.getFirst());

After the truck went to the first location, the first agent is removed using the code:

  order.orderLocation.removeFirst();

The process iterates until the collection is empty (see figure).

I am trying to make the truck go to the nearest agent instead of just the first in the collection. However, I don't know what the code will be to remove the agent that it moved to. I also tried to sort the list based on the distance but didn't succeed. Does anyone know how to model this?

enter image description here

Yope
  • 43
  • 6

1 Answers1

0

First step, finding the closest destination, use this:

Order theorder= top(orders,x->distanceTo(x));

Second step... remove the agent from the population

order.orderLocation.remove(theorder);

you can also find its index

 int index=order.orderLocation.indexOf(theorder);
order.orderLocation.remove(index);

If you are more interested in sorting, i would need to know what orderLocation is to make a proper comparator to sort based on distance

Felipe
  • 8,311
  • 2
  • 15
  • 31
  • Thank you for your answer. I'm trying to implement it. I should have given more information on how I modelled it indeed. The variable order (stored in the truck) contains a collection "linkedlist". In this linked list several order locations are stored as type "Retailer". – Yope Aug 25 '21 at 14:24
  • unfortunately the x->distanceTo(x) function doesn't work. Is that due to the choice of collection? – Yope Aug 25 '21 at 14:47
  • well "it doesn't work" doesn't give me enough information... but you can look in the help documentation how to use this top function ... ir retailer is your element in the collection, i still don't know what Retailer is... so not much of a help... – Felipe Aug 25 '21 at 15:46
  • In my model, the retailers are agents placed on a GIS map containing some parameters. I'm sorry, I am not sure what's more to say about it. Hope this info. helps in understand my question. – Yope Aug 26 '21 at 11:09
  • well maybe you can do Retailer retailer=top(retailers,r->distanceTo(r)); instead then – Felipe Aug 26 '21 at 11:32
  • You're a hero. Thank you! – Yope Aug 26 '21 at 12:17