solve_cvxpy_problem
Solve CVXPY optimization problems by defining variables, objectives, and constraints. Returns solutions for linear, quadratic, and convex optimization tasks efficiently.
Instructions
Solve a CVXPY optimization problem.
This tool takes a CVXPY optimization problem defined with variables, objective,
and constraints, and returns a solution if one exists.
Example:
Solve the following problem:
minimize ||Ax - b||₂²
subject to:
0 ≤ x ≤ 1
where A = [1.0, -0.5; 0.5, 2.0; 0.0, 1.0] and b = [2.0, 1.0, -1.0]
Should be this tool call:
simple_cvxpy_solver(
variables=[{"name": "x", "shape": 2}],
objective_type="minimize",
objective_expr="cp.sum_squares(np.array(A) @ x - np.array(b))",
constraints=["x >= 0", "x <= 1"],
parameters={"A": [[1.0, -0.5], [0.5, 2.0], [0.0, 1.0]],
"b": [2.0, 1.0, -1.0]}
)
Args:
problem: The problem definition with variables, objective, and constraints
Returns:
A list of TextContent containing the solution or an error message
Input Schema
Name | Required | Description | Default |
---|---|---|---|
problem | Yes |
Input Schema (JSON Schema)
{
"$defs": {
"CVXPYConstraint": {
"description": "Model representing a CVXPY constraint.",
"properties": {
"description": {
"default": "",
"title": "Description",
"type": "string"
},
"expression": {
"title": "Expression",
"type": "string"
}
},
"required": [
"expression"
],
"title": "CVXPYConstraint",
"type": "object"
},
"CVXPYObjective": {
"description": "Model representing a CVXPY objective.",
"properties": {
"expression": {
"title": "Expression",
"type": "string"
},
"type": {
"$ref": "#/$defs/ObjectiveType"
}
},
"required": [
"type",
"expression"
],
"title": "CVXPYObjective",
"type": "object"
},
"CVXPYProblem": {
"description": "Model representing a complete CVXPY optimization problem.",
"properties": {
"constraints": {
"items": {
"$ref": "#/$defs/CVXPYConstraint"
},
"title": "Constraints",
"type": "array"
},
"description": {
"default": "",
"title": "Description",
"type": "string"
},
"objective": {
"$ref": "#/$defs/CVXPYObjective"
},
"parameters": {
"default": {},
"title": "Parameters",
"type": "object"
},
"variables": {
"items": {
"$ref": "#/$defs/CVXPYVariable"
},
"title": "Variables",
"type": "array"
}
},
"required": [
"variables",
"objective",
"constraints"
],
"title": "CVXPYProblem",
"type": "object"
},
"CVXPYVariable": {
"description": "Model representing a CVXPY variable.",
"properties": {
"name": {
"title": "Name",
"type": "string"
},
"shape": {
"anyOf": [
{
"type": "integer"
},
{
"items": {
"type": "integer"
},
"type": "array"
}
],
"title": "Shape"
}
},
"required": [
"name",
"shape"
],
"title": "CVXPYVariable",
"type": "object"
},
"ObjectiveType": {
"description": "Enum for objective types in CVXPY.",
"enum": [
"minimize",
"maximize"
],
"title": "ObjectiveType",
"type": "string"
}
},
"properties": {
"problem": {
"$ref": "#/$defs/CVXPYProblem"
}
},
"required": [
"problem"
],
"title": "solve_cvxpy_problem_toolArguments",
"type": "object"
}