Syng google3: use base/types.h
This commit is contained in:
@@ -25,9 +25,9 @@
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "ortools/base/int_type.h"
|
||||
#include "ortools/base/integral_types.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/map_util.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/routing.h"
|
||||
#include "ortools/constraint_solver/routing_lp_scheduling.h"
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "ortools/base/integral_types.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/strong_vector.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/routing_types.h"
|
||||
|
||||
namespace operations_research {
|
||||
|
||||
@@ -34,9 +34,9 @@
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "ortools/base/dump_vars.h"
|
||||
#include "ortools/base/integral_types.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/mathutil.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/routing.h"
|
||||
#include "ortools/constraint_solver/routing_parameters.pb.h"
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "ortools/base/integral_types.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/constraint_solveri.h"
|
||||
#include "ortools/constraint_solver/routing_types.h"
|
||||
@@ -1041,14 +1041,14 @@ bool RelocateSubtrip::RelocateSubTripFromPickup(const int64_t chain_first_node,
|
||||
return false;
|
||||
}
|
||||
const int pair = pair_of_node_[current];
|
||||
if (is_delivery_node_[current] && !opened_pairs_bitset_[pair]) {
|
||||
if (IsDeliveryNode(current) && !opened_pairs_bitset_[pair]) {
|
||||
rejected_nodes_.push_back(current);
|
||||
} else {
|
||||
subtrip_nodes_.push_back(current);
|
||||
if (is_pickup_node_[current]) {
|
||||
if (IsPickupNode(current)) {
|
||||
++num_opened_pairs;
|
||||
opened_pairs_bitset_[pair] = true;
|
||||
} else if (is_delivery_node_[current]) {
|
||||
} else if (IsDeliveryNode(current)) {
|
||||
--num_opened_pairs;
|
||||
opened_pairs_bitset_[pair] = false;
|
||||
}
|
||||
@@ -1089,14 +1089,14 @@ bool RelocateSubtrip::RelocateSubTripFromDelivery(
|
||||
return false;
|
||||
}
|
||||
const int pair = pair_of_node_[current];
|
||||
if (is_pickup_node_[current] && !opened_pairs_bitset_[pair]) {
|
||||
if (IsPickupNode(current) && !opened_pairs_bitset_[pair]) {
|
||||
rejected_nodes_.push_back(current);
|
||||
} else {
|
||||
subtrip_nodes_.push_back(current);
|
||||
if (is_delivery_node_[current]) {
|
||||
if (IsDeliveryNode(current)) {
|
||||
++num_opened_pairs;
|
||||
opened_pairs_bitset_[pair] = true;
|
||||
} else if (is_pickup_node_[current]) {
|
||||
} else if (IsPickupNode(current)) {
|
||||
--num_opened_pairs;
|
||||
opened_pairs_bitset_[pair] = false;
|
||||
}
|
||||
@@ -1128,9 +1128,9 @@ bool RelocateSubtrip::RelocateSubTripFromDelivery(
|
||||
bool RelocateSubtrip::MakeNeighbor() {
|
||||
const auto do_move = [this](int64_t node, int64_t insertion_node) {
|
||||
if (IsInactive(node)) return false;
|
||||
if (is_pickup_node_[node]) {
|
||||
if (IsPickupNode(node)) {
|
||||
return RelocateSubTripFromPickup(node, insertion_node);
|
||||
} else if (is_delivery_node_[node]) {
|
||||
} else if (IsDeliveryNode(node)) {
|
||||
return RelocateSubTripFromDelivery(node, insertion_node);
|
||||
} else {
|
||||
return false;
|
||||
@@ -1188,10 +1188,11 @@ bool ExchangeSubtrip::MakeNeighbor() {
|
||||
const int64_t node = BaseNode(0);
|
||||
const int64_t neighbor = GetNeighborForBaseNode(0);
|
||||
if (IsInactive(neighbor)) return false;
|
||||
if (is_delivery_node_[node] && is_delivery_node_[Prev(neighbor)]) {
|
||||
if (IsDeliveryNode(node) && IsDeliveryNode(Prev(neighbor))) {
|
||||
node0 = node;
|
||||
node1 = Prev(neighbor);
|
||||
} else if (is_pickup_node_[neighbor] && is_pickup_node_[Next(node)]) {
|
||||
} else if (IsPickupNode(neighbor) && !IsPathEnd(Next(node)) &&
|
||||
IsPickupNode(Next(node))) {
|
||||
node0 = Next(node);
|
||||
node1 = neighbor;
|
||||
} else {
|
||||
@@ -1234,12 +1235,12 @@ bool ExchangeSubtrip::MakeNeighbor() {
|
||||
const bool concatenated01 = last0 == subtrip1_.front();
|
||||
const bool concatenated10 = last1 == subtrip0_.front();
|
||||
|
||||
if (is_delivery_node_[node0]) std::swap(subtrip1_, rejects0_);
|
||||
if (IsDeliveryNode(node0)) std::swap(subtrip1_, rejects0_);
|
||||
path0_.insert(path0_.end(), subtrip1_.begin(), subtrip1_.end());
|
||||
path0_.insert(path0_.end(), rejects0_.begin(), rejects0_.end());
|
||||
path0_.push_back(last0);
|
||||
|
||||
if (is_delivery_node_[node1]) std::swap(subtrip0_, rejects1_);
|
||||
if (IsDeliveryNode(node1)) std::swap(subtrip0_, rejects1_);
|
||||
path1_.insert(path1_.end(), subtrip0_.begin(), subtrip0_.end());
|
||||
path1_.insert(path1_.end(), rejects1_.begin(), rejects1_.end());
|
||||
path1_.push_back(last1);
|
||||
@@ -1266,12 +1267,12 @@ bool ExchangeSubtrip::ExtractChainsAndCheckCanonical(
|
||||
int64_t base_node, std::vector<int64_t>* rejects,
|
||||
std::vector<int64_t>* subtrip) {
|
||||
const bool extracted =
|
||||
is_pickup_node_[base_node]
|
||||
IsPickupNode(base_node)
|
||||
? ExtractChainsFromPickup(base_node, rejects, subtrip)
|
||||
: ExtractChainsFromDelivery(base_node, rejects, subtrip);
|
||||
if (!extracted) return false;
|
||||
// Check canonicality.
|
||||
return !is_delivery_node_[base_node] ||
|
||||
return !IsDeliveryNode(base_node) ||
|
||||
pair_of_node_[subtrip->front()] != pair_of_node_[subtrip->back()] ||
|
||||
!rejects->empty();
|
||||
}
|
||||
@@ -1279,7 +1280,7 @@ bool ExchangeSubtrip::ExtractChainsAndCheckCanonical(
|
||||
bool ExchangeSubtrip::ExtractChainsFromPickup(int64_t base_node,
|
||||
std::vector<int64_t>* rejects,
|
||||
std::vector<int64_t>* subtrip) {
|
||||
DCHECK(is_pickup_node_[base_node]);
|
||||
DCHECK(IsPickupNode(base_node));
|
||||
DCHECK(rejects->empty());
|
||||
DCHECK(subtrip->empty());
|
||||
// Iterate from base_node forwards while maintaining the set of opened pairs.
|
||||
@@ -1289,14 +1290,14 @@ bool ExchangeSubtrip::ExtractChainsFromPickup(int64_t base_node,
|
||||
int current = base_node;
|
||||
do {
|
||||
const int pair = pair_of_node_[current];
|
||||
if (is_delivery_node_[current] && !opened_pairs_set_[pair]) {
|
||||
if (IsDeliveryNode(current) && !opened_pairs_set_[pair]) {
|
||||
rejects->push_back(current);
|
||||
} else {
|
||||
subtrip->push_back(current);
|
||||
if (is_pickup_node_[current]) {
|
||||
if (IsPickupNode(current)) {
|
||||
++num_opened_pairs;
|
||||
opened_pairs_set_[pair] = true;
|
||||
} else if (is_delivery_node_[current]) {
|
||||
} else if (IsDeliveryNode(current)) {
|
||||
--num_opened_pairs;
|
||||
opened_pairs_set_[pair] = false;
|
||||
}
|
||||
@@ -1309,7 +1310,7 @@ bool ExchangeSubtrip::ExtractChainsFromPickup(int64_t base_node,
|
||||
bool ExchangeSubtrip::ExtractChainsFromDelivery(int64_t base_node,
|
||||
std::vector<int64_t>* rejects,
|
||||
std::vector<int64_t>* subtrip) {
|
||||
DCHECK(is_delivery_node_[base_node]);
|
||||
DCHECK(IsDeliveryNode(base_node));
|
||||
DCHECK(rejects->empty());
|
||||
DCHECK(subtrip->empty());
|
||||
// Iterate from base_node backwards while maintaining the set of opened pairs.
|
||||
@@ -1319,14 +1320,14 @@ bool ExchangeSubtrip::ExtractChainsFromDelivery(int64_t base_node,
|
||||
int current = base_node;
|
||||
do {
|
||||
const int pair = pair_of_node_[current];
|
||||
if (is_pickup_node_[current] && !opened_pairs_set_[pair]) {
|
||||
if (IsPickupNode(current) && !opened_pairs_set_[pair]) {
|
||||
rejects->push_back(current);
|
||||
} else {
|
||||
subtrip->push_back(current);
|
||||
if (is_delivery_node_[current]) {
|
||||
if (IsDeliveryNode(current)) {
|
||||
++num_opened_pairs;
|
||||
opened_pairs_set_[pair] = true;
|
||||
} else if (is_pickup_node_[current]) {
|
||||
} else if (IsPickupNode(current)) {
|
||||
--num_opened_pairs;
|
||||
opened_pairs_set_[pair] = false;
|
||||
}
|
||||
|
||||
@@ -648,6 +648,17 @@ class RelocateSubtrip : public PathOperator {
|
||||
/// Relocates the subtrip ending at chain_first_node. It must be a delivery.
|
||||
bool RelocateSubTripFromDelivery(int64_t chain_last_node,
|
||||
int64_t insertion_node);
|
||||
bool IsPickupNode(int64_t node) const {
|
||||
DCHECK_LT(node, is_pickup_node_.size());
|
||||
DCHECK_GE(node, 0);
|
||||
return is_pickup_node_[node];
|
||||
}
|
||||
bool IsDeliveryNode(int64_t node) const {
|
||||
DCHECK_LT(node, is_delivery_node_.size());
|
||||
DCHECK_GE(node, 0);
|
||||
return is_delivery_node_[node];
|
||||
}
|
||||
|
||||
std::vector<bool> is_pickup_node_;
|
||||
std::vector<bool> is_delivery_node_;
|
||||
std::vector<int> pair_of_node_;
|
||||
@@ -706,6 +717,16 @@ class ExchangeSubtrip : public PathOperator {
|
||||
std::vector<int64_t>* rejects,
|
||||
std::vector<int64_t>* subtrip);
|
||||
void SetPath(const std::vector<int64_t>& path, int path_id);
|
||||
bool IsPickupNode(int64_t node) const {
|
||||
DCHECK_LT(node, is_pickup_node_.size());
|
||||
DCHECK_GE(node, 0);
|
||||
return is_pickup_node_[node];
|
||||
}
|
||||
bool IsDeliveryNode(int64_t node) const {
|
||||
DCHECK_LT(node, is_delivery_node_.size());
|
||||
DCHECK_GE(node, 0);
|
||||
return is_delivery_node_[node];
|
||||
}
|
||||
|
||||
// Precompute some information about nodes.
|
||||
std::vector<bool> is_pickup_node_;
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "ortools/base/integral_types.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/map_util.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/routing.h"
|
||||
#include "ortools/constraint_solver/routing_parameters.pb.h"
|
||||
|
||||
@@ -44,17 +44,15 @@
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "ortools/base/adjustable_priority_queue.h"
|
||||
#include "ortools/base/integral_types.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/macros.h"
|
||||
#include "ortools/base/map_util.h"
|
||||
#include "ortools/base/stl_util.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/constraint_solveri.h"
|
||||
#include "ortools/constraint_solver/routing.h"
|
||||
#include "ortools/constraint_solver/routing_parameters.pb.h"
|
||||
#include "ortools/constraint_solver/routing_types.h"
|
||||
#include "ortools/constraint_solver/routing_utils.h"
|
||||
#include "ortools/graph/christofides.h"
|
||||
#include "ortools/util/bitset.h"
|
||||
#include "ortools/util/range_query_function.h"
|
||||
@@ -644,6 +642,7 @@ void CheapestInsertionFilteredHeuristic::AppendInsertionPositionsAfter(
|
||||
std::vector<NodeInsertion>* node_insertions) {
|
||||
DCHECK(node_insertions != nullptr);
|
||||
int64_t insert_after = start;
|
||||
if (!model()->VehicleVar(node_to_insert)->Contains(vehicle)) return;
|
||||
while (!model()->IsEnd(insert_after)) {
|
||||
const int64_t insert_before =
|
||||
(insert_after == start) ? next_after_start : Value(insert_after);
|
||||
@@ -1008,7 +1007,10 @@ bool GlobalCheapestInsertionFilteredHeuristic::
|
||||
// Since this vehicle is empty and has the same fixed cost as the
|
||||
// entry_vehicle, it shouldn't be the representative of empty vehicles
|
||||
// for any pickup/delivery in the priority queue.
|
||||
DCHECK_EQ(num_previous_vehicle_entries, 0);
|
||||
DCHECK(
|
||||
num_previous_vehicle_entries == 0 ||
|
||||
model()->GetVehicleClassIndexOfVehicle(compatible_vehicle).value() !=
|
||||
model()->GetVehicleClassIndexOfVehicle(entry_vehicle).value());
|
||||
return true;
|
||||
}
|
||||
// The previously unused entry_vehicle is now used, so we use the next
|
||||
@@ -1302,7 +1304,10 @@ bool GlobalCheapestInsertionFilteredHeuristic::
|
||||
// Since this vehicle is empty and has the same fixed cost as the
|
||||
// entry_vehicle, it shouldn't be the representative of empty vehicles
|
||||
// for any node in the priority queue.
|
||||
DCHECK(no_prior_entries_for_this_vehicle);
|
||||
DCHECK(
|
||||
no_prior_entries_for_this_vehicle ||
|
||||
model()->GetVehicleClassIndexOfVehicle(compatible_vehicle).value() !=
|
||||
model()->GetVehicleClassIndexOfVehicle(entry_vehicle).value());
|
||||
return true;
|
||||
}
|
||||
// The previously unused entry_vehicle is now used, so we use the next
|
||||
@@ -1406,6 +1411,23 @@ void GlobalCheapestInsertionFilteredHeuristic::DetectUsedVehicles(
|
||||
}
|
||||
}
|
||||
|
||||
bool GlobalCheapestInsertionFilteredHeuristic::IsCheapestClassRepresentative(
|
||||
int vehicle) const {
|
||||
if (VehicleIsEmpty(vehicle)) {
|
||||
// We only consider the least expensive empty vehicle of each type for
|
||||
// entries of the same vehicle class.
|
||||
const int curator_vehicle =
|
||||
empty_vehicle_type_curator_->GetLowestFixedCostVehicleOfType(
|
||||
empty_vehicle_type_curator_->Type(vehicle));
|
||||
if (curator_vehicle != vehicle &&
|
||||
model()->GetVehicleClassIndexOfVehicle(curator_vehicle).value() ==
|
||||
model()->GetVehicleClassIndexOfVehicle(vehicle).value()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void GlobalCheapestInsertionFilteredHeuristic::InsertFarthestNodesAsSeeds() {
|
||||
// TODO(user): consider checking search limits.
|
||||
if (gci_params_.farthest_seeds_ratio <= 0) return;
|
||||
@@ -1557,13 +1579,7 @@ void GlobalCheapestInsertionFilteredHeuristic::
|
||||
std::vector<NodeInsertion> pickup_insertions;
|
||||
std::vector<NodeInsertion> delivery_insertions;
|
||||
for (int vehicle = 0; vehicle < model()->vehicles(); ++vehicle) {
|
||||
if (VehicleIsEmpty(vehicle) &&
|
||||
empty_vehicle_type_curator_->GetLowestFixedCostVehicleOfType(
|
||||
empty_vehicle_type_curator_->Type(vehicle)) != vehicle) {
|
||||
// We only consider the least expensive empty vehicle of each type for
|
||||
// entries.
|
||||
continue;
|
||||
}
|
||||
if (!IsCheapestClassRepresentative(vehicle)) continue;
|
||||
const int64_t start = model()->Start(vehicle);
|
||||
pickup_insertions.clear();
|
||||
AppendInsertionPositionsAfter(pickup, start, Value(start), vehicle,
|
||||
@@ -1609,13 +1625,7 @@ void GlobalCheapestInsertionFilteredHeuristic::
|
||||
continue;
|
||||
}
|
||||
|
||||
if (VehicleIsEmpty(vehicle) &&
|
||||
empty_vehicle_type_curator_->GetLowestFixedCostVehicleOfType(
|
||||
empty_vehicle_type_curator_->Type(vehicle)) != vehicle) {
|
||||
// We only consider the least expensive empty vehicle of each type for
|
||||
// entries.
|
||||
continue;
|
||||
}
|
||||
if (!IsCheapestClassRepresentative(vehicle)) continue;
|
||||
|
||||
int64_t delivery_insert_after = pickup;
|
||||
while (!model()->IsEnd(delivery_insert_after)) {
|
||||
@@ -1771,14 +1781,17 @@ bool GlobalCheapestInsertionFilteredHeuristic::AddPairEntriesWithPickupAfter(
|
||||
node_index_to_neighbors_by_cost_class_->GetNeighborsOfNodeForCostClass(
|
||||
cost_class, insert_after)) {
|
||||
if (StopSearchAndCleanup(priority_queue)) return false;
|
||||
if (Contains(pickup)) continue;
|
||||
if (Contains(pickup) || !model()->VehicleVar(pickup)->Contains(vehicle)) {
|
||||
continue;
|
||||
}
|
||||
for (const std::pair<int, int>& index_pairs :
|
||||
model()->GetPickupIndexPairs(pickup)) {
|
||||
if (!pair_indices.contains(index_pairs.first)) continue;
|
||||
const RoutingModel::IndexPair& index_pair =
|
||||
pickup_delivery_pairs[index_pairs.first];
|
||||
for (const int64_t delivery : index_pair.second) {
|
||||
if (Contains(delivery)) {
|
||||
if (Contains(delivery) ||
|
||||
!model()->VehicleVar(delivery)->Contains(vehicle)) {
|
||||
continue;
|
||||
}
|
||||
int64_t delivery_insert_after = pickup;
|
||||
@@ -1816,14 +1829,20 @@ bool GlobalCheapestInsertionFilteredHeuristic::AddPairEntriesWithDeliveryAfter(
|
||||
node_index_to_neighbors_by_cost_class_->GetNeighborsOfNodeForCostClass(
|
||||
cost_class, insert_after)) {
|
||||
if (StopSearchAndCleanup(priority_queue)) return false;
|
||||
if (Contains(delivery)) continue;
|
||||
if (Contains(delivery) ||
|
||||
!model()->VehicleVar(delivery)->Contains(vehicle)) {
|
||||
continue;
|
||||
}
|
||||
for (const std::pair<int, int>& index_pairs :
|
||||
model()->GetDeliveryIndexPairs(delivery)) {
|
||||
if (!pair_indices.contains(index_pairs.first)) continue;
|
||||
const RoutingModel::IndexPair& index_pair =
|
||||
pickup_delivery_pairs[index_pairs.first];
|
||||
for (const int64_t pickup : index_pair.first) {
|
||||
if (Contains(pickup)) continue;
|
||||
if (Contains(pickup) ||
|
||||
!model()->VehicleVar(pickup)->Contains(vehicle)) {
|
||||
continue;
|
||||
}
|
||||
int64_t pickup_insert_after = model()->Start(vehicle);
|
||||
while (pickup_insert_after != insert_after) {
|
||||
AddPairEntry(pickup, pickup_insert_after, delivery, insert_after,
|
||||
@@ -1983,17 +2002,16 @@ void GlobalCheapestInsertionFilteredHeuristic::
|
||||
if (!gci_params_.use_neighbors_ratio_for_initialization) {
|
||||
auto vehicles_it = vehicles.begin();
|
||||
std::vector<NodeInsertion> insertions;
|
||||
// TODO(user): Ideally we'd want to iterate on vehicle var values:
|
||||
// std::unique_ptr<IntVarIterator>
|
||||
// it(model()->VehicleVar(node)->MakeDomainIterator(false));
|
||||
// for (const int64_t v : InitAndGetValues(it)) {
|
||||
// Requires taking vehicles into account.
|
||||
for (int v = 0; v < num_vehicles; v++) {
|
||||
const int vehicle = vehicles.empty() ? v : *vehicles_it++;
|
||||
|
||||
const int64_t start = model()->Start(vehicle);
|
||||
if (all_vehicles && VehicleIsEmpty(vehicle) &&
|
||||
empty_vehicle_type_curator_->GetLowestFixedCostVehicleOfType(
|
||||
empty_vehicle_type_curator_->Type(vehicle)) != vehicle) {
|
||||
// We only consider the least expensive empty vehicle of each type for
|
||||
// entries.
|
||||
continue;
|
||||
}
|
||||
if (all_vehicles && !IsCheapestClassRepresentative(vehicle)) continue;
|
||||
insertions.clear();
|
||||
AppendInsertionPositionsAfter(node, start, Value(start), vehicle,
|
||||
/*ignore_cost=*/true, &insertions);
|
||||
@@ -2026,13 +2044,7 @@ void GlobalCheapestInsertionFilteredHeuristic::
|
||||
!insert_on_vehicle_for_cost_class(vehicle, cost_class)) {
|
||||
continue;
|
||||
}
|
||||
if (all_vehicles && VehicleIsEmpty(vehicle) &&
|
||||
empty_vehicle_type_curator_->GetLowestFixedCostVehicleOfType(
|
||||
empty_vehicle_type_curator_->Type(vehicle)) != vehicle) {
|
||||
// We only consider the least expensive empty vehicle of each type for
|
||||
// entries.
|
||||
continue;
|
||||
}
|
||||
if (all_vehicles && !IsCheapestClassRepresentative(vehicle)) continue;
|
||||
AddNodeEntry(node, insert_after, vehicle, all_vehicles, queue);
|
||||
}
|
||||
}
|
||||
@@ -2267,6 +2279,7 @@ void LocalCheapestInsertionFilteredHeuristic::InsertBestPickupThenDelivery(
|
||||
if (StopSearch()) return;
|
||||
for (const NodeInsertion& pickup_insertion : pickup_insertions) {
|
||||
const int vehicle = pickup_insertion.vehicle;
|
||||
if (!model()->VehicleVar(delivery)->Contains(vehicle)) continue;
|
||||
if (bin_capacities_ && !bin_capacities_->CheckAdditionsFeasibility(
|
||||
{pickup, delivery}, vehicle)) {
|
||||
continue;
|
||||
@@ -2370,10 +2383,16 @@ void LocalCheapestInsertionFilteredHeuristic::InsertBestPairMultitour(
|
||||
};
|
||||
|
||||
for (int pickup : index_pair.first) {
|
||||
const IntVar* pickup_vehicle_var = model()->VehicleVar(pickup);
|
||||
if (StopSearch()) return;
|
||||
for (int delivery : index_pair.second) {
|
||||
const IntVar* delivery_vehicle_var = model()->VehicleVar(delivery);
|
||||
insertion_container_.Clear();
|
||||
for (int vehicle = 0; vehicle < model()->vehicles(); ++vehicle) {
|
||||
std::unique_ptr<IntVarIterator> pickup_vehicles(
|
||||
pickup_vehicle_var->MakeDomainIterator(false));
|
||||
for (const int vehicle : InitAndGetValues(pickup_vehicles.get())) {
|
||||
if (vehicle == -1) continue;
|
||||
if (!delivery_vehicle_var->Contains(vehicle)) continue;
|
||||
if (bin_capacities_ && !bin_capacities_->CheckAdditionsFeasibility(
|
||||
{pickup, delivery}, vehicle)) {
|
||||
continue;
|
||||
@@ -2553,7 +2572,11 @@ LocalCheapestInsertionFilteredHeuristic::ComputeEvaluatorSortedPositions(
|
||||
const int size = model()->Size();
|
||||
if (node >= size) return {};
|
||||
std::vector<NodeInsertion> sorted_insertions;
|
||||
for (int vehicle = 0; vehicle < model()->vehicles(); ++vehicle) {
|
||||
const IntVar* vehicle_var = model()->VehicleVar(node);
|
||||
std::unique_ptr<IntVarIterator> node_vehicles(
|
||||
vehicle_var->MakeDomainIterator(false));
|
||||
for (const int vehicle : InitAndGetValues(node_vehicles.get())) {
|
||||
if (vehicle == -1) continue;
|
||||
if (bin_capacities_ &&
|
||||
!bin_capacities_->CheckAdditionFeasibility(node, vehicle)) {
|
||||
continue;
|
||||
@@ -2588,7 +2611,13 @@ LocalCheapestInsertionFilteredHeuristic::ComputeEvaluatorSortedPairPositions(
|
||||
const int size = model()->Size();
|
||||
DCHECK_LT(pickup, size);
|
||||
DCHECK_LT(delivery, size);
|
||||
for (int vehicle = 0; vehicle < model()->vehicles(); ++vehicle) {
|
||||
const IntVar* pickup_vehicle_var = model()->VehicleVar(pickup);
|
||||
const IntVar* delivery_vehicle_var = model()->VehicleVar(delivery);
|
||||
std::unique_ptr<IntVarIterator> pickup_vehicles(
|
||||
pickup_vehicle_var->MakeDomainIterator(false));
|
||||
for (const int vehicle : InitAndGetValues(pickup_vehicles.get())) {
|
||||
if (vehicle == -1) continue;
|
||||
if (!delivery_vehicle_var->Contains(vehicle)) continue;
|
||||
if (bin_capacities_ && !bin_capacities_->CheckAdditionsFeasibility(
|
||||
{pickup, delivery}, vehicle)) {
|
||||
continue;
|
||||
|
||||
@@ -36,10 +36,10 @@
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/log/check.h"
|
||||
#include "ortools/base/adjustable_priority_queue.h"
|
||||
#include "ortools/base/integral_types.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/macros.h"
|
||||
#include "ortools/base/mathutil.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/constraint_solveri.h"
|
||||
#include "ortools/constraint_solver/routing.h"
|
||||
@@ -610,6 +610,10 @@ class GlobalCheapestInsertionFilteredHeuristic
|
||||
std::vector<int>* unused_vehicles,
|
||||
absl::flat_hash_set<int>* used_vehicles);
|
||||
|
||||
/// Returns true of the vehicle's route is not empty or if the vehicle is the
|
||||
/// representative of its class and type.
|
||||
bool IsCheapestClassRepresentative(int vehicle) const;
|
||||
|
||||
/// Inserts the (farthest_seeds_ratio_ * model()->vehicles()) nodes farthest
|
||||
/// from the start/ends of the available vehicle routes as seeds on their
|
||||
/// closest route.
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "ortools/base/int_type.h"
|
||||
#include "ortools/base/integral_types.h"
|
||||
#include "ortools/base/types.h"
|
||||
|
||||
namespace operations_research {
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "ortools/base/integral_types.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/macros.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/constraint_solveri.h"
|
||||
#include "ortools/util/string_array.h"
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "ortools/base/integral_types.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/macros.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/constraint_solveri.h"
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "ortools/base/integral_types.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/constraint_solveri.h"
|
||||
#include "ortools/util/string_array.h"
|
||||
|
||||
@@ -29,10 +29,10 @@
|
||||
#include "absl/strings/str_join.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "ortools/base/bitmap.h"
|
||||
#include "ortools/base/integral_types.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/mathutil.h"
|
||||
#include "ortools/base/timer.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/constraint_solveri.h"
|
||||
#include "ortools/constraint_solver/search_limit.pb.h"
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/strings/str_join.h"
|
||||
#include "ortools/base/commandlineflags.h"
|
||||
#include "ortools/base/integral_types.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/map_util.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/constraint_solveri.h"
|
||||
#include "ortools/util/bitset.h"
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "ortools/base/integral_types.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/macros.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/constraint_solveri.h"
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/strings/str_join.h"
|
||||
#include "ortools/base/commandlineflags.h"
|
||||
#include "ortools/base/integral_types.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/map_util.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/constraint_solveri.h"
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/strings/str_join.h"
|
||||
#include "ortools/base/hash.h"
|
||||
#include "ortools/base/integral_types.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/map_util.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/constraint_solveri.h"
|
||||
#include "ortools/util/bitset.h"
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "ortools/base/integral_types.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/macros.h"
|
||||
#include "ortools/base/map_util.h"
|
||||
#include "ortools/base/stl_util.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/constraint_solveri.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user