Go away for a couple days and all hell breaks loose!
So I skimmed the responses, and this one got me thinking:
But that farm is one more potential cottage tile that you want to switch over earlier.
You'll find you slightly undervalued farms, and (at least for grassland farms/cottages) the shift from farms to cottages happens suddenly, it isn't gradual.
When I worked out the original formula, I assumed that the future farm/cottage split was 100% cottages. This assumption seems fine for valuing cottages, but is generally suboptimal for valuing farms. Thus, relative to my original formula, assuming optimal future behavior could result in wanting more farms.
Thinking a bit more about this problem, I realize it is really a dynamic optimization problem. For these types of problems, it is usually a robust solution strategy to start at the end of the problem and work your way backwards towards the beginning. It turns out you can make some progress taking this approach with this problem.
If you are not interested in the math/intuition feel free to
*skip ahead to the answer*, otherwise, read on!
Let me start by listing what I see as the key assumptions for this problem.
(1) Fractional turns are allowed.
(2) Game length: sufficient turns remain to grow to max size with cottages only and still have time for all cottages to turn to towns
(3) Value function assumption: The thing that is optimized is the total commerce created over the entire game. This coupled with (2) mean we can look only at cottage-turns.
(4) building/multipliers: buildings/multipliers are unchanged throughout the problem
(5) we have access to infinite workers, or equivalently, we can instantly change between farms/cottages without cost.
(6) Finally, a note to self that I am not going to tell the system that working a cottage and then farming over it is a very bad idea. We will need to check our solution to make sure this does not happen. If it does we need to rethink the whole thing to impose this constraint.
(1) just allows me to not deal with surpluses, etc. (2) and (3) mean I can just focus on cottage-turns because all cottages have time to become towns. (4) eliminates all of the slavery/library type considerations. (5) means we dont have to consider costs associated with changing improvements and (6) is a reminder to check the solution.
Now to backward solve this problem, we need to start at the end. Suppose we focus on the problem described by OP and we want to end with a size 15 city working 15 cottages.
Suppose we arrive at our optimal size (15) and we have N turns left to go in the game. We know at this point it is optimal to have 15 cottages. So the value function associated with arriving at size 15 with N turns left is (recall the value function is just cottage turns)
V_15 = 15*N
Now, suppose we just arrived at size 14 and would like to know our optimal cottage/farm mix. The key question to answer is
How valuable is it to grow to size 15 one turn earlier?
If we get to size 15 one turn earlier, it means we get to work all 15 cottages an extra turn. In other words we get 15 cottage-turns by growing one turn faster.
The cost of growing faster is that our farms are not producing any cottage-turns for us. To figure out what to do at size 14 we need to check all the possible combinations of farms/cottages and figure out which gives us the most cottage turns over the rest of the game.
If we let
V_14_15(i) = cottage turns created while growing from size 14 to size 15 assuming i farms
and
V_15(i) = cottage turns spent at size 15 assuming i farms at size 14
then we just need to pick the number of farms that maximizes:
V_14_15(i) + V_15(i)
In words, we keep adding farms until the loss in cottage-turns growing between size 14 and size 15 exceeds the gain in cottage-turns from arriving at size 15 earlier.
If the terminal number of cottages is 15, then we want to keep adding farms until our surplus food is 15. At this point, another farm is too costly relative to the additional growth (this uses essentially the same logic from the earlier discussion)
Now that we know what to do at size 14, we can attack the problem at size 13. This is where it gets cool! How beneficial is it to grow to size 14 one turn faster? It turns out reaching size 14 one turn earlier improves the total value function by
15 cottage turns!
Optimal behavior at size 14 didnt depend on when you got to size 14. You follow the same optimal policy no matter when you get there. That means that getting to size 14 one turn earlier results in getting to size 15 one turn earlier which results in 15 cottage turns.
No matter when you look at the problem, speeding up growth by 1 turn results in 15 cottage turns of improvement! How valuable is it to get to size 7 one turn earlier? Well you are going to follow the same optimal strategy from size 7 to size 15, so you will end up at size 15 one turn earlier resulting in 15 extra cottage turns. How sweet is that!
This implies that the optimal policy doesnt vary with city size. You always want to add farms if your food surplus is less than the ending number of cottages!
<checking this answer with assumption (6) above, and we are OK. The total number of cottages is always non-decreasing
whew!>
The intuition turned out to be right. The original approach did under value some farms. Given optimal future behavior, we want to add farms until surplus food = target # of cottages.
*Skip to the answer*
Pre-biology, you want to be working farms until:
Surplus food = ending number of cottages
Post-biology, you want to be working farms until:
Surplus food = 2 * (ending number of cottages)
Example #1: OP problem
Target number of cottages: 15
Terrain: All grassland except one food special (5 food surplus at size 1)
Solution:
-Size <12: all farms (10 farms + 1 special).
-Size 12-14: 10 farms / 1 special / rest cottages.
-Size 15: all cottages (including special!).
Example #2:
Target number of cottages: 15
Terrain: irrigated corn, 3 floodplains (9 surplus at size 4 and above)
Solution:
-Size <7: All farms
-Size 7 14: 6 farms / rest cottages (15 surplus at all sizes).
-Size 15: all cottages
Looking at some of the latter posts, it seems like people are coming up with similar answers. That's good. Hopefully we are all right
GS