Analytic Hierarchy Process Calculator

.ahp-calculator-container { background-color: #f9f9f9; border: 1px solid #ccc; padding: 25px; border-radius: 8px; max-width: 800px; margin: 20px auto; font-family: Arial, sans-serif; } .ahp-calculator-container h2, .ahp-calculator-container h3 { color: #333; text-align: center; margin-bottom: 20px; } .ahp-calculator-container .input-group { margin-bottom: 20px; } .ahp-calculator-container .input-group label { display: block; margin-bottom: 5px; font-weight: bold; color: #555; } .ahp-calculator-container input[type="text"] { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px; box-sizing: border-box; } .ahp-calculator-container .comparison-grid { display: grid; grid-template-columns: 1fr 2fr 1fr; gap: 10px; align-items: center; margin-bottom: 15px; } .ahp-calculator-container .comparison-grid span { text-align: center; } .ahp-calculator-container select { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px; background-color: #fff; } .ahp-calculator-container fieldset { border: 1px solid #ddd; border-radius: 5px; padding: 15px; margin-bottom: 20px; } .ahp-calculator-container legend { font-weight: bold; color: #333; padding: 0 10px; } .ahp-calculator-container .scale-info { font-size: 0.9em; color: #666; background-color: #eef; padding: 10px; border-radius: 4px; margin-bottom: 15px; } .ahp-calculator-container button { display: block; width: 100%; padding: 15px; background-color: #0056b3; color: white; border: none; border-radius: 5px; font-size: 1.2em; cursor: pointer; margin-top: 20px; } .ahp-calculator-container button:hover { background-color: #004494; } #ahpResult { margin-top: 25px; padding: 20px; background-color: #e9f5e9; border: 1px solid #a3d3a3; border-radius: 5px; } #ahpResult h3 { margin-top: 0; } #ahpResult table { width: 100%; border-collapse: collapse; margin-top: 15px; } #ahpResult th, #ahpResult td { border: 1px solid #ccc; padding: 8px; text-align: left; } #ahpResult th { background-color: #f2f2f2; } .consistency-warning { color: #D8000C; background-color: #FFD2D2; padding: 10px; border-radius: 4px; font-weight: bold; }

Analytic Hierarchy Process (AHP) Calculator

Make complex decisions by systematically comparing criteria and alternatives. This calculator supports 3 criteria and 3 alternatives.

Step 1: Define Criteria & Alternatives
Step 2: Compare Criteria Importance
Comparison Scale:
1: Equally important | 3: Moderately more important | 5: Strongly more important | 7: Very strongly more important | 9: Extremely more important. (Values 2, 4, 6, 8 are intermediate).
Criterion 1 Extremely more important than Very strongly more important than Strongly more important than Moderately more important than Equally important to Moderately less important than Strongly less important than Very strongly less important than Extremely less important than Criterion 2
Criterion 1 Extremely more important than Very strongly more important than Strongly more important than Moderately more important than Equally important to Moderately less important than Strongly less important than Very strongly less important than Extremely less important than Criterion 3
Criterion 2 Extremely more important than Very strongly more important than Strongly more important than Moderately more important than Equally important to Moderately less important than Strongly less important than Very strongly less important than Extremely less important than Criterion 3
Step 3: Compare Alternatives for each Criterion

Comparisons for Criterion 1

Alternative 1 Extremely better than Very strongly better than Strongly better than Moderately better than Equally good as Moderately worse than Strongly worse than Very strongly worse than Extremely worse than Alternative 2
Alternative 1 Extremely better than Very strongly better than Strongly better than Moderately better than Equally good as Moderately worse than Strongly worse than Very strongly worse than Extremely worse than Alternative 3
Alternative 2 Extremely better than Very strongly better than Strongly better than Moderately better than Equally good as Moderately worse than Strongly worse than Very strongly worse than Extremely worse than Alternative 3

Comparisons for Criterion 2

Alternative 1 Extremely better than Very strongly better than Strongly better than Moderately better than Equally good as Moderately worse than Strongly worse than Very strongly worse than Extremely worse than Alternative 2
Alternative 1 Extremely better than Very strongly better than Strongly better than Moderately better than Equally good as Moderately worse than Strongly worse than Very strongly worse than Extremely worse than Alternative 3
Alternative 2 Extremely better than Very strongly better than Strongly better than Moderately better than Equally good as Moderately worse than Strongly worse than Very strongly worse than Extremely worse than Alternative 3

Comparisons for Criterion 3

Alternative 1 Extremely better than Very strongly better than Strongly better than Moderately better than Equally good as Moderately worse than Strongly worse than Very strongly worse than Extremely worse than Alternative 2
Alternative 1 Extremely better than Very strongly better than Strongly better than Moderately better than Equally good as Moderately worse than Strongly worse than Very strongly worse than Extremely worse than Alternative 3
Alternative 2 Extremely better than Very strongly better than Strongly better than Moderately better than Equally good as Moderately worse than Strongly worse than Very strongly worse than Extremely worse than Alternative 3
// Function to update labels dynamically as user types function updateLabels() { var c1 = document.getElementById('criterion1').value || 'Criterion 1'; var c2 = document.getElementById('criterion2').value || 'Criterion 2'; var c3 = document.getElementById('criterion3').value || 'Criterion 3'; var a1 = document.getElementById('alternative1').value || 'Alternative 1'; var a2 = document.getElementById('alternative2').value || 'Alternative 2'; var a3 = document.getElementById('alternative3').value || 'Alternative 3'; document.getElementById('crit1Label1').innerText = c1; document.getElementById('crit1Label2').innerText = c1; document.getElementById('crit2Label1').innerText = c2; document.getElementById('crit2Label2').innerText = c2; document.getElementById('crit3Label1').innerText = c3; document.getElementById('crit3Label2').innerText = c3; document.getElementById('compCrit1').innerText = 'Comparisons for ' + c1; document.getElementById('compCrit2').innerText = 'Comparisons for ' + c2; document.getElementById('compCrit3').innerText = 'Comparisons for ' + c3; var altLabels = [a1, a2, a3]; for (var i = 1; i <= 3; i++) { for (var j = 1; j <= 3; j++) { if (document.getElementById('alt' + j + 'Label_c' + i + '_1')) { document.getElementById('alt1Label_c' + i + '_1').innerText = a1; document.getElementById('alt2Label_c' + i + '_1').innerText = a2; document.getElementById('alt1Label_c' + i + '_2').innerText = a1; document.getElementById('alt3Label_c' + i + '_1').innerText = a3; document.getElementById('alt2Label_c' + i + '_2').innerText = a2; document.getElementById('alt3Label_c' + i + '_2').innerText = a3; } } } } // Attach event listeners to update labels document.getElementById('criterion1').addEventListener('keyup', updateLabels); document.getElementById('criterion2').addEventListener('keyup', updateLabels); document.getElementById('criterion3').addEventListener('keyup', updateLabels); document.getElementById('alternative1').addEventListener('keyup', updateLabels); document.getElementById('alternative2').addEventListener('keyup', updateLabels); document.getElementById('alternative3').addEventListener('keyup', updateLabels); // Initial call to set labels updateLabels(); function calculateWeightsAndCR(matrix) { var n = matrix.length; var colSums = new Array(n).fill(0); for (var j = 0; j < n; j++) { for (var i = 0; i < n; i++) { colSums[j] += matrix[i][j]; } } var normalizedMatrix = JSON.parse(JSON.stringify(matrix)); // Deep copy for (var i = 0; i < n; i++) { for (var j = 0; j < n; j++) { if (colSums[j] === 0) return null; // Avoid division by zero normalizedMatrix[i][j] /= colSums[j]; } } var weights = new Array(n).fill(0); for (var i = 0; i < n; i++) { var rowSum = 0; for (var j = 0; j < n; j++) { rowSum += normalizedMatrix[i][j]; } weights[i] = rowSum / n; } // Consistency Calculation var weightedSumVector = new Array(n).fill(0); for (var i = 0; i < n; i++) { for (var j = 0; j < n; j++) { weightedSumVector[i] += matrix[i][j] * weights[j]; } } var lambdaSum = 0; for (var i = 0; i 2) ? CI / RI[n] : 0; return { weights: weights, cr: CR }; } function buildMatrix(val12, val13, val23) { var v12 = parseFloat(val12); var v13 = parseFloat(val13); var v23 = parseFloat(val23); if (isNaN(v12) || isNaN(v13) || isNaN(v23)) return null; var matrix = [ [1, v12, v13], [1 / v12, 1, v23], [1 / v13, 1 / v23, 1] ]; return matrix; } function calculateAHP() { var resultDiv = document.getElementById('ahpResult'); resultDiv.innerHTML = "; // Get names var goal = document.getElementById('goal').value || 'Decision'; var critNames = [ document.getElementById('criterion1').value || 'Criterion 1', document.getElementById('criterion2').value || 'Criterion 2', document.getElementById('criterion3').value || 'Criterion 3' ]; var altNames = [ document.getElementById('alternative1').value || 'Alternative 1', document.getElementById('alternative2').value || 'Alternative 2', document.getElementById('alternative3').value || 'Alternative 3' ]; // 1. Calculate Criteria Weights var critMatrix = buildMatrix( document.getElementById('c1_vs_c2').value, document.getElementById('c1_vs_c3').value, document.getElementById('c2_vs_c3').value ); if (!critMatrix) { resultDiv.innerHTML = 'Error: Invalid input for criteria comparisons.'; return; } var critResult = calculateWeightsAndCR(critMatrix); if (!critResult) { resultDiv.innerHTML = 'Error: Calculation failed for criteria.'; return; } var criteriaWeights = critResult.weights; var criteriaCR = critResult.cr; // 2. Calculate Alternative Scores for each Criterion var altScores = []; var altCRs = []; for (var i = 1; i <= 3; i++) { var altMatrix = buildMatrix( document.getElementById('a1_vs_a2_c' + i).value, document.getElementById('a1_vs_a3_c' + i).value, document.getElementById('a2_vs_a3_c' + i).value ); if (!altMatrix) { resultDiv.innerHTML = 'Error: Invalid input for alternative comparisons for ' + critNames[i-1] + '.'; return; } var altResult = calculateWeightsAndCR(altMatrix); if (!altResult) { resultDiv.innerHTML = 'Error: Calculation failed for alternatives under ' + critNames[i-1] + '.'; return; } altScores.push(altResult.weights); altCRs.push(altResult.cr); } // 3. Synthesize Final Scores var finalScores = [0, 0, 0]; for (var i = 0; i < 3; i++) { // For each alternative for (var j = 0; j < 3; j++) { // For each criterion finalScores[i] += altScores[j][i] * criteriaWeights[j]; } } // 4. Rank Alternatives var rankedAlternatives = []; for (var i = 0; i < 3; i++) { rankedAlternatives.push({ name: altNames[i], score: finalScores[i] }); } rankedAlternatives.sort(function(a, b) { return b.score – a.score; }); // 5. Display Results var html = '

Results for: ' + goal + '

'; // Criteria Weights Table html += '

Criteria Importance

'; html += ''; for (var i = 0; i < 3; i++) { html += ''; } html += '
CriterionWeight
' + critNames[i] + '' + (criteriaWeights[i] * 100).toFixed(2) + '%
'; html += 'Criteria Consistency Ratio (CR): ' + criteriaCR.toFixed(4) + "; if (criteriaCR > 0.1) { html += 'Warning: Your criteria comparisons are inconsistent (CR > 0.1). You should review your judgments.'; } // Final Ranking Table html += '

Final Ranking

'; html += ''; for (var i = 0; i < rankedAlternatives.length; i++) { html += ''; } html += '
RankAlternativeFinal Score
' + (i + 1) + '' + rankedAlternatives[i].name + '' + (rankedAlternatives[i].score * 100).toFixed(2) + '%
'; html += 'The best choice is: ' + rankedAlternatives[0].name + ''; resultDiv.innerHTML = html; }

Understanding the Analytic Hierarchy Process (AHP)

The Analytic Hierarchy Process (AHP) is a powerful decision-making framework developed by Dr. Thomas L. Saaty in the 1970s. It helps individuals and groups tackle complex decisions by breaking them down into a structured hierarchy, quantifying subjective judgments, and synthesizing them to determine the best possible outcome. It's particularly useful when a decision involves multiple, often conflicting, criteria.

How This AHP Calculator Works

This calculator simplifies the AHP method for a decision involving up to three criteria and three alternatives. Here's a breakdown of the steps you'll take:

  • Define Your Goal: Clearly state the decision you need to make (e.g., "Choose a vacation destination").
  • Define Criteria and Alternatives: List the factors that are important to your decision (criteria) and the options you are choosing from (alternatives).
  • Make Pairwise Comparisons: This is the core of AHP. You will compare each element against every other element at the same level.
    • First, you compare the importance of your criteria against each other. For example, is 'Cost' more important than 'Activities'?
    • Then, for each criterion, you compare how well your alternatives perform. For example, regarding 'Cost', is 'Paris' better or worse than 'Tokyo'?
  • Calculate Decision: The calculator takes your comparisons, converts them into numerical values, and runs the AHP algorithm to calculate the final scores and rank your alternatives.

The AHP Steps in Detail

1. Structure the Hierarchy

A decision problem is structured like a pyramid:

  • Level 1 (Top): The overall goal of the decision.
  • Level 2 (Middle): The criteria (or sub-criteria) that contribute to the goal.
  • Level 3 (Bottom): The alternatives or choices available.

2. Make Pairwise Comparisons and Saaty's Scale

AHP uses a 1-to-9 scale to capture the intensity of preference between two items. When you compare Item A to Item B, you are answering the question: "How much more important/preferred is A than B?"

  • 1 – Equal Importance: Two items contribute equally to the objective.
  • 3 – Moderate Importance: Experience and judgment slightly favor one item over another.
  • 5 – Strong Importance: An item is strongly favored and its dominance is demonstrated in practice.
  • 7 – Very Strong Importance: An item is very strongly dominant.
  • 9 – Extreme Importance: The evidence favoring one item over another is of the highest possible order of affirmation.

Values of 2, 4, 6, and 8 are used for intermediate judgments. If Item B is more important than Item A, you use the reciprocal value (e.g., 1/3, 1/5, etc.). Our calculator handles this automatically based on your selection.

3. Calculate Weights and Check for Consistency

Once all comparisons are made, the calculator creates a comparison matrix for each set of judgments. It then performs calculations to derive a "priority vector" or a set of weights for each criterion and alternative. A crucial part of this step is calculating the Consistency Ratio (CR). This ratio measures how consistent your judgments were. A CR of 0.10 or less is considered acceptable. If your CR is higher, it indicates contradictory judgments (e.g., saying A > B, B > C, but C > A), and you should reconsider your comparisons.

A Practical Example: Choosing a New Laptop

  • Goal: Choose the best new laptop.
  • Criteria: Price, Performance, Portability.
  • Alternatives: Laptop A (Budget), Laptop B (Gaming), Laptop C (Ultrabook).

Criteria Comparison:

  • You decide Price is 'moderately more important' (3) than Performance.
  • You decide Price is 'strongly more important' (5) than Portability.
  • You decide Performance is 'moderately more important' (3) than Portability.

The calculator would determine that Price is your most important criterion, followed by Performance, and then Portability.

Alternative Comparisons:

  • For Price: Laptop A is extremely better (9) than B and strongly better (5) than C.
  • For Performance: Laptop B is extremely better (9) than A and C.
  • For Portability: Laptop C is strongly better (5) than B and extremely better (9) than A.

After entering these values, the calculator would synthesize the results. Even though Laptop B has the best performance, its high price might lead the AHP model to rank Laptop A or C higher overall, depending on the weights you assigned to the criteria. This demonstrates how AHP helps balance competing factors to arrive at a logical conclusion.

Limitations of AHP

While powerful, AHP is based on your subjective inputs. The quality of the output is directly related to the quality and consistency of your judgments. It's a tool to structure and clarify your own thinking, not an objective truth-teller. Always review the results and the consistency ratio to ensure they reflect your true preferences.

Leave a Reply

Your email address will not be published. Required fields are marked *