(svn r25948) -Fix [FS#5796]: Make sure LinkRefresher doesn't delete the LinkGraph DeleteStaleLinks() is examining.

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
fonsinchen 11 years ago
parent fbceb10ff5
commit f6fd21e8e6

@ -20,8 +20,9 @@
/** /**
* Refresh all links the given vehicle will visit. * Refresh all links the given vehicle will visit.
* @param v Vehicle to refresh links for. * @param v Vehicle to refresh links for.
* @param allow_merge If the refresher is allowed to merge or extend link graphs.
*/ */
/* static */ void LinkRefresher::Run(Vehicle *v) /* static */ void LinkRefresher::Run(Vehicle *v, bool allow_merge)
{ {
/* If there are no orders we can't predict anything.*/ /* If there are no orders we can't predict anything.*/
if (v->orders.list == NULL) return; if (v->orders.list == NULL) return;
@ -31,7 +32,7 @@
if (first == NULL) return; if (first == NULL) return;
HopSet seen_hops; HopSet seen_hops;
LinkRefresher refresher(v, &seen_hops); LinkRefresher refresher(v, &seen_hops, allow_merge);
refresher.RefreshLinks(first, first, v->last_loading_station != INVALID_STATION ? 1 << HAS_CARGO : 0); refresher.RefreshLinks(first, first, v->last_loading_station != INVALID_STATION ? 1 << HAS_CARGO : 0);
} }
@ -59,9 +60,12 @@ bool LinkRefresher::Hop::operator<(const Hop &other) const
/** /**
* Constructor for link refreshing algorithm. * Constructor for link refreshing algorithm.
* @param vehicle Vehicle to refresh links for. * @param vehicle Vehicle to refresh links for.
* @param seen_hops Set of hops already seen. This is shared between this
* refresher and all its children.
* @param allow_merge If the refresher is allowed to merge or extend link graphs.
*/ */
LinkRefresher::LinkRefresher(Vehicle *vehicle, HopSet *seen_hops) : LinkRefresher::LinkRefresher(Vehicle *vehicle, HopSet *seen_hops, bool allow_merge) :
vehicle(vehicle), seen_hops(seen_hops), cargo(CT_INVALID) vehicle(vehicle), seen_hops(seen_hops), cargo(CT_INVALID), allow_merge(allow_merge)
{ {
/* Assemble list of capacities and set last loading stations to 0. */ /* Assemble list of capacities and set last loading stations to 0. */
for (Vehicle *v = this->vehicle; v != NULL; v = v->Next()) { for (Vehicle *v = this->vehicle; v != NULL; v = v->Next()) {
@ -190,10 +194,19 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
if (st != NULL && next_station != INVALID_STATION && next_station != st->index) { if (st != NULL && next_station != INVALID_STATION && next_station != st->index) {
for (CapacitiesMap::const_iterator i = this->capacities.begin(); i != this->capacities.end(); ++i) { for (CapacitiesMap::const_iterator i = this->capacities.begin(); i != this->capacities.end(); ++i) {
/* Refresh the link and give it a minimum capacity. */ /* Refresh the link and give it a minimum capacity. */
if (i->second == 0) continue; if (i->second == 0) continue;
CargoID c = i->first;
/* If not allowed to merge link graphs, make sure the stations are
* already in the same link graph. */
if (!this->allow_merge && st->goods[c].link_graph != Station::Get(next_station)->goods[c].link_graph) {
continue;
}
/* A link is at least partly restricted if a /* A link is at least partly restricted if a
* vehicle can't load at its source. */ * vehicle can't load at its source. */
IncreaseStats(st, i->first, next_station, i->second, IncreaseStats(st, c, next_station, i->second,
(cur->GetLoadType() & OLFB_NO_LOAD) == 0 ? LinkGraph::REFRESH_UNRESTRICTED : LinkGraph::REFRESH_RESTRICTED); (cur->GetLoadType() & OLFB_NO_LOAD) == 0 ? LinkGraph::REFRESH_UNRESTRICTED : LinkGraph::REFRESH_RESTRICTED);
} }
} }

@ -23,7 +23,7 @@
*/ */
class LinkRefresher { class LinkRefresher {
public: public:
static void Run(Vehicle *v); static void Run(Vehicle *v, bool allow_merge = true);
protected: protected:
/** /**
@ -87,8 +87,9 @@ protected:
RefitList refit_capacities; ///< Current state of capacity remaining from previous refits versus overall capacity per vehicle in the consist. RefitList refit_capacities; ///< Current state of capacity remaining from previous refits versus overall capacity per vehicle in the consist.
HopSet *seen_hops; ///< Hops already seen. If the same hop is seen twice we stop the algorithm. This is shared between all Refreshers of the same run. HopSet *seen_hops; ///< Hops already seen. If the same hop is seen twice we stop the algorithm. This is shared between all Refreshers of the same run.
CargoID cargo; ///< Cargo given in last refit order. CargoID cargo; ///< Cargo given in last refit order.
bool allow_merge; ///< If the refresher is allowed to merge or extend link graphs.
LinkRefresher(Vehicle *v, HopSet *seen_hops); LinkRefresher(Vehicle *v, HopSet *seen_hops, bool allow_merge);
void HandleRefit(const Order *next); void HandleRefit(const Order *next);
void ResetRefit(); void ResetRefit();

@ -3447,7 +3447,7 @@ void DeleteStaleLinks(Station *from)
* - We could try to figure out if we've seen a consist with the same cargo on the * - We could try to figure out if we've seen a consist with the same cargo on the
* same list already and if the consist can actually carry the cargo we're looking * same list already and if the consist can actually carry the cargo we're looking
* for. With conditional and refit orders this is not quite trivial, though. */ * for. With conditional and refit orders this is not quite trivial, though. */
LinkRefresher::Run(v); LinkRefresher::Run(v, false); // Don't allow merging. Otherwise lg might get deleted.
if (edge.LastUpdate() == _date) updated = true; if (edge.LastUpdate() == _date) updated = true;
} }
if (updated) break; if (updated) break;

Loading…
Cancel
Save