Read 334 times | Created 2015-01-29 17:05:29 | Updated 2015-01-29 17:06:07 | | |

 

<?php
/*
-- ----------------------------
-- DSS WP METHOD
-- CREATED BY : CAHYA DSN
-- CREATED ON : 2015-01-28
-- UPDATED ON : 2015-01-29
-- ----------------------------
/*
Metode Weighted Product(WP)

Metode WP menggunakan perkalian untuk menghubungkan rating atribut,dimana rating 
setiap atribut harus dipangkatkan dulu dengan bobot atribut yang bersangkutan
(Yoon,1989). Proses ini sama halnya dengan proses normalisasi(kusumadewi, dkk.,
2006:79) Preferensi untuk alternatif Ai diberikan sebagai berikut:

              wj
S  =    phi x     ;dengan i=1,2,...,m
 i   j=1  n  ij
 
 dimana sigma wj=1. wj adalah pangkat bernilai positif untuk atribut keuntungan,
 dan bernilai negatif untuk atribut biaya.
 
 Preferensi relatif dari setiap alternatif, diberikan sebagai:
 
              wi              wj
V  =    phi x    /    phi (x*)   ;dengan i=1,2,...,m 
 i   j=1  n  ij    j=1  n   j 
================================================================================
CREATE DATABASE IF NOT EXISTS db_saw;
USE db_saw;

DROP TABLE IF EXISTS wp_criterias;
CREATE TABLE IF NOT EXISTS wp_criterias(
  id_criteria TINYINT(3) UNSIGNED NOT NULL,
  criteria VARCHAR(100) NOT NULL,
  weight FLOAT NOT NULL,
  attribute SET('benefit','cost'),
  PRIMARY KEY(id_criteria)
)ENGINE=MyISAM;

INSERT INTO wp_criterias(id_criteria,criteria,weight,attribute)
VALUES
(1,'Pengalaman Kerja',3,'benefit'),
(2,'Pendidikan',2,'benefit'),
(3,'Usia',2,'benefit'),
(4,'Status Perkawinan',1.5,'cost'),
(5,'Alamat',1.5,'cost');

SELECT * FROM wp_criterias;
+-------------+-------------------+--------+-----------+
| id_criteria | criteria          | weight | attribute |
+-------------+-------------------+--------+-----------+
|           1 | Pengalaman Kerja  |      3 | benefit   |
|           2 | Pendidikan        |      2 | benefit   |
|           3 | Usia              |      2 | benefit   |
|           4 | Status Perkawinan |    1.5 | cost      |
|           5 | Alamat            |    1.5 | cost      |
+-------------+-------------------+--------+-----------+
5 rows in set (0.01 sec)

DROP TABLE IF EXISTS wp_alternatives;
CREATE TABLE IF NOT EXISTS wp_alternatives(
  id_alternative SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
  name VARCHAR(30) NOT NULL,
  PRIMARY KEY(id_alternative)
) ENGINE=MyISAM;

INSERT INTO wp_alternatives(name)
VALUES
('Alfian'),
('Bella'),
('Carlie'),
('Dewi'),
('Enrico');

SELECT * FROM wp_alternatives;
+----------------+--------+
| id_alternative | name   |
+----------------+--------+
|              1 | Alfian |
|              2 | Bella  |
|              3 | Carlie |
|              4 | Dewi   |
|              5 | Enrico |
+----------------+--------+
5 rows in set (0.00 sec)

DROP TABLE IF EXISTS wp_evaluations;
CREATE TABLE IF NOT EXISTS wp_evaluations(
  id_alternative SMALLINT(5) UNSIGNED NOT NULL,
  id_criteria TINYINT(3) UNSIGNED NOT NULL,
  value FLOAT NOT NULL,
  PRIMARY KEY (id_alternative,id_criteria)
)ENGINE=MyISAM;

INSERT INTO wp_evaluations(id_alternative,id_criteria,value)
VALUES
(1,1,0.5),
(1,2,1),
(1,3,0.7),
(1,4,0.7),
(1,5,0.8),
(2,1,0.8),
(2,2,0.7),
(2,3,1),
(2,4,0.5),
(2,5,1),
(3,1,1),
(3,2,0.3),
(3,3,0.4),
(3,4,0.7),
(3,5,1),
(4,1,0.2),
(4,2,1),
(4,3,0.5),
(4,4,0.9),
(4,5,0.7),
(5,1,1),
(5,2,0.7),
(5,3,0.4),
(5,4,0.7),
(5,5,1);


*/
//-- database configuration
$dbhost='localhost';
$dbuser='root';
$dbpass='';
$dbname='db_dss';
//-- database connection
$db=new mysqli($dbhost,$dbuser,$dbpass,$dbname);
?>
<!doctype html>
<html>
<head>
  <title>DSS WP Method</title>
  <style>
    * {font-family:verdana,arial,sans-serif;font-size:1em;padding:2px;}
    h1 {font-size:1.5em}
    h2 {font-size:1.2em}
    td,th {min-width:70px;border:solid 1px #999;}
    th {background-color:#99f;}
    table {min-width:600px;}
    sub,sup {font-size:0.8em}
    .center {text-align:center}
  </style>
</head>
<body>
  <h1>DSS WP Method</h1>
  <h2>[1] Normalisasi bobot W</h2>
  <p>
  <?php
    $sql="SELECT id_criteria,weight,attribute FROM wp_criterias";
    $result=$db->query($sql);
    $W=array();
    $attribute=array();
    while($row=$result->fetch_object()){
      $W[$row->id_criteria]=$row->weight;
      $attribute[$row->id_criteria]=$row->attribute;
    }
    $result->free();
   ?>
   Bobot awal W=(<?php echo implode(',',$W);?>) akan diperbaiki sehingga total 
   bobot sigma w<sub>j</sub>=1, dengan cara w<sub>j</sub>=w<sub>j</sub>/sigma 
   w<sub>j</sub>
  </p>
  <p>
    <?php
    $i=0;
    $sigma_w=array_sum($W);
    foreach($W as $j=>$w){
      echo "w<sub>".(++$i)."</sub>= {$w} /(".implode('+',$W).") = {$w} / {$sigma_w} = ".($w/$sigma_w)."<br>";
      $W[$j]=$w/$sigma_w;
    }
    ?>
  </p>
  <p>
    Bobot ternormalisasi w=(<?php echo implode(',',$W);?>)
  </p>
  <h2>[2] Menghitung nilai vektor S</h2>
  <p>
    <?php
    $sql="SELECT * FROM wp_evaluations ORDER BY id_alternative,id_criteria";
    $result=$db->query($sql);
    $X=array();
    $alternative='';
    while($row=$result->fetch_object()){
      if($row->id_alternative!=$alternative){
        $X[$row->id_alternative]=array();
        $alternative=$row->id_alternative;
      }
      $X[$row->id_alternative][$row->id_criteria]=$row->value;
    }
    $S=array();
    foreach($X as $alternative=>$x){
      $S[$alternative]=1;
      echo "S<sub>{$alternative}</sub> = ";
      foreach($x as $criteria=>$value){
         $S[$alternative]*=pow($value,($attribute[$criteria]=='cost'?-$W[$criteria]:$W[$criteria]));
         echo "({$value}<sup>".($attribute[$criteria]=='cost'?-$W[$criteria]:$W[$criteria])."</sup>)";
      };
      echo " = {$S[$alternative]}<br>";
    }
    ?>
  </p>
  <h2>[3] Menghitung nilai vektor V</h2>
  <?php
     $V=array();
     $sigma_s=array_sum($S);
     $devider=implode(' + ',$S);
     foreach($S as $alternative=>$s){
       echo "<p>V<sub>{$alternative}</sub> = $s/({$devider})<br>= ";
       $V[$alternative]=$s/$sigma_s;
       echo $V[$alternative]."</p>";
     }
  ?>
  <h2>[4] Perangkingan nilai vektor V</h2>
  <p>
    <table>
      <tr>
        <th>No</th>
        <th>Alternative</th>
        <th>Result</th>
      </tr>
      <?php
      arsort($V);
      $no=0;
      foreach($V as $alternative=>$result){
      echo "<tr class='center'>
              <td>".(++$no)."</td>
              <td>A<sub>{$alternative}<sub></td>
              <td>{$result}</td>
            </tr>";
      }
      ?>
    </table>
  </p>
</body>
</html>