Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculation differences with npm 'ahp' library #8

Open
dfrankow opened this issue Jul 29, 2021 · 2 comments
Open

Calculation differences with npm 'ahp' library #8

dfrankow opened this issue Jul 29, 2021 · 2 comments

Comments

@dfrankow
Copy link
Contributor

Node has an AHP library, found at https://github.com/airicyu/ahp.

This library and that one do not agree on results. I put code samples below.

I don't know that this is a bug. You may have just chosen different calculation methods.

However, I'd be interested if you had any thoughts on this.

Your library:

$ ./cost_speed.py 
Target weights {'f150': 0.7785, 'ferrari': 0.1799, 'honda': 0.0416}
Local weights {'cost': 0.5, 'speed': 0.5}

The node library (I pick out only the relevant lines):

  ...
  criteriaRankMetaMap: { ci: 0, ri: 0, cr: 0, weightedVector: [ 0.5, 0.5 ] },
  ...
  rankedScoreMap: {
    ferrari: 0.22116480011216855,
    honda: 0.05150989361515677,
    f150: 0.7273253062726747
  },
  ...

Your library (cost_speed.py):

#!/usr/bin/env python

import ahpy

cost_comparisons = {('ferrari', 'honda'): 9,
            ('f150', 'honda'): 9,
            ('f150', 'ferrari'): 9}
speed_comparisons = {('ferrari', 'honda'): 9,
            ('f150', 'honda'): 9,
            ('f150', 'ferrari'): 9}
criteria_comparisons = {('cost', 'speed'): 1}

cost = ahpy.Compare('cost', cost_comparisons)
speed = ahpy.Compare('speed', speed_comparisons)
criteria = ahpy.Compare('criteria', criteria_comparisons)
criteria.add_children([cost, speed])

print('Target weights', criteria.target_weights)

Node library (cost_speed.js):

#!/usr/bin/env node

const AHP = require('ahp');
var ahpContext = new AHP();

ahpContext.addItems(['ferrari', 'honda', 'f150']);

ahpContext.addCriteria(['cost', 'speed']);

ahpContext.rankCriteriaItem('cost', [
    ['ferrari', 'honda', 9],
    ['f150', 'honda', 9],
    ['f150', 'ferrari', 9]
]);

ahpContext.rankCriteriaItem('speed', [
    ['ferrari', 'honda', 9],
    ['f150', 'honda', 9],
    ['f150', 'ferrari', 9]
]);

ahpContext.rankCriteria([
    ['cost', 'speed', 1],
]);

let output = ahpContext.run();
console.log(output);
@dfrankow
Copy link
Contributor Author

dfrankow commented Jul 29, 2021

Here is a medium post that does agree with your results, and also references the eigenvalue method.

The post has two examples of results:

  1. safety 6/10, style 3/10, comfort 1/10
  2. safety 0.558, style 0.319, comfort 0.121

And your code:

$ ./medium_example.py 
Example 1
Target weights {'safety': 0.6, 'style': 0.3, 'comfort': 0.1}
Local weights {'safety': 0.6, 'style': 0.3, 'comfort': 0.1}
Example 2
Target weights {'safety': 0.5584, 'style': 0.3196, 'comfort': 0.122}
Local weights {'safety': 0.5584, 'style': 0.3196, 'comfort': 0.122}

code (medium_example.py):

#!/usr/bin/env python

import ahpy

sss_comparisons = {
    ('safety', 'style'): 2,
    ('safety', 'comfort'): 6,
    ('style', 'comfort'): 3}

compare = ahpy.Compare('sss', sss_comparisons)

print('Example 1')
print('Target weights', compare.target_weights)
print('Local weights', compare.local_weights)

sss_comparisons = {
    ('safety', 'style'): 2,
    ('safety', 'comfort'): 4,
    ('style', 'comfort'): 3}

compare = ahpy.Compare('sss', sss_comparisons)

print('Example 2')
print('Target weights', compare.target_weights)
print('Local weights', compare.local_weights)

@cruzmike1
Copy link

Hello please i need help on how to used AHPY for COST-RELATED FACTORS
ScreenShot_20231021203152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants