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).
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().
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-08-06 UTC."],[[["\u003cp\u003e\u003ccode\u003eKnapsackSolverForCuts\u003c/code\u003e is a C++ class designed for solving one-dimensional knapsack problems.\u003c/p\u003e\n"],["\u003cp\u003eIt utilizes a primary propagator to determine the next item for assignment, which can be customized using \u003ccode\u003eSetPrimaryPropagator\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe class provides methods for initialization (\u003ccode\u003eInit\u003c/code\u003e), solving (\u003ccode\u003eSolve\u003c/code\u003e), and retrieving solution details (\u003ccode\u003ebest_solution\u003c/code\u003e, \u003ccode\u003eGetUpperBound\u003c/code\u003e, etc.).\u003c/p\u003e\n"],["\u003cp\u003eUsers can set limits on nodes explored (\u003ccode\u003eset_node_limit\u003c/code\u003e) and thresholds for solution bounds (\u003ccode\u003eset_solution_lower_bound_threshold\u003c/code\u003e, \u003ccode\u003eset_solution_upper_bound_threshold\u003c/code\u003e) to control the solving process.\u003c/p\u003e\n"]]],["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,["# KnapsackSolverForCuts\n\nC++ Reference: class KnapsackSolverForCuts\n==========================================\n\n\nNote: This documentation is automatically generated.\n\n----- KnapsackSolverForCuts ----- \nKnapsackSolverForCuts 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).\n\n| Method ||\n|-----------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [`best_solution`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver_for_cuts.h#L342) | Return type: `bool ` Arguments: `int item_id` Returns true if the item 'item_id' is packed in the optimal knapsack. |\n| [`GetLowerAndUpperBoundWhenItem`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver_for_cuts.h#L316) | 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(). |\n| [`GetName`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver_for_cuts.h#L347) | Return type: `const std::string& ` \u003cbr /\u003e |\n| [`GetNumberOfItems`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver_for_cuts.h#L311) | Return type: `int ` \u003cbr /\u003e |\n| [`GetUpperBound`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver_for_cuts.h#L320) | Return type: `double ` Get the best upper bound found so far. |\n| [`Init`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver_for_cuts.h#L309) | Return type: `void ` Arguments: `const std::vector\u003cdouble\u003e& profits, const std::vector\u003cdouble\u003e& weights, const double capacity` Initializes the solver and enters the problem to be solved. |\n| [`KnapsackSolverForCuts`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver_for_cuts.h#L303) | Return type: `explicit ` Arguments: `std::string solver_name` \u003cbr /\u003e |\n| [`KnapsackSolverForCuts`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver_for_cuts.h#L305) | \u003cbr /\u003e Arguments: `const KnapsackSolverForCuts&) = delete; KnapsackSolverForCuts& operator=(const KnapsackSolverForCuts&) = delete; // Initializes the solver and enters the problem to be solved. void Init(const std::vector\u003cdouble\u003e& profits, const std::vector\u003cdouble\u003e& weights, const double capacity` \u003cbr /\u003e |\n| [`set_node_limit`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver_for_cuts.h#L337) | Return type: `void ` Arguments: `const int64_t node_limit` Stops the knapsack solver after processing 'node_limit' nodes. |\n| [`set_solution_lower_bound_threshold`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver_for_cuts.h#L324) | 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. |\n| [`set_solution_upper_bound_threshold`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver_for_cuts.h#L331) | 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'. |\n| [`Solve`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver_for_cuts.h#L340) | Return type: `double ` Arguments: `TimeLimit* time_limit, bool* is_solution_optimal` Solves the problem and returns the profit of the best solution found. |"]]