Transport automation improvements [work in progress]

FlaviusBelisarius

Chieftain
Joined
May 13, 2020
Messages
59
Location
Finland
I've been working extensively on making the transportation game more functional and less painful to setup. Work is not finished (meaning I have still ideas on how to move forward) but since I have had quite nice results on my test game, I will describe what I have done so far.

Briefly:
  1. New yield setting (spinbox) in city governor import/export popup: import feeder threshold
  2. New yield setting (spinbox) in city governor import/export popup: export threshold
  3. New button in city governor import/export popup: Auto-setup feeder on all goods
  4. New button in city governor import/export popup: Auto-setup domestic goods
  5. New button in trade routes advisor: switch export/import city roles
  6. Changed functionality: import feeder by default precisely transports construction materials (not bringing more than needed as was before)
  7. Changed functionality: route-automated transports adhere to the feeder condition logic (and the new export threshold logic). Before, only full auto transports respected feeder status.
Detailed descriptions:

1 and 2: new transport controls

Similarly to the existing import feeder logic, the idea here is to have hysteresis and better control over when stuff moves in or out of a city. Whereas the old feeder was hard-coded to trigger on 75% maintain level, the new threshold parameter allows full control. For symmetry, a similar threshold is added for export: do not start exporting before a set level of storage is reached (export threshold).

This is how import/export governor popup looks like now:
new_thresholds.jpg

Lumber is fully set for import and export functions. Max storage is 100. Maintain level is 20. Import feeder threshold is 40. Export threshold is 60.

Import of lumber is turned on (while it was off) when storage level drops below 40.
Import of lumber is turned off (while it was on) when storage level surpasses 40 (and maintain level if it was higher).
Lumber imports will not exceed 100 storage level.
Lumber export is turned on (while it was off) when storage level reaches 60.
Lumber export is turned off (while it was on) when storage level drops to 20 or below.
So in this case, in the hysteresis range of 40-59 storage, the situation is static. No importing. No exporting.

Stone is set for automatic needs-only import. If construction requires stone, just that much will be imported, not more, not less (feature 6). Otherwise, storage is kept at zero assuming no local production takes place.

3. Auto setup feeder
What this feature does, it makes a single xml-editable load function of the import/export governor popup parameters.
CIV4YieldInfos.xml
has new fields for
  • what yield to apply the function for
  • maintain storage level
  • maximum storage level
  • feeder threshold
  • export threshold
Edit the xml with a nice table view ("excel view") editor and you can create a profile for feeder stuff to your preference. Pressing the new button
new_buttons.jpg


loads and applies the settings in one go.

4. Automatic domestic goods button
Similarly to 3, this is a new one-click automatic setup function. But this one is rather clever.
  • It looks at the city domestic demands - only those goods that are needed are adjusted.
  • It looks if the city is producing locally or needs to import.
  • If the city needs to import a domestic demanded yield, suitable import feeder and max storage are set based on how much the yield is demanded. So small demands require small storage, large volumes more. It is based on how many turns the city can satisfy said demand.
  • If the city produces a domestic yield it needs, imports are not set but export parameters are set instead, ensuring that there is sufficient storage remaining to satisfy domestic demand.
An example. Rum is domestically demanded with volume 2 (per turn). Import feeder is set to have trigger 10 in storage and max 30 in storage. So 5 turns worth minimum storage / import feeder trigger and 15 turns worth demand to be maximally stored.
Coats are produced locally (and in demand too locally for volume 1). Import is set to off and export is set on with a threshold of 60 storage, keeping 10. (I set the keep_min as closest multiple of 10 rounded up)

new_auto_domestic.jpg
In the above screen capture, domestic imports and exports are set with one click. Coffee, .. to Wine are imported with differing parameters. Wool cloth, Cloth and Beer are exported instead since they are locally produced.

Note the new visualization on the import export fields:
[a-b] @c-
a: maintain level
b: maximum storage
c: import threshold

[d-] @e+
d: maintain level
e: export threshold

Both have color highlight denoting if import / export is active or stopped presently.

There are a lot of small things to improve with this function yet. But it is very powerful already!

5. switch export/import city roles
new_switch_cities.jpg
City in export / import squares switch places. No need to remove and re-select.

7. route-automation adheres to thresholds
By activating the transport advisor screen (above screen shot), you can put transports to partially automated mode. In this mode, it used to be so that feeder logic was ignored partially. Now, it does not matter. All transports follow the rules.

[Edit:] Now published in:
https://github.com/MagisterBelisarius/Mod/tree/transport_automation
 
Last edited:
Next steps in mind:
  1. More testing...
  2. Even smarter auto domestic setup. Now, it does not set up exports for yields that are not in demand locally.
  3. Fully automated transports with city list limits: "fully automate transport routes but only between the selected cities". This should make it much easier to manage huge / discontinuous empires. Make trade around hubs full auto with city limits. Route-automated trade between hubs (longer distance travel). This might even work!
  4. Multiple persistent save/load profiles for import/export governor popup. Persistent across saved games. Shareable human-readable configuration files.
Observations on my test game with 10 cities in a rather compact configuration.
  • If the new controls are used, automatic trade is close to optimal! It does pretty much what I would manually do. And other times, transports wait patiently instead of running around doing marginal things.
  • Setting up is very easy and fast. Put the import export check boxes and see how stuff moves around.
  • Exact construction needs transportation is super nice! I put a well under construction on the borderlands - a transport kindly brings in 20 tools. (Not all of the tools it can hold as before!). One click to set tools import feeder on. Another to set stone feeder on.
  • Since hysteresis keeps unneeded trade off, there are many times when transports are just waiting. This makes their response times much better than before!
  • The amount of transport units needed is not too big for a production-weak beginning game empire. Just a few will do even for 10 cities since player has high control (thresholds) over what is worth doing.
 
This is really great! I always though if I had unlimited free time, I would try to hack something together for transport automation. But it seems you spent some theoretical reflection first, which is even better than a simple hack :)

Just one question: With the old (=current) trade automation system I had the impression that turn times go up exponentially with more and more cities added. I usually like to play on gigantic maps and sometimes have like 50 colonies. Did you just change the "list of tasks" for the transport units or also the logic the use when deciding where to go and what to transport?
I suppose the decision making and route finding is the expensive calculation here ...
 
Nice !
:love: domestic goods automatic .
I tried with the current trade automation but i :sad:

What is the optimal ratio of wagon train vs number of city ?
What is the best to use in automatic , wagon train (2 slots) or trek , carriage etc. ?
 
This is really great! I always though if I had unlimited free time, I would try to hack something together for transport automation. But it seems you spent some theoretical reflection first, which is even better than a simple hack :)

Just one question: With the old (=current) trade automation system I had the impression that turn times go up exponentially with more and more cities added. I usually like to play on gigantic maps and sometimes have like 50 colonies. Did you just change the "list of tasks" for the transport units or also the logic the use when deciding where to go and what to transport?
I suppose the decision making and route finding is the expensive calculation here ...

To my understanding the turn times are AI dependent (if you are talking about that, time between your own turns). So sadly, these changes won't help much unless someone teaches AI to use them which is far from simple. Basic algorithms are unchanged, just added more controls.

On second thought, I am not sure if the player transports in auto mode use the CPU time much in between turns or if it is insignificant in comparison to other tasks. The features I have done do help with player units in AI control especially if I implement the city restriction feature. Will that make a difference? No idea honestly.
 
Nice !
:love: domestic goods automatic .
I tried with the current trade automation but i :sad:

What is the optimal ratio of wagon train vs number of city ?
What is the best to use in automatic , wagon train (2 slots) or trek , carriage etc. ?
These are all open questions and will depend heavily on how parameters are set. With the added controls, there is a lot of room for different styles. And all this is so far untested since I have just tested a bit around with this myself and my work is unpublished (and unfinished).

So far, I have managed quite fine with 2 wagon trains and one trek in full auto mode (before having domestic setup complete, mind you!). 9 cities with 110 total population. My setup presently is to only allow 50+ unit transportation apart from construction needs which are what they are.
 
if you want to share the code or the file, i can help for test.
I use 3.0.1
 
This work is now public in my fork & branch:
https://github.com/MagisterBelisarius/Mod/tree/transport_automation

How to playtest this modmod?
  1. Follow the link above and download the files.
  2. Extract the files into a new folder (name e.g. wtp_ta_modmod) inside your mods location (in my computer, this is: [USER_NAME]\Documents\My Games\Civilization IV Colonization\MODS).
  3. Unzip the attached dll into the assets folder inside the mod folder you created.
Base of this modmod is WtP 3.0.1 release.

Optional:
You can use your old savegame but once you save with this modmod, there is no turning back so beware!
Use this tool to make a copy of a savegame you want to try with the modmod.
https://we-the-people-civ4col-mod.github.io/DeveloperNotes/SavegameModRenamingTool/index.html

Disclaimer: this work is not "official". It has been tested only little. That is why I publish it now: for testing and early feedback.

What I would like to receive from potential volunteer testers:
  • General feedback.
  • Functionality testing - does it work as I advertise above in this thread? If not, what fails?
  • Ideas on how to develop further.
  • Crash reports or similar.
 

Attachments

  • CvGameCoreDLL.zip
    1.3 MB · Views: 23
i make a test focused ont the domestic demands with 4 goodies.
I test low number of wagon train and high number of wagon trains.
In the end, nothing work.
Edit: it works with 1 wagon train, 1 goodies between 2 colonies.
Spoiler Main steps and notes: :

I create a map with the builder. I create 15 colonies to represent a standard evolution game.
England, Revolutionary, A_new_World, Huge world size, Temperate Climate, Low sea Level, Discovery Starting Era, Normal speed Game.
Plastered country road connected.
some pionners in auto.
After a few laps of getting started, I did the following tests:

One main colony is set on "import all goods"

begining: the main colony Export luxuary goods - 1 colony need (manually set up: Max storage is 15. Maintain level is 5. Import feeder threshold is 5. Export threshold is 0.)
Send 1 wagon train with Automate Transport

Result: after a few turns, 15 luxuary goods arrived in the colony.

and then: the main colony Export luxuary goods - all colonies, Clic on the "Auto-set up automatic domestic goods" and "auto export all goods"
Add some new goods in a production colony : cloth and colored colth.
Result: The auto-set correctly detect the goods needed in a colony (as well as the evolution of needs in the following turns). After a few turns:
- with 7 wagon train in Automate Transport:
--after 4 turns, and 3 colonies have some luxuary goods. 200 cloth an colored cloth on the main colony. 0 in other colonies. Turn 26: 800 new luxuary goods arrive in main colony. Turn 28: no really changes: 2 or 3 cities have some luxuary goods and only the main colony receives cloth and colored cloth (normal: they don't demand :sick: )

some turns, I lose up to 20,000 gold (why? i dont know; it seems a little too much for it to be the auto pioneers). so with the worldbuilder i put gold in galeon and send them in europe

And then
turn 28: Worldbuilder: add a coffee (which is more needed) production in 2 colonies.
turn 35: one of the 2 cities doesnt auto detect the coffee export. So i set it manualy.
turn 40: i'm watching for 5 goods: Luxuary, coffee, cloth and colored cloth. In the end, with 7 wagon trains, the 4 goods are not evenly distributed between the cities.

So i add 3 wagon train / colony.
turn 41 anf follows : little freeze at the start of the turn. there is almost no more loss of money and the auto workers have stopped
turn 47: Lewis & Clarck arrived
turn 50: In the end, with approx. 52 wagon trains, the 4 goods are not evenly distributed between the cities. And more, some wagon trains are freezing in colonies, with doing nothing.



I upload the last file.
 

Attachments

  • turn50.ColonizationSave
    478.7 KB · Views: 21
i make a test focused ont the domestic demands with 4 goodies.
I test low number of wagon train and high number of wagon trains.
In the end, nothing work.
Edit: it works with 1 wagon train, 1 goodies between 2 colonies.
Spoiler Main steps and notes: :

I create a map with the builder. I create 15 colonies to represent a standard evolution game.
England, Revolutionary, A_new_World, Huge world size, Temperate Climate, Low sea Level, Discovery Starting Era, Normal speed Game.
Plastered country road connected.
some pionners in auto.
After a few laps of getting started, I did the following tests:

One main colony is set on "import all goods"

begining: the main colony Export luxuary goods - 1 colony need (manually set up: Max storage is 15. Maintain level is 5. Import feeder threshold is 5. Export threshold is 0.)
Send 1 wagon train with Automate Transport

Result: after a few turns, 15 luxuary goods arrived in the colony.

and then: the main colony Export luxuary goods - all colonies, Clic on the "Auto-set up automatic domestic goods" and "auto export all goods"
Add some new goods in a production colony : cloth and colored colth.
Result: The auto-set correctly detect the goods needed in a colony (as well as the evolution of needs in the following turns). After a few turns:
- with 7 wagon train in Automate Transport:
--after 4 turns, and 3 colonies have some luxuary goods. 200 cloth an colored cloth on the main colony. 0 in other colonies. Turn 26: 800 new luxuary goods arrive in main colony. Turn 28: no really changes: 2 or 3 cities have some luxuary goods and only the main colony receives cloth and colored cloth (normal: they don't demand :sick: )

some turns, I lose up to 20,000 gold (why? i dont know; it seems a little too much for it to be the auto pioneers). so with the worldbuilder i put gold in galeon and send them in europe

And then
turn 28: Worldbuilder: add a coffee (which is more needed) production in 2 colonies.
turn 35: one of the 2 cities doesnt auto detect the coffee export. So i set it manualy.
turn 40: i'm watching for 5 goods: Luxuary, coffee, cloth and colored cloth. In the end, with 7 wagon trains, the 4 goods are not evenly distributed between the cities.

So i add 3 wagon train / colony.
turn 41 anf follows : little freeze at the start of the turn. there is almost no more loss of money and the auto workers have stopped
turn 47: Lewis & Clarck arrived
turn 50: In the end, with approx. 52 wagon trains, the 4 goods are not evenly distributed between the cities. And more, some wagon trains are freezing in colonies, with doing nothing.



I upload the last file.
Thank you Uraeus for the test! A few quick notes:
  • Auto domestic market button is static so you need to click it again if/when the situation changes for it to refresh. And at the moment, it cannot remove unneeded imports (I know how to fix that later). Maybe this needs more clarity or was there misunderstanding here?
  • Auto domestic setup really does not work for the main trade hub cities because those have entirely different role. So setup hubs trading with Europe manually. I set up them with both import / export on without max storage limits. That way, the hub city draws and redistributes all the excess goods. And when the storages grow, extras are sold to Europe.
  • It is normal for wagons to wait in cities - if there is nothing to do. Was there a situation in which trade routes were active (green) and wagons did not wake up the next turn? They do have a delay in waking up.
  • What do you mean by "not evenly distributed"? Was there enough to share to all cities? Distribution does not work evenly if there is not enough production for all cities.
  • What do you mean that "in the end, nothing work"?
  • Can you provide your own analysis and conclusions as well?
 
An update. I have basically lost faith in the present transport automation code. What convinced me? I witnessed 4(!!) transport units simultaneously delivering 50 tools order for the same construction project. Naturally, that did not turn out alright. It made a mess. Realizing that this happens is a much bigger mess though. It affects both import and export. The present code cannot be saved, it needs to be changed or better yet, replaced.
 
I have basically lost faith in the present transport automation code.
I share this point of view. I tried adding to the current system and others too. Each time it got a little better, but it feels like wack a mole. Each time you deal with one issue, another shows up and there are more and more known issues, which are hard if not impossible to fix without a rewrite. The biggest question is how to design a new system.

If we are to design a new system, it should be based on a different strategy than the current one. A strategy, which takes scaling into account. It should likely be something where the system isn't in the units, but rather some code, which manage multiple units. If a colony needs 50 tools, it will get 50 tools, not 50 * "number of units" tools. The question is how to design such a new system. Ideally it shouldn't use more CPU power than the current one. In fact less would be good as the current one is inefficient.
 
Update: I am testing concepts for a new transport approach by first improving in-game analysis tools. Domestic advisor has been augmented to make further work easier.

This development in my vision could eventually replace full auto transport function. In addition, I think trade route function has to be re-planned to something alike original colonization had but with more control (able to override city-based limits for sure). That will be later.

To fix the "breaking issue" that I discovered above, the new transport system needs to make reservations and remember orders properly. Then, no multiple transports will do the same thing any more. And for added benefit, it would be easy to make it possible for the player to see straight from the city screen that a transport is en-route to bring yield X with quantity Y. Or coming to take stuff away.

What I have done:

I have added a lot of new rows to total production page of domestic advisor. They all calculate aggregate values over all cities. Idea I am approaching here is to have priority categories of transportation and secondarily, having global analysis on what to move first. This is handy info for the player even though my aim is to help transportation AI in the end with these values.
  1. Needs - automatic feeder construction import (20 tools for a well etc.)
  2. Below min - how much is there deficit compared to a set minimum storage level
  3. Feeder demand - how much would active feeder imports take to fill their set limits
  4. Import potential - total maximum import potential of all cities. Up to storage max capacity if not limited otherwise.
  5. Export potential - total available goods for exporting
  6. Transport potential - a smart intersection of the two previous ones. Here, self-transport needs to be excluded (otherwise, transport potential equals min(import potential, export potential))
total_prod_changes.jpg
Look at the example image above for an idea how the numbers are useful.
  • Looking at the table, we can infer that there would be immediate demand of 360 coffee to get feeder max levels. Even keeping minimum level satisfied would require 160 coffee. I have used auto domestic function so feeder orders are there (for no extra effort) before I have production set for a certain yield like coffee in this example.
  • Another case study: 60 cannons are required for construction somewhere but there is none available for export at the moment. An immediate concern.
  • Cigars have at the present highest transport potential (available exports with potential destinations). Note that non-trivial calculation is needed to get the number here.
In addition, I added a new page, per-city transport potential:
transport_potential.jpg
This is packed with relevant information. Color codes:
  • gray: no transport set, idle storage
  • Dark tone "In" "Out": feeder / auto export is stopped. No transport activity at the moment.
  • Bright green: import potential
  • Bright red: export potential
  • Light cyan: auto feeder construction needs unfulfilled / import needed
Compare the city-level numbers to understand the concept "transport potential [TP]". Cigars have TP of 71. Nya Stockholm -> Fort Christina 56 units and Fort Christina -> Silverhills 15 units. The remaining export potential from Fort Christina is unmet at the moment since most import potential is in that city (no self-transportation!).

[Edit]: this work has been pushed to my fork repository for curious eyes. No dll changes.
 
Last edited:
Definitely looks interesting. :thumbsup:
A lot of player will be looking forward to these improvements.

Otherwise I can not say much about it, because I simply never used Transport Automation.
I am a "micro-manager" in games like Civ4Col and like to manage transportation manually.
 
I personally prefer a design level play style: player has to do the high-level work to set up a system for transportation but with minimal "grinding" effort. I do not prefer to play "truck simulator" in WTP. I have manually managed transportation in the past because there were no satisfactory options. If I am successful, this will change, there will be a satisfactory option :)

Good planning will be rewarded with scalability and low player effort. Bad planning will be punished with system failure / inefficiency. Auto transport will not "play the game by itself" (it will break down in efficiency by scale - I am not even trying to solve NP-complete optimization here).

Vision at the moment
Transportation design will need two different parts:
  1. Full auto (with optional city list limits, only transport between defined cities). This can handle local transportation with very low player effort. Will be based on city governor import / export settings. Might work ok for global transport so AI should be better off (it should not do anything as stupid as the present one) but will lose efficiency with scale.
  2. Transport routes. Explicit pathing and load/unload conditions. Can override city governor limits. Transport routes can do transcontinental scale core routes. And hub/node logic with full auto mode. Inter-hub traffic with routes, hub-node traffic with full auto.
Full auto algorithm raw ideas this far:
  • Present "transport route" constructs (two-city pairs of yields) will be obsolete.
  • Global analysis as shown above will give the basis for decisions. This can be done by looking at city governor import/export settings so no need to construct the combinatorial transport route entities explicitly in memory. Import / export potential are more robust constructs in my mind. Sensible use of import feeder threshold and export threshold will dramatically limit the count of positive import / export potential in cities, making search operations more efficient!
  • First question to solve is to decide what to transport. This will be based on transport need priority, transport potential and proximity to export resources at the moment.
  • When a decision is made, that is formalized as an explicit plan / order that is kept in record for the unit. Orders consists of source city, goods to move, and the target city. A plan is a queue of actions that in the end fulfill the orders. Naturally, several orders can be kept so that transport unit can e.g. load 100 tools and then distribute that to several cities.
  • A transport order makes explicit reservations / notes to the city storage. Thus, planned transportation is already "half-done" in bookkeeping and thus will not be double booked.
  • Careful cleanup needs to be done to account for changes in plans or cancelled plans (units get destroyed, manually stopped etc.). Since transport units keep orders in memory, a fresh reconstruction of reservations is possible so this should not become an issue (brute force cleanup solution).
  • The algorithm can be highly heuristic instead of aiming for optimum. A combination of rules and calculation such as "feed starving cities first" / "cater for construction needs before trade exports" / "if no pressing needs are unmet, transport the highest transport potential yield" etc.
  • When the primary transport plan is decided for, sub-optimize locally the remaining cargo capacity. For example, A -> B food transport is first priority and thus planned. Unit has 3 slots open for other stuff. Look for exports near A that have demand near B and if such are found, add them to the plan queue.
 
Update: city list limited transport full auto is working but only with an ugly hack at the moment due to unimaginable complications (I have no idea what is going on with the code honestly).

Screenshot 2021-09-17 15.46.49.jpg
A new screen alike the trade route advisor screen controls the city assignment for a transport. A new command button (5th from the left in the screen capture) activates the city selection screen. Select the cities, exit and the transport will automatically serve all transportation between those cities (also keeping up with new routes / import export rules without a need for an update). Branch updated if someone wants to test.
 
Update: preset load and save feature works as well for city list limited transport automation. With this milestone, hub & nodes transportation system is quite ergonomic (little clicking) to set up.

Next step will be fixing the multiple simultaneous transportation issue. All this far is on top of the existing code. Changing that will be only after I feel confident I have fixed most obvious shortcomings.
 
Top Bottom