本文整理汇总了C++中Link::addTraffic方法的典型用法代码示例。如果您正苦于以下问题:C++ Link::addTraffic方法的具体用法?C++ Link::addTraffic怎么用?C++ Link::addTraffic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Link
的用法示例。
在下文中一共展示了Link::addTraffic方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateRoute
Network::RouteInfo Network::updateRoute(Route& newRoute) throw(NetworkException) {
std::pair<const Node&, const Node&> np(newRoute.front(), newRoute.back());
auto ori = routes.find(np);
assert(ori != routes.end());
Route& oldRoute = ori->second.first;
const double traffic = ori->second.second;
// Remove the traffic from the old route
for (auto i = oldRoute.begin(); i < oldRoute.end() - 1; i++) {
Link l = getLink(make_pair(*i, *(i + 1)));
l.removeTraffic(traffic);
i->removeTraffic(*(i + 1), traffic);
}
// Add it to the new route
double cost = 0.0;
for (auto i = newRoute.begin(); i < newRoute.end() - 1; i++) {
Link l = getLink(make_pair(*i, *(i + 1)));
l.addTraffic(traffic);
i->addTraffic(*(i + 1), traffic);
cost += l.getCurrentCost(traffic);
}
ori->second = RouteInfo(newRoute, traffic);
return RouteInfo(newRoute, cost);
}
示例2: addTraffic
Network::RouteInfo Network::addTraffic(Node orig, const Node& dst, double traffic, RouteMode mode) throw (TrancasException) {
/* Algorithm:
* a) Calculate route (link collection)
* b) Update info at orig node
* c) Update link traffic
* d) Update Nodes neighbour traffic
*/
Dijkstra spf(orig, dst, *this, traffic, mode==SPF ? Dijkstra::Constant : Dijkstra::Real);
Route r = spf.getRoute();
double cost = 0.0;
for (auto i = r.begin(); i < r.end() - 1; i++) {
Link l = getLink(make_pair(*i, *(i + 1)));
cost += l.getCost(traffic);
l.addTraffic(traffic);
i->addTraffic(*(i + 1), traffic);
}
addNewRoute(r, traffic);
return RouteInfo(move(r), cost);
}
示例3: changeTrafficInRoute
Network::RouteInfo Network::changeTrafficInRoute(const Node& orig, const Node& dst, double traffic) throw (NetworkException) {
auto ci = routes.find(make_pair(orig, dst));
if (ci == routes.end())
return addTraffic(orig, dst, traffic);
Route& route = ci->second.first;
double& curTraffic = ci->second.second;
if (curTraffic + traffic < 0.0) {
throw NetworkException("Routes must have positive values from total traffic");
}
for (auto i = route.begin(); i < route.end() - 1; i++) {
Link l = getLink(make_pair(*i, *(i + 1)));
l.addTraffic(traffic);
i->addTraffic(*(i + 1), traffic);
}
curTraffic += traffic;
return ci->second;
}