Trade
Intergalactic trade is the heart of the economy of Librae. The game implements an iterative market simulation algorithm which matches demand and supply in an optimal way.
Terms
- EC: universal currency, issued by Void Church.
- Goods: Some commodity which can be bought for EC.
- Economy agent: An entity possessing some goods and/or EC which wants to participate in the market. The agent has a specific location and a store of EC and goods.
- Demand: information about a good being desired somewhere. A demand has:
- Budget: how much EC it is willing to spend during the cycle.
- Maximum quantity: how much goods total it is willing to buy.
- Maximum price: how much it is ready to spend per item.
- Supply: information about a good being provided somewhere
- Maximum quantity': how much goods total it is willing to sell.
- Minimum price: how cheap it is willing to sell the items.
- Some of properties on Supply/Demand might be absent or infinite, there is also special information like demand issuing energy credits, not willing to bargain, or not considering shipping a part of price.
- Shipping: goods being transferred from supply to demand cost EC to transport. The price depends on number of breaches between agents as well as other minor factors like gravity of agent's base. EC paid for shipping are destroyed along with matching amount of fuel in VC storage, and are considered to be spent on transport.
Trading process
Trading is done separately for every good.
First, all economy agents (planets, VC, fleets) are queried for the list of their Demands and Supplies.
Trading tables are created. These are maps ordered by price that are created for every supply or demand, and look like this:
| Maximum price | Agent | Quantity | ... |
|---|---|---|---|
| 0.556 | Planet 1 | 400 | |
| Planet 2 | 300 | ||
| 0.345 | Fleet 1 | 1000 |
Every combination of Demand and Supply is queried for its viability. If a deal is theoretically possible (the max and min prices are compatible, shipping is considered, etc), a maximum price for demander and minimum price for the supplier that is possible as part of the deal is calculated and deal is added to the proper tables.
During this step, a 'sink price' is also determined, a best price for a 'sink' demander that issues credits and will buy unlimited goods. Currently, this is the case only for VC. All supplies are adjusted to sell only at this price or above, because it does not make sense to try to chase other suppliers from unlimited sinks.
Now, the main iterations begin. For every demand, best supplies is found, which are ready to pay the most. For these supplies, similarly, best demands are found. If a supply and a demand are best for each other, they make a deal. The price is determined to be either the effective price to buy from the next best supplier, so that it's barely feasible to choose the current supplier, or the demander's maximum if there is no competition.
As agents run out of EC and stock, they are removed from the trading tables. If at least one modification to the tables has been made, the cycle starts again, so that all the best deals are found. When no more deals are possible, the trading cycle ends.