Skip to main content

Documentation 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.

Binary Integer Programming (BIP) is a special case of integer programming in which every decision variable is restricted to exactly two values: 0 or 1. These problems arise naturally in yes/no decisions — selecting projects from a portfolio, assigning workers to shifts, or activating equipment — where a continuous relaxation would produce meaningless fractional answers. The POST /api/v1/binary/solve endpoint solves such problems using the Branch and Bound algorithm, returning both the optimal 0/1 variable assignment and the full exploration tree so the search process can be visualized.

When to use

Use this endpoint when your LP has the additional requirement that all decision variables are binary integers (xᵢ ∈ {0, 1}). The objective function and constraints are otherwise identical in structure to those of the standard Simplex endpoint — same coefficient arrays, same inequality types, same right-hand sides.
The solver supports 2 to 5 binary decision variables. Every constraint must have the same number of coefficients as there are entries in the objective array.

Branch and Bound algorithm

The engine in binary_engine.py performs a depth-first Branch and Bound search over the space of 0/1 assignments:
  1. LP relaxation — at each node, the subproblem is solved as a continuous LP by SimplexEngine, with every unfixed variable bounded to [0, 1] and every fixed variable forced to xᵢ ≤ 0 (for xᵢ = 0) or xᵢ ≥ 1 (for xᵢ = 1).
  2. Integer feasibility check — if the LP is optimal and all variable values are already integer (within ε = 1e-6), the node is recorded as "integer" and, if its objective is better than the current incumbent, it becomes the new best solution.
  3. Bounding and pruning — if an incumbent already exists and the node’s LP relaxation value is no better than the current best (for maximization, lp_val ≤ best_val; for minimization, lp_val ≥ best_val), the node is pruned as "pruned_bound".
  4. Infeasibility pruning — if the LP relaxation is infeasible or unbounded, the node is pruned as "pruned_infeasible".
  5. Branching — when fractional variables remain, the algorithm selects the most fractional variable (the one closest to 0.5) as the branch variable. Two child nodes are pushed onto the DFS stack: one fixing that variable to 1 (explored first) and one fixing it to 0.
  6. Node limit — the search terminates after at most 500 nodes (MAX_NODES) to prevent runaway execution on large instances. If the limit is reached the response status is "limit".

Endpoint

POST /api/v1/binary/solve

Request

objective
number[]
required
Coefficients of the objective function, one per binary variable. Length must be between 2 and 5.Example: [1, 6, 10, 16] represents x₁ + 6x₂ + 10x₃ + 16x₄.
goal
string
required
Optimization direction. Accepted values: "max" or "min".
constraints
Constraint[]
required
Array of linear constraint objects. At least one constraint is required. Constraint coefficients must each have the same length as objective.

Request example

The following problem selects a subset of four binary projects to maximize profit subject to a weight capacity of 22 units.
{
  "objective": [1, 6, 10, 16],
  "goal": "max",
  "constraints": [
    { "coefficients": [2, 4, 6, 9], "inequality": "<=", "rhs": 22 }
  ]
}

Response

status
string
Final solution status. One of:
  • "optimal" — a globally optimal 0/1 solution was found.
  • "infeasible" — no feasible integer solution exists.
  • "limit" — the 500-node exploration limit was reached before proving optimality.
objective_value
number | null
Optimal objective value for the best integer solution found. null when the problem is infeasible.
variables
object | null
Dictionary mapping variable names to their optimal binary values (always 0 or 1), e.g. { "x1": 0, "x2": 1, "x3": 0, "x4": 1 }. null when infeasible.
nodes_explored
number
Total number of B&B nodes evaluated during the search.
nodes
BBNode[]
Full exploration tree as a flat list of node objects. The frontend uses this array to render the Branch and Bound tree visualization. Parent–child relationships are encoded via parent_id.
message
string
Human-readable summary, e.g. "Solución óptima encontrada con valor Z = 22.0. Nodos explorados: 5.".

Response example

{
  "status": "optimal",
  "objective_value": 22.0,
  "variables": { "x1": 0, "x2": 0, "x3": 0, "x4": 1 },
  "nodes_explored": 5,
  "nodes": [
    {
      "node_id": 0,
      "parent_id": null,
      "depth": 0,
      "fixed_vars": {},
      "lp_value": 23.111,
      "lp_vars": { "x1": 0.0, "x2": 0.0, "x3": 0.444, "x4": 1.0 },
      "status": "branched",
      "branched_on": "x3",
      "edge_label": null
    },
    {
      "node_id": 1,
      "parent_id": 0,
      "depth": 1,
      "fixed_vars": { "x3": 1 },
      "lp_value": 20.667,
      "lp_vars": { "x1": 0.0, "x2": 0.667, "x3": 1.0, "x4": 0.0 },
      "status": "branched",
      "branched_on": "x2",
      "edge_label": "x3 = 1"
    },
    {
      "node_id": 2,
      "parent_id": 1,
      "depth": 2,
      "fixed_vars": { "x3": 1, "x2": 1 },
      "lp_value": null,
      "lp_vars": null,
      "status": "pruned_infeasible",
      "branched_on": null,
      "edge_label": "x2 = 1"
    },
    {
      "node_id": 3,
      "parent_id": 1,
      "depth": 2,
      "fixed_vars": { "x3": 1, "x2": 0 },
      "lp_value": 16.0,
      "lp_vars": { "x1": 0.0, "x2": 0.0, "x3": 1.0, "x4": 0.0 },
      "status": "integer",
      "branched_on": null,
      "edge_label": "x2 = 0"
    },
    {
      "node_id": 4,
      "parent_id": 0,
      "depth": 1,
      "fixed_vars": { "x3": 0 },
      "lp_value": 22.0,
      "lp_vars": { "x1": 0.0, "x2": 0.0, "x3": 0.0, "x4": 1.0 },
      "status": "integer",
      "branched_on": null,
      "edge_label": "x3 = 0"
    }
  ],
  "message": "Solución óptima encontrada con valor Z = 22.0. Nodos explorados: 5."
}

cURL example

curl -X POST http://localhost:8000/api/v1/binary/solve \
  -H "Content-Type: application/json" \
  -d '{
    "objective": [1, 6, 10, 16],
    "goal": "max",
    "constraints": [
      { "coefficients": [2, 4, 6, 9], "inequality": "<=", "rhs": 22 }
    ]
  }'

Branch and Bound tree visualization

The nodes array is designed to drive the frontend’s interactive tree diagram. Because every node records its node_id, parent_id, depth, edge_label, and status, the frontend can reconstruct the full directed tree without any additional API calls. Each node is rendered with a colour that reflects its status:
StatusMeaningTypical color
"branched"Node was split furtherNeutral / blue
"integer"Integer solution foundGreen
"pruned_bound"Bound cut-off appliedOrange
"pruned_infeasible"LP was infeasibleRed
Edges are labelled with edge_label (e.g. "x2 = 1") to show which branching decision led to each child node.
For minimization problems the bounding condition is reversed: a node is pruned when its LP value is greater than or equal to the current incumbent. The status field always reflects the actual pruning reason regardless of the optimization direction.

Build docs developers (and LLMs) love