Question re: new commerce cities

^ I think of it like this,

(T_c - T_f) * N > T_f

where T_c is the number of turns having the free population working all cottages, and T_f is working one farm, and N is the number of population you have left to grow.

This simplifies to just N > f, where f is simply your 'fixed' food surplus, i.e. the surplus before you add any farms.

To figure out if we want to change additional cottages to farms, our food surplus increases by one (since we have the previous farm) and N also increases by one, because we gain by switching the previous farm to a cottage too.

So if it is right to work a farm instead of cottage for the first tile, it is right for all other tiles, and likewise for cottages to farms.

So there is a fixed population above which you want cottages and below which you want farms. This is given by the extremely simple formula N = f. (which generalizes simply when we are trading other than 1 food for 1 cottage-turn)
 
In every (roughly homogeneous) situation I've ever analyzed, it's always best to grow as soon as possible until you hit a magic population number where you can leisurely switch from farms to what you really want, and then once you grow again, you stop working extra farms.


I've found the easiest analysis is in terms of a single population point, Each turn you spend at this population is one turn you are not at your maximum population. Assuming fractional numbers of turns, what you do at this population point is completely independent from what you do with future population points.

So, you simply look at different ways to assign your tiles, and take the one that yields the least "loss". (I've also found this to be an effective way of figuring out during game time when to work farms and when to switch to hills, etc. I simply look at each way to arrange my citizens and compute the loss)


. Here is sample analysis: (assuming we always work the rice until we're full size)

Let N be the current population.
Let F be the number of farms worked, including the rice.

Food to grow: 10 + N (Normal speed with granary)
Food surplus: 5 + (F - 1) (rice = 5, each additional farm adds 1 more)
Cottage turns per turn: N - F
Cottage turns per turn at max size: 15
Cottage turns "lost" per turn: 15 - (N - F)
Turns to grow: (10 + N) / (4 + F)
Total loss: L = (15 - N + F) (10 + N) / (4 + F)

Simplifying, L = (10 + N) (1 + (11 - N) / (4 + F))

Observe:
If N < 11, then increasing F means decreasing loss.
If N = 11, then F is irrelevant
If N > 11, then decreasing F means decreasing loss.

In other words, work all farms below 11 pop, and work all cottages above 11 pop. (Still assuming we keep the rice until we're size 15)


Notice this agrees with Artichoker's analysis. And you may be able to do slightly better if you find a clever scheme to deal with overflow when the city actually grows.
 
can you post your save so we can replicate your results?

No such thing, I just created the map in worldbuilder... but didnt save and/or play it...

I used my spreadsheet that I am trying to build, which should help in situations like this.
 
On a 200 turn timescale (on Epic) as long as you reach size 15 buy 200 - 15 (Cottage) - 30 (Hamlett) - 45 (Village) => 200 - 90 = 110 basicaly any turn you spend working a farm is a turn lost on working a Town.

I think any formula beeing "developed" should take that into account (not that math savy myself, more of a do it kind of guy)

Presumptions
- 8 workers are available on turn 0 (founding of the city) to farm the rice
- Whip the granary ASAP at size 4
- Whip the Library as soon as a 2 pop whip is allowed
- 15 pop max
- Work the rice untill size 15 is reached, then switch to a non-riverside cottage, keeping the rice farm in tact for future growth/whips

The city


The results:
attachment.php


The graps shows everything from working only the Rice farm and cottages (107 - 000, meaning 107 turns working the Rice farm while working 0 turns on additional farms) to working all farms to size 15, thens switching to all cottages (060 - 280).

A farm turn is 1 turn working 1 farm
So at size 4 working Rice + 3 farms, makes for 1 Rice turn, but 3 Farm turns.

There are 3 seperate "bests" for the 3 categories.
Gold
098 - 060
98 turns on the Rice
60 turns other farms
1063 Gold
6777 Beakers
7840 Beakers + Gold

Beakers
092 - 092
87 turns working the Rice
120 turns working additional farms
1032 Gold
6827 Beakers
7860 Beakers + Gold

Beakers + Gold
092 - 092
92 turns working the Rice
92 turns working additional farms
1051 Gold
6824 Beakers
7876 Beakers + Gold

It also shows that 80% of all solutions with or without farms fall within 95% of optimum for Beakers + gold. Which means even if you do it not perfect but, somewhat close to it.... you might lose 52 gold and 341 beakers. Which is not to catastrophic but, can be the reason why you get a (important?) tech one turn earlier than you would otherwize.

I will edit this later to add in what exactly those numbers mean in actual turns/growth etc.
 

Attachments

  • BeakerAndGoldMax.jpg
    BeakerAndGoldMax.jpg
    76.6 KB · Views: 482
:crazyeye:

Crikey - nice work fellas! :thumbsup:

So... in summary... we farm like crazy, whipping granary and library and then cottage over everything at about size 10? :confused:
 
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 don’t 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 didn’t 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 doesn’t 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
 
s + 1 special).
-Size 12-14: 10 farms / 1 special / rest cottages.
-Size 15: all cottages (including special!).

This is wrong -- it is suboptimal by 18.667 cottage turns on normal speed, assuming we always work the rice. The optimal strategy works all cottages at sizes 12-14, and all farms under 11. (What mix you use at 11 doesn't matter)

In particular,
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 quote is incorrect.


By your scheme:
@ size 12:
Food surplus = 15
Food to grow = 22
Cottage turns per turn = 1
Turns spent: 1.467
Cottage turns produced = 1.467

@ size 13:
Food surplus = 15
Food to grow = 23
Cottage turns per turn = 2
Turns spent: 1.533
Cottage turns produced = 3.066

@ size 14:
Food surplus = 15
Food to grow = 24
Cottage turns per turn = 3
Turns spent: 1.600
Cottage turns produced = 4.800

Net result: 4.6 turns to grow, producing 9.333 cottage turns in the process.


The optimal scheme performs as follows:

@ size 12:
Food surplus = 5
Food to grow = 22
Cottage turns per turn = 11
Turns spent: 4.400
Cottage turns produced = 48.4

@ size 13:
Food surplus = 5
Food to grow = 23
Cottage turns per turn = 12
Turns spent: 4.600
Cottage turns produced = 55.2

@ size 14:
Food surplus = 5
Food to grow = 24
Cottage turns per turn = 13
Turns spent: 4.800
Cottage turns produced = 62.4

Net result: 13.8 turns, producing 166 cottage turns.

Your scheme, after 13.8 turns, produces
9.333 + 15 * (13.8 - 4.6) = 147.333 cottage turns.


Let's look at how much each strategy is 'losing' per turn by not being at full size:

Yours: @ 12, you lose 14 cottage turns per turn (you're making 1, but we make 15 at full size), over 1.467 turns, and so forth. The net loss is
14 * 1.467 + 13 * 1.533 + 12 * 1.600 = 59.667

Best:
4 * 4.4 + 3 * 4.6 + 2 * 4.8 = 41

So we see again that your method underperforms the optimal one by 18.667 cottage turns.
 
Once upon a time I tried to write a program that would calculate the efficient frontier of sets of tiles for a given city to work at any pop. If anyone would like to help me with the maths (definitely not my strong point), Id love to go back and rewrite the code in Python or C++. The original was Ruby, and I was pushing the limits of an unusual coding technique as much as I was trying to solve the problem. Perhaps more inputs can be given, such as happy/health limits. It should be possible to work out the best target size for a city if you can find a reasonable present value calculation.

Edit: I did manage to get to a point where I could display a three-dimensional (gold/hammers/food) surface potential for each pop size, but it was very inefficient for large populations.

Optimal behavior at size 14 didn&#8217;t depend on when you got to size 14. You follow the same optimal policy no matter when you get there.

This was one of my key assumptions. Technically, however, its actually incorrect. History does matter because of overflow. Im happy to ignore it, however.
 
See Post #73 for my correction of Gr8Scott's original formula.

In summary, it agrees with MyOtherName's alternate method of calculation.
 
See Post #73 for my correction of Gr8Scott's original formula.

In summary, it agrees with MyOtherName's alternate method of calculation.

Your correction isn't quite correct. The cottage turns lost in the short term by adopting a farm rather than cottage is the number of turns to grow with that farm. I don't know why you decided to change this.

The reason the form of your answer looks more correct than gr8scott's original one is because you do account for the farms you are currently working in counting the cottages you have remaining to work.

Really, gr8scott had it nearly right at first but he forgot about these farms. If you account for these the math is very simple. I pointed this out a while ago but there has been a lot of clutter in this thread (not a bad thing, some interesting ways to look at this).
 
Your correction isn't quite correct. The cottage turns lost in the short term by adopting a farm rather than cottage is the number of turns to grow with that farm. I don't know why you decided to change this.

The reason the form of your answer looks more correct than gr8scott's original one is because you do account for the farms you are currently working in counting the cottages you have remaining to work.

Really, gr8scott had it nearly right at first but he forgot about these farms. If you account for these the math is very simple. I pointed this out a while ago but there has been a lot of clutter in this thread (not a bad thing, some interesting ways to look at this).

(T_c - T_f) * c > T_c


Let me explain why I used T_c instead of T_f:

The quantity on either side represents the number of cottages turns gained in T_c turns in comparison to building nothing for that city's new 1 pop count.

In the case of building a new cottage, it's a flat amount applied over T_c turns. With 1 extra cottage, that results in T_c cottage turns.

For the left side, which represents building a new farm, it's a bit more complicated:

After T_f turns, there is no benefit from building a Farm. However, there still remain T_c - T_f turns for that time frame. In the remaining T_c - T_f turns, the city has reached a pop count that is 1 higher.

In the case of building 1 extra Farm, we haven't assumed how many cottages the city will have after gaining the 1 extra pop. But, we do know that after T_c - T_f turns, the city gets a head start in terms of city growth.

We know that for the remaining c cottages that need to be built and worked,
the city will need to reach a certain size to work each cottage. Whatever that city size is for each cottage, the extra growth provided by the farm for that 1 extra pop will speed up the time when those remaining cottages are built and worked. So, the amount of extra time is (T_c - T_f), and it is multiplied by the number of remaining cottages, c.
 
In every (roughly homogeneous) situation I've ever analyzed, it's always best to grow as soon as possible until you hit a magic population number where you can leisurely switch from farms to what you really want, and then once you grow again, you stop working extra farms.


I've found the easiest analysis is in terms of a single population point, Each turn you spend at this population is one turn you are not at your maximum population. Assuming fractional numbers of turns, what you do at this population point is completely independent from what you do with future population points.

So, you simply look at different ways to assign your tiles, and take the one that yields the least "loss". (I've also found this to be an effective way of figuring out during game time when to work farms and when to switch to hills, etc. I simply look at each way to arrange my citizens and compute the loss)


. Here is sample analysis: (assuming we always work the rice until we're full size)

Let N be the current population.
Let F be the number of farms worked.

Food to grow: 10 + N (Normal speed with granary)
Food surplus: 5 + (F - 1) (rice = 5, each additional farm adds 1 more)
Cottage turns per turn: N - (F + 1)
Cottage turns per turn at max size: 15
Cottage turns "lost" per turn: 15 - (N - F - 1) = 16 - N + F
Turns to grow: (10 + N) / (4 + F)
Total loss: L = (16 - N + F) (10 + N) / (4 + F)

Simplifying, L = (10 + N) (1 + (12 - N) / (4 + F))

Observe:
If N < 12, then increasing F means decreasing loss.
If N = 12, then F is irrelevant
If N < 12, then decreasing F means decreasing loss.

In other words, work all farms below 12 pop, and work all cottages above 12 pop. (Still assuming we keep the rice until we're size 15)


Notice this agrees with Artichoker's analysis. And you may be able to do slightly better if you find a clever scheme to deal with overflow when the city actually grows.


Yes, it seems to agree...

But, according to your math,

Food surplus: 5 + (F - 1) (rice = 5, each additional farm adds 1 more)

Isn't Food Surplus 5 + F, for Rice, assuming an irrigated Rice?

Because each Grassland tile is food-neutral, and the city tile provides another 2 Food.

Each grassland farm provides 3 Food, which results in 1 surplus food.
The Rice tile itself provides 5-2=3 surplus food, but the city tile brings that back to 5.

So the amount of surplus food would be (5+F) instead of (4+F).

This might explain why your answer has N=12 instead of N=11 as the pop count to switch from Farms to Cottages.
 
The quantity on either side represents the number of cottages turns gained in T_c turns in comparison to building nothing for that city's new 1 pop count.

Taking Tf on the right in that inequality represents the cottage-turns lost at this population level by choosing a farm over a cottage. You are talking about the cottage turns gained in Tc turns, but that is not a good way to look at it since by choosing a farm we grow before then. If you think in these terms then the left side of your inequality is incorrect.
 
I believe that the assumption is that F includes the rice farm....
I wound up double-counting the rice farm. What you said was correct, and what I intended to do in my analysis. But then I brilliantly decided to subtract 1 for the rice farm again when I was computing the number of cottages. :(

I've corrected my original post.
 
I believe that the assumption is that F includes the rice farm....

Here are two lines from the original calculations:

Food surplus: 5 + (F - 1) (rice = 5, each additional farm adds 1 more)
Cottage turns per turn: N - (F + 1)

If it were taken that way (that F includes the Rice Farm), then the cottage turns per turn should be N - F instead of N - (F + 1). At least that's how I see it.
 
I wound up double-counting the rice farm. What you said was correct, and what I intended to do in my analysis. But then I brilliantly decided to subtract 1 for the rice farm again when I was computing the number of cottages. :(

I've corrected my original post.


Not trying to be picky or anything, but just trying to prevent disagreement...
 
Taking Tf on the right in that inequality represents the cottage-turns lost at this population level by choosing a farm over a cottage. You are talking about the cottage turns gained in Tc turns, but that is not a good way to look at it since by choosing a farm we grow before then. If you think in these terms then the left side of your inequality is incorrect.


OK, for the sake of keeping it simple, I'll answer you with a concrete example.

Here was the formula:

(T_c - T_f) * c > T_c

So, the concrete example is that the current city size is 14, and it's about to grow to 15, which is the maximum, at which point we will go with 15 cottages.

We already know that at pop 15, our goal is to be working 15 cottages.

But what if, for some reason, we decided to delay building cottages all the way up to pop 14?

In that case, let's assume a time frame of T_c turns for both sides.

Also, let's break up the timeline into 4 parts:

1) t < 0

2) 0 <= t < T_f

3) T_f <= t < T_c

4) T_c <= t

Now, let's compare two cases:

A) build 1 new cottage

From t=0 to t=T_c, the city accumulates 1 * T_c = T_c cottage turns. After T_c, the city grows to size 15 and works 15 cottages, which accumulate 15 cottage turns per turn.


B) build 1 new farm


From t=0 to t=T_f, the city accumulates 0 cottage turns. After T_f, the city grows to size 15 and works 15 cottages. Therefore, from t=T_f to t=T_c, the city accumulates 15 * (T_c - T_f) cottage turns. After T_c, the city is still at size 15 and works 15 cottages, which accumulate 15 cottage turns per turn.

Now, let's compare the cottage turns in each time frame:

1) t < 0
case A), 0
case B), 0

2) 0 <= t < T_f
case A), T_f
case B), 0

3) T_f <= t < T_c
case A), T_c - T_f
case B), 15 * (T_c - T_f)

4) T_c <= t
case A), 15 * (t - T_c)
case B), 15 * (t - T_c)

So, for time frame 1) and time frame 4), both A) and B) accumulate the same number of cottage turns.

For time frame 2) and time frame 3), case A) accumulates T_f + (T_c - T_f), or T_c cottage turns.

And case B) accumulates 15 * (T_c - T_f) cottage turns.

So, this example is consistent with the formula:

(T_c - T_f) * c > T_c

If the right-hand side is changed to T_f instead, it would be incorrect because it doesn't account for the cottage turns accumulated by A) in time frame 3).
 
So, the concrete example is that the current city size is 14, and it's about to grow to 15, which is the maximum, at which point we will go with 15 cottages.

We already know that at pop 15, our goal is to be working 15 cottages.

But what if, for some reason, we decided to delay building cottages all the way up to pop 14?

13 of those 15 cottage have nothing to do with our decision between a farm and a cottage at pop 14. The only thing that is preventing me from running 15 cottages right now is that I am at pop 14.

I'll also look at a time frame of Tc turns, so I get my point across.

From 0 to Tf the farm option gets no cottage turns beyond those 13, the cottage option gets Tf turns.

From Tf to Tc the cottage option gets (Tc - Tf) turns. The farm option gets 2(Tc - Tf).

So farm is better if 1*(Tc - Tf) > Tf, where 1 is the potential cottages we have left to add.

Which was a formula posted here a few days ago, the mistake came from when there was more than 1 tile in question. The answer is to farm all free tiles when your cottages remaining is greater than your fixed surplus, avoid overflow when it's equal, and have all cottages when it is less.

Truthfully I'm surprised there have been so many posts here.
 
Back
Top Bottom