Over-time the game automatically optimizes location if possible, however I've noticed that reassigning jobs can speed up this process if you find it necessary.
For example, when I notice I'm starting to make less food than I use I start looking at paths.
Occasionally I notice that my Gatherers have to walk long distances but my foresters live in the house right next to the forester lodge and gathering hut.
Resetting House Locations:
- Set all gatherers and foresters to laborers.
- Reassign the jobs in the order you want them to take first pick at housing.
So for my example above, reassign the gatherers before the foresters to have them take housing priority.
I've also noticed that builders quite commonly cause issues with this. Since their job moves they quite commonly are is just the worst locations possible, quite commonly taking a location that would be better suited to another job. I use this method to fix that as well.
This isn't a fix-all as the game does automatically do this over-time (as mentioned in Nicole's answer), however it has been quite helpful for me in speeding up the situations occasionally.