Trade Network

AIAndy

Deity
Joined
Jun 8, 2011
Messages
3,428
While thinking about the culture/religion diffusion with 1D properties, I noticed that we don't really have a good connectivity network between cities (we have the trade plot groups, but those are plot based and do not really describe a network).

On the other hand we have the very simple trade route calculation that just opens up trade routes that maximize profit (as long as there is any connection). That is not really a proper network either (and it is somewhat unstable even now for crime diffusion).

So what I would suggest is that we calculate a proper trade network and store it as a graph that connects cities and also has a bit of a measure how good each connection is. What I mean is a network where there are few connections that bypass a major city that is somewhat in the mid. Then we can use it both for a new way to calculate trade income and for good diffusion paths between cities for cultures/religions.

The question are:
What should influence the trade network?
What are good ways to calculate it?
How should trade income be determined based on the network?
 
I'm not incredibly knowledgable about the innards of trade, but I do know that it tends to use a lot of processing time whenever parts of it change, so for any things that we do to it I'd keep that in mind.
 
I'm not incredibly knowledgable about the innards of trade, but I do know that it tends to use a lot of processing time whenever parts of it change, so for any things that we do to it I'd keep that in mind.
You are talking about the trade plot groups, which calculate what resources are available where and those connections are interruptable by blockades.
That is expensive but it is already calculated so it is possible to rely on it for parts of the calculation.
 
You are talking about the trade plot groups, which calculate what resources are available where and those connections are interruptable by blockades.
That is expensive but it is already calculated so it is possible to rely on it for parts of the calculation.

But if this new mechanism messes with trade plot groups too much then they need to be recalculated more often, which would be bad. I agree, we can use them for networks.
 
But if this new mechanism messes with trade plot groups too much then they need to be recalculated more often, which would be bad. I agree, we can use them for networks.
What would make you think that the new mechanism would mess with trade plot groups?
 
While thinking about the culture/religion diffusion with 1D properties, I noticed that we don't really have a good connectivity network between cities (we have the trade plot groups, but those are plot based and do not really describe a network).

On the other hand we have the very simple trade route calculation that just opens up trade routes that maximize profit (as long as there is any connection). That is not really a proper network either (and it is somewhat unstable even now for crime diffusion).

So what I would suggest is that we calculate a proper trade network and store it as a graph that connects cities and also has a bit of a measure how good each connection is. What I mean is a network where there are few connections that bypass a major city that is somewhat in the mid. Then we can use it both for a new way to calculate trade income and for good diffusion paths between cities for cultures/religions.
So the cultures would diffuse across trade routes instead of plots?From what I understand that would be a lot less memory use then having cultures spread across all plots.

The question are:
What should influence the trade network?
Proximity to your city. Diplomacy rating towards each other. Amount of revenue possible.
What are good ways to calculate it?
That I have no idea how to answer without knowing the system better.
How should trade income be determined based on the network?
Number of trade based improvements. Shorter distance is more profitable. Trade that travels through neutral territory more expensive. Just throwing some ideas out there.

Responses in red.
 
Better route type - higher trade income (faster goods transportation)
Big crime on plots - less income (guarding costs)

I belive that with that system we will able to make bigger differences between route types
 
What would make you think that the new mechanism would mess with trade plot groups?

Opening and closing routes more often (whenever a connection strength changed in your model it sounds like there would need to be recalculations) sounds expensive to me. Maybe I'm misunderstanding here between trade plots groups and the routes that connect them.
 
Opening and closing routes more often (whenever a connection strength changed in your model it sounds like there would need to be recalculations) sounds expensive to me. Maybe I'm misunderstanding here between trade plots groups and the routes that connect them.
Yes, you misunderstand that.
Let me explain:
Plot groups calculate which plots are connected (for trade purposes) with which plots by forming huge sets of plots.
Then there is the trade route calculation which just checks with which trade reachable cities a city has the highest profit and then uses them as trade route targets. The reachable part here uses the plot groups but does not change them (the plot groups do not care if something is a trade route or not).

What I want to change is the second calculation, not the first, by using a different approach. It will rely on the plot sets but not influence them as well.

Mind, depending on how it is done calculating the trade network can be expensive but there are also ways that don't cost that much (and you don't need to recalculate every turn either, established trade routes need time to change when they are broken).
 
  • Distance weighted by route type (the hypotheticalPathLength function can generate this easily) - using that rather than raw distance means that cities connected by faster routes will score higher. That only works for same-landmass, but you can do the same thing to find 'best port' for another landmass, and then for other cities on said other landmass use the weighted connectivity transitively
  • Population
  • Stability (an unstable environment is not conducive to efficient trade)
  • Crime (inversely - same reasons as previous)
  • Mutual attitude between the civs concerned
  • Trade infrastructure of the cities (some measure of their collective trade-supporting buildings - could be a new building tag, but probably just derive from existing trade-related tags, so things like buildings that give extra trade routes imply more hub-edness)
  • Active trade agreements between the owners of the cities concerned (so if two civs are trading many different commodities it increase the strength of their trade connections - ideally this might be something that has history and decay, so imagine a property that is sourced by active trade agreements, and decays each turn - in fact that might be better applied to the entire outcome of the rest of the calculation so the whole thing has a degree of momentum and hysteresis-like effect)
 
  • Distance weighted by route type (the hypotheticalPathLength function can generate this easily) - using that rather than raw distance means that cities connected by faster routes will score higher. That only works for same-landmass, but you can do the same thing to find 'best port' for another landmass, and then for other cities on said other landmass use the weighted connectivity transitively
  • Population
  • Stability (an unstable environment is not conducive to efficient trade)
  • Crime (inversely - same reasons as previous)
  • Mutual attitude between the civs concerned
  • Trade infrastructure of the cities (some measure of their collective trade-supporting buildings - could be a new building tag, but probably just derive from existing trade-related tags, so things like buildings that give extra trade routes imply more hub-edness)
  • Active trade agreements between the owners of the cities concerned (so if two civs are trading many different commodities it increase the strength of their trade connections - ideally this might be something that has history and decay, so imagine a property that is sourced by active trade agreements, and decays each turn - in fact that might be better applied to the entire outcome of the rest of the calculation so the whole thing has a degree of momentum and hysteresis-like effect)

those are great ideas
 
loving the topic! I'll give it some more thought tomorrow before a full reply, but off the top of my head, I noticed an ad for the Navy the other day stating that 80% of all international trade takes place via water. I began thinking about this and came up with some reasons for why:
1) The fastest route from pt A to pt B is a straight line and they can achieve this via water.
2) Boats can carry a hell of a lot in one trip, far superior to flight transport in this.
3) Ok, so there's a lot of water on the planet and many nations are linked by ocean.

There was more but I'm pressed for time. Some conclusions, however:
1) The size of the standard contemporary transport method should be an influence.
2) The difficulty of the easiest terrain route taken should be an influence.
3) The speed of the standard contemporary transport method should be an influence.
4) The costs (and availability) of fuel could somehow play a role.

I was also thinking of banditry... this is where crime on plots could play a deeper game role, leading to increased trade hindrance and could cause rerouting for safer travel for traders, which could lead through tougher and thus slower terrains.

It was funny you brought this up because it was for the same reasons I had been wondering how effective our intercity property diffusion system would be considering pretty much only trade routes and proximity (without plot to plot diffusion) and began to consider some of what you were talking about here (though your thoughts went a LOT further than mine!)
 
Some thoughts about the trade network generation:
  • Every city gets a trade importance that depends on size, being capital, number of wonders and trade infrastructure
  • Start with generating a local trade network that only consists of connections of up to a maximum local trade path length and only in non foreign territory and land only
  • Calculate the pathing distance between those cities with the pathfinder using plots with routes only
  • Eliminate a connection if there is a route over a third city that may be longer by a percentage that depends on how much more important the third city is than the two first ones
  • Continue with cross border connections in the same way
  • Now connect the local trade clusters (local is relative, they may end up quite large) by far trade routes trying to connect the most important cities in each cluster
 
Better route type - higher trade income (faster goods transportation)
Big crime on plots - less income (guarding costs)

I belive that with that system we will able to make bigger differences between route types


Also, the different ressources in cities should be taken in account.
If city A has Deer, Pig, Sheep, Horse and city B has Wheat, Corn, Potatos, Iron Ingots etc I think they would trade a lot more than two cities with almost identically ressources.

Also, Events like Black Pearls, wild Parrots, Holy Water or even "We now trade tea with Civilization X!" should be taken in account.
 
What sort of net effect will this have on :gold:?
None of the parameters or even the calculation are set yet so this is not an answerable question at this point.

@Hydro: That is part of what we are trying to determine here still so not set yet, suggestions welcome.

@Koshling: Is the pathfinder threadsafe at the moment?
 
None of the parameters or even the calculation are set yet so this is not an answerable question at this point.

@Hydro: That is part of what we are trying to determine here still so not set yet, suggestions welcome.

@Koshling: Is the pathfinder threadsafe at the moment?

OK, I thought that it was more advanced in development than it actually is. I'll sit back and wait for more details.
 
None of the parameters or even the calculation are set yet so this is not an answerable question at this point.

@Hydro: That is part of what we are trying to determine here still so not set yet, suggestions welcome.

@Koshling: Is the pathfinder threadsafe at the moment?

No. My intention (longer term) was to instantiate one per thread ultimately, but there is also the issue of movement cost caching on plots, which is also not thread safe. I'd say you'd be better off having one thread perform all your pathing calculations (preferably all routes you need to calculate from each city in turn, since that reuses all the info from the previously generated path until you change the start point) done on one thread with other aspects on other threads.
 
I have not started the implementation yet as I am not entirely sure about the mechanic and algorithm for the trade network generation.

As I mentioned before I want to start with the national land based trade network.
For each land area and each player a national trade network is generated. The cities of that player in that area are added as nodes to a graph and a trade importance is calculated. Then for each city the pathing distance to each city within a given maximum coordinate distance is calculated and added as edge to the graph.
So now we have a graph with nodes that have trade importance and edges that have a pathing distance.
The next step should eliminate edges from the graph so that cities that have a high trade importance attract connections from the lesser important ones so the direct connections between the less important cities are eliminated and the connection runs over the major trade centers (so they are at the center of star like trade connections).

So a connection between A and B may be eliminated if there is a path over C that is up to x% longer where x depends on the trade importance of A, B and C.
What is not clear yet is the way to calculate x and especially what happens to x when the alternative path is over more than one city (maybe more than one important one). Also, in what order should the elimination happen? Does it matter?
Then the question is a good algorithm to do that.
 
Back
Top Bottom