Hi,
I am trying to write use BGL.dijkstra to calculate a shortest path in a time dependent network where edge.cost C(u, v) is a function of distance@edge.source and a variable wait time dependent on Edge.departure i.e.
Cost(Edge(u,v), D(u)) = Wait(Edge(u, v).departure, D(u)) + Edge(u, v).delay
The cost function ( and edge property is defined as):
struct Eonnection {
Eonnection(const Vertex source, const Vertex destination, const double departure, const double duration, const double cost) {
this->source = source;
this->destination = destination;
this->departure = departure;
this->duration = duration;
this->cost = cost;
};
Vertex source;
Vertex destination;
double departure; // Time of departure
double duration; // Duration of traversing edge
double cost; // Actual cost of traversing Edge
std::pair<double, double> dyn_cost(std::vector<std::pair<double, double> > distances, double t_max) {
std::pair<double, double> d_parent = distances[this->source];
double t_parent = d_parent.first;
double c_parent = d_parent.second;
double t_time_of_day = fmod(t_parent, 24 * 3600);
double t_delay = t_time_of_day <= this->departure ? this->departure - t_time_of_day: this->departure + (24 * 3600 - t_time_of_day);
double t_total = t_parent + t_delay + this->duration;
if(t_total < t_max) {
std::cout << "Edge usable with cost " << c_parent + this->cost << ", " << t_total << std::endl;
return std::pair<double, double>(c_parent + this->cost, t_total);
} else {
std::cout << "Edge unusable" << std::endl;
return std::pair<double, double>(std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity());
}
};
};
I'm trying to call dijkstra as
dijkstra_shortest_paths_no_color_map(
g, source,
boost::make_iterator_property_map(pred.begin(), get(boost::vertex_index, g)),
boost::make_iterator_property_map(distances.begin(), get(boost::vertex_index, g)),
boost::make_transform_value_property_map(
boost::bind<std::pair<double, double> >(&Eonnection::dyn_cost, _1, _2, distances, 24 * 3600 * 3),
get(boost::edge_bundle, g)
),
get(vertex_index, g), smaller, combiner,
std::pair<double, double>(std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()),
std::pair<double, double>(0, 0), vis
);
However, this does not seem to work. How can I pass the weights as a dynamic function to dijkstra_shortest_paths?