Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
local_search.cc File Reference
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <limits>
#include <memory>
#include <numeric>
#include <optional>
#include <random>
#include <string>
#include <utility>
#include <vector>
#include "absl/algorithm/container.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/random/distributions.h"
#include "absl/random/random.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
#include "absl/types/span.h"
#include "ortools/base/iterator_adaptors.h"
#include "ortools/base/logging.h"
#include "ortools/base/map_util.h"
#include "ortools/base/strong_int.h"
#include "ortools/base/strong_vector.h"
#include "ortools/base/timer.h"
#include "ortools/constraint_solver/constraint_solver.h"
#include "ortools/constraint_solver/constraint_solveri.h"
#include "ortools/graph/hamiltonian_path.h"
#include "ortools/util/bitset.h"
#include "ortools/util/saturated_arithmetic.h"

Go to the source code of this file.

Classes

class  operations_research::TwoOpt
 --— 2Opt --— More...
 
class  operations_research::Relocate
 --— Relocate --— More...
 
class  operations_research::Exchange
 --— Exchange --— More...
 
class  operations_research::Cross
 --— Cross --— More...
 
class  operations_research::BaseInactiveNodeToPathOperator
 
class  operations_research::MakeActiveOperator
 --— MakeActiveOperator --— More...
 
class  operations_research::RelocateAndMakeActiveOperator
 -— RelocateAndMakeActiveOperator --— More...
 
class  operations_research::MakeActiveAndRelocate
 --— MakeActiveAndRelocate --— More...
 
class  operations_research::MakeInactiveOperator
 --— MakeInactiveOperator --— More...
 
class  operations_research::RelocateAndMakeInactiveOperator
 --— RelocateAndMakeInactiveOperator --— More...
 
class  operations_research::MakeChainInactiveOperator
 --— MakeChainInactiveOperator --— More...
 
class  operations_research::SwapActiveOperator
 --— SwapActiveOperator --— More...
 
class  operations_research::ExtendedSwapActiveOperator
 --— ExtendedSwapActiveOperator --— More...
 
class  operations_research::TSPOpt
 --— TSP-based operators --— More...
 
class  operations_research::TSPLns
 
class  operations_research::NearestNeighbors
 --— Lin Kernighan --— More...
 
class  operations_research::LinKernighan
 
class  operations_research::PathLns
 --— Path-based Large Neighborhood Search --— More...
 
class  operations_research::NeighborhoodLimit
 --— Limit the number of neighborhoods explored --— More...
 
class  operations_research::LocalSearchProfiler
 --— LocalSearchProfiler --— More...
 
class  operations_research::FindOneNeighbor
 --— Finds a neighbor of the assignment passed --— More...
 
class  operations_research::LocalSearchPhaseParameters
 -------— Local Search Phase Parameters -------— More...
 
class  operations_research::LocalSearch
 --— Local search decision builder --— More...
 
class  operations_research::DefaultSolutionPool
 

Namespaces

namespace  operations_research
 In SWIG mode, we don't want anything besides these top-level includes.
 

Macros

#define MAKE_LOCAL_SEARCH_OPERATOR(OperatorClass)
 
#define MAKE_LOCAL_SEARCH_OPERATOR_WITH_NEIGHBORS(OperatorClass)
 

Typedefs

using operations_research::VariableDomainId = LocalSearchState::VariableDomainId
 
using operations_research::NodeId = SubDagComputer::NodeId
 
using operations_research::ArcId = SubDagComputer::ArcId
 

Functions

 ABSL_FLAG (int, cp_local_search_sync_frequency, 16, "Frequency of checks for better solutions in the solution pool.")
 
 ABSL_FLAG (int, cp_local_search_tsp_opt_size, 13, "Size of TSPs solved in the TSPOpt operator.")
 
 ABSL_FLAG (int, cp_local_search_tsp_lns_size, 10, "Size of TSPs solved in the TSPLns operator.")
 
 ABSL_FLAG (bool, cp_use_empty_path_symmetry_breaker, true, "If true, equivalent empty paths are removed from the neighborhood " "of PathOperators")
 
bool operations_research::LocalOptimumReached (Search *search)
 Returns true if a local optimum has been reached and cannot be improved.
 
bool operations_research::AcceptDelta (Search *search, Assignment *delta, Assignment *deltadelta)
 
void operations_research::AcceptNeighbor (Search *search)
 Notifies the search that a neighbor has been accepted by local search.
 
void operations_research::AcceptUncheckedNeighbor (Search *search)
 
template<class T >
LocalSearchOperatoroperations_research::MakeLocalSearchOperator (Solver *solver, const std::vector< IntVar * > &vars, const std::vector< IntVar * > &secondary_vars, std::function< int(int64_t)> start_empty_path_class)
 Operator Factories.
 
template<class T >
LocalSearchOperatoroperations_research::MakeLocalSearchOperatorWithNeighbors (Solver *solver, const std::vector< IntVar * > &vars, const std::vector< IntVar * > &secondary_vars, std::function< int(int64_t)> start_empty_path_class, std::function< const std::vector< int > &(int, int)> get_neighbors)
 
LocalSearchFilteroperations_research::MakePathStateFilter (Solver *solver, std::unique_ptr< PathState > path_state, const std::vector< IntVar * > &nexts)
 
LocalSearchFilteroperations_research::MakeDimensionFilter (Solver *solver, std::unique_ptr< DimensionChecker > checker, const std::string &dimension_name)
 
void operations_research::InstallLocalSearchProfiler (LocalSearchProfiler *monitor)
 
LocalSearchProfileroperations_research::BuildLocalSearchProfiler (Solver *solver)
 
void operations_research::DeleteLocalSearchProfiler (LocalSearchProfiler *monitor)
 

Macro Definition Documentation

◆ MAKE_LOCAL_SEARCH_OPERATOR

#define MAKE_LOCAL_SEARCH_OPERATOR ( OperatorClass)
Value:
template <> \
LocalSearchOperator* MakeLocalSearchOperator<OperatorClass>( \
Solver * solver, const std::vector<IntVar*>& vars, \
const std::vector<IntVar*>& secondary_vars, \
std::function<int(int64_t)> start_empty_path_class) { \
return solver->RevAlloc(new OperatorClass( \
vars, secondary_vars, std::move(start_empty_path_class))); \
}

Definition at line 2444 of file local_search.cc.

◆ MAKE_LOCAL_SEARCH_OPERATOR_WITH_NEIGHBORS

#define MAKE_LOCAL_SEARCH_OPERATOR_WITH_NEIGHBORS ( OperatorClass)
Value:
template <> \
LocalSearchOperator* MakeLocalSearchOperatorWithNeighbors<OperatorClass>( \
Solver * solver, const std::vector<IntVar*>& vars, \
const std::vector<IntVar*>& secondary_vars, \
std::function<int(int64_t)> start_empty_path_class, \
std::function<const std::vector<int>&(int, int)> get_neighbors) { \
return solver->RevAlloc(new OperatorClass( \
vars, secondary_vars, std::move(start_empty_path_class), \
std::move(get_neighbors))); \
}

Definition at line 2454 of file local_search.cc.

Function Documentation

◆ ABSL_FLAG() [1/4]

ABSL_FLAG ( bool ,
cp_use_empty_path_symmetry_breaker ,
true ,
"If true,
equivalent empty paths are removed from the neighborhood " "of PathOperators"  )

◆ ABSL_FLAG() [2/4]

ABSL_FLAG ( int ,
cp_local_search_sync_frequency ,
16 ,
"Frequency of checks for better solutions in the solution pool."  )

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

◆ ABSL_FLAG() [3/4]

ABSL_FLAG ( int ,
cp_local_search_tsp_lns_size ,
10 ,
"Size of TSPs solved in the TSPLns operator."  )

◆ ABSL_FLAG() [4/4]

ABSL_FLAG ( int ,
cp_local_search_tsp_opt_size ,
13 ,
"Size of TSPs solved in the TSPOpt operator."  )

Variable Documentation

◆ arc

int arc

Definition at line 2839 of file local_search.cc.

◆ delta_costs_

std::vector<int64_t> delta_costs_
protected

Definition at line 3563 of file local_search.cc.

◆ delta_sum_

int64_t delta_sum_
protected

Definition at line 3566 of file local_search.cc.

◆ filter_

Filter filter_
protected

Definition at line 3564 of file local_search.cc.

◆ head_index

int head_index

Definition at line 2835 of file local_search.cc.

◆ incremental_

bool incremental_
protected

Definition at line 3567 of file local_search.cc.

◆ index

int index

Definition at line 2838 of file local_search.cc.

◆ primary_vars_size_

const int primary_vars_size_
protected

Definition at line 3561 of file local_search.cc.

◆ synchronized_costs_

std::vector<int64_t> synchronized_costs_
protected

Definition at line 3562 of file local_search.cc.

◆ synchronized_sum_

int64_t synchronized_sum_
protected

Definition at line 3565 of file local_search.cc.

◆ tail_index

int tail_index

Definition at line 2834 of file local_search.cc.