Cargo Distribution

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

User avatar
fonso
President
President
Posts: 945
Joined: 13 Oct 2007 08:28

Re: Cargo Distribution

Post by fonso »

MJS wrote:With the r16055 exe version I get 100% CPU load and then game crashes. I run the 2cc set on a 512/256 map with snowy terrain. What debugging/crash information can I send in to help?

(I've just built a network with an eye on the CPU meter all the time. Seems that my method of making a few very long-distance connections with very few stations all across the map brings CPU up quite a lot.; up to 60% for some time after I open the link, with just two trains. See attached image. The other two trains run a local line with four stops.)
I'll release a new version later today with some bugs corrected and a new MCF algorithm. Unfortunately that will break savegame compatibility, so I don't know if I'll get around to debugging that problem. But still it would be nice to have a savegame of shortly before the crash and a screenshot of the economy and linkgraph settings.
The guy on the picture is not me, it's Alonso.
User avatar
fonso
President
President
Posts: 945
Joined: 13 Oct 2007 08:28

Re: Cargo Distribution

Post by fonso »

In the first post find the new version.

Notable changes:
  • New algorithm for solving the MCF. Does balance routes, doesn't use floats, doesn't produce numeric instability, doesn't overplan links, is somewhat inspired by previous algorithm but easier to understand.
  • Bug fixed: When removing a station, the cargo being sent there from other stations wasn't invalidated
  • Bug fixed: When a link disappeared during the linkgraph calculation a plan for it could still be made and committed into the main game state later.
There's nothing new in the GUI for this release, but I'm quite pleased with everything else now. I'll concentrate on the GUI now.
The guy on the picture is not me, it's Alonso.
as
Transport Coordinator
Transport Coordinator
Posts: 281
Joined: 07 Mar 2007 20:13

Re: Cargo Distribution

Post by as »

Win32 binary:

btw. MSVC linking fails because demand_settings.h is not in source.list and project files
Attachments
cargodist_r16058.diff.zip
(3.92 MiB) Downloaded 132 times
mullie0
Engineer
Engineer
Posts: 14
Joined: 13 Oct 2008 11:40

Re: Cargo Distribution

Post by mullie0 »

How long does it take before a link disappears?

For instance when you make a new route and remove old ones
User avatar
fonso
President
President
Posts: 945
Joined: 13 Oct 2007 08:28

Re: Cargo Distribution

Post by fonso »

as wrote:btw. MSVC linking fails because demand_settings.h is not in source.list and project files
Thanks. Will be fixed.
mullie0 wrote:How long does it take before a link disappears? For instance when you make a new route and remove old ones
That depends on the capacity of the old route and your moving average settings. The link capacity is multiplied with average_length and then divided by (average_length + 1) every average_unit days. As this is an integer calculation it will be reduced by 1 every average_unit days if it is smaller than average_length. When it reaches 0 it disappears. So if you set your average length and average unit low, it will disappear more quickly. On the other hand, if you have links that are regularly but infrequently served and the average unit and length are low, those links might disappear as well before the next vehicle comes.
The guy on the picture is not me, it's Alonso.
User avatar
Ammler
President
President
Posts: 953
Joined: 18 Jun 2006 18:18
Location: Switzerland
Contact:

Re: Cargo Distribution

Post by Ammler »

We would like to playtest your patch, is the git repo available to clone/pull/update somehow? Would be easier than fiddeling with patch. ;-)
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: Cargo Distribution

Post by TrueBrain »

You can publish your git on many places (github I believe allows it for free). The reason I hint to this method, is that you can ask me if our Compile-Farm can run your source. It then produces binaries for you for all targets the nightly is in, in a way that is identical and correct ;) Feel free to PM me when ever you need a version.
The only thing necessary for the triumph of evil is for good men to do nothing.
User avatar
fonso
President
President
Posts: 945
Joined: 13 Oct 2007 08:28

Re: Cargo Distribution

Post by fonso »

Access via git is now available. See first post.
The guy on the picture is not me, it's Alonso.
jmurrayufo
Engineer
Engineer
Posts: 22
Joined: 24 May 2008 23:06

Re: Cargo Distribution

Post by jmurrayufo »

Got the patch to compile, but saddly I am stuck in school work till sunday ish. Hopfully i'll get a chance to play around then!
jungle
Engineer
Engineer
Posts: 76
Joined: 17 Dec 2004 23:40
Location: UK

Re: Cargo Distribution

Post by jungle »

I think this patch is pretty impressive having started a quick game with it. No crashes yet, which is great considering how little testing from players it's had so far!

My only issue is that it shares one of the problems of the previous patch, in that it seems to generate intensely large numbers of passengers on local (within-city) routes compared to inter-city routes between towns, to the extent that no amount of bus routes can reasonably cope, at least in the early part of any game containing cities (before the higher capacity trams come in).
User avatar
fonso
President
President
Posts: 945
Joined: 13 Oct 2007 08:28

Re: Cargo Distribution

Post by fonso »

jungle wrote: My only issue is that it shares one of the problems of the previous patch, in that it seems to generate intensely large numbers of passengers on local (within-city) routes compared to inter-city routes between towns, to the extent that no amount of bus routes can reasonably cope, at least in the early part of any game containing cities (before the higher capacity trams come in).
This problem can either be solved in several ways:

1. by building more stations in the cities, so that less passengers are generated for each station but more space is available for the vehicles serving them. Also, build direct routes to the inter-city stations as there probably are a lot of passengers who'd like to leave the city but are stuck somewhere.
2. by reducing the overall amount of passengers generated. This option is out of scope for this patch and can easily be done independently.
3. by modifying the demand function. This can be done, but the question is: how would you like it? I think it is good that it assigns a high demand to short links between stations with high supply. The demand curve could be smoothed out a bit, but I wouldn't change it dramatically. After all, also in reality local transport is the place where the greatest amount of passengers is generated and there frequently are problems meeting the demand for local transport. It should be hard to build a working local transport network in a city in OpenTTD, too.
4. by restricting the capacity of stations. This is a whole new topic, though.

I suggest you try option 1 first and if that doesn't help, I'd suggest option 2. If someone comes up with a clever modification of my demand algorithm I'll think about that, too. And you can have a look at my prototype implementation of station capacities if you're interested.
The guy on the picture is not me, it's Alonso.
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Cargo Distribution

Post by reylas »

I downloaded the binary linked above to give this a try, and I must say, good job on the implementation. But I do have a few suggestions on how to improve things.

I was excited at first when I started running this patch as it seemed like it was what I was looking for. But as the game went on, I found myself wondering what this actually adds to the game. I started out with about 6 coal mines servicing one power plant. What I expected when I loaded the patch was that those coal mines *already* had a destination in mind for its coal and that I would have to build new networks to handle it all. But what I found was that they only wanted to send coal to a new destination if I added a route to that destination. Even worse, I could add a power plant with a terminal, but new destinations would come up only if I had a train (a route) service that terminal.

What I thought would happen is that the patch would either.
A) have pre-conceived destinations for cargo *before* I built a route so that I would have to manage how and when I brought things online.
B) See that I have a station at a Powerstation and demand that I somehow deliver coal there. Right now, it waits till I create a train route and then finds the best way there. Well, that kinda automates things and really is not much of a change. If it takes the responsibility of getting it the best way there without me doing much, then the game is no different.

Would it be possible for your cargodest to see that I have a terminal next to a powerstation and demand that I find a way to get it there instead of doing it automatically? The way it is now, it would not work with the budget patch as my coal mines would want to service a powerstation and the powerstation would not have the budget to buy it so coal would be produced that could not be sold.

I would like to click a coal mine and see that he has a contract to deliver coal to 2-3 different powerplants and then build my network (with including transfer orders) to service that coal mine. Much like the real world.

Now it is too automated. It sees that I have a working route and decides on its own that it will send coal the best way possible to the destination it wants to go without any feedback from me.

Now having said all that, please understand I like what you are doing, and only wanted to offer suggestions. I mean no offense by anything. I am only hoping to start a discussion on what you are hoping to accomplish.

Reylas
User avatar
fonso
President
President
Posts: 945
Joined: 13 Oct 2007 08:28

Re: Cargo Distribution

Post by fonso »

reylas wrote: What I thought would happen is that the patch would either.
A) have pre-conceived destinations for cargo *before* I built a route so that I would have to manage how and when I brought things online.
B) See that I have a station at a Powerstation and demand that I somehow deliver coal there. Right now, it waits till I create a train route and then finds the best way there. Well, that kinda automates things and really is not much of a change. If it takes the responsibility of getting it the best way there without me doing much, then the game is no different.

Would it be possible for your cargodest to see that I have a terminal next to a powerstation and demand that I find a way to get it there instead of doing it automatically? The way it is now, it would not work with the budget patch as my coal mines would want to service a powerstation and the powerstation would not have the budget to buy it so coal would be produced that could not be sold.

I would like to click a coal mine and see that he has a contract to deliver coal to 2-3 different powerplants and then build my network (with including transfer orders) to service that coal mine. Much like the real world.

Now it is too automated. It sees that I have a working route and decides on its own that it will send coal the best way possible to the destination it wants to go without any feedback from me.
Generally, what you describe is out of scope for the cargo distribution. I don't preconceive destinations for individual cargo packets, because that makes things much more complicated. And I don't precalculate demands for all of the map, because that would make the game really hard in the beginning. Also I'd need to decide what to do if several stations try to service a single industry and it gets even harder with stations servicing several industries and towns. That's why I went with the IMO elegant solution with capacity and supply as building blocks of the link graph and calculate everything on top of that.

Still, your suggestion can be added as an "industry contracts" patch on top of cargo distribution:

First you calculate the contracts however you like. A contract consists of a source station, a destination station and a volume. You could then hook a LinkgraphHandler into the link graph calculation before demands and introduce a virtual link between the stations that need to be services because of some contract. This would prompt the demand calculator to create a demand for them. You could also post-process the demand with a second handler or modify the demand function itself if you're not satisfied with what it does. Of course that demand couldn't be met until there is a real link, so you'd get cargo waiting at the source station for such a link. You could also modify the Join() method and save the demands that have been calculated for contracts somewhere, for example to show them in the industry window.

OK, it wouldn't work exactly like that now because it checks if a link is there before assigning flow, but with a few smaller tweaks it could be done.
The guy on the picture is not me, it's Alonso.
jungle
Engineer
Engineer
Posts: 76
Joined: 17 Dec 2004 23:40
Location: UK

Re: Cargo Distribution

Post by jungle »

fonso wrote:
jungle wrote: My only issue is that it shares one of the problems of the previous patch, in that it seems to generate intensely large numbers of passengers on local (within-city) routes compared to inter-city routes between towns, to the extent that no amount of bus routes can reasonably cope, at least in the early part of any game containing cities (before the higher capacity trams come in).
This problem can either be solved in several ways:
Thanks for these suggestions - initally will try building the stations so the coverage areas overlap more.

One more question - will the total number of passengers generated at a station remain constant when more destinations are connected to the network, resulting in smaller local flows? Or will the passengers generated increase further?
User avatar
fonso
President
President
Posts: 945
Joined: 13 Oct 2007 08:28

Re: Cargo Distribution

Post by fonso »

jungle wrote: One more question - will the total number of passengers generated at a station remain constant when more destinations are connected to the network, resulting in smaller local flows? Or will the passengers generated increase further?
I don't change the total number of passengers generated. So, yes, more passengers will be going to remote destinations and less to local destinations if more and larger remote destinations become available.
The guy on the picture is not me, it's Alonso.
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: Cargo Distribution

Post by Eddi »

jungle wrote:I think this patch is pretty impressive having started a quick game with it. No crashes yet, which is great considering how little testing from players it's had so far!

My only issue is that it shares one of the problems of the previous patch, in that it seems to generate intensely large numbers of passengers on local (within-city) routes compared to inter-city routes between towns, to the extent that no amount of bus routes can reasonably cope, at least in the early part of any game containing cities (before the higher capacity trams come in).
this is imho an intrinsic problem of the station rating system, because it only looks at the frequency that vehicles come in, not how much they can transport. this means, frequent road vehicle transports get highly overvalued while infrequent mammoth trains get highly undervalued. this in turn means that the station rating does not stabilize at an appropriate level for the generated cargo amount being balanced towards transport capacity.

if the station rating could stabilize at values like 12% for low capacity road vehicle networks, significantly fewer passengers would get generated. station ratings should majorly depend on the ratio of expected cargo (for 100% rating) and offered transport capacity, not just the frequency of service, which has practically no meaningful value.
jungle
Engineer
Engineer
Posts: 76
Joined: 17 Dec 2004 23:40
Location: UK

Re: Cargo Distribution

Post by jungle »

Eddi wrote:this is imho an intrinsic problem of the station rating system, because it only looks at the frequency that vehicles come in, not how much they can transport. this means, frequent road vehicle transports get highly overvalued while infrequent mammoth trains get highly undervalued.
True - however using passenger destinations potentially offers a better way of solving this problem than either frequency or capacity on their own.

Having thought a bit about it, I believe the problem is that under the current destinations system, as you connect more long distance routes to the city, congestion on suburban lines within the city will actually decrease as you remove passengers to other places (assuming your main railway station is near the centre where most passengers are generated). In real life of course congestion would increase as more local people got onto your network to go to the new destinations.

This is not a criticism of the destinations patch (which does the difficult task of assigning destinations very well, and massively beats all previous attempts :bow: ), but this passenger generation problem does mean that the results of using the patch go a little against common sense. People don't respond to being unable to catch a train to Glasgow by going down the road and back instead.

One solution might be to extend the passenger destinations patch to also determine the station rating, largely based on the percentage of passenger-producing tiles on the map accessible from it. If this gave nearby squares more weight than those further away, and took into account that some squares generate more passengers than others, this would offer some kind of approximation at real life. Unfortunately my lack of understanding of the workings of OTTD (and programming C generally) means I couldn't suggest how this would work in terms of code :oops:

Edit: I'd also suggest taking into account frequency of service for an arbitrary % of the rating (maybe 30%ish) - but not total capacity of service since this would mean that vehicles rarely got overcrowded even if massively inadequate for the scale of demand.
Last edited by jungle on 17 Apr 2009 19:58, edited 1 time in total.
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Cargo Distribution

Post by reylas »

First a problem, using the binary above of 16058, I cannot get links to die. It is this killing my network. I have several links now that show 0/0:0/0 in the map, but they stay there. Hence, none of the coal get delivered as I am trying to kill those routes. I want to drop coal off at a transfer station. Am I missing something on how they die?

Second, I currently have 390 tons of coal sitting at a station that has a destination that I do not want to deliver directly to. But there is currently one of those "hoping to die" links that keep other trains from picking it up. (ie station A has a link to station B and station C, I want the coal to go to station B then on to the power plant at C, but since it has a defunct link to C directly, it never gets picked up. I have no trains going from A to C directly, used to, but trying to get rid of that route). My question? Will those 390 tonnes ever get redirected to station B once that route dies? Or will it always sit there waiting for me to add a train that will keep that route from dieing
Attachments
Salyer Transport, 3rd Mar 1977.png
Salyer Transport, 3rd Mar 1977.png (144.96 KiB) Viewed 872 times
User avatar
fonso
President
President
Posts: 945
Joined: 13 Oct 2007 08:28

Re: Cargo Distribution

Post by fonso »

reylas wrote:First a problem, using the binary above of 16058, I cannot get links to die. It is this killing my network. I have several links now that show 0/0:0/0 in the map, but they stay there. Hence, none of the coal get delivered as I am trying to kill those routes. I want to drop coal off at a transfer station. Am I missing something on how they die?
Could you post a savegame, please? There shouldn't be links with 0 for capacity. This is a bug. As soon as those links are gone, the cargo waiting for them will be rerouted.
The guy on the picture is not me, it's Alonso.
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Cargo Distribution

Post by reylas »

Here it is. Let me know if you need more
Attachments
Salyer Transport, 20th Jul 1976 Bug.sav
(493.14 KiB) Downloaded 86 times
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 39 guests