Page 1 of 154

Cargo Distribution

Posted: 24 Feb 2009 00:37
by fonso
So, this is the (n+1)th attempt to provide passenger and cargo with destinations and then getting them there using the existing transport links as efficiently as possible. This means it includes what others call "load balancing". I have moved the main description of cargodist into the wiki, see http://wiki.openttd.org/Passenger_and_c ... stribution. Here you'll only get some status information on the progress for the different mile stones. Basically cargodist does what I envisioned when I started it and now I'm only tweaking some things to integrate it more nicely with the rest of the game. You can get the code from my github repository at http://github.com/ulfhermann/openttd . The relevant branch is "cd". Have a look at https://github.com/ulfhermann/openttd/commits/cd to see the individual milestones which have been reached. If you don't want to use git you can get a diff between trunk and cd at this URL: https://github.com/ulfhermann/openttd/c ... ...cd.diff . You can always find the current trunk revision the patch is meant to be applied to by looking at the topmost commit at https://github.com/ulfhermann/openttd/commits/master . You can also download a source package from https://github.com/ulfhermann/openttd/archive/cd.zip and directly compile that without patching. It is equivalent to the openttd source package, but has cargodist included.

To check out the release branch, do:

Code: Select all

git clone git://github.com/ulfhermann/openttd.git
git checkout origin/cd
The openttd compile farm creates binaries for various platforms from the "cd" branch every night and stores them at http://bundles.openttdcoop.org/cargodist/. Downloading a bundle from there is probably the fastest way to get started with cargodist. If you experience a crash please go ahead and post a report, including crash.log, crash.sav, crash.png and crash.dmp (if available) in this thread. The same goes for any non-crashing unexpected behavior or anything you think might be a bug. I'll examine and fix the problem as soon as possible. If you like to discuss how to play with cargodist and what strategies to apply and so on, please do that in this thread: http://www.tt-forums.net/viewtopic.php?f=29&t=58091

My plan for further development is (in no particular order):
  • Support more order modifications like "unload all" and "transfer" in the routing algorithm rather than just routing like they don't exist.
  • Make the time a thread gets for calculating the linkgraph dependent on the relevant settings and the size of the linkgraph to be calculated. Right now the time reserved for the link graph calculation is based on a worst case scenario and thus very long. This is the direct cause of the long delay between changes in the game and reactions in the routing scheme.
  • Convince people to publicly play network games and show to the devs that Cargodist really is stable and ready for trunk inclusion (or fix any bugs showing up in that process).

Re: Link Capacities

Posted: 24 Feb 2009 03:40
by audigex
This sounds very nice, better than the approximate estimation of traffic we have to rely on now.

1) If the station has passengers piling up, it needs more trains
2) If trains are consistantly partially empty, you can remove trains.

It takes so long to check 2) that most routes end up with too many trains, and any shared track ends up with so many trains on it that half the game is spent upgrading it.

Assuming you get this finished, it could be a massive time saver :)

Re: Link Capacities

Posted: 24 Feb 2009 09:16
by fonso
The timesaving when estimating which routes are over- and underloaded is already feasible. The only problem is that you can't decipher the numbers in the smallmap for short links. If someone comes up with an idea how to solve that and if that's easy to do I'll implement it. For now I'll stick to saving and configuration.

OK, I'll come up with an idea myself: The overall capacity of a link could be represented by the width of a line and the usage ratio by its color. Then you don't need the numbers anymore. I'll try to implement it.

Re: Link Capacities

Posted: 24 Feb 2009 23:40
by Zuu
An idea that pops out of my head is to draw the higher level network not only in the minimap but as a overlay in the main viewport. That way there is more space for more details. Though the overview that might be as important is lost then. And would probably require quite some initial coding time to get that started.

Re: Link Capacities and Connected Components

Posted: 03 Mar 2009 10:16
by fonso
updated. See first post.

Re: Cargo Distribution

Posted: 13 Mar 2009 22:38
by fonso
updated again. See first post. But if no one is interested I will stop updating and only tell you when it's done ...

Re: Cargo Distribution

Posted: 14 Mar 2009 00:27
by SirXavius
No no, don't do that! If you keep us aware of how things are coming along, then we're comforted in a small way that you're still working on it. As a Cargodest fan, i'm interested in your work. But like most of us, i'm more interested in its implementation and what it means to gameplay. This is why we want to know how it's going.

Remember, a lot more folks are interested in your work than those who will actually place a comment in this thread.... Our deep-down dream is that you don't give up, especially because you don't think anyone cares about what you're doing! :wink:

Re: Cargo Distribution

Posted: 16 Mar 2009 19:02
by fonso
So, I found a new toy called git. It allows me to easily create and maintain hierarchical patches on top of each other. So I can give you the link capacities which are fairly useful on their own as standalone version, which is still being maintained while I work on other parts of cargo distribution. As patches to be applied on top of that you get first connected components and then demands. Others will follow. While I did all that I also cleaned up the code so that it conforms to OpenTTD coding standards (or at least tries to). Due to the 3 file limit I'll post only the capacities patch and an all-in-one patch with all of cargo distribution in the first post.

Re: Cargo Distribution

Posted: 17 Mar 2009 02:05
by audigex
This looks very good, especially compared to what you had when I first posted.

Any chance of a binary? Visual Studio is having a disagreement with my laptop :-(

Re: Cargo Distribution

Posted: 17 Mar 2009 10:29
by fonso
audigex wrote:This looks very good, especially compared to what you had when I first posted.

Any chance of a binary? Visual Studio is having a disagreement with my laptop :-(
Not from me. I don't use Windows. But of course anyone is free to build a Windows binary. And if you tell me the exact problem you are having I might be able to find out if it's related to my code and fix it if that's the case.

Re: Cargo Distribution

Posted: 19 Mar 2009 14:39
by Zuu
I tried to use your combined diff from the first post. However examinating the patch I found out that SVN tortoise would probably not understand it, so i used patch.exe from cygwin. From reading the patch I figured -p0 is the correct way to apply it but that fails:

Code: Select all

G:\Programming\OpenTTD\Trunk>patch -p0 < cargodist_r15743.diff
patching file source.list
Assertion failed: hunk, file ../patch-2.5.9-src/patch.c, line 354

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
-p1 gives:

Code: Select all

G:\Programming\OpenTTD\Trunk>patch -p 1 < cargodist_r15743.diff
missing header for unified diff at line 5 of patch
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git source.list source.list
|index 6f34894..0080d24 100644
|--- source.list
|+++ source.list
--------------------------
File to patch:
I type source.list and <enter>

But then I get

Code: Select all

patching file source.list
missing header for unified diff at line 21 of patch
can't find file to patch at input line 21
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|,7 @@ heightmap.cpp
| highscore.cpp
| ini.cpp
| landscape.cpp
|+linkgraph.cpp
| map.cpp
| md5.cpp
| minilzo.cpp
--------------------------
File to patch:
Which seams to correspond to part of the changes to source.list.

I also tried google for patch.exe and downloaded it directly from GnuForWindows, but that just gave the same errors. (not surprisingly as it is the same version)



I don't know if it is anything you can do about it really, just wanted to inform that I tried to do something but it failed.

Edit: I have "updated" to version r15743 using SVN, which is the revision in the patch file name.

Re: Cargo Distribution

Posted: 19 Mar 2009 14:50
by jmurrayufo
Very cool project. I'll have to try compiling it this weekend. Any chance we can see a few pictures of the map overlays?

Re: Cargo Distribution

Posted: 19 Mar 2009 15:43
by fonso
Zuu wrote:I tried to use your combined diff from the first post. However examinating the patch I found out that SVN tortoise would probably not understand it, so i used patch.exe from cygwin. From reading the patch I figured -p0 is the correct way to apply it but that fails:

Code: Select all

G:\Programming\OpenTTD\Trunk>patch -p0 < cargodist_r15743.diff
patching file source.list
Assertion failed: hunk, file ../patch-2.5.9-src/patch.c, line 354

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
...
-p0 should be correct. The problem is that git produces diffs with some special lines the windows patch.exe doesn't understand. I'll try to create a Windows-friendly patch by manually running diff between two different trees later when I prepare today's update. And I'll give you a screenshot ...

Re: Cargo Distribution

Posted: 19 Mar 2009 21:52
by DaleStan
fonso wrote:I'll try to create a Windows-friendly patch by ...
I'd try removing the "index" and "new file" lines.

And Zuu, what's the output of patch -v or patch --version?

Re: Cargo Distribution

Posted: 19 Mar 2009 22:10
by Zuu
DaleStan wrote:And Zuu, what's the output of patch -v or patch --version?
patch 2.5.9

And then the copyright notice.

Re: Cargo Distribution

Posted: 20 Mar 2009 00:15
by DaleStan
Very much not the answer I was expecting. My patch(1) ("patch 2.5.8", from Cygwin) can apply the patch just fine. Are you sure that the line endings in the diff and the source match?

Re: Cargo Distribution

Posted: 20 Mar 2009 01:04
by fonso
So here are the three patches up-to-date with configurable demands functions per cargo class and with an antisymmetric demand function. I removed all the index and /dev/null entries. Please tell me if that helps.

Re: Cargo Distribution

Posted: 20 Mar 2009 07:35
by Zuu
DaleStan wrote:Very much not the answer I was expecting. My patch(1) ("patch 2.5.8", from Cygwin) can apply the patch just fine. Are you sure that the line endings in the diff and the source match?
About line endings, most likely not. As SVN tortoise convert the line endings if I recall correctly. Meaning that I need to convert the patch file too. As reading your post I guess the patch tool do not handle differences in line ending characters between source and patch file. (or at least not without applying some flag for that)

Thanks for pointing out that DaleStan.

Re: Cargo Distribution

Posted: 22 Mar 2009 22:59
by audigex
fonso wrote:
audigex wrote:This looks very good, especially compared to what you had when I first posted.

Any chance of a binary? Visual Studio is having a disagreement with my laptop :-(
Not from me. I don't use Windows. But of course anyone is free to build a Windows binary. And if you tell me the exact problem you are having I might be able to find out if it's related to my code and fix it if that's the case.
Thanks for the offer, but it's nothing to do with your code :-) I can't even make it compile trunk and I'm at a complete loss as to why not. I need to try a different compiler when I get the time.

Re: Link Capacities and Cargo Distribution

Posted: 25 Mar 2009 00:55
by fonso
I have updated the first post and the patches. I'm using git's patch format again as no one could say if the other one is better. You get the all-in-one patch in this post.