I recall a game named Children oif the Nile (an ancient egyptian game) which had a severe problem (and lack of a competant designer/programmer aparently ) where the workers were generated by placing houses on the map which attracted immigrants which then sought available work -- you also placed various workplaces (effectively factories) on the map to provide those jobs. Unfortunately the workers got locked into whatever job the first assigned themselves to and would waste huge amounts of time crossing the map (some taking all day and then walking home without doing much of a work period) when similar work positions were nearby. New housing placed adjacent to the factory went unused or attracted workers which also often went across the whole map to work. There were even administrative functionals who should have had the job to organize/straighten things out but they were just as logic-less.
When calculating where a worker should live, we start with a list of possible homes and another list of possible employers. Then we want to select the pairing of available home-work that has the shortest walking distance.
Each candidate house has a full set of the possible workplaces to travel to. So the total number of distances to consider is numHouses * numWorkplaces. For example, if the map currently has 4 home vacancies, and 3 factories that can employ people, then there are a total of 4 * 3 = 12 possible routes.
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.