const price = {
big: 1,
small:2
};
const size = {
small: 1,
medium: 2,
big: 3
};
const state = {
bad: 1,
medium: 2,
good: 3
}
const distance = {
outside: 1,
big: 2,
small: 3,
center: 4
};
const A1 = [price.small, size.big, state.bad, distance.small],
A2 = [price.big, size.medium, state.good, distance.big],
A3 = [price.small, size.small, state.medium, distance.big],
A4 = [price.small, size.big, state.medium, distance.outside],
A5 = [price.small, size.medium, state.good, distance.outside],
A6 = [price.big, size.big, state.good, distance.big],
A7 = [price.small, size.medium, state.medium, distance.big],
A8 = [price.big, size.small, state.good, distance.outside],
A9 = [price.small, size.small, state.medium, distance.small],
A10 = [price.big, size.big, state.bad, distance.center];
const Alternatives = [A1,A2,A3,A4,A5,A6,A7,A8,A9,A10];
const ArrRes = Alternatives.map(function (item) {
return [...item]
});
function diff (arr, arrRes, firstArrIndex){
let k = 0;
while (k < arr[firstArrIndex].length) {
if (arr[firstArrIndex][k] >= arr[0][k] && arr[firstArrIndex][k] >= arr[1][k] && arr[firstArrIndex][k] >= arr[2][k] &&
arr[firstArrIndex][k] >= arr[3][k] && arr[firstArrIndex][k] >= arr[4][k] && arr[firstArrIndex][k] >= arr[5][k] &&
arr[firstArrIndex][k] >= arr[6][k] && arr[firstArrIndex][k] >= arr[7][k] && arr[firstArrIndex][k] >= arr[8][k] &&
arr[firstArrIndex][k] >= arr[9][k]) {
arrRes[firstArrIndex][k] = 1;
} else {
arrRes[firstArrIndex][k] = 0;
}
k++
}
}
for (let A = 0; A < Alternatives.length; A++) {
if(A < Alternatives.length - 1) {
diff(Alternatives, ArrRes, A);
} else {
diff(Alternatives, ArrRes, A);
}
}
function getMaxOfArray(numArray) {
return Math.max.apply(null, numArray);
}
function alter(arr) {
arr.forEach((alternative, index) => {
ArrRes[index] = alternative.reduce((accum, item) => {
accum = accum + item
return accum
})
});
arr.forEach((el, i) => {
if (el == getMaxOfArray(arr)) {
console.log(`${i+1} альтернатива входит в множество Эджворта-Парето`);
}
});
}
alter(ArrRes);
// const list = [];
// function allAlt (arr) {
// let arrI = 0;
// let numI = 0;
// for (arrI; arrI < arr.length; arrI++) {
// list.push(arr[arrI][numI])
// }
// }
// if (arr[firstArrIndex][k] >= getMaxOfArray(list)) {
// arrRes[firstArrIndex][k] = 1;
// list.length = 0
// } else {
// arrRes[firstArrIndex][k] = 0;
// list.length = 0
// }