solve_linear_program_tool
Optimize resource allocation, diet plans, manufacturing mixes, and more by solving linear programming problems. Input objective, variables, and constraints to maximize or minimize outcomes efficiently.
Instructions
Solve a linear programming problem using PuLP.
This tool solves general linear programming problems where you want to
optimize a linear objective function subject to linear constraints.
Use cases:
- Resource allocation: Distribute limited resources optimally
- Diet planning: Create nutritionally balanced meal plans within budget
- Manufacturing mix: Determine optimal product mix to maximize profit
- Investment planning: Allocate capital across different investment options
- Supply chain optimization: Minimize transportation and storage costs
- Energy optimization: Optimize power generation and distribution
Args:
objective: Objective function with 'sense' ("minimize" or "maximize")
and 'coefficients' (dict mapping variable names to coefficients)
variables: Variable definitions mapping variable names to their properties
(type: "continuous"/"integer"/"binary", lower: bound, upper: bound)
constraints: List of constraints, each with 'expression' (coefficients),
'operator' ("<=", ">=", "=="), and 'rhs' (right-hand side value)
solver: Solver to use ("CBC", "GLPK", "GUROBI", "CPLEX")
time_limit_seconds: Maximum time to spend solving (optional)
Returns:
Optimization result with status, objective value, variable values, and solver info
Example:
# Maximize 3x + 2y subject to 2x + y <= 20, x + 3y <= 30, x,y >= 0
solve_linear_program(
objective={"sense": "maximize", "coefficients": {"x": 3, "y": 2}},
variables={
"x": {"type": "continuous", "lower": 0},
"y": {"type": "continuous", "lower": 0}
},
constraints=[
{"expression": {"x": 2, "y": 1}, "operator": "<=", "rhs": 20},
{"expression": {"x": 1, "y": 3}, "operator": "<=", "rhs": 30}
]
)
Input Schema
Name | Required | Description | Default |
---|---|---|---|
constraints | Yes | ||
objective | Yes | ||
solver | No | CBC | |
time_limit_seconds | No | ||
variables | Yes |
Input Schema (JSON Schema)
{
"properties": {
"constraints": {
"items": {
"additionalProperties": true,
"type": "object"
},
"title": "Constraints",
"type": "array"
},
"objective": {
"additionalProperties": true,
"title": "Objective",
"type": "object"
},
"solver": {
"default": "CBC",
"title": "Solver",
"type": "string"
},
"time_limit_seconds": {
"anyOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"default": null,
"title": "Time Limit Seconds"
},
"variables": {
"additionalProperties": {
"additionalProperties": true,
"type": "object"
},
"title": "Variables",
"type": "object"
}
},
"required": [
"objective",
"variables",
"constraints"
],
"type": "object"
}