Metadata-Version: 2.4
Name: einheit-cli
Version: 0.6.0
License-File: LICENSE
Summary: The einheit command line: a linear and mixed-integer programming solver written in Rust.
License-Expression: MIT
Requires-Python: >=3.11
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Documentation, https://docs.einheit.tech
Project-URL: Homepage, https://einheit.tech

# einheit

Einheit is a linear and mixed-integer programming solver written in Rust. It solves LPs with a
primal and a dual simplex method over a sparse LU factorization, with presolve and steepest-edge
pricing (an interior-point method with crossover is available, off by default), and
mixed-integer programs (MILPs) with a branch-and-bound search that races its work across cores. **MILP is a preview**: its interfaces and defaults may change between releases.

This crate is Einheit: the LP engine (`einheit::lp`), the MILP engine (`einheit::mip`), the model
and its MPS and LP-format readers (`einheit::model`), the plugin host (`einheit::plugin`), the
einheit_form modeling layer (`einheit::form`), and the `einheit` command-line tool. Plugins are
written against [`einheit-plugin-sdk`](https://crates.io/crates/einheit-plugin-sdk) and installed
with [`cargo-einheit`](https://crates.io/crates/cargo-einheit).

## Install

Install the command-line tool:

```sh
cargo install einheit
```

Add the library to a project:

```sh
cargo add einheit
```

Both need Rust 1.96 or newer. The command-line tool is the default `cli` feature and the MILP
engine the default `mip` feature, so a project that uses only the LP library can leave both out:

```sh
cargo add einheit --no-default-features
```

For Python, install the [`einheit`](https://pypi.org/project/einheit/) package from PyPI.

## The command line

```sh
einheit model.mps                               # solve an LP, or a MILP by branch and bound
einheit model.mps --time-limit 60 --stats       # a MILP with a time limit and a statistics block
einheit lp model.mps --stats                    # force the LP engine (a MILP's relaxation)
einheit mip model.mps                           # force branch and bound
einheit lp model.mps --solution-file model.sol  # write the solution (.sol, or JSON for .json)
einheit lp --help                               # every LP option, grouped, with its default
einheit mip --help                              # every MILP option
```

`einheit` reads MPS and CPLEX LP format, chosen by file extension. A model with integer or binary
variables is solved by branch and bound; `einheit lp` solves its continuous relaxation on purpose.
A MILP solve prints a one-line preview notice on stderr, which `--set mip.preview_notice=false`
turns off.

## As a library

`einheit::solve` solves any model: by the simplex when it is an LP, by branch and bound when it has
integer columns. `einheit::solve_with` does the same under an `einheit::Options`.

```rust
use einheit::lp::Sense;
use einheit::LpBuilder;
use einheit::Status;

// maximize 3x + 2y  subject to  x + y <= 4,  x + 3y <= 6,  x, y >= 0
let mut b = LpBuilder::new();
b.sense(Sense::Maximize);
let x = b.add_var("x", 3.0, 0.0, f64::INFINITY);
let y = b.add_var("y", 2.0, 0.0, f64::INFINITY);
b.add_constraint("c1", &[(x, 1.0), (y, 1.0)], f64::NEG_INFINITY, 4.0);
b.add_constraint("c2", &[(x, 1.0), (y, 3.0)], f64::NEG_INFINITY, 6.0);

let model = b.build().unwrap();
let solution = einheit::solve(&model);

assert_eq!(solution.status(), Status::Optimal);
assert!((solution.objective() - 12.0).abs() < 1e-6);
```

Always match on `status()` before reading `objective()` or `x()` — they carry no meaning on a
non-optimal outcome. Each engine also has its own `solve`, `einheit::lp::solve` and
`einheit::mip::solve`, with that engine's options and result in full.

## The good_lp backend

The `good_lp` feature makes einheit a solver for [good_lp](https://crates.io/crates/good_lp):

```toml
[dependencies]
einheit = { version = "0.6", features = ["good_lp"] }
good_lp = "1"
```

Pass `einheit::good_lp::einheit` to good_lp's `.using(...)`. The backend solves the continuous
relaxation: integer variables are relaxed to their bounds, not branched on.

## Links

- Documentation: <https://docs.einheit.tech> — installation, guides, the option reference, and the
  API reference
- Website: <https://einheit.tech>

## License

MIT. See [LICENSE](../../LICENSE).

