41 absl::Span<const ArcWithLengthAndResources> arcs_with_length_and_resources,
42 int source,
int destination,
const std::vector<double>& max_resources) {
45 using ArcIndex = GraphType::ArcIndex;
47 const int num_arcs = arcs_with_length_and_resources.size();
48 GraphType graph(num_nodes, num_arcs);
49 std::vector<double> arc_lengths;
50 arc_lengths.reserve(num_arcs);
51 std::vector<std::vector<double>> arc_resources(max_resources.size());
52 for (
int i = 0; i < max_resources.size(); ++i) {
53 arc_resources[i].reserve(num_arcs);
55 for (
const auto& arc : arcs_with_length_and_resources) {
56 graph.AddArc(arc.from, arc.to);
57 arc_lengths.push_back(arc.length);
58 for (
int i = 0; i < arc.resources.size(); ++i) {
59 arc_resources[i].push_back(arc.resources[i]);
63 std::vector<ArcIndex> permutation;
64 graph.Build(&permutation);
66 for (
int i = 0; i < max_resources.size(); ++i) {
70 std::vector<ArcIndex> inverse_permutation =
73 const absl::StatusOr<std::vector<NodeIndex>> topological_order =
75 CHECK_OK(topological_order) <<
"arcs_with_length form a cycle.";
77 std::vector<NodeIndex> sources = {source};
78 std::vector<NodeIndex> destinations = {destination};
80 constrained_shortest_path_on_dag(&graph, &arc_lengths, &arc_resources,
81 *topological_order, sources,
82 destinations, &max_resources);
87 ApplyMapping(inverse_permutation, path_with_length.
arc_path);
89 return path_with_length;