Metadata-Version: 2.4
Name: markov-solver
Version: 2.0.0
Summary: Generate modern CLIs from OpenAPI specifications
Author-email: Giacomo Marciani <giacomo.marciani@gmail.com>
License: MIT
Project-URL: Homepage, https://github.com/gmarciani/markov-solver
Project-URL: Repository, https://github.com/gmarciani/markov-solver
Project-URL: Issues, https://github.com/gmarciani/markov-solver/issues
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click~=8.3.1
Requires-Dist: colored~=2.3.1
Requires-Dist: graphviz~=0.21
Requires-Dist: networkx~=3.6.1
Requires-Dist: numpy~=2.4.2
Requires-Dist: pydantic~=2.12.5
Requires-Dist: pyfiglet~=1.0.4
Requires-Dist: pyyaml~=6.0.3
Requires-Dist: scipy~=1.17.0
Requires-Dist: sympy~=1.14.0
Provides-Extra: dev
Requires-Dist: autoflake~=2.3; extra == "dev"
Requires-Dist: black~=26.1; extra == "dev"
Requires-Dist: build~=1.4; extra == "dev"
Requires-Dist: flake8~=7.3; extra == "dev"
Requires-Dist: mypy~=1.19; extra == "dev"
Requires-Dist: pre-commit~=4.5; extra == "dev"
Requires-Dist: pytest~=9.0; extra == "dev"
Requires-Dist: pytest-cov~=7.0; extra == "dev"
Requires-Dist: pytest-resource-path~=1.4; extra == "dev"
Requires-Dist: assertpy~=1.1; extra == "dev"
Requires-Dist: tox~=4.34; extra == "dev"
Requires-Dist: twine~=6.2; extra == "dev"
Requires-Dist: types-PyYAML~=6.0; extra == "dev"
Requires-Dist: types-requests~=2.32; extra == "dev"
Provides-Extra: docs
Requires-Dist: sphinx~=9.1; extra == "docs"
Requires-Dist: sphinx-click~=6.2; extra == "docs"
Requires-Dist: sphinx-rtd-theme~=3.1; extra == "docs"
Requires-Dist: sphinx-new-tab-link~=0.8; extra == "docs"
Requires-Dist: autodoc_pydantic~=2.2; extra == "docs"
Dynamic: license-file

# MARKOV SOLVER

<div align="center">
<img src="https://raw.githubusercontent.com/gmarciani/markov-solver/main/resources/brand/banner.png" alt="markov-solver-banner" width="500">

[![PyPI version](https://img.shields.io/pypi/v/markov-solver.svg)](https://pypi.org/project/markov-solver)
[![Python versions](https://img.shields.io/pypi/pyversions/markov-solver.svg)](https://pypi.org/project/markov-solver)
[![License](https://img.shields.io/github/license/gmarciani/markov-solver.svg)](https://github.com/gmarciani/markov-solver/blob/main/LICENSE)
[![Build status](https://img.shields.io/github/actions/workflow/status/gmarciani/markov-solver/test.yaml?branch=main)](https://github.com/gmarciani/markov-solver/actions)
[![Tests](https://img.shields.io/github/actions/workflow/status/gmarciani/markov-solver/test.yaml?branch=main&label=tests)](https://github.com/gmarciani/markov-solver/actions)
[![Coverage](https://img.shields.io/codecov/c/github/gmarciani/markov-solver)](https://codecov.io/gh/gmarciani/markov-solver)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Downloads](https://img.shields.io/pypi/dm/markov-solver.svg)](https://pypi.org/project/markov-solver)

</div>

Solve Markov Chains in a glance.

## Table of Contents

- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [References](#references)
- [Issues](#issues)
- [License](#license)

## Features

- **Solve Markov Chains**: Compute steady-state probabilities for discrete-time Markov chains.
- **Symbolic Transition Rates**: Define transition rates using symbolic expressions with named parameters.
- **YAML Chain Definitions**: Define Markov chains in simple, human-readable YAML files.
- **Graph Visualization**: Automatically render Markov chain diagrams in SVG and PNG formats using Graphviz.
- **CLI and Library**: Use as a command-line tool or integrate directly into your Python projects.
- **Export Results**: Save solutions to TXT and CSV files for further analysis.
- **High Precision**: Calculations with 12 decimal places of floating-point precision.

## Installation

```shell
pip install markov-solver
```

## Usage

You can use `markov-solver` as a CLI or as a library in your project.

To use it as a CLI, check the recorded demo:

![Markov Chain Solver Demo](https://raw.githubusercontent.com/gmarciani/markov-solver/main/resources/brand/demo.gif)

To use it as a library, you can check the [examples](./examples).

In both cases you need to define the Markov Chain to solve.
See the instructions below to know how to do it.

### Chain with constant transition rates
Let us image that we want to solve the following Markov chain:

![Markov Chain Simple](https://raw.githubusercontent.com/gmarciani/markov-solver/main/resources/definitions/simple/simple.graph.svg)

We should create a YAML file that defines the chain:
```yaml
chain:
  - from: "Sunny"
    to: "Sunny"
    value: "0.9"

  - from: "Sunny"
    to: "Rainy"
    value: "0.1"

  - from: "Rainy"
    to: "Rainy"
    value: "0.5"

  - from: "Rainy"
    to: "Sunny"
    value: "0.5"
```

Then, running the following command:
```shell
markov-solver solve --definition [PATH_TO_DEFINITION_FILE]
```

We obtain the following result:
```
===============================================================
                     MARKOV CHAIN SOLUTION
===============================================================

                      states probability
Rainy.........................................0.166666666666667
Sunny.........................................0.833333333333333
```

### Chain with symbolic transition rates
Let us image that we want to solve the following Markov chain:

![Markov Chain Symbolic](https://raw.githubusercontent.com/gmarciani/markov-solver/main/resources/definitions/symbolic/symbolic.graph.svg)

We should create a YAML file that defines the chain:
```yaml
symbols:
  lambda: 1.5
  mu: 2.0

chain:
  - from: "0"
    to: "1"
    value: "lambda"

  - from: "1"
    to: "2"
    value: "lambda"

  - from: "2"
    to: "3"
    value: "lambda"

  - from: "3"
    to: "2"
    value: "3*mu"

  - from: "2"
    to: "1"
    value: "2*mu"

  - from: "1"
    to: "0"
    value: "mu"
```

Then, running the following command:
```shell
markov-solver solve --definition [PATH_TO_DEFINITION_FILE]
```

We obtain the following result:
```
===============================================================
                     MARKOV CHAIN SOLUTION
===============================================================

                      states probability
0.............................................0.475836431226766
1.............................................0.356877323420074
2.............................................0.133828996282528
3............................................0.0334572490706320
```

## References
* ["Discrete-Event Simulation", 2006, L.M. Leemis, S.K. Park](https://www.amazon.com/Discrete-Event-Simulation-Lawrence-M-Leemis/dp/0131429175)
* ["Performance Modeling and Design of Computer Systems, 2013, M. Harchol-Balter](https://www.amazon.com/Modeling-Simulation-Discrete-Event-Systems-ebook/dp/B00EMB3MXA)

## Issues

Please report any issues or feature requests on the [GitHub Issues](https://github.com/gmarciani/cli-wizard/issues) page.

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
