Generated on: Thu Mar 29 07:46:58 PDT 2012 for custom file set | ||
|
||
// doxy/ or-tools/ src/ algorithms/ |
#include <knapsack_solver.h>
Public Member Functions | |
KnapsackPropagator (const KnapsackState &state) | |
KnapsackPropagator. | |
virtual | ~KnapsackPropagator () |
void | Init (const std::vector< int64 > &profits, const std::vector< int64 > &weights) |
Initializes data structure and then calls InitPropagator. | |
bool | Update (bool revert, const KnapsackAssignment &assignment) |
Updates data structure and then calls UpdatePropagator. | |
virtual void | ComputeProfitBounds ()=0 |
ComputeProfitBounds should set 'profit_lower_bound_' and 'profit_upper_bound_' which are constraint specific. | |
virtual int | GetNextItemId () const =0 |
Returns the id of next item to assign. | |
int64 | current_profit () const |
int64 | profit_lower_bound () const |
int64 | profit_upper_bound () const |
void | CopyCurrentStateToSolution (bool has_one_propagator, std::vector< bool > *solution) const |
Copies the current state into 'solution'. | |
Protected Member Functions | |
virtual void | InitPropagator ()=0 |
Initializes data structure. | |
virtual bool | UpdatePropagator (bool revert, const KnapsackAssignment &assignment)=0 |
Updates internal data structure incrementally. | |
virtual void | CopyCurrentStateToSolutionPropagator (std::vector< bool > *solution) const =0 |
Copies the current state into 'solution'. | |
const KnapsackState & | state () const |
const std::vector < KnapsackItemPtr > & | items () const |
void | set_profit_lower_bound (int64 profit) |
void | set_profit_upper_bound (int64 profit) |
When some work has to be done both by the base and the derived class, a protected pure virtual method ending by 'Propagator' is defined. For instance 'Init' creates a vector of items, and then calls 'InitPropagator' to let the derived class to do its own initialization.
Definition at line 345 of file knapsack_solver.h.
operations_research::KnapsackPropagator::KnapsackPropagator | ( | const KnapsackState & | state | ) | [explicit] |
operations_research::KnapsackPropagator::~KnapsackPropagator | ( | ) | [virtual] |
Definition at line 176 of file knapsack_solver.cc.
void operations_research::KnapsackPropagator::Init | ( | const std::vector< int64 > & | profits, | |
const std::vector< int64 > & | weights | |||
) |
Initializes data structure and then calls InitPropagator.
Definition at line 180 of file knapsack_solver.cc.
bool operations_research::KnapsackPropagator::Update | ( | bool | revert, | |
const KnapsackAssignment & | assignment | |||
) |
Updates data structure and then calls UpdatePropagator.
Returns false when failure.
Definition at line 193 of file knapsack_solver.cc.
virtual void operations_research::KnapsackPropagator::ComputeProfitBounds | ( | ) | [pure virtual] |
ComputeProfitBounds should set 'profit_lower_bound_' and 'profit_upper_bound_' which are constraint specific.
Implemented in operations_research::KnapsackCapacityPropagator.
virtual int operations_research::KnapsackPropagator::GetNextItemId | ( | ) | const [pure virtual] |
Returns the id of next item to assign.
Returns kNoSelection when all items are bound.
Implemented in operations_research::KnapsackCapacityPropagator.
int64 operations_research::KnapsackPropagator::current_profit | ( | ) | const [inline] |
Definition at line 364 of file knapsack_solver.h.
int64 operations_research::KnapsackPropagator::profit_lower_bound | ( | ) | const [inline] |
Definition at line 365 of file knapsack_solver.h.
int64 operations_research::KnapsackPropagator::profit_upper_bound | ( | ) | const [inline] |
Definition at line 366 of file knapsack_solver.h.
void operations_research::KnapsackPropagator::CopyCurrentStateToSolution | ( | bool | has_one_propagator, | |
std::vector< bool > * | solution | |||
) | const |
Copies the current state into 'solution'.
All unbound items are set to false (i.e. not in the knapsack). When 'has_one_propagator' is true, CopyCurrentSolutionPropagator is called to have a better solution. When there is only one propagator there is no need to check the solution with other propagators, so the partial solution can be smartly completed.
Definition at line 205 of file knapsack_solver.cc.
virtual void operations_research::KnapsackPropagator::InitPropagator | ( | ) | [protected, pure virtual] |
Initializes data structure.
This method is called after initialization of KnapsackPropagator data structure.
Implemented in operations_research::KnapsackCapacityPropagator.
virtual bool operations_research::KnapsackPropagator::UpdatePropagator | ( | bool | revert, | |
const KnapsackAssignment & | assignment | |||
) | [protected, pure virtual] |
Updates internal data structure incrementally.
This method is called after update of KnapsackPropagator data structure.
Implemented in operations_research::KnapsackCapacityPropagator.
virtual void operations_research::KnapsackPropagator::CopyCurrentStateToSolutionPropagator | ( | std::vector< bool > * | solution | ) | const [protected, pure virtual] |
Copies the current state into 'solution'.
Only unbound items have to be copied as CopyCurrentSolution was already called with current state. This method is useful when a propagator is able to find a better solution than the blind instantiation to false of unbound items.
Implemented in operations_research::KnapsackCapacityPropagator.
const KnapsackState& operations_research::KnapsackPropagator::state | ( | ) | const [inline, protected] |
Definition at line 395 of file knapsack_solver.h.
const std::vector<KnapsackItemPtr>& operations_research::KnapsackPropagator::items | ( | ) | const [inline, protected] |
Definition at line 396 of file knapsack_solver.h.
void operations_research::KnapsackPropagator::set_profit_lower_bound | ( | int64 | profit | ) | [inline, protected] |
Definition at line 398 of file knapsack_solver.h.
void operations_research::KnapsackPropagator::set_profit_upper_bound | ( | int64 | profit | ) | [inline, protected] |
Definition at line 399 of file knapsack_solver.h.