OR-Tools  9.1
OptimizeVar

Detailed Description

This class encapsulates an objective.

It requires the direction (minimize or maximize), the variable to optimize, and the improvement step.

Definition at line 4208 of file constraint_solver.h.

Public Member Functions

 OptimizeVar (Solver *const s, bool maximize, IntVar *const a, int64_t step)
 
 ~OptimizeVar () override
 
int64_t best () const
 Returns the best value found during search. More...
 
IntVarVar () const
 Returns the variable that is optimized. More...
 
bool AcceptDelta (Assignment *delta, Assignment *deltadelta) override
 Internal methods. More...
 
void EnterSearch () override
 Beginning of the search. More...
 
void BeginNextDecision (DecisionBuilder *const db) override
 Before calling DecisionBuilder::Next. More...
 
void RefuteDecision (Decision *const d) override
 Before refuting the decision. More...
 
bool AtSolution () override
 This method is called when a valid solution is found. More...
 
bool AcceptSolution () override
 This method is called when a solution is found. More...
 
virtual std::string Print () const
 
std::string DebugString () const override
 
void Accept (ModelVisitor *const visitor) const override
 Accepts the given model visitor. More...
 
void ApplyBound ()
 
virtual void RestartSearch ()
 Restart the search. More...
 
virtual void ExitSearch ()
 End of the search. 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 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 void NoMoreSolutions ()
 When the search tree is finished. More...
 
virtual bool LocalOptimum ()
 When a local optimum is reached. More...
 
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 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 Attributes

IntVar *const var_
 
int64_t step_
 
int64_t best_
 
bool maximize_
 
bool found_initial_solution_
 

Constructor & Destructor Documentation

◆ OptimizeVar()

OptimizeVar ( Solver *const  s,
bool  maximize,
IntVar *const  a,
int64_t  step 
)

Definition at line 2729 of file search.cc.

◆ ~OptimizeVar()

~OptimizeVar ( )
override

Definition at line 2748 of file search.cc.

Member Function Documentation

◆ Accept()

void Accept ( ModelVisitor *const  visitor) const
overridevirtual

Accepts the given model visitor.

Reimplemented from SearchMonitor.

Reimplemented in SwigDirector_OptimizeVar.

Definition at line 2854 of file search.cc.

◆ AcceptDelta()

bool AcceptDelta ( Assignment delta,
Assignment deltadelta 
)
overridevirtual

Internal methods.

Reimplemented from SearchMonitor.

Reimplemented in SwigDirector_OptimizeVar.

Definition at line 2802 of file search.cc.

◆ AcceptNeighbor()

void AcceptNeighbor ( )
virtualinherited

◆ AcceptSolution()

bool AcceptSolution ( )
overridevirtual

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 from SearchMonitor.

Reimplemented in SwigDirector_OptimizeVar.

Definition at line 2777 of file search.cc.

◆ AcceptUncheckedNeighbor()

void AcceptUncheckedNeighbor ( )
virtualinherited

◆ 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.

Reimplemented in SwigDirector_RegularLimit, SwigDirector_SearchLimit, SwigDirector_SearchMonitor, SwigDirector_OptimizeVar, SwigDirector_SolutionCollector, SwigDirector_SearchMonitor, and SwigDirector_SearchMonitor.

Definition at line 2880 of file constraint_solver.cc.

◆ ApplyBound()

void ApplyBound ( )

Definition at line 2765 of file search.cc.

◆ ApplyDecision()

void ApplyDecision ( Decision *const  d)
virtualinherited

◆ AtSolution()

bool AtSolution ( )
overridevirtual

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 from SearchMonitor.

Reimplemented in SwigDirector_OptimizeVar.

Definition at line 2789 of file search.cc.

◆ BeginFail()

◆ BeginInitialPropagation()

void BeginInitialPropagation ( )
virtualinherited

◆ BeginNextDecision()

void BeginNextDecision ( DecisionBuilder *const  b)
overridevirtual

Before calling DecisionBuilder::Next.

Reimplemented from SearchMonitor.

Reimplemented in SwigDirector_OptimizeVar.

Definition at line 2759 of file search.cc.

◆ best()

int64_t best ( ) const
inline

Returns the best value found during search.

Definition at line 4214 of file constraint_solver.h.

◆ DebugString()

std::string DebugString ( ) const
overridevirtual

Reimplemented from BaseObject.

Reimplemented in SwigDirector_OptimizeVar.

Definition at line 2842 of file search.cc.

◆ EndFail()

◆ EndInitialPropagation()

void EndInitialPropagation ( )
virtualinherited

◆ EndNextDecision()

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

◆ EnterSearch()

void EnterSearch ( )
overridevirtual

Beginning of the search.

Reimplemented from SearchMonitor.

Reimplemented in SwigDirector_OptimizeVar.

Definition at line 2750 of file search.cc.

◆ ExitSearch()

◆ Install()

void Install ( )
virtualinherited

◆ IsUncheckedSolutionLimitReached()

virtual bool IsUncheckedSolutionLimitReached ( )
inlinevirtualinherited

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

Reimplemented in RegularLimit, SwigDirector_RegularLimit, SwigDirector_SearchLimit, SwigDirector_SearchMonitor, SwigDirector_OptimizeVar, SwigDirector_SolutionCollector, SwigDirector_SearchMonitor, and SwigDirector_SearchMonitor.

Definition at line 3709 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.

Reimplemented in SwigDirector_RegularLimit, SwigDirector_SearchLimit, SwigDirector_SearchMonitor, SwigDirector_OptimizeVar, SwigDirector_SolutionCollector, SwigDirector_SearchMonitor, and SwigDirector_SearchMonitor.

Definition at line 2888 of file constraint_solver.cc.

◆ NoMoreSolutions()

void NoMoreSolutions ( )
virtualinherited

◆ PeriodicCheck()

void PeriodicCheck ( )
virtualinherited

◆ Print()

std::string Print ( ) const
virtual

Reimplemented in SwigDirector_OptimizeVar.

Definition at line 2838 of file search.cc.

◆ ProgressPercent()

virtual int ProgressPercent ( )
inlinevirtualinherited

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

Reimplemented in RegularLimit, SwigDirector_RegularLimit, SwigDirector_SearchLimit, SwigDirector_SearchMonitor, SwigDirector_OptimizeVar, SwigDirector_SolutionCollector, SwigDirector_SearchMonitor, and SwigDirector_SearchMonitor.

Definition at line 3718 of file constraint_solver.h.

◆ RefuteDecision()

void RefuteDecision ( Decision *const  d)
overridevirtual

Before refuting the decision.

Reimplemented from SearchMonitor.

Reimplemented in SwigDirector_OptimizeVar.

Definition at line 2775 of file search.cc.

◆ RestartSearch()

◆ solver()

Solver* solver ( ) const
inlineinherited

Definition at line 3711 of file constraint_solver.h.

◆ Var()

IntVar* Var ( ) const
inline

Returns the variable that is optimized.

Definition at line 4217 of file constraint_solver.h.

Member Data Documentation

◆ best_

int64_t best_
protected

Definition at line 4234 of file constraint_solver.h.

◆ found_initial_solution_

bool found_initial_solution_
protected

Definition at line 4236 of file constraint_solver.h.

◆ kNoProgress

constexpr int kNoProgress = -1
staticinherited

Definition at line 3640 of file constraint_solver.h.

◆ maximize_

bool maximize_
protected

Definition at line 4235 of file constraint_solver.h.

◆ step_

int64_t step_
protected

Definition at line 4233 of file constraint_solver.h.

◆ var_

IntVar* const var_
protected

Definition at line 4232 of file constraint_solver.h.


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