Public Member Functions | List of all members
operations_research::KnapsackGenericSolver Class Reference

--— KnapsackGenericSolver --— KnapsackGenericSolver is the multi-dimensional knapsack solver class. More...

#include <knapsack_solver.h>

Inheritance diagram for operations_research::KnapsackGenericSolver:
Inheritance graph
[legend]
Collaboration diagram for operations_research::KnapsackGenericSolver:
Collaboration graph
[legend]

Public Member Functions

 KnapsackGenericSolver (const std::string &solver_name)
 
 ~KnapsackGenericSolver () override
 
void Init (const std::vector< int64 > &profits, const std::vector< std::vector< int64 > > &weights, const std::vector< int64 > &capacities) override
 Initializes the solver and enters the problem to be solved. More...
 
int GetNumberOfItems () const
 
void GetLowerAndUpperBoundWhenItem (int item_id, bool is_item_in, int64 *lower_bound, int64 *upper_bound) override
 Gets the lower and upper bound when the item is in or out of the knapsack. More...
 
void set_master_propagator_id (int master_propagator_id)
 Sets which propagator should be used to guide the search. More...
 
int64 Solve (TimeLimit *time_limit, bool *is_solution_optimal) override
 Solves the problem and returns the profit of the optimal solution. More...
 
bool best_solution (int item_id) const override
 Returns true if the item 'item_id' is packed in the optimal knapsack. More...
 
virtual std::string GetName () const
 

Detailed Description

--— KnapsackGenericSolver --— KnapsackGenericSolver is the multi-dimensional knapsack solver class.

In the current implementation, the next item to assign is given by the master propagator. Using SetMasterPropagator allows changing the default (propagator of the first dimension), and selecting another dimension when more constrained.

Todo:
(user): In the case of a multi-dimensional knapsack problem, implement an aggregated propagator to combine all dimensions and give a better guide to select the next item (see, for instance, Dobson's aggregated efficiency).

Definition at line 533 of file knapsack_solver.h.

Constructor & Destructor Documentation

◆ KnapsackGenericSolver()

operations_research::KnapsackGenericSolver::KnapsackGenericSolver ( const std::string &  solver_name)
explicit

◆ ~KnapsackGenericSolver()

operations_research::KnapsackGenericSolver::~KnapsackGenericSolver ( )
override

Member Function Documentation

◆ best_solution()

bool operations_research::KnapsackGenericSolver::best_solution ( int  item_id) const
inlineoverridevirtual

Returns true if the item 'item_id' is packed in the optimal knapsack.

Implements operations_research::BaseKnapsackSolver.

Definition at line 557 of file knapsack_solver.h.

◆ GetLowerAndUpperBoundWhenItem()

void operations_research::KnapsackGenericSolver::GetLowerAndUpperBoundWhenItem ( int  item_id,
bool  is_item_in,
int64 *  lower_bound,
int64 *  upper_bound 
)
overridevirtual

Gets the lower and upper bound when the item is in or out of the knapsack.

To ensure objects are correctly initialized, this method should not be called before ::Init.

Reimplemented from operations_research::BaseKnapsackSolver.

◆ GetName()

virtual std::string operations_research::BaseKnapsackSolver::GetName ( ) const
inlinevirtualinherited

Definition at line 518 of file knapsack_solver.h.

◆ GetNumberOfItems()

int operations_research::KnapsackGenericSolver::GetNumberOfItems ( ) const
inline

Definition at line 542 of file knapsack_solver.h.

◆ Init()

void operations_research::KnapsackGenericSolver::Init ( const std::vector< int64 > &  profits,
const std::vector< std::vector< int64 > > &  weights,
const std::vector< int64 > &  capacities 
)
overridevirtual

Initializes the solver and enters the problem to be solved.

Implements operations_research::BaseKnapsackSolver.

◆ set_master_propagator_id()

void operations_research::KnapsackGenericSolver::set_master_propagator_id ( int  master_propagator_id)
inline

Sets which propagator should be used to guide the search.

'master_propagator_id' should be in 0..p-1 with p the number of propagators.

Definition at line 550 of file knapsack_solver.h.

◆ Solve()

int64 operations_research::KnapsackGenericSolver::Solve ( TimeLimit *  time_limit,
bool *  is_solution_optimal 
)
overridevirtual

Solves the problem and returns the profit of the optimal solution.

Implements operations_research::BaseKnapsackSolver.


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