Advertisement
cahyadsn

DSS MDAM AHP Method Prototype

Nov 4th, 2015
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.08 KB | None | 0 0
  1. <pre>
  2. <?php
  3. /********************************
  4. / AHP PROTOTYPE
  5. / FILENAME     : ahp.php
  6. / CREATED BY   : CAHYA DSN
  7. / CREATED DATE : 2013-04-23
  8. /*******************************/
  9. //Data Pair Wise Comparison
  10. $data=array(
  11.         array('absensi','loyalitas',4),
  12.         array('absensi','kedisiplinan',3),
  13.         array('loyalitas','kedisiplinan',0.5)
  14.       );
  15. //Random Index
  16. $ri=Array(0,0,0,0.58,0.9,1.12,1.24,1.32,1.41,1.45,1.49);
  17.  
  18. $a=array();
  19. $d=array();
  20. foreach($data as $dt){
  21.   $idx1=$a[]=str_replace(" ","_",$dt[0]);
  22.   $idx2=$a[]=str_replace(" ","_",$dt[1]);
  23.   if(!isset($d[$idx1])){$d[$idx1]=array();$d[$idx1][$idx1]=1;}
  24.   if(!isset($d[$idx2])){$d[$idx2]=array();$d[$idx2][$idx2]=1;}
  25.   $d[$idx1][$idx2]=$dt[2];
  26.   $d[$idx2][$idx1]=1/$dt[2];
  27. }
  28. $a=array_unique($a);
  29. $b=array();
  30. foreach($a as $v) $b[]=$v;
  31. echo "Criteria:\n";print_r($a);
  32. echo "Comparison data:\n";print_r($d);
  33. $a=$b;
  34. $n=count($a);
  35. echo "</pre>\n<table border=1>\n";
  36. $rows=array();
  37. $columns=array();
  38. for($i=0;$i<=$n;$i++){
  39.   for($j=0;$j<$n;$j++){
  40.     if($i>0) $columns[$i-1]=isset($columns[$i-1])?$columns[$i-1]+$d[$a[$j]][$a[$i-1]]:$d[$a[$j]][$a[$i-1]];
  41.   }
  42. }
  43. for($i=0;$i<=$n;$i++){
  44.   echo "<tr><th>".ucwords($i==0?"criteria":str_replace("_"," ",$a[$i-1]))."</th>";
  45.   for($j=0;$j<$n;$j++){
  46.     echo ($i==0?"<th>".ucwords(str_replace("_"," ",$a[$j]))."</th>":"<td>".round($d[$a[$i-1]][$a[$j]],4)."</td>");
  47.     if($i>0) $rows[$i-1]=isset($rows[$i-1])?$rows[$i-1]+$d[$a[$i-1]][$a[$j]]/$columns[$j]:$d[$a[$i-1]][$a[$j]]/$columns[$j];
  48.   }
  49.   if($i>0){$rows[$i-1]/=$n;echo "<td>".$rows[$i-1]."</td>";}else{echo "<th>Priority Vector</th>";}
  50.   $p=($i==0?0:$p+$rows[$i-1]*$columns[$i-1]);
  51.   echo "</tr>\n";
  52. }
  53. $ci=($p-$n)/($n-1);
  54. $cr=$ci/$ri[$n];
  55. echo "<table>\n<pre>";
  56. echo "Total:\n";
  57. print_r($columns);
  58. echo "Priority Vector:\n";
  59. print_r($rows);
  60. echo "</pre>";
  61. echo "Principal Eigen Value (&#955;<sub>max</sub>)=$p<br />\n"
  62.     ."Consistency Index (CI) =$ci<br/>\n"
  63.     ."Random Index (RI)=".$ri[$n]."<br />\n"
  64.     ."Consistency Ratio (CR)=<span".($cr>0.1?' style="color:red"':'').">$cr</span>";
  65. ?>
  66. </pre>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement