Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::SavingsFilteredHeuristic::SavingsContainer< S > Class Template Reference

Public Member Functions

 SavingsContainer (const SavingsFilteredHeuristic *savings_db, int vehicle_types)
 
void InitializeContainer (int64_t size, int64_t saving_neighbors)
 
void AddNewSaving (const Saving &saving, int64_t total_cost, int64_t before_node, int64_t after_node, int vehicle_type)
 
void Sort ()
 
bool HasSaving ()
 
Saving GetSaving ()
 
void Update (bool update_best_saving, int type=-1)
 
void UpdateWithType (int type)
 
const std::vector< Saving > & GetSortedSavingsForVehicleType (int type)
 
void ReinjectSkippedSavingsStartingAt (int64_t node)
 
void ReinjectSkippedSavingsEndingAt (int64_t node)
 

Detailed Description

template<typename S>
class operations_research::SavingsFilteredHeuristic::SavingsContainer< S >

Class storing and allowing access to the savings according to the number of vehicle types. The savings are stored and sorted in sorted_savings_per_vehicle_type_. Furthermore, when there is more than one vehicle type, the savings for a same before-->after arc are sorted in costs_and_savings_per_arc_[arc] by increasing cost(s-->before-->after-->e), where s and e are the start and end of the route, in order to make sure the arc is served by the route with the closest depot (start/end) possible. When there is only one vehicle "type" (i.e. all vehicles have the same start/end and cost class), each arc has a single saving value associated to it, so we ignore this last step to avoid unnecessary computations, and only work with sorted_savings_per_vehicle_type_[0]. In case of multiple vehicle types, the best savings for each arc, i.e. the savings corresponding to the closest vehicle type, are inserted and sorted in sorted_savings_.

This class also handles skipped Savings: The vectors skipped_savings_starting/ending_at_ contain all the Savings that weren't added to the model, which we want to consider for later: 1) When a Saving before-->after with both nodes uncontained cannot be used to start a new route (no more available vehicles or could not commit on any of those available). 2) When only one of the nodes of the Saving is contained but on a different vehicle type. In these cases, the Update() method is called with update_best_saving = true, which in turn calls SkipSavingForArc() (within UpdateNextAndSkippedSavingsForArcWithType()) to mark the Saving for this arc (with the correct type in the second case) as "skipped", by storing it in skipped_savings_starting_at_[before] and skipped_savings_ending_at_[after].

UpdateNextAndSkippedSavingsForArcWithType() also updates the next_savings_ vector, which stores the savings to go through once we've iterated through all sorted_savings_. In the first case above, where neither nodes are contained, we skip the current Saving (current_saving_), and add the next best Saving for this arc to next_savings_ (in case this skipped Saving is never considered). In the second case with a specific type, we search for the Saving with the correct type for this arc, and add it to both next_savings_ and the skipped Savings.

The skipped Savings are then re-considered when one of their ends gets inserted: When another Saving other_node-->before (or after-->other_node) gets inserted, all skipped Savings in skipped_savings_starting_at_[before] (or skipped_savings_ending_at_[after]) are once again considered by calling ReinjectSkippedSavingsStartingAt() (or ReinjectSkippedSavingsEndingAt()). Then, when calling GetSaving(), we iterate through the reinjected Savings in order of insertion in the vectors while there are reinjected savings.

Definition at line 1283 of file routing_search.h.

Constructor & Destructor Documentation

◆ SavingsContainer()

template<typename S >
operations_research::SavingsFilteredHeuristic::SavingsContainer< S >::SavingsContainer ( const SavingsFilteredHeuristic * savings_db,
int vehicle_types )
inlineexplicit

Definition at line 3133 of file routing_search.cc.

Member Function Documentation

◆ AddNewSaving()

template<typename S >
void operations_research::SavingsFilteredHeuristic::SavingsContainer< S >::AddNewSaving ( const Saving & saving,
int64_t total_cost,
int64_t before_node,
int64_t after_node,
int vehicle_type )
inline

Definition at line 3171 of file routing_search.cc.

◆ GetSaving()

template<typename S >
Saving operations_research::SavingsFilteredHeuristic::SavingsContainer< S >::GetSaving ( )
inline

Get the best Saving among the two.

Definition at line 3238 of file routing_search.cc.

◆ GetSortedSavingsForVehicleType()

template<typename S >
const std::vector< Saving > & operations_research::SavingsFilteredHeuristic::SavingsContainer< S >::GetSortedSavingsForVehicleType ( int type)
inline

Definition at line 3303 of file routing_search.cc.

◆ HasSaving()

template<typename S >
bool operations_research::SavingsFilteredHeuristic::SavingsContainer< S >::HasSaving ( )
inline

Definition at line 3233 of file routing_search.cc.

◆ InitializeContainer()

template<typename S >
void operations_research::SavingsFilteredHeuristic::SavingsContainer< S >::InitializeContainer ( int64_t size,
int64_t saving_neighbors )
inline

Definition at line 3143 of file routing_search.cc.

◆ ReinjectSkippedSavingsEndingAt()

template<typename S >
void operations_research::SavingsFilteredHeuristic::SavingsContainer< S >::ReinjectSkippedSavingsEndingAt ( int64_t node)
inline

Definition at line 3314 of file routing_search.cc.

◆ ReinjectSkippedSavingsStartingAt()

template<typename S >
void operations_research::SavingsFilteredHeuristic::SavingsContainer< S >::ReinjectSkippedSavingsStartingAt ( int64_t node)
inline

Definition at line 3309 of file routing_search.cc.

◆ Sort()

template<typename S >
void operations_research::SavingsFilteredHeuristic::SavingsContainer< S >::Sort ( )
inline

For each arc, sort the savings by decreasing total cost start-->a-->b-->end. The best saving for each arc is therefore the last of its vector.

Insert all Savings for this arc with the lowest cost into sorted_savings_.

Todo
(user): Also do this when reiterating on next_savings_.

Definition at line 3180 of file routing_search.cc.

◆ Update()

template<typename S >
void operations_research::SavingsFilteredHeuristic::SavingsContainer< S >::Update ( bool update_best_saving,
int type = -1 )
inline

Definition at line 3274 of file routing_search.cc.

◆ UpdateWithType()

template<typename S >
void operations_research::SavingsFilteredHeuristic::SavingsContainer< S >::UpdateWithType ( int type)
inline

Definition at line 3298 of file routing_search.cc.


The documentation for this class was generated from the following files: