Re: [Bug v3.7] Off-by-One in IF Condition of calculate_paths()
Reply #2 –
James,
It seems to me that the code does not exhibit the same behaviour as you have described.
****uming max_rerouting_interval_months = 2, each time rebuild_connexions() is called, connexions_timestamp[c] is set either to the value of base_pathing_counter (in case where reschedule[c] is false) or to base_pathing_counter + 1 (in case where reschedule[c] is true). Thus, rebuilding of connexions will happen after 2 or 3 months, depending on reschedule[c]. I fail to see why path reconstruction will be done 3 months later instead of the default 2 months.
Incidentally, for this part of code in calculate_paths() :
if(paths_timestamp[category] <= welt->get_base_pathing_counter() - welt->get_einstellungen()->get_max_rerouting_interval_months() || welt->get_base_pathing_counter() >= (65535 - welt->get_einstellungen()->get_max_rerouting_interval_months()))
{
// List is stale. Recalculate.
// If this is false, then this is only being called to finish
// calculating paths that have not yet been calculated.
if(!open_list.empty())
{
open_list.clear();
delete[] path_nodes;
}
// Reset the timestamp.
paths_timestamp[category] = welt->get_base_pathing_counter();
}
Probably you may want to add reschedule[category] to the IF condition. The reason is that, when reschedule[c] is true, the paths become immediately stale and are deleted in get_path_to(), so all paths will be recalculated. In that case, paths_timestamp[c] should also be set to the value of base_pathing_counter, so that path reconstruction will not happen again shortly. I suppose this is the behaviour you expect, right?
Lastly, one more minor suggestion. I can see that the IF conditions for paths_timestamp[c] and connexions_timestamp[c] contain the same expressions : welt->get_base_pathing_counter() and welt->get_einstellungen()->get_max_rerouting_interval_months(). Maybe you can add a local variable to save the 2 values before the IF conditions, to shorten such lenghy IF conditions?