News:

Simutrans Tools
Know our tools that can help you to create add-ons, install and customize Simutrans.

Factor out max speed calculation

Started by Dwachs, October 23, 2014, 09:09:41 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Dwachs

The calculation of possible max speed in depot window sometimes gives wrong values, see http://forum.simutrans.com/index.php?topic=13940

The patch factors out the computation of residual power from the calc_acceleration routine. Then uses this auxiliary routine to find the maximum possible speed
by bisection. Here, maximum possible speed is the maximum speed that is reachable under the algorithm used in calc_accerlation.

Any comments?
Parsley, sage, rosemary, and maggikraut.

DrSuperGood

Error in one of your comments.

+/**
+ * Returns residual power given power, weight, and current speed.
+ * @param speed (in internal speed unit)
+ * @param total_power sum of power times gear (see calculation of sum_gear_und_leistung)
+ * @param total_weight weight including friction of the convoy
+ * @param total_weight weight of the convoy
+ * @returns maximum possible speed given the internal accelaration calculation with integers
+ */
+static inline sint32 res_power(sint64 speed, sint32 total_power, sint64 friction_weight, sint64 total_weight)
+{
+ sint32 res = total_power - (sint32)( ( (sint64)speed * ( (friction_weight * (sint64)speed ) / 3125ll + 1ll) ) / 2048ll + (total_weight * 64ll) / 1000ll);
+ return res;
+}

total_weight is listed twice as a parameter instead of friction_weight being mentioned.

Is it really necessary to do iteration to find the theoretical maximum speed?

TurfIt

Can't say I've seen the value off as far as described in the linked thread, but iteration certainly gives a more accurate result... Perhaps too accurate - maybe some tolerance to stop the bisection once within 0.5 km/h ?

How about using the current estimate formula for the starting point of the bisection? The formula could likely use some attention to make more accurate too... I see a change in the deccel calculation a couple years ago but no change to the formula then, perhaps the change made the formula more accurate already, or just forgotten about. Seems like ~3% change introduced in r5781

Bisection could be skipped entirely if the residual power at the convoi's min_top_speed is still positive. Just return the min_top_speed, convois are always capped to that anyway.

The whole point of adding this display to the depot was to show the max speed bonus value with overloaded convois. Hence shouldn't the speedbonus use the bisection results too?

prissi

The actual final speed depends also a little on the delta_t. Hence in fast forward records tend to be slightly higher.

For the speed bonus indeed I think both should use the same formula. But the calculation needs to be only done when a convoi is started; hence also the "coorect" one should be fine.

Dwachs

Here is an updated patch. The impact on performance is negligible.
Parsley, sage, rosemary, and maggikraut.

prissi