Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::bop::LocalSearchAssignmentIterator Class Reference

#include <bop_ls.h>

Public Member Functions

 LocalSearchAssignmentIterator (const ProblemState &problem_state, int max_num_decisions, int max_num_broken_constraints, absl::BitGenRef random, SatWrapper *sat_wrapper)
 
 LocalSearchAssignmentIterator (const LocalSearchAssignmentIterator &)=delete
 This type is neither copyable nor movable.
 
LocalSearchAssignmentIteratoroperator= (const LocalSearchAssignmentIterator &)=delete
 
 ~LocalSearchAssignmentIterator ()
 
void UseTranspositionTable (bool v)
 Parameters of the LS algorithm.
 
void UsePotentialOneFlipRepairs (bool v)
 
void Synchronize (const ProblemState &problem_state)
 
void SynchronizeSatWrapper ()
 
bool NextAssignment ()
 Move to the next assignment. Returns false when the search is finished.
 
const BopSolutionLastReferenceAssignment () const
 Returns the last feasible assignment.
 
bool BetterSolutionHasBeenFound () const
 
double deterministic_time () const
 
std::string DebugString () const
 

Detailed Description

This class is used to iterate on all assignments that can be obtained by deliberately flipping 'n' variables from the reference solution, 'n' being smaller than or equal to max_num_decisions.

Note
one deliberate variable flip may lead to many other flips due to constraint propagation, those additional flips are not counted in 'n'.

Definition at line 531 of file bop_ls.h.

Constructor & Destructor Documentation

◆ LocalSearchAssignmentIterator() [1/2]

operations_research::bop::LocalSearchAssignmentIterator::LocalSearchAssignmentIterator ( const ProblemState & problem_state,
int max_num_decisions,
int max_num_broken_constraints,
absl::BitGenRef random,
SatWrapper * sat_wrapper )

LocalSearchAssignmentIterator

Definition at line 715 of file bop_ls.cc.

◆ LocalSearchAssignmentIterator() [2/2]

operations_research::bop::LocalSearchAssignmentIterator::LocalSearchAssignmentIterator ( const LocalSearchAssignmentIterator & )
delete

This type is neither copyable nor movable.

◆ ~LocalSearchAssignmentIterator()

operations_research::bop::LocalSearchAssignmentIterator::~LocalSearchAssignmentIterator ( )

Definition at line 737 of file bop_ls.cc.

Member Function Documentation

◆ BetterSolutionHasBeenFound()

bool operations_research::bop::LocalSearchAssignmentIterator::BetterSolutionHasBeenFound ( ) const
inline

Returns true if the current assignment has a better solution than the one passed to the last Synchronize() call.

Definition at line 572 of file bop_ls.h.

◆ DebugString()

std::string operations_research::bop::LocalSearchAssignmentIterator::DebugString ( ) const

Definition at line 864 of file bop_ls.cc.

◆ deterministic_time()

double operations_research::bop::LocalSearchAssignmentIterator::deterministic_time ( ) const

Returns a deterministic number that should be correlated with the time spent in the iterator. The order of magnitude should be close to the time in seconds.

Todo
(user): The 1.2 multiplier is an approximation only based on the time spent in the SAT wrapper. So far experiments show a good correlation with real time, but we might want to be more accurate.

Definition at line 860 of file bop_ls.cc.

◆ LastReferenceAssignment()

const BopSolution & operations_research::bop::LocalSearchAssignmentIterator::LastReferenceAssignment ( ) const
inline

Returns the last feasible assignment.

Definition at line 566 of file bop_ls.h.

◆ NextAssignment()

bool operations_research::bop::LocalSearchAssignmentIterator::NextAssignment ( )

Move to the next assignment. Returns false when the search is finished.

We only look for potential one flip repairs if we reached the end of the LS tree. I tried to do that at every level, but it didn't change the result much on the set-partitionning example I was using.

Todo
(user): Perform more experiments with this.

Temporarily apply the potential repair and see if it worked!

If possible, go deeper, i.e. take one more decision.

If not, backtrack to the first node that still has untried way to fix its associated constraint. Update it to the next untried way.

All nodes have been explored.

Apply the next decision, i.e. the literal of the flipped variable.

Definition at line 801 of file bop_ls.cc.

◆ operator=()

LocalSearchAssignmentIterator & operations_research::bop::LocalSearchAssignmentIterator::operator= ( const LocalSearchAssignmentIterator & )
delete

◆ Synchronize()

void operations_research::bop::LocalSearchAssignmentIterator::Synchronize ( const ProblemState & problem_state)

Synchronizes the iterator with the problem state, e.g. set fixed variables, set the reference solution. Call this only when a new solution has been found. This will restart the LS.

Definition at line 746 of file bop_ls.cc.

◆ SynchronizeSatWrapper()

void operations_research::bop::LocalSearchAssignmentIterator::SynchronizeSatWrapper ( )

Synchronize the SatWrapper with our current search state. This needs to be called before calls to NextAssignment() if the underlying SatWrapper was used by someone else than this class.

In order to restore the synchronization from any state, we backtrack everything and retry to take the same decisions as before. We stop at the first one that can't be taken.

Note(user): at this stage, the sat trail contains the fixed variables. There will almost always be at the same value in the reference solution. However since the objective may be over-constrained in the sat_solver, it is possible that some variable where propagated to some other values.

Definition at line 762 of file bop_ls.cc.

◆ UsePotentialOneFlipRepairs()

void operations_research::bop::LocalSearchAssignmentIterator::UsePotentialOneFlipRepairs ( bool v)
inline

Definition at line 548 of file bop_ls.h.

◆ UseTranspositionTable()

void operations_research::bop::LocalSearchAssignmentIterator::UseTranspositionTable ( bool v)
inline

Parameters of the LS algorithm.

Definition at line 547 of file bop_ls.h.


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