Note: This thread adopts a useful practice to improve its readability: The first/opening post will get regularly updated from later posts with every important information, so as to keep everything important in one place.
The requirements are these:
- Avoid full congestion of a road-system and most cases of half-full congestion.
- Prevent a road-system from getting messed-up by overproduction of a single type of ware.
- Improve the situation where a rare ware needs to move quickly through a busy road-system.
- Be relatively easy to explain to players.
- Don't alter the existing system too much.
- Achieve the above points without stressing the computer.
This is not a perfect final solution, it is merely a considerable improvement, an early step to the right direction, of a bigger effort to improve Widelands' road-system and overall performance of big maps.
After much analysis and calculations, number 6 has been found to be the critical one, and it all comes down to the following algorithm, which checks the number, type and destination of wares stored on a flag, waiting to be carried by someone:
- If a ware of the same type is heading to the opposite direction, then remotely swap the two wares, avoiding their transfer on that road. Otherwise:
- If the number of wares is 0-5, consider that as a low risk of congestion and allow the transfer of any ware to the flag. Of course 5 wares are more risky than 0, but not by much. This should be the most common case and is identical to the old approach.
- If the number of wares is 6 or 7, consider that as a middle risk of congestion and deny the transfer of any type of ware that is already stored on that flag. Allow transfer of non-stored types.
- If the number of wares is 8 (maximum), consider that as a high risk of congestion and deny the transfer of any type of ware that is already stored on the flag. Also deny the transfer of any other ware, except if one of the stored wares is heading to the opposite direction and thus it can get locally swapped by the carrier.
UPDATE: An implementation of that got merged in the official installation for build 20.