Author Topic: Population Model  (Read 19144 times)

Offline IDMclean

  • Newbie
  • *
  • Posts: 4
Re: Population Model
« Reply #25 on: July 04, 2016, 01:12:25 PM »
Okay, I did a rough check. I didn't keep track of when I landed my population, but I did start keeping track of the infants born; I am conducting this on Beta Hydri 1 which has a AU of 1 from the star, so it should have a year comparable to Earth; I will be conducting a second test on a 1.52 AU planet and on at least one planet with a distance farther than 1.52 AU from its star.

My first infants (6 from non-infant 48 pop and a total pop of about 54) were born around turn 25. My second set of infants (8 from about non-infant, non-student 44 pop and a total pop of about 58) were born on turn 37. That's 12 turns between the first and the second, so I think it is safe to assume that a turn is about 1 Earth month for the purposes of the Outpost population model on 1 AU planets.

I'll be tracking exact population numbers and distributions per turn on subsequent tests.

Update: Testing on 82 Eridani 1, Site 5 at 1.52 AU from its star. I lost 1 colonist on turn 19-20. I landed my colonists on turn 20 (0 infants/13 students/18 workers/18 scientists/0 retired). Lost 1 colonist for turns 22-23 (0/13/18/17/0), 23-24 (0/13/18/16/0), 24-25 (6/13/9/24/0), and 25-26 (6/13/9/23/0). The second set of infants were born on turn 36-37 (15/0/22/23/0). Infants were reliably born every 12 turns from that point on for at least 61 total turns (32/0/22/23/0).

So we can conclude rather soundly that the basic temporal model for Outpost's population model is based around a yearly cycle. This would imply that a turn is either 1 month and the infants that are born are not necessarily new borns by the time they're reported in the model, or it implies that 1 turn is about 1/12th of a 40 week gestational period or about 3 and 1/3rd weeks in length. This produces absurdities for the production times of various objects (fuel cells are produced about 1 per year or 1 per 2/3rds of a year) and the movement times for trucks over tiles.

I would say based on my experience with game designs and the game design process that this is due to a failure to pick and develop a temporal model during their initial prototyping process. Outpost was not finished when it shipped, and I think this is one of the major places where it shows.

If turns are equivalent to 1 week then a new population can be added for every 2 non-infant, non-student population every 40 turns. Simple model would have a maximum of 1/2th the total non-infant, non-student population in a 40 turn period.

If turns are equivalent to 4 weeks then a new population can be added for every 2 non-infant, non-student population every 10 turns. For a simple example a population of 100 productive members could produce 50 infants in 10 turns.


You would want to actually use a fertility rate and a gestational mortality (spontaneous abortions or miscarriages, infant mortality, maternal mortality) rate. Agrarian pre-contraception societies have a fertility rate of about 6, and most modern societies have a fertility rate of about 2.1 or lower; the fertility rate is the number of children born to the average woman in her lifetime, so a fertility rate of 6 is 6 children per woman per her total lifetime. A fertility rate of about 2.1 is just above sub-replacement and grows slightly; a fertility rate below 2 causes the population to diminish over successive generations towards extinction.
« Last Edit: July 04, 2016, 04:36:11 PM by IDMclean »

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2352
  • OPHD Lead Developer
    • LairWorks Entertainment
Re: Population Model
« Reply #26 on: July 07, 2016, 12:32:55 PM »
Quote
so I think it is safe to assume that a turn is about 1 Earth month for the purposes of the Outpost population model on 1 AU planets.
Quote
So we can conclude rather soundly that the basic temporal model for Outpost's population model is based around a yearly cycle.

Yup. This is stated in the official strategy guide.

Quote
I would say based on my experience with game designs and the game design process that this is due to a failure to pick and develop a temporal model during their initial prototyping process.

I would agree. I wanted to pick a clean temporal model for OutpostHD as well but kind of abandoned that during the initial development. However, because resource trucking and processing hasn't been fully fleshed out or fully developed, this is still a case where it can be settled on (as discussed in the resource trucking topic). I also thought of building construction in terms of months... e.g., if a building takes three turns to complete, it's effectively a 3 month process. Obviously in the case of landers it doesn't take a month to land them but for the SEED Lander it can be seen either as it took roughly a month for the lander to land, robots to be deployed and initial structures to be started. Or we can just pretend that that first turn doesn't really count for anything other than progressing the game forward.

Quote
For a simple example a population of 100 productive members could produce 50 infants in 10 turns.

At first I thought this was far too high but then realized that this is in an ideal situation where there is no infant mortality or parent mortality. It also doesn't include colonist mortality rates in general so this seems like a reasonable set of numbers.

Quote
You would want to actually use a fertility rate and a gestational mortality (spontaneous abortions or miscarriages, infant mortality, maternal mortality) rate.

Naturally. This is something that would be influenced by difficulty and planetary hostility rating.

Quote
so a fertility rate of 6 is 6 children per woman per her total lifetime.

This is about what the Outpost strategy guide states... at least for the first 60 turns or so. After that it drops down to roughly 3 or 4. I'm not entirely sure how to set that up without special case code but if I play with the math a bit I'm sure I'll figure it out.

This is also something that should be affected by difficulty and planetary hostility rating.

Offline IDMclean

  • Newbie
  • *
  • Posts: 4
Re: Population Model
« Reply #27 on: July 21, 2016, 04:37:08 AM »
Realistically, various social policies and soci-economic conditions would also influence growth rates in the population model. Access to universal contraception and abortion services, comprehensive sex education, poverty (which tends to increase birth rates) or abundance (which tends to decrease birth rates), access to economic means such that a real decision can be made about children vs luxury living, and social support for parenting such a universal child care facilities and services.

In 4X games, they tend to simulate that complexity with some kind of happiness or colonial approval measure. The simple model tends to be that high happiness results in population booms and low happiness adversely effects growth and resource productivity. Happiness tends to be tied to a tax rate, but I highly encourage you to develop the OutpostHD model independent from a capitalist model of monetary exchange. Environmental (presence or absence and type of atmosphere, proximity to star, star spectrum, primary composition of the planetary crust, and similar conditions), economic (mineral, food, power, residential availability, education, and other goods and services), and social factors though should be ultimately implemented on top of the population model and interact with it.

We can really break down the more complex stuff into those three major factors, I think. Environment. Economics. Social Policy. Recently, I have been playing a game called Democracy 3 which I think is worth looking at for inspiration of how to handle the interaction between those things in a relatively simplified way. You could probably even strip down the mods for it to look at the code for study.

An economic value can likely be derived from comparing the relative resources available to the number of colonists you have. A general resources per capita measure would be useful, i think. I tend to think that having huge excesses of resources per colonist is not great generally; imagine 50 people living in a mostly unused shell of a colony built for millions of people. A ghost town. Resource shortages are kind of obvious in their impact on the health and well being of colonists. A robust model would have a way of automatically deriving [RESOURCE] per pop statistics for each resource added in the basic game or for extensions by mod.

I would encourage you to check out 4X conquer the galaxy type games. I tend to think that Endless Space has a interesting basic model; there's a lot of things I don't like about it, but the FIDS and approval systems are worth examination, and they play around with the basic mechanics a lot from faction to faction. I especially encourage you to check out the Harmony faction; they eliminate the game's equivalent of money (Dust) and approval and focus on Food, Industry, and Science; I tend to disagree with their basic approval model, but it is also worth examining if you're going to implement your own.

I will always have a special place for Sid Meier's Alpha Centauri. I loved its social policy system and future society techs that allowed for mixing and matching your own particular social model.

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2352
  • OPHD Lead Developer
    • LairWorks Entertainment
Re: Population Model
« Reply #28 on: July 21, 2016, 03:30:10 PM »
Quote
Realistically, various social policies and soci-economic conditions would also influence growth rates in the population model. Access to universal contraception and abortion services, comprehensive sex education, poverty (which tends to increase birth rates) or abundance (which tends to decrease birth rates), access to economic means such that a real decision can be made about children vs luxury living, and social support for parenting such a universal child care facilities and services.

True, though I wonder really in the case of Outpost how much the population growth rate would match what it is in Earth today. From the manual and strategy guide, these are smart people (mostly scientists and engineers) that understand the need to procreate in order to produce enough of a population to sustain the last bastion of humanity. This basically leads to people that would normally have no children or only one or two to have many more, say 6 to 8.

After about 60 turns, or 5 years, according to the manual and strategy guide this rate drops down to 3 - 4. I'm thinking to follow a similar model and then maybe later drop it even further down and go for a growth rate that more closely follows what we see on Earth. After say, 20 years or so, the population would very much have slowed down and you now have the second generation of colonists that are producing children. Couple this with an education level, crime rates, residence capacities and a myriad of other factors... damn, this is kind of a complex model isn't it? A lot of variables to think about and account for. Going to start putting these variables into a Redmine task as I develop the prototype.

Quote
Happiness tends to be tied to a tax rate, but I highly encourage you to develop the OutpostHD model independent from a capitalist model of monetary exchange.

That would be Morale, a factor in both games. In Outpost, the morale level could range between 0 and 1000 starting at 600. In Outpost 2, the range was 0 to 100 and starting was whatever the current mission would set it to.

Anyway, I'm thinking of leaving Morale is the major value players need to pay attention to. Happy colonists mean productive colonists. Unhappy colonists means low productivity and an almost inevitable failure.

Quote
Environmental (presence or absence and type of atmosphere, proximity to star, star spectrum, primary composition of the planetary crust, and similar conditions)

To simplify this part of the model, this can be boiled down to a single value based on planet type. I'm changing the planet selection stage a bit from the original game. Instead of packing a ship and choosing a star, you instead get a choice of planets. Basically, it fast forwards to the planet selection stage of Outpost but you get more planet choices immediately.

Anyway, back on topic, the planet types themselves would determine all of those factors so that would be known ahead of time. The question is in finding a scalar value which affects the Morale level. Morale is pretty much the value in the population model that really matters -- of morale is low, you have much lower birth rates, much higher death rates, much lower production rates (both factor and laboratory), crime rates tend to soar, etc.

Quote
We can really break down the more complex stuff into those three major factors, I think. Environment. Economics. Social Policy.

Agreed, but I have to ask, what does social policy involve? Environment is easy -- planetary hostility + our impact on the environment + terraforming projects (basically like Outpost 1, it changes the atmosphere making the planet more hospitable on planets that can sustain an atmosphere). Economics is also simple enough -- availability of resources and food, residential capacity, medical capacity, education level and unemployment rates.

Social policy has me kind of scratching my head though -- I'm not sure what factors would be involved in this.

Quote
I would encourage you to check out 4X conquer the galaxy type games.

I've played and enjoy many but I'm not really sure how they fit into this game. Outpost has a lot of similarities to 4X games but it's ultimately a city construction and population management simulation game. Borrowing from some 4X games, on the other hand, intrigues me. Unfortunately I'm a better programmer than I am a designer. -_- But I'm entirely open to suggestions and thoughts about how we can make OutpostHD a fun and interesting game to play.

Quote
I will always have a special place for Sid Meier's Alpha Centauri.

This is an amazing game. I still enjoy playing it to this day!

Offline IDMclean

  • Newbie
  • *
  • Posts: 4
Re: Population Model
« Reply #29 on: July 21, 2016, 08:28:41 PM »
http://strategywiki.org/wiki/Sid_Meier's_Alpha_Centauri/Social_Engineering or http://alphacentauri2.info/wiki/Social_Engineering we can use this as a common reference between us for discussing social policy modelling.

We can talk about birth or growth policies specifically to start with. When you arrive at the planet, there is a default growth policy in effect which greatly increases birthrates for the first 60 turns (5 or 6 years based on the manual and experiment). After the colony reaches a point of stability, the growth policy can be more of a detriment than an assist while you tool up for the massive excavation projects necessary to house rapidly growing population. The default behavior is for the growth policy to change after that duration to a lower growth rate and stay there.

This can be left static or the player can influence it directly as part of trying to control the complex of interacting variables. In Alpha Centuari, you have four different parts of a matrix that defines your social model. Politics, Economics, Values, and Future Society. They are further subdivided in to specific social policy models. Politics has Frontier, Police State, Democratic, Fundamentalist. Economics has Simple, Free Market, Planned, and Green. Values has Survival, Power, Knowledge, Wealth. Future Society has None, Cybernetic, Eudaimonic, Thought Control. You can mix and match from the four different parts, so you can have Democratic, Planned, Power, Thought Control society or a Police State, Green, Knowledge, Cybernetic society. They change a complex of variables and can greatly change the way that you develop your society's infrastructure.

SimCity 2000 has comparable features that correspond to social policies including a complex taxation system for controlling what kinds of growth occur in your city. http://simcity.wikia.com/wiki/SimCity (Incidentally, http://www.donhopkins.com/home/micropolis/ is the open source version of the SimCity Classic engine.)

Democracy 3 implements social policies as groupings of variable relationships which can be effectively be positively or negatively impacted by adoption or abolition of the policies; the policies generally can be adopted as a sliderbar that represents a spectrum of possibly discrete states between either no implementation or negative implementation to complete implementation. They form feedback and control systems between dynamic interdependent or networked statistical models; the colony command facility and associated popup forms the first part of the feedback and control system. Example social policy: abolishing birth control.

For Outpost, I always liked the fact that you were not just rebuilding the culture of Earth on some far away colony, but you are building a future society that starts out with similar technology of the 1990s Earth then you rapidly diverge off into a very different society. A big part of that is deciding whether to go totalitarian to survive or instituting the glorious socialist revolution.

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2352
  • OPHD Lead Developer
    • LairWorks Entertainment
Re: Population Model
« Reply #30 on: July 21, 2016, 09:59:53 PM »
Okay, so, I'm building a prototyping program now to simulate the numbers with given inputs. With it numbers can be tested with a constant morale, given university, medical facility and resource values. Different starting population configurations can be provided and different environmental factors, etc.

But I'm finding it difficult to come up with a formula to take into account all of these things and then modify population values accordingly.

We know the following facts and assumptions:

Populations tend to be fairly evenly split in terms of binary genders. I'm unconcerned with current social issues regarding gender identity, sexual identity, sexual orientation and gender fluidity. While these are important issues, they are irrelevant, I think, to this sort of game. Ultimately if humanity was thrust into such a situation the end result would be those who can bear children will be expected to do so else have humanity go extinct.

So a 50/50 split is assumed.

Population is split into the following categories:

  • Children
  • Students
  • Workers
  • Scientists
  • Retired

These come from the original game and ultimately makes sense in terms of a population.

The following assumptions can be made about the population:

  • ChildrenRepresents a population that only consumes. These cannot be used for work and certainly do not produce more population.
  • StudentsThis is the population in school and can be thought of as the people from age 6 - 18. This is up for debate as they can also be considered young adults that can also be used as workers.
  • WorkersThis is the age group between 18 - 50 and represents an adult population that can also produce additional children.
  • ScientistsThis is the age group between 18 - 50. This group can also produce children. The number of scientists is affected by morale and available university capacity.
  • RetiredThis is the population basically over 50 and represents the population of humans that are no longer producing children or are part of the work force.

These numbers are very much up for debate -- I can also see children being ages 0 - 15, students being 15 - 25, workers being 16 - 50 and scientists being 25 - 50. Outpost 1 did the student-->Scientist automatically but I like Outpost 2's idea of explicitly training scientists out of the Workers group. Scientist training would run 5 - 10 years (60 - 120 turns).

This is what I've got at the moment... this is turning out to be a lot harder than I anticipated. It would be very easy to do this using a series of objects representing people considering the myriad complexities involved in this but as Hooman and others have stated, doing so raises the amount of memory required to do this and with very large populations can be very slow. This is where my weakness in math starts to take its toll.

On the other hand, I'll need to start doing some work on paper because I think this can be done using numerical models.

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Re: Population Model
« Reply #31 on: July 25, 2016, 01:59:00 PM »
Quote
I think this can be done using numerical models
:)

*thumbs up*

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2352
  • OPHD Lead Developer
    • LairWorks Entertainment
Re: Population Model
« Reply #32 on: July 26, 2016, 10:40:37 PM »
So it can be done using numerical models but I'm finding it exceedingly difficult to make it work. Perhaps I'm stuck in OOP mode but it would seem a lot easier to think about these as individual objects each considering age, gender, health and role.

When I did some basic math, since only a few values are stored, roughly 10,000 'person' objects with three int's and one bool will only really take up a few hundred KiB of memory (140 for the raw info itself) with a bit more for vtables and whatnot. E.g., a 'person' object costs a bit more memory than just the sum of its parts.

Anyway, point being I tested it with up to 30,000 'person' objects and found that the program only takes about 1.5Mib memory (not sure why so much) but ultimately in the grand scheme of things it's a negligible amount of memory for handling this. Also, it runs through the objects very fast, withing a few nanoseconds to update each individual person object in  group of 30,000. I suspect late games to have somewhere in the realm of 4 - 5K populations, I don't really know why the would get any larger than that, if that.

Okay, so, here's the real problem. Savegames.

If I went minimalistic with the population saving information, it would look something like this in XML:

Code: [Select]
<person age="400" health="100" gender="0" role="2" />

With 30,000 population we're looking at a savegame size of 1.6MiB not accounting for other information including structures, etc.

Not sure if I should just go the route of writing out that information as human readable XML (could take awhile to save and load due to DOM processing) or if I should just write it out as a binary stream and save that between <population></population> tags (reduces 30,000 population to a little under 500KiB).

I know this one is really super 100% technical but it's kind of a reasonable thing to consider earlier on. I may simply go with human readable XML for now, can always add binary output later... it's not like storage space is at a premium anymore.  :-\

Offline UtopiaPlanetia

  • Newbie
  • *
  • Posts: 25
Re: Population Model
« Reply #33 on: July 26, 2016, 11:54:47 PM »
Is modeling individual health an important feature? I've seen population models using systems of differential equations (e.g. https://en.wikipedia.org/wiki/Lotka%E2%80%93Volterra_equations). The models don't care about the individual. Then, you only have to save a few variables including the time, current population count, and some parameters instead of thousands of objects.

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2352
  • OPHD Lead Developer
    • LairWorks Entertainment
Re: Population Model
« Reply #34 on: July 27, 2016, 01:14:35 AM »
Therein lies my difficulty. Sure, by using a formula like this I could reduce all of this down into just a handful of variables. Which is cool and all, but I'm not entirely convinced I'd be able to properly track things like children to adults (workers), workers to scientists (training is on an as needed basis) and adults to retirees.

The individual health is gradually reduced and as it gets closer to 0 chance of death is much higher. It's less a matter of state of health vs. a chance modifier which can be adjusted based on whether or not the person is starving, receiving adequate medical care, general stress levels (though this would be generalized based on crowding conditions and overall morale) and a few other factors.

I'm also still considering adapting it to work more like it does in some of the Sim and Tycoon games where you can actually track individual people. I haven't completely decided on this so for now this allows me the option to do that in the future.

Lastly, I'm having a hard time really admitting my failure to understand abstract mathematical models. I suppose my mind just isn't built for that, I look at things in more real-world ways as objects and their relationships to each other. I see the advantage in a somewhat more complex model of the population. As Hooman has pointed out earlier when you start getting larger groups it almost doesn't matter... so that's why I'm posing it here as a discussion because I see the potential in going for the less efficient (but much easier to understand) model or the more abstract and more efficient methods.

Really has me scratching my head again.

Offline UtopiaPlanetia

  • Newbie
  • *
  • Posts: 25
Re: Population Model
« Reply #35 on: July 27, 2016, 02:47:55 AM »
If you are going for the group models, would this be plausible?

childPopGrowthRate        = birthRate - childDeathRate - toStudentRate
studentPopGrowthRate   = toStudentRate - studentDeathRate - ( toWorkerRate + toScientistRate )
workerPopGrowthRate    = toWorkerRate - workerDeathRate - workerToRetiredRate
scientistPopGrowthRate  = toScientistRate - scientistDeathRate - scientistToRetiredRate
retiredPopGrowthRate     = workerToRetiredRate + scientistsToRetiredRate - retiredDeathRate

toStudentRate is the rate that children become students.
toWorkerRate is the rate that students become workers.
toScientistRate is the rate that students become scientists.
workerToRetiredRate is the rate that workers retire.
scientistToRetiredRate is the rate that scientists retire.
The other rates should be obvious. Everything right of the equal sign will probably not be a constant values, will change depending on number of resources, number of buildings, random disasters, etc. Everything left of the equal sign will be used to calculate the population count. Pop1 is the current population, Pop2 is the new population after the turn.

childPop2        = childPopGrowthRate + childPop1
studentPop2   = studentPopGrowthRate + studentPop1
workerPop2    = workerPopGrowthRate + workerPop1
scientistPop2  = scientistPopGrowthRate  + scientistPop1
retiredPop2    = retiredPopGrowthRate  + retiredPop1

currentPop = childPop1  + studentPop1 + workerPop1 + scientistPop1 + retiredPop1
newPop = childPop2 + studentPop2 + workerPop2 + scientistPop2 + retiredPop2
« Last Edit: July 27, 2016, 03:01:09 AM by UtopiaPlanetia »

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Re: Population Model
« Reply #36 on: July 28, 2016, 07:39:08 PM »
Quote
... workers to scientists (training is on an as needed basis)
That's the easy one. The user controls the training. There is no growth model there.  ;)

Sounds like you're afflicted by the mental laziness bug. There's something you don't yet understand, and you want to be lazy and avoid doing it, and thus avoid learning something new and unfamiliar. Quite a serious illness really, affecting millions of people. I'm afraid it's terminal.

Keep in mind the actual model doesn't really matter that much. It doesn't need to be realistic. It just needs to be fun. If people enjoy something, they'll invent their own reasons why it's the way it is. Worry more about the effect you're going for, rather than trying to reason about what should happen.

I have some thoughts on building a population model, including the math, and techniques to tweak the numbers. It's taking a while to formalize and really nail down the core concepts though. I try to post the details in a day or two.

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2352
  • OPHD Lead Developer
    • LairWorks Entertainment
Re: Population Model
« Reply #37 on: July 28, 2016, 09:33:26 PM »
Quote
Sounds like you're afflicted by the mental laziness bug.

Yes and no. First and foremost, my abstract math skills are weak. This is something I can fix by simply doing the math and really understanding it and just practicing.

No because normally I would, but I simply don't have the time to do it. Work has me slammed all the time and mentally drained all the time so when it comes to really putting the time to understanding something difficult like that, ya no, I take the easy way out.

Plus, as stated when I think about certain other games like SimTower, SimCity (new SimCity), Roller Coaster Tycoon and others they do actually keep track of individuals as collections of objects. I guess ultimately when it comes down to when I play the games I don't always go inspecting each of the potentially thousands of individuals but I can see a lot of potentially cool things that can be done by doing it this way.

Quote
Keep in mind the actual model doesn't really matter that much. It doesn't need to be realistic. It just needs to be fun.

Yes. After talking to a few non-programmer friends, I opted to skip the complex mathematical model and go for the object based model as 1) I have a much firmer grasp of it and 2) it'll ultimately produce the results that I want.

So on that note, I've started building a prototyping program that allows me to see how numbers work together. I haven't yet added in mortality rates, difficulty settings or various other variables that would influence birth and death rates so people continue to age indefinitely until the great mediator Food runs out. In the screenshot once food runs low you get mass die off's... and as you can see it usually leaves only a few kids to fend for themselves.  :o

This is with the aforementioned design of looking at the population as collections of individuals. I have a few values in there I call 'jitter' values that are applied to birth mechanics. This basically randomizes how many kids are born and when by randomizing a bit the rate of conception in female's. This is where things like morale, birth rates and such start to kick in but the way I'm doing it now is that female's have a minimum and maximum birthing age (geez this sounds more and more like I'm some masochistic asshole seeing women only as baby makers... but I suppose in this particular case that's kind of an important function that they kind of sort of need to do this).

Anyway, minimum age is 20, max is 45 so that gives women a 25 year window into which to produce children. The base spacing between conceptions is 18 months (generally speaking it's very bad for health to pop one child out after the next immediately after a pregnancy and modern doctors recommend children no sooner than 18 months after a pregnancy... I've reduced this to no sooner than 9 months as this is kind of a dire situation). Anyway, the jitter value can increase this up to 4 years which would lead to roughly 6 kids per female per peak reproduction years on the minimum and up to 16 kids for someone really getting busy. I'll want to play with these values some.

Bleh, anyway, once I add in the death and mortality rates (things that kill colonists besides starving) I expect to see very different values (e.g., at turn 1215 I'm probably not going to have 50000 colonists with 1600 or so 80+ years olds).

Of note:

As I put this together in the prototyping program, I broke logic down into a number of functions and realized that all of these could easily belong to a Population class... which means that the implementation of the Population itself can be switched out for whatever system works the best with no changes to the rest of the game. Which I like... modularity... this is what OOP was designed for.

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Re: Population Model
« Reply #38 on: July 31, 2016, 05:09:00 PM »
Ok, so here are some thoughts for developing a numerical model, such as for population growth.

Start from a simple idea. Numbers grow over time. They should not grow too slow, nor blow up too quickly. For population, you'll probably want a bit of an accelerating growth as the game goes on. Think of a gently upward curving graph, with time along the x-axis, and population along the y-axis. There are many formulas that will produce such an upward (concave up) curve. Two types of equations that immediately come to mind are quadratics (such as x^2), and exponentials (such as e^x). Exponentials are often used to model population growth, so they make for an obvious choice here. We have yet to specify a property that requires exponentials though, and much of this discussion will be generic to other numerical models beyond just population. For the sake of the initial discussion it really doesn't matter, the only requirement so far is a gently upward curving graph, so we'll consider both the quadratics and exponentials. We'll even expand on this a little and consider higher order polynomials, and non-integer powers of x.

Some examples would help at this point. Try looking at a few formulas in an online graphing calculator. We can start by looking at some base formulas. Try entering the following (you can graph them all on the same graph):
e^x  (exponential)
x^2  (quadratic = polynomial of order 2)
x^2 +x+1  (quadratic = polynomial of order 2)
x^3  (cubic = polynomial of order 3) (this one has an inflection point = a change in concavity)
x^3 -x^2 = x^2 (x-1) (cubic = polynomial of order 3)  (this one has a dip, which would be a bit weird for population growth)
x^1.1  (any fixed exponent strictly greater than 1 will produce an upward curving graph)
x^0.5  (square root function, concave down, just for fun)
x^10000  (very sharp bend, concave up, resembling the bottom and right sides of a box)
x^0.0001  (very sharp bend, concave down, resembling the left and top sides of a box)

Aside concerning x^n:
If n was 1, there would be no curvature. You'd have a diagonal line. It n was stricly geater than 1, including non-integer values, the curve will be concave up. If n was between 0 and 1 it would be concave down. Such a concave down curve will still always be increasing, just at ever slower rates as x gets large. Higher exponents produce more dramatic changes in the steepness of curves. As the exponent increases to approach infinity, the bend approaches a sharp corner, looking like the bottom and right edges of a box. As the exponent decreases towards 0, the bend again approaches a sharp corner, looking like the left and top edges of a box. Note that 0^n = 0 for any n, and 1^n = 1 for any n. All the simple powers of x will pass through the points (0, 0), and (1, 1). The curve will start out slow near 0, and start getting quite steep by 1.

You'll notice all these graphs get very steep very quickly. Remember, we want gradual controlled population growth, not babies exploding out of airlocks. Zoom in on the graphs where they are still gently curving up. What we'll want to do is transform this small zoomed in area and expand it to match the time frame and expected population levels of the game.

For simple fixed powers of x, the area between 0.0 and 1.0 will be of most interest. Already by the time x = 1, the curve will be quite steep. Perhaps uncomfortably so for a population curve, making it difficult to manage. For x^2, the part up to about 0.5, or perhaps even as low as 0.3 looks much better.

For the exponential equation, the area where x is negative will be of most interest. The point when x = 0 looks to be about the point where managing a growing population starts to be difficult and will soon be vexing and tiresome. For e^x, we can take the graph from about -3 to 0.

Next we need to define some sort of target area for time and population. Some thought needs to be given to the unit of time. In Outpost 2 for example, there are game ticks, game marks (100 ticks), and the time period during which population adjustments run (every 256 ticks, or 2.56 marks). You might also use a real time measure, such as seconds, minutes, or hours. Perhaps the most natural unit of time is how often the population algorithm runs, or 2.56 marks. Let's say an average game should last 2560 marks, then there are 2560/2.56 = 1000 population increase intervals during an average game. (Not all of them will produce new people). Our desired time scale for the population graph is then 1000 time units (calls to the population algorithm). To win a game, you need at least 200 colonists. There may have been some setbacks though, and the player doesn't always launch the spaceship right away, so to account for this, let's say population = 220 at that point. We'll then want to transform the equation for the graph to match up the origins, scale the x range (time) so it ends at 1000, and scale the y range so it ends at 220.

For a turn based game like Outpost 1, the natural unit of time would be 1 turn, which is also how often you should call the population growth code.


This is getting a bit long, so this is probably a good place to cut it. Join us next time for graph transformations. We'll discuss the math behind matching up the origins, scaling in both the x and y, and identifying a starting population level.

The topic after that, will be some Calculus. We'll talk about the pesky time aspect of the equations, a bit about derivatives, numerical integration, and build a case for using an exponential function.
« Last Edit: August 02, 2016, 06:33:33 PM by Hooman »

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2352
  • OPHD Lead Developer
    • LairWorks Entertainment
Re: Population Model
« Reply #39 on: August 02, 2016, 06:03:19 PM »
And about half way through and my eyes glazed over. I genuinely don't understand this even after having read it 4 times.

Odd how I can design and architect an entire complex system but what ought to be simple math is just beyond my understanding.
« Last Edit: August 02, 2016, 06:30:28 PM by leeor_net »

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Re: Population Model
« Reply #40 on: August 02, 2016, 06:32:56 PM »
Did you try out the online graphing calculator?

Any terms you'd like me to elaborate on?

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2352
  • OPHD Lead Developer
    • LairWorks Entertainment
Re: Population Model
« Reply #41 on: August 02, 2016, 06:45:52 PM »
It's not terminology that I'm not understanding, it's putting it all to practical use. I guess for me the hard part about working with numerical models is that they are abstract in a lot of ways. On the other hand, I think in purely relational ways, e.g., objects and how they relate to each other. On occasion I use mathematical models because I have to and most of the solutions I come up with are clearly just me plodding through and coming up with something that's 'good enough' and leaving it at that.

It's very likely the reason I can't for the life of me come up with fragment and vertex shaders. 3D geometry is whatever, I can deal with that. Scenegraphs and world trees and all of that is simple enough.

Come up with actual equations and formulas that deal entirely with numbers and nothing else? Now you've lost me. As I've stated in the past and probably will long into the future, I'm very, very weak with applied mathematics so when I see these kinds of formulas I leave it up to those who understand the math and take their word for it.

FFS, I can't even figure out basic matrix math. I think it's lead me to some seriously bad formulas and in some cases horribly inefficient code. Look at my mouse picking code for OutpostHD, for example. You know how I do it? Using a lookup table. It WORKS, but it's by no means elegant. An elegant approach would simply use a mathematical approach but I literally have no idea how to do it. I've looked at the mouse picking code for OpenXCom and ... it literally makes no sense (it's also somewhat inaccurate but generally does the job). And yet, I just KNOW that there's a way to mathematically and elegantly do isometric mouse picking without resorting to a brute force approach.