News:

Simutrans.com Portal
Our Simutrans site. You can find everything about Simutrans from here.

[devel-new] Maximum waiting time doesn't work

Started by Rollmaterial, July 13, 2016, 09:15:30 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rollmaterial

When using maximum waiting time, convoys never depart.

Isaac Eiland-Hall

max_wait_time = heat_death_of_universe

Change that to something else in simuconf.tab. ;-)

Milko

Hello

I have same problem, convoy never depart setting max load not 0, or depart immediatly if max load = 0.

Giuseppe

jamespetts

I cannot reproduce this in a very simple case: can anyone upload a saved game in which this can reliably be reproduced?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.


jamespetts

Thank you for that. I think that I have managed to fix this; would you mind re-testing?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Rollmaterial

The original bug seems fixed, except that now normal spacing doesn't work :/

jamespetts

Thank you for letting me know. This should work correctly now; would you mind re-testing again?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Rollmaterial

Now from the second time on, the convoy will always wait for the specified time, even if the minimum amount of load is reached.

jamespetts

I am currently reviewing old bug reports and I notice that this one appears to have no reported resolution. May I ask whether this can still be reproduced?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

A.Badger

I believe so.  Tested with nightly downloaded on 20170228 with pak128.britain-ex downloaded the same day.

Here's a save game showing the problem: https://toshio.fedorapeople.org/simutrans/departure-waits-for-full-max-wait-time.sve

The brig has a 75t hold.  It is set to wait for a minimum of 10% filled (so 8t of food) and a maximum wait time of 1 month.

When you start the save game, the brig should be about ready to return from the dairy dock to the cattle farm dock.  Once it gets to the cattle farm, you should be able to observe that it's countdown timer starts at the limit for a full month and starts going down.  At some point before the timer expires, the farm sends 10 milk to the dock and that is loaded onto the brig.  The countdown timer continues to go down uninterrupted instead of going immediately to zero (as the minimum fill percentage has now been satisfied).

jamespetts

Thank you for the report. Can I clarify - when you refer to the "countdown timer", are you referring to the time displayed on hovering next to "Loading:"? If so, this is the time that it takes to load the cargo onto the ship, so this should remain constant even when the minimum load is reached; or are you referring specifically to a waiting time?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

A.Badger

Correct, the countdown in the hover text is what I'm referring to as the countdown timer.  However, presently, it's not showing just the time it takes to load cargo on the brig.  It's showing the max(loading time, wait for load).  That may be a bug (as the tooltip says "Loading:" rather than "Departure in:") but departure time does seem to be more generally useful than just the waiting time.

* When you load the save game and see what the countdown timer displays after it reaches the cattle dock, it presently reads 6:23:59 or so.
* Reload from the save game, pause the game, open up the line's schedule and set the "Max. wait for load" from 6:24:00 to 3:12:00.  let the game run and when the Brig reaches the cattle dock, pause it and observe the time displayed when hovering.  It presently reads 3:11:59 or so.
* The loading time for the Brig is supposed to be between 45:00 and 1:30:00.  So reload the game, pause it, open the line's schedule and set the "Max. wait for load" to 24:00, the first value below the Brig's loading time.  Let the game run and when the Brig reaches the cattle dock, observe the time displayed while hovering.  For me it reads 44:59, at the bottom end of the Brig's loading range.  I'm not sure if the loading time is calculated on 100% stable values or if there's a random calculation thrown in there but everytime I've checked, this is in the convoy's loading time range.

A.Badger

Browsing the code, I think I've figured out what section of the code the problem is in but I'm not sure precisely what the solution is (as I've now confused myself about what the expectations are)

* I'm reasonably certain the problem is in this section which seems to deal with when a convoy can be released from a station: https://github.com/jamespetts/simutrans-extended/blob/master/simconvoi.cc#L5597-L5632

* Reading the code, there's a few things that need to be mapped from the GUI to understand what it's doing.  This is what I think the mapping is:
  * "Minimum load" in the GUI equates to loading_limit
  * "Max. wait for load" in the GUI equates to waiting_time_shift in the code
  * "Wait for time" in the GUI equates to wait_for_time in the code
  * "spacing convoys per month" equates to schedule->get_spacing()
  * "spacing shift" equates to spacing_shift
  * Other factors (reversing, convoy's load time, etc)  I believe this gets encapsulated into earliest_departure_time earlier in the code
  * Current convoy load is loading_level


If the mapping is right, then we want:
* If !loading_limit and !wait_for_time then leave if now > earliest_departure_time
* If !wait_for_time && loading_limit then leave if:
  * now > (earliest_departure_time + wait_for_time_shift)
  * OR loading_level >= loading_limit

* If wait_for_time I'm not entirely sure how it interacts with loading_limit.  The documentation says that both need to be set which imply that there's an OR here:
  * Release if we're the next convoy in the queue and now > the start of the next open slot
  * OR loading_level >= loading_limit

  However, the UI disables "Minimum load" when "wait for time" is checked and other parts of the code set minimum_load = 0 if wait_for_time is set.  This implies that if wait_for_time is set we should ignore loading_limit/loading_level and just do this:
  * Release if we're the next convoy in the queue and now > the start of the next open slot

Now let's look at the current comparisons:

bool can_go = false;

can_go = loading_level >= loading_limit && now >= go_on_ticks;
can_go = can_go || (now >= go_on_ticks && !wait_for_time);
can_go = can_go || running_late;
can_go = can_go || no_load;                                              // This is a cornercase when the vehicle (is empty?  Or doesn't have anything to do at this stop?)
        can_go = can_go && now > earliest_departure_time;


The first two conditionals are a problem.  go_on_ticks is being set from waiting_time_shift when wait_for_time is not set.  Therefore we need something like this to represent "minimum load" + "max wait for load":

can_go =  !wait_for_time && (loading_level >= loading_limit || now >= go_on_ticks);


But with that change, the only thing that handles the convoy spacing feature is can_go || running_late;.  It seems like there should be something else there as well... like

can_go = can_go || (wait_for_time && now >= go_on_ticks)

but I'm not sure if that's correct.  Perhaps it's not needed because running_late is recalculated frequently enough that we can wait until running_late is true to go.  Or perhaps when wait_for_time is set go_on_ticks is being used for something else, not for the start of the next open slot.

jamespetts

Thank you very much for testing this: this is most helpful. I have just pushed what I think is a fix to this (as well as including, commented out, the code that was present before the 14th of August 2016 that gave rise to the original bug reports). Would you be able to re-test this to see whether the problem is now fixed? I should be most grateful.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

A.Badger

tested with latest nightly: rbbea0d4

Looks like this now works!  I tested the following, all working:

* My original test case.  As expected, the ship waited until either loading time && load_level was satisfied or max(loading_time, max_wait_for_load)
* Tested with a single ship and set for two departures from the cattle farm per month.  As expected, the ship left the dock twice, at 00:00 and 3:12:00
* Tested with three ships (one of which had the wrong hold  type to ever load anything from the cattle farm) and set number of departures per month.  Each ship left the cattle farm once per month at approximately 2 hour intervals (to fill out the `6 hour month)

Thanks James!

jamespetts

Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.