Stay organized with collections
Save and categorize content based on your preferences.
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.
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.
[[["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\u003eKnapsackPropagator is a base class for modeling and propagating knapsack constraints within the OR-Tools library.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods for initialization, updating the problem state, and computing profit bounds.\u003c/p\u003e\n"],["\u003cp\u003eDerived classes extend its functionality by implementing specific propagation logic.\u003c/p\u003e\n"],["\u003cp\u003eThe class manages the assignment of items to the knapsack and aims to find optimal solutions.\u003c/p\u003e\n"],["\u003cp\u003eIt utilizes virtual and protected methods for flexible extension and customization.\u003c/p\u003e\n"]]],["`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"],null,["# KnapsackPropagator\n\nC++ Reference: class KnapsackPropagator\n=======================================\n\n\nNote: This documentation is automatically generated.\n\n----- KnapsackPropagator ----- \nKnapsackPropagator is the base class for modeling and propagating a constraint given an assignment. \n\nWhen 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.\n\n| Method ||\n|------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [`ComputeProfitBounds`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver.h#L460) | Return type: `virtual void ` ComputeProfitBounds should set 'profit_lower_bound_' and 'profit_upper_bound_' which are constraint specific. |\n| [`CopyCurrentStateToSolution`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver.h#L475) | Return type: `void ` Arguments: `bool has_one_propagator, std::vector\u003cbool\u003e* 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. |\n| [`current_profit`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver.h#L465) | Return type: `int64_t ` \u003cbr /\u003e |\n| [`GetNextItemId`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver.h#L463) | Return type: `virtual int ` Returns the id of next item to assign. Returns kNoSelection when all items are bound. |\n| [`Init`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver.h#L452) | Return type: `void ` Arguments: `const std::vector\u003cint64_t\u003e& profits, const std::vector\u003cint64_t\u003e& weights` Initializes data structure and then calls InitPropagator. |\n| [`KnapsackPropagator`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver.h#L448) | Return type: `explicit ` Arguments: `const KnapsackState& state` \u003cbr /\u003e |\n| [`~KnapsackPropagator`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver.h#L449) | Return type: `virtual ` \u003cbr /\u003e |\n| [`profit_lower_bound`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver.h#L466) | Return type: `int64_t ` \u003cbr /\u003e |\n| [`profit_upper_bound`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver.h#L467) | Return type: `int64_t ` \u003cbr /\u003e |\n| [`Update`](https://github.com/google/or-tools/blob/v9.4/ortools/algorithms/knapsack_solver.h#L457) | Return type: `bool ` Arguments: `bool revert, const KnapsackAssignment& assignment` Updates data structure and then calls UpdatePropagator. Returns false when failure. |"]]