flutter_decision_making 1.0.1
flutter_decision_making: ^1.0.1 copied to clipboard
Dart package for lightweight decision making using the Analytic Hierarchy Process (AHP). Helps prioritize alternatives objectively via pairwise comparison.
A Flutter package for implementing multi-criteria decision-making using the Analytic Hierarchy Process (AHP).
Easily manage criteria, alternatives, pairwise comparisons, consistency checks, and final decision scoring โ all in one unified package.
๐ง This package implements the Analytic Hierarchy Process (AHP) originally developed by Thomas L. Saaty.
โจ Features #
- ๐ Generate hierarchy from criteria and alternatives
- โ๏ธ Pairwise comparisons using Saaty's 1โ9 scale
- โ Consistency Ratio check to ensure logical consistency
- ๐ Eigenvector and final score calculation
- ๐ง Customizable and extendable architecture
- ๐ Built-in performance profiling (dev-friendly)
๐ Getting Started #
Initialize the FlutterDecisionMaking instance before using other methods.
late FlutterDecisionMaking _decisionMaking;
@override
void initState() {
super.initState();
_decisionMaking = FlutterDecisionMaking();
๐ Usage Guide #
๐ ๏ธ User Role #
1. ๐งฑ Define Criteria and Alternatives #
Each item must have a unique ID. If not provided, the package auto-generates it.
final criteria = [
Criteria(id: 'c1', name: 'Price'),
Criteria(id: 'c2', name: 'Quality'),
];
final alternatives = [
Alternative(id: 'a1', name: 'Product A'),
Alternative(id: 'a2', name: 'Product B'),
];
2. ๐งฎ Identification, Generate Hierarchy and Generate Pairwise Comparison Input #
Validate and prepare your inputs.
await _decisionMaking.generateHierarchyAndPairwiseTemplate(
listCriteria: criteria,listAlternative: alternatives);
After the process is complete, a paired matrix list will be generated:
List<PairwiseComparisonInput<Criteria>> inputCriteria;
List<PairwiseAlternativeInput> inputAlternative;
Please ensure that all priority weights are filled in before proceeding to the next step.
3. ๐ Generate Result #
Call this method to compute the final scores based on input data.
await _decisionMaking.generateResult()
๐ ๏ธ AHP Role #
on generate result, AHP will do
1. ๐งฎ Generate Pairwise Matrix #
Create a pairwise comparison matrix from criteria or alternatives input.
2. ๐งฎ Calculate Approximate Eigenvector #
Calculate priority weights (eigenvector) from the pairwise matrix.
3. ๐งฎ Check Consistency Ratio #
Compute and verify matrix consistency using the Consistency Ratio (CR).
4. ๐งฎ Calculate Result #
Calculate final scores for alternatives based on criteria and alternative weights, including consistency checks.
The result includes:
- Sorted list of alternative scores (
results) - Consistency status and ratio for criteria and alternatives
- Additional notes on consistency issues (if any)
final ahpResult = AhpResult(
results: ahpResultDetail..sort((a, b) => b.value.compareTo(a.value)), // list result
isConsistentCriteria: consistencyCriteria.isConsistent, /// boolean
consistencyCriteriaRatio: consistencyCriteria.ratio, // double
isConsistentAlternative: alternativesConsistency[0].isConsistent, // boolean
consistencyAlternativeRatio: alternativesConsistency[0].ratio, // double
note: note, // string
);
๐ Sample Case #
1. Pairwise Comparison Matrix #
| C1 | C2 | C3 | |
|---|---|---|---|
| C1 | 1.000 | 1.000 | 5.000 |
| C2 | 1.000 | 1.000 | 7.000 |
| C3 | 0.200 | 0.143 | 1.000 |
2. Matrix Normalization #
Column totals:
- C1: 2.200
- C2: 2.143
- C3: 13.000
Normalized matrix:
| C1 | C2 | C3 | |
|---|---|---|---|
| C1 | 0.455 | 0.467 | 0.385 |
| C2 | 0.455 | 0.467 | 0.538 |
| C3 | 0.091 | 0.067 | 0.077 |
3. Eigenvector (Priority of Each Criterion) #
| Criterion | Priority |
|---|---|
| C1 | 0.436 |
| C2 | 0.487 |
| C3 | 0.078 |
Interpretation:
- C2 is the most important criterion (48.7%)
- Followed by C1 (43.6%)
- C3 has a low weight (7.8%)
4. Consistency Ratio (CR) #
a. ฮป_max Value
ฮป_max = 3.078
b. Consistency Index (CI)
CI = (ฮป_max - n) / (n - 1) = (3.078 - 3) / 2 = 0.039
c. Consistency Ratio (CR)
Random Index (RI) for n=3 is 0.58
CR = CI / RI = 0.039 / 0.58 โ 0.067
5. Conclusion #
- Consistency Ratio (CR) = 0.067 < 0.1, which means the level of consistency is still acceptable.
- The criterion weights can be used for further decision-making.
โ๏ธ Architecture Notes #
- ๐งฉ Uses immutable data classes (
Criteria,Alternative, etc.) - ๐ Unique ID generation via internal
_helper - โฑ Integrated performance profiling using
Stopwatch - ๐งผ Strong validation with helpful exceptions:
- Duplicate IDs
- Empty inputs
- Invalid matrix dimensions
๐ Performance Profiling #
Every major method logs:
- โฑ Start and end timestamps.
- โ Execution duration (in milliseconds).
Great for debugging and optimization during development.
๐ Important #
Because the calculations are performed on the client side, the total number of criteria and alternatives may impact your deviceโs performance. Please use the data wisely.
๐โโ๏ธ Contributing #
We welcome all contributions and suggestions!
๐ Open an issue or submit a pull request at GitHub Repo