Data Structures | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes

LinkRefresher Class Reference

Utility to refresh links a consist will visit. More...

#include <refresh.h>

Data Structures

struct  Hop
 A hop the refresh algorithm might evaluate. More...
struct  RefitDesc
 Simulated cargo type and capacity for prediction of future links. More...

Static Public Member Functions

static void Run (Vehicle *v, bool allow_merge=true)
 Refresh all links the given vehicle will visit.

Protected Types

enum  RefreshFlags { USE_NEXT, HAS_CARGO, WAS_REFIT, RESET_REFIT }
 

Various flags about properties of the last examined link that might have an influence on the next one.

More...
typedef std::list< RefitDescRefitList
typedef std::map< CargoID, uint > CapacitiesMap
typedef std::set< HopHopSet

Protected Member Functions

 LinkRefresher (Vehicle *v, HopSet *seen_hops, bool allow_merge)
 Constructor for link refreshing algorithm.
void HandleRefit (const Order *next)
 Handle refit orders by updating capacities and refit_capacities.
void ResetRefit ()
 Restore capacities and refit_capacities as vehicle might have been able to load now.
void RefreshStats (const Order *cur, const Order *next)
 Refresh link stats for the given pair of orders.
const OrderPredictNextOrder (const Order *cur, const Order *next, uint8 flags, uint num_hops=0)
 Predict the next order the vehicle will execute and resolve conditionals by recursion and return next non-conditional order in list.
void RefreshLinks (const Order *cur, const Order *next, uint8 flags, uint num_hops=0)
 Iterate over orders starting at cur and next and refresh links associated with them.

Protected Attributes

Vehiclevehicle
 Vehicle for which the links should be refreshed.
CapacitiesMap capacities
 Current added capacities per cargo ID 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.
CargoID cargo
 Cargo given in last refit order.
bool allow_merge
 If the refresher is allowed to merge or extend link graphs.

Detailed Description

Utility to refresh links a consist will visit.

Definition at line 24 of file refresh.h.


Member Enumeration Documentation

enum LinkRefresher::RefreshFlags [protected]

Various flags about properties of the last examined link that might have an influence on the next one.

Enumerator:
USE_NEXT 

There was a conditional jump. Try to use the given next order when looking for a new one.

HAS_CARGO 

Consist could leave the last stop where it could interact with cargo carrying cargo (i.e. not an "unload all" + "no loading" order).

WAS_REFIT 

Consist was refit since the last stop where it could interact with cargo.

RESET_REFIT 

Consist had a chance to load since the last refit and the refit capacities can be reset.

Definition at line 33 of file refresh.h.


Constructor & Destructor Documentation

LinkRefresher::LinkRefresher ( Vehicle vehicle,
HopSet *  seen_hops,
bool  allow_merge 
) [protected]

Constructor for link refreshing algorithm.

Parameters:
vehicle Vehicle to refresh links for.
seen_hops Set of hops already seen. This is shared between this refresher and all its children.
allow_merge If the refresher is allowed to merge or extend link graphs.

Definition at line 67 of file refresh.cpp.

References capacities, Vehicle::Next(), and refit_capacities.


Member Function Documentation

void LinkRefresher::HandleRefit ( const Order next  )  [protected]
const Order * LinkRefresher::PredictNextOrder ( const Order cur,
const Order next,
uint8  flags,
uint  num_hops = 0 
) [protected]

Predict the next order the vehicle will execute and resolve conditionals by recursion and return next non-conditional order in list.

Parameters:
cur Current order being evaluated.
next Next order to be evaluated.
flags RefreshFlags to give hints about the previous link and state carried over from that.
num_hops Number of hops already taken by recursive calls to this method.
Returns:
new next Order.

Definition at line 151 of file refresh.cpp.

References Order::GetConditionSkipToOrder(), OrderList::GetNext(), OrderList::GetNextDecisionNode(), OrderList::GetNumOrders(), OrderList::GetOrderAt(), HasBit(), Order::IsType(), Vehicle::list, Vehicle::orders, RefreshLinks(), SetBit(), USE_NEXT, and vehicle.

Referenced by RefreshLinks().

void LinkRefresher::RefreshLinks ( const Order cur,
const Order next,
uint8  flags,
uint  num_hops = 0 
) [protected]

Iterate over orders starting at cur and next and refresh links associated with them.

cur and next can be equal. If they're not they must be "neigbours" in their order list, which means next must be directly reachable from cur without passing any further OT_GOTO_STATION or OT_IMPLICIT orders in between.

Parameters:
cur Current order being evaluated.
next Next order to be checked.
flags RefreshFlags to give hints about the previous link and state carried over from that.
num_hops Number of hops already taken by recursive calls to this method.

Definition at line 225 of file refresh.cpp.

References Order::CanLeaveWithCargo(), ClrBit(), HandleRefit(), HAS_CARGO, HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Order::IsAutoRefit(), Order::IsRefit(), Order::IsType(), PredictNextOrder(), RefreshStats(), RESET_REFIT, ResetRefit(), seen_hops, SetBit(), USE_NEXT, and WAS_REFIT.

Referenced by PredictNextOrder(), and Run().

void LinkRefresher::RefreshStats ( const Order cur,
const Order next 
) [protected]
void LinkRefresher::Run ( Vehicle v,
bool  allow_merge = true 
) [static]

Refresh all links the given vehicle will visit.

Parameters:
v Vehicle to refresh links for.
allow_merge If the refresher is allowed to merge or extend link graphs.

Definition at line 25 of file refresh.cpp.

References BaseConsist::cur_implicit_order_index, OrderList::GetNextDecisionNode(), Vehicle::GetOrder(), HAS_CARGO, Vehicle::last_loading_station, Vehicle::list, Vehicle::orders, RefreshLinks(), and seen_hops.

Referenced by DeleteStaleLinks(), Vehicle::LeaveStation(), and LoadUnloadVehicle().


The documentation for this class was generated from the following files: