Author Topic: Population Models  (Read 4655 times)

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Population Models
« on: May 28, 2007, 02:31:16 AM »
So I finally got around to doing something I've wanted to do for a long time now. I had analysed the population growth/death code in Outpost 2 a while back, and had wanted to write a population simulator. I've finally done so. Now, in all the glory that a terminal can display it in, I can calculate the population you would have at any given tick, given the values that determine population growth/death.

I should note that I don't (yet) have a morale simulator, which this is somewhat dependent on, and which would be dependent on other things that can't be simulated quite perfectly. So I basically hacked in a morale setting approximation. I tried a few simple things, like morale decreasing by 5 until 0, where it stayed, and fixing morale at various values, such as 0, 30, 65, 100. I programed in the values from the sheets for each of the 5 morale levels (in particular, the FERT[ility] and DIE rates).

I also get to play around with the number of universities (ok, on/off is all that really matters here), and the number of nurseries, as well as the number of medical centers, and the capacity of the medical centers. The initial population is also setable.


I ran some tests with the initial settings from CES (Colony Eden Starship) and assumed morale started at 50, and droped by 5 on each iteration, which is accurate if you do nothing in that level. I let the simulation go for 150 iterations (which ends at about mark 381), and compared the actual results from doing nothing in the game. The numbers seemed to be right on the whole way through, so the code seems to be good, at least as far as I was able to tell. =)



Results
--------


After playing with the setting on the simulator, a few things became obvious. The morale level has a big impact on population levels. (No surprise there). For instance, by doing nothing on CES (starting with 26 workers, 13 scientists, and 15 children), it takes until mark 1771 for your population to completely die off (but you'd lose before this). If morale is fixed at 30, so it is one level higher, it will take until mark 3842 for everyone to complete die off. If morale was fixed at 100, it would take until mark 6110. This is without ever building a nursery or university, or any medical centers.

If you built a nursery and university (assumed they were there from the start for simplicity), then by mark 2905 everyone would have died off, provided morale dropped to 0 and stayed there. Under the same conditions, but holding morale steady at 30, by mark 2905 you will have 133 workers, 1 scientist, and 97 kids, and by mark 3169, when all your initial scientists would have died off (assuming you don't train any more), you will have 151 workers, and 109 kids. If instead of managing morale (and holding it way up at 30!) you have instead built a medical center, then by mark 2905 you will have 4 workers and 2 kids, and if you upgraded the medical center, you'd have 10 workers and 4 kids.

Also, if your morale is left to drop to 0, you'd need at least 3 (upgraded) medical centers for your population to grow. If you only have 2 medical centers, your population will decrease down to about 38 and then stay relatively stable. With less than 2 medical centers, your population will go to 0. If the medical centers are not upgraded, then you need at least 4 medical centers to stay alive, and the population will stabalize at about 81, but it will take till about mark 43000 to stabilize there. A bit of a wait.

If morale is held at 100, then all your initial scientists will die off by mark 5043, but if you had a university and a nursery that whole time, you will have 43027 workers, and 43129 children. With an unupgraded medical center, that would be 52581 workers, 1 scientist, and 52763 children. If the medical center was upgraded, it would be 61522 workers, 1 scientist, and 62017 children.



Ok, so morale has a big impact on population growth, everybody knows that. Also, what use are these big numbers? Games don't typically run that long.


Let's look at a more interesting question. How long before a medical center increases your population by enough to run the medical center. Think of it this way, you're paying to run the medical center, by having one less worker and one less scientist available to do other things. How long does it take before the population increase from the medical center is enough to cover the cost of running it.

I'll assume by the point they can build medical centers, they will have stabilized their morale, and I'll just assume morale is 100. I'll also assume the medical center has been upgraded by the time it is built. (and that the morale penalty during the period between when you research it and when you get one up and running is not enough to lower your morale by a full level). If at the point the medical center comes online you have 26 workers, 13 scientists, and 15 children, then you will be ahead by 1 worker and 1 scientists in 120 time marks. But you will only be ahead temporarily, and after 135 marks you will only be ahead by 1 worker, and not ahead at all after 138 marks. After 220 marks, you'll be 2 workers ahead, which will suffice if you've trained 1 into a scientist. But again, this lead is only temporary, lasting a whole 2 marks. It takes until 253 marks to be ahead by 1 worker and 1 scientists again, but is still only temporary, this time lasting about 20 marks. The frequency of these small intervals of the medical center paying for itself increase slowly until we are consistently ahead after 453 marks.

Yes, after 453 marks, the medical center will pay for itself full time! What a useless piece of junk! During those 453 marks, you've lost out on the majority of that time on what you could have researched with that extra scientist, or what you could have produced with that extra worker working elsewhere. You're basically most of 453 marks of time worth of work for 2 colonists short of where your opponents could be. Getting caught up with your now slightly higher population, and also you're now slightly faster rate of growth is going to take additional time. Btw, after 453 marks, the populations will have grown to 56 workers, 10 scientists, and 63 kids without the medical center, and 58 workers, 10 scientists, and 68 kids with the medical center.


So, what I've long suspected, the amount of time to catch up on what you've lost out on by staffing a medical center takes a long time to get caught up on again. Considering the typical length of a game, you're pretty unlikely to see the benefits of a medical center. You pretty much have to be playing a high mark game. It seems like there is no point in building a medical center unless you have the people to spare to run it anyways, but if you have people to spare, why do you need more people? And how critical are a few extra workers in a high mark game? I usually don't find there's a big shortage late game.


But, I suppose this is maybe a little unfair to medical centers. If the morale is fixed to be high, then they do proportionally less to prevent deaths. The different should be more remarkable if morale was low for long periods of time. I don't usually experience this, but I suppose if you're killing "good" buildings in a game with unsteady morale, it might happen. In which case medical centers can keep your population growing instead of heading to 0. If morale is fixed at 0 and you build 1 medical center then aside from a short period of 2 marks, the medical center will be consistently paying for itself after 71 marks. That's not too bad. Plus the difference in population you'll soon have will easily make up for the lost time of those 2 colonists.
 

Offline Tellaris

  • Sr. Member
  • ****
  • Posts: 460
Population Models
« Reply #1 on: May 28, 2007, 04:06:19 AM »
Thats one medical center, but how long does it take for two to pay off?
Spell Checker!   The PoWeR tOoL
Click Here For Coolness
Self Proclaimed OPU Help desk.

Offline Arklon

  • Administrator
  • Hero Member
  • *****
  • Posts: 1267
Population Models
« Reply #2 on: May 28, 2007, 10:17:13 AM »
You need to try 3 medical centers. You should see a difference then.
« Last Edit: May 28, 2007, 10:26:25 AM by Arklon »

Offline Leviathan

  • Hero Member
  • *****
  • Posts: 4055
Population Models
« Reply #3 on: May 28, 2007, 10:29:04 AM »
Interesting. Great work :)

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Population Models
« Reply #4 on: May 28, 2007, 08:42:12 PM »
Yes, I did a little experiementing with more medical centers, but I figured the post was getting a bit long so I cut it off there.


I made a few slight upgrades to the output so I can see the differences more easily. Plus I started keeping a running counter of the difference in work potential. That way I can know exactly when the difference in work potentials pay off, and how far behind you got. In other words, I can know not just when your population increases by enough to run the medical centers, but when it's increased by enough beyond that so the extra work you get done makes up for what you didn't get done while staffing the medical centers.


I think I'll start using some simplified terminology to make this a little easier to read. In the following discussion, the only colony state difference will be between having no Med Centers and the stated number of Med Centers. Also, the worker and scientist populations will be agregated, since you have control over when your workers become scientists. So if your population is now ahead by 2 workers, and no scientists, this will be counted as enough to run the medical center, since you can always time the training of a worker into a scientist to end at that given time. (And because scientists don't "grow" on their own, they only die. So to get the required difference from the lower death rate generally takes a very long time).

IR - will denote how many time marks before the medical centers will have increased your population by enough to intermittently run the medical centers. Your population might not hold at the increased level for very long, but this is the point in time where the medical centers start to be run by the population increase they caused.

CR - will denote how many time marks before the medical centers will have increased your population by enough to continuously run the medical centers. At no point beyond this mark will the population increase drop by more than it takes to run the med centers.

WP0 - will denote how many time marks before the worker potential reaches 0. That is, the number of workers difference multiplied by the time. So a +3 worker difference over 2 time marks gives a value of +6. This measures the point at which you'd be caught up on work.

SP0 - will denote how many time marks before the scientist potential reaches 0. Similar to the above, this is how long is takes to get caught up on research. (This assumes no training of workers into scientists).

TP0 - will denote how many time marks before the worker and scientist potential reaches 0, provided some workers were trained into scientists at some earlier point. This attempts to balance the two so they both potentials reach 0 at about the same point. This is somewhat of a guess and requires some experimentation. By training workers into a scientists, the growth and death rate of all population components will change from that point on. (That is, workers die slower, scientists die faster, and children are born slower).

Results
--------

Starting with: 26 workers, 13 scientists, and 15 children, 1 nursery, 1 university, and upgraded med centers (capacity 75).
Morale: Morale starting at 50, dropping by 5 each round to 0, and staying there.

NumMedCenters: 1  IR: 71  CR: 128  WP0: 117  SP0: 353  T0: 166
NumMedCenters: 2  IR: 128  CR: 145  WP0: 153  SP0: 519  T0: 217
NumMedCenters: 3  IR: 148  CR: 166  WP0: 181  SP0: 788  T0: 266
NumMedCenters: 4  IR: 168  CR: 192  WP0: 212  SP0: Never*  T0: 314
NumMedCenters: 5  IR: 227  CR: 250  WP0: 245  SP0: Never*  T0: 366


* The scientist potential never climbs back to 0 since the initial scientist population completely dies off (and no new ones are trained for this value) before they can pay off the difference generated.


Morale: Fixed at 100

NumMedCenters: 1  IR: 220  CR: 453  WP0: 504  SP0: Never*  T0: 704
NumMedCenters: 2  IR: 327  CR: 453  WP0: 527  SP0: ---*  T0: ---*
NumMedCenters: 3  IR: 422  CR: 473  WP0: 568  SP0: ---*  T0: ---*
NumMedCenters: 4  IR: 453  CR: 506  WP0: 596  SP0: ---*  T0: ---*
NumMedCenters: 5  IR: 496  CR: 550  WP0: 632  SP0: ---*  T0: ---*


* --- Didn't bother to calculate these values. They were becomming too much of a pain, and too time consuming.

Offline Tellaris

  • Sr. Member
  • ****
  • Posts: 460
Population Models
« Reply #5 on: May 28, 2007, 10:48:34 PM »
Question:   You said that scientists die off at a faster rate when there is more of them, and that workers die at a slower rate.   Assume default population levels for HIGH resources.   If the player immediately builds a uni, then trains 10 scientists (We will assume nobody died during the intermittent period, and that a nursery is already up or up at the same time), how much would that one medical center help?
Actual values:
67 total
Children 22
Workers 27
Scientists 18
(as of mark 003)
Where if you assume 10 workers to scientists
Workers 17
Scientists 28
« Last Edit: May 28, 2007, 10:50:10 PM by Baikon »
Spell Checker!   The PoWeR tOoL
Click Here For Coolness
Self Proclaimed OPU Help desk.

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Population Models
« Reply #6 on: May 29, 2007, 08:47:42 AM »
Err, workers and scientists die at the same rate. Well, they die in proportion to their number, but equal numbers will give an equal rate. Children die twice as fast as workers or scientists though. Although, if you have a nursery up, it's like having an unupgraded med center for the kids only, so the rate won't be quite twice as fast.


What kind of output are you looking for? Just a dump of population levels at various marks? Or just the end result after so many marks? What point should it stop at? At a certain time? Or at a certain population level?

If you want me to take the training time into account, I expect you to tell me at what point the workers transfer to scientists. (The time when the training completes). I also expect you to tell me the marks when each building become active. If you only tell me what buildings, then I'll just assume they're available from the start.


The raw output I have it producing when comparing two models looks like this:
Quote
Mark:  0 Workers:[ 27| 27] Scientists:[18|18] Kids:[ 22| 22]  Tot:[67|67]
Mark:  2 Workers:[ 27| 27] Scientists:[18|18] Kids:[ 22| 22]  Tot:[67|67]
Mark:  5 Workers:[ 27| 27] Scientists:[18|18] Kids:[ 23| 23]  Tot:[68|68]
Mark:  7 Workers:[ 27| 27] Scientists:[18|18] Kids:[ 23| 23]  Tot:[68|68]
Mark: 10 Workers:[ 27| 27] Scientists:[18|18] Kids:[ 24| 24]  Tot:[69|69]
Mark: 12 Workers:[ 27| 27] Scientists:[18|18] Kids:[ 24| 24]  Tot:[69|69]
Mark: 15 Workers:[ 28| 28] Scientists:[18|18] Kids:[ 24| 24]  Tot:[70|70]
Mark: 17 Workers:[ 28| 28] Scientists:[18|18] Kids:[ 24| 24]  Tot:[70|70]
Mark: 20 Workers:[ 28| 28] Scientists:[18|18] Kids:[ 25| 25]  Tot:[71|71]
Mark: 23 Workers:[ 28| 28] Scientists:[18|18] Kids:[ 25| 25]  Tot:[71|71]
Mark: 25 Workers:[ 28| 28] Scientists:[18|18] Kids:[ 26| 26]  Tot:[72|72]
Mark: 28 Workers:[ 28| 28] Scientists:[18|18] Kids:[ 27| 27]  Tot:[73|73]
Mark: 30 Workers:[ 28| 28] Scientists:[18|18] Kids:[ 27| 27]  Tot:[73|73]
Mark: 33 Workers:[ 29| 29] Scientists:[18|18] Kids:[ 27| 27]  Tot:[74|74]
Mark: 35 Workers:[ 29| 29] Scientists:[18|18] Kids:[ 26| 27]  Tot:[73|74]
Mark: 38 Workers:[ 29| 29] Scientists:[18|18] Kids:[ 27| 28]  Tot:[74|75]
Mark: 40 Workers:[ 29| 29] Scientists:[18|18] Kids:[ 27| 27]  Tot:[74|74]
Mark: 43 Workers:[ 29| 29] Scientists:[18|18] Kids:[ 28| 28]  Tot:[75|75]
Mark: 46 Workers:[ 30| 30] Scientists:[18|18] Kids:[ 27| 27]  Tot:[75|75]
Mark: 48 Workers:[ 30| 30] Scientists:[18|18] Kids:[ 28| 28]  Tot:[76|76]
Mark: 51 Workers:[ 30| 30] Scientists:[18|18] Kids:[ 28| 28]  Tot:[76|76]
Mark: 53 Workers:[ 29| 30] Scientists:[18|18] Kids:[ 29| 29]  Tot:[76|77]
...

The numbers on the left are under one model (usually a base reference model, such as without med centers), and the ones on the right for the other settings.

Oh, and it increments by 256 ticks each round. So 2.56 marks, but I just rounded the values when displaying them.  

Offline White Claw

  • Hero Member
  • *****
  • Posts: 854
Population Models
« Reply #7 on: September 01, 2007, 12:40:58 PM »
Hooman,

Can you tell what kind of population model it is? Is it an unlimited or limited growth model? (Does the population continue to grow or does it stabilize at some point?)

Also, can you tell what kind of factors weigh into the population calculation from your code snooping? Are the death rates tied directly into the growth calculators or are they separate?

I'm trying to work up a model for my OP1 clone and I'd like it to be similar to what is already in place. I'm working on tying elements from OP2 into the model of OP1 (since the population and morale models in OP1 are a bit simplistic/incomplete). I haven't decided yet if I want to model the population with a discrete formula or if I want to model it by tracking of individual colonists. I'm thinking a hybrid of the two with the births based on a growth rate formula but directly linked to actual colonists in existance. (i.e. not every colonist is capable of having a child or is in child bearing years.) I haven't decided how to incorporate the "clone" portion yet either (or if I will at all).

All this being aside, I can see why it might be easier to just fall back to a simple model; prevent the model from spiraling out of control or getting caught up in some sort of random oscillation with too many inputs. But I also don't want births to be so heavily dependent on morale. (Why can't I have high morale AND keep my colony size from exploding!?)

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Population Models
« Reply #8 on: September 02, 2007, 12:29:59 AM »
Well, I remember posting some details once, but they seem to have gone into hiding. It might have only been the death code though. I do remember saying something about fractional deaths, and how Outpost 2 would remember, so it can count it towards your death rate in the future.


The model does seem to be quite unbounded. Once your population gets large, it just explodes. There is a slight growing limit to the rate at which children are trained into workers that takes effect at 160 people though, so there is a little more resistance to growth beyond that point. But by then, the natural growth force of 160 people is already pretty large.


Actually, upon examining my code, I realize there was a slight bug with the clipping of an intermediate value to at least 160. (I had the If condition reversed, as you'd normally see it in assembly code). I guess that sort of invalidates the results I posted above, which were below that 160 clipping point. The difference does seem to be very minor though for small values, but should be a little more exagerated for large values. I'll have to retest though. My results were predicted to be a bit high.


I don't really feel like explaining the model, so here's the code from the population simulator.

Code: [Select]
	// -- Growth --


// New Workers
if (colonyState.active.numUniversities > 0 && colonyState.pop.num.kids > 0)
{
  growth.workers += num.kids;
  divisor = num.workers + num.scientists + num.kids;
  if (divisor <= 160)
   divisor = 160;
  divisor = ((divisor / 40) * 3 + 36) * 4;
  
  newPop.workers = growth.workers / divisor;
  growth.workers = growth.workers % divisor;

  num.workers += newPop.workers;
  num.kids -= newPop.workers;
}

// New Kids
if (colonyState.active.numNurseries > 0 && num.workers + num.scientists > num.kids)
{
  growth.kids += num.scientists / 4 + num.workers / 2;
  divisor = colonyState.moraleLevel->fertRate;

  newPop.kids = growth.kids / divisor;
  growth.kids = growth.kids % divisor;

  num.kids += newPop.kids;
}


// -- Deaths --


// Kid Deaths
if (num.kids > 0)
{
  death.kids += num.kids;
  divisor = colonyState.moraleLevel->deathRate / 2 + colonyState.active.numNurseries * 40 + medCenterCapacity;

  diePop.kids = death.kids / divisor;
  death.kids = death.kids % divisor;

  num.kids -= diePop.kids;
  if (num.kids == 0)
  {
   death.kids = 0;
   growth.workers = 0;
  }
}

// Worker Deaths
if (num.workers > 0)
{
  death.workers += num.workers;
  divisor = colonyState.moraleLevel->deathRate + medCenterCapacity;

  diePop.workers = death.workers / divisor;
  death.workers = death.workers % divisor;

  num.workers -= diePop.workers;
  if (num.workers == 0)
   death.workers = 0;
}

// Scientist Deaths
if (num.scientists > 0)
{
  death.scientists += num.scientists;
  divisor = colonyState.moraleLevel->deathRate + medCenterCapacity;

  diePop.scientists = death.scientists / divisor;
  death.scientists = death.scientists % divisor;

  num.scientists -= diePop.scientists;
  if (num.scientists == 0)
   death.scientists = 0;
}


Edit: I take that back about the population explosion. I started wondering how that continual increase to the resistance of the population growth might affect things, particularly for large numbers, so I ran a few tests with about 5000 colonists and 10000 colonists, and I'm actually seeing a net decrease in population levels. This is with morale fixed at 100. From what I can see, the number of kids grows very quickly, and then halts, since the number of adults must be at least as large as the number of kids to allow further growth. At that point, the extremely high death rate associated with such a large population takes over and trims it down quite fast. You never really achive any population growth due to a lack of adults in relation to the number of kids, and if there is any temporary growth, it's reversed pretty fast due to the high death rate associated with having that many kids from the initial baby boom. What tends to happen is that the number of kids and the number of adults spirals down at about the same rate. I found population levels tended towards a little over 1600, for both small and large initial populations. I tested in the range 50 to 100000 initial people, and simulated for 20000 marks, and the results where always in the same ball park.

For lower morale levels, the population will tend to different values. For morale of 25 or less, it'll go to 0. For morale of at least 26, it'll stabilize at about 840. The above tests were without med centers, which do increase the stable population level. Having just 1 med center increases the stable level to just under 1900 people.
 
« Last Edit: September 02, 2007, 01:11:42 AM by Hooman »

Offline White Claw

  • Hero Member
  • *****
  • Posts: 854
Population Models
« Reply #9 on: September 03, 2007, 02:00:24 PM »
All very interesting. I sat and pondered the moral code this weekend and how much I wanted it to tie directly into the population model. The two things I want to get away from is the uncontrollable growth of the colony (early game) and then the population limit.

Thanks for the code of the growth and death rates. That helps a bunch. I starting to lean toward a weighted system that also takes into account the space available (residence) as well as food available (agri). I didn't want the growth rate to be driven almost 100% by morale. I would think you could have high morale without having an explosion in population.

Where'd you get all this code from? Did you decompile the code or is this your own "recreation" based on the asm code?

Good work! Thanks...

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Population Models
« Reply #10 on: September 03, 2007, 02:03:48 PM »
It's my own recreating from reading the asm code. Hence why it actually had a bug, but it fairly readable.
 

Offline White Claw

  • Hero Member
  • *****
  • Posts: 854
Population Models
« Reply #11 on: September 04, 2007, 09:41:19 AM »
I find it interesting that the number of active nurseries has an impact on the child death rate. I guess that gives some reason to have a few extra nurseries or medical centers (since they affect everyone). I suppose it all has limitations as you already described though...  <_<