Flow statistics telling how much flow should be sent along a link. More...
#include <station_base.h>
Public Types | |
typedef std::map< uint32, StationID > | SharesMap |
Public Member Functions | |
FlowStat (StationID st, uint flow) | |
void | AppendShare (StationID st, uint flow) |
Add some flow to the end of the shares map. | |
uint | GetShare (StationID st) const |
Get flow for a station. | |
void | ChangeShare (StationID st, int flow) |
Change share for specified station. | |
const SharesMap * | GetShares () const |
StationID | GetVia () const |
Get a station a package can be routed to. | |
StationID | GetVia (StationID excluded, StationID excluded2=INVALID_STATION) const |
Get a station a package can be routed to, but exclude the given one. | |
void | Cleanup (NodeID self, LinkGraphID link_graph) |
Remove flows for which there are no edges anymore. | |
Private Attributes | |
SharesMap | shares |
Shares of flow to be sent via specified station (or consumed locally). |
Flow statistics telling how much flow should be sent along a link.
This is done by creating "flow shares" and using std::map's upper_bound() method to look them up with a random number. A flow share is the difference between a key in a map and the previous key. So one key in the map doesn't actually mean anything by itself.
Definition at line 36 of file station_base.h.
void FlowStat::AppendShare | ( | StationID | st, | |
uint | flow | |||
) | [inline] |
Add some flow to the end of the shares map.
Only do that if you know that the station isn't in the map yet. Anything else may lead to inconsistencies.
st | Remote station. | |
flow | Amount of flow to be added. |
Definition at line 55 of file station_base.h.
References shares.
Referenced by FlowStatMap::PassOnFlow().
void FlowStat::ChangeShare | ( | StationID | st, | |
int | flow | |||
) |
Change share for specified station.
By specifing INT_MIN as parameter you can erase a share.
st | Next Hop to be removed. | |
flow | Share to be added or removed. |
Definition at line 4098 of file station_cmd.cpp.
References shares.
Referenced by FlowStatMap::DeleteFlows(), and FlowStatMap::FinalizeLocalConsumption().
void FlowStat::Cleanup | ( | NodeID | self, | |
LinkGraphID | link_graph | |||
) |
Remove flows for which there are no edges anymore.
self | Own node ID in link graph. | |
link_graph | Link graph to be checked against. |
Definition at line 4133 of file station_cmd.cpp.
References LinkGraph::Cargo(), SpecializedStation< Station, false >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_link_graph_pool >::Get(), Station::goods, INVALID_DATE, GoodsEntry::link_graph, GoodsEntry::node, and shares.
uint FlowStat::GetShare | ( | StationID | st | ) | const |
Get flow for a station.
st | Station to get flow for. |
Definition at line 4025 of file station_cmd.cpp.
References shares.
Referenced by FlowStatMap::FinalizeLocalConsumption().
StationID FlowStat::GetVia | ( | StationID | excluded, | |
StationID | excluded2 = INVALID_STATION | |||
) | const |
Get a station a package can be routed to, but exclude the given one.
excluded | StationID not to be selected. |
Definition at line 4043 of file station_cmd.cpp.
StationID FlowStat::GetVia | ( | ) | const [inline] |
Get a station a package can be routed to.
This done by drawing a random number between 0 and sum_shares and then looking that up in the map with lower_bound. So each share gets selected with a probability dependent on its flow.
Definition at line 74 of file station_base.h.
References shares.