(svn r26166) -Fix: Scale flows only after mapping to avoid rounding errors.

This commit is contained in:
fonsinchen
2013-12-20 14:57:44 +00:00
parent 4818b72c75
commit ec492bfb77
5 changed files with 42 additions and 8 deletions

View File

@@ -4289,6 +4289,22 @@ void FlowStat::ReleaseShare(StationID st)
assert(!this->shares.empty());
}
/**
* Scale all shares from link graph's runtime to monthly values.
* @param runtime Time the link graph has been running without compression.
*/
void FlowStat::ScaleToMonthly(uint runtime)
{
SharesMap new_shares;
uint share = 0;
for (SharesMap::iterator i = this->shares.begin(); i != this->shares.end(); ++i) {
share = max(share + 1, i->first * 30 / runtime);
new_shares[share] = i->second;
if (this->unrestricted == i->first) this->unrestricted = share;
}
this->shares.swap(new_shares);
}
/**
* Add some flow from "origin", going via "via".
* @param origin Origin of the flow.