11package org .expr .mcdm
22
3- case class MarcosResult () extends MCDMResult
3+ case class MarcosResult (
4+ normalizedDecmat : Mat ,
5+ S : Vec ,
6+ KPlus : Vec ,
7+ KMinus : Vec ,
8+ fKPlus : Vec ,
9+ fKMinus : Vec ,
10+ scores : Vec ,
11+ orderings : VecInt ,
12+ bestIndex : Int
13+ ) extends MCDMResult
414
515def marcos (
616 decmat : Mat ,
@@ -9,4 +19,48 @@ def marcos(
919 normalization : NormalizationFunction =
1020 Normalization .MarcosNormalization ,
1121 options : Map [String , Any ] = Map .empty
12- ): MarcosResult = ???
22+ ): MarcosResult =
23+
24+ val (row, col) = Matrix .size(decmat)
25+
26+ val normalizedDecmat = normalization(decmat, weights, directions)
27+
28+ val S = normalizedDecmat.map(row => Matrix .sumproduct(weights, row))
29+
30+ // KPlus = S[1:row] ./ S[row+1]
31+ // S.slice(0, 4) takes S(0), S(1), S(2), S(3)
32+ val KPlus = S .slice(0 , row).map(x => x / S (row))
33+
34+ // KMinus = S[1:row] ./ S[row+2]
35+ val KMinus = S .slice(0 , row).map(x => x / S (row + 1 ))
36+
37+ // fKPlus = KPlus ./ (KPlus .+ KMinus)
38+ val fKPlus = KPlus .zip(KMinus ).map((x, y) => x / (x + y))
39+
40+ // fKMinus = KMinus ./ (KPlus .+ KMinus)
41+ val fKMinus = KMinus .zip(KPlus ).map((x, y) => x / (x + y))
42+
43+ var scores = Matrix .zeros(row)
44+ for i <- 0 until row do
45+ scores(i) =
46+ (KPlus (i) + KMinus (i)) /
47+ ((1 + (1 - fKPlus(i)) / fKPlus(i)) + ((1 - fKMinus(i)) / fKMinus(i)))
48+
49+ val orderings = scores.zipWithIndex
50+ .sortBy(- _._1)
51+ .map(_._2)
52+ .toArray
53+
54+ val bestIndex = orderings.last
55+
56+ MarcosResult (
57+ normalizedDecmat,
58+ S ,
59+ KPlus ,
60+ KMinus ,
61+ fKPlus,
62+ fKMinus,
63+ scores,
64+ orderings,
65+ bestIndex
66+ )
0 commit comments