The graphical method translates a 2-variable linear program into a set of geometric objects — boundary lines, a feasible polygon, corner vertices, an objective-level line, and the optimal point — that can be rendered directly as a 2D chart. It is not a standalone endpoint; instead, it is automatically invoked byDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/FabianeloV/Metodo-simplex/llms.txt
Use this file to discover all available pages before exploring further.
POST /api/v1/simplex/solve whenever the objective array contains exactly 2 coefficients. The result is returned inside the graphical field of the normal Simplex response.
How it is triggered
The simplex route checks the length ofpayload.objective immediately after solving:
build_graphical_data function in graphical_method.py performs all geometric computations and returns a plain dictionary that is validated against the GraphicalData Pydantic schema before serialization.
The
graphical field is only populated for 2-variable problems. For 3-, 4-, or 5-variable problems it is always null.Geometry pipeline
-
Constraint objects — each user constraint
aᵢx + bᵢy ≤/≥/= cᵢis converted to aConstraint2Ddataclass. Two implicit non-negativity constraints (x ≥ 0,y ≥ 0) are appended. -
Feasible intersections — every pair of constraint boundary lines is intersected using Cramer’s rule. Points that satisfy all constraints (within tolerance
ε = 1e-8) are kept as corner candidates. Duplicate points (closer than1e-6) are deduplicated. -
Bounds computation —
x_maxandy_maxare derived from the feasible corner points and the axis intercepts of each constraint. A 15% margin is added so chart elements are never clipped at the edge. -
Constraint line segments — for each user constraint the boundary line
ax + by = cis clipped to the computed bounds, yielding exactly two endpoint coordinates suitable for chart rendering. -
Feasible polygon — the corner points are sorted by polar angle around their centroid (counter-clockwise) using
atan2. If the resulting polygon encloses a non-zero area it is returned as an ordered vertex list; otherwisenullis returned. -
Objective line — the line
c₁x + c₂y = Z*is clipped to the bounds and returned as aGraphLinewithlabel: "objetivo". -
Optimal point — the
x1,x2values from the Simplex result are packaged as{ "x": ..., "y": ... }.
Response fields
Thegraphical object inside the Simplex response has the following structure.
Mirrors the Simplex solution status:
"optimal", "unbounded", or "infeasible".Optimization direction passed in the request:
"max" or "min".Axis ranges to use when initializing the chart viewport.
One entry per user-supplied constraint. Each entry describes the boundary line clipped to the chart bounds.
Ordered list of
{ "x": ..., "y": ... } corner points that define the feasible region polygon, sorted counter-clockwise by polar angle. null when the feasible region is empty, a single point, or a line segment.All corner points of the feasible region sorted in the same counter-clockwise order. These are the candidate optimal points of the LP by the extreme-point theorem.
The objective function evaluated at
Z*, i.e. the line c₁x + c₂y = Z*, clipped to the chart bounds. null when the problem is infeasible or the objective is identically zero.The optimal solution as
{ "x": x1*, "y": x2* }. null when no optimal solution exists.Numeric value of
Z*. Matches objective_value in the parent Simplex response.2-variable request and graphical response
Request
Graphical response snippet
cURL example
Frontend rendering
The frontend uses thegraphical payload to draw a Plotly.js 2D scatter/line chart:
- Constraint lines — each entry in
constraintsproduces a line trace drawn between its twopoints, labelled with itslabelstring. - Feasible polygon —
feasible_polygon(if non-null) is rendered as a filled, semi-transparent shape using a scatter trace in"toself"fill mode. - Corner vertices — each point in
verticesis drawn as a marker, allowing users to inspect the extreme points of the feasible region. - Objective line —
objective_lineis drawn as a dashed line to show the level curve ofZ*passing through the optimal point. - Optimal point —
optimal_pointis rendered as a highlighted marker with an annotation showing its coordinates and the objective value. - Viewport —
boundsprovidesx_min,x_max,y_min,y_maxfor configuring the Plotly axis ranges, ensuring all elements are visible with the pre-computed margin.