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); }
void Network::addNewRoute(const Route& r, double traffic) throw (TrancasException) { const Node& orig = r.front(); const Node& dst = r.back(); pair<string, string> np(orig, dst); auto ci = routes.find(np); if (ci != routes.end()) { throw RouteException("There is already a route from " + orig.getName() + " to " + dst.getName()); } routes[np] = make_pair(r, traffic); // Tell nodes to adjust neighbour probabilities for (Node n : r) { if (n != r.getDst()) n.cleanRoute(make_pair(getNode(orig), getNode(dst))); } }
void plot_shared_points(const Route& r, const char* filename) { std::ofstream os(filename); SvgWriter svg(r, os); if(r.empty()) return; std::vector<Point> sharedPoints; find_shared_points(r, sharedPoints); for(const Path& path : r) { svg.write(path, "stroke:rgb(0,0,0);stroke-width:10;"); } for(const Point& p : sharedPoints) { svg.write(p, "stroke:rgb(255,0,0);stroke-width:10;fill:none"); } svg.write(r.front().front(), "stroke:rgb(0,255,0);stroke-width:40;"); svg.write(r.back().back(), "stroke:rgb(0,0,255);stroke-width:40;"); }