mdp-solver-ic
A Python library of algorithms for solving infinite-horizon, discounted Markov Decision Processes (MDPs), with a performance-critical core written in C++ (via pybind11).
Implements:
- Value Iteration (Jacobi and Gauss-Seidel variants)
- Policy Iteration
- Q-Learning and SARSA (model-free reinforcement learning)
Installation
pip install mdp-solver-ic
Building from source requires a C++17 compiler (the extension is compiled at install time):
git clone https://github.com/LuccaGiannelli/mdp-solver.git
cd mdp-solver
pip install .
Basic usage
from mdp import MDP
S = [0, 1, 2] # states
A = [0, 1, 2] # actions
def Pt(sn, a, sn1):
# returns P(sn1 | sn, a)
...
def rt(sn, a, sn1):
# returns the reward
...
problem = MDP(S, A, Pt, rt)
# Value Iteration
problem.VI(gamma=0.9, tol=1e-6)
problem.print_results()
# Policy Iteration
problem.PI(gamma=0.9, tol=1e-6)
problem.print_results()
See examples/basic_example.py for a complete example (a machine maintenance problem).
Available algorithms
| Method | Description |
|---|---|
VI |
Value Iteration (Jacobi) |
VIGS |
Value Iteration with Gauss-Seidel |
PI |
Policy Iteration |
QLearning |
Q-Learning (off-policy TD control) |
SARSA |
SARSA (on-policy TD control) |
Common parameters
| Parameter | Description |
|---|---|
gamma |
Discount factor (0 ≤ γ < 1) |
tol |
Convergence tolerance |
max_iter |
Maximum number of iterations |
v0 |
Initial value vector (optional) |
verbose |
Print progress on completion |
norm_type |
0 = relative sup norm, 1 = sup norm, 2 = euclidean norm |
epsilon |
Final epsilon for the epsilon-greedy policy (Q-Learning / SARSA) |
alpha |
Learning rate (Q-Learning / SARSA) |
How it works
You define the state space S, action space A, a transition probability function Pt(sn, a, sn1), and a reward function rt(sn, a, sn1). The constructor enumerates all feasible transitions into a CSV (sn,a,sn1,prob,reward) and loads it into a NumPy array; the algorithms then hand that array to the C++ core, which does the inner loops with direct memory access for performance.
After solving, results are available as:
| Attribute | Description |
|---|---|
value |
optimal value for each state |
policy |
optimal action for each state |
time |
execution time (seconds) |
n_iterations |
number of iterations to convergence |
Adding a new algorithm
- Create
mdp/algorithms/new_algo.pywith a functiondef NewAlgo(self, ...): - Import it in
mdp/algorithms/__init__.py - Attach it to the class in
mdp/core.py:NewAlgo = NewAlgo
Tests
pip install pytest
pytest tests/
About
mdp-solver-ic was developed as part of an undergraduate research project ("Iniciação Científica") titled Programação Rodoviária.
License
TBD.
Metadata
Release files for mdp-solver-ic 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mdp_solver_ic-1.0.0.tar.gz | 12.1 kB | Without provenance | Details for mdp_solver_ic-1.0.0.tar.gz |
Release files / mdp_solver_ic-1.0.0.tar.gz
| Download URL | mdp_solver_ic-1.0.0.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
44ce68ee4abc2c4e9b54605bdf449130794593991a59cd2a43c9cdd07778a809
|
|
BLAKE2b-256 checksum How to use checksums |
1c55a7ac5426ad2b1b90ca3cd21d67e7604fda4529750adb224c4de8398cd158
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Security for mdp-solver-ic 1.0.0
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.