1893 lines
50 KiB
Plaintext
1893 lines
50 KiB
Plaintext
<snippet>
|
||
<subclass>afryca.ase.Snippet</subclass>
|
||
<file></file>
|
||
<category>Library</category>
|
||
<name>consistency</name>
|
||
<description>Consistency</description>
|
||
<code>
|
||
var consistency = (typeof exports === "undefined")?(function consistency() {}):(exports);
|
||
if(typeof global !== "undefined") { global.consistency = consistency; }
|
||
|
||
//
|
||
// Compute the value of an assessment on (x_l,x_k) by applying an uninorm
|
||
// operator on assessments on pairs of the form (x_l,x_(l+1))
|
||
//
|
||
// @param preference FPR
|
||
// @param l First alternative of the pair
|
||
// @param k Second alternative of the pair
|
||
// @return The result of the uninorm, used as the assessment value
|
||
//
|
||
consistency.uninorm = function uninorm(preference, l, k) {
|
||
var numerator = 1;
|
||
var denominator = 1;
|
||
var value;
|
||
for (var i = l; i < k; i++) {
|
||
value = preference.getValue((i -1) | 0, i | 0);
|
||
numerator *= value;
|
||
denominator *= 1 - value;
|
||
}
|
||
return (numerator / (numerator + denominator)).toFixed(2)/1;
|
||
}
|
||
|
||
//
|
||
// Method invoked to generate a FPR of dimension n x n following the approach of Chiclana et al. (IEEE TFS, 2009)
|
||
//
|
||
// @param n Number of alternatives
|
||
// @return Generated FPR
|
||
//
|
||
consistency.chiclanaRandomFPR = function chiclanaRandomFPR(n) {
|
||
var result = new FPR(n);
|
||
|
||
// Generate "n-1" assessments randomly
|
||
// Assign them to pairs (x_l,x_(l+1)), l=1,...,n-1
|
||
for (var l = 1; l <= n - 1; l++) {
|
||
result.setValueSymmetrically(
|
||
(l-1) | 0, // Row
|
||
l | 0, // Column
|
||
Math.random().toFixed(2)/1); // Value between 0.00 and 1.00
|
||
}
|
||
|
||
// Generate assessments for remaining elements in the upper diagonal of
|
||
// the matrix assessments on pairs (x_l,x_k) such that k > l+1
|
||
for (var l = 1; l < n; l++) {
|
||
for (var k = l +2; k <= n; k++) {
|
||
result.setValueSymmetrically(
|
||
(l - 1) | 0, // Row
|
||
(k - 1) | 0, // Column
|
||
consistency.uninorm(result, l, k)); // Value
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
//
|
||
// Adapt preferences with missing values to compute Saaty CI
|
||
// http://dx.doi.org/10.1016/0270-0255(87)90492-1
|
||
//
|
||
consistency.missingValuesHarker1987 = function missingValuesHarker1987(matrix) {
|
||
var result = new Array(matrix.length);
|
||
for (var row = 0; row < result.length; row++) {
|
||
result[row] = new Array(matrix[row].length);
|
||
result[row][row] = 1;
|
||
for (var col = 0; col < matrix[row].length; col++) {
|
||
if (row != col) {
|
||
if (isNaN(matrix[row][col])) {
|
||
result[row][col] = 0;
|
||
result[row][row]++;
|
||
} else {
|
||
result[row][col] = matrix[row][col];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
//
|
||
// Check if preference contains missing values
|
||
//
|
||
consistency.containsMissingValues = function containsMissingValues(preference) {
|
||
var alternatives = preference.getNumberOfAlternatives();
|
||
var preferences = preference.getPreferences();
|
||
var row = preferences.length;
|
||
|
||
for (var i = 0; i < row; i++) {
|
||
for (var j = 0; j < alternatives; j++) {
|
||
if (isNaN(preference.getValue(i | 0, j | 0))) {
|
||
return true;
|
||
}
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
//
|
||
// Check if preference contains missing values
|
||
//
|
||
consistency.containsMissingValues = function containsMissingValues(preference, row, col) {
|
||
var value;
|
||
for (var i = 0; i < row; i++) {
|
||
for (var j = 0; j < col; j++) {
|
||
value = preference.getValue(i | 0, j | 0);
|
||
if(typeof value === 'number') {
|
||
if (isNaN(preference.getValue(i | 0, j | 0))) {
|
||
return true;
|
||
}
|
||
}else if(value == null || value=='' || value ==' ' || value == "{}") {
|
||
return true;
|
||
}
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
//
|
||
// Check if there is at least one preference relation for an alternative
|
||
//
|
||
consistency.thereIsAnPreferenceRelationForAlternative = function thereIsAnPreferenceRelationForAlternative(preference, i) {
|
||
var alternatives = preference.getNumberOfAlternatives();
|
||
for (var j = 0; j < alternatives; j++) {
|
||
if ((i != j) && (!isNaN(preference.getValue(i | 0, j | 0)))) {
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
//
|
||
// Check if a spanning set exists in preferences
|
||
//
|
||
consistency.spanningSetExists = function spanningSetExists(preference) {
|
||
var alternatives = preference.getNumberOfAlternatives();
|
||
for (var i = 0; i < alternatives; i++) {
|
||
if (!consistency.thereIsAnPreferenceRelationForAlternative(preference, i)) {
|
||
return false;
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
//
|
||
// Return Saaty's preference matrix
|
||
//
|
||
consistency.getSaatyPreference = function getSaatyPreference(preference, missingValuesFunction) {
|
||
if (consistency.containsMissingValues(preference)) {
|
||
if (typeof missingValuesFunction === "undefined") {
|
||
return null;
|
||
} else if (!consistency.spanningSetExists(preference)) {
|
||
return null;
|
||
}
|
||
var saatyPreference = adapters.fpr2jsSaatyRelation(preference);
|
||
return missingValuesFunction(saatyPreference);
|
||
} else {
|
||
return adapters.fpr2jsSaatyRelation(preference);
|
||
}
|
||
}
|
||
|
||
//
|
||
// Compute Saaty's CI
|
||
// T.L. Saaty. The Analytic Hierarchy Process. McGraw-Hill, New York (1980)
|
||
//
|
||
consistency.saatyConsistencyIndex = function saatyConsistencyIndex(preference, missingValuesFunction) {
|
||
var saatyPreference = consistency.getSaatyPreference(preference, missingValuesFunction);
|
||
if (saatyPreference == null) {
|
||
return NaN;
|
||
}
|
||
|
||
//Descomposition
|
||
var descomposition = pca.generateDescomposition(adapters.fpr2jsArray(preference));
|
||
//Eigen values
|
||
var eigenValues = pca.generateEigenValues(descomposition);
|
||
|
||
var principalEigenvalue = eigenValues[0];
|
||
var N = saatyPreference.length;
|
||
var result = (principalEigenvalue - N) / (N - 1);
|
||
return result.toFixed(2)/1;
|
||
}
|
||
|
||
//
|
||
// Saaty's Random Indexes
|
||
//
|
||
consistency.saatyRI = [
|
||
[0.00], //0
|
||
[0.00], //1
|
||
[0.00], //2
|
||
[0.58], //3
|
||
[0.90], //4
|
||
[1.12], //5
|
||
[1.24], //6
|
||
[1.32], //7
|
||
[1.41], //8
|
||
[1.45], //9
|
||
[1.49], //10
|
||
[1.51], //11
|
||
[1.48], //12
|
||
[1.56], //13
|
||
[1.57], //14
|
||
[1.59]]; //15
|
||
|
||
//
|
||
// Forman's RI
|
||
// http://dx.doi.org/10.1016/0377-2217(90)90072-J
|
||
//
|
||
consistency.formanRI = [
|
||
[0.00], //0
|
||
[0.00], //1
|
||
[0.00], //2
|
||
[0.52333, 0.00], //3
|
||
[0.88604, 0.58614, 0.29994, 0.00], //4
|
||
[1.10983, 0.93120, 0.75097, 0.57231, 0.39095, 0.20171, 0.00], //5
|
||
[1.25390, 1.13028, NaN, 0.89415, 0.78113, 0.66280, 0.53832, 0.41822, 0.28718, 0.15141, 0.00], //6
|
||
[1.34516, 1.25976, 1.18055, 1.09311, 1.01190, 0.92629, 0.84444, 0.75805, 0.67878, 0.59372, 0.55072, 0.41665, 0.32232, 0.22515, 0.11962, 0.00]]; //7
|
||
|
||
//
|
||
// Donegan-Dodd's Random Indexes
|
||
// http://dx.doi.org/10.1016/0895-7177(91)90098-R
|
||
//
|
||
consistency.doneganDoddRI = [
|
||
[0.0000], // 0
|
||
[0.0000], // 1
|
||
[0.0000], // 2
|
||
[0.4914], // 3
|
||
[0.8286], // 4
|
||
[1.0591], // 5
|
||
[1.1797], // 6
|
||
[1.2519], // 7
|
||
[1.3171], // 8
|
||
[1.3733], // 9
|
||
[1.4055], //10
|
||
[1.4213], //11
|
||
[1.4497], //12
|
||
[1.4643], //13
|
||
[1.4822], //14
|
||
[1.4969], //15
|
||
[1.5078], //16
|
||
[1.5153], //17
|
||
[1.5262], //18
|
||
[1.5313], //19
|
||
[1.5371]]; //20
|
||
|
||
//
|
||
// Count missing values
|
||
//
|
||
consistency.countMissingValues = function countMissingValues(preference) {
|
||
var alternatives = preference.getNumberOfAlternatives();
|
||
var result = 0;
|
||
for (var i = 0; i < alternatives - 1; i++) {
|
||
for (var j = i + 1; j < alternatives; j++) {
|
||
if (isNaN(preference.getValue(i | 0, j | 0))) {
|
||
result++;
|
||
}
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
//
|
||
// Return Random Index
|
||
//
|
||
consistency.getRI = function getRI(preference, randomIndexes) {
|
||
if (typeof randomIndexes === "undefined") {
|
||
randomIndexes = consistency.saatyRI;
|
||
}
|
||
var alternatives = preference.getNumberOfAlternatives();
|
||
if (alternatives < randomIndexes.length) {
|
||
var missingValues = consistency.countMissingValues(preference);
|
||
return (missingValues < randomIndexes[alternatives].length)
|
||
? randomIndexes[alternatives][missingValues]
|
||
: NaN;
|
||
}
|
||
return NaN;
|
||
}
|
||
|
||
//
|
||
// Saaty Consistency Ratio
|
||
//
|
||
consistency.saatyConsistencyRatio = function saatyConsistencyRatio(preference, missingValuesFunction, randomIndexes) {
|
||
|
||
if (preference.getNumberOfAlternatives() <= 2) {
|
||
return 0.0;
|
||
}
|
||
|
||
var CI = consistency.saatyConsistencyIndex(preference, missingValuesFunction);
|
||
var RI = consistency.getRI(preference, randomIndexes);
|
||
return (isNaN(CI) || isNaN(RI))
|
||
? NaN
|
||
: (RI == 0)
|
||
? 0
|
||
: (CI / RI).toFixed(2)/1;
|
||
}
|
||
|
||
//
|
||
// Saaty's multiplicative consistent
|
||
//
|
||
// a_{ih} = a_{hj} = a_{ij} for each i,h,j \in [1, ..., n] and n = number of alternatives
|
||
//
|
||
// Default threshold == 1.0
|
||
//
|
||
consistency.multiplicativeConsistent = function multiplicativeConsistent(preference, threshold) {
|
||
var saaty = consistency.getSaatyPreference(preference);
|
||
if (saaty == null) {
|
||
return NaN;
|
||
}
|
||
if (typeof threshold === "undefined") {
|
||
threshold = 1.0;
|
||
}
|
||
var alternatives = saaty.length;
|
||
var value, left, bottom, difference;
|
||
for (var row = 0; row < (alternatives - 2); row++) {
|
||
for (var col = row + 2; col < alternatives; col++) {
|
||
left = saaty[row][col - 1];
|
||
bottom = saaty[row + 1][col];
|
||
value = saaty[row][col];
|
||
difference = Math.abs(((left * bottom) - value).toFixed(2)/1);
|
||
if (difference > threshold) {
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
//
|
||
// Additive consistent
|
||
//
|
||
// a_{ih} + a_{hj} - a_{ij} - 0.5 = 0 for each i,h,j \in [1, ..., n] and n = number of alternatives
|
||
//
|
||
// Default threshold == 0.01
|
||
//
|
||
consistency.additiveConsistent = function additiveConsistent(preference, threshold) {
|
||
if (consistency.containsMissingValues(preference)) {
|
||
return NaN;
|
||
}
|
||
if (typeof threshold === "undefined") {
|
||
threshold = 0.01;
|
||
}
|
||
var alternatives = preference.getNumberOfAlternatives();
|
||
var value, left, bottom, additiveApproach;
|
||
for (var row = 0; row < (alternatives - 2); row++) {
|
||
for (var col = row + 2; col < alternatives; col++) {
|
||
left = preference.getValue(row | 0, (col - 1) | 0);
|
||
bottom = preference.getValue((row + 1) | 0, col | 0);
|
||
value = preference.getValue(row | 0, col | 0);
|
||
additiveApproach = Math.abs(left + bottom - value - 0.5).toFixed(2)/1;
|
||
if (additiveApproach > threshold) {
|
||
|
||
return false;
|
||
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
//
|
||
// Fedrizzi's Global Inconsistency Index
|
||
//
|
||
consistency.fedrizziGlobalInconsistencyIndex = function fedrizziGlobalInconsistencyIndex(preference) {
|
||
if (consistency.containsMissingValues(preference)) {
|
||
return NaN;
|
||
}
|
||
var result = 0;
|
||
var alternatives = preference.getNumberOfAlternatives();
|
||
var value_ih, value_hj, value_ji;
|
||
for (var i = 0; i < (alternatives - 2); i++) {
|
||
for (var j = i+1; j < (alternatives - 1); j++) {
|
||
value_ji = preference.getValue(j | 0, i | 0);
|
||
for (var h = j+1; h < alternatives; h++) {
|
||
value_ih = preference.getValue(i | 0, h | 0);
|
||
value_hj = preference.getValue(h | 0, j | 0);
|
||
result += Math.pow(value_ih + value_hj + value_ji - 1.5, 2);
|
||
}
|
||
}
|
||
}
|
||
return (6 * result).toFixed(2)/1;
|
||
}
|
||
|
||
//
|
||
// Optimal preference value for preference relation r_st
|
||
//
|
||
consistency.fedrizziOptimalValue = function fedrizziOptimalValue(preference, s, t) {
|
||
var n = preference.getNumberOfAlternatives();
|
||
var s_sum = 0;
|
||
var t_sum = 0;
|
||
var value;
|
||
for (var h = 0; h < n; h++) {
|
||
if (h != t) {
|
||
value = preference.getValue(s | 0, h | 0);
|
||
if (isNaN(value)) {
|
||
return NaN;
|
||
}
|
||
s_sum += value;
|
||
}
|
||
if (h != s) {
|
||
value = preference.getValue(h | 0, t | 0);
|
||
if (isNaN(value)) {
|
||
return NaN;
|
||
}
|
||
t_sum += value;
|
||
}
|
||
}
|
||
var numerator = s_sum + t_sum - (n / 2);
|
||
var denominator = n - 2;
|
||
var result = (numerator / denominator).toFixed(2)/1;
|
||
if (result < 0) {
|
||
result = 0;
|
||
} else if (result > 1) {
|
||
result = 1;
|
||
}
|
||
return result;
|
||
}
|
||
|
||
//
|
||
// Resolve Fedrizzi equation system
|
||
//
|
||
consistency.fedrizziResolveEquationSystem = function fedrizziResolveEquationSystem(Q, B, set) {
|
||
var result = [];
|
||
var inverseQ = numeric.inv(Q);
|
||
var values = numeric.dot(inverseQ, B);
|
||
var value;
|
||
for (var v = 0; v < values.length; v++) {
|
||
value = values[v];
|
||
result[v] = (isNaN(value) || (value < 0) || (value > 1))
|
||
? NaN
|
||
: value;
|
||
}
|
||
return result;
|
||
}
|
||
|
||
//
|
||
// Compute 'position' element of Right Hand Side
|
||
//
|
||
consistency.fedrizziElementValueOfRHSV = function fedrizziElementValueOfRHSV(preference, set, k) {
|
||
|
||
var s_k = set[k].i;
|
||
var t_k = set[k].j;
|
||
|
||
var s_h, t_h;
|
||
var R_s_k = [];
|
||
var R_s_k_above = [];
|
||
var R_s_k_below = [];
|
||
var C_t_k = [];
|
||
var C_t_k_above = [];
|
||
var C_t_k_below = [];
|
||
for (var h = 0; h < set.length; h++) {
|
||
if (h != k) {
|
||
s_h = set[h].i;
|
||
t_h = set[h].j;
|
||
if (s_h == s_k) {
|
||
if (R_s_k.indexOf(t_h) == -1) {
|
||
R_s_k[R_s_k.length] = t_h;
|
||
if (s_h < t_h) {
|
||
R_s_k_above[R_s_k_above.length] = t_h;
|
||
} else {
|
||
R_s_k_below[R_s_k_below.length] = t_h;
|
||
}
|
||
}
|
||
} else if (t_h == t_k) {
|
||
if (C_t_k.indexOf(s_h) == -1) {
|
||
C_t_k[C_t_k.length] = s_h;
|
||
if (s_h < t_h) {
|
||
C_t_k_above[C_t_k_above.length] = s_h;
|
||
} else {
|
||
C_t_k_below[C_t_k_below.length] = s_h;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
var n = preference.getNumberOfAlternatives();
|
||
var r_s_k_h_sum = 0;
|
||
var r_h_t_k_sum = 0;
|
||
for (var h = 0; h < n; h++) {
|
||
if ((h != t_k) && (R_s_k.indexOf(h) == -1)) {
|
||
r_s_k_h_sum += preference.getValue(s_k | 0, h | 0);
|
||
}
|
||
if ((h != s_k) && (C_t_k.indexOf(h) == -1)) {
|
||
r_h_t_k_sum += preference.getValue(h | 0, t_k | 0);
|
||
}
|
||
}
|
||
|
||
return R_s_k_below.length
|
||
+ C_t_k_below.length
|
||
+ r_s_k_h_sum
|
||
+ r_h_t_k_sum
|
||
- n / 2;
|
||
}
|
||
|
||
//
|
||
// Optimal preference value for more than two preference relations
|
||
//
|
||
consistency.fedrizziOptimalValueForMoreThanTwoElements = function fedrizziOptimalValueForMoreThanTwoElements(preference, set) {
|
||
var result = [];
|
||
|
||
var n = preference.getNumberOfAlternatives();
|
||
var diagonal = n - 2;
|
||
var Q = [];
|
||
var value;
|
||
for (var row = 0; row < set.length; row++) {
|
||
Q[row] = [];
|
||
for (var col = 0; col < set.length; col++) {
|
||
if (row == col) {
|
||
Q[row][col] = diagonal;
|
||
} else if ((set[row].i == set[col].i) || (set[row].j == set[col].j)) {
|
||
Q[row][col] = -1;
|
||
} else if ((set[row].i == set[col].j) || (set[row].j == set[col].i)) {
|
||
Q[row][col] = 1;
|
||
} else {
|
||
Q[row][col] = 0;
|
||
}
|
||
}
|
||
}
|
||
|
||
var completeSet = [];
|
||
for (var s = 0; s < set.length; s++) {
|
||
completeSet[completeSet.length] = set[s];
|
||
completeSet[completeSet.length] = {
|
||
i: set[s].j,
|
||
j: set[s].i
|
||
};
|
||
}
|
||
var B = [];
|
||
for (var s = 0; s < set.length; s++) {
|
||
B[B.length] = consistency.fedrizziElementValueOfRHSV(preference, completeSet, s * 2);
|
||
}
|
||
|
||
return consistency.fedrizziResolveEquationSystem(Q, B, set);
|
||
}
|
||
|
||
//
|
||
// Optimal preference value for two preference relations
|
||
//
|
||
consistency.fedrizziOptimalValueForTwoElements =function fedrizziOptimalValueForTwoElements(preference, set) {
|
||
var n = preference.getNumberOfAlternatives();
|
||
|
||
var diagonal = n - 2;
|
||
var Q = [
|
||
[diagonal, -1],
|
||
[-1, diagonal]];
|
||
|
||
var s, t, u;
|
||
t = ((set[0].i == set[1].i) || (set[0].i == set[1].j))
|
||
? set[0].i
|
||
: set[0].j;
|
||
|
||
var r_st = (set[0].i == t)
|
||
? {i: set[0].j, j: set[0].i}
|
||
: set[0];
|
||
s = r_st.i;
|
||
|
||
var r_ut = (set[1].i == t)
|
||
? {i: set[1].j, j: set[1].i}
|
||
: set[1];
|
||
u = r_ut.i;
|
||
|
||
var r_sh_sum = 0;
|
||
var r_uh_sum = 0;
|
||
var r_ht_sum = 0;
|
||
for (var h = 0; h < n; h++) {
|
||
if (h != t) {
|
||
r_sh_sum += preference.getValue(s | 0, h | 0);
|
||
r_uh_sum += preference.getValue(u | 0, h | 0);
|
||
}
|
||
if ((h != s) && (h != u)) {
|
||
r_ht_sum += preference.getValue(h | 0, t | 0);
|
||
}
|
||
}
|
||
|
||
var B = [
|
||
r_sh_sum + r_ht_sum - (n / 2),
|
||
r_uh_sum + r_ht_sum - (n / 2)];
|
||
|
||
var result = consistency.fedrizziResolveEquationSystem(Q, B, set);
|
||
var value;
|
||
for (var v = 0; v < result.length; v++) {
|
||
value = result[v];
|
||
result[v] = (isNaN(value))
|
||
? value
|
||
: (set[v].i == t)
|
||
? 1 - value
|
||
: value;
|
||
}
|
||
return result;
|
||
}
|
||
|
||
//
|
||
// Optimal preference relations values
|
||
//
|
||
consistency.fedrizziOptimalValues = function fedrizziOptimalValues(preference, set) {
|
||
var result = [];
|
||
var values = [];
|
||
if (set.length == 1) {
|
||
values[0] = consistency.fedrizziOptimalValue(preference, set[0].i, set[0].j);
|
||
} else if (set.length == 2) {
|
||
values = consistency.fedrizziOptimalValueForTwoElements(preference, set);
|
||
} else {
|
||
values = consistency.fedrizziOptimalValueForMoreThanTwoElements(preference, set);
|
||
}
|
||
for (var v = 0; v < values.length; v++) {
|
||
result[v] = {
|
||
i: set[v].i,
|
||
j: set[v].j,
|
||
v: values[v]
|
||
};
|
||
}
|
||
return result;
|
||
}
|
||
|
||
//
|
||
// Compute missing preference relations
|
||
//
|
||
consistency.getMissingPreferenceRelations = function getMissingPreferenceRelations(preference) {
|
||
var result = [];
|
||
var alternatives = preference.getNumberOfAlternatives();
|
||
var counter = 0;
|
||
for (var i = 0; i < alternatives - 1; i++) {
|
||
for (var j = i + 1; j < alternatives; j++) {
|
||
if (isNaN(preference.getValue(i | 0, j | 0))) {
|
||
result[counter++] = {i: i, j: j};
|
||
}
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
//
|
||
// Compute indexes of first dependent set in relations
|
||
//
|
||
consistency.getFirstDependentSetIndexes = function getFirstDependentSetIndexes(relations) {
|
||
var indexes = [];
|
||
var initialLength;
|
||
var i, j;
|
||
do {
|
||
initialLength = indexes.length;
|
||
for (var relation = 0; relation < relations.length; relation++) {
|
||
i = relations[relation].i;
|
||
j = relations[relation].j;
|
||
if (indexes.length == 0) {
|
||
indexes[indexes.length] = i;
|
||
indexes[indexes.length] = j;
|
||
} else {
|
||
if (indexes.indexOf(i) > -1) {
|
||
if (indexes.indexOf(j) == -1) {
|
||
indexes[indexes.length] = j;
|
||
}
|
||
} else if (indexes.indexOf(j) > -1) {
|
||
if (indexes.indexOf(i) == -1) {
|
||
indexes[indexes.length] = i;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
} while (indexes.length != initialLength);
|
||
return indexes;
|
||
}
|
||
|
||
//
|
||
// Set of index relations
|
||
// @return {result.set: set of index relations, result.rest: rest of relations}
|
||
//
|
||
consistency.extractIndexSet = function extractIndexSet(relations, indexes) {
|
||
var set = [];
|
||
var rest = [];
|
||
for (var relation = 0; relation < relations.length; relation++) {
|
||
if ((indexes.indexOf(relations[relation].i) > -1) || (indexes.indexOf(relations[relation].j) > -1)) {
|
||
set[set.length] = relations[relation];
|
||
} else {
|
||
rest[rest.length] = relations[relation];
|
||
}
|
||
}
|
||
return {set: set, rest: rest};
|
||
}
|
||
|
||
//
|
||
// Compute independent relation sets
|
||
//
|
||
consistency.computeIndependentRelationSets = function computeIndependentRelationSets(relations) {
|
||
var result = [];
|
||
var indexes;
|
||
var dependentSet;
|
||
while (relations.length > 0) {
|
||
indexes = consistency.getFirstDependentSetIndexes(relations);
|
||
dependentSet = consistency.extractIndexSet(relations, indexes);
|
||
result[result.length] = dependentSet.set;
|
||
relations = dependentSet.rest;
|
||
}
|
||
return result;
|
||
}
|
||
|
||
// Consistency level of additive FPR
|
||
// E. Herrera-Viedma, F. Chiclana, F. Herrera, and S. Alonso.
|
||
// Group decision-making model with incomplete fuzzy preference relations based on additive consistency.
|
||
// IEEETransactions on Systems, Man, and Cybernetics, Part B (Cybernetics), 37(1):176–189, 2007
|
||
|
||
consistency.consistencyLevelAdditive = function consistencyLevelAdditive(preference) {
|
||
var n = preference.getNumberOfAlternatives();
|
||
|
||
var acum = 0;
|
||
for(var i = 0; i < n - 2; i++) {
|
||
for(var j = i + 1; j < n - 1; j++) {
|
||
for(var t = j + 1; t < n; t++) {
|
||
acum += Math.abs(preference.getValue(i |0, j | 0) + preference.getValue(j |0, t | 0) - preference.getValue(i |0, t | 0) - 0.5)
|
||
}
|
||
}
|
||
}
|
||
|
||
return 1 - ((4 / (n * (n - 1) * (n - 2))) * acum);
|
||
|
||
}
|
||
|
||
//
|
||
// Preference optimizer based on Fedrizzi paper
|
||
// 'Incomplete pairwise comparison and consistency optimization'
|
||
//
|
||
// http://dx.doi.org/10.1016/j.ejor.2006.09.065
|
||
//
|
||
consistency.fedrizziConsistencyOptimizer = function fedrizziConsistenceOptimizer(preference) {
|
||
var result = FPR.parseFPR(preference.toString());
|
||
var missingPreferenceRelations = consistency.getMissingPreferenceRelations(result);
|
||
if (missingPreferenceRelations.length == 0) {
|
||
return result;
|
||
} else {
|
||
var sets = consistency.computeIndependentRelationSets(missingPreferenceRelations);
|
||
var changes;
|
||
for (var s = 0; s < sets.length; s++) {
|
||
changes = consistency.fedrizziOptimalValues(result, sets[s]);
|
||
for (var c = 0; c < changes.length; c++) {
|
||
result.setValueSymmetrically(
|
||
changes[c].i | 0,
|
||
changes[c].j | 0,
|
||
changes[c].v);
|
||
}
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
//
|
||
// Inconsistency index of a triad of alternatives
|
||
//
|
||
// @param a x_ij
|
||
// @param b x_jk
|
||
// @param c x_ik
|
||
consistency.koczkodajTriadInconsistency = function koczkodajTriadInconsistency(a, b, c) {
|
||
var v1 = Math.abs(1 - (b / (a * c)));
|
||
var v2 = Math.abs(1 - ((a * c) / b));
|
||
return Math.min(v1, v2);
|
||
}
|
||
|
||
//
|
||
// Koczkodaj's inconsistency index
|
||
//
|
||
// 'A new definition of consistency of pairwise comparisons'
|
||
// http://dx.doi.org/10.1016/0895-7177(93)90059-8
|
||
//
|
||
// @param preference FPR
|
||
//
|
||
consistency.koczkodajInconsistencyIndex = function koczkodajInconsistencyIndex(preference) {
|
||
if (consistency.containsMissingValues(preference)) {
|
||
return NaN;
|
||
}
|
||
var saatyPreference = adapters.fpr2jsSaatyRelation(preference);
|
||
var alternatives = saatyPreference.length;
|
||
var a, b, c;
|
||
var result = 0;
|
||
for (var i = 0; i < (alternatives - 1); i++) {
|
||
for (var j = i + 1; j < (alternatives - 1); j++) {
|
||
a = saatyPreference[i][j];
|
||
for (var k = j + 1; k < alternatives; k++) {
|
||
b = saatyPreference[j][k];
|
||
c = saatyPreference[i][k];
|
||
result = Math.max(result, consistency.koczkodajTriadInconsistency(a, b, c));
|
||
}
|
||
}
|
||
}
|
||
return result.toFixed(2)/1;
|
||
}
|
||
|
||
//
|
||
// Koczkodaj's element inconsistency index
|
||
//
|
||
// 'A new definition of consistency of pairwise comparisons'
|
||
// http://dx.doi.org/10.1016/0895-7177(93)90059-8
|
||
//
|
||
// @param preference FPR
|
||
// @param i Alternative index i
|
||
// @param j Alternative index j
|
||
//
|
||
consistency.koczkodajElementInconsistencyIndex = function koczkodajElementInconsistencyIndex(preference, i, j) {
|
||
if (consistency.containsMissingValues(preference)) {
|
||
return NaN;
|
||
}
|
||
var alternatives = preference.getNumberOfAlternatives();
|
||
if ((i < 0) || (i >= alternatives) || (j < 0) || (j >= alternatives)) {
|
||
return NaN;
|
||
}
|
||
if (i == j) {
|
||
return 0;
|
||
}
|
||
var saatyPreference = adapters.fpr2jsSaatyRelation(preference);
|
||
var a, b, c;
|
||
var result = 0;
|
||
for (var ii = 0; ii < (alternatives - 1); ii++) {
|
||
for (var jj = ii + 1; jj < (alternatives - 1); jj++) {
|
||
a = saatyPreference[ii][jj];
|
||
for (var k = jj + 1; k < alternatives; k++) {
|
||
b = saatyPreference[jj][k];
|
||
c = saatyPreference[ii][k];
|
||
if (((i == ii) || (i == jj) || (i == k)) && ((j == ii) || (j == jj) || (j == k))) {
|
||
result = Math.max(result, consistency.koczkodajTriadInconsistency(a, b, c));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return result.toFixed(2)/1;
|
||
}
|
||
|
||
//
|
||
// Consistency LSM
|
||
//
|
||
// A Comparison of Two Methods for Determining the Weights of Belonging to Fuzzy Sets
|
||
// DOI: 10.1007/BF00933438
|
||
//
|
||
// @param preference FPR
|
||
//
|
||
consistency.LSM = function LSM(preference) {
|
||
if (consistency.containsMissingValues(preference)) {
|
||
return NaN;
|
||
}
|
||
|
||
var saatyPreference = adapters.fpr2jsSaatyRelation(preference);
|
||
var alternatives = saatyPreference.length;
|
||
|
||
var m = [];
|
||
for (var i = 0; i <= alternatives; i++) {
|
||
m[i] = (i != alternatives) ? 0 : 1;
|
||
}
|
||
var B = [];
|
||
for (var i = 0; i <= alternatives; i++) {
|
||
B[i] = [];
|
||
}
|
||
var aux;
|
||
for (var i = 0; i <= alternatives; i++) {
|
||
for (var j = i; j <= alternatives; j++) {
|
||
if (i == j) {
|
||
if (i == alternatives) {
|
||
B[i][j] = 0;
|
||
} else {
|
||
aux = alternatives - 1;
|
||
for (var k = 0; k < alternatives; k++) {
|
||
if (k != j) {
|
||
aux += Math.pow(saatyPreference[k][j], 2);
|
||
}
|
||
}
|
||
B[i][j] = aux;
|
||
}
|
||
} else if ((i == alternatives) || (j == alternatives)) {
|
||
B[j][i] = B[i][j] = 1;
|
||
} else {
|
||
B[j][i] = B[i][j] = - saatyPreference[i][j] - saatyPreference[j][i];
|
||
}
|
||
}
|
||
}
|
||
|
||
var inverseB = numeric.inv(B);
|
||
var w = numeric.dot(inverseB, m);
|
||
|
||
var solution = 0;
|
||
for (var i = 0; i < alternatives; i++) {
|
||
for (var j = 0; j < alternatives; j++) {
|
||
solution += Math.pow((saatyPreference[i][j] * w[j]) - w[i], 2);
|
||
}
|
||
}
|
||
return solution.toFixed(2)/1;
|
||
}
|
||
|
||
//
|
||
// Dong's consistency index
|
||
//
|
||
// On consistency measures of linguistic preference relations - Corollary 1
|
||
// doi:10.1016/j.ejor.2007.06.013
|
||
//
|
||
// @param lpr LPR
|
||
//
|
||
consistency.dongConsistencyIndex = function(lpr) {
|
||
var P = LPR.dongAverageLPR(lpr);
|
||
if (typeof P == 'number') {
|
||
return NaN;
|
||
}
|
||
|
||
return LPR.dongDistanceBetweenTwoLPR(lpr, P);
|
||
}
|
||
|
||
//
|
||
// Approximates Chi-Square critical value
|
||
//
|
||
// @param degreesOfFreedom Degrees of freedom
|
||
// @param Significance level
|
||
//
|
||
consistency.approximateChiSquareCriticalValue = function (degreesOfFreedom, significanceLevel) {
|
||
var threshold = 0.001;
|
||
var ChiSquaredDistribution = Java.type('org.apache.commons.math3.distribution.ChiSquaredDistribution');
|
||
var distribution = new ChiSquaredDistribution(degreesOfFreedom);
|
||
var increment = 10;
|
||
var value;
|
||
var nextValue = 0;
|
||
var computed;
|
||
var exit = false;
|
||
do {
|
||
value = nextValue;
|
||
computed = distribution.cumulativeProbability(value);
|
||
if (computed > significanceLevel) {
|
||
value -= increment;
|
||
nextValue -= increment;
|
||
increment /= 2;
|
||
} else {
|
||
exit = Math.abs(computed - significanceLevel) < threshold;
|
||
}
|
||
if (!exit) {
|
||
nextValue += increment;
|
||
}
|
||
} while (!exit);
|
||
return value;
|
||
}
|
||
|
||
//
|
||
// Dong's consistency index threshold
|
||
//
|
||
// On consistency measures of linguistic preference relations - Theorem 3
|
||
// doi:10.1016/j.ejor.2007.06.013
|
||
//
|
||
// @param lpr LPR
|
||
// @param significanceLevel Significance level
|
||
// @param standardDeviation Standard deviation
|
||
//
|
||
consistency.dongConsistencyIndexThreshold = function(lpr, significanceLevel, standardDeviation) {
|
||
if (typeof lpr == 'undefined') {
|
||
return NaN;
|
||
}
|
||
|
||
if (typeof lpr.preference == 'undefined') {
|
||
return NaN;
|
||
}
|
||
|
||
var n = lpr.n;
|
||
var T = lpr.ids.length;
|
||
var degreesOfFreedom = (n * (n - 1)) / 2;
|
||
var criticalValue = consistency.approximateChiSquareCriticalValue(degreesOfFreedom, significanceLevel);
|
||
var result = (standardDeviation/T) * Math.sqrt(1/degreesOfFreedom * criticalValue)
|
||
return result.toFixed(2)/1;
|
||
}
|
||
|
||
|
||
//
|
||
// Wu consistency index
|
||
//
|
||
// Managing consistency and consensus in group decision making with hesitant fuzzy linguistic preference relations - Definition 9
|
||
// http://dx.doi.org/10.1016/j.omega.2015.12.005
|
||
//
|
||
// @param hlpr HLPR
|
||
//
|
||
consistency.wuConsistencyIndex = function(hlpr) {
|
||
if (typeof hlpr == 'undefined') {
|
||
return NaN;
|
||
}
|
||
if (typeof hlpr.lowerPreference == 'undefined') {
|
||
return NaN;
|
||
}
|
||
var E = HLPR.expectedLPR(hlpr);
|
||
if (typeof E == 'number') {
|
||
return NaN;
|
||
}
|
||
var C = LPR.dongAverageLPR(E);
|
||
var result = HLPR.wuDistanceBetweenExpectedAndAdittiveConsistent(E, C);
|
||
return result.toFixed(2)/1;
|
||
}
|
||
|
||
//
|
||
// Check if a FPR verifies the weak transitivity
|
||
//
|
||
// Exploring consistency for hesitant preference relations in Decision Making- Discussing concepts, meaning and taxonomy - Definition 4
|
||
// DOI: 10.1007/BF00933438
|
||
//
|
||
// @param preference FPR
|
||
//
|
||
consistency.weakTransitivity = function(preference) {
|
||
var n = preference.getNumberOfAlternatives();
|
||
for (var i = 0; i < n; i++) {
|
||
for (var j = 0; j < n; j++) {
|
||
if (i != j) {
|
||
if (preference.getValue(i | 0, j | 0) < 0.5) {
|
||
for (var k = 0; k < n; k++) {
|
||
if ((i != k) && (j != k)) {
|
||
if ((preference.getValue(i | 0, k | 0) >= 0.5) && (preference.getValue(k | 0, j | 0) >= 0.5)) {
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
//
|
||
// Check if a FPR is ordinal consistent
|
||
//
|
||
// Exploring consistency for hesitant preference relations in Decision Making- Discussing concepts, meaning and taxonomy - Definition 7
|
||
// DOI: 10.1007/BF00933438
|
||
//
|
||
// @param preference FPR
|
||
//
|
||
consistency.ordinalConsistent = function(preference) {
|
||
var n = preference.getNumberOfAlternatives();
|
||
var p_i_k, p_k_j;
|
||
for (var i = 0; i < n; i++) {
|
||
for (var j = 0; j < n; j++) {
|
||
if (i != j) {
|
||
if (preference.getValue(i | 0, j | 0) <= 0.5) {
|
||
for (var k = 0; k < n; k++) {
|
||
if ((i != k) && (j != k)) {
|
||
p_i_k = preference.getValue(i | 0, k | 0);
|
||
p_k_j = preference.getValue(k | 0, j | 0);
|
||
if (((p_i_k > 0.5) && (p_k_j >= 0.5)) || ((p_i_k >= 0.5) && (p_k_j > 0.5))) {
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
consistency.calculateRwithAditiveConsistency = function(preference){
|
||
var result=new FPR(preference.getNumberOfAlternatives());
|
||
|
||
for(var i=0;i<preference.getNumberOfAlternatives();i++){
|
||
for(var j=0;j<preference.getNumberOfAlternatives();j++){
|
||
var value=0;
|
||
for(var k=0;k<preference.getNumberOfAlternatives();k++){
|
||
|
||
value=value+((preference.getValue(i | 0, k | 0)+preference.getValue(k | 0, j | 0))-0.5);
|
||
}
|
||
//TODO a veces el valor se pasa de 1 o es menor que 0
|
||
|
||
value=(value/preference.getNumberOfAlternatives());
|
||
if(value>1) value=1;
|
||
if(value<0) value=0;
|
||
|
||
result.setValueSymmetrically(i | 0, j | 0, value);
|
||
|
||
}
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
consistency.calculateCIPAdditiveConsistency = function(preference, preferenceR){
|
||
var value=0;
|
||
var result=0;
|
||
var n=preference.getNumberOfAlternatives();
|
||
for(var i=0;i<n-1;i++){
|
||
for(var j=i+1;j<n;j++){
|
||
var dif=0;
|
||
dif=preference.getValue(i | 0,j | 0)-preferenceR.getValue(i | 0, j | 0);
|
||
value=value+Math.pow(dif,2);
|
||
}
|
||
}
|
||
result=Math.sqrt((value*(2/((n-1)*n))));
|
||
|
||
return result;
|
||
}
|
||
|
||
consistency.calculateCI = function(alfa,degreeFreedom){
|
||
var str='qchisq('+alfa+','+degreeFreedom+', lower.tail=FALSE)';
|
||
var rengine = ase.evalCode('R', str);
|
||
var stringData=""+rengine;
|
||
stringData=stringData.split("(");
|
||
stringData=stringData[1].split(")");
|
||
stringData=stringData[0];
|
||
var result=parseFloat(stringData);
|
||
|
||
return result;
|
||
}
|
||
|
||
/*
|
||
Generate a consistent additive preference by iterative algorithm 2
|
||
The additive consistency measure of fuzzy reciprocal preference relations Yejun Xu, Xia Lu, Huimin Hang March 2017
|
||
|
||
*/
|
||
consistency.YejunXuRandomFPRDevelop = function(n){
|
||
var RandomFPR = new FPR(n);
|
||
var R_FPR = new FPR(n);
|
||
|
||
for(var i=0;i<n-1;i++){
|
||
for(var j=i+1;j<n;j++){
|
||
RandomFPR.setValueSymmetrically(i | 0, j | 0, Math.random().toFixed(2)/1);
|
||
}
|
||
}
|
||
R_FPR=consistency.calculateRwithAditiveConsistency(RandomFPR);
|
||
var CIP=consistency.calculateCIPAdditiveConsistency(RandomFPR,R_FPR);
|
||
var chi=consistency.calculateCI(0.9,((n*(n-1))/2));
|
||
var CI=0.2*(Math.sqrt(((2/(n*(n-1)))*chi)));
|
||
|
||
while(CIP>CI){
|
||
R_FPR=consistency.calculateRwithAditiveConsistency(RandomFPR);
|
||
|
||
var max=0;
|
||
var str="";
|
||
for(var i=0;i<n;i++){
|
||
for(var j=0;j<n;j++){
|
||
if(Math.abs((RandomFPR.getValue(i | 0, j | 0)-R_FPR.getValue(i | 0, j | 0)))> max ){
|
||
max=Math.abs((RandomFPR.getValue(i | 0, j | 0)-R_FPR.getValue(i | 0, j | 0)));
|
||
str=i+","+j+"|";
|
||
}else if(Math.abs((RandomFPR.getValue(i | 0, j | 0)-R_FPR.getValue(i | 0, j | 0)))== max){
|
||
str+=""+i+","+j+"|";
|
||
}
|
||
}
|
||
}
|
||
var array=str.split("|");
|
||
for(var i=0;i<array.length-1;i++){
|
||
var numbers=array[i].split(",");
|
||
RandomFPR.setValueSymmetrically(numbers[0] | 0, numbers[1] | 0, R_FPR.getValue(numbers[0] | 0, numbers[1] | 0));
|
||
}
|
||
CIP=consistency.calculateCIPAdditiveConsistency(RandomFPR,R_FPR);
|
||
|
||
}
|
||
|
||
return RandomFPR;
|
||
}
|
||
|
||
/*
|
||
Consistency Index based in paper "The additive consistency measure of fuzzy reciprocal preference relations"
|
||
Yejun Xu, Xia Lu, Huimin Hang
|
||
|
||
*/
|
||
|
||
consistency.CalculateIndexAdditiveConsistencyXU = function(RandomFPR){
|
||
var n=RandomFPR.getNumberOfAlternatives();
|
||
var R_FPR = new FPR(n);
|
||
|
||
R_FPR=consistency.calculateRwithAditiveConsistency(RandomFPR);
|
||
var CIP=consistency.calculateCIPAdditiveConsistency(RandomFPR,R_FPR);
|
||
CIP=Math.round(CIP*100)/100;
|
||
return CIP;
|
||
}
|
||
|
||
|
||
/*
|
||
Consistency Index based in paper :
|
||
Consensus building with individual consistency control in group decision making
|
||
Cong-Cong Lia, Rosa M. Rodriguez, Francisco Herrera, Luis Martinez, and Yucheng Donga
|
||
*/
|
||
|
||
consistency.CalculateIndexAdditiveConsistencyCongLi = function(preference){
|
||
var n=preference.getNumberOfAlternatives();
|
||
var value=0;
|
||
|
||
for(var i=0;i<n;i++){
|
||
for(var j=0;j<n;j++){
|
||
for(var k=0;k<n;k++){
|
||
value=value+(Math.abs(preference.getValue(i | 0, j | 0)+preference.getValue(j | 0, k | 0)-preference.getValue(i | 0, k | 0)-0.5));
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
var CIP=1-((2/((3*n)*(n-1)*(n-2)))*value);
|
||
CIP=Math.round(CIP*100)/100;
|
||
return CIP;
|
||
}
|
||
|
||
|
||
|
||
/*
|
||
Generate a consistent additive preference / Pij + Pjk + Pki = 3/2 (i,j,k) E n
|
||
|
||
*/
|
||
|
||
consistency.AdditiveConsistencyRandomFPR = function(n){
|
||
var RandomFPR = new FPR(n);
|
||
var R_FPR = new FPR(n);
|
||
for(var i=0;i<n-1;i++){
|
||
RandomFPR.setValueSymmetrically(i | 0, (i+1) | 0,Math.random().toFixed(2)/1);
|
||
}
|
||
|
||
var pref=RandomFPR.getPreferences();
|
||
|
||
var changes=false;
|
||
var minimum=100;
|
||
|
||
for(var i=0;i<n;i++){
|
||
for(var j=0;j<n;j++){
|
||
if(isNaN(RandomFPR.getValue(i | 0,j | 0)) && i>j){
|
||
var value=((i-j)+1)/2;
|
||
|
||
for(var l=j;l<i;l++){
|
||
value=Math.round((value-RandomFPR.getValue(l | 0, (l+1) | 0))*100)/100;
|
||
}
|
||
if(value<0 ||value>1) {
|
||
changes=true;
|
||
}
|
||
|
||
pref[i][j]=value;
|
||
pref[j][i]=1-value;
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
var minimumAux=100;
|
||
var maximumAux=0;
|
||
for(var i=0;i<n-1;i++){
|
||
for(var j=i+1;j<n;j++){
|
||
if(minimumAux>pref[i][j]){
|
||
minimumAux=pref[i][j];
|
||
}
|
||
if(maximumAux<pref[i][j]){
|
||
maximumAux=pref[i][j];
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
var positiveMinimum=(-1)*minimumAux;
|
||
|
||
for(var i=0;i<n-1;i++){
|
||
for(var j=i+1;j<n;j++){
|
||
if(minimumAux < 0){
|
||
if( pref[i][j] > 0 && minimum > pref[i][j] && pref[i][j] > positiveMinimum ){
|
||
minimum=pref[i][j];
|
||
}
|
||
}else if(maximumAux > 1){
|
||
if( pref[i][j] > 0 && minimum > pref[i][j] && pref[i][j] > (maximumAux-1)){
|
||
minimum=pref[i][j];
|
||
}
|
||
|
||
}else{
|
||
if( pref[i][j] > 0 && minimum > pref[i][j]){
|
||
minimum=pref[i][j];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
for(var i=0;i<n-1;i++){
|
||
for(var j=i+1;j<n;j++){
|
||
if(changes == true){
|
||
var result=(pref[i][j]+minimum)/(1+(2*minimum));
|
||
RandomFPR.setValueSymmetrically(i | 0, j | 0, Math.round(result*100)/100);
|
||
}else{
|
||
RandomFPR.setValueSymmetrically(i | 0, j | 0, pref[i][j]);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
return RandomFPR;
|
||
}
|
||
|
||
|
||
consistency.checkAdditiveConsistency = function (preference) {
|
||
if (consistency.containsMissingValues(preference)) {
|
||
return NaN;
|
||
}
|
||
|
||
for(var i=0;i<preference.getNumberOfAlternatives();i++){
|
||
for(var j=0;j<preference.getNumberOfAlternatives();j++){
|
||
for(var k=0;k<preference.getNumberOfAlternatives();k++){
|
||
var value=Math.round((preference.getValue(i | 0, j | 0)+preference.getValue(j | 0, k | 0)+preference.getValue(k | 0, i | 0))*10)/10;
|
||
if(value!=1.5){
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
return true;
|
||
}
|
||
|
||
/*
|
||
Generate a consistent multiplicative preference
|
||
|
||
*/
|
||
|
||
consistency.multiplicativeConsistencyRandomFPR = function(n){
|
||
var RandomFPR = new FPR(n);
|
||
for(var i=0;i<n-1;i++){
|
||
RandomFPR.setValueSymmetrically(i | 0, (i+1) | 0, Math.random().toFixed(2)/1);
|
||
}
|
||
|
||
for(var i=0;i<n;i++){
|
||
for(var j=0;j<n;j++){
|
||
var numerator=1;
|
||
var denominatorLeft=1;
|
||
var denominatorRight=1;
|
||
var value=0;
|
||
if(isNaN(RandomFPR.getValue(i | 0, j | 0)) && i<j){
|
||
for(var l=0;l<=(j-(i+1));l++){
|
||
value=Math.round(RandomFPR.getValue((i+l) | 0,(i+l+1) | 0)*10000)/10000;
|
||
numerator=Math.round((numerator*value)*10000)/10000;
|
||
denominatorLeft=Math.round((denominatorLeft*value)*10000)/10000;
|
||
denominatorRight=Math.round((denominatorRight*(1-value))*10000)/10000;
|
||
}
|
||
var result=(numerator/(denominatorLeft+denominatorRight));
|
||
RandomFPR.setValueSymmetrically(i | 0, j | 0, result);
|
||
}
|
||
}
|
||
}
|
||
|
||
return RandomFPR;
|
||
}
|
||
|
||
/*
|
||
Generate a consistent multiplicative preference
|
||
|
||
*/
|
||
consistency.RandomMPR = function(n){
|
||
var RandomFPR = new MPR(n);
|
||
for(var i=0;i<n-1;i++){
|
||
for(var j=i+1;j<n;j++){
|
||
var random = (Math.random() * (9 - 1)) + 1;
|
||
random=Math.round(random);
|
||
var randomDiv = (Math.random() * (10 - 1)) + 1;
|
||
if(randomDiv<5){
|
||
RandomFPR.setValueSymmetrically(i | 0, j | 0, random);
|
||
}else{
|
||
RandomFPR.setValueSymmetrically(i | 0, j | 0, 1/random);
|
||
}
|
||
}
|
||
}
|
||
return RandomFPR;
|
||
}
|
||
|
||
|
||
consistency.multiplicativegeometricconsistencyindex = function(preference){
|
||
var n=preference.getNumberOfAlternatives();
|
||
var result=0;
|
||
for(var i=0;i<n;i++){
|
||
for(var j=0;j<n;j++){
|
||
if( i<j){
|
||
var value=preference.getValue(i | 0, j | 0);
|
||
var kValue=1;
|
||
for(var k=0;k<n;k++){
|
||
kValue*=preference.getValue(i | 0, k | 0)*preference.getValue(k | 0, j | 0);
|
||
}
|
||
kValue=Math.pow(kValue,(1/n));
|
||
result+=(2/(3*(n-1)*(n-2)))*Math.abs((Math.log(value) / Math.log(9))-(Math.log(kValue) / Math.log(9)));
|
||
}
|
||
}
|
||
}
|
||
return 1-result;
|
||
}
|
||
|
||
|
||
consistency.checkMultiplicativeConsistency = function (preference) {
|
||
if (consistency.containsMissingValues(preference)) {
|
||
return NaN;
|
||
}
|
||
|
||
for(var i=0;i<preference.getNumberOfAlternatives();i++){
|
||
for(var j=0;j<preference.getNumberOfAlternatives();j++){
|
||
for(var k=0;k<preference.getNumberOfAlternatives();k++){
|
||
var value1=preference.getValue(i | 0, j | 0)*preference.getValue(j | 0, k | 0)*preference.getValue(k | 0, i | 0);
|
||
var value2=preference.getValue(j | 0, i | 0)*preference.getValue(i | 0, k | 0)*preference.getValue(k | 0, j | 0);
|
||
value1=Math.round(value1*10000)/10000;
|
||
value2=Math.round(value2*10000)/10000;
|
||
if(Math.abs(value1-value2)>0.01){
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
/*
|
||
LPR Consistency Index based in paper :
|
||
Consistency Measures of Linguistic Preference Relations and Its Propertires in Group Decision Making
|
||
Yucheng Dong and Yinfeng Xu
|
||
*/
|
||
|
||
consistency.CalculateIndexConsistencyLPRDong = function(preference){
|
||
var n=preference.getNumberOfAlternatives();
|
||
var value=0;
|
||
var CIP;
|
||
var T=preference.getDomain().getLabelSet().getCardinality();
|
||
for(var i=0;i<n;i++){
|
||
for(var j=i+1;j<n;j++){
|
||
var sum=0;
|
||
for(var c=0;c<n;c++){
|
||
sum=sum+(preference.getLabelIndex(i,c)+preference.getLabelIndex(c,j));
|
||
}
|
||
var l=preference.getLabelIndex(i,j)-(sum/n);
|
||
var y=Math.pow(l,2);
|
||
value=value+y;
|
||
}
|
||
}
|
||
CIP=(Math.sqrt((2*value)/(n*(n-1))))/T;
|
||
return CIP;
|
||
}
|
||
|
||
|
||
/*
|
||
Consistency Index based in paper :
|
||
Consistency Measures for Hesitant Fuzzy Linguistic Preference Relations
|
||
Bin Zhu, Zeshui Xu
|
||
*/
|
||
|
||
consistency.CalculateIndexConsistencyHLPRZhu = function(preference){
|
||
var NHFLPR = consistency.normalizeHLPR(preference);
|
||
|
||
//The HFLPR has not been constructed properly if isNormalized = false
|
||
var isNormalized = consistency.checkIsNormalized(NHFLPR);
|
||
if(!isNormalized) {
|
||
return 1;
|
||
}
|
||
|
||
var consistentNHFLPR = consistency.computeConsistentNHFLPR(NHFLPR);
|
||
|
||
var acumEpsilon = 0;
|
||
for(var i = 0; i < preference.getNumberOfAlternatives() - 1; ++i) {
|
||
for(var j = i + 1; j < preference.getNumberOfAlternatives(); ++j) {
|
||
acumEpsilon += Math.pow(consistency.computeEpsilon(NHFLPR[i][j], consistentNHFLPR[i][j]), 2);
|
||
}
|
||
}
|
||
|
||
var T = preference.getDomain(0 | 0, 0 | 0).getLabelSet().getCardinality();
|
||
var n = preference.getNumberOfAlternatives();
|
||
return (1 / T) * Math.sqrt((2 / (n * (n - 1))) * acumEpsilon);
|
||
}
|
||
|
||
consistency.normalizeHLPR = function(preference) {
|
||
var bMax = 0;
|
||
var bCurrent;
|
||
for(var i = 0; i < preference.getNumberOfAlternatives() - 1; ++i) {
|
||
for(var j = i + 1; j < preference.getNumberOfAlternatives(); ++j) {
|
||
bCurrent = preference.getHesitantLinguisticValuation(i | 0, j | 0).getLinguisticIndexes().size();
|
||
if(bCurrent > bMax) {
|
||
bMax = bCurrent;
|
||
}
|
||
}
|
||
}
|
||
|
||
var hflts = consistency.createMatrix(preference.getNumberOfAlternatives());
|
||
var indexes_ij;
|
||
var indexes_ji;
|
||
for(var i = 0; i < preference.getNumberOfAlternatives() - 1; ++i) {
|
||
for(var j = i + 1; j < preference.getNumberOfAlternatives(); ++j) {
|
||
indexes_ij = preference.getHesitantLinguisticValuation(i | 0, j | 0).getLinguisticIndexes();
|
||
indexes_ji = preference.getHesitantLinguisticValuation(j | 0, i | 0).getLinguisticIndexes();
|
||
bCurrent = indexes_ij.size();
|
||
if(bCurrent < bMax) {
|
||
for(var k = 0; k < bMax - bCurrent; ++k) {
|
||
indexes_ij.add(indexes_ij.get(indexes_ij.size() - 1));
|
||
indexes_ji.add(indexes_ji.get(indexes_ji.size() - 1));
|
||
}
|
||
}
|
||
|
||
hflts[i][j] = indexes_ij;
|
||
hflts[j][i] = indexes_ji;
|
||
}
|
||
}
|
||
return hflts;
|
||
}
|
||
|
||
consistency.createMatrix = function(n) {
|
||
var matrix = [];
|
||
for(var i = 0; i < n; i++) {
|
||
matrix[i] = [];
|
||
for(var j = 0; j < n; j++) {
|
||
matrix[i][j] = undefined;
|
||
}
|
||
}
|
||
return matrix;
|
||
}
|
||
|
||
consistency.checkIsNormalized = function(NHFLPR) {
|
||
var nElements = NHFLPR[0][1].size();
|
||
|
||
for(var i = 0; i < NHFLPR.length; ++i) {
|
||
for(var j = 0; j < NHFLPR.length; ++j) {
|
||
if(i != j) {
|
||
if(NHFLPR[i][j].size() !== nElements) {
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
consistency.computeConsistentNHFLPR = function(NHFLPR) {
|
||
var consistentNHFLPR = consistency.createMatrix(NHFLPR.length);
|
||
var indexes1;
|
||
var indexes2;
|
||
var nElements = NHFLPR[0][1].size();
|
||
|
||
/*//Ejemplo paper Bin zhu
|
||
var auxIndexes1 = NHFLPR[2][1];
|
||
auxIndexes1.clear();
|
||
auxIndexes1.add(4);
|
||
auxIndexes1.add(3);
|
||
NHFLPR[2][1] = auxIndexes1;
|
||
|
||
var auxIndexes2 = NHFLPR[3][2];
|
||
auxIndexes2.clear();
|
||
auxIndexes2.add(3);
|
||
auxIndexes2.add(2);
|
||
NHFLPR[3][2] = auxIndexes2;
|
||
|
||
var auxIndexes3 = NHFLPR[2][0];
|
||
auxIndexes3.clear();
|
||
auxIndexes3.add(-2);
|
||
auxIndexes3.add(-3);
|
||
NHFLPR[2][0] = auxIndexes3;*/
|
||
|
||
|
||
for(var i = 0; i < NHFLPR.length ; ++i) {
|
||
for(var j = 0; j < NHFLPR.length; ++j) {
|
||
if(i != j) {
|
||
var sumIndexes = new Array(nElements);
|
||
|
||
for(var s = 0; s < nElements; ++s) {
|
||
sumIndexes[s] = 0;
|
||
}
|
||
|
||
for(var k = 0; k < NHFLPR.length; ++k) {
|
||
if(k != i || k != j) {
|
||
indexes1 = NHFLPR[i][k];
|
||
indexes2 = NHFLPR[k][j];
|
||
|
||
for(var l = 0; l < nElements; ++l) {
|
||
if(indexes1 === undefined) {
|
||
sumIndexes[l] += indexes2.get(l) / NHFLPR.length;
|
||
} else if(indexes2 === undefined) {
|
||
sumIndexes[l] += indexes1.get(l) / NHFLPR.length;
|
||
} else {
|
||
sumIndexes[l] += indexes1.get(l) / NHFLPR.length + indexes2.get(l) / NHFLPR.length;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
consistentNHFLPR[i][j] = sumIndexes;
|
||
}
|
||
}
|
||
}
|
||
return consistentNHFLPR;
|
||
}
|
||
|
||
consistency.computeEpsilon = function(indexesNormalized, indexesConsistent) {
|
||
var S = 0;
|
||
|
||
for(var k = 0; k < indexesNormalized.size(); ++k) {
|
||
S += indexesNormalized.get(k) - indexesConsistent[k];
|
||
}
|
||
return S / indexesNormalized.size();
|
||
}
|
||
|
||
/*
|
||
Generate consistent random HPR
|
||
|
||
*/
|
||
consistency.additiveConsistencyRandomHPR = function(n,number){
|
||
var RandomHPR=new HPR(n);
|
||
var c=new HPR(n);
|
||
var numValues=number;
|
||
var numFPRMax=number;
|
||
|
||
|
||
for(var i=0;i<n-1;i++){
|
||
var hesitantNumericV=new HesitantNumericValuation();
|
||
for(var b=0;b<numValues;b++){
|
||
var vrandom=0;
|
||
do{
|
||
vrandom=Math.random().toFixed(2)/1;
|
||
}while(vrandom<0.26 || vrandom>0.74);
|
||
|
||
var value=new ExpertDegree(-1,vrandom);
|
||
hesitantNumericV.addHesitantValue(value);
|
||
}
|
||
RandomHPR.setValueSymmetrically(i | 0, (i+1) | 0, hesitantNumericV);
|
||
}
|
||
for(var i=0;i<(n-2);i++){
|
||
for(var j=(i+1);j<(n-1);j++){
|
||
var hesitantNumericV=new HesitantNumericValuation();
|
||
for(var b=0;b<numValues;b++){
|
||
var k=j+1;
|
||
var acumulate=RandomHPR.getValue(i | 0, j | 0).getHesitantValue(b).getDegree()+RandomHPR.getValue(j | 0, k | 0).getHesitantValue(b).getDegree()-0.5;
|
||
var value=new ExpertDegree(-1,acumulate);
|
||
hesitantNumericV.addHesitantValue(value);
|
||
}
|
||
RandomHPR.setValueSymmetrically(i | 0, (j+1) | 0, hesitantNumericV);
|
||
}
|
||
}
|
||
|
||
|
||
//Normalizar
|
||
for(var b=0;b<numValues;b++){
|
||
var max=-3;
|
||
var min=3;
|
||
for(var i=0;i<n;i++){
|
||
for(var j=0;j<n;j++){
|
||
if(i!=j){
|
||
if(max<RandomHPR.getValue(i | 0, j | 0).getHesitantValue(b).getDegree()){
|
||
max=RandomHPR.getValue(i | 0, j | 0).getHesitantValue(b).getDegree();
|
||
}
|
||
if(min>RandomHPR.getValue(i | 0, j | 0).getHesitantValue(b).getDegree()){
|
||
min=RandomHPR.getValue(i | 0, j | 0).getHesitantValue(b).getDegree();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if(max>1){
|
||
for(var i=0;i<n;i++){
|
||
for(var j=0;j<n;j++){
|
||
if(i!=j){
|
||
var data=(RandomHPR.getValue(i | 0, j | 0).getHesitantValue(b).getDegree()-min)/(max-min);
|
||
RandomHPR.getValue(i | 0, j | 0).getHesitantValues().set(b,(new ExpertDegree(-1,data) ));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return RandomHPR;
|
||
}
|
||
|
||
/*
|
||
Generate consistent random HPR with umbral
|
||
|
||
*/
|
||
consistency.additiveConsistencyRandomHPRwithUmbral = function(n,number,umbral){
|
||
var RandomHPR=new HPR(n);
|
||
var numFPRMax=number;
|
||
|
||
var arrayFPR=new Array();
|
||
|
||
for(var i=0;i<numFPRMax;i++){
|
||
arrayFPR[i]=consistency.AdditiveConsistencyRandomFPR(n);
|
||
}
|
||
for(var i=0;i<n-1;i++){
|
||
for(var j=i+1;j<n;j++){
|
||
var numValues=99999999;
|
||
numValues=number;
|
||
var hesitantNumericV=new HesitantNumericValuation();
|
||
for(var b=0;b<numValues;b++){
|
||
var value=new ExpertDegree(-1,arrayFPR[b].getValue(i | 0, (i+1) | 0));
|
||
hesitantNumericV.addHesitantValue(value);
|
||
}
|
||
RandomHPR.setValueSymmetrically(i | 0, j | 0, hesitantNumericV);
|
||
}
|
||
}
|
||
|
||
var normalizada=consistency.calculateNHPR(RandomHPR,0.25);
|
||
var c=consistency.calculateCHPR(normalizada);
|
||
var dist=consistency.calculateDistanceBetweenHPRs(normalizada,c);
|
||
|
||
while(dist>umbral){
|
||
normalizada=consistency.calculateModifiedHPR(normalizada,c,0.1);
|
||
c=consistency.calculateCHPR(normalizada);
|
||
dist=consistency.calculateDistanceBetweenHPRs(normalizada,c);
|
||
}
|
||
return normalizada;
|
||
}
|
||
|
||
/*
|
||
Dada una HPR y un valor stigma, devuelve una HPR normalizada
|
||
|
||
*/
|
||
consistency.calculateNHPR = function (preference,stigma,max){
|
||
var n=preference.getNumberOfAlternatives();
|
||
var NHPR=new HPR(n);
|
||
if(max === undefined){
|
||
var max=0;
|
||
for(var i=0;i<(n-1);i++){
|
||
for(var j=i+1;j<n;j++){
|
||
if(max<preference.getValue(i | 0, j | 0).getNumHesitantValues()){
|
||
max=preference.getValue(i | 0, j | 0).getNumHesitantValues();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
for(var i=0;i<n;i++){
|
||
for(var j=i;j<n;j++){
|
||
var hesitantNumericV=new HesitantNumericValuation();
|
||
var minValue=preference.getValue(i | 0, j | 0).getHesitantValue(0).getDegree();
|
||
var maxValue=preference.getValue(i | 0, j | 0).getHesitantValue(preference.getValue(i | 0, j | 0).getNumHesitantValues()-1).getDegree();
|
||
for(var k=0;k<max;k++){
|
||
var value=(stigma*maxValue)+(1-stigma)*minValue;
|
||
if(k<preference.getValue(i | 0, j | 0).getNumHesitantValues()){
|
||
value=preference.getValue(i | 0, j | 0).getHesitantValue(k).getDegree();
|
||
}
|
||
var ex=new ExpertDegree(-1,Math.round(value*10000)/10000);
|
||
hesitantNumericV.addHesitantValue(ex);
|
||
|
||
}
|
||
NHPR.setValueSymmetrically(i | 0, j | 0, hesitantNumericV);
|
||
}
|
||
}
|
||
return NHPR;
|
||
|
||
}
|
||
/*
|
||
Calcula H~(Consitent HPR with c)
|
||
preference debe tener el mismo numero de valores en cada preferencia excepto
|
||
en la diagonal(lo que es lo mismo, debe ser una HPR normalizada)
|
||
|
||
*/
|
||
consistency.calculateCHPR = function (preference){
|
||
|
||
var n=preference.getNumberOfAlternatives();
|
||
var nPreference=preference.getValue(0,1).getNumHesitantValues();
|
||
var NHPR=new HPR(n);
|
||
|
||
for(var i=0;i<n-1;i++){
|
||
for(var j=(i+1);j<n;j++){
|
||
var hesitantNumericV=new HesitantNumericValuation();
|
||
var value=[];
|
||
//Initialize value
|
||
for(var m=0;m<nPreference;m++){
|
||
value[m]=0;
|
||
}
|
||
//Calculate values
|
||
for(var k=0;k<n;k++){
|
||
for(var l=0;l<nPreference;l++){
|
||
var hesitantIK=0.5;
|
||
if(i!=k){
|
||
hesitantIK=preference.getValue(i | 0, k | 0).getHesitantValues().get(l).getDegree();
|
||
}
|
||
var hesitantKJ=0.5;
|
||
if(j!=k){
|
||
hesitantKJ=preference.getValue(k | 0, j | 0).getHesitantValues().get(l).getDegree();
|
||
}
|
||
value[l]=value[l]+hesitantIK+hesitantKJ-0.5;
|
||
}
|
||
}
|
||
//Asign values
|
||
for(var p=0;p<nPreference;p++){
|
||
value[p]=value[p]/n;
|
||
var ex=new ExpertDegree(-1,Math.round(value[p]*10000)/10000);
|
||
hesitantNumericV.addHesitantValueNotOrder(ex);
|
||
}
|
||
NHPR.setValueSymmetrically(i | 0, j | 0, hesitantNumericV);
|
||
}
|
||
}
|
||
return NHPR;
|
||
|
||
}
|
||
|
||
/*
|
||
Distancia entre dos HPR que tengan el mismo numero de elementos en cada preferencia
|
||
|
||
|
||
*/
|
||
|
||
consistency.calculateDistanceBetweenHPRs= function(preference1,preference2){
|
||
var n=preference1.getNumberOfAlternatives();
|
||
var nPreference=preference2.getValue(0,1).getNumHesitantValues();
|
||
var value=0;
|
||
for(var i=0;i<(n-1);i++){
|
||
for(var j=(i+1);j<n;j++){
|
||
for(var k=0;k<nPreference;k++){
|
||
var hesitantp1=preference1.getValue(i | 0, j | 0).getHesitantValues().get(k).getDegree();
|
||
var hesitantp2=preference2.getValue(i | 0, j | 0).getHesitantValues().get(k).getDegree();
|
||
value=value+Math.abs(hesitantp1-hesitantp2);
|
||
}
|
||
}
|
||
}
|
||
var result=value*(2/(n*(n-1)*nPreference));
|
||
return result;
|
||
|
||
}
|
||
|
||
|
||
consistency.calculateModifiedHPR= function(preference1,preference2,delta){
|
||
var n=preference1.getNumberOfAlternatives();
|
||
var nPreference=preference2.getValue(0,1).getNumHesitantValues();
|
||
var resultHPR=new HPR(n);
|
||
var value=0;
|
||
for(var i=0;i<(n-1);i++){
|
||
for(var j=(i+1);j<n;j++){
|
||
var hesitantNumericV=new HesitantNumericValuation();
|
||
//Calcualte value
|
||
for(var k=0;k<nPreference;k++){
|
||
var value=(delta*preference1.getValue(i | 0, j | 0).getHesitantValues().get(k).getDegree())+((1-delta)*preference2.getValue(i | 0, j | 0).getHesitantValues().get(k).getDegree());
|
||
var ex=new ExpertDegree(-1,Math.round(value*10000)/10000);
|
||
hesitantNumericV.addHesitantValueNotOrder(ex);
|
||
}
|
||
resultHPR.setValueSymmetrically(i | 0, j | 0, hesitantNumericV);
|
||
}
|
||
}
|
||
return resultHPR;
|
||
|
||
}
|
||
/*
|
||
Calculate consistency index with 0.5 positive/negative pessimistic/optimistic
|
||
*/
|
||
consistency.calculateConsistencyIndexHPR=function(preference){
|
||
var NHPR=consistency.calculateNHPR(preference,0.5);
|
||
var CHPR=consistency.calculateCHPR(NHPR);
|
||
return consistency.calculateDistanceBetweenHPRs(NHPR,CHPR);
|
||
|
||
}
|
||
|
||
/*
|
||
|
||
|
||
|
||
*/
|
||
consistency.checkConsistencyHPR = function(preference){
|
||
var n=preference.getNumberOfAlternatives();
|
||
for(var i=0;i<(n-1);i++){
|
||
for(var j=(i+1);j<n;j++){
|
||
for(var k=0;k<n;k++){
|
||
if(i!=j && i!=k && j!=k){
|
||
for(var b=0;b<preference.getValue(i | 0, j | 0).getNumHesitantValues();b++){
|
||
var aux1=Math.round(preference.getValue(i | 0, k | 0).getHesitantValue(b).getDegree()*10000)/10000;
|
||
var aux2=Math.round(preference.getValue(j | 0, k | 0).getHesitantValue(b).getDegree()*10000)/10000;
|
||
|
||
var value1=Math.round(preference.getValue(i | 0, j | 0).getHesitantValue(b).getDegree()*10000)/10000;
|
||
var value2=Math.round((aux1-aux2+0.5)*10000)/10000;
|
||
|
||
if(Math.abs(value1-value2)>0.01){
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
/*
|
||
Prueba de HPR aleatorio
|
||
|
||
*/
|
||
consistency.additiveConsistencyRandomHPR2 = function(n){
|
||
var c=new HPR(n);
|
||
var pruebas2=new HPR(n);
|
||
var numValues=0;
|
||
|
||
var RandomHPR=new HPR(n);
|
||
var numFPRMax=10;
|
||
do{
|
||
numFPRMax=Math.round(((Math.random().toFixed(2))*10));
|
||
}while(numFPRMax==0);
|
||
var arrayFPR=new Array();
|
||
|
||
for(var i=0;i<numFPRMax;i++){
|
||
arrayFPR[i]=consistency.AdditiveConsistencyRandomFPR(n);
|
||
}
|
||
for(var i=0;i<n-1;i++){
|
||
for(var j=i+1;j<n;j++){
|
||
numValues=99999999;
|
||
do{
|
||
numValues=Math.round(((Math.random().toFixed(2))*10));
|
||
}while(numValues > numFPRMax || numValues==0);
|
||
var hesitantNumericV=new HesitantNumericValuation();
|
||
for(var b=0;b<numValues;b++){
|
||
var value=new ExpertDegree(-1,Math.round(arrayFPR[b].getValue(i | 0, (i+1) | 0)*10000)/10000);
|
||
hesitantNumericV.addHesitantValue(value);
|
||
}
|
||
RandomHPR.setValueSymmetrically(i | 0, j | 0, hesitantNumericV);
|
||
}
|
||
}
|
||
|
||
var normalizada=consistency.calculateNHPR(RandomHPR,0.5);
|
||
|
||
return RandomHPR;
|
||
}
|
||
|
||
|
||
consistency
|
||
</code>
|
||
</snippet> |