Advertisement
Guest User

Untitled

a guest
Sep 10th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.46 KB | None | 0 0
  1. <?php
  2. /*
  3. -- ----------------------------
  4. -- DSS TOPSIS METHOD
  5. -- CREATED BY : CAHYA DSN
  6. -- CREATED ON : 2014-12-03
  7. -- UPDATED ON : 2015-01-27
  8. -- ----------------------------
  9.  
  10. Metode Technique for Order of Preference by Similarity to Ideal Solution (TOPSIS)
  11.  
  12. TOPSIS adalah metode pengambilan keputusan multikriteria yang pertama kali diper
  13. kenalkan oleh Yoon dan Hwang tahun 1981. Menurut Hwang dan Zeleny (Kusumadewi,dkk.
  14. , 2006), TOPSIS didasarkan pada konsep dimana alternatif terpilih yang terbaik ti
  15. dak hanya memiliki jarak terpendek dari solusi ideal positif, namun juga memiliki
  16. jarak terpanjang dari solusi ideal negatif.
  17.  
  18. Solusi ideal positif didefinisikan sebagai jumlah dari seluruh nilai terbaik yang
  19. dapat dicapai untuk setiap atribut, sedangkan solusi ideal negatif terdiri dari
  20. seluruh nilai terburuk yang dicapai untuk setiap atribut (Meliana, 2011).
  21.  
  22. Konsep ini banyak digunakan pada beberapa model MADM untuk menyelesaikan masalah
  23. keputusan secara praktis (Hwang, 1993; Liang,1999; Yeh, 2000). Hal ini disebabkan
  24. konsepnya sederhana dan, mudah dipahami, komputasinya efisien, dan memiliki kemam
  25. puan untuk mengukur kinerja relatif dari alternatif-alternatif keputusan dalam
  26. bentuk matematis yang sederhana (Kusumadewi, dkk., 2006: 88).
  27.  
  28. 3.2.1 Prosedur TOPSIS
  29. Secara umum, prosedur TOPSIS mengikuti langkah-langkah sebagai berikut:
  30. 1. Membuat matriks keputusan yang ternormalisasi
  31. TOPSIS membutuhkan rating kinerja setiap alternatif Ai pada setiap kriteria Cj yang
  32. ternormalisasi, yaitu:
  33.  
  34. 2 0.5
  35. r = x /( sigma x )
  36. ij ij i=1 m ij
  37.  
  38. dengan
  39. i = 1, 2, ... , m;
  40. dan
  41. j = 1, 2, 3, ... , n;
  42.  
  43. 2. Membuat matriks keputusan yang ternormalisasi terbobot
  44. Solusi ideal positif A+ dan solusi ideal negatif A-
  45. dapat ditentukan berdasarkan rating bobot ternormalisasi (y ) sebagai:
  46. ij
  47. y = w r
  48. ij i ij
  49.  
  50. dengan
  51. i = 1, 2, ... , m;
  52. dan
  53. j = 1, 2, 3, ... , n;
  54.  
  55. dimana:
  56.  
  57. r = matriks ternormalisasi terbobot
  58. ij
  59. w = vektor bobot ke-i
  60. i
  61.  
  62. 3. Menentukan matriks solusi ideal positif dan matriks solusi ideal negatif
  63. Solusi ideal positif dihitung berdasarkan:
  64.  
  65. + + + +
  66. A = (y , y , ... y )
  67. 1 2 n
  68. Solusi ideal negatif dihitung berdasarkan:
  69.  
  70. - - - -
  71. A = (y , y , ... y )
  72. 1 2 n
  73.  
  74. dengan
  75.  
  76. max y ; jika j adalah atribut keuntungan
  77. + i ij
  78. y = {
  79. j min y ; jika j adalah atribut biaya
  80. i ij
  81.  
  82.  
  83. min y ; jika j adalah atribut keuntungan
  84. - i ij
  85. y = {
  86. j max y ; jika j adalah atribut biaya
  87. i ij
  88.  
  89. dengan
  90. j=1,2,...,n
  91.  
  92. 4. Menentukan jarak antara nilai setiap alternatif dengan matriks solusi
  93. positif dan matriks solusi ideal negatif
  94.  
  95. Jarak antara alternatif Ai dengan solusi ideal positif dirumuskan sebagai:
  96.  
  97. + + 2 0.5
  98. D =( sigma (y - y ) ) ; i= 1,2,...,m
  99. i j=1 n i ij
  100.  
  101. Jarak antara alternatif Ai dengan solusi ideal negatif dirumuskan sebagai
  102.  
  103. - - 2 0.5
  104. D =( sigma (y - y ) ) ; i= 1,2,...,m
  105. i j=1 n ij i
  106.  
  107.  
  108. 5.Menentukan nilai preferensi untuk setiap alternatif
  109. Nilai preferensi untuk setiap alternatif (Vi) diberikan sebagai:
  110. - - +
  111. V = D /(D + D ) ; i=1,2,...,m
  112. i i i i
  113.  
  114. Nilai yang lebih besar menunjukkan bahwa alternatif Ai lebih dipilih.
  115. //----------------
  116.  
  117. CREATE DATABASE IF NOT EXISTS db_dss;
  118. USE db_dss;
  119.  
  120. DROP TABLE IF EXISTS topsis_criterias;
  121. CREATE TABLE IF NOT EXISTS topsis_criterias(
  122. id_criteria TINYINT(3) UNSIGNED NOT NULL,
  123. criteria VARCHAR(100) NOT NULL,
  124. weight FLOAT NOT NULL,
  125. attribute SET('benefit','cost'),
  126. PRIMARY KEY(id_criteria)
  127. )ENGINE=MyISAM;
  128.  
  129. INSERT INTO topsis_criterias(id_criteria,criteria,weight,attribute)
  130. VALUES
  131. (1,'Pengalaman Kerja',0.3,'benefit'),
  132. (2,'Pendidikan',0.2,'benefit'),
  133. (3,'Usia',0.2,'benefit'),
  134. (4,'Status Perkawinan',0.15,'cost'),
  135. (5,'Alamat',0.15,'cost');
  136.  
  137. SELECT * FROM topsis_criterias;
  138. +-------------+-------------------+--------+-----------+
  139. | id_criteria | criteria | weight | attribute |
  140. +-------------+-------------------+--------+-----------+
  141. | 1 | Pengalaman Kerja | 0.3 | benefit |
  142. | 2 | Pendidikan | 0.2 | benefit |
  143. | 3 | Usia | 0.2 | benefit |
  144. | 4 | Status Perkawinan | 0.15 | cost |
  145. | 5 | Alamat | 0.15 | cost |
  146. +-------------+-------------------+--------+-----------+
  147. 5 rows in set (0.01 sec)
  148.  
  149. DROP TABLE IF EXISTS topsis_alternatives;
  150. CREATE TABLE IF NOT EXISTS topsis_alternatives(
  151. id_alternative SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
  152. name VARCHAR(30) NOT NULL,
  153. PRIMARY KEY(id_alternative)
  154. ) ENGINE=MyISAM;
  155.  
  156. INSERT INTO topsis_alternatives(name)
  157. VALUES
  158. ('Alfian'),
  159. ('Bella'),
  160. ('Carlie'),
  161. ('Dewi'),
  162. ('Enrico');
  163.  
  164. SELECT * FROM topsis_alternatives;
  165. +----------------+--------+
  166. | id_alternative | name |
  167. +----------------+--------+
  168. | 1 | Alfian |
  169. | 2 | Bella |
  170. | 3 | Carlie |
  171. | 4 | Dewi |
  172. | 5 | Enrico |
  173. +----------------+--------+
  174. 5 rows in set (0.00 sec)
  175.  
  176. DROP TABLE IF EXISTS topsis_evaluations;
  177. CREATE TABLE IF NOT EXISTS topsis_evaluations(
  178. id_alternative SMALLINT(5) UNSIGNED NOT NULL,
  179. id_criteria TINYINT(3) UNSIGNED NOT NULL,
  180. value FLOAT NOT NULL,
  181. PRIMARY KEY (id_alternative,id_criteria)
  182. )ENGINE=MyISAM;
  183.  
  184. INSERT INTO topsis_evaluations(id_alternative,id_criteria,value)
  185. VALUES
  186. (1,1,0.5),
  187. (1,2,1),
  188. (1,3,0.7),
  189. (1,4,0.7),
  190. (1,5,0.8),
  191. (2,1,0.8),
  192. (2,2,0.7),
  193. (2,3,1),
  194. (2,4,0.5),
  195. (2,5,1),
  196. (3,1,1),
  197. (3,2,0.3),
  198. (3,3,0.4),
  199. (3,4,0.7),
  200. (3,5,1),
  201. (4,1,0.2),
  202. (4,2,1),
  203. (4,3,0.5),
  204. (4,4,0.9),
  205. (4,5,0.7),
  206. (5,1,1),
  207. (5,2,0.7),
  208. (5,3,0.4),
  209. (5,4,0.7),
  210. (5,5,1);
  211.  
  212. */
  213. $dbhost='localhost';
  214. $dbuser='root';
  215. $dbpass='';
  216. $dbname='db_dss';
  217. $db=new mysqli($dbhost,$dbuser,$dbpass,$dbname);
  218. $sql="
  219. SELECT
  220. b.name,c.criteria,a.value,c.weight,c.attribute
  221. FROM
  222. topsis_evaluations a
  223. JOIN
  224. topsis_alternatives b USING(id_alternative)
  225. JOIN
  226. topsis_criterias c USING(id_criteria)
  227. ";
  228. $result=$db->query($sql);
  229. $data=array();
  230. $kriterias=array();
  231. $bobot=array();
  232. $atribut=array();
  233. $nilai_kuadrat=array();
  234. while($row=$result->fetch_object()){
  235. if(!isset($data[$row->name])){
  236. $data[$row->name]=array();
  237. }
  238. if(!isset($data[$row->name][$row->criteria])){
  239. $data[$row->name][$row->criteria]=array();
  240. }
  241. if(!isset($nilai_kuadrat[$row->criteria])){
  242. $nilai_kuadrat[$row->criteria]=0;
  243. }
  244. $bobot[$row->criteria]=$row->weight;
  245. $atribut[$row->criteria]=$row->attribute;
  246. $data[$row->name][$row->criteria]=$row->value;
  247. $nilai_kuadrat[$row->criteria]+=pow($row->value,2);
  248. $kriterias[]=$row->criteria;
  249. }
  250. $kriteria=array_unique($kriterias);
  251. $jml_kriteria=count($kriteria);
  252. ?>
  253. <!doctype html>
  254. <html>
  255. <head>
  256. <title>TOPSIS</title>
  257. </head>
  258. <body>
  259. <table border='1'>
  260. <caption>Evaluation Matrix (x<sub>ij</sub>)</caption>
  261. <thead>
  262. <tr>
  263. <th rowspan='3'>No</th>
  264. <th rowspan='3'>Alternatif</th>
  265. <th rowspan='3'>Nama</th>
  266. <th colspan='<?php echo $jml_kriteria;?>'>Kriteria</th>
  267. </tr>
  268. <tr>
  269. <?php
  270. foreach($kriteria as $k)
  271. echo "<th>{$k}</th>\n";
  272. ?>
  273. </tr>
  274. <tr>
  275. <?php
  276. for($n=1;$n<=$jml_kriteria;$n++)
  277. echo "<th>C{$n}</th>";
  278. ?>
  279. </tr>
  280. </thead>
  281. <tbody>
  282. <?php
  283. $i=0;
  284. foreach($data as $nama=>$krit){
  285. echo "<tr>
  286. <td>".(++$i)."</td>
  287. <th>A{$i}</th>
  288. <td>{$nama}</td>";
  289. foreach($kriteria as $k){
  290. echo "<td align='center'>{$krit[$k]}</td>";
  291. }
  292. echo
  293. "</tr>\n";
  294. }
  295. ?>
  296. </tbody>
  297. </table>
  298. <table border='1'>
  299. <caption>Rating Kinerja Ternormalisasi (r<sub>ij</sub>)</caption>
  300. <thead>
  301. <tr>
  302. <th rowspan='3'>No</th>
  303. <th rowspan='3'>Alternatif</th>
  304. <th rowspan='3'>Nama</th>
  305. <th colspan='<?php echo $jml_kriteria;?>'>Kriteria</th>
  306. </tr>
  307. <tr>
  308. <?php
  309. foreach($kriteria as $k)
  310. echo "<th>{$k}</th>\n";
  311. ?>
  312. </tr>
  313. <tr>
  314. <?php
  315. for($n=1;$n<=$jml_kriteria;$n++)
  316. echo "<th>C{$n}</th>";
  317. ?>
  318. </tr>
  319. </thead>
  320. <tbody>
  321. <?php
  322. $i=0;
  323. foreach($data as $nama=>$krit){
  324. echo "<tr>
  325. <td>".(++$i)."</td>
  326. <th>A{$i}</th>
  327. <td>{$nama}</td>";
  328. foreach($kriteria as $k){
  329. echo "<td align='center'>".round(($krit[$k]/sqrt($nilai_kuadrat[$k])),4)."</td>";
  330. }
  331. echo
  332. "</tr>\n";
  333. }
  334. ?>
  335. </tbody>
  336. </table>
  337. <table border='1'>
  338. <caption>Rating Bobot Ternormalisasi(y<sub>ij</sub>)</caption>
  339. <thead>
  340. <tr>
  341. <th rowspan='3'>No</th>
  342. <th rowspan='3'>Alternatif</th>
  343. <th rowspan='3'>Nama</th>
  344. <th colspan='<?php echo $jml_kriteria;?>'>Kriteria</th>
  345. </tr>
  346. <tr>
  347. <?php
  348. foreach($kriteria as $k)
  349. echo "<th>{$k}</th>\n";
  350. ?>
  351. </tr>
  352. <tr>
  353. <?php
  354. for($n=1;$n<=$jml_kriteria;$n++)
  355. echo "<th>C{$n}</th>";
  356. ?>
  357. </tr>
  358. </thead>
  359. <tbody>
  360. <?php
  361. $i=0;
  362. $y=array();
  363. foreach($data as $nama=>$krit){
  364. echo "<tr>
  365. <td>".(++$i)."</td>
  366. <th>A{$i}</th>
  367. <td>{$nama}</td>";
  368. foreach($kriteria as $k){
  369. $y[$k][$i-1]=round(($krit[$k]/sqrt($nilai_kuadrat[$k])),4)*$bobot[$k];
  370. echo "<td align='center'>".$y[$k][$i-1]."</td>";
  371. }
  372. echo
  373. "</tr>\n";
  374. }
  375. ?>
  376. </tbody>
  377. </table>
  378. <table border='1'>
  379. <caption>Solusi Ideal positif (A<sup>+</sup>)</caption>
  380. <thead>
  381. <tr>
  382. <th colspan='<?php echo $jml_kriteria;?>'>Kriteria</th>
  383. </tr>
  384. <tr>
  385. <?php
  386. foreach($kriteria as $k)
  387. echo "<th>{$k}</th>\n";
  388. ?>
  389. </tr>
  390. <tr>
  391. <?php
  392. for($n=1;$n<=$jml_kriteria;$n++)
  393. echo "<th>y<sub>{$n}</sub><sup>+</sup></th>";
  394. ?>
  395. </tr>
  396. </thead>
  397. <tbody>
  398. <tr>
  399. <?php
  400. $yplus=array();
  401. foreach($kriteria as $k){
  402. $yplus[$k]=($atribut[$k]=='benefit'?max($y[$k]):min($y[$k]));
  403. echo "<th>{$yplus[$k]}</th>";
  404. }
  405. ?>
  406. </tr>
  407. </tbody>
  408. </table>
  409. <table border='1'>
  410. <caption>Solusi Ideal negatif (A<sup>-</sup>)</caption>
  411. <thead>
  412. <tr>
  413. <th colspan='<?php echo $jml_kriteria;?>'>Kriteria</th>
  414. </tr>
  415. <tr>
  416. <?php
  417. foreach($kriteria as $k)
  418. echo "<th>{$k}</th>\n";
  419. ?>
  420. </tr>
  421. <tr>
  422. <?php
  423. for($n=1;$n<=$jml_kriteria;$n++)
  424. echo "<th>y<sub>{$n}</sub><sup>-</sup></th>";
  425. ?>
  426. </tr>
  427. </thead>
  428. <tbody>
  429. <tr>
  430. <?php
  431. $ymin=array();
  432. foreach($kriteria as $k){
  433. $ymin[$k]=$atribut[$k]=='cost'?max($y[$k]):min($y[$k]);
  434. echo "<th>{$ymin[$k]}</th>";
  435. }
  436. ?>
  437. </tr>
  438. </tbody>
  439. </table>
  440. <table border='1'>
  441. <caption>Jarak positif (D<sub>i</sub><sup>+</sup>)</caption>
  442. <thead>
  443. <tr>
  444. <th>No</th>
  445. <th>Alternatif</th>
  446. <th>Nama</th>
  447. <th>D<suo>+</sup></th>
  448. </tr>
  449. </thead>
  450. <tbody>
  451. <?php
  452. $i=0;
  453. $dplus=array();
  454. foreach($data as $nama=>$krit){
  455. echo "<tr>
  456. <td>".(++$i)."</td>
  457. <th>A{$i}</th>
  458. <td>{$nama}</td>";
  459. foreach($kriteria as $k){
  460. if(!isset($dplus[$i-1])) $dplus[$i-1]=0;
  461. $dplus[$i-1]+=pow($yplus[$k]-$y[$k][$i-1],2);
  462. }
  463. echo "<td>".round(sqrt($dplus[$i-1]),6)."</td>
  464. </tr>\n";
  465. }
  466. ?>
  467. </tbody>
  468. </table>
  469. <table border='1'>
  470. <caption>Jarak negatif (D<sub>i</sub><sup>-</sup>)</caption>
  471. <thead>
  472. <tr>
  473. <th>No</th>
  474. <th>Alternatif</th>
  475. <th>Nama</th>
  476. <th>D<suo>+</sup></th>
  477. </tr>
  478. </thead>
  479. <tbody>
  480. <?php
  481. $i=0;
  482. $dmin=array();
  483. foreach($data as $nama=>$krit){
  484. echo "<tr>
  485. <td>".(++$i)."</td>
  486. <th>A{$i}</th>
  487. <td>{$nama}</td>";
  488. foreach($kriteria as $k){
  489. if(!isset($dmin[$i-1]))$dmin[$i-1]=0;
  490. $dmin[$i-1]+=pow($ymin[$k]-$y[$k][$i-1],2);
  491. }
  492. echo "<td>".round(sqrt($dmin[$i-1]),6)."</td>
  493. </tr>\n";
  494. }
  495. ?>
  496. </tbody>
  497. </table>
  498. <table border='1'>
  499. <caption>Nilai Preferensi(V<sub>i</sub>)</caption>
  500. <thead>
  501. <tr>
  502. <th>No</th>
  503. <th>Alternatif</th>
  504. <th>Nama</th>
  505. <th>V<sub>i</sub></th>
  506. </tr>
  507. </thead>
  508. <tbody>
  509. <?php
  510. $i=0;
  511. $V=array();
  512. foreach($data as $nama=>$krit){
  513. echo "<tr>
  514. <td>".(++$i)."</td>
  515. <th>A{$i}</th>
  516. <td>{$nama}</td>";
  517. foreach($kriteria as $k){
  518. $V[$i-1]=$dmin[$i-1]/($dmin[$i-1]+$dplus[$i-1]);
  519. }
  520. echo "<td>{$V[$i-1]}</td></tr>\n";
  521. }
  522. ?>
  523. </tbody>
  524. </table>
  525. </body>
  526. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement