0

I'm working on implementing a model in Python. As part of this model, I have a set of agents (e.g. humans) that need to visit a set of targets (e.g. places). Each agent has its own initial location (i.e. starting point) and I can calculate the distance from each agent to each target.

What I need at this point is to allocate a first job to each agent in a way that the sum of all travel distances for agents from their starting location to their first job is minimum.

I considered greedy algorithm, but I found examples that proves order of allocation can lead to non-optimal solutions. I also looked into nearest neighbour algorithm in TSP, but all I could find was for one agent (or salesman) not multiple.

Could someone point me to any (non-exhaustive search) algorithm/approach that could be used for this purpose please? Thanks

Alijy
  • 155
  • 1
  • 8
  • What is the relation between the agents and the target? Can multiple agents share the same targets? If so, can two agents be on the same target? Besides this, can you please define what you mean by "first job"? – Jérôme Richard Feb 06 '22 at 17:42
  • Please provide a minimum example with data, with (possible) solution that you want to scale to a full solution – Willem Hendriks Feb 06 '22 at 21:29
  • After your initial greedy round- you could check for each agent, if a simple swap could improve. That is; after initial (greedy) solution, check for each agent if it is connected to its nearest target, if not re-allocate and overtake, and re-allocate the agent that lost its target by take the closest free one. – Willem Hendriks Feb 07 '22 at 10:52
  • https://en.wikipedia.org/wiki/Maximum_weight_matching – Willem Hendriks Feb 07 '22 at 10:54

1 Answers1

1

If the number of agents = number of targets, we end up with a standard assignment problem. This can be solved in different ways:

  • as an LP (linear programming problem). Technically a MIP but variables are automatically integer-valued, so an LP solver suffices.
  • as a network problem
  • or using specialized algorithms.

If, say, the number of locations > number of agents, we still can use an LP/MIP:

 min sum((i,j), d(i,j)*x(i,j))
 sum(j, x(i,j)) = 1  for all agents i  (each agent should be assigned to exactly one location)
 sum(i, x(i,j)) <= 1  for all locations j (each location should be assigned to at most one agent)
 x(i,j) in {0,1} 

For the network approach, we would need to add some dummy nodes.

All these methods are quite fast (this is an easy model). To give you an indication: I solved a random example with 500 agents and 1000 locations as an LP and it took 0.3 seconds.

Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39