solve_knapsack_problem_tool
Maximize value by selecting items under weight and volume constraints for cargo loading, portfolio selection, resource allocation, advertising planning, menu planning, and inventory optimization.
Instructions
Solve knapsack optimization problems using OR-Tools.
This tool solves knapsack problems where items need to be selected
to maximize value while staying within capacity constraints.
Use cases:
- Cargo loading: Optimize loading of trucks, ships, or planes by weight and volume
- Portfolio selection: Choose optimal set of investments within budget constraints
- Resource allocation: Select projects or activities with limited budget or resources
- Advertising planning: Choose optimal mix of advertising channels within budget
- Menu planning: Select dishes for a restaurant menu considering costs and popularity
- Inventory optimization: Decide which products to stock in limited warehouse space
Args:
items: List of items, each with 'name', 'value', 'weight', and optionally 'volume', 'quantity'
capacity: Weight capacity constraint
volume_capacity: Volume capacity constraint (optional)
knapsack_type: Type of knapsack problem ('0-1', 'bounded', 'unbounded')
max_items_per_type: Maximum items per type for bounded knapsack
Returns:
Knapsack result with total value and selected items
Example:
# Select items to maximize value within weight limit
solve_knapsack_problem(
items=[
{"name": "Item1", "value": 10, "weight": 5, "volume": 2},
{"name": "Item2", "value": 15, "weight": 8, "volume": 3},
{"name": "Item3", "value": 8, "weight": 3, "volume": 1}
],
capacity=10,
volume_capacity=5
)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| items | Yes | ||
| capacity | Yes | ||
| volume_capacity | No | ||
| knapsack_type | No | 0-1 | |
| max_items_per_type | No |