2 #ifndef ANDRES_GRAPH_SHORTEST_PATHS_HXX
3 #define ANDRES_GRAPH_SHORTEST_PATHS_HXX
12 #include "subgraph.hxx"
13 #include "edge-value.hxx"
24 std::deque<std::size_t>&,
25 std::vector<std::ptrdiff_t>&
34 std::deque<std::size_t>&
37 template<
class GRAPH,
class SUBGRAPH_MASK>
44 std::deque<std::size_t>&
47 template<
class GRAPH,
class SUBGRAPH_MASK>
54 std::deque<std::size_t>&,
55 std::vector<std::ptrdiff_t>&
60 class EDGE_VALUE_ITERATOR,
69 std::deque<std::size_t>&,
76 class EDGE_VALUE_ITERATOR,
86 std::deque<std::size_t>&,
90 template<
class GRAPH,
class DISTANCE_ITERATOR>
98 template<
class GRAPH,
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
107 template<
class GRAPH,
class SUBGRAPH_MASK,
class DISTANCE_ITERATOR>
111 const SUBGRAPH_MASK&,
116 template<
class GRAPH,
class SUBGRAPH_MASK,
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
120 const SUBGRAPH_MASK&,
126 template<
class GRAPH,
class EDGE_VALUE_ITERATOR,
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
131 const EDGE_VALUE_ITERATOR,
139 class EDGE_VALUE_ITERATOR,
140 class DISTANCE_ITERATOR,
141 class PARENT_ITERATOR
146 const SUBGRAPH_MASK&,
148 const EDGE_VALUE_ITERATOR,
156 class EDGE_VALUE_ITERATOR,
157 class DISTANCE_ITERATOR,
158 class PARENT_ITERATOR,
164 const SUBGRAPH_MASK&,
166 const EDGE_VALUE_ITERATOR,
175 class EDGE_VALUE_ITERATOR,
177 class DISTANCE_ITERATOR,
178 class PARENT_ITERATOR
183 const SUBGRAPH_MASK&,
187 std::deque<std::size_t>&,
193 template<
class GRAPH>
199 std::deque<std::size_t>&,
200 std::vector<std::ptrdiff_t>&
203 template<
class GRAPH>
209 std::deque<std::size_t>&
212 template<
class GRAPH,
class SUBGRAPH_MASK>
216 const SUBGRAPH_MASK&,
219 std::deque<std::size_t>&
222 template<
class GRAPH,
class SUBGRAPH_MASK>
226 const SUBGRAPH_MASK&,
229 std::deque<std::size_t>&,
230 std::vector<std::ptrdiff_t>&
236 class EDGE_VALUE_ITERATOR,
245 std::deque<std::size_t>&,
252 class EDGE_VALUE_ITERATOR,
258 const SUBGRAPH_MASK&,
262 std::deque<std::size_t>&,
266 template<
class GRAPH,
class DISTANCE_ITERATOR>
274 template<
class GRAPH,
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
283 template<
class GRAPH,
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
293 template<
class GRAPH,
class SUBGRAPH_MASK,
class DISTANCE_ITERATOR>
297 const SUBGRAPH_MASK&,
302 template<
class GRAPH,
class SUBGRAPH_MASK,
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
306 const SUBGRAPH_MASK&,
312 template<
class GRAPH,
class SUBGRAPH_MASK,
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
316 const SUBGRAPH_MASK&,
323 template<
class GRAPH,
class EDGE_VALUE_ITERATOR,
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
328 const EDGE_VALUE_ITERATOR,
333 template<
class GRAPH,
class EDGE_VALUE_ITERATOR,
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
338 const EDGE_VALUE_ITERATOR,
347 class EDGE_VALUE_ITERATOR,
348 class DISTANCE_ITERATOR,
349 class PARENT_ITERATOR
354 const SUBGRAPH_MASK&,
356 const EDGE_VALUE_ITERATOR,
364 class EDGE_VALUE_ITERATOR,
365 class DISTANCE_ITERATOR,
366 class PARENT_ITERATOR
371 const SUBGRAPH_MASK&,
373 const EDGE_VALUE_ITERATOR,
382 class EDGE_VALUE_ITERATOR,
383 class DISTANCE_ITERATOR,
384 class PARENT_ITERATOR,
390 const SUBGRAPH_MASK&,
392 const EDGE_VALUE_ITERATOR,
401 class EDGE_VALUE_ITERATOR,
403 class DISTANCE_ITERATOR,
404 class PARENT_ITERATOR
409 const SUBGRAPH_MASK&,
413 std::deque<std::size_t>&,
420 namespace graph_detail {
425 const std::vector<std::ptrdiff_t>& parents,
430 assert(vPositive >= 0);
431 assert(vNegative >= 0);
435 if(parents[t] - 1 == t) {
445 if(-parents[t] - 1 == t) {
455 struct DijkstraQueueEntry {
458 DijkstraQueueEntry(
const std::size_t vertex = 0,
const Value distance = Value())
459 : vertex_(vertex), distance_(distance)
461 bool operator<(const DijkstraQueueEntry<Value>& other)
const
462 {
return distance_ > other.distance_; }
463 bool operator==(
const DijkstraQueueEntry<Value>& other)
const
464 {
return vertex_ == other.vertex_ && distance_ == other.distance_; }
465 bool operator!=(
const DijkstraQueueEntry<Value>& other)
const
466 {
return vertex_ != other.vertex_ || distance_ != other.distance_; }
473 template<
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
474 class DijkstraSPSPVisitor {
476 typedef DISTANCE_ITERATOR Distances;
477 typedef PARENT_ITERATOR Parents;
478 typedef typename std::iterator_traits<DISTANCE_ITERATOR>::value_type Value;
481 const std::size_t vs,
482 const std::size_t vt,
483 std::deque<std::size_t>& path
485 : vs_(vs), vt_(vt), path_(path)
496 const Value infinity = std::numeric_limits<Value>::has_infinity
497 ? std::numeric_limits<Value>::infinity()
498 : std::numeric_limits<Value>::max();
499 if(distances[vertex] == infinity) {
504 path_.push_front(vertex);
509 vertex = parents[vertex];
521 Parents parentsEdges,
525 const Value infinity = std::numeric_limits<Value>::has_infinity
526 ? std::numeric_limits<Value>::infinity()
527 : std::numeric_limits<Value>::max();
528 if(distances[vertex] == infinity) {
537 path_.push_front(parentsEdges[vertex]);
538 vertex = parents[vertex];
549 std::deque<std::size_t>& path_;
569 template<
class GRAPH>
573 const std::size_t vs,
574 const std::size_t vt,
575 std::deque<std::size_t>& path,
576 std::vector<std::ptrdiff_t>& parents
581 template<
class GRAPH>
585 const std::size_t vs,
586 const std::size_t vt,
587 std::deque<std::size_t>& path
589 std::vector<std::ptrdiff_t> parents = std::vector<std::ptrdiff_t>();
607 template<
class GRAPH,
class SUBGRAPH_MASK>
611 const SUBGRAPH_MASK& mask,
612 const std::size_t vs,
613 const std::size_t vt,
614 std::deque<std::size_t>& path
617 std::vector<std::ptrdiff_t> parents = std::vector<std::ptrdiff_t>();
618 return spsp(g, mask, vs, vt, path, parents);
637 template<
class GRAPH,
class SUBGRAPH_MASK>
641 const SUBGRAPH_MASK& mask,
642 const std::size_t vs,
643 const std::size_t vt,
644 std::deque<std::size_t>& path,
645 std::vector<std::ptrdiff_t>& parents
648 if(!mask.vertex(vs) || !mask.vertex(vt)) {
655 parents.resize(g.numberOfVertices());
656 std::fill(parents.begin(), parents.end(), 0);
657 parents[vs] = vs + 1;
658 parents[vt] = -
static_cast<std::ptrdiff_t
>(vt) - 1;
659 std::queue<std::size_t> queues[2];
662 for(std::size_t q = 0;
true; q = 1 - q) {
663 const std::size_t numberOfNodesAtFront = queues[q].size();
664 for(std::size_t n = 0; n < numberOfNodesAtFront; ++n) {
665 const std::size_t v = queues[q].front();
667 typename GRAPH::AdjacencyIterator it;
668 typename GRAPH::AdjacencyIterator end;
670 it = g.adjacenciesFromVertexBegin(v);
671 end = g.adjacenciesFromVertexEnd(v);
674 it = g.adjacenciesToVertexBegin(v);
675 end = g.adjacenciesToVertexEnd(v);
677 for(; it != end; ++it) {
678 if(!mask.edge(it->edge()) || !mask.vertex(it->vertex())) {
681 if(parents[it->vertex()] < 0 && q == 0) {
682 graph_detail::spspHelper(parents, v, it->vertex(), path);
683 assert(path[0] == vs);
684 assert(path.back() == vt);
687 else if(parents[it->vertex()] > 0 && q == 1) {
688 graph_detail::spspHelper(parents, it->vertex(), v, path);
689 assert(path[0] == vs);
690 assert(path.back() == vt);
693 else if(parents[it->vertex()] == 0) {
695 parents[it->vertex()] = v + 1;
698 parents[it->vertex()] = -
static_cast<std::ptrdiff_t
>(v) - 1;
700 queues[q].push(it->vertex());
704 if(queues[0].empty() && queues[1].empty()) {
723 class EDGE_VALUE_ITERATOR,
729 const std::size_t vs,
730 const std::size_t vt,
731 EDGE_VALUE_ITERATOR edgeWeights,
732 std::deque<std::size_t>& path,
735 std::vector<T> distances(g.numberOfVertices());
736 std::vector<std::size_t> parents(g.numberOfVertices());
738 distances.begin(), parents.begin()
757 class EDGE_VALUE_ITERATOR,
763 const SUBGRAPH_MASK& mask,
764 const std::size_t vs,
765 const std::size_t vt,
766 EDGE_VALUE_ITERATOR edgeWeights,
767 std::deque<std::size_t>& path,
770 std::vector<T> distances(g.numberOfVertices());
771 std::vector<std::size_t> parents(g.numberOfVertices());
772 spsp(g, mask, vs, vt, edgeWeights, path, distance,
773 distances.begin(), parents.begin()
783 template<
class GRAPH,
class DISTANCE_ITERATOR>
787 const std::size_t vs,
788 DISTANCE_ITERATOR distances
790 std::vector<std::size_t> parents(g.numberOfVertices());
791 sssp(g, vs, distances, parents.begin());
801 template<
class GRAPH,
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
805 const std::size_t vs,
806 DISTANCE_ITERATOR distances,
807 PARENT_ITERATOR parents
809 typedef typename std::iterator_traits<DISTANCE_ITERATOR>::value_type Value;
822 template<
class GRAPH,
class SUBGRAPH_MASK,
class DISTANCE_ITERATOR>
826 const SUBGRAPH_MASK& mask,
827 const std::size_t vs,
828 DISTANCE_ITERATOR distances
830 std::vector<std::size_t> parents(g.numberOfVertices());
831 sssp(g, mask, vs, distances, parents.begin());
842 template<
class GRAPH,
class SUBGRAPH_MASK,
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
846 const SUBGRAPH_MASK& mask,
847 const std::size_t vs,
848 DISTANCE_ITERATOR distances,
849 PARENT_ITERATOR parents
851 typedef typename std::iterator_traits<DISTANCE_ITERATOR>::value_type Value;
863 template<
class GRAPH,
class EDGE_VALUE_ITERATOR,
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
867 const std::size_t vs,
868 const EDGE_VALUE_ITERATOR edgeWeights,
869 DISTANCE_ITERATOR distances,
870 PARENT_ITERATOR parents
877 template<
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
900 class EDGE_VALUE_ITERATOR,
901 class DISTANCE_ITERATOR,
902 class PARENT_ITERATOR
907 const SUBGRAPH_MASK& mask,
908 const std::size_t vs,
909 const EDGE_VALUE_ITERATOR edgeWeights,
910 DISTANCE_ITERATOR distances,
911 PARENT_ITERATOR parents
915 sssp<GRAPH, SUBGRAPH_MASK, EDGE_VALUE_ITERATOR, DISTANCE_ITERATOR, PARENT_ITERATOR, Visitor>(
916 g, mask, vs, edgeWeights, distances, parents, visitor
933 class EDGE_VALUE_ITERATOR,
934 class DISTANCE_ITERATOR,
935 class PARENT_ITERATOR,
941 const SUBGRAPH_MASK& mask,
942 const std::size_t vs,
943 const EDGE_VALUE_ITERATOR edgeWeights,
944 DISTANCE_ITERATOR distances,
945 PARENT_ITERATOR parents,
948 typedef typename std::iterator_traits<DISTANCE_ITERATOR>::value_type Value;
949 typedef typename graph_detail::DijkstraQueueEntry<Value> Entry;
951 assert(mask.vertex(vs));
952 const Value infinity = std::numeric_limits<Value>::has_infinity
953 ? std::numeric_limits<Value>::infinity()
954 : std::numeric_limits<Value>::max();
955 std::priority_queue<Entry> queue;
957 for(std::size_t v = 0; v < g.numberOfVertices(); ++v) {
958 distances[v] = infinity;
960 queue.push(Entry(v, infinity));
964 while(!queue.empty()) {
965 const std::size_t v = queue.top().vertex_;
966 const bool proceed = visitor(distances, parents, v);
971 if(distances[v] == infinity) {
974 for(
typename GRAPH::AdjacencyIterator it = g.adjacenciesFromVertexBegin(v);
975 it != g.adjacenciesFromVertexEnd(v); ++it) {
976 if(mask.vertex(it->vertex()) && mask.edge(it->edge())) {
977 const Value alternativeDistance = distances[v] + edgeWeights[it->edge()];
978 if(alternativeDistance < distances[it->vertex()]) {
979 distances[it->vertex()] = alternativeDistance;
980 parents[it->vertex()] = v;
981 queue.push(Entry(it->vertex(), alternativeDistance));
1009 class SUBGRAPH_MASK,
1010 class EDGE_VALUE_ITERATOR,
1012 class DISTANCE_ITERATOR,
1013 class PARENT_ITERATOR
1018 const SUBGRAPH_MASK& mask,
1019 const std::size_t vs,
1020 const std::size_t vt,
1021 EDGE_VALUE_ITERATOR edgeWeights,
1022 std::deque<std::size_t>& path,
1024 DISTANCE_ITERATOR distances,
1025 PARENT_ITERATOR parents
1027 typedef graph_detail::DijkstraSPSPVisitor<DISTANCE_ITERATOR, PARENT_ITERATOR> Visitor;
1028 Visitor visitor(vs, vt, path);
1029 sssp<GRAPH, SUBGRAPH_MASK, EDGE_VALUE_ITERATOR, DISTANCE_ITERATOR, PARENT_ITERATOR, Visitor>(
1030 g, mask, vs, edgeWeights, distances, parents, visitor
1032 distance = distances[vt];
1051 template<
class GRAPH>
1055 const std::size_t vs,
1056 const std::size_t vt,
1057 std::deque<std::size_t>& path,
1058 std::vector<std::ptrdiff_t>& parents
1063 template<
class GRAPH>
1067 const std::size_t vs,
1068 const std::size_t vt,
1069 std::deque<std::size_t>& path
1071 std::vector<std::ptrdiff_t> parents = std::vector<std::ptrdiff_t>();
1089 template<
class GRAPH,
class SUBGRAPH_MASK>
1093 const SUBGRAPH_MASK& mask,
1094 const std::size_t vs,
1095 const std::size_t vt,
1096 std::deque<std::size_t>& path
1098 std::vector<std::ptrdiff_t> parents = std::vector<std::ptrdiff_t>();
1099 return spspEdges(g, mask, vs, vt, path, parents);
1117 template<
class GRAPH,
class SUBGRAPH_MASK>
1121 const SUBGRAPH_MASK& mask,
1122 const std::size_t vs,
1123 const std::size_t vt,
1124 std::deque<std::size_t>& path,
1125 std::vector<std::ptrdiff_t>& parents
1128 if(!mask.vertex(vs) || !mask.vertex(vt)) {
1134 for (
typename GRAPH::AdjacencyIterator i = g.adjacenciesFromVertexBegin(vs); i < g.adjacenciesFromVertexEnd(vs) ; ++i) {
1135 if (i->vertex() == vt && mask.edge(i->edge())) {
1136 path.push_front(i->edge());
1140 parents.resize(g.numberOfEdges());
1141 std::fill(parents.begin(), parents.end(), 0);
1142 std::queue<std::size_t> queues[2];
1143 for (
typename GRAPH::AdjacencyIterator i = g.adjacenciesFromVertexBegin(vs); i < g.adjacenciesFromVertexEnd(vs) ; ++i) {
1144 if (mask.edge(i->edge()) && mask.vertex(i->vertex())) {
1145 queues[0].push(i->edge());
1146 parents[i->edge()] = i->edge() + 1;
1149 for (
typename GRAPH::AdjacencyIterator i = g.adjacenciesToVertexBegin(vt); i < g.adjacenciesToVertexEnd(vt) ; ++i) {
1150 if (mask.edge(i->edge()) && mask.vertex(i->vertex())) {
1151 queues[1].push(i->edge());
1152 parents[i->edge()] = -
static_cast<std::ptrdiff_t
>(i->edge()) - 1;
1155 for(std::size_t q = 0;
true; q = 1 - q) {
1156 const std::size_t numberOfEdgesAtFront = queues[q].size();
1157 for(std::size_t n = 0; n < numberOfEdgesAtFront; ++n) {
1158 const std::size_t e = queues[q].front();
1160 typename GRAPH::AdjacencyIterator it;
1161 typename GRAPH::AdjacencyIterator end;
1163 it = g.adjacenciesFromVertexBegin(g.vertexOfEdge(e, 1));
1164 end = g.adjacenciesFromVertexEnd(g.vertexOfEdge(e, 1));
1167 it = g.adjacenciesToVertexBegin(g.vertexOfEdge(e, 0));
1168 end = g.adjacenciesToVertexEnd(g.vertexOfEdge(e, 0));
1170 for(; it != end; ++it) {
1171 if(!mask.edge(it->edge()) || !mask.vertex(it->vertex())) {
1174 if(parents[it->edge()] < 0 && q == 0) {
1175 graph_detail::spspHelper(parents, e, it->edge(), path);
1178 else if(parents[it->edge()] > 0 && q == 1) {
1179 graph_detail::spspHelper(parents, it->edge(), e, path);
1182 else if(parents[it->edge()] == 0) {
1184 parents[it->edge()] = e + 1;
1187 parents[it->edge()] = -
static_cast<std::ptrdiff_t
>(e) - 1;
1189 queues[q].push(it->edge());
1193 if(queues[0].empty() && queues[1].empty()) {
1212 class EDGE_VALUE_ITERATOR,
1218 const std::size_t vs,
1219 const std::size_t vt,
1220 EDGE_VALUE_ITERATOR edgeWeights,
1221 std::deque<std::size_t>& path,
1224 std::vector<T> distances(g.numberOfVertices());
1225 std::vector<std::size_t> parents(g.numberOfVertices());
1226 std::vector<std::size_t> parentsEdges(g.numberOfVertices());
1228 distances.begin(), parents.begin(), parentsEdges.begin());
1245 class SUBGRAPH_MASK,
1246 class EDGE_VALUE_ITERATOR,
1252 const SUBGRAPH_MASK& mask,
1253 const std::size_t vs,
1254 const std::size_t vt,
1255 EDGE_VALUE_ITERATOR edgeWeights,
1256 std::deque<std::size_t>& path,
1259 std::vector<T> distances(g.numberOfVertices());
1260 std::vector<std::size_t> parents(g.numberOfVertices());
1261 std::vector<std::size_t> parentsEdges(g.numberOfVertices());
1262 spspEdges(g, mask, vs, vt, edgeWeights, path, distance,
1263 distances.begin(), parents.begin(), parentsEdges.begin());
1272 template<
class GRAPH,
class DISTANCE_ITERATOR>
1276 const std::size_t vs,
1277 DISTANCE_ITERATOR distances
1279 std::vector<std::size_t> parents(g.numberOfVertices());
1280 ssspEdges(g, vs, distances, parents.begin());
1290 template<
class GRAPH,
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
1294 const std::size_t vs,
1295 DISTANCE_ITERATOR distances,
1296 PARENT_ITERATOR parents
1298 typedef typename std::iterator_traits<DISTANCE_ITERATOR>::value_type Value;
1299 std::vector<std::size_t> parentsEdges(g.numberOfVertices());
1301 distances, parents, parentsEdges.begin());
1312 template<
class GRAPH,
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
1316 const std::size_t vs,
1317 DISTANCE_ITERATOR distances,
1318 PARENT_ITERATOR parents,
1319 PARENT_ITERATOR parentsEdges
1321 typedef typename std::iterator_traits<DISTANCE_ITERATOR>::value_type Value;
1323 distances, parents, parentsEdges);
1333 template<
class GRAPH,
class SUBGRAPH_MASK,
class DISTANCE_ITERATOR>
1337 const SUBGRAPH_MASK& mask,
1338 const std::size_t vs,
1339 DISTANCE_ITERATOR distances
1341 std::vector<std::size_t> parents(g.numberOfVertices());
1342 ssspEdges(g, mask, vs, distances, parents.begin());
1353 template<
class GRAPH,
class SUBGRAPH_MASK,
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
1357 const SUBGRAPH_MASK& mask,
1358 const std::size_t vs,
1359 DISTANCE_ITERATOR distances,
1360 PARENT_ITERATOR parents
1362 typedef typename std::iterator_traits<DISTANCE_ITERATOR>::value_type Value;
1363 std::vector<std::size_t> parentsEdges(g.numberOfVertices());
1376 template<
class GRAPH,
class SUBGRAPH_MASK,
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
1380 const SUBGRAPH_MASK& mask,
1381 const std::size_t vs,
1382 DISTANCE_ITERATOR distances,
1383 PARENT_ITERATOR parents,
1384 PARENT_ITERATOR parentsEdges
1386 typedef typename std::iterator_traits<DISTANCE_ITERATOR>::value_type Value;
1398 template<
class GRAPH,
class EDGE_VALUE_ITERATOR,
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
1402 const std::size_t vs,
1403 const EDGE_VALUE_ITERATOR edgeWeights,
1404 DISTANCE_ITERATOR distances,
1405 PARENT_ITERATOR parents
1419 template<
class GRAPH,
class EDGE_VALUE_ITERATOR,
class DISTANCE_ITERATOR,
class PARENT_ITERATOR>
1423 const std::size_t vs,
1424 const EDGE_VALUE_ITERATOR edgeWeights,
1425 DISTANCE_ITERATOR distances,
1426 PARENT_ITERATOR parents,
1427 PARENT_ITERATOR parentsEdges
1443 class SUBGRAPH_MASK,
1444 class EDGE_VALUE_ITERATOR,
1445 class DISTANCE_ITERATOR,
1446 class PARENT_ITERATOR
1451 const SUBGRAPH_MASK& mask,
1452 const std::size_t vs,
1453 const EDGE_VALUE_ITERATOR edgeWeights,
1454 DISTANCE_ITERATOR distances,
1455 PARENT_ITERATOR parents
1459 std::vector<std::size_t> parentsEdges(g.numberOfVertices());
1460 ssspEdges<GRAPH, SUBGRAPH_MASK, EDGE_VALUE_ITERATOR, DISTANCE_ITERATOR, PARENT_ITERATOR, Visitor>(g, mask, vs, edgeWeights, distances, parents, parentsEdges.begin(), visitor);
1475 class SUBGRAPH_MASK,
1476 class EDGE_VALUE_ITERATOR,
1477 class DISTANCE_ITERATOR,
1478 class PARENT_ITERATOR
1483 const SUBGRAPH_MASK& mask,
1484 const std::size_t vs,
1485 const EDGE_VALUE_ITERATOR edgeWeights,
1486 DISTANCE_ITERATOR distances,
1487 PARENT_ITERATOR parents,
1488 PARENT_ITERATOR parentsEdges
1492 ssspEdges<GRAPH, SUBGRAPH_MASK, EDGE_VALUE_ITERATOR, DISTANCE_ITERATOR, PARENT_ITERATOR, Visitor>(
1493 g, mask, vs, edgeWeights, distances, parents, parentsEdges, visitor);
1509 class SUBGRAPH_MASK,
1510 class EDGE_VALUE_ITERATOR,
1511 class DISTANCE_ITERATOR,
1512 class PARENT_ITERATOR,
1518 const SUBGRAPH_MASK& mask,
1519 const std::size_t vs,
1520 const EDGE_VALUE_ITERATOR edgeWeights,
1521 DISTANCE_ITERATOR distances,
1522 PARENT_ITERATOR parents,
1523 PARENT_ITERATOR parentsEdges,
1526 typedef typename std::iterator_traits<DISTANCE_ITERATOR>::value_type Value;
1527 typedef typename graph_detail::DijkstraQueueEntry<Value> Entry;
1529 assert(mask.vertex(vs));
1530 const Value infinity = std::numeric_limits<Value>::has_infinity
1531 ? std::numeric_limits<Value>::infinity()
1532 : std::numeric_limits<Value>::max();
1533 std::priority_queue<Entry> queue;
1535 for(std::size_t v = 0; v < g.numberOfVertices(); ++v) {
1536 distances[v] = infinity;
1537 if(mask.vertex(v)) {
1538 queue.push(Entry(v, infinity));
1542 while(!queue.empty()) {
1543 const std::size_t v = queue.top().vertex_;
1544 const bool proceed = visitor(distances, parents, parentsEdges, v);
1550 if(distances[v] == infinity) {
1554 for(
typename GRAPH::AdjacencyIterator it = g.adjacenciesFromVertexBegin(v);
1555 it != g.adjacenciesFromVertexEnd(v); ++it) {
1556 if(mask.vertex(it->vertex()) && mask.edge(it->edge())) {
1557 const Value alternativeDistance = distances[v] + edgeWeights[it->edge()];
1558 if(alternativeDistance < distances[it->vertex()]) {
1559 distances[it->vertex()] = alternativeDistance;
1560 parentsEdges[it->vertex()] = it->edge();
1561 parents[it->vertex()] = v;
1562 queue.push(Entry(it->vertex(), alternativeDistance));
1591 class SUBGRAPH_MASK,
1592 class EDGE_VALUE_ITERATOR,
1594 class DISTANCE_ITERATOR,
1595 class PARENT_ITERATOR
1600 const SUBGRAPH_MASK& mask,
1601 const std::size_t vs,
1602 const std::size_t vt,
1603 EDGE_VALUE_ITERATOR edgeWeights,
1604 std::deque<std::size_t>& path,
1606 DISTANCE_ITERATOR distances,
1607 PARENT_ITERATOR parents,
1608 PARENT_ITERATOR parentsEdges
1611 typedef graph_detail::DijkstraSPSPVisitor<DISTANCE_ITERATOR, PARENT_ITERATOR> Visitor;
1612 Visitor visitor(vs, vt, path);
1613 ssspEdges<GRAPH, SUBGRAPH_MASK, EDGE_VALUE_ITERATOR, DISTANCE_ITERATOR, PARENT_ITERATOR, Visitor>(g, mask, vs, edgeWeights, distances, parents, parentsEdges, visitor);
1614 distance = distances[vt];
1620 #endif // #ifndef ANDRES_GRAPH_SHORTEST_PATHS_HXX