当前位置: 首页>>代码示例>>C++>>正文


C++ Link::addTraffic方法代码示例

本文整理汇总了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);
}
开发者ID:migrax,项目名称:trancas,代码行数:31,代码来源:Network.cpp

示例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);
}
开发者ID:migrax,项目名称:trancas,代码行数:22,代码来源:Network.cpp

示例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;
}
开发者ID:migrax,项目名称:trancas,代码行数:22,代码来源:Network.cpp


注:本文中的Link::addTraffic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。