Skip to content

Example 08: Fuzzy BWM with sezgi

The fuzzy best-worst method of Guo and Zhao, solved with the jDE metaheuristic from sezgi.

Needs an extra

This example uses the sezgi bridge (pip install "bulanik[sezgi]"). The documentation build installs it, so the output below is real.

Source

examples/08_fuzzy_bwm_sezgi.py
"""Fuzzy best-worst method (Guo & Zhao 2017) solved with sezgi's jDE.

Needs the sezgi extra: pip install "bulanik[sezgi]".
"""

import math

from bulanik.mcdm.bwm import fuzzy_bwm_consistency_index
from bulanik.scales import FUZZY_BWM_TFN as S
from bulanik.sezgi import FuzzyBWMProblem

# C1 is the best criterion and C3 the worst, rated with Guo & Zhao's linguistic terms.
best_to_others = {"C1": S["EI"], "C2": S["FI"], "C3": S["VI"]}
others_to_worst = {"C1": S["VI"], "C2": S["FI"], "C3": S["EI"]}

result = FuzzyBWMProblem(best_to_others, others_to_worst).solve(seed=1)
print(f"best = {result.best}, worst = {result.worst}")
for c, w in result.fuzzy_weights.items():
    print(f"  {c}: ({w.l:.4f}, {w.m:.4f}, {w.u:.4f}) -> {result.weights[c]:.4f}")
print(f"k* = {result.xi:.4f}, CR = {result.consistency_ratio:.4f}")

# Hand check: the middle values alone are the crisp BWM a12 = 2, a13 = 3, a23 = 2,
# whose optimum solves (2 - k)(2 - k) = 3 + k, i.e. k^2 - 5k + 1 = 0, k = (5 - sqrt 21) / 2.
# That is a lower bound on k*, and the fuzzy model attains it.
k_star = (5 - math.sqrt(21)) / 2
assert abs(result.xi - k_star) < 1e-3
# CI(VI) is the larger root of k^2 - 8k + 35/4 = 0 (u = 7/2): (8 + sqrt 29) / 2 = 6.69
assert abs(fuzzy_bwm_consistency_index(S["VI"]) - (8 + math.sqrt(29)) / 2) < 1e-12
assert result.ranking == ("C1", "C2", "C3")
assert abs(sum(result.weights.values()) - 1) < 1e-9

Output

Run when this page is built:

best = C1, worst = C3
  C1: (0.4780, 0.5359, 0.5647) -> 0.5311
  C2: (0.2419, 0.2992, 0.3656) -> 0.3007
  C3: (0.1590, 0.1670, 0.1823) -> 0.1682
k* = 0.2087, CR = 0.0312

What to notice

  • The comparisons are linguistic terms of the five-term fuzzy BWM scale.
  • Weights are triangular numbers; the last number in each line is its crisp value.
  • k* is the optimal inconsistency level and CR the consistency ratio derived from it. The run is seeded, so the output is reproducible.

Go further

Run it yourself: python examples/08_fuzzy_bwm_sezgi.py.