Skip to content

Commit d75c44e

Browse files
committed
implement Mabac
1 parent a15bbc5 commit d75c44e

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

src/main/scala/mabac.scala

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.expr.mcdm
2+
3+
case class MabacResult(
4+
scores: Vec
5+
) extends MCDMResult
6+
7+
def mabac(
8+
decmat: Mat,
9+
weights: Vec,
10+
directions: Array[Direction],
11+
normalization: NormalizationFunction =
12+
Normalization.MaxMinRangeNormalization,
13+
options: Map[String, Any] = Map.empty
14+
): MabacResult =
15+
16+
val (row, col) = Matrix.size(decmat)
17+
18+
val colMax = Matrix.colmaxs(decmat)
19+
20+
val colMin = Matrix.colmins(decmat)
21+
22+
val A = normalization(decmat, weights, directions)
23+
24+
// wA = Utilities.weightise((A .+ one(zerotype)), w)
25+
val wA = Matrix.weightizeColumns(A.map(row => row.map(_ + 1.0)), weights)
26+
27+
// g[i] = geomean(wA[:, i])
28+
val g = Matrix.applyFunctionToColumns(wA, Statistics.geomean)
29+
30+
// Q = wA .- g'
31+
val Q = wA.map(row => row.zip(g).map { case (x, y) => x - y })
32+
33+
34+
// scores[i] = sum(Q[i, :])
35+
val scores = Q.map(row => row.sum)
36+
37+
MabacResult(scores)
38+

src/main/scala/statistics.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.expr.mcdm
22

3+
import scala.math.{log, exp}
4+
35
object Statistics:
46

57
def mean(a: Vec): Double = a.sum / a.length
@@ -48,3 +50,4 @@ object Statistics:
4850
case n if n % 2 == 0 => (sorted(n / 2 - 1) + sorted(n / 2)) / 2.0
4951
case _ => sorted(L / 2)
5052

53+

src/test/scala/testmabac.scala

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import munit.Assertions as A
2+
3+
import org.expr.mcdm.mabac
4+
import org.expr.mcdm.Direction.{Maximize, Minimize}
5+
import org.expr.mcdm.Matrix
6+
7+
class TestMabac extends munit.FunSuite {
8+
test("Mabac Example - 1") {
9+
10+
val decmat = Array(
11+
Array(2.0, 1, 4, 7, 6, 6, 7, 3000),
12+
Array(4.0, 1, 5, 6, 7, 7, 6, 3500),
13+
Array(3.0, 2, 6, 6, 5, 6, 8, 4000),
14+
Array(5.0, 1, 5, 7, 6, 7, 7, 3000),
15+
Array(4.0, 2, 5, 6, 7, 7, 6, 3000),
16+
Array(3.0, 2, 6, 6, 6, 6, 6, 3500))
17+
18+
val weights = Array(0.293, 0.427, 0.067, 0.027, 0.053, 0.027, 0.053, 0.053)
19+
20+
val fns = Array(
21+
Maximize,
22+
Maximize,
23+
Maximize,
24+
Maximize,
25+
Maximize,
26+
Maximize,
27+
Maximize,
28+
Minimize
29+
)
30+
31+
val result = mabac(decmat, weights, fns)
32+
33+
val expected_scores = Array(-0.31132, -0.10898, 0.20035, 0.04218, 0.34452, 0.20035)
34+
35+
A.assert(Matrix.elementwise_equal(result.scores, expected_scores, 0.0001))
36+
}
37+
38+
}

0 commit comments

Comments
 (0)