# Optex v0.1.0 - Table of Contents

> Model and solve LP/MILP/QP/QCP/SOCP with in-process solver bindings: HiGHS built in (precompiled), Gurobi, CPLEX, and COPT optional. Native indicators, abs, piecewise-linear, min/max, SOS, duals, IIS, and live solve streaming.

## Pages

- [Optex](readme.md)
- [Changelog](changelog.md)
- [LICENSE](license.md)

## Modules

- [Optex](Optex.md): Optex: an Elixir library for modeling and solving mixed-integer linear
programs, with an in-process HiGHS binding via Rustler.

- Modeling
  - [Optex.Aff](Optex.Aff.md): Affine-plus-quadratic expression a^T x + x^T C x + b, sparse over variable
ids. `terms` holds the linear part; `qterms` holds quadratic coefficients
keyed by normalized `{lo_id, hi_id}` pairs (so `x*y` and `y*x` sum into one
cell, and `x*x` lives at `{i, i}`). Coefficients are literal: the qterm
coefficient of `{i, j}` is exactly the coefficient of `x_i * x_j` as
written. Products of degree greater than two raise `Optex.NonlinearError`.

  - [Optex.Cone](Optex.Cone.md): A second-order cone in its own id space. `type` `:quad` relates one head
to its members: `head >= sqrt(sum member^2)`; `type` `:rquad` (rotated)
relates two heads: `2 * h1 * h2 >= sum member^2`. Heads are guaranteed to
carry a nonnegative lower bound (the model layer enforces it: the bound
is part of the cone's meaning, and it is what makes the SOC-shaped
quadratic encodings on Gurobi/CPLEX legal). Solved natively by capable
backends (Gurobi, CPLEX, COPT); backends without cone support reject the
model at solve time.

  - [Optex.Constraint](Optex.Constraint.md): One linear row, normalized: pure a^T x on the left, number on the right.
  - [Optex.DSL](Optex.DSL.md): The modeling DSL: `model do ... end` with variable/constraint/objective.
  - [Optex.Expr](Optex.Expr.md): Compile-time translation of arithmetic-looking AST into Aff-building code.
  - [Optex.Indicator](Optex.Indicator.md): An indicator constraint: a linear row that must hold when a binary variable
takes a given value (`bin = active_value -> a^T x SENSE rhs`). Stored
normalized like `Optex.Constraint` (pure a^T x on the left). Solved natively
by capable backends; never reformulated.

  - [Optex.Model](Optex.Model.md): The neutral model. Immutable; builder calls return a new struct.
  - [Optex.NonlinearError](Optex.NonlinearError.md)
  - [Optex.QConstraint](Optex.QConstraint.md): A quadratic constraint x^T C x + a^T x SENSE rhs, stored normalized (the
affine constant folded into the rhs) with literal coefficients. Lives in
its own id space, separate from linear rows. Solved natively by capable
backends: Gurobi (including nonconvex and equality), CPLEX (convex,
`<=`/`>=` only); HiGHS rejects.

  - [Optex.Sos](Optex.Sos.md): A special ordered set in its own id space: `type` is `:sos1` (at most one
member nonzero) or `:sos2` (at most two, adjacent in weight order);
`var_ids` and `weights` are parallel lists, weights distinct because they
define the set's order. Solved natively by capable backends (Gurobi,
CPLEX, COPT); backends without SOS support reject the model at solve
time.

  - [Optex.Var](Optex.Var.md): A decision variable. Created by the model, carries its own id.

- Solver abstraction
  - [Optex.Format](Optex.Format.md): Human-readable rendering of an `Optex.Model` using the user-facing names as
written (`y[1]`, `w[{1, :a}]`). Answers "what did my model block actually
build?"; for a solver-parseable file see `Optex.LP`.

  - [Optex.LP](Optex.LP.md): CPLEX-LP-format emitter for an `Optex.Model`, using sanitized versions of
the user-facing variable and constraint names, so the file stays readable.
  - [Optex.MPS](Optex.MPS.md): Minimal free-format MPS emitter for a `Optex.SolverInput`.
  - [Optex.Solution](Optex.Solution.md): The result of a solve: a decoded status, the objective value, primal
variable values, and, for LPs, dual information.
  - [Optex.Solver](Optex.Solver.md): The behaviour a solver backend implements. This is the only contract between
the solver-abstraction layer and a backend; a second solver implements this
and touches nothing above it.

  - [Optex.SolverInput](Optex.SolverInput.md): Column-oriented problem ready for a solver. Variables 0..n-1, constraints 0..m-1.
Constraint matrix is CSC: column j occupies row_index/values at
col_start[j] .. col_start[j+1]-1.
Each constraint is a range: row_lb <= a^T x <= row_ub.
Bounds use :infinity/:neg_infinity; the binding substitutes the solver's value.

  - [Optex.Transform](Optex.Transform.md): The one-time transform from a neutral Model to column-sparse SolverInput.

- Backends
  - [Optex.Solver.COPT](Optex.Solver.COPT.md): COPT (Cardinal Optimizer) backend. Implements the same `Optex.Solver`
contract as the other backends and accepts the same neutral options; use
it with `Optex.optimize(m, solver: Optex.Solver.COPT)`.
  - [Optex.Solver.CPLEX](Optex.Solver.CPLEX.md): CPLEX backend. Implements the same `Optex.Solver` contract as the HiGHS
and Gurobi backends and accepts the same neutral options; use it with
`Optex.optimize(m, solver: Optex.Solver.CPLEX)`.
  - [Optex.Solver.Gurobi](Optex.Solver.Gurobi.md): Gurobi backend. Implements the same `Optex.Solver` contract as
`Optex.Solver.HiGHS` and accepts the same neutral options; use it with
`Optex.optimize(m, solver: Optex.Solver.Gurobi)`.
  - [Optex.Solver.HiGHS](Optex.Solver.HiGHS.md): HiGHS backend. Maps neutral variable types to HiGHS vartype ints, translates
neutral solver options to HiGHS option names, and decodes HiGHS status
codes; symbolic :infinity bounds pass through to the NIF, which substitutes
HiGHS's own infinity value (see DECISIONS.md).

