C++ Reference: class KnapsackSolverForCuts

Note: This documentation is automatically generated.


   ----- KnapsackSolverForCuts -----
KnapsackSolverForCuts is the one-dimensional knapsack solver class. In the current implementation, the next item to assign is given by the primary propagator. Using SetPrimaryPropagator allows changing the default (propagator of the first dimension).
Method
best_solution

Return type: bool

Arguments: int item_id

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

GetLowerAndUpperBoundWhenItem

Return type: void

Arguments: int item_id, bool is_item_in, double* lower_bound, double* upper_bound

Gets the lower and the 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().

GetName

Return type: const std::string&

GetNumberOfItems

Return type: int

GetUpperBound

Return type: double

Get the best upper bound found so far.

Init

Return type: void

Arguments: const std::vector<double>& profits, const std::vector<double>& weights, const double capacity

Initializes the solver and enters the problem to be solved.

KnapsackSolverForCuts

Return type: explicit

Arguments: std::string solver_name

KnapsackSolverForCuts

Arguments: const KnapsackSolverForCuts&) = delete; KnapsackSolverForCuts& operator=(const KnapsackSolverForCuts&) = delete; // Initializes the solver and enters the problem to be solved. void Init(const std::vector<double>& profits, const std::vector<double>& weights, const double capacity

set_node_limit

Return type: void

Arguments: const int64_t node_limit

Stops the knapsack solver after processing 'node_limit' nodes.

set_solution_lower_bound_threshold

Return type: void

Arguments: const double solution_lower_bound_threshold

The solver stops if a solution with profit better than 'solution_lower_bound_threshold' is found.

set_solution_upper_bound_threshold

Return type: void

Arguments: const double solution_upper_bound_threshold

The solver stops if the upper bound on profit drops below 'solution_upper_bound_threshold'.

Solve

Return type: double

Arguments: TimeLimit* time_limit, bool* is_solution_optimal

Solves the problem and returns the profit of the best solution found.