OR-Tools  8.2
SolutionCollector

Detailed Description

This class is the root class of all solution collectors.

It implements a basic query API to be used independently of the collector used.

Definition at line 4101 of file constraint_solver.h.

Classes

struct  SolutionData
 

Public Member Functions

 SolutionCollector (Solver *const solver, const Assignment *assignment)
 
 SolutionCollector (Solver *const solver)
 
 ~SolutionCollector () override
 
std::string DebugString () const override
 
void Add (IntVar *const var)
 Add API. More...
 
void Add (const std::vector< IntVar * > &vars)
 
void Add (IntervalVar *const var)
 
void Add (const std::vector< IntervalVar * > &vars)
 
void Add (SequenceVar *const var)
 
void Add (const std::vector< SequenceVar * > &vars)
 
void AddObjective (IntVar *const objective)
 
void EnterSearch () override
 Beginning of the search. More...
 
int solution_count () const
 Returns how many solutions were stored during the search. More...
 
Assignmentsolution (int n) const
 Returns the nth solution. More...
 
int64 wall_time (int n) const
 Returns the wall time in ms for the nth solution. More...
 
int64 branches (int n) const
 Returns the number of branches when the nth solution was found. More...
 
int64 failures (int n) const
 Returns the number of failures encountered at the time of the nth solution. More...
 
int64 objective_value (int n) const
 Returns the objective value of the nth solution. More...
 
int64 Value (int n, IntVar *const var) const
 This is a shortcut to get the Value of 'var' in the nth solution. More...
 
int64 StartValue (int n, IntervalVar *const var) const
 This is a shortcut to get the StartValue of 'var' in the nth solution. More...
 
int64 EndValue (int n, IntervalVar *const var) const
 This is a shortcut to get the EndValue of 'var' in the nth solution. More...
 
int64 DurationValue (int n, IntervalVar *const var) const
 This is a shortcut to get the DurationValue of 'var' in the nth solution. More...
 
int64 PerformedValue (int n, IntervalVar *const var) const
 This is a shortcut to get the PerformedValue of 'var' in the nth solution. More...
 
const std::vector< int > & ForwardSequence (int n, SequenceVar *const var) const
 This is a shortcut to get the ForwardSequence of 'var' in the nth solution. More...
 
const std::vector< int > & BackwardSequence (int n, SequenceVar *const var) const
 This is a shortcut to get the BackwardSequence of 'var' in the nth solution. More...
 
const std::vector< int > & Unperformed (int n, SequenceVar *const var) const
 This is a shortcut to get the list of unperformed of 'var' in the nth solution. More...
 
virtual void RestartSearch ()
 Restart the search. More...
 
virtual void ExitSearch ()
 End of the search. More...
 
virtual void BeginNextDecision (DecisionBuilder *const b)
 Before calling DecisionBuilder::Next. More...
 
virtual void EndNextDecision (DecisionBuilder *const b, Decision *const d)
 After calling DecisionBuilder::Next, along with the returned decision. More...
 
virtual void ApplyDecision (Decision *const d)
 Before applying the decision. More...
 
virtual void RefuteDecision (Decision *const d)
 Before refuting the decision. More...
 
virtual void AfterDecision (Decision *const d, bool apply)
 Just after refuting or applying the decision, apply is true after Apply. More...
 
virtual void BeginFail ()
 Just when the failure occurs. More...
 
virtual void EndFail ()
 After completing the backtrack. More...
 
virtual void BeginInitialPropagation ()
 Before the initial propagation. More...
 
virtual void EndInitialPropagation ()
 After the initial propagation. More...
 
virtual bool AcceptSolution ()
 This method is called when a solution is found. More...
 
virtual bool AtSolution ()
 This method is called when a valid solution is found. More...
 
virtual void NoMoreSolutions ()
 When the search tree is finished. More...
 
virtual bool LocalOptimum ()
 When a local optimum is reached. More...
 
virtual bool AcceptDelta (Assignment *delta, Assignment *deltadelta)
 
virtual void AcceptNeighbor ()
 After accepting a neighbor during local search. More...
 
virtual void AcceptUncheckedNeighbor ()
 After accepting an unchecked neighbor during local search. More...
 
virtual bool IsUncheckedSolutionLimitReached ()
 Returns true if the limit of solutions has been reached including unchecked solutions. More...
 
Solversolver () const
 
virtual void PeriodicCheck ()
 Periodic call to check limits in long running methods. More...
 
virtual int ProgressPercent ()
 Returns a percentage representing the propress of the search before reaching limits. More...
 
virtual void Accept (ModelVisitor *const visitor) const
 Accepts the given model visitor. More...
 
virtual void Install ()
 Registers itself on the solver such that it gets notified of the search and propagation events. More...
 

Static Public Attributes

static constexpr int kNoProgress = -1
 

Protected Member Functions

void PushSolution ()
 Push the current state as a new solution. More...
 
void Push (const SolutionData &data)
 
void PopSolution ()
 Remove and delete the last popped solution. More...
 
SolutionData BuildSolutionDataForCurrentState ()
 
void FreeSolution (Assignment *solution)
 
void check_index (int n) const
 

Protected Attributes

std::unique_ptr< Assignmentprototype_
 
std::vector< SolutionDatasolution_data_
 
std::vector< Assignment * > recycle_solutions_
 

Constructor & Destructor Documentation

◆ SolutionCollector() [1/2]

SolutionCollector ( Solver *const  solver,
const Assignment assignment 
)

Definition at line 2205 of file search.cc.

◆ SolutionCollector() [2/2]

SolutionCollector ( Solver *const  solver)
explicit

Definition at line 2211 of file search.cc.

◆ ~SolutionCollector()

~SolutionCollector ( )
override

Definition at line 2214 of file search.cc.

Member Function Documentation

◆ Accept()

void Accept ( ModelVisitor *const  visitor) const
virtualinherited

Accepts the given model visitor.

Reimplemented in RegularLimit, and OptimizeVar.

Definition at line 2890 of file constraint_solver.cc.

◆ AcceptDelta()

bool AcceptDelta ( Assignment delta,
Assignment deltadelta 
)
virtualinherited

Reimplemented in OptimizeVar.

Definition at line 2884 of file constraint_solver.cc.

◆ AcceptNeighbor()

void AcceptNeighbor ( )
virtualinherited

After accepting a neighbor during local search.

Definition at line 2887 of file constraint_solver.cc.

◆ AcceptSolution()

bool AcceptSolution ( )
virtualinherited

This method is called when a solution is found.

It asserts whether the solution is valid. A value of false indicates that the solution should be discarded.

Reimplemented in OptimizeVar.

Definition at line 2880 of file constraint_solver.cc.

◆ AcceptUncheckedNeighbor()

void AcceptUncheckedNeighbor ( )
virtualinherited

After accepting an unchecked neighbor during local search.

Reimplemented in SearchLog.

Definition at line 2888 of file constraint_solver.cc.

◆ Add() [1/6]

void Add ( const std::vector< IntervalVar * > &  vars)

Definition at line 2239 of file search.cc.

◆ Add() [2/6]

void Add ( const std::vector< IntVar * > &  vars)

Definition at line 2227 of file search.cc.

◆ Add() [3/6]

void Add ( const std::vector< SequenceVar * > &  vars)

Definition at line 2251 of file search.cc.

◆ Add() [4/6]

void Add ( IntervalVar *const  var)

Definition at line 2233 of file search.cc.

◆ Add() [5/6]

void Add ( IntVar *const  var)

Add API.

Definition at line 2221 of file search.cc.

◆ Add() [6/6]

void Add ( SequenceVar *const  var)

Definition at line 2245 of file search.cc.

◆ AddObjective()

void AddObjective ( IntVar *const  objective)

Definition at line 2257 of file search.cc.

◆ AfterDecision()

void AfterDecision ( Decision *const  d,
bool  apply 
)
virtualinherited

Just after refuting or applying the decision, apply is true after Apply.

This is called only if the Apply() or Refute() methods have not failed.

Definition at line 2875 of file constraint_solver.cc.

◆ ApplyDecision()

void ApplyDecision ( Decision *const  d)
virtualinherited

Before applying the decision.

Reimplemented in SearchLog.

Definition at line 2873 of file constraint_solver.cc.

◆ AtSolution()

bool AtSolution ( )
virtualinherited

This method is called when a valid solution is found.

If the return value is true, then search will resume after. If the result is false, then search will stop there.

Reimplemented in SearchLog, ImprovementSearchLimit, and OptimizeVar.

Definition at line 2881 of file constraint_solver.cc.

◆ BackwardSequence()

const std::vector< int > & BackwardSequence ( int  n,
SequenceVar *const  var 
) const

This is a shortcut to get the BackwardSequence of 'var' in the nth solution.

The backward sequence is the list of ranked interval variables starting from the end of the sequence.

Definition at line 2372 of file search.cc.

◆ BeginFail()

void BeginFail ( )
virtualinherited

Just when the failure occurs.

Reimplemented in DemonProfiler, and SearchLog.

Definition at line 2876 of file constraint_solver.cc.

◆ BeginInitialPropagation()

void BeginInitialPropagation ( )
virtualinherited

Before the initial propagation.

Reimplemented in SearchLog.

Definition at line 2878 of file constraint_solver.cc.

◆ BeginNextDecision()

void BeginNextDecision ( DecisionBuilder *const  b)
virtualinherited

Before calling DecisionBuilder::Next.

Reimplemented in OptimizeVar, and SearchLimit.

Definition at line 2870 of file constraint_solver.cc.

◆ branches()

int64 branches ( int  n) const

Returns the number of branches when the nth solution was found.

Definition at line 2332 of file search.cc.

◆ BuildSolutionDataForCurrentState()

SolutionCollector::SolutionData BuildSolutionDataForCurrentState ( )
protected

Definition at line 2284 of file search.cc.

◆ check_index()

void check_index ( int  n) const
protected

Definition at line 2315 of file search.cc.

◆ DebugString()

std::string DebugString ( ) const
inlineoverridevirtual

Reimplemented from BaseObject.

Definition at line 4106 of file constraint_solver.h.

◆ DurationValue()

int64 DurationValue ( int  n,
IntervalVar *const  var 
) const

This is a shortcut to get the DurationValue of 'var' in the nth solution.

Definition at line 2355 of file search.cc.

◆ EndFail()

void EndFail ( )
virtualinherited

After completing the backtrack.

Definition at line 2877 of file constraint_solver.cc.

◆ EndInitialPropagation()

void EndInitialPropagation ( )
virtualinherited

After the initial propagation.

Reimplemented in SearchLog.

Definition at line 2879 of file constraint_solver.cc.

◆ EndNextDecision()

void EndNextDecision ( DecisionBuilder *const  b,
Decision *const  d 
)
virtualinherited

After calling DecisionBuilder::Next, along with the returned decision.

Reimplemented in SymmetryManager.

Definition at line 2871 of file constraint_solver.cc.

◆ EndValue()

int64 EndValue ( int  n,
IntervalVar *const  var 
) const

This is a shortcut to get the EndValue of 'var' in the nth solution.

Definition at line 2359 of file search.cc.

◆ EnterSearch()

void EnterSearch ( )
overridevirtual

Beginning of the search.

Reimplemented from SearchMonitor.

Definition at line 2263 of file search.cc.

◆ ExitSearch()

void ExitSearch ( )
virtualinherited

End of the search.

Reimplemented in LocalSearchProfiler, SearchLog, and RegularLimit.

Definition at line 2869 of file constraint_solver.cc.

◆ failures()

int64 failures ( int  n) const

Returns the number of failures encountered at the time of the nth solution.

Definition at line 2337 of file search.cc.

◆ ForwardSequence()

const std::vector< int > & ForwardSequence ( int  n,
SequenceVar *const  var 
) const

This is a shortcut to get the ForwardSequence of 'var' in the nth solution.

The forward sequence is the list of ranked interval variables starting from the start of the sequence.

Definition at line 2367 of file search.cc.

◆ FreeSolution()

void FreeSolution ( Assignment solution)
protected

Definition at line 2309 of file search.cc.

◆ Install()

void Install ( )
virtualinherited

Registers itself on the solver such that it gets notified of the search and propagation events.

Reimplemented in LocalSearchProfiler, DemonProfiler, LocalSearchMonitor, PropagationMonitor, LocalSearchMonitorMaster, and Trace.

Definition at line 2892 of file constraint_solver.cc.

◆ IsUncheckedSolutionLimitReached()

virtual bool IsUncheckedSolutionLimitReached ( )
inlinevirtualinherited

Returns true if the limit of solutions has been reached including unchecked solutions.

Reimplemented in RegularLimit.

Definition at line 3706 of file constraint_solver.h.

◆ LocalOptimum()

bool LocalOptimum ( )
virtualinherited

When a local optimum is reached.

If 'true' is returned, the last solution is discarded and the search proceeds with the next one.

Definition at line 2883 of file constraint_solver.cc.

◆ NoMoreSolutions()

void NoMoreSolutions ( )
virtualinherited

When the search tree is finished.

Reimplemented in SearchLog.

Definition at line 2882 of file constraint_solver.cc.

◆ objective_value()

int64 objective_value ( int  n) const

Returns the objective value of the nth solution.

Definition at line 2342 of file search.cc.

◆ PerformedValue()

int64 PerformedValue ( int  n,
IntervalVar *const  var 
) const

This is a shortcut to get the PerformedValue of 'var' in the nth solution.

Definition at line 2363 of file search.cc.

◆ PeriodicCheck()

void PeriodicCheck ( )
virtualinherited

Periodic call to check limits in long running methods.

Reimplemented in SearchLimit.

Definition at line 2889 of file constraint_solver.cc.

◆ PopSolution()

void PopSolution ( )
protected

Remove and delete the last popped solution.

Definition at line 2276 of file search.cc.

◆ ProgressPercent()

virtual int ProgressPercent ( )
inlinevirtualinherited

Returns a percentage representing the propress of the search before reaching limits.

Reimplemented in RegularLimit.

Definition at line 3715 of file constraint_solver.h.

◆ Push()

void Push ( const SolutionData data)
inlineprotected

Definition at line 4182 of file constraint_solver.h.

◆ PushSolution()

void PushSolution ( )
protected

Push the current state as a new solution.

Definition at line 2272 of file search.cc.

◆ RefuteDecision()

void RefuteDecision ( Decision *const  d)
virtualinherited

Before refuting the decision.

Reimplemented in SymmetryManager, SearchLog, SearchLimit, and OptimizeVar.

Definition at line 2874 of file constraint_solver.cc.

◆ RestartSearch()

void RestartSearch ( )
virtualinherited

Restart the search.

Reimplemented in LocalSearchProfiler, and DemonProfiler.

Definition at line 2868 of file constraint_solver.cc.

◆ solution()

Assignment * solution ( int  n) const

Returns the nth solution.

Definition at line 2320 of file search.cc.

◆ solution_count()

int solution_count ( ) const

Returns how many solutions were stored during the search.

Definition at line 2325 of file search.cc.

◆ solver()

Solver* solver ( ) const
inlineinherited

Definition at line 3708 of file constraint_solver.h.

◆ StartValue()

int64 StartValue ( int  n,
IntervalVar *const  var 
) const

This is a shortcut to get the StartValue of 'var' in the nth solution.

Definition at line 2351 of file search.cc.

◆ Unperformed()

const std::vector< int > & Unperformed ( int  n,
SequenceVar *const  var 
) const

This is a shortcut to get the list of unperformed of 'var' in the nth solution.

Definition at line 2377 of file search.cc.

◆ Value()

int64 Value ( int  n,
IntVar *const  var 
) const

This is a shortcut to get the Value of 'var' in the nth solution.

Definition at line 2347 of file search.cc.

◆ wall_time()

int64 wall_time ( int  n) const

Returns the wall time in ms for the nth solution.

Definition at line 2327 of file search.cc.

Member Data Documentation

◆ kNoProgress

constexpr int kNoProgress = -1
staticconstexprinherited

Definition at line 3637 of file constraint_solver.h.

◆ prototype_

std::unique_ptr<Assignment> prototype_
protected

Definition at line 4189 of file constraint_solver.h.

◆ recycle_solutions_

std::vector<Assignment*> recycle_solutions_
protected

Definition at line 4191 of file constraint_solver.h.

◆ solution_data_

std::vector<SolutionData> solution_data_
protected

Definition at line 4190 of file constraint_solver.h.


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