Stay organized with collections
Save and categorize content based on your preferences.
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.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-08-06 UTC.
[null,null,["Last updated 2024-08-06 UTC."],[],["The `KnapsackSolverForCuts` class solves one-dimensional knapsack problems. Key actions include initializing the solver with item profits, weights, and capacity via `Init`. Users can query information like the number of items with `GetNumberOfItems`. `GetLowerAndUpperBoundWhenItem` provides bounds for specific items. `Solve` computes the optimal solution, while `best_solution` checks if an item is in the optimal solution. Additionally, `set_node_limit` limits the search, and `set_solution_lower_bound_threshold` and `set_solution_upper_bound_threshold` allows to stop the search based on solution quality.\n"],null,[]]