Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
routing_filter_committables.cc
Go to the documentation of this file.
1// Copyright 2010-2025 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
15
16#include "absl/log/check.h"
17#include "absl/types/span.h"
18
19namespace operations_research {
20
21bool PropagateTransitAndSpan(int path, DimensionValues& dimension_values) {
22 DCHECK_GT(dimension_values.NumNodes(path), 0);
23 using Interval = DimensionValues::Interval;
24 const absl::Span<Interval> cumuls = dimension_values.MutableCumuls(path);
25 const absl::Span<const Interval> transits = dimension_values.Transits(path);
26 const int num_nodes = dimension_values.NumNodes(path);
27 const Interval span = dimension_values.Span(path);
28 // Span -> cumul front/back.
29 if (!cumuls.back().IntersectWith(cumuls[0] + span)) return false;
30 if (!cumuls[0].IntersectWith(cumuls.back() - span)) return false;
31 // Propagate from start to end.
32 Interval cumul = cumuls[0];
33 for (int t = 0; t < num_nodes - 1; ++t) {
34 cumul.Add(transits[t]);
35 if (!cumul.IntersectWith(cumuls[t + 1])) return false;
36 cumuls[t + 1] = cumul;
37 }
38 // Propagate span to cumul front, then re-propagate from start to end
39 // as long as there are changes.
40 cumul = cumuls.back() - span;
41 for (int t = 0; t < num_nodes; ++t) {
42 if (!cumul.IntersectWith(cumuls[t])) return false;
43 if (cumul == cumuls[t]) break;
44 cumuls[t] = cumul;
45 if (t == num_nodes - 1) break;
46 cumul.Add(transits[t]);
47 }
48 // Propagate from end to start.
49 cumul = cumuls.back();
50 for (int t = num_nodes - 2; t >= 0; --t) {
51 cumul.Subtract(transits[t]);
52 if (!cumul.IntersectWith(cumuls[t])) return false;
53 cumuls[t] = cumul;
54 }
55 // Propagate span to cumul back, then re-propagate from end to start
56 // as long as there are changes.
57 cumul = cumuls[0] + span;
58 for (int t = num_nodes - 1; t >= 0; --t) {
59 if (!cumul.IntersectWith(cumuls[t])) return false;
60 if (cumul == cumuls[t]) break;
61 cumuls[t] = cumul;
62 if (t == 0) break;
63 cumul.Subtract(transits[t - 1]);
64 }
65 // Cumul front/back -> span.
66 if (!dimension_values.MutableSpan(path).IntersectWith(cumuls.back() -
67 cumuls[0])) {
68 return false;
69 }
70 return true;
71}
72
73} // namespace operations_research
absl::Span< Interval > MutableCumuls(int path)
absl::Span< const Interval > Transits(int path) const
OR-Tools root namespace.
bool PropagateTransitAndSpan(int path, DimensionValues &dimension_values)