afryca.ase.Snippet Library HLPR Hesitant Linguistic Preference Relation // Hesitant Linguistic Preference Relation class // // @param ids Labels // @param n Number of alternatives // var HLPR = function HLPR(ids, n) { this.ids = ids; // Ids this.n = n; // Number of alternatives this.lowerPreference = new LPR(ids, n); this.upperPreference = new LPR(ids, n); this.labelsValues = this.lowerPreference.labelsValues; this.beta = this.lowerPreference.beta; this.linguisticValue = this.lowerPreference.linguisticValue; this.valueFor = this.lowerPreference.valueFor; this.getValue = function(i, j) { var result = { lower: this.lowerPreference.getValue(i, j), upper: this.upperPreference.getValue(i, j), hlpr: this }; result.toString = function() { if (typeof result.lower == 'number') { return 'NaN'; } if (result.lower == result.upper) { return '{' + result.lower + '}'; } else { return '{' + result.lower + ', ' + result.upper + '}'; } } return result; } // Set alternative value this.setValueSymmetrically = function (i, j, lowerLabel, lowerAlpha, upperLabel, upperAlpha) { this.lowerPreference.setValueSymmetrically(i | 0, j | 0, lowerLabel, lowerAlpha); this.upperPreference.setValueSymmetrically(i | 0, j | 0, upperLabel, upperAlpha); } this.toString = function() { var result = []; var lengths = []; var value; for (var i = 0; i < this.n; i++) { result[i] = []; for (var j = 0; j < this.n; j++) { value = this.getValue(i | 0, j | 0).toString(); result[i][j] = (i == j) ? '-' : ((value == 'NaN') ? '' : value); lengths[j] = (i == 0) ? result[i][j].length : Math.max(lengths[j], result[i][j].length); } } var output = ''; for (var i = 0; i < this.n; i++) { for (var j = 0; j < this.n; j++) { if (j > 0) { output += ' '; } output += '| ' + result[i][j]; for (var s = result[i][j].length; s < lengths[j]; s++) { output += ' '; } } output += ' |\n'; } return output; } } // // HLPR inverse delta // // Computed as mean of lower and upper values // // @param value HLPR preference // HLPR.inverseDelta = function(value) { if (typeof value == 'undefined') { return NaN; } if (typeof value.hlpr == 'undefined') { return NaN; } var L = hlpr.beta(hlpr.valueFor(value.lower.s)) + value.lower.alpha; var U = hlpr.beta(hlpr.valueFor(value.upper.s)) + value.upper.alpha; return (L + U) / 2; } // // HLPR possibility distribution // // Managing consistency and consensus in group decision making with hesitant fuzzy linguistic preference relations - Definition 2 // http://dx.doi.org/10.1016/j.omega.2015.12.005 // // @param value HLPR preference // HLPR.possibilityDistribution = function(value) { if (typeof value == 'undefined') { return NaN; } if (typeof value.hlpr == 'undefined') { return NaN; } var hlpr = value.hlpr; var T = hlpr.ids.length; var L = hlpr.beta(hlpr.valueFor(value.lower.s)); var U = hlpr.beta(hlpr.valueFor(value.upper.s)); var p = 1 / ((U - L) + 1); var result = []; for (var l = 0; l < T; l++) { result[l] = ((l >= L) && (l <= U)) ? p : 0; } return result; } // // HLPR expected value // // Managing consistency and consensus in group decision making with hesitant fuzzy linguistic preference relations - Definition 3 // http://dx.doi.org/10.1016/j.omega.2015.12.005 // // @param value HLPR preference // HLPR.expectedValue = function(value) { var p = HLPR.possibilityDistribution(value); if (typeof p == 'number') { return NaN; } var hlpr = value.hlpr; var ids = hlpr.ids; var T = ids.length; var result = 0; for (var l = 0; l < T; l++) { result += hlpr.valueFor(ids[l]) * p[l]; } return result; } // // HLPR variance // // Managing consistency and consensus in group decision making with hesitant fuzzy linguistic preference relations - Definition 4 // http://dx.doi.org/10.1016/j.omega.2015.12.005 // // @param value HLPR preference // HLPR.variance = function(value) { var p = HLPR.possibilityDistribution(value); if (typeof p == 'number') { return NaN; } var hlpr = value.hlpr; var ids = hlpr.ids; var T = ids.length; var result = 0; var E = HLPR.expectedValue(value); for (var l = 0; l < T; l++) { result += Math.pow(hlpr.valueFor(ids[l]) - E, 2) * p[l]; } return result; } // // Hesitant Fuzzy Linguistic Weighted Average operator // // Managing consistency and consensus in group decision making with hesitant fuzzy linguistic preference relations - Definition 6 // http://dx.doi.org/10.1016/j.omega.2015.12.005 // // @param values Preferences to aggregate // @param weights HLPRs weights // HLPR.HFLWA = function(values, weights) { var n = values.length; if (typeof weights == 'undefined') { weights = []; var w = 1/n; for (var i = 0; i < n; i++) { weights[i] = w; } } else { var sum = 0; for (var i = 0; i < weights.length; i++) { sum += weights[i]; } for (var i = 0; i < weights.length; i++) { weights[i] /= sum; } } var distributions = []; for (var i = 0; i < n; i++) { distributions[i] = HLPR.possibilityDistribution(values[i]); } var result = []; var T = values[0].hlpr.ids.length; for (var i = 0; i < T; i++) { result[i] = 0; for (var j = 0; j < n; j++) { result[i] += weights[j] * distributions[j][i]; } } return result; } // // Expected LPR // // Managing consistency and consensus in group decision making with hesitant fuzzy linguistic preference relations - EB // http://dx.doi.org/10.1016/j.omega.2015.12.005 // // @param hlpr HLPR // HLPR.expectedLPR = function(hlpr) { if (typeof hlpr == 'undefined') { return NaN; } if (typeof hlpr.n == 'undefined') { return NaN; } var n = hlpr.n; var ids = hlpr.ids; var result = new LPR(ids, n); var value; var e; for (var i = 0; i < (n - 1); i++) { for (var j = i + 1; j < n; j++) { value = hlpr.getValue(i | 0, j | 0); if (value.toString() !== 'NaN') { e = HLPR.expectedValue(value); result.preference.setValueSymmetrically(i | 0, j | 0, e); } } } return result; } // // Group LPR // // Managing consistency and consensus in group decision making with hesitant fuzzy linguistic preference relations - Eq. (10-13) // http://dx.doi.org/10.1016/j.omega.2015.12.005 // // @param hlprs HLPRs // @param weights Experts' weights // HLPR.groupLPR = function(hlprs, weights) { if (typeof hlprs == 'undefined') { return NaN; } if (typeof hlprs[0] == 'undefined') { return NaN; } var experts = hlprs.length; var hlpr = hlprs[0]; var n = hlpr.n; var ids = hlpr.ids; var T = ids.length; var result = new LPR(ids, n); var aggregateValue; var values; var expectedValue; for (var i = 0; i < (n - 1); i++) { for (var j = i + 1; j < n; j++) { values = []; expectedValue = 0; for (var e = 0; e < experts; e++) { values[e] = hlprs[e].getValue(i | 0, j | 0); } aggregateValue = HLPR.HFLWA(values, weights); for (var l = 0; l < T; l++) { expectedValue += hlpr.valueFor(ids[l]) * aggregateValue[l]; } result.preference.setValueSymmetrically(i | 0, j | 0, expectedValue); } } return result; } // // Wu's distance between two values // // Managing consistency and consensus in group decision making with hesitant fuzzy linguistic preference relations - Eq. (16) // http://dx.doi.org/10.1016/j.omega.2015.12.005 // // @param a Linguistic variable a // @param b Linguistic variable b // HLPR.wuDistanceBetweenTwoValues = function(a, b) { if ((typeof a == 'undefined') || (typeof b == 'undefined')) { return NaN; } if ((typeof a.lpr == 'undefined') || (typeof b.lpr == 'undefined')) { return NaN; } if (a.lpr.ids != b.lpr.ids) { return NaN; } if (!( a.lpr.ids.length & 1 )) { return NaN; } var lpr = a.lpr; var T = lpr.ids.length; var aInverseDelta = lpr.beta(lpr.valueFor(a.s)) + a.alpha; var bInverseDelta = lpr.beta(lpr.valueFor(b.s)) + b.alpha; var result = Math.abs(aInverseDelta - bInverseDelta); result /= T - 1; return result; } // // Wu's distance between expected and additive consistent // // Managing consistency and consensus in group decision making with hesitant fuzzy linguistic preference relations - Eq. (15) // http://dx.doi.org/10.1016/j.omega.2015.12.005 // // @param E Expected LPR // @param B Additive consistent LPR // HLPR.wuDistanceBetweenExpectedAndAdittiveConsistent = function(E, B) { if ((typeof E == 'undefined') || (typeof B == 'undefined')) { return NaN; } if (E.ids != E.ids) { return NaN; } if (!(E.ids.length & 1 )) { return NaN; } var result = 0; var e; var b; var n = E.n; for (var i = 0; i < (n - 1); i++) { for (var j = i + 1; j < n; j++) { e = E.getValue(i | 0, j | 0); b = B.getValue(i | 0, j | 0); result += Math.pow(HLPR.wuDistanceBetweenTwoValues(e, b), 2); } } result *= 2 / (n * (n - 1)); result = Math.sqrt(result).toFixed(2)/1; return result; }