A Python implementation of Saaty's Analytic Hierarchy Process (AHP) and Analytic Network Process (ANP) for multi-criteria decision making
Project description
SaatyPy
SaatyPy is a Python package for Analytic Hierarchy Process (AHP) and Analytic Network Process (ANP) decision modeling.
It provides robust, flexible, and well-tested tools for multi-criteria decision analysis, supporting both academic and business use cases.
The package is named in honor of Thomas L. Saaty, the originator of AHP and ANP methodologies.
His pioneering work laid the foundation for modern multi-criteria decision making.
Features
- AHP and ANP model builders
- Pairwise comparison matrices
- Consistency checks and error handling
- Matrix limiters and normalization utilities
- Reporting and result export
- Extensible and type-safe API
Modules Overview
- saatypy.ahp: Build and solve AHP models (hierarchies, priorities, reporting)
- saatypy.anp: Build and solve ANP models (networks, supermatrices, limiters)
- saatypy.components: Core types, pairwise comparisons, error classes, math utilities
- saatypy.reporting: Generate reports and export results
Installation
pip install saatypy
Or clone the repository and install locally:
git clone https://github.com/ehsanAhmadzadeh/saatypy.git
cd saatypy
pip install .
Quick Start (AHP)
from saatypy.ahp import AHPBuilder
model = (AHPBuilder()
.add_criteria(["price", "quality", "service"])
.add_alternatives(["A", "B", "C"])
.build())
model.set_criteria_weights({"price": 0.5, "quality": 0.3, "service": 0.2})
for crit in ["price", "quality", "service"]:
model.set_alt_priorities(crit, {
("A", "B"): 2.0,
("A", "C"): 3.0,
("B", "C"): 1.5
})
priorities, labels = model.alternative_priorities()
print(dict(zip(labels, priorities)))
Quick Start (ANP)
from saatypy.anp import ANPBuilder
from saatypy.components.pairwise import PairwiseComparison
model = (ANPBuilder()
.add_cluster("criteria", ["C1", "C2"])
.add_alternatives(["A", "B"])
.build())
model.set_cluster_weights({"criteria": 0.6, "Alternatives": 0.4})
block_alt_given_crit = {
"C1": PairwiseComparison.from_judgments(["A", "B"], {("A", "B"): 4.0}),
"C2": PairwiseComparison.from_judgments(["A", "B"], {("A", "B"): 3.0/7.0}),
}
model.add_block("Alternatives", "criteria", block_alt_given_crit)
model.add_block_uniform("criteria", "criteria")
priorities, labels = model.alternative_priorities()
print(dict(zip(labels, priorities)))
Error Handling
SaatyPy provides detailed error messages for invalid inputs, missing weights, and matrix inconsistencies:
from saatypy.ahp import AHPBuilder
from saatypy.components.errors import NormalizationError
model = AHPBuilder().add_criteria(["A", "B"]).add_alternatives(["X", "Y"]).build()
try:
model.set_criteria_weights({"invalid": 1.0})
except NormalizationError as e:
print("Error:", e)
Reporting
Extract results directly from your model:
report = model.to_report_data()
print(report["criteria_weights"])
print(report["global_priorities"])
print(report["ranking_str"])
Saving Reports
You can save a formatted report for any model using the ReportManager:
from saatypy.reporting.report import ReportManager
manager = ReportManager() # Default: Markdown format, saves to 'reports/'
report_path = manager.save(model) # model can be AHPModel or ANPModel
print(f"Report saved to: {report_path}")
# To use plain text format:
from saatypy.reporting.report import PlainRenderer
manager = ReportManager(renderer=PlainRenderer())
report_path = manager.save(model, path="my_report.txt")
- By default, reports are saved in Markdown format to the
reports/directory. - You can specify a custom path, file name, or renderer.
- The filename will include a timestamp unless you set
add_timestamp=False.
Advanced Usage
- Hierarchical criteria (AHP)
- Custom limiters (ANP)
- Extend with new adapters or reporting formats
- Use math utilities for normalization and consistency checks
Documentation
References
- Saaty, T. L. (1980). The Analytic Hierarchy Process. McGraw-Hill.
- Saaty, T. L. (1996). Decision Making with Dependence and Feedback: The Analytic Network Process. RWS Publications.
- Saaty, T. L. (2008). Decision making with the analytic hierarchy process. International Journal of Services Sciences, 1(1), 83–98.
- Saaty, T. L. (2005). Theory and Applications of the Analytic Network Process. RWS Publications.
Contributing
See CONTRIBUTING.md for guidelines.
License
See LICENSE.
Changelog
See CHANGELOG.md.
For more details, see the documentation in the docs/ folder.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file saatypy-0.1.1.tar.gz.
File metadata
- Download URL: saatypy-0.1.1.tar.gz
- Upload date:
- Size: 27.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56389b785c788bbdddc8c95fd98354ceeee9d56732c4c40313bc38b573c8792b
|
|
| MD5 |
e24ff102d7d9cbc7453c52ad56daf413
|
|
| BLAKE2b-256 |
909156e92fb767a64f291bf3a6b221fc7e0e5ed4488114362d9327a934eb66c3
|
File details
Details for the file saatypy-0.1.1-py3-none-any.whl.
File metadata
- Download URL: saatypy-0.1.1-py3-none-any.whl
- Upload date:
- Size: 25.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2c68c0b604a2b556797719b8cc63b4d497e29b9572f3edb79edada71fc63c91
|
|
| MD5 |
81291ab47601b807f143be63d9356fca
|
|
| BLAKE2b-256 |
ccb74e8f0dcf44f9db9d4e08b6c38606b68452a235f3eb7743b99b7be3e92133
|