Metadata-Version: 2.4
Name: milpython
Version: 0.6.4
Summary: Build and solve linear and mixed-integer optimization models for time series
Author-email: Hannes Hanse <hannes.hanse@tu-clausthal.de>
License-Expression: MIT
Project-URL: Homepage, https://github.com/hanneshanse/MilPython
Project-URL: Issues, https://github.com/hanneshanse/MilPython/issues
Project-URL: Repository, https://github.com/hanneshanse/MilPython.git
Keywords: MILP,optimization,time series,Gurobi,SciPy
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
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: Topic :: Scientific/Engineering
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: gurobipy>=10
Requires-Dist: matplotlib>=3.5
Requires-Dist: numpy>=1.23
Requires-Dist: scipy>=1.9
Requires-Dist: sympy>=1.10
Provides-Extra: cplex
Requires-Dist: cplex; extra == "cplex"
Provides-Extra: excel
Requires-Dist: openpyxl>=3.1; extra == "excel"
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: openpyxl>=3.1; extra == "dev"
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: twine>=5; extra == "dev"
Dynamic: license-file

# MilPython

MilPython is a small Python framework for formulating linear and mixed-integer
optimization models with time-dependent variables. Models are assembled once
and can be solved with Gurobi, SciPy/HiGHS, or an optional CPLEX installation.

## Installation

```console
python -m pip install milpython
```

Gurobi requires a valid license for the selected model size. Excel export is an
optional feature:

```console
python -m pip install "milpython[excel]"
```

## Minimal example

```python
from MilPython import LPInputdata, LPMain, LPObject, Solver


class Dispatch(LPObject, LPMain):
    def __init__(self, prices):
        inputdata = LPInputdata({"price": prices}, dt_h=1, verbose=False)
        LPObject.__init__(self, inputdata, name="dispatch", comment="")
        self.power = self.add_time_var("power", unit="kW", lb=2, ub=10)
        LPMain.__init__(self, inputdata)

    def def_equations(self):
        self.add_eq([[self.power, 1]], ">", 2)

    def def_targetfun(self):
        self.add_var_targetfun(self.power, self.inputdata.data["price"])


model = Dispatch([3, 1, 2])
model.optimize(solver=Solver.SCIPY)
print(model.power.result)
```

The [`examples`](examples/) directory contains executable examples for LP and
MILP models, automated switches, decision variables, solver selection, and
working with the local source checkout.

## Running the examples

Install the repository in editable mode and run an example from the repository
root:

```console
python -m pip install -e ".[dev]"
python examples/01_basic_lp/basic_lp.py
```

See [`examples/README.md`](examples/README.md) for an overview of all examples.

## Development

```console
python -m pip install -e ".[dev]"
python -m pytest
python -m build
python -m twine check dist/*
```

MilPython is under active development. Please report reproducible problems via
the GitHub issue tracker.
