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).
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,
int64_t* lower_bound,
int64_t* upper_bound |
GetNumberOfItems | Return type: int |
Init | Return type: void Arguments: const std::vector<int64_t>& profits,
const std::vector<std::vector<int64_t> >& weights,
const std::vector<int64_t>& capacities Initializes the solver and enters the problem to be solved.
|
KnapsackGenericSolver | Return type: explicit Arguments: const std::string& solver_name |
~KnapsackGenericSolver | |
set_primary_propagator_id | 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.
|
Solve | Return type: int64_t Arguments: TimeLimit* time_limit, bool* is_solution_optimal Solves the problem and returns the profit of the optimal solution.
|
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."],[[["`KnapsackGenericSolver` is a C++ class designed for solving multi-dimensional knapsack problems."],["It utilizes propagators to guide the search for the optimal solution, with the primary propagator determining the next item to consider."],["Users can initialize the solver with profits, weights, and capacities, and then call `Solve` to find the optimal solution's profit."],["The `best_solution` method can be used to check if a specific item is included in the optimal knapsack."],["While a default primary propagator is used, it's recommended to implement an aggregated propagator for improved efficiency in multi-dimensional scenarios."]]],[]]