I'm always happy to give advice on the code I've written.3298 wrote:fonso: You telling me (or whoever implements it) where to look could be really helpful, thanks!
Random numbers for the link graph jobs aren't difficult. You could refactor the random number generator to allow for separate instances working independently from each other. Then you could add such an instance to the link graph job. Finding accepting stations is also not a problem as each link graph job only handles a specific cargo and has information about supply and acceptance. Distance is also no problem as each link graph already contains the distances between all its nodes. About your question: You should definitely do as much work as possible in the link graph thread. However, before actually writing any code you should figure out a concept on how to determine which nodes should be destinations of cargo from which other nodes. In addition you will probably want to assign something like demand between industries and/or towns before and only derive demand between stations from that. This is where it gets complicated: Which towns and industries are actually relevant? How do you make the information available to the link graph jobs?3298 wrote:1. You're right, this is difficult because it probably involves random numbers, and due to the way random numbers are implemented they have to be generated in the main thread. We basically need a random tile (well, a station next to that tile because we shouldn't access the map in the link graph thread) which accepts the cargo type we are currently looking at. There should be some parameter, though, to influence this randomness. YACD has it somewhere in the config, and even though I'm not entirely sure what it exactly does (that part of the code didn't change much, no reason to touch stuff that isn't broken), it seems to tell how close to the source tile a destination is considered "nearby". Nearby destinations get more demand, and there are separate settings for towns and industries.
The only design question I have in this area is: Do we want to choose the destination tile in the main thread, or do we want to pass some cargo acceptance information as part of the linkgraph structure and choose the destination in the link graph thread from this and a random number? By the way, there is some helpful stuff for cargo acceptance in trunk, committed shortly after r23400. It is used for subsidies and was largely YACD code.
My suggestion to keep it simple would be the following:
1. Destinations aren't actually calculated before the link graph exists. In the beginning each industry or town is "free" and doesn't list any destinations.
2. Reachable industry and town IDs are listed in the link graph nodes (which is not as trivial as it sounds, btw)
3. Depending on output volume a town or industry may have one or several destinations (towns or industries). Those are just the first ones being connected to it in the link graph. The information about those destinations is saved as some kind of list in the link graph job and after joining the link graph job becomes persistent and is then added to all new link graph jobs of the respective cargo. (so that other companies can build parallel routes)
4. The "destinations" demand handler only assigns demands that follow those destinations.
5. The destinations can then be shown in the town or industry GUI.
Of course this doesn't meet the requirement of pre-existing destinations. Destinations are still generated from the link graph. However, once a destination is established it stays around forever and there is a limited number of destinations per source. Note that you don't have to determine global production, global demand, distances of all possible destination tiles or similar things like that.
You have to familiarize yourself with the concept that actual cargo routing and computation of the routing scheme are two completely separate things in cargodist. This has proven to be quite advantagious and IMHO you should stick to it. So no, cargo generation is about the worst place to do that.3298 wrote:3. (the first one) Cargo generation seems to be the logical place to do this.
You may want to add two additional demand modes: symmetric destinations and asymmetric destinations.3298 wrote:Note that YACD does have symmetric and asymmetric demand too, but it seems hardwired to be symmetric for passengers and asymmetric for everything else.
Think again. How do you determine "potential destinations"? If you find a good solution for that please go ahead. I've tried and I couldn't.3298 wrote:On the other hand, I would already be kinda happy if Cargodist dropped cargo based on how many potential destinations are unreachable. On a second thought, that should be quite a bit easier to pull off.