1
0
Fork 0

(svn r26267) -Fix [FS#5865]: Really fix the infinite recursion problem and always consider all branches of conditional orders as possible next stopping stations.

release/1.4
fonsinchen 2014-01-19 09:27:44 +00:00
parent b158c7d0fa
commit 7e91f96b92
2 changed files with 17 additions and 31 deletions

View File

@ -263,7 +263,7 @@ public:
*/ */
inline VehicleOrderID GetNumManualOrders() const { return this->num_manual_orders; } inline VehicleOrderID GetNumManualOrders() const { return this->num_manual_orders; }
StationIDStack GetNextStoppingStation(const Vehicle *v, const Order *first = NULL) const; StationIDStack GetNextStoppingStation(const Vehicle *v, const Order *first = NULL, uint hops = 0) const;
const Order *GetNextDecisionNode(const Order *next, uint hops) const; const Order *GetNextDecisionNode(const Order *next, uint hops) const;
void InsertOrderAt(Order *new_order, int index); void InsertOrderAt(Order *new_order, int index);

View File

@ -391,11 +391,12 @@ const Order *OrderList::GetNextDecisionNode(const Order *next, uint hops) const
* Recursively determine the next deterministic station to stop at. * Recursively determine the next deterministic station to stop at.
* @param v The vehicle we're looking at. * @param v The vehicle we're looking at.
* @param first Order to start searching at or NULL to start at cur_implicit_order_index + 1. * @param first Order to start searching at or NULL to start at cur_implicit_order_index + 1.
* @param hops Number of orders we have already looked at.
* @return Next stoppping station or INVALID_STATION. * @return Next stoppping station or INVALID_STATION.
* @pre The vehicle is currently loading and v->last_station_visited is meaningful. * @pre The vehicle is currently loading and v->last_station_visited is meaningful.
* @note This function may draw a random number. Don't use it from the GUI. * @note This function may draw a random number. Don't use it from the GUI.
*/ */
StationIDStack OrderList::GetNextStoppingStation(const Vehicle *v, const Order *first) const StationIDStack OrderList::GetNextStoppingStation(const Vehicle *v, const Order *first, uint hops) const
{ {
const Order *next = first; const Order *next = first;
@ -413,42 +414,27 @@ StationIDStack OrderList::GetNextStoppingStation(const Vehicle *v, const Order *
} }
} }
uint hops = 0;
do { do {
next = this->GetNextDecisionNode(next, ++hops); next = this->GetNextDecisionNode(next, ++hops);
/* Resolve possibly nested conditionals by estimation. */ /* Resolve possibly nested conditionals by estimation. */
while (next != NULL && next->IsType(OT_CONDITIONAL)) { while (next != NULL && next->IsType(OT_CONDITIONAL)) {
++hops; /* We return both options of conditional orders. */
if (next->GetConditionVariable() == OCV_LOAD_PERCENTAGE) { const Order *skip_to = this->GetNextDecisionNode(
/* If the condition is based on load percentage we can't this->GetOrderAt(next->GetConditionSkipToOrder()), hops);
* tell what it will do. So we choose randomly. */ const Order *advance = this->GetNextDecisionNode(
const Order *skip_to = this->GetNextDecisionNode( this->GetNext(next), hops);
this->GetOrderAt(next->GetConditionSkipToOrder()), if (advance == NULL || advance == first || skip_to == advance) {
hops); next = (skip_to == first) ? NULL : skip_to;
const Order *advance = this->GetNextDecisionNode( } else if (skip_to == NULL || skip_to == first) {
this->GetNext(next), hops); next = (advance == first) ? NULL : advance;
if (advance == NULL || advance == first) {
next = (skip_to == first) ? NULL : skip_to;
} else if (skip_to == NULL || skip_to == first) {
next = (advance == first) ? NULL : advance;
} else {
StationIDStack st1 = this->GetNextStoppingStation(v, skip_to);
StationIDStack st2 = this->GetNextStoppingStation(v, advance);
while (!st2.IsEmpty()) st1.Push(st2.Pop());
return st1;
}
} else { } else {
/* Otherwise we're optimistic and expect that the StationIDStack st1 = this->GetNextStoppingStation(v, skip_to, hops);
* condition value won't change until it's evaluated. */ StationIDStack st2 = this->GetNextStoppingStation(v, advance, hops);
VehicleOrderID skip_to = ProcessConditionalOrder(next, v); while (!st2.IsEmpty()) st1.Push(st2.Pop());
if (skip_to != INVALID_VEH_ORDER_ID) { return st1;
next = this->GetNextDecisionNode(this->GetOrderAt(skip_to),
hops);
} else {
next = this->GetNextDecisionNode(this->GetNext(next), hops);
}
} }
++hops;
} }
/* Don't return a next stop if the vehicle has to unload everything. */ /* Don't return a next stop if the vehicle has to unload everything. */