Metadata-Version: 2.4
Name: kos-solver
Version: 1.0.0b1
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Rust
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Software Development :: Libraries
Requires-Dist: numpy
License-File: LICENSE
License-File: THIRD_PARTY_LICENSES.txt
Summary: KOS — the Katsenia Optimization Solver: fast LP and MIP, with exact proofs and open certificates for linear programs
Keywords: linear programming,mixed-integer programming,LP,MIP,simplex,optimization,solver
Author-email: Katsenia SpA <support@katsenia.com>
License-Expression: LicenseRef-KOS-EULA
Requires-Python: >=3.9
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Documentation, https://katsenia.com/help.html
Project-URL: Homepage, https://katsenia.com
Project-URL: Pricing, https://katsenia.com/pricing.html

# KOS — the Katsenia Optimization Solver

KOS solves linear programs (LP) and mixed-integer linear programs (MIP).

- For linear programs, KOS also says what it has proven: the objective of an LP optimum can be proven in exact
  arithmetic (`objective_proven`), and an LP that cannot be solved to the tolerance says why (`optimal_flagged` with
  its `flag_origin`, or `no_verdict` with its `no_verdict_reason`) instead of reporting an unqualified optimum.
- For MIP, KOS reports the incumbent, the dual bound and the gap of its branch and cut (exact proofs and certificates
  are for linear programs).
- For both, with the same data, parameters and threads every solve gives the same result, bit for bit.

What it includes:

- LP: dual and primal simplex with warm starts (change bounds or costs and solve again from the previous basis),
  interior point with crossover, presolve, an irreducible infeasible subsystem (IIS) of an infeasible LP.
- MIP: branch and cut with presolve, cutting planes, primal heuristics and a deterministic parallel tree search.
- Models from MPS (fixed or free) and LP files or strings, or loaded by columns from numpy arrays; written back to MPS
  or LP.

This is the Community edition (see below), version 1.0.0b1, a beta.

## Installation

```
pip install --pre kos-solver
```

The package is `kos-solver`; the module it installs is `kos` (`import kos`).

Linux on x86_64 and aarch64 (glibc 2.17 or newer), Python 3.9 or newer; it needs numpy.

## A first model

```python
import kos

m = kos.Model.from_string("""
Maximize
 profit: 3 x + 2 y
Subject To
 wood: x + y <= 4
 labor: x + 3 y <= 7
Bounds
 x <= 3
End
""", "lp")
status = m.solve()
print(status, m.objective, m.solution)   # optimal 11.0 [3. 1.]
print(m.duals, m.objective_proven)       # [2. 0.] True: the objective is proven in exact arithmetic
print(m.write_certificate("first.json"))  # optimal: the certificate of this LP solve
```

`write_certificate` writes the certificate of the last LP solve: a JSON file in the open `kos-certificate` format with
what the solve proves (an optimum, an infeasibility, an unbounded ray or a bound) and the numbers that prove it, which a
verifier can check in exact arithmetic without trusting KOS. Certificates are for linear programs; a MIP raises
`kos.Error` with code `not_applicable`.

`kos.Model.read("model.mps")` reads a file (MPS or LP, by the extension). A model can also be loaded by columns: the
matrix in compressed sparse column form, as sequences or numpy arrays.

```python
import numpy as np
import kos

m = kos.Model()
m.load(cost=[-1.0, -1.0], col_lower=[0.0, 0.0], col_upper=[kos.INFINITY, kos.INFINITY],
       row_lower=[-kos.INFINITY, -kos.INFINITY], row_upper=[4.0, 6.0],
       start=[0, 2, 4], index=[0, 1, 0, 1], value=[1.0, 3.0, 2.0, 1.0])
print(m.solve(), m.objective)            # optimal -2.8
m.set_integrality([True, True])          # now a MIP
print(m.solve(), m.objective)            # optimal -2.0
```

Parameters are set by name (`kos.parameters()` lists them with their defaults and help), and every error is a
`kos.Error` with a stable `code`:

```python
m.set_param("time_limit", 60)
m.set_param("mip_relative_gap", 1e-6)
try:
    m.set_param("no_such_parameter", 1)
except kos.Error as e:
    print(e.code)                        # unknown_parameter
```

## The Community edition

This package is the KOS Community edition: it solves models of up to **2,000 rows (constraints) and 2,000 columns
(variables)**. A larger model can be read, loaded, inspected, changed and written, but `solve()` (and `compute_iis()`)
raises `kos.Error` with code `size_limit` without solving. For larger models, see the other editions at
https://katsenia.com/pricing.html.

## Documentation

The reference of the Python module, the C library and the command line: https://katsenia.com/help.html. Questions:
support@katsenia.com.

## License

KOS is proprietary software of Katsenia SpA: © Katsenia SpA, all rights reserved. Its use is governed by the KOS
End-User License Agreement, https://katsenia.com/license.html (see the LICENSE file in this package). The open-source
components it includes are listed, with their licenses, in THIRD_PARTY_LICENSES.txt.

