pioneerspacesim/pioneer — pull request #3243 by impaktor (2014-11-10 17:29:35+00:00)
Title: A smarter ShipMarket in SpaceStation

## "Moar" plots!

I know, I know, only I care about this, but I'd like to describe what I've done, and show how it works, and I find plots to be the best way to investigate overall behavior. This fixes #3221 (and makes use of Poisson numbers #3242, see @fluffyfreak, not merged in vain :wink:.)

## Old rules for ShipMarket size

The system currently in use works like so: Always add or remove one ship advert every hour. If 0 ships, then add 20 ships.

## New rules for ShipMarket size

New system models each ship market on each station separately, allowing each to have its own dynamics.

Surface stations have 1.5 more ships in ship market, since there's more space to house all the ships, compared to an orbital station. I choose this "excuse" since I think there should be an incentive for the player to visit ground stations. They should be "bigger". More commodities in stock (something for another PR) and more ships in market (this PR).

Ship adverts have a half life of 7 days (i.e. after 7 days half of the adverts are gone, if no new have been created), for both orbital and surface stations.

ShipMarket size is determined by population of planet it belongs to. The minimum is 2 ships (E.g. Barnard's star, Tranquility base, or Gas giants), and then we get bigger ShipMarkets for more populated planets, but it is not linear, but according to plot below:

![sol_log_notes](https://cloud.githubusercontent.com/assets/619390/4980099/dfa82b60-68fc-11e4-901f-a20ea825ecd6.png)
_Marked above the levels for Earth Orbitals and Earth Surface ports, as Earth has 7.7 billion._

_Worth knowing, is that population sizes (in billions) of some planets in Sol (x-axis): Earth 7.7, Moon: 0 (!?), Mars: 0.38, Phobos 0.47, Deimos 0.42, Europa 0.52._

## Ship adverts are spawned in equilibrium

In plot below, straight dashed lines mark the theoretical equilibrium ("EQ"), which the market should fluctuate to/from for different stations.

"TOTAL" number of ships on sale in the system is shown by the gray line, and right hand side y-axis is used. Notice that the markets are spawned in equilibrium (plus some stochastic noise), and total number of ships is roughly constant. Nice.

![sol](https://cloud.githubusercontent.com/assets/619390/4980101/e9ce796e-68fc-11e4-8f28-2f4b897c2cfe.png)

London and Los Angeles are Surface earth ports, and have an equilibrium of 22 (red dashed line). Gates Spaceport is orbiting Earth, and has on average 15 ship adverts. Clarke's station orbits Europa which has 0.5 billion people. Mars high is a small stations, with only a few ships on sale.

__Take home message:__ Each station shipMarket has its own basic number of ships for sale, determined by planet population and orbital/surface starport. Each station shipMarket is spawned close it its equilibrium.

## Suggestions?

I'm open to suggestions for changing and tweaking this before merge. It's just a matter of tweaking the parameters that are already there.