So create a PriorityQueue containing home-work associations, sorted on distance between them. Then draw the top item whenever you need to assign a worker to a home-work route.
The the question is are there any other factors which effect the decision to make one home more desireable than another for a worker or worker differentiation which makes some better than others for a particular factory. Thus complicating your 'fitting' calculations/decision.
Another is: is it a static situation or if dynamic which can change and what will your strategy will be for recalculation . Depends how complex you simulation is as to wheter the change itself has some cost so you then have to weight which corrections cost the least but still have adaquate benefits for production (ex- in the Nile game, housing grew/developed and progressed and when a worker moved they had to start over which was a big negative cost factor , likewise transportation paths (dependant on seperate map objects) could be shifted and a workers old path might be very different from a new current shortest path)
- The above system used minimum walking distance as the score criteria, but you can create a utility function that weights any number of additional factors any way you please and returns a single scalar score for use in the priorityqueue. But the business of arriving at a mathematically accurate weighting for additional factors is typically...Unrefined. Often resolved by ballpark guess followed by iterative buff/nerf adjustments. Is it necessarily a refinement process, or can it be calculated? Don't know, and it could be that this is an instance where the answer can only be achieved through executing a procedure, rather than calculating an answer.
- The represented situation was dynamic, with buildings being constructed and demolished, with people being hired and possibly fired or killed. If people are given the option to automatically move to closer distance housing as soon as that's available, then we have a re-evaluation taking place by each citizen after construction. This re-evaluation could take the form of summing up the total distance walked by all citizens, then running a simulation where everyone is kicked and re-housed, and comparing the proposed new total distance to the old total distance. If the new score meets some threshhold criteria, then relocation happens.