Stay organized with collections
Save and categorize content based on your preferences.
C++ Reference: class KnapsackGenericSolver
Note: This documentation is automatically generated.
----- KnapsackGenericSolver -----
KnapsackGenericSolver is the multi-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), 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).
[[["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\u003eKnapsackGenericSolver\u003c/code\u003e is a C++ class designed for solving multi-dimensional knapsack problems.\u003c/p\u003e\n"],["\u003cp\u003eIt utilizes propagators to guide the search for the optimal solution, with the primary propagator determining the next item to consider.\u003c/p\u003e\n"],["\u003cp\u003eUsers can initialize the solver with profits, weights, and capacities, and then call \u003ccode\u003eSolve\u003c/code\u003e to find the optimal solution's profit.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ebest_solution\u003c/code\u003e method can be used to check if a specific item is included in the optimal knapsack.\u003c/p\u003e\n"],["\u003cp\u003eWhile a default primary propagator is used, it's recommended to implement an aggregated propagator for improved efficiency in multi-dimensional scenarios.\u003c/p\u003e\n"]]],["The `KnapsackGenericSolver` class solves multi-dimensional knapsack problems. Key actions include `Init` to set up the problem with profits, weights, and capacities, and `Solve` to find the optimal solution's profit, optionally with a time limit. `set_primary_propagator_id` allows selecting the dimension guiding the next item assignment. `best_solution` checks if an item is in the optimal solution. `GetLowerAndUpperBoundWhenItem` retrieves the bounds when specific item is packed. `GetNumberOfItems` gets the number of items.\n"],null,["# KnapsackGenericSolver\n\nC++ Reference: class KnapsackGenericSolver\n==========================================\n\n\nNote: This documentation is automatically generated.\n\n----- KnapsackGenericSolver ----- \nKnapsackGenericSolver is the multi-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), 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).\n\n| Method ||\n|---------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [`best_solution`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver.h#L636) | 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.h#L622) | Return type: `void ` Arguments: `int item_id, bool is_item_in, int64_t* lower_bound, int64_t* upper_bound` \u003cbr /\u003e |\n| [`GetNumberOfItems`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver.h#L621) | Return type: `int ` \u003cbr /\u003e |\n| [`Init`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver.h#L618) | Return type: `void ` Arguments: `const std::vector\u003cint64_t\u003e& profits, const std::vector\u003cstd::vector\u003cint64_t\u003e \u003e& weights, const std::vector\u003cint64_t\u003e& capacities` Initializes the solver and enters the problem to be solved. |\n| [`KnapsackGenericSolver`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver.h#L614) | Return type: `explicit ` Arguments: `const std::string& solver_name` \u003cbr /\u003e |\n| [`~KnapsackGenericSolver`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver.h#L615) | \u003cbr /\u003e |\n| [`set_primary_propagator_id`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver.h#L629) | Return type: `void ` Arguments: `int primary_propagator_id` Sets which propagator should be used to guide the search. 'primary_propagator_id' should be in 0..p-1 with p the number of propagators. |\n| [`Solve`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver.h#L634) | Return type: `int64_t ` Arguments: `TimeLimit* time_limit, bool* is_solution_optimal` Solves the problem and returns the profit of the optimal solution. |"]]