29 std::function<int64_t(
int,
int)> load_demand_of_item_for_bin,
30 std::vector<LoadLimit> load_limit_per_bin) {
31 DCHECK_EQ(num_bins_, load_limit_per_bin.size());
32 for (
const LoadLimit& limit : load_limit_per_bin) {
33 const int64_t violation = std::max<int64_t>(0,
CapOpp(limit.soft_max_load));
35 CapAdd(total_cost_,
CapProd(violation, limit.cost_above_soft_max_load));
37 load_demands_per_dimension_.push_back(std::move(load_demand_of_item_for_bin));
38 for (
int b = 0;
b < num_bins_; ++
b) {
39 load_per_bin_[
b].push_back(0);
40 load_limits_per_bin_[
b].push_back(load_limit_per_bin[
b]);
65 for (
size_t dim = 0; dim < load_demands_per_dimension_.size(); ++dim) {
66 int64_t& load = load_per_bin_[bin][dim];
67 const LoadLimit& limit = load_limits_per_bin_[bin][dim];
68 const int64_t prev_violation =
70 load =
CapAdd(load, load_demands_per_dimension_[dim](item, bin));
71 const int64_t curr_violation =
83 for (
size_t dim = 0; dim < load_demands_per_dimension_.size(); ++dim) {
84 int64_t& load = load_per_bin_[bin][dim];
85 const LoadLimit& limit = load_limits_per_bin_[bin][dim];
86 const int64_t prev_violation =
88 load =
CapSub(load, load_demands_per_dimension_[dim](item, bin));
89 const int64_t curr_violation =
121 int num_arcs, int64_t
start,
122 const std::function<int64_t(int64_t)>& next_accessor,
123 const std::function<
bool(int64_t)>& is_end,
124 const std::function<int64_t(int64_t, int64_t, int64_t)>&
125 arc_cost_for_route_start,
126 std::vector<std::pair<int64_t, int>>* most_expensive_arc_starts_and_ranks,
127 std::pair<int, int>* first_expensive_arc_indices) {
128 if (is_end(next_accessor(
start))) {
130 *first_expensive_arc_indices = {-1, -1};
136 using ArcCostNegativeRankStart = std::tuple<int64_t, int, int64_t>;
137 std::priority_queue<ArcCostNegativeRankStart,
138 std::vector<ArcCostNegativeRankStart>,
139 std::greater<ArcCostNegativeRankStart>>
142 int64_t before_node =
start;
144 while (!is_end(before_node)) {
145 const int64_t after_node = next_accessor(before_node);
146 const int64_t arc_cost =
147 arc_cost_for_route_start(before_node, after_node,
start);
148 arc_info_pq.emplace(arc_cost, -rank, before_node);
150 before_node = after_node;
153 if (rank > num_arcs) {
159 DCHECK_EQ(arc_info_pq.size(), std::min(rank, num_arcs));
161 most_expensive_arc_starts_and_ranks->resize(arc_info_pq.size());
162 int arc_index = arc_info_pq.size() - 1;
163 while (!arc_info_pq.empty()) {
164 const ArcCostNegativeRankStart& arc_info = arc_info_pq.top();
165 (*most_expensive_arc_starts_and_ranks)[arc_index] = {
166 std::get<2>(arc_info), -std::get<1>(arc_info)};
171 *first_expensive_arc_indices = {0, 1};
bool FindMostExpensiveArcsOnRoute(int num_arcs, int64_t start, const std::function< int64_t(int64_t)> &next_accessor, const std::function< bool(int64_t)> &is_end, const std::function< int64_t(int64_t, int64_t, int64_t)> &arc_cost_for_route_start, std::vector< std::pair< int64_t, int > > *most_expensive_arc_starts_and_ranks, std::pair< int, int > *first_expensive_arc_indices)