Introduction
So, after reading another SC2 math thread, I - being very bored - decided to pursue a problem that's been troubling me for quite awhile:
How many gatherers do I need to have to constantly produce some unit u out of X amount of buildings?
Spreadsheet: http://www.mediafire.com/?lugm36un2m0n2ij
Web App (not by me, but awesome nonetheless): http://haploid.nl/sc2/unit_production/
+ Show Spoiler +
This has been on my mind a lot, especially as a Zerg player. I mean, how many times have you Zergs out there made too many drones and found your money sky rocketing past what you can spend? Or maybe vice-versa where you are trying to support a build which is too expensive. As a math major, it is my duty to provide the world with all kinds of crazy shit like this. Hopefully nobody's already done this (if so then the experience was worth the while anyways!). I hope this post will lead to some very interesting analysis of SC2!
P.S. I wouldn't mind if someone made a spreadsheet of all the units in-game vs. the number of production buildings which had cells containing the number of workers needed for minerals/gas. I'm too burnt out to figure out how to do one myself!
Special thanks to Texas Instruments for making ballin' calculators and to Columbus for giving me a three-day weekend.
Also, for corrections, questions, or other comments, I can be reached at trebyoyoyoyo.236 on North American servers.
Enjoy!
EDIT: A cool program which someone just referred me to. Definitely recommend people check it out. Good to see our results match!
http://haploid.nl/sc2/unit_production/
http://www.teamliquid.net/forum/viewmessage.php?topic_id=155279
I hope I didn't fuck up the bolded, simplified versions. Sorry if I did!
P.S. I wouldn't mind if someone made a spreadsheet of all the units in-game vs. the number of production buildings which had cells containing the number of workers needed for minerals/gas. I'm too burnt out to figure out how to do one myself!
Special thanks to Texas Instruments for making ballin' calculators and to Columbus for giving me a three-day weekend.
Also, for corrections, questions, or other comments, I can be reached at trebyoyoyoyo.236 on North American servers.
Enjoy!
EDIT: A cool program which someone just referred me to. Definitely recommend people check it out. Good to see our results match!
http://haploid.nl/sc2/unit_production/
http://www.teamliquid.net/forum/viewmessage.php?topic_id=155279
I hope I didn't fuck up the bolded, simplified versions. Sorry if I did!
------------------------------
Overview
(note that F(x) does not imply F is a function of x is my notation; these are substitutes for subscripts, e.g. F(x) could be food supplied by x):
The following are equations for each of the races which will output the approximate number of workers required to sustain constant production of some unit out of a number of buildings. An explanation of my methods and a list of the assumptions I made are also listed below. Examples of tests I performed are given as well.
USES:
+ Show Spoiler +
Massing one unit of of some amount of bases, this will tell you how many workers on mins/gas you should have. This accounts for supply units and automatically calculates their cost in the total cost.
You can create unit compositions with this as well. Say I wanted an army of 40% Roaches and 60% Hydras. Then, for minerals (and similarly for gas), I would do this:
Total gatherers on minerals = 0.4(Gatherers to mass Roaches) + 0.6(Gatherers to mass Hydras)
One interesting find: Carriers (without Interceptor costs) are cheaper to mass than Void Rays, Phoenix, or Collosus!
You can create unit compositions with this as well. Say I wanted an army of 40% Roaches and 60% Hydras. Then, for minerals (and similarly for gas), I would do this:
Total gatherers on minerals = 0.4(Gatherers to mass Roaches) + 0.6(Gatherers to mass Hydras)
One interesting find: Carriers (without Interceptor costs) are cheaper to mass than Void Rays, Phoenix, or Collosus!
Spreadsheet: http://www.mediafire.com/?ihdinkzl8192c4f
Considering saturation:
+ Show Spoiler +
Using strictly Liquipedia data:
2 or less mining a patch = negligible saturation rates
drone mining w/o sat = .7 per sec
drone mining w/ sat = 102/(60 * 3) = .567 minerals per sec
(.7 - .567) / .7 = ~19% loss
Each saturated drone (must consider all 3 in each patch) is mines at 4/5 the rate of an unsaturated drone
In other words, we should add 1 unsaturated drone for every 5 saturated drones. Calculate the number of drones on the spreadsheet and then compensate for however many of those drones are on saturated mineral patches. Understand that this means if I have 2 saturated patches, that means I have 6 drones on saturated drones. I'm defining saturated patches to be patches with 3 workers on them; a patch with 2 drones mines practically as well as 2 patches with 1 drone. In general, if you have 24 on minerals / base, then you want 5 extra drones on unsaturated veins.
Check
Assume 5 patches (15 workers). We assume that we should add 3 additional workers. This should give us the same result as 15 workers on unsaturated minerals.
5 * 1.7 + 3 * .7 should equal 15 * .7
5 * 1.7 + 3 * .7 = 10.6 minerals per sec
15 * .7 = 10.5 minerals per sec
Note: 3 typically on gas mines with negligible saturation rates.
2 or less mining a patch = negligible saturation rates
drone mining w/o sat = .7 per sec
drone mining w/ sat = 102/(60 * 3) = .567 minerals per sec
(.7 - .567) / .7 = ~19% loss
Each saturated drone (must consider all 3 in each patch) is mines at 4/5 the rate of an unsaturated drone
In other words, we should add 1 unsaturated drone for every 5 saturated drones. Calculate the number of drones on the spreadsheet and then compensate for however many of those drones are on saturated mineral patches. Understand that this means if I have 2 saturated patches, that means I have 6 drones on saturated drones. I'm defining saturated patches to be patches with 3 workers on them; a patch with 2 drones mines practically as well as 2 patches with 1 drone. In general, if you have 24 on minerals / base, then you want 5 extra drones on unsaturated veins.
Check
Assume 5 patches (15 workers). We assume that we should add 3 additional workers. This should give us the same result as 15 workers on unsaturated minerals.
5 * 1.7 + 3 * .7 should equal 15 * .7
5 * 1.7 + 3 * .7 = 10.6 minerals per sec
15 * .7 = 10.5 minerals per sec
Note: 3 typically on gas mines with negligible saturation rates.
For Protoss/Terran
+ Show Spoiler +
Let M(u) = mineral cost of a unit u
Let T(u) = time cost of a unit u
Let G(u) = gas cost of a unit u
Let X(u) = the number of structures to produce u
Let F(u) = the food cost of unit u
Let M(s) = mineral cost of a supply source s
Let F(s) = the food supply of a supply source s
Let G(M) = number of gatherers on minerals
Let R(M) = the average gathering rate of minerals for a single gatherer = ~ .679 minerals / sec
Let G(G) = number of gatherers on gas
Let R(G) = the average gathering rate of gas for a single gatherer = ~.676 gas / sec
Gatherers required on minerals to produce unit u on X(u) structures:
G(M) >= [X(u) / [T(u) * R(M)]] * [M(u) + [F(u) / F(s)] * M(s)]
Gatherers on minerals >= 18.41 * (number of buildings) * [8 * (mineral cost of unit)
+ (supply cost of unit)] / (time to make unit)
Gatherers required on gas to produce unit u on X(u) structures:
G(G) >= [X(u) * G(u)] / [T(u) * R(G)]
Gatherers on gas >= 1.48 * (number of buildings) * (gas cost of unit) / (time to make unit)
Note: R(G) is more sensitive on the distance of the gas on the map. On Kulas where there is a close geyser and a far geyser, the close geyser mines at about .774 gas / sec and the far one about .600 gas / sec.
Let T(u) = time cost of a unit u
Let G(u) = gas cost of a unit u
Let X(u) = the number of structures to produce u
Let F(u) = the food cost of unit u
Let M(s) = mineral cost of a supply source s
Let F(s) = the food supply of a supply source s
Let G(M) = number of gatherers on minerals
Let R(M) = the average gathering rate of minerals for a single gatherer = ~ .679 minerals / sec
Let G(G) = number of gatherers on gas
Let R(G) = the average gathering rate of gas for a single gatherer = ~.676 gas / sec
Gatherers required on minerals to produce unit u on X(u) structures:
G(M) >= [X(u) / [T(u) * R(M)]] * [M(u) + [F(u) / F(s)] * M(s)]
Gatherers on minerals >= 18.41 * (number of buildings) * [8 * (mineral cost of unit)
+ (supply cost of unit)] / (time to make unit)
Gatherers required on gas to produce unit u on X(u) structures:
G(G) >= [X(u) * G(u)] / [T(u) * R(G)]
Gatherers on gas >= 1.48 * (number of buildings) * (gas cost of unit) / (time to make unit)
Note: R(G) is more sensitive on the distance of the gas on the map. On Kulas where there is a close geyser and a far geyser, the close geyser mines at about .774 gas / sec and the far one about .600 gas / sec.
For Zerg
+ Show Spoiler +
Let M(u) = mineral cost of a unit u
Let T(u) = time cost of a unit u
Let G(u) = gas cost of a unit u
Let X(u) = number of hatcheries producing unit u
Let F(u) = the food cost of unit u
Let M(s) = mineral cost of a supply source s
Let F(s) = the food supply of a supply source s
Let G(M) = number of gatherers on minerals
Let R(M) = the average gathering rate of minerals for a single gatherer = ~ .679 minerals / sec
Let G(G) = number of gatherers on gas
Let R(G) = the average gathering rate of gas for a single gatherer = ~.676 gas / sec
Let R(L) = rate of larva spawn for one hatchery = (1 larva / 15 sec) + (4 larva / 40 sec) = ~ .167 larva / sec
Gatherers required on minerals to produce unit u on X(u) hatcheries:
G(M) >= X(u) * R(L) * [F(s) * M(u) + F(u) * M(s)] / [R(M) * [F(s) + F(u)]]
Gatherers on minerals >= 2.46 * (number of hatcheries) * [.08 * (mineral cost of unit) + (supply cost of unit)] / [(supply cost of unit) + 8]
Gatherers required on gas to produce unit u on X(u) hatcheries:
G(G) >= X(u) * R(L) * F(s) * G(u) / [R(G) * [F(s) + F(z)]]
Gatherers on gas >= 1.97 * (number of hatcheries) * (gas cost of unit) / [(supply cost of unit) + 8]
Let T(u) = time cost of a unit u
Let G(u) = gas cost of a unit u
Let X(u) = number of hatcheries producing unit u
Let F(u) = the food cost of unit u
Let M(s) = mineral cost of a supply source s
Let F(s) = the food supply of a supply source s
Let G(M) = number of gatherers on minerals
Let R(M) = the average gathering rate of minerals for a single gatherer = ~ .679 minerals / sec
Let G(G) = number of gatherers on gas
Let R(G) = the average gathering rate of gas for a single gatherer = ~.676 gas / sec
Let R(L) = rate of larva spawn for one hatchery = (1 larva / 15 sec) + (4 larva / 40 sec) = ~ .167 larva / sec
Gatherers required on minerals to produce unit u on X(u) hatcheries:
G(M) >= X(u) * R(L) * [F(s) * M(u) + F(u) * M(s)] / [R(M) * [F(s) + F(u)]]
Gatherers on minerals >= 2.46 * (number of hatcheries) * [.08 * (mineral cost of unit) + (supply cost of unit)] / [(supply cost of unit) + 8]
Gatherers required on gas to produce unit u on X(u) hatcheries:
G(G) >= X(u) * R(L) * F(s) * G(u) / [R(G) * [F(s) + F(z)]]
Gatherers on gas >= 1.97 * (number of hatcheries) * (gas cost of unit) / [(supply cost of unit) + 8]
------------------------------
Methods I used to model this problem:
+ Show Spoiler +
How many gatherers on minerals do I need to constantly produce marines from a given number of barracks?
Assumptions:
*** Gatherers do not lose gathering time by switching between mineral patches. We are only concerned with time to gather and time to return cargo/come back to patch.
*** Mineral patches never become over-saturated. We can have an infinite number of workers on one mineral patch and each will mine at the same rate as one worker would from its own distinct patch.
*** Builders are not considered gatherers.
*** We have all the buildings necessary to make the marines prior to the calculations. *** The cost of a barracks, for example, is not considered.
*** We can start producing units immediately with no supply blocks or other lack of funds.
*** Build time for supply is not considered.
*** All workers, both gatherers and builders, are assumed to be built prior to calculation.
*** All time will be measure in in-game seconds.
*** Income rate is constant.
*** All marines start perfectly on time and are not queued.
*** Some other stuff I forgot about that doesn't matter a whole lot.
Let M(m) = mineral cost of a marine = 50 minerals
Let T(m) = time cost of a marine = 25 sec
Let X(m) = the number of barracks producing marines
Let F(m) = the food cost of a marine = 1 supply
Let M(s) = mineral cost of a supply depot = 100 minerals
Let F(s) = the food supply of supply depots = 8 supply
Let G(M) = number of gatherers on minerals
Let R(M) = the average gathering rate of minerals for a single gatherer = ~ .679 minerals / sec
Fundamental constraint:
Income >= Cost (both in minerals/sec)
If we disregard supply constraints, then clearly
Income >= [X(m) * M(m)] / [T(m)]
If we have one barracks, then our income must be >= 50 minerals / 25 sec = 2 minerals / sec
If we have two barracks, then out income must be >= 100 minerals / 25 sec = 4 minerals /sec
Now we consider supply. By averaging, we find that, for each marine we produce, we must also produce F(m) / F(s) supply depots. Thus, our cost now becomes:
Income >= [X(m) * M(m)] / [T(m)] + [F(m) / F(s)] * [M(s)] * [X(m) / T(m)]
Which can be simplified to read:
Income >= [X(m) / T(m)] * [M(m) + [F(m) / F(s)] * M(s)]
This can be verified with simple dimensional analysis.
Now, we approach the problem of income. Income is directly related to the number of gatherers G we have. The mining rates for SCVs were measured by experimentation and averaged. Some notes about how this data was obtained:
*** Spawned in Top Left position of Kulas Ravine.
*** SCV's spread to middle six mineral patches. End patches were not used.
*** All measurements made in replay viewer at normal speed.
*** Measurements were made at the times which the Return Cargo icon disappeared.
*** All measurements were made after 1 minute of natural mining cycles.
*** Measurements were made for approximately 1 minute game time. I believe this is enough time given the amount of redundancy in the data. Practically speaking, these values will wash in with the rest of the errors in the model and errors in the player's performance.
Avg mining rate = ~ 5 minerals / 7.361 sec = ~ .679 minerals / sec = R(M)
So, our mineral income (given our assumptions) should be:
Income = R(M) * G(M)
Thus, Income >= Cost becomes:
[R(M) * G(M)] >= [X(m) / T(m)] * [M(m) + [F(m) / F(s)] * M(s)]
Solving for G(M):
G(M) >= [X(m) / [T(m) * R(M)]] * [M(m) + [F(m) / F(s)] * M(s)]
Now we can test this result on a real situation. Let's try 5 barracks. This means we need:
G(M) >= (5 / (25sec * .679 minerals/sec)) * (50 minerals + (1 supply / 8 supply) * 100 minerals)
G(M) >= .295 * 62.5
G(M) >= 18.4 gatherers
Which we round to 19 gatherers. Note that having an extra gatherer will also help prevent any early supply blocks we might get from not having the time to finish a supply depot. By having the extra money we can drop the depot earlier, thus refrain from halting any marine production. In the practical sense, having an extra worker will allow you to have an easier time progressing into later stages of the game.
We must also take into consideration the fact that it was assumed that we had enough to produce marines out of every barracks immediately. This means we need X(m) * M(m) = 5 * 50 minerals = 250 minerals to start. We will also need at least X(m) * F(m) = 5 * 1 supply = 5 spare supply to start. Due to our averaging of the cost of supply, it will probably end up being a good idea getting an extra supply depot prior to making marines.
To test this, I've created a custom map. So far I've tested 5 barracks, 19 workers on one base as well as two. I've found two bases to be a significant improvement (due to over-saturation in the main). Over about 5 minutes with less than perfect timing, I wound up having roughly 300 extra minerals with 2 bases and 19 workers mining. I started with 250 minerals and and about 21/38 supply dropping depots roughly every 8 marines (as long as it didn't interfere with marine production). I ended with around 70 marines.
Big picture: This formula seems to be a decent estimate of how many workers you need to support constant unit production. The formula was kept general so that users can plug-in their own unit combinations. The formula will be reformulated below to incorporate gas. I also plan to write a formula for Zerg. Users should be able to accommodate for over-saturation rather easily either by splitting workers to an expansion or by modifying the formula to account for it. Liquipedia has some mining rates listed as well which you can use. Just remember to convert the rates into (resources / game second).
Let M(u) = mineral cost of a unit u
Let T(u) = time cost of a unit u
Let G(u) = gas cost of a unit u
Let X(u) = the number of structures to produce u
Let F(u) = the food cost of unit u
Let M(s) = mineral cost of a supply source s
Let F(s) = the food supply of a supply source s
Let G(M) = number of gatherers on minerals
Let R(M) = the average gathering rate of minerals for a single gatherer = ~ .679 minerals / sec
Let G(G) = number of gatherers on gas
Let R(G) = the average gathering rate of gas for a single gatherer = ~.676 gas / sec
Note: R(G) is more sensitive on the distance of the gas on the map. On Kulas where there is a close geyser and a far geyser, the close geyser mines at about .774 gas / sec and the far one about .600 gas / sec.
Gatherers required on minerals to produce unit u on X(u) structures:
G(M) >= [X(u) / [T(u) * R(M)]] * [M(u) + [F(u) / F(s)] * M(s)]
Gatherers required on gas to produce unit u on X(u) structures:
G(G) >= [X(u) * G(u)] / [T(u) * R(G)]
------------------------------
For Zerg, Larva needs to be taken into consideration. Assuming that we have queens and that we spawn larva perfectly. We also assume that we only have 1 free larva in this calculation. We can add more by assuming that we have extra money stored up (see marine example):
Let X(u) = number of hatcheries producing unit u
Let R(L) = rate of larva spawn for one hatchery = (1 larva / 15 sec) + (4 larva / 40 sec) = ~ .167 larva / sec
As Zerg, we wish to create a unit, say Zerglings, every larva spawn, ignoring supply:
Income >= X(z) * R(L) * M(z)
Including supply means that we make a Zergling some percent of the time and an Overlord the other percent. We find these percentages by realizing we make 8:1 Zerglings to Overlords:
Income >= X(z) * R(L) * [F(s) * M(z) + F(z) * M(s)] / [F(s) + F(z)]
Income should stay the same as the marine case:
[R(M) * G(M)] >= X(z) * R(L) * [F(s) * M(z) + F(z) * M(s)] / [F(s) + F(z)]
So the number of gatherers on minerals should be:
G(M) >= X(z) * R(L) * [F(s) * M(z) + F(z) * M(s)] / [R(M) * [F(s) + F(z)]]
So, if we are making Zergling off of one base:
G(M) >= .167 (larva / sec) * (8 supply * 50 minerals + 1 supply * 100 minerals) / (.679 (minerals / sec) * 9 supply)
G(M) >= 13.7 gatherers
Round to 14 gatherers and test this result. I will give myself 150 minerals to use the first spawns on Zerglings and cast Spawn Larva immediately. In my test I actually found myself just able to manage with 13 gatherers, but I also tested on LT. Regardless, this method still seems to bring you very close to the optimal number of gatherers.
Gatherers required on minerals to produce unit u on X(u) hatcheries:
G(M) >= X(u) * R(L) * [F(s) * M(u) + F(u) * M(s)] / [R(M) * [F(s) + F(u)]]
Gatherers required on gas to produce unit u on X(u) hatcheries:
G(G) >= X(u) * R(L) * F(s) * G(u) / [R(G) * [F(s) + F(z)]]
------------------------------
For my final test I decided to try Mutas off of two bases:
G(M) >= 2 * .167 * [8 * 100 + 2 * 100] / [.679 * 10]
G(M) >= 49.2 gatherers
Let G(M) = 50 gatherers
G(G) >= 2 * .167 * 8 * 100 / [.676 * 10]
G(G) >= 39.5 gatherers
Let G(G) = 40 gatherers
I chose LT again and made four hatcheries for workers. I only produced out of two with queens. I added extra geysers to my bases so I could reach 14 to avoid trouble with over-saturation. Considering how difficult it is to setup workers on 4 bases, spawn larva, and make units simultaneously, the money was spent very well. Money went up to about 1000/1000 right when larva popped off both hatches and was spent right away. Gas was never in excess and kept right with larva availability. Minerals did creep up a bit because I didn't make Overlords in the beginning since I gave myself a bunch to begin with to avoid the hassle. At about 7 minutes (about 5 of which was actually played) I had about 500 excess minerals, no excess gas and no excess larva.
Assumptions:
*** Gatherers do not lose gathering time by switching between mineral patches. We are only concerned with time to gather and time to return cargo/come back to patch.
*** Mineral patches never become over-saturated. We can have an infinite number of workers on one mineral patch and each will mine at the same rate as one worker would from its own distinct patch.
*** Builders are not considered gatherers.
*** We have all the buildings necessary to make the marines prior to the calculations. *** The cost of a barracks, for example, is not considered.
*** We can start producing units immediately with no supply blocks or other lack of funds.
*** Build time for supply is not considered.
*** All workers, both gatherers and builders, are assumed to be built prior to calculation.
*** All time will be measure in in-game seconds.
*** Income rate is constant.
*** All marines start perfectly on time and are not queued.
*** Some other stuff I forgot about that doesn't matter a whole lot.
Let M(m) = mineral cost of a marine = 50 minerals
Let T(m) = time cost of a marine = 25 sec
Let X(m) = the number of barracks producing marines
Let F(m) = the food cost of a marine = 1 supply
Let M(s) = mineral cost of a supply depot = 100 minerals
Let F(s) = the food supply of supply depots = 8 supply
Let G(M) = number of gatherers on minerals
Let R(M) = the average gathering rate of minerals for a single gatherer = ~ .679 minerals / sec
Fundamental constraint:
Income >= Cost (both in minerals/sec)
If we disregard supply constraints, then clearly
Income >= [X(m) * M(m)] / [T(m)]
If we have one barracks, then our income must be >= 50 minerals / 25 sec = 2 minerals / sec
If we have two barracks, then out income must be >= 100 minerals / 25 sec = 4 minerals /sec
Now we consider supply. By averaging, we find that, for each marine we produce, we must also produce F(m) / F(s) supply depots. Thus, our cost now becomes:
Income >= [X(m) * M(m)] / [T(m)] + [F(m) / F(s)] * [M(s)] * [X(m) / T(m)]
Which can be simplified to read:
Income >= [X(m) / T(m)] * [M(m) + [F(m) / F(s)] * M(s)]
This can be verified with simple dimensional analysis.
Now, we approach the problem of income. Income is directly related to the number of gatherers G we have. The mining rates for SCVs were measured by experimentation and averaged. Some notes about how this data was obtained:
*** Spawned in Top Left position of Kulas Ravine.
*** SCV's spread to middle six mineral patches. End patches were not used.
*** All measurements made in replay viewer at normal speed.
*** Measurements were made at the times which the Return Cargo icon disappeared.
*** All measurements were made after 1 minute of natural mining cycles.
*** Measurements were made for approximately 1 minute game time. I believe this is enough time given the amount of redundancy in the data. Practically speaking, these values will wash in with the rest of the errors in the model and errors in the player's performance.
Avg mining rate = ~ 5 minerals / 7.361 sec = ~ .679 minerals / sec = R(M)
So, our mineral income (given our assumptions) should be:
Income = R(M) * G(M)
Thus, Income >= Cost becomes:
[R(M) * G(M)] >= [X(m) / T(m)] * [M(m) + [F(m) / F(s)] * M(s)]
Solving for G(M):
G(M) >= [X(m) / [T(m) * R(M)]] * [M(m) + [F(m) / F(s)] * M(s)]
Now we can test this result on a real situation. Let's try 5 barracks. This means we need:
G(M) >= (5 / (25sec * .679 minerals/sec)) * (50 minerals + (1 supply / 8 supply) * 100 minerals)
G(M) >= .295 * 62.5
G(M) >= 18.4 gatherers
Which we round to 19 gatherers. Note that having an extra gatherer will also help prevent any early supply blocks we might get from not having the time to finish a supply depot. By having the extra money we can drop the depot earlier, thus refrain from halting any marine production. In the practical sense, having an extra worker will allow you to have an easier time progressing into later stages of the game.
We must also take into consideration the fact that it was assumed that we had enough to produce marines out of every barracks immediately. This means we need X(m) * M(m) = 5 * 50 minerals = 250 minerals to start. We will also need at least X(m) * F(m) = 5 * 1 supply = 5 spare supply to start. Due to our averaging of the cost of supply, it will probably end up being a good idea getting an extra supply depot prior to making marines.
To test this, I've created a custom map. So far I've tested 5 barracks, 19 workers on one base as well as two. I've found two bases to be a significant improvement (due to over-saturation in the main). Over about 5 minutes with less than perfect timing, I wound up having roughly 300 extra minerals with 2 bases and 19 workers mining. I started with 250 minerals and and about 21/38 supply dropping depots roughly every 8 marines (as long as it didn't interfere with marine production). I ended with around 70 marines.
Big picture: This formula seems to be a decent estimate of how many workers you need to support constant unit production. The formula was kept general so that users can plug-in their own unit combinations. The formula will be reformulated below to incorporate gas. I also plan to write a formula for Zerg. Users should be able to accommodate for over-saturation rather easily either by splitting workers to an expansion or by modifying the formula to account for it. Liquipedia has some mining rates listed as well which you can use. Just remember to convert the rates into (resources / game second).
Let M(u) = mineral cost of a unit u
Let T(u) = time cost of a unit u
Let G(u) = gas cost of a unit u
Let X(u) = the number of structures to produce u
Let F(u) = the food cost of unit u
Let M(s) = mineral cost of a supply source s
Let F(s) = the food supply of a supply source s
Let G(M) = number of gatherers on minerals
Let R(M) = the average gathering rate of minerals for a single gatherer = ~ .679 minerals / sec
Let G(G) = number of gatherers on gas
Let R(G) = the average gathering rate of gas for a single gatherer = ~.676 gas / sec
Note: R(G) is more sensitive on the distance of the gas on the map. On Kulas where there is a close geyser and a far geyser, the close geyser mines at about .774 gas / sec and the far one about .600 gas / sec.
Gatherers required on minerals to produce unit u on X(u) structures:
G(M) >= [X(u) / [T(u) * R(M)]] * [M(u) + [F(u) / F(s)] * M(s)]
Gatherers required on gas to produce unit u on X(u) structures:
G(G) >= [X(u) * G(u)] / [T(u) * R(G)]
------------------------------
For Zerg, Larva needs to be taken into consideration. Assuming that we have queens and that we spawn larva perfectly. We also assume that we only have 1 free larva in this calculation. We can add more by assuming that we have extra money stored up (see marine example):
Let X(u) = number of hatcheries producing unit u
Let R(L) = rate of larva spawn for one hatchery = (1 larva / 15 sec) + (4 larva / 40 sec) = ~ .167 larva / sec
As Zerg, we wish to create a unit, say Zerglings, every larva spawn, ignoring supply:
Income >= X(z) * R(L) * M(z)
Including supply means that we make a Zergling some percent of the time and an Overlord the other percent. We find these percentages by realizing we make 8:1 Zerglings to Overlords:
Income >= X(z) * R(L) * [F(s) * M(z) + F(z) * M(s)] / [F(s) + F(z)]
Income should stay the same as the marine case:
[R(M) * G(M)] >= X(z) * R(L) * [F(s) * M(z) + F(z) * M(s)] / [F(s) + F(z)]
So the number of gatherers on minerals should be:
G(M) >= X(z) * R(L) * [F(s) * M(z) + F(z) * M(s)] / [R(M) * [F(s) + F(z)]]
So, if we are making Zergling off of one base:
G(M) >= .167 (larva / sec) * (8 supply * 50 minerals + 1 supply * 100 minerals) / (.679 (minerals / sec) * 9 supply)
G(M) >= 13.7 gatherers
Round to 14 gatherers and test this result. I will give myself 150 minerals to use the first spawns on Zerglings and cast Spawn Larva immediately. In my test I actually found myself just able to manage with 13 gatherers, but I also tested on LT. Regardless, this method still seems to bring you very close to the optimal number of gatherers.
Gatherers required on minerals to produce unit u on X(u) hatcheries:
G(M) >= X(u) * R(L) * [F(s) * M(u) + F(u) * M(s)] / [R(M) * [F(s) + F(u)]]
Gatherers required on gas to produce unit u on X(u) hatcheries:
G(G) >= X(u) * R(L) * F(s) * G(u) / [R(G) * [F(s) + F(z)]]
------------------------------
For my final test I decided to try Mutas off of two bases:
G(M) >= 2 * .167 * [8 * 100 + 2 * 100] / [.679 * 10]
G(M) >= 49.2 gatherers
Let G(M) = 50 gatherers
G(G) >= 2 * .167 * 8 * 100 / [.676 * 10]
G(G) >= 39.5 gatherers
Let G(G) = 40 gatherers
I chose LT again and made four hatcheries for workers. I only produced out of two with queens. I added extra geysers to my bases so I could reach 14 to avoid trouble with over-saturation. Considering how difficult it is to setup workers on 4 bases, spawn larva, and make units simultaneously, the money was spent very well. Money went up to about 1000/1000 right when larva popped off both hatches and was spent right away. Gas was never in excess and kept right with larva availability. Minerals did creep up a bit because I didn't make Overlords in the beginning since I gave myself a bunch to begin with to avoid the hassle. At about 7 minutes (about 5 of which was actually played) I had about 500 excess minerals, no excess gas and no excess larva.