C++ Reference: class KnapsackPropagator
Note: This documentation is automatically generated.
----- KnapsackPropagator -----
KnapsackPropagator is the base class for modeling and propagating a
constraint given an assignment.
When some work has to be done both by the base and the derived class,
a protected pure virtual method ending by 'Propagator' is defined.
For instance, 'Init' creates a vector of items, and then calls
'InitPropagator' to let the derived class perform its own initialization.
Method |
ComputeProfitBounds | Return type: virtual void ComputeProfitBounds should set 'profit_lower_bound_' and
'profit_upper_bound_' which are constraint specific.
|
CopyCurrentStateToSolution | Return type: void Arguments: bool has_one_propagator,
std::vector<bool>* solution Copies the current state into 'solution'.
All unbound items are set to false (i.e. not in the knapsack).
When 'has_one_propagator' is true, CopyCurrentSolutionPropagator is called
to have a better solution. When there is only one propagator
there is no need to check the solution with other propagators, so the
partial solution can be smartly completed.
|
current_profit | Return type: int64_t |
GetNextItemId | Return type: virtual int Returns the id of next item to assign.
Returns kNoSelection when all items are bound.
|
Init | Return type: void Arguments: const std::vector<int64_t>& profits,
const std::vector<int64_t>& weights Initializes data structure and then calls InitPropagator.
|
KnapsackPropagator | Return type: explicit Arguments: const KnapsackState& state |
~KnapsackPropagator | Return type: virtual |
profit_lower_bound | Return type: int64_t |
profit_upper_bound | Return type: int64_t |
Update | Return type: bool Arguments: bool revert, const KnapsackAssignment& assignment Updates data structure and then calls UpdatePropagator.
Returns false when failure.
|
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."],[[["KnapsackPropagator is a base class for modeling and propagating knapsack constraints within the OR-Tools library."],["It provides methods for initialization, updating the problem state, and computing profit bounds."],["Derived classes extend its functionality by implementing specific propagation logic."],["The class manages the assignment of items to the knapsack and aims to find optimal solutions."],["It utilizes virtual and protected methods for flexible extension and customization."]]],["`KnapsackPropagator` is a base class for modeling constraints, involving actions like initialization (`Init`), and updates (`Update`). It manages profit bounds via `ComputeProfitBounds`. `GetNextItemId` determines the next item for assignment. `CopyCurrentStateToSolution` transfers the current state to a solution vector, potentially using `CopyCurrentSolutionPropagator` for optimization. It defines virtual methods like `InitPropagator` and `UpdatePropagator` allowing derived classes to perform custom initialization and updates.\n"]]