Metadata-Version: 2.4
Name: mpfit
Version: 0.1.0
Summary: MPFit - A Python Library for Learning Approximate Solutions to Multiparametric Programming and Generalized Nash Equilibrium Problems.
Author-email: Alberto Bemporad <alberto.bemporad@imtlucca.it>
Project-URL: Homepage, https://github.com/bemporad/mpfit
Keywords: multiparametric programming,generalized Nash equilibrium,neural networks,optimization,learning
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: jax
Requires-Dist: jaxopt
Requires-Dist: optax
Requires-Dist: scipy
Requires-Dist: joblib
Requires-Dist: tqdm
Requires-Dist: nashopt
Dynamic: license-file

<img src="http://cse.lab.imtlucca.it/~bemporad/images/mpfit-logo.png" alt="mpfit" width=40%/>

# mpfit
### A Python library for Learning Approximate Solutions to Multiparametric Programming and Generalized Nash Equilibrium Problems

This repository includes a library for learning approximate solutions to multiparametric programming and generalized Nash equilibrium problems (GNEPs). Given a parametric optimization problem or a parametric GNEP, the library attempts fitting a solution model over a given set of parameters. 

For more details about the mathematical formulations implemented in the library, see the 
[arXiv preprint](#citation).

---
## Installation

~~~python
pip install mpfit
~~~

## Usage

`mpfit` provides a general class `MultiParametricFit` to define rather arbitrary multiparametric GNE problems with $N$ players ($N>1$) and standard multiparametric programming problems ($N=1$).

For specific problems, the following classes are provided:

- **`LQ_GNEP`** — (multi-agent) GNEP with convex quadratic objectives and shared linear constraints
- **`QCQ_GNEP`** — (multi-agent) GNEP with convex quadratic objectives and shared quadratic and linear constraints
- **`NL_GNEP`** — general nonlinear GNEPs
- **`MPQP`** — (single-agent) multiparametric QPs
- **`MPQCQP`** — (single-agent) multiparametric QCQPs
- **`MPNLP`** - (single agent) multiparametric NLPs

### Example
Solve the following LQ-GNEP:

$$\min_{x_i}\ \tfrac{1}{2} x^T Q^{i} x + (c^i + F^i p)^T x \quad \text{s.t.} \quad Ax \leq b + Sp,\quad lb \le x \le ub$$

```python
from mpfit import LQ_GNEP

# Define the problem, using `nashopt`'s syntax where Q = list of N dim(x)-by-dim(x) matrices, 
# c = list of N vectors of dimension dim(x)
mp = LQ_GNEP(N, sizes, npar, Q, c, F, A, b, S, lb, ub, pmin, pmax, ncon)

# Stage 1: generate data and fit value functions
mp.setup(N_train=1000, N_val=1000)

# Stage 2: fit the solution network
mp.solve()

# Evaluate on test data
res = mp.test(N_test=1000)

# Predict GNE for a new parameter p
x_hat = mp.predict(p)

# Inspect the trained networks
sol_weights = mp.solution_network() 
vf_weights = mp.value_function_network()
```

## Citation

```
@article{MPFit,
    author={A. Bemporad and T. Tatarenko},
    title={Learning Approximate Solutions to Multiparametric Generalized {Nash} Equilibrium Problems},
    journal = {arXiv preprint},
    note = {\url{https://github.com/bemporad/mpfit}},
    year=2026
}
```

---
## Related packages

<a href="https://github.com/bemporad/nashopt">**nashopt**</a> a Python library for computing generalized Nash equilibria and solving game-design and game-theoretic control problems.

<a href="https://github.com/bemporad/nash-mpqp">**nash-mpqp**</a> a Python package for solving parametric generalized Nash equilibrium problems with quadratic objectives and coupled linear inequality constraints in explicit form. 

<a href="https://github.com/bemporad/gnep-learn">**gnep-learn**</a>
A Python package for solving Generalized Nash Equilibrium Problems by active learning of best-response models.

---
## License

Apache 2.0

(C) 2026 A. Bemporad

## Acknowledgement
This work was funded by the European Union (ERC Advanced Research Grant COMPACT, No. 101141351). Views and opinions expressed are however those of the authors only and do not necessarily reflect those of the European Union or the European Research Council. Neither the European Union nor the granting authority can be held responsible for them.

<p align="center">
<img src="erc-logo.png" alt="ERC" width="400"/>
</p>
