SkillAgentSearch skills...

Ahp

Analytic hierarchy process (AHP)

Install / Use

/learn @airicyu/Ahp
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

ahp.js

npm version Build Codecov branch

This node.js module is a library for Analytic Hierarchy Process(AHP).

Wiki page for AHP: https://en.wikipedia.org/wiki/Analytic_hierarchy_process

Project page


Glossary

| Term | Description | Example | | -------------------- | -------------------------------------------------------------- | ------------------------------------------------ | | Items | The choices | Car A, Car B, Car C | | Criteria | The judging perspectives | Price, Speed, Safety | | Criteria Rank Matrix | The Criterion Rank Matrix | Criterion Price is prefferred over Speed | | Criterion Item Rank | The Criterion perspective Item Rank Matrix | In terms of Price, Car A is preferred over Car B | | Rank Scale | The Scale a factor/choice preffered over another factor/choice | Two factors contribute equally to the objective | | RI | Random Consistency Index | 2: 0, 3: 0.58, 4: 0.9, 5: 1.12, ... | | CI | Consistency Index | - | | CR | Consistency Ration (CI/RI) | - |


Install

$ npm i ahp

Quick Samples

Hello World Sample

import AHP from 'ahp';
const ahpContext = new AHP();

ahpContext.addItems(['VendorA', 'VendorB', 'VendorC']);

ahpContext.addCriteria(['price', 'functionality', 'UX']);

//rank criteria with rank scale
ahpContext.rankCriteriaItem('price', [
    ['VendorB', 'VendorC', 1 / 2],
    ['VendorA', 'VendorC', 1 / 2],
    ['VendorA', 'VendorB', 1]
]);

//rank criteria with rank scale
ahpContext.rankCriteriaItem('functionality', [
    ['VendorB', 'VendorC', 1],
    ['VendorA', 'VendorC', 5],
    ['VendorA', 'VendorB', 5]
]);

//rank criteria with absolute rank scole
ahpContext.setCriteriaItemRankByGivenScores('UX', [10, 10, 1]);

ahpContext.rankCriteria(
    [
        ['price', 'functionality', 3],
        ['price', 'UX', 3],
        ['functionality', 'UX', 1]
    ]
);

const output = ahpContext.run();
console.log(output);

Console output

{ error: null,
  rankingMatrix:
   [ [ 0.25, 0.7142857142857141, 0.4761904761904761 ],
     [ 0.25, 0.14285714285714285, 0.4761904761904761 ],
     [ 0.5, 0.14285714285714285, 0.047619047619047616 ] ],
  itemRankMetaMap:
   { price: { ci: 0, ri: 0.58, cr: 0 },
     functionality: { ci: 0, ri: 0.58, cr: 0 },
     UX: { ci: 0, ri: 0.58, cr: 0 } },
  criteriaRankMetaMap:
   { ci: 0,
     ri: 0.58,
     cr: 0,
     weightedVector: [ 0.6000000000000001, 0.20000000000000004, 0.20000000000000004 ] },
  rankedScoreMap:
   { VendorA: 0.3880952380952381,
     VendorB: 0.27380952380952384,
     VendorC: 0.33809523809523817 },
  rankedScores: [ 0.3880952380952381, 0.27380952380952384, 0.33809523809523817 ] }

Import Data Context Sample

import AHP from 'ahp';

const ahpContext = new AHP();

/*
notice that in this demo, we import price item ranking with matrix,
and import UX item ranking with absolute scores. Both are supported.
*/
ahpContext.import({
    items: ['VendorA', 'VendorB', 'VendorC'],
    criteria: ['price', 'functionality', 'UX'],
    criteriaItemRank: {
        price: [
            [1, 1, 0.5],
            [1, 1, 0.5],
            [2, 2, 1]
        ],
        functionality: [
            [1, 5, 5],
            [0.2, 1, 1],
            [0.2, 1, 1]
        ],
        UX: [10, 10, 1]
    },
    criteriaRank: [
        [1, 3, 3],
        [0.3333333333333333, 1, 1],
        [0.3333333333333333, 1, 1]
    ]
});

const output = ahpContext.run();
console.log(output);

Console output

{ error: null,
  rankingMatrix:
   [ [ 0.25, 0.7142857142857141, 0.4761904761904761 ],
     [ 0.25, 0.14285714285714285, 0.4761904761904761 ],
     [ 0.5, 0.14285714285714285, 0.047619047619047616 ] ],
  itemRankMetaMap:
   { price: { ci: 0, ri: 0.58, cr: 0 },
     functionality: { ci: 0, ri: 0.58, cr: 0 },
     UX: { ci: 0, ri: 0.58, cr: 0 } },
  criteriaRankMetaMap:
   { ci: 0,
     ri: 0.58,
     cr: 0,
     weightedVector: [ 0.6000000000000001, 0.20000000000000004, 0.20000000000000004 ] },
  rankedScoreMap:
   { VendorA: 0.3880952380952381,
     VendorB: 0.27380952380952384,
     VendorC: 0.33809523809523817 },
  rankedScores: [ 0.3880952380952381, 0.27380952380952384, 0.33809523809523817 ] }

Export Data Context Sample

import AHP from 'ahp';
const ahpContext = new AHP();
......
const util = require('util');
console.log(util.inspect(ahpContext.export(), false, null));

Console output

{ items: [ 'VendorA', 'VendorB', 'VendorC' ],
  criteria: [ 'price', 'functionality', 'UX' ],
  criteriaItemRank:
   { price: [ [ 1, 1, 0.5 ], [ 1, 1, 0.5 ], [ 2, 2, 1 ] ],
     functionality: [ [ 1, 5, 5 ], [ 0.2, 1, 1 ], [ 0.2, 1, 1 ] ],
     UX: [ [ 1, 1, 10 ], [ 1, 1, 10 ], [ 0.1, 0.1, 1 ] ] },
  criteriaRank:
   [ [ 1, 3, 3 ],
     [ 0.3333333333333333, 1, 1 ],
     [ 0.3333333333333333, 1, 1 ] ] }

Output Analysis Process Information Sample

import AHP from 'ahp';
const ahpContext = new AHP();
......
const analyticContext = ahpContext.debug();
for(const key in analyticContext){
    console.log(`${key}: `, analyticContext[key], '\n');
}

Console output

error:  null

rankingMatrix:  [ [ 0.25, 0.7142857142857141, 0.4761904761904761 ],
  [ 0.25, 0.14285714285714285, 0.4761904761904761 ],
  [ 0.5, 0.14285714285714285, 0.047619047619047616 ] ]

itemRankMetaMap:  { price: { ci: 0, ri: 0.58, cr: 0 },
  functionality: { ci: 0, ri: 0.58, cr: 0 },
  UX: { ci: 0, ri: 0.58, cr: 0 } }

criteriaRankMetaMap:  { ci: 0,
  ri: 0.58,
  cr: 0,
  weightedVector: [ 0.6000000000000001, 0.20000000000000004, 0.20000000000000004 ] }

rankedScoreMap:  { VendorA: 0.3880952380952381,
  VendorB: 0.27380952380952384,
  VendorC: 0.33809523809523817 }

rankedScores:  [ 0.3880952380952381, 0.27380952380952384, 0.33809523809523817 ]

log:  ==========================================
context:
items:
[ 'VendorA', 'VendorB', 'VendorC' ]
criteria:
[ 'price', 'functionality', 'UX' ]
criteriaItemRank:
{ price: [ [ 1, 1, 0.5 ], [ 1, 1, 0.5 ], [ 2, 2, 1 ] ],
  functionality: [ [ 1, 5, 5 ], [ 0.2, 1, 1 ], [ 0.2, 1, 1 ] ],
  UX: [ [ 1, 1, 10 ], [ 1, 1, 10 ], [ 0.1, 0.1, 1 ] ] }
criteriaRank:
[ [ 1, 3, 3 ],
  [ 0.3333333333333333, 1, 1 ],
  [ 0.3333333333333333, 1, 1 ] ]
__________________________________
criteriaItemRank['price']
---------------------------------------------
|          |   VendorA|   VendorB|   VendorC|
|----------|----------|----------|----------|
|   VendorA|     1.000|     1.000|     0.500|
|   VendorB|     1.000|     1.000|     0.500|
|   VendorC|     2.000|     2.000|     1.000|
---------------------------------------------

Consistentcy index: 0
Random index: 0.58
Consistentcy ratio: 0
CR<=0.1 => sufficient consistency
__________________________________
criteriaItemRank['functionality']
---------------------------------------------
|          |   VendorA|   VendorB|   VendorC|
|----------|----------|----------|----------|
|   VendorA|     1.000|     5.000|     5.000|
|   VendorB|     0.200|     1.000|     1.000|
|   VendorC|     0.200|     1.000|     1.000|
---------------------------------------------

Consistentcy index: 0
Random index: 0.58
Consistentcy ratio: 0
CR<=0.1 => sufficient consistency
__________________________________
criteriaItemRank['UX']
---------------------------------------------
|          |   VendorA|   VendorB|   VendorC|
|----------|----------|----------|----------|
|   VendorA|     1.000|     1.000|    10.000|
|   VendorB|     1.000|     1.000|    10.000|
|   VendorC|     0.100|     0.100|     1.000|
---------------------------------------------

Consistentcy index: 0
Random index: 0.58
Consistentcy ratio: 0
CR<=0.1 => sufficient consistency
__________________________________
criteriaRank:
---------------------------------------------------------
|             |        price|functionality|           UX|
|-------------|-------------|-------------|-------------|
|        price|        1.000|        3.000|        3.000|
|functionality|        0.333|        1.000|        1.000|
|           UX|        0.333|        1.000|        1.000|
---------------------------------------------------------

Consistentcy index: 0
Random index: 0.58
Consistentcy ratio: 0
CR<=0.1 => sufficient consistency
Criteria Weight Vector: 0.6000000000000001,0.20000000000000004,0.20000000000000004
__________________________________

rankingMatrix: (Higher score is better)
---------------------------------------
|             |VendorA|VendorB|VendorC|
|-------------|-------|-------|-------|
|        price|  0.250|  0.250|  0.500|
|functionality|  0.714|  0.143|  0.143|
|           UX|  0.
View on GitHub
GitHub Stars27
CategoryDevelopment
Updated2mo ago
Forks9

Languages

JavaScript

Security Score

90/100

Audited on Jan 13, 2026

No findings