PDA

View Full Version : Simulating Trade Routes



SteelyGlint
02-23-2010, 09:39 PM
I'm developing a small sandbox RPG, and one procedural element I'd like to have is fairly realistic trade between cities. I'm curious if anyone here has experience with this sort of thing, or at least knowledge about European trade practices in the 1300's to 1500's. I'm especially interested in algorithms people may have that would help this simulation.

My simulation must serve multiple goals. The first goal is to determine how important each city in the world is, since in the real world city population size was highly linked with how much of a hub of trade a city was. Initially, I want to procedurally determine the population level of each city before the game starts. As the game progresses, I'd like cities to slowly wax or wane in power based partially on how involved they are in the flow of trade. Finally if the player wants to be a merchant I want to allow that, so the simulation needs to be able to handle local prices.

So, how do I determine which cities prosper due to trade? How do I determine which nations (groups of cities) prosper due to trade? How can cities or merchant organizations attempt to control trade to their advantage (naval power)?

Here's the basic framework I'm planning on using, though I'm willing to consider changing anything if someone has a good idea:

I have approximately 250 cities placed across my map. Each city is the center of trade of its own surroundings, which include 6-10 market towns and up to 1000 villages. For the purposes of my simulation, each province (city + satellite settlements) is considered a single unit.

Each city supplies certain luxury or manufactured goods for export, such as alcohol (wine, rum, beer), weapons and armor, jewelry, textiles (wool, cotton, silk), perfume, dyes, spices, incense, glass, ceramics/porcelain, alchemical goods, furs, fine timber, opium, etc. Cities have demand for goods that they don't produce.

Cities are linked together in a web of trade connections. Land routes connect cities to each other as long as they're quite close or inaccessible by water. Sea routes connect ports to each other in chains along the coast. River routes allow barge traffic to move along the slow, wide rivers in the lowlands.

Each trade connection is assigned a cost which represents time and risk involved in using it. Connection length and type are the primary cost factors, but other modifiers such as a mountain pass or areas of known pirate/bandit activity also apply. This network of connections can be searched using a search algorithm like A* to allow AI agents to make rational decisions about which trade routes should be taken.

Mark Oliva
02-24-2010, 12:33 AM
It's pretty clear to me what you want to do, but it's not at all clear to me what you want from us. You asked about an algorithm. A sensible algorithm would be pretty illusory, because the number of factors that affect trade and its success or failure are variable and often not logical but rather politically emotional. However, if you're going to implement the following basically good concept:


Each city supplies certain luxury or manufactured goods for export, such as alcohol (wine, rum, beer), weapons and armor, jewelry, textiles (wool, cotton, silk), perfume, dyes, spices, incense, glass, ceramics/porcelain, alchemical goods, furs, fine timber, opium, etc.

You should give more thought to what you can and can't export. In the 1300s to 1500s, beer, for instance, certainly was one of the items you wouldn't export. Beers and ales of that era spoiled within a few days' time. Not only was refrigeration limited to what a beer cellar could provide, but the use of effective ingredients - particularly hops - that stabilized and helped preserve the brew were little known.

SteelyGlint
02-24-2010, 02:43 AM
I guess you're right, it's a little hard for me to explain what I'm looking for in responses here. I'm trying to figure out how the wealth produced by trade gets distributed, and what intentional human factors go into deciding where trade hubs appear. Is there a positive feedback loop caused by an arbitrary city having a slight edge in trade, and the benefits from that edge spiraling into local dominance? If so, how could I simulate that?

Why is it that some tiny states like Venice, Genoa, Holland, the ancient Phoenicians, and Lubeck (the seat of the Hanseatic League) were able to exert such extensive control over regional trade? Is it simply because they happen to have powerful navies, and therefore are able to protect their merchant fleets?

Would merchants work solely out of their "home city," trading only between it and foreign ports? Is that a good way to ensure that cities with the largest amount of merchants benefit the most from trade?

As far as I know hops were cultivated in central Germany by around 900 AD, and had spread throughout most of Europe as a beer additive by the end of the 1500's. But even if the cultivation of hops was a problem, I'd say it's a minor problem since this is an alternate world and I could say that beer production is more advanced than it was in the real world.

Al. I. Cuza
02-24-2010, 03:28 AM
Try searching for the algorithms in game forums such as "The Patrician 2" or "Port Royal 1&2". These are games, that almost exclusively handle trade.

gilgamec
02-25-2010, 04:59 PM
Hmmm... I think you're putting the cart before the horse here. For instance:

The first goal is to determine how important each city in the world is, since in the real world city population size was highly linked with how much of a hub of trade a city was.This is, at best, a misrepresentation of where population size comes from. Many 'trade hubs' of the Middle Ages (say, Lagny in Champagne) were seasonal trade fairs and never functioned as cities. Many cities (or, at least, settlements) had political power because the local lord was important and powerful, but were never trade hubs (like, say, Lusignan, also in France). The force that makes cities more and less powerful (and, peripherally, larger or smaller), at least in the long term, is economic development, which is symbiotic with but orthogonal to trade.


Initially, I want to procedurally determine the population level of each city before the game starts.Again, city sizes are dependent (somewhat) on economic development -- the more things are produced, the more people can be supported doing something other than growing food. This means that city sizes are highly historical. Still, you could do worse than draw sizes from a logistic distribution and fake a consistent backstory.


As the game progresses, I'd like cities to slowly wax or wane in power based partially on how involved they are in the flow of trade. ... So, how do I determine which cities prosper due to trade? How do I determine which nations (groups of cities) prosper due to trade? How can cities or merchant organizations attempt to control trade to their advantage (naval power)?Again, begin involved in trade is less of an issue than economic development. Basically, it comes down to four (and one bonus) steps:


You export something. Initially, at least, this is usually natural resources (mined silver, sea fish, salt, whatever). Being able to export means that you have more than you need.
You can thus trade your exported goods with other cities (via merchants, trade routes, what have you). You buy things you want (or need), that you don't produce yourself.
The key to the process is that it's cheaper to import the raw materials and process them yourself, than to import finished goods. So you see things like the development of a fine Flemish textile industry, replacing the importing of linens from southern Europe. This in turn has two effects:

You no longer have to import linen.
You can now export the textiles you make.


These two factors mean that your city is bigger (by all of the textile manufacturers, and the people who make their shoes and candles and...), you can import something in lieu of the linen, and you can import even more stuff by selling your textiles.
The additional bonus is that some of the textile manufacturers might now branch out into other fields (say, decorative lace) and you have have even more exports.

I've tried to work out a way to simulate this process procedurally, but it's extremely difficult due to the fine-grained nature of the goods you have; basically, just having "precious metals" or "fine timber" isn't enough (what about the craftsmen that make the jewelery or build the oak-beamed manse?), and lumping all "luxury goods" together completely ignores the creative side of the process. Without economic development, trade is just "buy low - sell high", which can be a fun game, but is pretty much completely solvable (with something like solving a Walrasian system of equations for the equilibrium prices).

So, in short: The process of "trade" can be broken up into static and dynamic processes. In the static simulation, it's pretty simple, because what is produced where doesn't change; even fluctuations like land routes closing or cities being besieged will have only short-lived effects. If you want trade to affect the economic fortunes of cities, you need a much more fine-grained analysis, simulating the economic life of each city, and allowing novel goods to appear; this is difficult to do.

Al. I. Cuza
02-25-2010, 08:14 PM
In addition to this fine explanation: It depends on how long you intend to play. What settlements produce won't change overnight.

SteelyGlint
02-25-2010, 08:44 PM
Thanks for your input.

I'm trying to get a handle on how the three main wealth creation/allocation avenues interact, and what results their interactions have with regard to city populations and the flow of history. The three avenues I'm referring to here are raw production (agriculture, mining, forestry, fishing, etc.), manufacturing (metalworking, textiles, brewing, crafts, etc.) and trade. To use your words, production would be fairly static, manufacturing would be somewhat more dynamic, and trade would be the most dynamic of the three. Each layer is interrelated with the other two.

I'd guess that what you're saying is that the development of guilds and their associated industries within each city are more important than the trade that occurs with other cities. I imagine that manufacturing industries would generally spring up in close proximity to the raw materials they require; textile guilds near supplies of wool or flax for instance.

I'm also trying to figure out how to decide where manufacturing centers arise, since they're at least as important as centers of trade. Perhaps this whole problem could be divided into a three layer system as I mentioned above: production arranged semi-randomly based on biome, manufacturing appearing initially near raw materials, and trade allowing manufacturing centers to compete. I'm open to suggestions on how to model the growth or failure of guilds and manufacturing, especially concerning how they relate to trade.

When I mentioned fine timber, I was actually trying to draw a distinction between the kind of wood that would be used for firewood or simple construction versus the great beams needed for the roof of a cathedral or the keel or mast of a ship. This might be important in a province analogous to Holland, with a large shipbuilding industry and insufficient forests to supply it.

I don't need to simulate everything perfectly; I just want to produce something that's not completely unrealistic.

To that end, I've divided goods into a number of categories. Goods like food locally depress the demand for similar goods, and low value goods like bricks are unlikely to be traded. The categories are food (cheese, fish, fruit, grain, livestock, salt), intoxicants (beer, coffee, opium, tea, tobacco, wine), construction materials (bricks, stone, wood, fine stone like marble, fine timber for ships), textiles (cotton, flax, furs, silk, wool), metal goods (armor, tools, weapons), and luxuries (books, dyes, glass, incense, jewelry, perfume, porcelain, spices).

Obviously, things can always be more finely divided or grouped differently and I'm open to suggestions. But I'm mainly interested in continuing the discussion of what leads to the growth of city populations, industries, and trade.



In addition to this fine explanation: It depends on how long you intend to play. What settlements produce won't change overnight.

The time scale could extend out to multiple lifetimes, though probably not more than 200 years.

Al. I. Cuza
02-26-2010, 03:16 AM
Little observation: Big manufacturing centers were usually also big trade hubs. Or at least in very close proximity. Because there you would have everything you needed.

Xyll
02-26-2010, 12:53 PM
In my unprofessional opinion you need to develop a base cost for all materials that are to be traded. You then need to create a rating system to determine the base scarcity or abundance of the material for each province. Next would be the time scale for change either monthly or seasonal. Then you would have to create a chart for the events that could occur and the modifiers that they could apply to the product war, poor harvest, boom etc. Further more you would have to determine a base population for the provinces and the modifiers that could occur due to events plagues , war, economic expansion.

you obviously know all of this but start with the baseline and then go from there. If you do not have the base then the rest seems overwhelming in my opinion. Unless your players are really into this then it really have no value besides an intellectual exercise. Good luck

The other method that i have seen as functional was used to the darksun traders book that left the values fixed until the players arrived at a location and then the random factor was determined this simulated the effects of random actions upon arrival not predetermined values that do not directly affect the characters. But it is your world .

isomage
02-27-2010, 09:19 PM
For my random Traveller subsector maps (http://axiscity.hexamon.net/users/isomage/traveller/subsector/) I connected each A, B, or C type starport with up to two random nearest neighbors of the same or better type; lower types are left unconnected. This typically results in treelike connectivity (though loops occasionally form) with A ports being hubs for B ports, which are in turn hubs for C ports. It's a pretty simple algorithm and seems to give reasonable-looking results.

It's not as involved as what you're trying to do, but maybe you'd find the basic idea applicable at some level -- connecting cities to random nearest neighbors of the same or greater population would give the same kind of routes.

SteelyGlint
02-28-2010, 11:46 PM
In my unprofessional opinion you need to develop a base cost for all materials that are to be traded. You then need to create a rating system to determine the base scarcity or abundance of the material for each province. Next would be the time scale for change either monthly or seasonal. Then you would have to create a chart for the events that could occur and the modifiers that they could apply to the product war, poor harvest, boom etc. Further more you would have to determine a base population for the provinces and the modifiers that could occur due to events plagues , war, economic expansion.
Yeah, this is essentially what I'm working on right now. I'm working on some quick dev tools to generate populations based on the environment surrounding each city. The amount of settled land within each province will be partially randomly generated, to account for unknown positive/negative events in the recent city history.

What are people's opinions about whether large cities in heavily populated provinces would increase or decrease the neighboring province density / major city size? Could prosperous neighbors cause higher settlement density but smaller major cities?

I'd assume that setting cheap food goods as the most basic economic unit would be a good idea. Perhaps 1 unit of food could be the food surplus generated by an average village (of around 200 people) for a given year. Obviously the quality of the harvest, tax levels, events like locust plagues or war, and so on would have an effect on how much food a given province produces per year. Anyway, this "food unit" would itself be equivalent to the ubiquitous gold piece used in so many settings.

The actual sale price of a unit of food would of course fluctuate, with 1 gp being the value in a good year, and the value skyrocketing in the case of famine or war. All other goods follow the same pattern locally, with base values that are adjusted by the ratio of goods in the province to the demand or consumption rate.

Anyway, another excuse for this post is to show the current state of what could be called an interactive map. The attached screenshots include a dev view of how cities are connected and an overlay that shows the connections in a more stylish way.

Xyll
03-01-2010, 11:49 AM
Have you found this link on random kingdom generators? http://www.io.com/~sjohn/demog.htm

Talroth
03-01-2010, 01:26 PM
I've been working on a similar economic simulation system (but as a tool for research.)

Where I started was establishing the diets of the time frame for the location to be simulated, and basically the economy get boiled down to "What does it take for me to survive?" as the key question every Agent in the sim asks.

From there I create a base where every person produces food, and only food, at realistic levels using the best estimates I can find. I branch out and start adding different food types, etc. Everyone should, in theory, be producing a decent surplus (Or are in an inhospitable environment and starving).

Then I start working on building the 'other' items, and keep adding them. Always keeping in mind how much a single human with the tools/technology in question could have produced. The really hard part is establishing guidelines on why people would want an item, and for this stage Maslow's hierarchy of needs is a great basis. Everything added is this assigned a point on a custom scale based on the Hierarchy of Needs and then the Agents go to town and begin trading with the goal to establish the highest points possible.

(Eventually I threw in a multipass trade function to seek a Nash equilibrium. Turns out we're all suppose to have high-end sports cars in Communism. Funny how the real world can differ so greatly from simulations.)

SteelyGlint
03-01-2010, 04:47 PM
@Xyll - Yes, that's one of the resources I've been using, and it's where I got my ratio of cities:towns:villages.

@Talroth - Your method seems similar to mine, but I'm not sure I have the resources to simulate down to the individual agent... unless you refer to entire settlements as agents. I'm not even sure if I'll simulate anything below the city/town level, let alone individuals within villages. Village production will most likely be aggregated to keep things simple.

Your mention of the hierarchy of needs is a good idea. Obviously, the most needed category is food since I can assume that the cities were founded in places where water is available (though I can leave open the option of having lethal events that tamper with a settlement's water supply). The construction goods (clay->bricks, stone, wood) and associated industries (masons, carpenters) fill the need for shelter. I suppose the textile goods fill the need for shelter as well, especially in the northern region.

I'm thinking of introducing concepts like staple rights (http://en.wikipedia.org/wiki/Staple_right) to make trade a little more interesting. Does anyone know of other interesting features of trade during the late medieval/early renaissance period?

Talroth
03-01-2010, 07:45 PM
True, the scale of the 'Agent' in the simulation depends on the scale of the simulation as a whole. If you are doing a small village economy, then you can run it at a single person level and not bog down your system. Doing the whole world will require some scaling up to regional levels, which does make the Wants and Needs simulation a little more complex.

If I get some time I might rewrite some of the code this summer, and make it open source. Sadly I lack release rights on a handful of key components. (Biggest mistake I've ever made in coding personal projects.)

Al. I. Cuza
03-05-2010, 03:09 PM
What did you use for those interactive maps?

SteelyGlint
03-05-2010, 03:34 PM
What did you use for those interactive maps?
The program itself is mostly written by me. I used a 2D engine called HGE so I didn't have to reinvent the wheel, but all the rest was made from scratch in C++, Photoshop, and Illustrator.

Al. I. Cuza
03-05-2010, 03:40 PM
Looks quite nice, really.

Here is something i wrote in another thread regarding trade:


Trade should be simulated by modeling supply and demand through simple factors, much like everything else. Every bigger settlement should have a base supply (anything produced in a small enough radius will be included). Every 1000 persons of each class should have a base demand, the percentage of classes in each settlement will determine the settlements' base demand. The amount of trade between 2 settlements could then be calculated as a function of profit and travel (anything from distance to travel method: the longer the distance, the higher the travel expenses, longer time wasted on the road, is there a road, is it paved, is there a means to use the ship or even train, etc...). It shouldn't be too problematic this way.

SteelyGlint
03-05-2010, 04:27 PM
Wow, that's almost exactly what I was already planning to do. I even set base consumption to a number out of 1000.:D

I had originally wanted to do something that searched the trade network, but I recently decided that it would be much smarter/easier to simulate trade by running a multipass algorithm that is only concerned with single hops.

I have a number of factors that affect the consumption of each of my trade goods (there are currently 43), from prosperity to cultural proclivities. As you can imagine, certain goods are more elastic than others in their price/consumption rate.

Al. I. Cuza
03-05-2010, 04:55 PM
I had originally wanted to do something that searched the trade network, but I recently decided that it would be much smarter/easier to simulate trade by running a multipass algorithm that is only concerned with single hops.

That would be even historicallz accurate. Most traders were forced by law to pass every market town in their way and offer their goods to be sold.


I have a number of factors that affect the consumption of each of my trade goods (there are currently 43), from prosperity to cultural proclivities. As you can imagine, certain goods are more elastic than others in their price/consumption rate.

Maybe you could post the results of your work until now (and I don't mean the programming). I could contribute better if I knew what you already have and it would benefit the whole forum as well :)

SteelyGlint
03-05-2010, 05:22 PM
I had mentioned staple rights (aka stacking rights, according to wikipedia), which is one form of the kind of trade law you are referring to. I believe they were specifically for river traffic, but they could easily be expanded to cover land routes (assuming they weren't used that way in real life, which I don't know enough to comment on).

Right now each city generates a list of "environs" from the surrounding biomes that describe the lands of the province. Each environ is something like "forested hills" or "river flood plain" and can support a certain number of each type of village. The number of villages is usually only a fraction of this maximum though, due to war/famine/plague/etc.

All villages are self-sufficient in terms of food, and each one produces basic surplus goods that are sent to the market villages and main city of the province. A farming village produces grain, an orchard village produces fruit, a fishing village produces fish, a forest village produces wood, and so on. Each village also produces a small amount of trade goods, depending on its climate and type. For example, you might get furs or fine timber from a cold forest village, and spices or tobacco from a warm farming village.

The industries that convert raw goods into more valuable goods exist in cities. They covert grain into beer, fruit into wine, flax/cotton/wool into clothing, and so on. More developed industries have a chance of creating "fine" goods, which are worth a lot more than the normal kind. So an advanced textiles guild would produce some fraction of fine clothes, an advanced blacksmith's guild would produce a fair amount of fine weapons and armor, and an advanced brewing industry would produce fine spirits and fine wine. Other factors can also change the "fine fraction," for example the textiles guild can use silk, furs, or dye to greatly improve the chance of producing fine clothing.

Once all these various goods are produced, the multipass trade function takes over. I was planning for it to calculate one step each month, but perhaps I should step it up to weekly or twice a month. Anyway, I don't know when it will be done since Battlefield Bad Company 2 just came out...

Talroth
03-05-2010, 11:25 PM
Anyway, I don't know when it will be done since Battlefield Bad Company 2 just came out...

Funny. My projects have been put on hold for the same reason! Keep an eye out for the 75th Ranger Regiment's servers if you're on PC.