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

#include <constraint_solver.h>

Inheritance diagram for operations_research::OptimizeVar:
operations_research::ObjectiveMonitor operations_research::SearchMonitor operations_research::BaseObject

Public Member Functions

 OptimizeVar (Solver *solver, bool maximize, IntVar *var, int64_t step)
 
 OptimizeVar (Solver *solver, const std::vector< bool > &maximize, std::vector< IntVar * > vars, std::vector< int64_t > steps)
 
 ~OptimizeVar () override
 
int64_t best () const
 Returns the best value found during search.
 
IntVarvar () const
 Returns the variable that is optimized.
 
void BeginNextDecision (DecisionBuilder *db) override
 Internal methods.
 
void RefuteDecision (Decision *d) override
 Before refuting the decision.
 
bool AtSolution () override
 
bool AcceptSolution () override
 
virtual std::string Name () const
 
std::string DebugString () const override
 
void ApplyBound ()
 
- Public Member Functions inherited from operations_research::ObjectiveMonitor
 ObjectiveMonitor (Solver *solver, const std::vector< bool > &maximize, std::vector< IntVar * > vars, std::vector< int64_t > steps)
 -------— Objective Management -------—
 
 ~ObjectiveMonitor () override
 
 ObjectiveMonitor (const ObjectiveMonitor &)=delete
 
ObjectiveMonitoroperator= (const ObjectiveMonitor &)=delete
 
IntVarObjectiveVar (int index) const
 
IntVarMinimizationVar (int index) const
 
int64_t Step (int index) const
 
bool Maximize (int index) const
 
int64_t BestValue (int index) const
 
int Size () const
 
void EnterSearch () override
 Beginning of the search.
 
bool AcceptDelta (Assignment *delta, Assignment *deltadelta) override
 
void Accept (ModelVisitor *visitor) const override
 Accepts the given model visitor.
 
- Public Member Functions inherited from operations_research::SearchMonitor
 SearchMonitor (Solver *const s)
 
 SearchMonitor (const SearchMonitor &)=delete
 This type is neither copyable nor movable.
 
SearchMonitoroperator= (const SearchMonitor &)=delete
 
 ~SearchMonitor () override
 
virtual void RestartSearch ()
 Restart the search.
 
virtual void ExitSearch ()
 End of the search.
 
virtual void EndNextDecision (DecisionBuilder *b, Decision *d)
 After calling DecisionBuilder::Next, along with the returned decision.
 
virtual void ApplyDecision (Decision *d)
 Before applying the decision.
 
virtual void AfterDecision (Decision *d, bool apply)
 
virtual void BeginFail ()
 Just when the failure occurs.
 
virtual void EndFail ()
 After completing the backtrack.
 
virtual void BeginInitialPropagation ()
 Before the initial propagation.
 
virtual void EndInitialPropagation ()
 After the initial propagation.
 
virtual void NoMoreSolutions ()
 When the search tree is finished.
 
virtual bool LocalOptimum ()
 
virtual void AcceptNeighbor ()
 After accepting a neighbor during local search.
 
virtual void AcceptUncheckedNeighbor ()
 After accepting an unchecked neighbor during local search.
 
virtual bool IsUncheckedSolutionLimitReached ()
 
virtual void PeriodicCheck ()
 Periodic call to check limits in long running methods.
 
virtual int ProgressPercent ()
 
virtual void Install ()
 A search monitors adds itself on the active search.
 
Solversolver () const
 
- Public Member Functions inherited from operations_research::BaseObject
 BaseObject ()
 
 BaseObject (const BaseObject &)=delete
 This type is neither copyable nor movable.
 
BaseObjectoperator= (const BaseObject &)=delete
 
virtual ~BaseObject ()
 

Additional Inherited Members

- Static Public Attributes inherited from operations_research::SearchMonitor
static constexpr int kNoProgress = -1
 
- Protected Member Functions inherited from operations_research::ObjectiveMonitor
const std::vector< IntVar * > & objective_vars () const
 
const std::vector< IntVar * > & minimization_vars () const
 
int64_t BestInternalValue (int index) const
 
int64_t CurrentInternalValue (int index) const
 
void SetCurrentInternalValue (int index, int64_t value)
 
template<typename T >
void MakeMinimizationVarsLessOrEqualWithSteps (const T &upper_bounds)
 
template<typename T >
IntVarMakeMinimizationVarsLessOrEqualWithStepsStatus (const T &upper_bounds)
 
bool CurrentInternalValuesAreConstraining () const
 
- Protected Member Functions inherited from operations_research::SearchMonitor
void ListenToEvent (Solver::MonitorEvent event)
 
- Protected Attributes inherited from operations_research::ObjectiveMonitor
bool found_initial_solution_
 

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 4584 of file constraint_solver.h.

Constructor & Destructor Documentation

◆ OptimizeVar() [1/2]

operations_research::OptimizeVar::OptimizeVar ( Solver * solver,
bool maximize,
IntVar * var,
int64_t step )

Definition at line 3068 of file search.cc.

◆ OptimizeVar() [2/2]

operations_research::OptimizeVar::OptimizeVar ( Solver * solver,
const std::vector< bool > & maximize,
std::vector< IntVar * > vars,
std::vector< int64_t > steps )

Specifies a lexicographic objective. Each objective is specified in decreasing order with the corresponding direction and step.

Definition at line 3073 of file search.cc.

◆ ~OptimizeVar()

operations_research::OptimizeVar::~OptimizeVar ( )
inlineoverride

Definition at line 4592 of file constraint_solver.h.

Member Function Documentation

◆ AcceptSolution()

bool operations_research::OptimizeVar::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.

This code should never return false in sequential mode because ApplyBound should have been called before. In parallel, this is no longer true. That is why we keep it there, just in case.

In unchecked mode, variables are unbound and the solution should be accepted.

Reimplemented from operations_research::SearchMonitor.

Definition at line 3092 of file search.cc.

◆ ApplyBound()

void operations_research::OptimizeVar::ApplyBound ( )

Definition at line 3083 of file search.cc.

◆ AtSolution()

bool operations_research::OptimizeVar::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 operations_research::ObjectiveMonitor.

Definition at line 3112 of file search.cc.

◆ BeginNextDecision()

void operations_research::OptimizeVar::BeginNextDecision ( DecisionBuilder * db)
overridevirtual

Internal methods.

Reimplemented from operations_research::SearchMonitor.

Definition at line 3077 of file search.cc.

◆ best()

int64_t operations_research::OptimizeVar::best ( ) const
inline

Returns the best value found during search.

Definition at line 4596 of file constraint_solver.h.

◆ DebugString()

std::string operations_research::OptimizeVar::DebugString ( ) const
overridevirtual

Reimplemented from operations_research::BaseObject.

Definition at line 3119 of file search.cc.

◆ Name()

std::string operations_research::OptimizeVar::Name ( ) const
virtual

Definition at line 3117 of file search.cc.

◆ RefuteDecision()

void operations_research::OptimizeVar::RefuteDecision ( Decision * d)
overridevirtual

Before refuting the decision.

Reimplemented from operations_research::SearchMonitor.

Definition at line 3090 of file search.cc.

◆ var()

IntVar * operations_research::OptimizeVar::var ( ) const
inline

Returns the variable that is optimized.

Definition at line 4599 of file constraint_solver.h.


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