This release is a pre-release and may not be stable for production use.
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_flaggedwith itsflag_origin, orno_verdictwith itsno_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
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.
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:
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.
Metadata
Release files for kos-solver 1.0.0b1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kos_solver-1.0.0b1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ x86-64 | Details for kos_solver-1.0.0b1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| kos_solver-1.0.0b1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ ARM64 | Details for kos_solver-1.0.0b1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
Total release size: 3.2 MB
Release files / kos_solver-1.0.0b1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | kos_solver-1.0.0b1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
bd547644c1c7bcf36159f37389aab86a172ba5ad3214364c760417a5e8030ec1
|
|
BLAKE2b-256 checksum How to use checksums |
555b549e2512c799e4145d5ef64fee4a52709cabcf76ef463e4a7202f87eafc0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / kos_solver-1.0.0b1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | kos_solver-1.0.0b1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
b23dc057fbfa85cd93cfd797aa196f978bd05fd190f39c492e2b6f5c9b9c6b25
|
|
BLAKE2b-256 checksum How to use checksums |
38a78c0b1025f671fa833baf260a0197995fe2200d87f501d55b5f43349583ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for kos-solver 1.0.0b1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.