Villager allocation is optimized when you have exactly enough vils to support your build order/gameplan.
I don’t know exactly how VP switching works, because I’m a PC player, but you want to minimize efficiency losses that come from moving productive vils to other resources.
To create a game theory optimal VP switching order, you’d have to take every action your opponent is performing into consideration.
Some of this information is available if your scouting is good.
The rest is guesswork, though you can make educated guesses based on the opponent’s civ, score, upgrades, and what they’ve shown you so far.
Newer players shouldn’t go straight to creating optimized anything, they should work on basic mechanics and understanding the way vil allocation affects their budget.
For example, if you have two archery ranges, how many vils does it cost to keep those ranges pumping full-time, and how should the vils be allocated?
You might think, “I’ll just do what the build order tells me,” but you have to start making your own decisions sooner than you think, and it’s good to have an economic understanding of your limited resources.