Skip to content

Instantly share code, notes, and snippets.

@monsieurDuke
Last active July 16, 2022 03:23
Show Gist options
  • Save monsieurDuke/23788cab4719675c41d8ccbe34ef4247 to your computer and use it in GitHub Desktop.
Save monsieurDuke/23788cab4719675c41d8ccbe34ef4247 to your computer and use it in GitHub Desktop.
Muhammad Nur Ikshan Zahardjil - 18108042 | UAS SISTEM INFORMASI TRILOGI
import java.lang.Math.*;
import java.math.RoundingMode;
import java.text.DecimalFormat;
public class Topsis {
public static void main(String[] args) {
/*
K1 BENEFIT : SUDAH (2) // BELUM (1)
K2 BENEFIT : CLUSTER 1 (3) // CLUSTER 2 (2) // CLUSTER 3 (1)
K3 COST : >30 (4) // 21-30 (3) // 11-20 (2) // <11 (1)
K4 COST : SUDAH (2) // BELUM (1)
----
0[ 2 3 2 2 ]
1[ 1 2 2 2 ]
2[ 1 3 1 1 ]
3[ 2 3 1 1 ]
4[ 2 2 1 1 ]
5[ 1 2 1 2 ]
6[ 1 1 1 1 ]
7[ 2 1 1 1 ]
8[ 2 1 1 1 ]
9[ 1 1 1 1 ]
----
BOBOT : 0.4 // 0.3 // 0.1 // 0.1
COST BENEFIT : 1 // 1 // -1 // -1
*/
// deklarasi variabel
DecimalFormat df = new DecimalFormat("0.000");
df.setRoundingMode(RoundingMode.UP);
int[][] mtx = new int[10][4];
double[][] mtx_keputusan = new double[10][4];
double[][] mtx_normalisasi = new double[10][4];
double[] rij = new double[4];
double[] bobot = new double[]{0.4, 0.3, 0.2, 0.1};
int[] costben = {1, 1, -1, -1};
double[] max_ben = new double[4];
double[] max_cost = new double[4];
int tmp = 0;
// inisialisasi matrix keputusan
mtx[0][0] = 2; mtx[0][1] = 3; mtx[0][2] = 2; mtx[0][3] = 2;
mtx[1][0] = 1; mtx[1][1] = 2; mtx[1][2] = 2; mtx[1][3] = 2;
mtx[2][0] = 1; mtx[2][1] = 3; mtx[2][2] = 1; mtx[2][3] = 1;
mtx[3][0] = 2; mtx[3][1] = 3; mtx[3][2] = 1; mtx[3][3] = 1;
mtx[4][0] = 2; mtx[4][1] = 2; mtx[4][2] = 1; mtx[4][3] = 1;
mtx[5][0] = 1; mtx[5][1] = 2; mtx[5][2] = 1; mtx[5][3] = 2;
mtx[6][0] = 1; mtx[6][1] = 1; mtx[6][2] = 1; mtx[6][3] = 1;
mtx[7][0] = 2; mtx[7][1] = 1; mtx[7][2] = 1; mtx[7][3] = 1;
mtx[8][0] = 2; mtx[8][1] = 1; mtx[8][2] = 1; mtx[8][3] = 1;
mtx[9][0] = 1; mtx[9][1] = 1; mtx[9][2] = 1; mtx[9][3] = 1;
// membuat nilai rij
for (int y = 0; y < mtx[0].length; y++) {
for (int x = 0; x < mtx.length; x++) {
tmp += Math.pow(mtx[x][y],2);
}; rij[y] = Math.sqrt(tmp); tmp = 0;
}
// membuat matrix normalisasi terbobot & mencari ideal benefit cost
for (int x = 0; x < mtx.length; x++) {
for (int y = 0; y < mtx[0].length; y++) {
mtx_keputusan[x][y] = mtx[x][y] / rij[y];
mtx_normalisasi[x][y] = (mtx_keputusan[x][y] * bobot[y] * costben[y]);
};
}
// display matrix final
System.out.println("matrix normalisasi terbobot\n--");
for (int x = 0; x < mtx.length; x++) {
System.out.print("[ ");
for (int y = 0; y < mtx[0].length; y++) {
System.out.print(df.format(mtx_normalisasi[x][y])+" ");
}; System.out.println("]");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment