The Math of HOI4 - (1) Civilian Factories

  • We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

Simon_9732495

Lt. General
25 Badges
Feb 28, 2020
1.612
4.188
  • Crusader Kings II
  • Crusader Kings III
  • Europa Universalis IV
  • Europa Universalis IV: Rights of Man
  • Europa Universalis IV: Art of War
  • Europa Universalis IV: Common Sense
  • Victoria 2
  • Cities: Skylines
  • Cities: Skylines Industries
  • Cities: Skylines - Parklife
  • Cities: Skylines - Mass Transit
  • Cities: Skylines - Snowfall
  • Cities: Skylines - After Dark
  • Prison Architect
  • Stellaris
  • Hearts of Iron III
  • Hearts of Iron IV: Cadet
  • Hearts of Iron IV: Together for Victory
  • Hearts of Iron IV: Death or Dishonor
  • Hearts of Iron IV: Expansion Pass
  • Hearts of Iron IV: Expansion Pass
  • Hearts of Iron IV: La Resistance
  • Battle for Bosporus
  • Hearts of Iron IV: No Step Back
  • Hearts of Iron IV: By Blood Alone
(*) 21.12.2020: Revision 1, major changes, please read the posting again. See end of thread for Revisions.

Introduction

I'm trying to describe some fundemantal HOI4 mechanics mathematically. The thread on Civilian Factories (CIVs) is the first in a series, more threads will follow.
My goal is to describe game mechanics as accurate as possible, while also trying not to get stuck in unimportant details.
My benchmark are testruns. Running the game should give the same results as the math. (In a reasonable precision)
That means, if you can provide a testrun, that doesn't fit with the math, please tell me.


Derviation of the CIV-Formula

Let's describe the number of owned CIVs at the time t with the function c(t).
We know that 1 civilian factory has a construction output of 5 per day modified by production bonuses and infrastructure.
So we define the first important constant called CPD.
CPD stands for CIVs per day and is the amount of CIVs that 1 CIV can produce in 1 day.
CPD is the CIV construction speed of 1 CIV.

(1)
1608540060758.png

Infra stands for the infrastructure modifier in % (0% for Level 0 Infrastructure and 100% for Level 10 Infrastructure)
Bonus stands for the sum of production bonuses in %. (From Trade law, Construction research, Advisors and so on...)
5 is the construction output of 1 CIV
10800 is the production cost of 1 CIV

Defining this as a constant (invariable for the time t) might seem wrong, as infrastructure and production bonuses are not constant over the game. But it's not wrong because I chose to derive a formula for the timespan where CPD is constant. The game consists of timespans where CPD is constant in a row. More about this in the Conclusions at the end of the thread.

So with the CIV construction speed of 1 CIV defined we can calculate the overall CIV construction speed.
We call the overall CIV construction speed "c-dot"(t), the derivate of c(t) by the time t.
It's the rate by which the number of owned CIVs changes:

(2)
1608540072578.png

To calculate it we have to consider the number of CIVs that are available for construction.
We call them c_av(t):

(3)
1608540085611.png

c_av(t) is the number of CIVs available for construction
c(t) is the number of owned CIVs
c_in is the number of "incoming" CIVs e.g. from trade, licenses, puppets or occupation
c_out is the number of "outgoing" CIVs e.g. for trade, licenses or other constructions
CG is the Consumer Goods Ratio
m_0 is the number of Military factories (MILs) at the start point of the calculation

Note that c_in is reduced with CG and c_out is just substracted. That means with even trade you have less CIVs than with no trade.

Assumptions needed here:
  • The number of MILs is constant over the time where the formula is valid. We are not constructing MILs and CIVs at the same time. More about constructing MILs and MILs and CIVs at the same time in another thread.
  • Cosumer Goods ratio is constant. Same as with the construction bonuses. The formula is valid for the timespan where it is constant. More about this in the Conclusions at the end of the thread.
  • CIVs from trade, to trade, from licenses, to licenses, from puppets, from occupations and for other constructions are constant. That's an issue because in a real game these will not be constant. I have no good idea yet how to bring trade into this, because it can be quite random. If you have a good idea how to model CIVs from trade, please tell me.
The rate the number of owned CIV changes (c_dot(t)) is the construction speed of 1 CIV multiplied with the number of CIVs that are available for constrution.

(4)
1608540101567.png

We have to consider that c_av(t) is a number with decimal places and incomplete CIVs can't contribute to construction.
CIVs are organized in production lines with 15CIVs per line. So the number of production lines is about c_av(t) / 15
Each production line progresses in most cases with constant speed. That means the average progress of a production line over time is about 50%.
c_av(t) includes the unfinished CIVs, so our estimated correction is to substract 0.5 CIVs per line:

(5)
1608540125089.png

To find c_av_dot(t) we have to derive the equation (3) by the time t. Only c(t) is dependent on the time, so we get:

(6)
1608540135235.png

Now we bring c_dot(t) from equation (5) into equation (6) and get:

(7)
1608540160159.png


The equation (7) is a differential equation, because it sets c_av(t) and c_av_dot(t) into relation. It can be solved to get a formula for c_av(t).


Solving the differential equation

Equation (7) is a very basic differential equation for growth of the type:

(8)
1608540174053.png

with the well known solution:

(9)
1608540188458.png

We get:

(10)
1608540210606.png

Now we use the start conditions to find const. We call c_av_0 the number of CIVs available for consturction at t = 0. (Remark: t = 0 is not necessary the game start date.)

(11)
1608540223427.png

We found our result:


The CIV-Formula

(12)
1608540244558.png

Where:
c_av(t) is the number of CIVs available for construction at the time t
c_av,0 is the number of CIVs available for construction at the time 0
CG the consumer goods ratio (and constant as long as the formula is valid)
CPD the CIV construction speed of 1 CIV (and constant as long as the formula is valid)

The relation between c_av(t) (CIVs available for construction) and c(t) (CIVs owned) is: (Equation 3 reordered)

(13)
1608540261425.png

Or if we want to calculate c(t) (the number of CIVs owned) we can write (13) as:

(14)
1608540275200.png


Equation (12) is a formula of exponential growth, as everybody knows... (CIVs build CIVs, that CIVs build more CIVs faster, ...)
But the growth is slow, due to the factors being small. Here's an example:

Example

Soviet Union at 1936 start.
c_0 = 44 CIVs
m_0 = 32 MILs
CG = 20% (console cheat instant war economy)
c_in = 0 (No CIVs incoming for trade, licenses, Puppets or occupation
c_out = 0 (No CIVs used for trade or buying licenses, or other constructions)
CPD = 0.0009 (Level 5 Infrastructure, 30% Construction Bonus [Export Focus, Construction1, Captain of Industry] )

Run it for 1000 days:
Ingame Testrun gives 79 owned CIVs, 57 CIVs available for construction and 2.09 incomplete CIVs in construction
Formula gives 80.36 owned CIVs and 57.89 available CIVs

The number of CIVs after 1000 days is 80. It takes over 3 years (1144 days) to double the number of CIVs.
Look at Graph:

1608539780266.png

(The dotted line "Linear (CIVs)" is a linear regression line from excel.)
(In a real game you would research more levels of construction, get new CIVs by focus, trade, conquer new CIVs and so on... This example is here to show only the exponential nature of building CIVs and that the effect is small.)


Implications and Conlusions

  • When building CIVs the growth is exponential, but the exponential effect is low in typical time scales. If you looked at the function over 30 years, it looked like this:
1608539507847.png
There you see the impact of the exponential function. But you're not building CIVs that long.​
  • It's hard to calculate HOI4 economy in advance. There are so many things to consider and some of them have a random element like trade. It's not reasonable to find out every date when a law changes or when you hire an advisor to be able to calculate the economy. You can just do a testrun for that.

  • What's the point of the thread then? It's to get a better understanding of the mechanics and to be able to answer specific questions. For example this one:

  • In the example above you can decide between lowering consumer goods from 20% to 15% or raising construction bonus from 30% to 40%. Which is better for the construction of CIVs?
    -> It's the -5% Consumer goods. (But it's only by 1 CIV in 2 years.)

  • One idea behind making this a thread is to get questions from you. By trying to answer questions about the topic I hope to get an idea where I have to expand the formula.


Decisive factors for rapid CIV growth

Let's look at equation (3) again:

(3)
1608540085611.png


To have more CIVs available for construction you want to:
  • Have a lot of owned CIVs, obvious. Thats why you build CIVs to have more available CIVs.
  • You want to have more incoming trade and less outgoing trade. That's why you do tradebacks or even trade boosting in Multiplayer.
  • You want to have the lowest Consumer Goods ratio possible. Lowering CG gives you more available CIVs IN THAT MOMENT.
  • You want to have a low number of MILs. That's why converting MILs into CIVs at the very begining is a strategy. (I will address this in a future thread.)
Now let's look at equation (12) that describes the growth of available CIVs:

(12)
1608540244558.png


In an exponential term of the form e^(k*t) the factor k determines the speed of the growth. We want a large k.
With the use of (1) we can write k as:

(15)
1608629323970.png


We can increase k and thus the construction speed of CIVs by:
  • Building in high Infrastructure provinces. (We dont want to build Infrastruture first to construct CIVs faster, it's not worth it.)
  • Getting construction Bonuses. Get a good trade law, get a good economy law, research Construction 1-5 and hire an "Captain of Industry"
  • Lowering the Consumer Goods ratio. You can affect them with the economy laws, with the advisors "Financial Expert" you can do deals like giving Airplanes for lower consumer goods, there's the MEFO Bills for Germany, some decisions influence Consumer goods (e.g. Improved worker conditions) and so on...
But how to prioritize?
  • Concerning Infrastructure it's easy. You build in your high infrastructure provinces first.
  • Next thing to consider is that lowering Consumer Goods is almost always better than the construction Bonuses. One thing is that going from 30% CG to 20% CG changes the (1-CG) term from 0.70 to 0.80 which is a increase by 14.28%. If you change the prodcution bonus from 30% to 40% by adding an advisor the term (1+Bonus) changes from 1.3 to 1.4 which is a increase by 7.69%. That is only a bit more of the half effect. Even going from 0 to 10% in construction Bonus is only +10.00%
  • What's more if change Consumer Goods it also has the effect on equation (3) described above. It makes you CIVs available for construction JUMP UP.
  • Example: 50 CIVs, 50 MILs, 30% CG. You have 20 available CIV. 30 used for CG. If you change CG to 20% you have suddenly 30 available CIVs. +10 CIVs with one change. By changing CG by x% you get x%of your (CIVs+MILs) as new available CIVs.
  • That makes going from Civilian Economy to War economy a very powerful thing to do with only 150 political power. It makes basic CG go from 35% to 20%. And it adds 30% construction Bonus. (-30% before, 0% after) Thats going for example from (1-0.35)*(1-0.2)=0.52 to (1-0.2)*(1+0.1)=0,88 which is a increase of 69% !! +69% "construction speed" and +15%*(CIVs+MILs) more CIVs available for construction with 1 law change.
  • See the graph in this posting: https://forum.paradoxplaza.com/foru...i4-1-civilian-factories.1448922/post-27181155



Edits:
Revision1: (21.12.2020)
  • Correction factor 29/30 to take into account that CIVs that are constructed are not yet constructing anything. Thanks @ZebS98
  • Introduced c_av(t) the number of CIVs available for construction to simplify the equations
  • Introduced c_in and c_out instead of c_other because c_in is effected by consumer goods and c_out isn't. Thanks @el nora
  • Redone all formulas and graphs
  • Restructured Posting to reflect changes
Revision2: (22.12.2020)
  • Added "Decisive factors for rapid CIV growth"
 
Last edited:
  • 19
  • 5Like
  • 4Love
Reactions:

billcorr

Field Marshal
53 Badges
Feb 5, 2010
8.754
2.866
  • Cities in Motion
  • Stellaris: Apocalypse
  • Age of Wonders: Shadow Magic
  • Stellaris - Path to Destruction bundle
  • Victoria 2: A House Divided
  • Sword of the Stars
  • Ship Simulator Extremes
  • Semper Fi
  • Rome Gold
  • Victoria: Revolutions
  • Majesty 2 Collection
  • Majesty 2
  • Magicka
  • The Kings Crusade
  • Heir to the Throne
  • Darkest Hour
  • Crusader Kings II
  • Arsenal of Democracy
  • Europa Universalis III
  • Divine Wind
  • Leviathan: Warships
  • For The Glory
  • For the Motherland
  • Europa Universalis IV: Conquest of Paradise
  • Hearts of Iron III
  • Hearts of Iron III: Their Finest Hour
  • Hearts of Iron III Collection
  • Battle for Bosporus
  • Knights of Honor
  • Hearts of Iron IV: Death or Dishonor
  • Stellaris: Synthetic Dawn
  • Age of Wonders III
  • Hearts of Iron IV: Expansion Pass
  • Hearts of Iron IV: No Step Back
  • Hearts of Iron IV: By Blood Alone
  • Stellaris: Ancient Relics
  • Hearts of Iron IV: La Resistance
  • Stellaris: Federations
  • Hearts of Iron IV: Together for Victory
  • Stellaris: Leviathans Story Pack
  • Hearts of Iron IV: Cadet
  • Hearts of Iron IV Sign-up
  • Stellaris
  • Pillars of Eternity
  • Pride of Nations
  • Europa Universalis IV: El Dorado
  • 500k Club
  • Victoria 2
  • Europa Universalis IV
  • Rome: Vae Victis
In the example above you can decide between lowering consumer goods from 20% to 15% or raising construction bonus from 30% to 40%. Which is better for the construction of CIVs?
-> It's the -5% Consumer goods. (But it's only by 1 CIV in 2 years.)

Thank you.

Strong work.

Good to know (consumer goods -5% are a better investment when building CIVs compared to, let's say, spending 150 PP for a Captain of Industry +10% construction bonus...but then there is the Captain's +10% infrastructure building bonus. I suppose that analysis will come in a future installment. Looking forward to more articles.)
 

billcorr

Field Marshal
53 Badges
Feb 5, 2010
8.754
2.866
  • Cities in Motion
  • Stellaris: Apocalypse
  • Age of Wonders: Shadow Magic
  • Stellaris - Path to Destruction bundle
  • Victoria 2: A House Divided
  • Sword of the Stars
  • Ship Simulator Extremes
  • Semper Fi
  • Rome Gold
  • Victoria: Revolutions
  • Majesty 2 Collection
  • Majesty 2
  • Magicka
  • The Kings Crusade
  • Heir to the Throne
  • Darkest Hour
  • Crusader Kings II
  • Arsenal of Democracy
  • Europa Universalis III
  • Divine Wind
  • Leviathan: Warships
  • For The Glory
  • For the Motherland
  • Europa Universalis IV: Conquest of Paradise
  • Hearts of Iron III
  • Hearts of Iron III: Their Finest Hour
  • Hearts of Iron III Collection
  • Battle for Bosporus
  • Knights of Honor
  • Hearts of Iron IV: Death or Dishonor
  • Stellaris: Synthetic Dawn
  • Age of Wonders III
  • Hearts of Iron IV: Expansion Pass
  • Hearts of Iron IV: No Step Back
  • Hearts of Iron IV: By Blood Alone
  • Stellaris: Ancient Relics
  • Hearts of Iron IV: La Resistance
  • Stellaris: Federations
  • Hearts of Iron IV: Together for Victory
  • Stellaris: Leviathans Story Pack
  • Hearts of Iron IV: Cadet
  • Hearts of Iron IV Sign-up
  • Stellaris
  • Pillars of Eternity
  • Pride of Nations
  • Europa Universalis IV: El Dorado
  • 500k Club
  • Victoria 2
  • Europa Universalis IV
  • Rome: Vae Victis
Here's a question that's been addressed by others, IIRC (e.g. @BaddoSpirito )

In order to maximize civilian factory productions, when should a player build infrastructure before building civilian factories?

(Some players would point out that the right question is: "How can I maximize equipment production? Civilian factories are only a means to an end" But one step at a time...min-maxing civilian factory building.)
 

Simon_9732495

Lt. General
25 Badges
Feb 28, 2020
1.612
4.188
  • Crusader Kings II
  • Crusader Kings III
  • Europa Universalis IV
  • Europa Universalis IV: Rights of Man
  • Europa Universalis IV: Art of War
  • Europa Universalis IV: Common Sense
  • Victoria 2
  • Cities: Skylines
  • Cities: Skylines Industries
  • Cities: Skylines - Parklife
  • Cities: Skylines - Mass Transit
  • Cities: Skylines - Snowfall
  • Cities: Skylines - After Dark
  • Prison Architect
  • Stellaris
  • Hearts of Iron III
  • Hearts of Iron IV: Cadet
  • Hearts of Iron IV: Together for Victory
  • Hearts of Iron IV: Death or Dishonor
  • Hearts of Iron IV: Expansion Pass
  • Hearts of Iron IV: Expansion Pass
  • Hearts of Iron IV: La Resistance
  • Battle for Bosporus
  • Hearts of Iron IV: No Step Back
  • Hearts of Iron IV: By Blood Alone
Strong work.
Thank you!

In order to maximize civilian factory productions, when should a player build infrastructure before building civilian factories?
That's an easy one. The answer is: Never.
There are cases where it's reasonable to build Infrastructure first. E.g for resources and because CIVs and MILs are heavily debuffed. (Hello 1936 USA)
But if it's ONLY about build speed it's not worth to build Infrastructure first.
See this thread: https://forum.paradoxplaza.com/foru...ructure-for-the-build-speed-modifier.1388133/


(Some players would point out that the right question is: "How can I maximize equipment production? Civilian factories are only a means to an end" But one step at a time...min-maxing civilian factory building.)
Chapter 2 will be on MILs. The next chapters will be on production efficiency and prodcution itself.
After these there will be some kind of answer to this question, but it is very difficult.
One part of the answer I can tell you here: In order to maximize equipment production you MUST NOT change any production line ever. Because that gives a dent in production efficiency and thus a loss in equipment production. So "How can I maximize equipment production?" might not be the question you want an answer for. o_O

But it will take some time until I get there. I got the math somewhat finished, but writing a thread like these takes a lot of time for me. I think it was 5 hours for this one...
I'll need some break before the next one...
 
  • 1
  • 1Like
Reactions:

el nora

Colonel
68 Badges
Dec 12, 2016
822
2.485
  • Hearts of Iron IV: By Blood Alone
  • Hearts of Iron IV: No Step Back
Thank you.

Strong work.

Good to know (consumer goods -5% are a better investment when building CIVs compared to, let's say, spending 150 PP for a Captain of Industry +10% construction bonus...but then there is the Captain's +10% infrastructure building bonus. I suppose that analysis will come in a future installment. Looking forward to more articles.)
Not necessarily always. In this specific scenario. If your current buildspeed modifier is eg 0%, rather than the given 40%, then the +10% buildspeed is worth more than the -5% consumer goods.

Here's a question that's been addressed by others, IIRC (e.g. @BaddoSpirito )

In order to maximize civilian factory productions, when should a player build infrastructure before building civilian factories?

(Some players would point out that the right question is: "How can I maximize equipment production? Civilian factories are only a means to an end" But one step at a time...min-maxing civilian factory building.)
The simple answer to that is basically never. The slightly more accurate but still faulty answer to that is when the time spent building X infrastructure and Y civs is minimized in a state that already has N infrastructure. Let:

T(X,Y) = X*600/(1+infra buildspeed) + Y*2160/(1+civ buildspeed)/(1+(X+N)/10)

Which is minimized for a specified Y when ∂T/∂X = 0:

∂T/∂X = 600/(1+infra buildspeed) - Y*2160/(1+civ buildspeed)/(1+(X+N)/10)²/10 = 0

After a bit of algebra, and renaming the ratio of buildspeed modifiers R = (1+infra buildspeed)/(1+civ buildspeed), we can isolate X+N:

X+N = 6√(YR) - 10

So we can see that the initial infra count doesn't matter, except inasmuch as it reduces the amount you need to build to achieve the minimum time spent building. Only the final infra count matters. You can input the number of free buildslots you have available as Y and your ratio of buildspeeds as R to find out the necessary X+N that will minimize T.

For instance, if R=1 and Y=9, then you can calculate that you need 6√(9*1) - 10 = 8 final infrastructure (irrespective of how much you started with) to minimize the total amount of time spent on building civs in that state.


But that analysis is still flawed because it discount the extra time the civs built earlier would have contributed to building more buildings for simply having built them sooner. Regardless, it's rare to find a state in-game with less infra than the optimal value for that state, even as it is. So by not building infra in those states, you lose out on nothing and that is definitely more worthwhile than building infra would have been.

If you need resources, you should factor into your analysis how many extra resources you would have gained from building infra in those states and how many civs that would have cost you. But that's not something that can be analyzed objectively. It depends on how you play and what resources are useful to you. As heavy tank USA, for instance, I do not care at all about tungsten. But someone who plays medium tank USA would want to increase infra in Utah.
 
  • 2
Reactions:

Harin

General
53 Badges
Jun 8, 2012
1.800
4.035
  • Crusader Kings II
  • Hearts of Iron IV: By Blood Alone
  • Battle for Bosporus
  • BATTLETECH
  • Hearts of Iron IV: Death or Dishonor
  • Stellaris: Synthetic Dawn
  • Age of Wonders III
  • Hearts of Iron IV: Expansion Pass
  • Stellaris: Humanoids Species Pack
  • Stellaris: Apocalypse
  • Hearts of Iron IV: Expansion Pass
  • Stellaris: Distant Stars
  • Shadowrun Returns
  • Imperator: Rome
  • Hearts of Iron IV: Expansion Pass
  • Stellaris: Ancient Relics
  • Age of Wonders: Planetfall
  • Age of Wonders: Planetfall Deluxe edition
  • Age of Wonders: Planetfall Premium edition
  • Age of Wonders: Planetfall Season pass
  • Stellaris: Lithoids
  • Age of Wonders: Planetfall - Revelations
  • Hearts of Iron IV: La Resistance
  • Stellaris: Federations
  • Imperator: Rome - Magna Graecia
  • Crusader Kings III
  • Stellaris: Leviathans Story Pack
  • Europa Universalis IV
  • Hearts of Iron IV: No Step Back
  • Victoria 2
  • Warlock: Master of the Arcane
  • 500k Club
  • Cities: Skylines
  • Pride of Nations
  • Mount & Blade: With Fire and Sword
  • Europa Universalis IV: Common Sense
  • Stellaris
  • Hearts of Iron IV: Cadet
  • Hearts of Iron IV: Colonel
  • Europa Universalis IV: Rights of Man
  • Tyranny: Archon Edition
  • Stellaris: Digital Anniversary Edition
  • Hearts of Iron IV: Together for Victory
  • Victoria 2: Heart of Darkness
  • Victoria 2: A House Divided
  • Supreme Ruler 2020
  • Sword of the Stars
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis IV: Conquest of Paradise
  • Europa Universalis IV: Art of War
One part of the answer I can tell you here: In order to maximize equipment production you MUST NOT change any production line ever. Because that gives a dent in production efficiency and thus a loss in equipment production. So "How can I maximize equipment production?" might not be the question you want an answer for. o_O

First, @Simon_9732495, thank you so much for making such an effort digging into this. I have followed your posts in the past and know this is not your first dip of the toe into this deep water. I appreciate your work in pushing the margin of what is thought to be definable and your willingness to share it in detail. Salute.

Second, I have a questions in reference to your statement I copied above. Assuming all things remain the same from the first day to the last, is there any production advantage in making production lines with more than one factory?

More words to explain the question in my mind are below.

When a production line has multiple factories in it, for example 15 factories producing Light Tank 1s, does that production line recognize each of the 15 factories individual levels of efficiency, or does it use a method to aggregate such variables into one entity? If there is some kind of aggregation that result in an advantage or disadvantage?

I ask, because I would like to know which is more efficient: Case 1: 75 production lines of 1 factory each, or; Case 2: one maximum production line of 75. Both cases are making the same thing. This brings up a few questions, such as:

  • Would Case 1 and Case 2 produce exactly the same, if all else remained equal, or does one case gain an advantage?
  • If you pull five factories each off Case 1 and Case 2 to start new production lines, would the production of the remaining 70 factories in both Cases be equal, or does one of the cases pull ahead?
  • Would the 5 factories pulled off Case 1 to start five new production lines of one factory each, produce the same as the 5 factories pulled off Case 2 to start one new production line of 5 factories?
As you can see, I would like to know if efficiency is effected by using more than one factory in a production line, whether starting a new production line, adding to an existing production line, or removing from a production line. Is it more efficient to always make production lines of one factory or is their any kind of advantage by making production lines with more than one factory?
 
  • 5Like
  • 1
Reactions:

Mousetick

Major
93 Badges
Oct 13, 2012
689
1.401
  • Crusader Kings II: Monks and Mystics
  • Age of Wonders II
Nice work! Thorough and very well presented.
m_0 is the number of Military factories (MILs) at the start point of the calculation
m_0 the number of MILs at the time 0 (and constant as long as the formula is valid)
I could be wrong on this, I'm not sure, but shouldn't m_0 include the number of naval dockyards as well? If so, you may want to edit the text to clarify.
I can only objectively acknowledge your work and the effort you put into it, while subjectively I can't be more appreciative of it. Your research shows that HOI 4 fundamental mechanics are spreadsheet-like, and reinforces the feeling that I'm playing a spreadsheet. Which is not what I'm looking for or enjoy in a "grand" strategy wargame. It's entirely the fault of the game, and of my personal preferences.
 

bitmode

1st Reverse Engineer Battalion
Nov 10, 2016
3.824
7.024
I could be wrong on this, I'm not sure, but shouldn't m_0 include the number of naval dockyards as well?
Dockyards don't count towards consumer goods.
When a production line has multiple factories in it, for example 15 factories producing Light Tank 1s, does that production line recognize each of the 15 factories individual levels of efficiency, or does it use a method to aggregate such variables into one entity? If there is some kind of aggregation that result in an advantage or disadvantage?
Each factory slot in a line, even the ones currently not used, has a separate efficiency value which grows independently (or decays if no factory is assigned to the slot). They are just not shown individually in the UI. There is generally no downside to having factories in separate production lines versus one larger line other than the UI hassle while there are some small benefits in terms of added flexibility. The aggregated output is the same though.
Would the 5 factories pulled off Case 1 to start five new production lines of one factory each, produce the same as the 5 factories pulled off Case 2 to start one new production line of 5 factories?
Yes. When creating any new production line, all 150 factory slots in it are initialized to the minimum efficiency; 10% by default.
 
  • 3
  • 1Like
Reactions:

ZebS98

Private
Dec 20, 2020
11
15
Introduction

I'm trying to describe some fundemantal HOI4 mechanics mathematically. The thread on Civilian Factories (CIVs) is the first in a series, more threads will follow.
My goal is to describe game mechanics as accurate as possible, while also trying not to get stuck in unimportant details.
My benchmark are testruns. Running the game should give the same results as the math. (In a reasonable precision)
That means, if you can provide a testrun, that doesn't fit with the math, please tell me.


Derviation of the CIV-Formula

Let's describe the number of CIVs at the time t with the function c(t).
We know that 1 civilian factory has a construction output of 5 per day modified by production bonuses and infrastructure.
So we define the first important constant called CDP.
CPD stands for CIVs per day and is the amount of CIVs that 1 CIV can produce in 1 day.
CPD is the CIV construction speed of 1 CIV.


Infra stands for the infrastructure modifier in % (0% for Level 0 Infrastructure and 100% for Level 10 Infrastructure)
Bonus stands for the sum of production bonuses in %. (From Trade law, Construction research, Advisors and so on...)
5 is the construction output of 1 CIV
10800 is the production cost of 1 CIV

Defining this as a constant (invariable for the time t) might seem wrong, as infrastructure and production bonuses are not constant over the game. But it's not wrong because I chose to derive a formula for the timespan where CPD is constant. The game consists of timespans where CPD is constant in a row. More about this in the Conclusions at the end of the thread.

So with the CIV construction speed of 1 CIV defined we can calculate the overall CIV construction speed.
We call the overall CIV construction speed "c-dot"(t), the derivate of c(t) by the time t:


To calculate it we have to consider the actual number of CIVs that can construct stuff. Here the Consumer Goods ratio as well as eternal factors like trade come into play.
The overall CIV construction speed is the construction speed of 1 CIV multiplied with the number of CIVs that are actually constructing stuff.


c(t) is the number of owned CIVs at the time t
CG is the Consumer Goods Ratio
m_0 is the number of Military factories (MILs) at the start point of the calculation
c_other is the number of other CIVs e.g. from trade, or CIVs constructing other stuff. (Can be positive or negative)

Assumptions needed here:
  • The number of MILs is constant over the time where the formula is valid. We are not constructing MILs and CIVs at the same time. More about constructing MILs and MILs and CIVs at the same time in another thread.
  • Cosumer Goods ratio is constant. Same as with the construction bonuses. The formula is valid for the timespan where it is constant. More about this in the Conclusions at the end of the thread.
  • CIVs from trade, for other constructions and from other external factors are constant. That's an issue because in a real game even if you construct only CIVs, the number of CIVs from trade will change. I have no good idea yet how to bring trade into this, because it can be quite random. If you have a good idea how to model CIVs from trade, please tell me.
  • c(t) is a number with decimal places and incomplete CIVs can't contribute to construction. This effect evens out with the rounding of Consumer Goods that is in favorite of construction. I might have to consider these effects for some cases in the future. By now my testruns are reasonable identical to the theory.
The equation (3) is a differential equation, because it sets c(t) and c_dot(t) into relation. It can be solved to get a formula for c(t).


Solving the differential equation

We can reorder the equation (3) to:


Now we substitute (5) and (6) into (4) and get the differential equation (7): (In (5) we derive x(t) by t to get x_dot(t) which is c_dot(t) )


(7) is a very basic differential equation for growth with the well known solution:


Resubstitution gives:


Now we use the start conditions to find const. We call c_0 the number of CIVs at t = 0. (Remark: t = 0 is not necessary the game start date.)


We found our result:


The CIV-Formula


Where:
c(t) is the number of CIVs at the time t
c_0 the number of CIVs at the time 0
m_0 the number of MILs at the time 0 (and constant as long as the formula is valid)
CG the consumer goods ratio (and constant as long as the formula is valid)
c_other the CIVs from trade and used for other constructions (and constant as long as the formula is valid)
CPD the CIV construction speed of 1 CIV (and constant as long as the formula is valid)

It's a formula of exponential growth, as everybody knows... (CIVs build CIVs, that CIVs build more CIVs faster, ...)

But the growth is slow, due to the factors being small. Here's an example:
Soviet Union at 1936 start.
c_0 = 44 CIVs
m_0 = 32 MILs
CG = 20% (console cheat instant war economy)
c_other = 0 (No trade, building only CIVs)
CPD = 0.0009 (Level 5 Infrastructure, 30% Construction Bonus [Export Focus, Construction1, Captain of Industry] )

The number of CIVs after 1000 days is 82. It takes almost exactly 3 years (1095 days) to double the number of CIVs.
Look at Graph:


(The dotted line "Linear (CIVs)" is a linear regression line from excel.)
(In a real game you would research more levels of construction, get new CIVs by focus, trade, conquer new CIVs and so on... This example is here to show only the exponential nature of building CIVs and that the effect is small.)


Implications and Conlusions

  • When building CIVs the growth is exponential, but the exponential effect is low in typical time scales. If you looked at the function over 30 years, it looked like this:
There you see the impact of the exponential function. But you're not building CIVs that long.​
  • It's hard to calculate HOI4 economy in advance. There are so many things to consider and some of them have a random element like trade. It's not reasonable to find out every date when a law changes or when you hire an advisor to be able to calculate the economy. You can just do a testrun for that.

  • What's the point of the thread then? It's to get a better understanding of the mechanics and to be able to answer specific questions. For example this one:

  • In the example above you can decide between lowering consumer goods from 20% to 15% or raising construction bonus from 30% to 40%. Which is better for the construction of CIVs?
    -> It's the -5% Consumer goods. (But it's only by 1 CIV in 2 years.)

  • One idea behind making this a thread is to get questions from you. By trying to answer questions about the topic I hope to get an idea where I have to expand the formula.
I hope not to be a pain in the ass by saying this but what you said is not 100% correct. I don't now to what extent you verified the model, but in (2) you are making (implicitly at least) a rather strong assumption. Basically, by using a that differential equation, you are implying that all work done by factories does produce other output (which, as you pointed out in the remarks below, is not the case since incomplete CIVs don't do anything).

Actually i remember that some time back i tried this myself. By using this model in the short term you get a pretty accurate result but in the long run the solution you obtain grows much faster than the actual number of CIVs. To get a more accurate solution you would have to use
c'(t) = floor(k * c(t))
which i don't know how to solve (even thow i am a math student) and to be honest i don't think that that has an explicit solution.

Concerning the simulation of CIVs lost to trade, territorial losses, resistance, etc, since i'm majoring in financial mathematics i would guess that stochastic differential equations could do it but i'm not sure since i haven't had stochastic analysis yet. Sorry but i can't tell you more than that.
 
Last edited:
  • 1Like
  • 1
Reactions:

Simon_9732495

Lt. General
25 Badges
Feb 28, 2020
1.612
4.188
  • Crusader Kings II
  • Crusader Kings III
  • Europa Universalis IV
  • Europa Universalis IV: Rights of Man
  • Europa Universalis IV: Art of War
  • Europa Universalis IV: Common Sense
  • Victoria 2
  • Cities: Skylines
  • Cities: Skylines Industries
  • Cities: Skylines - Parklife
  • Cities: Skylines - Mass Transit
  • Cities: Skylines - Snowfall
  • Cities: Skylines - After Dark
  • Prison Architect
  • Stellaris
  • Hearts of Iron III
  • Hearts of Iron IV: Cadet
  • Hearts of Iron IV: Together for Victory
  • Hearts of Iron IV: Death or Dishonor
  • Hearts of Iron IV: Expansion Pass
  • Hearts of Iron IV: Expansion Pass
  • Hearts of Iron IV: La Resistance
  • Battle for Bosporus
  • Hearts of Iron IV: No Step Back
  • Hearts of Iron IV: By Blood Alone
First, @Simon_9732495, thank you so much for making such an effort digging into this. I have followed your posts in the past and know this is not your first dip of the toe into this deep water. I appreciate your work in pushing the margin of what is thought to be definable and your willingness to share it in detail. Salute.
Thank you very much. Kind words like these, in an otherwise rather harsh internet, keep my motivation up, to work a bit longer on a thread!


Second, I have a questions in reference to your statement I copied above. Assuming all things remain the same from the first day to the last, is there any production advantage in making production lines with more than one factory?
A thread on production efficiency will follow and I will go deep into it there.
The question was answered already by @bitmode (Thank you!) but I'd like to add:
The game does a really good job calculating efficiency per faction. So far I found no way to exploit it, cheese it in my favor or screw it up.
(Ok, a way to screw it up is having a line running at high efficiency and you change it by misclick. :D )
If you construcitng MILs, it doesnt matter if you have 1 line and add factories to it. (That line will never reach full efficiency)
Or doing, say, lines of 15 MILs where the older ones reach max efficiency.
It's really all calculated per factory.

Maybe to elaborate a bit on the point I made:
You dont want to max equipment production, because to do that you change the production lines only at game start (there you can do without losing efficiency) and then never assign a "old" MIL to a "new" line.
But at some point you want an "old" MIL to produce equipment you hadn't researched at game start. You assign the "old" MIL to a "new" line and it loses it's efficiency.
At that moment you violated the rule "I want to maximize equipment production."
You rather want to maximize the production of the RIGHT equipment. Surely not the production of ANY equipment.
And that's much harder to calculate, because what is the right equipment?
I have an idea in my mind and I will present in one of the future chapters, maybe in some weeks. (There is still a lot work to do)
 
  • 1
Reactions:

Simon_9732495

Lt. General
25 Badges
Feb 28, 2020
1.612
4.188
  • Crusader Kings II
  • Crusader Kings III
  • Europa Universalis IV
  • Europa Universalis IV: Rights of Man
  • Europa Universalis IV: Art of War
  • Europa Universalis IV: Common Sense
  • Victoria 2
  • Cities: Skylines
  • Cities: Skylines Industries
  • Cities: Skylines - Parklife
  • Cities: Skylines - Mass Transit
  • Cities: Skylines - Snowfall
  • Cities: Skylines - After Dark
  • Prison Architect
  • Stellaris
  • Hearts of Iron III
  • Hearts of Iron IV: Cadet
  • Hearts of Iron IV: Together for Victory
  • Hearts of Iron IV: Death or Dishonor
  • Hearts of Iron IV: Expansion Pass
  • Hearts of Iron IV: Expansion Pass
  • Hearts of Iron IV: La Resistance
  • Battle for Bosporus
  • Hearts of Iron IV: No Step Back
  • Hearts of Iron IV: By Blood Alone
I hope not to be a pain in the ass by saying this but what you said is not 100% correct. I don't now to what extent you verified the model, but in (2) you are making (implicitly at least) a rather strong assumption. Basically, by using a that differential equation, you are implying that all work done by factories does produce other output (which, as you pointed out in the remarks below, is not the case since incomplete CIVs don't do anything).

Actually i remember that some time back i tried this myself. By using this model in the short term you get a pretty accurate result but in the long run the solution you obtain grows much faster than the actual number of CIVs. To get a more accurate solution you would have to use
c'(t) = floor(k * c(t))
which i don't know how to solve (even thow i am a math student) and to be honest i don't think that that has an explicit solution.
Thank you for looking into it. Very helpful. I appreciate it!

I think you are correct.
I stated in the thread above that I might have to consider the effects that CIVs that are constructed don't construct anything in the future.
After I posted the thread I did some more testruns and noticed that the precision is not very good, if the amount of CIVs at the start is very high.
After your posting I decided, I should correct this immediately. The precision is ok, but better is better...

My idea to correct it is the following:
Say you use 60 available CIVs for 4 full construction lines to construct other CIVs.
(Available means the CIVs that are really consturcting after considering, trade, consumer goods and so on.)
That means in the best case all 4 lines are at 0% progress and all CIVs you have are actually constructing.
If all 4 Lines are on 50% that means you have 62 CIVs (4*0.5 = 2) but only 60 are constructing.
In the worst case all lines are almost finished, you have almost 64 CIVs and 4 CIVs that are not constructing.
Let's assume that the actual progress is normally distributed (like random, like white noise) which should be a solid representation. (As long as the player is not microing the construction.)
Then the average case is that: (Num CIVs / 15 ) / 2 are not constructing.

I'm going to correct the number of CIVs by that number.
But I think I'm going to start from scratch and make a formula for "CIVs available for construction" (The formula above is for "CIVs owned")
Wouldn't be the first time I start from scratch. :D
 
  • 2Like
Reactions:

Simon_9732495

Lt. General
25 Badges
Feb 28, 2020
1.612
4.188
  • Crusader Kings II
  • Crusader Kings III
  • Europa Universalis IV
  • Europa Universalis IV: Rights of Man
  • Europa Universalis IV: Art of War
  • Europa Universalis IV: Common Sense
  • Victoria 2
  • Cities: Skylines
  • Cities: Skylines Industries
  • Cities: Skylines - Parklife
  • Cities: Skylines - Mass Transit
  • Cities: Skylines - Snowfall
  • Cities: Skylines - After Dark
  • Prison Architect
  • Stellaris
  • Hearts of Iron III
  • Hearts of Iron IV: Cadet
  • Hearts of Iron IV: Together for Victory
  • Hearts of Iron IV: Death or Dishonor
  • Hearts of Iron IV: Expansion Pass
  • Hearts of Iron IV: Expansion Pass
  • Hearts of Iron IV: La Resistance
  • Battle for Bosporus
  • Hearts of Iron IV: No Step Back
  • Hearts of Iron IV: By Blood Alone
To calculate it we have to consider the actual number of CIVs that can construct stuff. Here the Consumer Goods ratio as well as eternal factors like trade come into play.
The overall CIV construction speed is the construction speed of 1 CIV multiplied with the number of CIVs that are actually constructing stuff.


c(t) is the number of owned CIVs at the time t
CG is the Consumer Goods Ratio
m_0 is the number of Military factories (MILs) at the start point of the calculation
c_other is the number of other CIVs e.g. from trade, or CIVs constructing other stuff. (Can be positive or negative)

Posting this here helped me find the first major mistake. My testing with trade was rather shallow and this slipped through!

CIVs from trade are of course also calculated for consumer goods factories !!!

Instead of:
1608479529560.png
The equation (3) has to be:
1608479571302.png

Testrun with heavy trade is now off only 0.3 CIVs or less than 1% after 2.5 years.
I will edit the first posting soon to correct it.
 
  • 3
Reactions:

el nora

Colonel
68 Badges
Dec 12, 2016
822
2.485
  • Hearts of Iron IV: By Blood Alone
  • Hearts of Iron IV: No Step Back
It might be relevant to separate c_other into positive civs boosting you and negative civs payed out. Because the civs you pay out are not reduced from consumer goods.

For instance, If you are getting 10 civs from trade and paying out 10 civs in trade (perfect trdebacks, every mp player's dream), and have a 10% consumer goods modifier, you are still 1 civ short of if you had not made any trades whatsoever.
 
  • 3
Reactions:

Simon_9732495

Lt. General
25 Badges
Feb 28, 2020
1.612
4.188
  • Crusader Kings II
  • Crusader Kings III
  • Europa Universalis IV
  • Europa Universalis IV: Rights of Man
  • Europa Universalis IV: Art of War
  • Europa Universalis IV: Common Sense
  • Victoria 2
  • Cities: Skylines
  • Cities: Skylines Industries
  • Cities: Skylines - Parklife
  • Cities: Skylines - Mass Transit
  • Cities: Skylines - Snowfall
  • Cities: Skylines - After Dark
  • Prison Architect
  • Stellaris
  • Hearts of Iron III
  • Hearts of Iron IV: Cadet
  • Hearts of Iron IV: Together for Victory
  • Hearts of Iron IV: Death or Dishonor
  • Hearts of Iron IV: Expansion Pass
  • Hearts of Iron IV: Expansion Pass
  • Hearts of Iron IV: La Resistance
  • Battle for Bosporus
  • Hearts of Iron IV: No Step Back
  • Hearts of Iron IV: By Blood Alone
Just finished a major rework of the first posting in the thread.
I corrected the issues that were brought up and chose a slighty different approach over c_av(t) = CIVs available for construction.
You can easily calculate back and forth between CIVs available for construction and owned CIVs. But the exponential growth formula becomes easier and clearer if written down in available CIVs.
If you are interested, I recommend to read everthing again, because it's really a substantial change.
All formulas and graphs are updated as well...

Sorry for not getting it 100% right at the first try.
 
  • 3
  • 1Like
Reactions:

Harin

General
53 Badges
Jun 8, 2012
1.800
4.035
  • Crusader Kings II
  • Hearts of Iron IV: By Blood Alone
  • Battle for Bosporus
  • BATTLETECH
  • Hearts of Iron IV: Death or Dishonor
  • Stellaris: Synthetic Dawn
  • Age of Wonders III
  • Hearts of Iron IV: Expansion Pass
  • Stellaris: Humanoids Species Pack
  • Stellaris: Apocalypse
  • Hearts of Iron IV: Expansion Pass
  • Stellaris: Distant Stars
  • Shadowrun Returns
  • Imperator: Rome
  • Hearts of Iron IV: Expansion Pass
  • Stellaris: Ancient Relics
  • Age of Wonders: Planetfall
  • Age of Wonders: Planetfall Deluxe edition
  • Age of Wonders: Planetfall Premium edition
  • Age of Wonders: Planetfall Season pass
  • Stellaris: Lithoids
  • Age of Wonders: Planetfall - Revelations
  • Hearts of Iron IV: La Resistance
  • Stellaris: Federations
  • Imperator: Rome - Magna Graecia
  • Crusader Kings III
  • Stellaris: Leviathans Story Pack
  • Europa Universalis IV
  • Hearts of Iron IV: No Step Back
  • Victoria 2
  • Warlock: Master of the Arcane
  • 500k Club
  • Cities: Skylines
  • Pride of Nations
  • Mount & Blade: With Fire and Sword
  • Europa Universalis IV: Common Sense
  • Stellaris
  • Hearts of Iron IV: Cadet
  • Hearts of Iron IV: Colonel
  • Europa Universalis IV: Rights of Man
  • Tyranny: Archon Edition
  • Stellaris: Digital Anniversary Edition
  • Hearts of Iron IV: Together for Victory
  • Victoria 2: Heart of Darkness
  • Victoria 2: A House Divided
  • Supreme Ruler 2020
  • Sword of the Stars
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis IV: Conquest of Paradise
  • Europa Universalis IV: Art of War
@Simon_9732495, your math skills are far beyond mine. Due to that, I do not know if the following question is already answered or outside the scope of what you plan to work on in the future. Please ignore it if it distracts from what your plans are. I would rather not be a distraction and delay your future posts.

Now that you have a formula and spreadsheet you are used to, would it be an easy thing to change some variables and run different graphs? Only if it is easy and you are willing, would you mind showing a graph for the same 44 civs and 32 mils, but with civilian economy and no research, no leader buffs, no trade? Basically a day one scenario, before any PP or research is used?