March 12, 2019

Trade III: You Have Something I Want

Time to put everything together and generate a trade network.

The network graph itself is created from the roads, seaways, and rivers. Right now, I have about 10 thousand separate resource-producing settlements, and about 20 thousand roads connecting them.

The problem I am running into is that networkx is pretty slow with this many edges (about 15,000 nodes and twice as many edges). But I found that pre-processing the trade distances makes this much faster. For instance, two cities may be connected by more than one route, even if its just a road and a navigable river. Although local circumstances may require trade to flow along a non-optimal route (the road is blocked, the river is too choppy), the vast majority of trade will occur in aggregate along the shortest route. Therefore, non-optimal routes are irrelevant to the market network; many of those 30,000 edges will never be used.

The process to assign a resource reference is as follows:
  • From the list of available raw resources for a given city hex, select those which the current infrastructure level will support
  • Determine the reference amount that the city can produce
  • Calculate the gold reference for every hex using the system described here
  • Calculate the reference costs for each raw resource
  • Calculate the labor costs for each raw resource. Really this is more of a measure of the amount of references available, and not the cost directly, but I can define a base cost just like any other material good and get, for example, the daily income of an ironworker
  • Calculate the costs for each manufactured commodity. Because a given good might depend on a number of other manufactured goods, I have to make sure that I do them in the right order. To this end, I define goods in stages. Hematite, as a raw resource, is a Stage 0 good. Iron ore is made from Hematite, and is thus a Stage 1 good. So all Stage 0 goods must be assigned and priced before the Stage 1 goods can be calculated. For every multi-stage good, the overall Stage must be $n+1$ where $n$ is the highest Stage used in the recipe
Manufactured goods are defined through recipes. This takes a lot of guesswork sometimes. For example:
'iron (ore)': {'min1': {'charcoal': 1; 'coal': 2};
'min2': {'goethite': 1.6; 'limonite': 1.8; 'magnetite': 1.4; 'hematite': 1.4};
'labor': 'ironsmith'}
This recipe for general iron ore says that you will need 1 lb of charcoal, or 2 lb of coal (whichever is cheaper), and the cheapest ore between 1.6 lb of goethite, 1.8 lb of limonite, 1.4 lb of magnetite, or 1.4 lb of hematite. These raw materials are then shaped by an ironsmith to produce 1 lb of iron ore.

This system is nicely versatile.

One snag that I've run into is the presence of trade networks without access to any precious metals at all, yet perhaps quite robust industry. There are a few solutions to this.
  1. Remove these networks entirely. No precious metal economy, no economy.
  2. Structure these to work as barter economies
  3. Use another substance as the practical fiat currency
  4. Assign a small amount of gold to the economy to lubricate it
2 and 3 are the most likely, historically speaking. But they also require the most work. The easiest for now is just 1. I think I'll redo a long history once I have a good number of raw resources defined. That should take care of most of these outposts. Most of them are small isolated mountain towns, which makes sense that they might not have structured economies, but there are several large cities in there (around 80k), which starts to make less sense in my mind.

Full trade network (sea routes not yet added), after many attempts to use force-directed layout

No comments:

Post a Comment