Example 03: Buckley fuzzy AHP¶
Three criteria compared with the Saaty triangular scale, weighted with Buckley's geometric-mean method.
Source¶
examples/03_fuzzy_ahp.py
"""Buckley fuzzy AHP: three criteria compared with the Saaty triangular scale."""
from bulanik.mcdm import fuzzy_ahp
from bulanik.scales import SAATY_TFN
criteria = ["cost", "quality", "delivery"]
# upper triangle as Saaty terms; the lower triangle is the reciprocal
judgements = {(0, 1): "3", (0, 2): "5", (1, 2): "2"}
matrix = [[SAATY_TFN["1"] for _ in criteria] for _ in criteria]
for (i, j), term in judgements.items():
matrix[i][j] = SAATY_TFN[term]
matrix[j][i] = SAATY_TFN.reciprocal(term)
result = fuzzy_ahp(matrix, criteria)
for name in criteria:
print(f"{name}: weight {result.weights[name]:.4f}, fuzzy {result.fuzzy_weights[name]}")
print(f"CR = {result.consistency_ratio:.4f}")
assert abs(sum(result.weights.values()) - 1.0) < 1e-9
assert result.consistency_ratio < 0.1
assert result.ranking == ("cost", "quality", "delivery")
Output¶
Run when this page is built:
cost: weight 0.6374, fuzzy TFN(l=0.42926064565143157, m=0.6483290138222366, u=0.9578178810370901)
quality: weight 0.2333, fuzzy TFN(l=0.1352086308369257, m=0.2296507940626371, u=0.3801102779880572)
delivery: weight 0.1294, fuzzy TFN(l=0.08189679580747211, m=0.12202019211512621, u=0.20918274741227957)
CR = 0.0928
What to notice¶
- Only the upper triangle of the comparison matrix is typed; the lower triangle is the reciprocal.
- Each criterion gets a fuzzy weight and a crisp one; the crisp weights sum to 1.
- The consistency ratio (CR) is reported; a value under about 0.1 is conventionally acceptable.
Go further¶
- Guide: Weighting
- API:
bulanik.mcdm
Run it yourself: python examples/03_fuzzy_ahp.py.