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

#include <knapsack_solver.h>

Public Types

enum  SolverType { KNAPSACK_BRUTE_FORCE_SOLVER = 0, KNAPSACK_64ITEMS_SOLVER = 1, KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER = 2, KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER = 5 }
 

Public Member Functions

 KnapsackSolver (const std::string &solver_name)
 
 KnapsackSolver (SolverType solver_type, const std::string &solver_name)
 
virtual ~KnapsackSolver ()
 
void Init (const std::vector< int64 > &profits, const std::vector< std::vector< int64 > > &weights, const std::vector< int64 > &capacities)
 Initializes the solver and enters the problem to be solved. More...
 
int64 Solve ()
 Solves the problem and returns the profit of the optimal solution. More...
 
bool BestSolutionContains (int item_id) const
 Returns true if the item 'item_id' is packed in the optimal knapsack. More...
 
bool IsSolutionOptimal () const
 Returns true if the solution was proven optimal. More...
 
std::string GetName () const
 
bool use_reduction () const
 
void set_use_reduction (bool use_reduction)
 
void set_time_limit (double time_limit_seconds)
 Time limit in seconds. More...
 

Detailed Description

Definition at line 117 of file knapsack_solver.h.

Member Enumeration Documentation

◆ SolverType

Enumerator
KNAPSACK_BRUTE_FORCE_SOLVER 
KNAPSACK_64ITEMS_SOLVER 
KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER 
KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER 

Definition at line 119 of file knapsack_solver.h.

Constructor & Destructor Documentation

◆ KnapsackSolver() [1/2]

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

◆ KnapsackSolver() [2/2]

operations_research::KnapsackSolver::KnapsackSolver ( SolverType  solver_type,
const std::string &  solver_name 
)

◆ ~KnapsackSolver()

virtual operations_research::KnapsackSolver::~KnapsackSolver ( )
virtual

Member Function Documentation

◆ BestSolutionContains()

bool operations_research::KnapsackSolver::BestSolutionContains ( int  item_id) const

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

◆ GetName()

std::string operations_research::KnapsackSolver::GetName ( ) const

◆ Init()

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

Initializes the solver and enters the problem to be solved.

◆ IsSolutionOptimal()

bool operations_research::KnapsackSolver::IsSolutionOptimal ( ) const
inline

Returns true if the solution was proven optimal.

Definition at line 147 of file knapsack_solver.h.

◆ set_time_limit()

void operations_research::KnapsackSolver::set_time_limit ( double  time_limit_seconds)
inline

Time limit in seconds.

When a finite time limit is set the solution obtained might not be optimal if the limit is reached.

Definition at line 155 of file knapsack_solver.h.

◆ set_use_reduction()

void operations_research::KnapsackSolver::set_use_reduction ( bool  use_reduction)
inline

Definition at line 151 of file knapsack_solver.h.

◆ Solve()

int64 operations_research::KnapsackSolver::Solve ( )

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

◆ use_reduction()

bool operations_research::KnapsackSolver::use_reduction ( ) const
inline

Definition at line 150 of file knapsack_solver.h.


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