forked from ipang-dwi/spk-ahp-pemilihan-lokasi-usaha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ahpcax.php
392 lines (351 loc) · 12.7 KB
/
ahpcax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DSS Candra - AHP Based >> Detail Proses</title>
<!-- Core CSS - Include with every page -->
<link href="sb2/css/bootstrap.min.css" rel="stylesheet">
<link href="sb2/font-awesome/css/font-awesome.css" rel="stylesheet">
<!-- Page-Level Plugin CSS - Blank -->
<!-- SB Admin CSS - Include with every page -->
<link href="sb2/css/sb-admin.css" rel="stylesheet">
</head>
<body>
<div id="wrapper">
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">DSS Candra - AHP Based</a>
</div>
<!-- /.navbar-header -->
</nav>
<!-- /.navbar-static-top -->
<nav class="navbar-default navbar-static-side" role="navigation">
<div class="sidebar-collapse">
<ul class="nav" id="side-menu">
<li class="active">
<a href="index.php"><i class="fa fa-dashboard fa-fw"></i> Dashboard</a>
</li>
<li>
<a href="kriteria.php"><i class="fa fa-table fa-fw"></i> Data Kriteria</a>
</li>
<li>
<a href="alternatif.php"><i class="fa fa-edit fa-fw"></i> Data Alternatif</a>
</li>
<li>
<a href="analisa.php"><i class="fa fa-files-o fa-fw"></i> Hasil Analisa</a>
</li>
</ul>
<!-- /#side-menu -->
</div>
<!-- /.sidebar-collapse -->
</nav>
<!-- /.navbar-static-side -->
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h3 class="page-header">Detail Proses</h3>
</div>
<!-- /.col-lg-12 -->
<div class="col-lg-12">
<div class="panel panel-primary">
<div class="panel-heading">
<b>Panel Detail Proses</b>
</div>
<div class="panel-body">
<?php
include 'config.php';
$arl = 5; //array lenght, 4 means ordo for 4x4 matrix
$alternatif = 0;
$kri = get_kriteria();
$alt = get_alternatif();
$mb = create_mx($kri);
for($i=0;$i<$arl;$i++){
@$mbk[$i] = create_mx($alt[$i]);
}
echo "<center>";
$k = print_art($mb,$arl,0);
$al = array(
0 => print_art($mbk[0],$arl,1), //
1 => print_art($mbk[1],$arl,1), //
2 => print_art($mbk[2],$arl,1), //
3 => print_art($mbk[3],$arl,1), //
4 => print_art($mbk[4],$arl,1) //
);
$wil = get_alt_name(); //new up 5 lines
$kriteria = get_kri_name(); //new up 5 lines
end($wil); $arl2 = key($wil)+1; //new
for($i=0; $i<$arl2; $i++){ //new
for($j=0; $j<$arl; $j++){
@$pha[$i] = $pha[$i] + ($k[$j]*$al[$j][$i]);
}
$pha[$i] = round($pha[$i],3);
}
//print_ar($pha);
echo "<b><i>Hasil Akhir</b></i><table border=1><tr><td></td>";
for($i=0; $i<$arl2; $i++){ //new
echo "<td>".$wil[$i]."</td>";
}
echo "<td>Prioritas</td></tr>";
for($i=0; $i<$arl; $i++){
echo "<tr>";
echo "<td>".$kriteria[$i]." </td>";
for($j=0; $j<$arl2; $j++){ //new
echo "<td>".$al[$i][$j]."</td>";
}
echo "<td>".$k[$i]."</td>";
echo "</tr>";
}
echo "<tr><td>Jumlah Hasil Perkalian</td>";
for($i=0; $i<$arl2; $i++){ //new
echo "<td>".$pha[$i]."</td>";
}
echo "<td></td></tr>";
echo "</table></br>";
uasort($pha,'cmp');
for($i=0;$i<$arl2;$i++){ //new for 8 lines below
if($i==0)
echo "<b><i>Dari tabel tersebut dapat disimpulkan bahwa ".$wil[array_search((end($pha)), $pha)]." mempunyai hasil paling tinggi, yaitu ".current($pha);
elseif($i==$arl2-1)
echo "</br>Dan terakhir ".$wil[array_search((prev($pha)), $pha)]." dengan nilai ".current($pha).".</i></b>";
else
echo "</br>Lalu diikuti dengan ".$wil[array_search((prev($pha)), $pha)]." dengan nilai ".current($pha);
}
function cmp($a, $b) { //function for last sorting
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
function print_art(array $x,$arl,$type){
echo "<b><i>Matrix Berpasangan ";
global $alternatif;
end($x); $arl = key($x)+1; //new
if($alternatif!=0)
echo "Kriteria ".$alternatif;
echo "</b></i><table border=1><tr><td>Matrix</td>"; //for print array table, or matrix arl dimension
for($i=0; $i<$arl; $i++){
echo "<td>";
if($type==0) echo "K";
else echo "A";
echo ($i+1)."</td>";
}
echo "</tr>";
for($i=0; $i<$arl; $i++){
echo "<tr>";
echo "<td>";
if($type==0) echo "K";
else echo "A";
echo ($i+1)." </td>";
for($j=0; $j<$arl; $j++){
echo "<td>".$x[$i][$j]."</td>";
}
echo "</tr>";
}
echo "<tr><td>Jumlah</td>";
for($i=0; $i<$arl; $i++){ //sum of each column
for($j=0; $j<$arl; $j++){
@$jml[$i] = $jml[$i] + $x[$j][$i];
}
echo "<td>".$jml[$i]."</td>";
}
echo "</tr>";
echo "</table>";
echo "</br></br>";
echo "<b><i>Matrix Nilai Kriteria</b></i><table border=1><tr><td>Matrix</td>"; //for print array table, or criterian matrix dimension
for($i=0; $i<$arl; $i++){
echo "<td>";
if($type==0) echo "K";
else echo "A";
echo ($i+1)."</td>";
}
echo "<td>Jumlah</td><td>Prioritas</td></tr>";
for($i=0; $i<$arl; $i++){
echo "<tr>";
echo "<td>";
if($type==0) echo "K";
else echo "A";
echo ($i+1)." </td>";
for($j=0; $j<$arl; $j++){
$mnk[$i][$j]=round(($x[$i][$j]/$jml[$j]),3);
@$jmlnk[$i] = $jmlnk[$i] + $mnk[$i][$j]; //sum of each row
echo "<td>".$mnk[$i][$j]."</td>";
}
echo "<td>".$jmlnk[$i]."</td>";
$prio[$i] = round(($jmlnk[$i]/$arl),3);
echo "<td>".$prio[$i]."</td>";
echo "</tr>";
}
echo "</table>";
echo "</br></br>";
echo "<b><i>Matrix Penjumlahan</b></i><table border=1><tr><td>Matrix</td>"; //for print array table, or summary matrix dimension
for($i=0; $i<$arl; $i++){
echo "<td>";
if($type==0) echo "K";
else echo "A";
echo ($i+1)."</td>";
}
echo "<td>Jumlah</td></tr>";
for($i=0; $i<$arl; $i++){
echo "<tr>";
echo "<td>";
if($type==0) echo "K";
else echo "A";
echo ($i+1)." </td>";
for($j=0; $j<$arl; $j++){
$mp[$i][$j]=round(($x[$i][$j]*$prio[$i]),3);
@$jmlp[$i] = $jmlp[$i] + $mp[$i][$j]; //sum of each row
echo "<td>".$mp[$i][$j]."</td>";
}
echo "<td>".$jmlp[$i]."</td>";
echo "</tr>";
}
echo "</table>";
echo "</br></br>";
echo "<b><i>Perhitungan Rasio Konsistensi</b></i><table border=1><tr><td>Matrix</td>"; //for print array table, or consistency rasio summary
echo "<td>Jumlah</td><td>Prioritas</td><td>Hasil</td></tr>";
for($i=0; $i<$arl; $i++){
echo "<tr>";
echo "<td>";
if($type==0) echo "K";
else echo "A";
echo ($i+1)." </td>";
echo "<td>".$jmlp[$i]."</td>";
echo "<td>".$prio[$i]."</td>";
@$hasil[$i] = round(($jmlp[$i] + $prio[$i]),3);
@$hsl = $hsl + $hasil[$i];
echo "<td>".$hasil[$i]."</td>";
echo "</tr>";
}
echo "<tr><td>Hasil</td><td></td><td></td><td>".$hsl."</td><tr>";
echo "</table>";
echo "</br></br>";
$nmax = round(($hsl/$arl),3);
$ci = round((($nmax-$arl)/($arl-1)),3);
$ri = round(((1.98*($arl-2))/$arl),3);
@$cr = round(($ci/$ri),3); //new
echo "<b>^Max</b> = Hasil/n = ".$hsl."/".$arl." = ".$nmax."</br>";
echo "<b>CI</b> = (^Max-n)/(n-1) = (".$nmax."-".$arl.")/(".$arl."-1) = ".$ci."</br>";
echo "<b>RI</b> = (1.98*(n-2))/n = (1.98*(".$arl."-2))/".$arl." = ".$ri."</br>";
echo "<b>CR</b> = CI/RI = ".$ci."/".$ri." = ".$cr."</br>";
if($cr<0.1)
echo "<b><i>Coz CR < 0.1 , maka rasio konsistensi dari perhitungan tersebut bisa diterima.</i></b>";
else
echo "<b><i>Coz CR > 0.1 , maka rasio konsistensi dari perhitungan tersebut tidak bisa diterima.</i></b>";
echo "<hr>";
$alternatif++;
return $prio;
}
function create_mx(array $input){
end($input); $l = key($input);
for($i=0;$i<=$l;$i++){
for($j=0;$j<=$l;$j++){
@$hsl[$i][$j] = round(($input[$j]/$input[$i]),3);
}
}
//print_ar($hsl);
return($hsl);
}
function get_kriteria(){
include 'config.php';
$kriteria = $mysqli->query("select * from kriteria");
if(!$kriteria){
echo $mysqli->connect_errno." - ".$mysqli->connect_error;
exit();
}
$i=0;
while ($row = $kriteria->fetch_assoc()) {
@$kri[$i] = $row["bobot"];
$i++;
}
//print_ar($kri);
return $kri;
}
function get_kri_name(){
include 'config.php';
$kriteria = $mysqli->query("select * from kriteria");
if(!$kriteria){
echo $mysqli->connect_errno." - ".$mysqli->connect_error;
exit();
}
$i=0;
while ($row = $kriteria->fetch_assoc()) {
@$kri[$i] = $row["kriteria"];
$i++;
}
//print_ar($kri);
return $kri;
}
function get_alternatif(){
include 'config.php';
$alternatif = $mysqli->query("select * from alternatif");
if(!$alternatif){
echo $mysqli->connect_errno." - ".$mysqli->connect_error;
exit();
}
$i=0;
while ($row = $alternatif->fetch_assoc()) {
@$alt[0][$i] = $row["k1"];
@$alt[1][$i] = $row["k2"];
@$alt[2][$i] = $row["k3"];
@$alt[3][$i] = $row["k4"];
@$alt[4][$i] = $row["k5"];
$i++;
}
//print_ar($alt);
return $alt;
}
function get_alt_name(){
include 'config.php';
$alternatif = $mysqli->query("select * from alternatif");
if(!$alternatif){
echo $mysqli->connect_errno." - ".$mysqli->connect_error;
exit();
}
$i=0;
while ($row = $alternatif->fetch_assoc()) {
@$alt[$i] = $row["alternatif"];
$i++;
}
//print_ar($alt);
return $alt;
}
function print_ar(array $x){ //just for print array
echo "<pre>";
print_r($x);
echo "</pre></br>";
}
/*
// DSS with ahp method implementation using N as ordo for matrix creation, web based coding with PHP..
// coded with love, by ip@ng http://www.firstplato.com email: admin@firstplato.com
*/
?>
</div>
<div class="panel-footer">
<i>by c@ndr@</i>
</div>
</div>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
</div>
<!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->
<!-- Core Scripts - Include with every page -->
<script src="sb2/js/jquery-1.10.2.js"></script>
<script src="sb2/js/bootstrap.min.js"></script>
<script src="sb2/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<!-- Page-Level Plugin Scripts - Blank -->
<!-- SB Admin Scripts - Include with every page -->
<script src="sb2/js/sb-admin.js"></script>
<!-- Page-Level Demo Scripts - Blank - Use for reference -->
</body>
</html>