Feature: [Linkgraph] Prioritize faster routes for passengers, mail and express cargo
Passengers usually prefer fast paths to short paths. Average travel times of links are updated in real-time for use in Dijkstra's algorithm, and newer travel times weigh more, just like capacities.
This commit is contained in:

committed by
Michael Lutz

parent
6acf204d14
commit
977604ef08
@@ -218,6 +218,12 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
|
||||
/* A link is at least partly restricted if a vehicle can't load at its source. */
|
||||
EdgeUpdateMode restricted_mode = (cur->GetLoadType() & OLFB_NO_LOAD) == 0 ?
|
||||
EUM_UNRESTRICTED : EUM_RESTRICTED;
|
||||
Station *st_to = Station::GetIfValid(next_station);
|
||||
/* This estimates the travel time of the link as the time needed
|
||||
* to travel between the stations at half the max speed of the consist.
|
||||
* The result is in tiles/tick (= 2048 km-ish/h). */
|
||||
uint32 time_estimate = (st_to != nullptr) ?
|
||||
DistanceManhattan(st->xy, st_to->xy) * 4096U / this->vehicle->GetDisplayMaxSpeed() : 0;
|
||||
|
||||
/* If the vehicle is currently full loading, increase the capacities at the station
|
||||
* where it is loading by an estimate of what it would have transported if it wasn't
|
||||
@@ -231,15 +237,15 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
|
||||
uint effective_capacity = cargo_quantity * this->vehicle->load_unload_ticks;
|
||||
if (effective_capacity > (uint)this->vehicle->orders.list->GetTotalDuration()) {
|
||||
IncreaseStats(st, c, next_station, effective_capacity /
|
||||
this->vehicle->orders.list->GetTotalDuration(), 0,
|
||||
this->vehicle->orders.list->GetTotalDuration(), 0, 0,
|
||||
EUM_INCREASE | restricted_mode);
|
||||
} else if (RandomRange(this->vehicle->orders.list->GetTotalDuration()) < effective_capacity) {
|
||||
IncreaseStats(st, c, next_station, 1, 0, EUM_INCREASE | restricted_mode);
|
||||
IncreaseStats(st, c, next_station, 1, 0, 0, EUM_INCREASE | restricted_mode);
|
||||
} else {
|
||||
IncreaseStats(st, c, next_station, cargo_quantity, 0, EUM_REFRESH | restricted_mode);
|
||||
IncreaseStats(st, c, next_station, cargo_quantity, 0, time_estimate, EUM_REFRESH | restricted_mode);
|
||||
}
|
||||
} else {
|
||||
IncreaseStats(st, c, next_station, cargo_quantity, 0, EUM_REFRESH | restricted_mode);
|
||||
IncreaseStats(st, c, next_station, cargo_quantity, 0, time_estimate, EUM_REFRESH | restricted_mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user