Skip to content

Commit 4b03f38

Browse files
committed
implement gui for copeland
1 parent 22cb05e commit 4b03f38

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ <h3>Enter your data and go on!</h3>
211211
<input type="checkbox" id="check_nds"></input>
212212
</td>
213213
</tr>
214+
<tr>
215+
<td>
216+
<label for="check_copeland">Copeland</label>
217+
<input type="checkbox" id="check_copeland"></input>
218+
</td>
214219
</table>
215220

216221

src/main/scala/Main.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,14 @@ def evaluate(problem: MCDMProblem): Unit =
359359
methodsnames = methodsnames.appended("Nds")
360360
scores = Matrix.appendcol(scores, ndsresult.scores)
361361
ranks = Matrix.appendcol(ranks, ndsresult.scores.reverse.map(_ + 1))
362+
if check_copeland.checked then
363+
if scores.length == 0 then
364+
HtmlUtils.msgbox("At least one method should be selected for perform Copeland.")
365+
else
366+
val copelandresult = copeland(ranks)
367+
methodsnames = methodsnames.appended("Copeland")
368+
scores = Matrix.appendcol(scores, copelandresult.scores)
369+
ranks = Matrix.appendcol(ranks, copelandresult.ranks)
362370

363371
val resultstr = HtmlUtils.scorematrixtohtml(problem, methodsnames, scores)
364372
div_output_scores.innerHTML = resultstr

src/main/scala/copeland.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ case class CopelandResult(
77
ranks: Vec
88
)
99

10-
def level_of_dominance(v1: Array[Int], v2: Array[Int]): Int =
10+
def level_of_dominance(v1: Vec, v2: Vec): Int =
1111
var lod = 0
1212
val n = v1.length
1313
for (i <- 0 until n)
@@ -16,20 +16,21 @@ def level_of_dominance(v1: Array[Int], v2: Array[Int]): Int =
1616

1717
lod
1818

19-
def dominance_scores(ordering_mat: Array[Array[Int]]): Array[Array[Int]] =
19+
def dominance_scores(ordering_mat: Mat): Mat =
2020
val n = ordering_mat.length
2121
Array.tabulate(n, n)((i, j) =>
2222
level_of_dominance(ordering_mat(i), ordering_mat(j))
2323
)
2424

25-
def winloss_scores(dommat: Array[Array[Int]]): Array[Array[Int]] =
25+
def winloss_scores(dommat: Mat): Mat =
2626
val n = dommat.length
27-
Array.tabulate(n, n)((i, j) => (dommat(i)(j) - dommat(j)(i)).sign.toInt)
27+
Array.tabulate(n, n)((i, j) => (dommat(i)(j) - dommat(j)(i)).sign)
2828

29-
def copeland(rankmatrix: Array[Array[Int]]): CopelandResult =
29+
30+
def copeland(rankmatrix: Mat): CopelandResult =
3031

3132
val winloses = winloss_scores(dominance_scores(rankmatrix))
32-
val scores = Array.tabulate(winloses.length)(i => winloses(i).sum.toDouble)
33+
val scores = Array.tabulate(winloses.length)(i => winloses(i).sum)
3334
val ranks = ranksfromscores(scores)
3435

3536
CopelandResult(

src/main/scala/gui/domobjects.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,6 @@ object DomObjects:
131131
val check_nds = document
132132
.getElementById("check_nds")
133133
.asInstanceOf[HTMLInputElement]
134+
val check_copeland = document
135+
.getElementById("check_copeland")
136+
.asInstanceOf[HTMLInputElement]

src/test/scala/testcopeland.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import org.expr.mcdm.rov
88
class TestCopeland extends munit.FunSuite {
99
test("Copeland Example - 1") {
1010

11-
val mopa_rank = Array(1, 4, 2, 3).reverse
12-
val moosra_rank = Array(1, 2, 3, 4).reverse
13-
val copras_rank = Array(1, 3, 2, 4).reverse
14-
val saw_rank = Array(1, 3, 2, 4).reverse
15-
val wpm_rank = Array(1, 3, 2, 4).reverse
16-
val rov_rank = Array(4, 1, 2, 3).reverse
11+
val mopa_rank = Array(1.0, 4, 2, 3).reverse
12+
val moosra_rank = Array(1.0, 2, 3, 4).reverse
13+
val copras_rank = Array(1.0, 3, 2, 4).reverse
14+
val saw_rank = Array(1.0, 3, 2, 4).reverse
15+
val wpm_rank = Array(1.0, 3, 2, 4).reverse
16+
val rov_rank = Array(4.0, 1, 2, 3).reverse
1717

1818
val mat = Array(
1919
mopa_rank,

0 commit comments

Comments
 (0)