flutter_decision_making 1.0.2 copy "flutter_decision_making: ^1.0.2" to clipboard
flutter_decision_making: ^1.0.2 copied to clipboard

Dart package for lightweight decision making using the Analytic Hierarchy Process (AHP). Helps prioritize alternatives objectively via pairwise comparison.

pub version

A Flutter package for implementing 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)

πŸ“š Usage Guide #

Initialize the FlutterDecisionMaking instance before using other methods.

late FlutterDecisionMaking _decisionMaking;

 @override
  void initState() {
    super.initState();
    _decisionMaking = FlutterDecisionMaking();
 }

πŸ› οΈ 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)
class AhpResult {
  final List<AhpResultDetail> results;
  final bool isConsistentCriteria;
  final double consistencyCriteriaRatio;
  final bool isConsistentAlternative;
  final double consistencyAlternativeRatio;
  final String? note;

  AhpResult({
    required this.results,
    required this.isConsistentCriteria,
    required this.consistencyCriteriaRatio,
    required this.isConsistentAlternative,
    required this.consistencyAlternativeRatio,
    this.note,
  });
}

class AhpResultDetail {
  final String? id;
  final String name;
  final double value;

  AhpResultDetail({
    required this.id,
    required this.name,
    required this.value,
  });
}

πŸ” 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

1
likes
0
points
194
downloads

Publisher

unverified uploader

Weekly Downloads

Dart package for lightweight decision making using the Analytic Hierarchy Process (AHP). Helps prioritize alternatives objectively via pairwise comparison.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on flutter_decision_making