Stay organized with collections
Save and categorize content based on your preferences.
C++ Reference: class BaseKnapsackSolver
Note: This documentation is automatically generated.
----- BaseKnapsackSolver -----
This is the base class for knapsack solvers.
Method |
BaseKnapsackSolver | Return type: explicit Arguments: const std::string& solver_name |
~BaseKnapsackSolver | Return type: virtual |
best_solution | Return type: virtual bool Arguments: int item_id Returns true if the item 'item_id' is packed in the optimal knapsack.
|
GetLowerAndUpperBoundWhenItem | Return type: virtual void Arguments: int item_id, bool is_item_in,
int64_t* lower_bound,
int64_t* upper_bound Gets the lower and 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: virtual std::string |
Init | Return type: virtual 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.
|
Solve | Return type: virtual 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."],[],["`BaseKnapsackSolver` is a foundational class for solving knapsack problems. Key actions include initializing the solver (`Init`) with item profits, weights, and capacities, and solving the problem (`Solve`) to find the optimal profit. The class provides methods to check if an item is in the optimal solution (`best_solution`), retrieve bounds for items being in or out of the knapsack (`GetLowerAndUpperBoundWhenItem`), and get the solver's name (`GetName`). There are methods for the constructor and destructor.\n"],null,[]]