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).
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."],[],["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,[]]