0% found this document useful (0 votes)
3 views

Source Code

The document contains source code for a web application using PHP, specifically for a decision support system based on the ELECTRE method for health facility searches in Sidoarjo. It includes the main pages such as 'welcome.php', which serves as the landing page for users, and 'index.php', which displays data about health facilities and their types. Additionally, 'ElectreSolver.php' outlines the logic for processing decisions using the ELECTRE method, including the calculation of ideal values and the construction of agreement and disagreement matrices.

Uploaded by

Barkah Wahyu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Source Code

The document contains source code for a web application using PHP, specifically for a decision support system based on the ELECTRE method for health facility searches in Sidoarjo. It includes the main pages such as 'welcome.php', which serves as the landing page for users, and 'index.php', which displays data about health facilities and their types. Additionally, 'ElectreSolver.php' outlines the logic for processing decisions using the ELECTRE method, including the calculation of ideal values and the construction of agreement and disagreement matrices.

Uploaded by

Barkah Wahyu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

LAMPIRAN SOURCE CODE PROGRAM

welcome.php

welcome.php merupakan halaman pertama untuk user baik user tamu maupun admin

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>SPK Electre Sidoarjo</title>
<!-- Bootstrap Core CSS -->
<link href="../vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- MetisMenu CSS -->
<link href="../vendor/metisMenu/metisMenu.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="../dist/css/sb-admin-2.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="../vendor/font-awesome/css/font-awesome.min.css"
rel="stylesheet" type="text/css">
<style type="text/css">
body, html {
height: 100%;
margin: 0;
}
.bg {
/* Ganti Gambar Disini */
background-image: url("man.jpg");
height: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
</style>
</head>
<body>
<div class="bg"></div>
<div class="container">
<!-- end -->
<div class="row">
<style type="text/css">

B-1
#myid {
top: 50%;
left: 50%;
width:30em;
height:18em;
margin-top: -9em;
margin-left: -15em;
position:fixed;
}
</style>
<div class="col-lg-12 col-sm-offset-3" id="myid">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><center><p><font color="Blue"><font
size="5">WELCOME</p></font></font></center></h3>
<h3 class="panel-
title"><center><p><font color="Blue"><font size="5">SISTEM PENDUKUNG
KEPUTUSAN METODE ELECTRE KABUPATEN
SIDOARJO</p></font></font></center></h3>
</div>
<div class="panel-body">
<center><a href="login.php" type="button" class="btn btn-info"><i
class="fa fa-user"></i><font size="5"> ADMIN </font></a>
<a href="index.php" type="button" class="btn btn-info"><i class="fa fa-
search"></i><font size="5"> TAMU (GUEST)</font></a></center>
</div>
</div>
</div>
</div>
</div>
<!-- jQuery -->
<script src="../vendor/jquery/jquery.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="../vendor/bootstrap/js/bootstrap.min.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="../vendor/metisMenu/metisMenu.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="../dist/js/sb-admin-2.js"></script>
</body>
</html>

index.php
index.php adalah halaman utama dari aplikasi web ini

<?
require "header.php";

B-2
require "db.php";
if (!isset($_SESSION)) {
session_start();
}
//Kesehatan
$q1 =mysql_query("SELECT COUNT('nama') AS nama FROM
t_f_kesehatan");
$row1 =mysql_fetch_array($q1);
//Jenisfasilitas
$q2 =mysql_query("SELECT COUNT('nama_jenis') AS nama FROM
t_jenis");
$row2 =mysql_fetch_array($q2);
?>
<!-- Page Content -->
<div id="page-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Selamat Datang</h1>
</div>
<!-- /.col-lg-12 -->
</div>
<div class="row">
<div class="col-lg-3 col-md-6">
<div class="panel panel-green">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-hospital-o fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div class="huge"><?=$row1['nama']?></div>
<div>Jumlah Fasilitas</div>
</div>
</div>
</div>
<?
if (isset($_SESSION['id'])) {
?>
<a href="fasilitas.php">
<div class="panel-footer">
<span class="pull-left">Lihat Detail</span>
<span class="pull-right"><i class="fa fa-arrow-circle-
right"></i></span>
<div class="clearfix"></div>
</div>

B-3
</a>
<?
}
?>
</div>
</div>
<div class="col-lg-3 col-md-6">
<div class="panel panel-primary">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-user-md fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div class="huge"><?=$row2['nama']?></div>
<div>Jenis Fasilitas</div>
</div>
</div>
</div>
<?
if (isset($_SESSION['id'])) {
?>
<a href="jenis.php">
<div class="panel-footer">
<span class="pull-left">Lihat Detail</span>
<span class="pull-right"><i class="fa fa-arrow-circle-
right"></i></span>
<div class="clearfix"></div>
</div>
</a>
<?
}
?>
</div>
</div>
</div>
<div class="row">
<div class="panel-body">
<div class="table-responsive">
<table width="100%" class="table table-striped table-
bordered table-hover" id="example">
<thead>
<tr>
<th>Nama</th>
<th>Jenis</th>
<th>Alamat</th>

B-4
<th>Pilih</th>
</tr>
</thead>
<tbody>

<?
$no=0;
$q=mysql_query("SELECT
t_f_kesehatan.id
, t_jenis.nama_jenis
, t_f_kesehatan.nama
, t_f_kesehatan.alamat
FROM
t_f_kesehatan
INNER JOIN t_jenis
ON (t_f_kesehatan.id_jenis = t_jenis.id)");
while ($row=mysql_fetch_array($q)) {
?>
<tr class="odd gradeX">
<td><?=$row['nama']?></td>
<td><?=$row['nama_jenis']?></td>
<td><?=$row['alamat']?></td>
<td style="width: 10%">
<a href="info.php?info=<?=$row['id']?>"
type="button" class="btn btn-info btn-xs"><i class="fa fa-search"></i> Lihat
Detail</a>
</td>
</tr>
<?
}
?>

</tbody>
</table>
</div>
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container-fluid -->
</div>
<!-- modal iki -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-
labelledby="Mlabel" aria-hidden="true">
<div class="modal-dialog">

B-5
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="Mlabel"><center>Sistem Pendukung Keputusan
Pencarian Fasilitas kesehatan dengan menggunakan Electre</center></h4>
</div>
<div class="modal-body">
<center>Selamat Datang di Aplikasi Sistem Pendukung Keputusan Pencarian
Fasilitas kesehatan dengan menggunakan Electre Untuk Kabupaten
Sidoarjo</center><br>
<center><a href="login.php" type="button" class="btn btn-info"><i
class="fa fa-user"></i> Admin</a>
<button type="button" class="btn btn-info" data-dismiss="modal">Tamu
(Guest)</button></center>
</div>
<div class="modal-footer">
<!-- <button type="button" class="btn btn-primary" data-
dismiss="modal">Close</button> -->
</div>
</div>
</div>
</div>
<!-- ./modal -->
<!-- /#page-wrapper -->
<?
require "footer.php";
?>
<script>
$(document).ready(function() {
$('#example').DataTable({
responsive: true
});
});
</script>

ElectreSolver.php
ElectreSolver.php adalah proses penyelesaian dengan menggunakan metode
ELECTRE

<?php
class ElectreSolver
{
private $alternatives;
private $criterias;
private $idealValues = array();
private $agreeMatrix = array();
private $disagreeMatrix = array();

B-6
private $finalMatrix = array();
private $outrankingAgreeThreshold;
private $outrankingDisagreeThreshold;
/**
* @param $alternatives
* @param $criterias
*/
public function __construct($alternatives, $criterias)
{
$this->setAlternatives($alternatives);
$this->setCriterias($criterias);
}
/**
* @return mixed
*/
public function getAlternatives()
{
return $this->alternatives;
}
/**
* @param mixed $alternatives
*/
public function setAlternatives($alternatives)
{
foreach ($alternatives as $alternative) {
$this->alternatives[] = $alternative;
}
}
/**
* @return mixed
*/
public function getCriterias()
{
return $this->criterias;
}
/**
* @param mixed $criterias
*/
public function setCriterias($criterias)
{
foreach ($criterias as $criteria) {
$this->criterias[] = $criteria;
}
}
protected function findIdealValues()
{

B-7
$ideals = array();
/** @var Criteria $criteria */
foreach ($this->criterias as $criteria) {
$ideal = null;
$values = array();
/** @var Alternative $alternative */
foreach ($this->alternatives as $alternative) {
$values[] = $alternative->getCriteriaValue($criteria->getName());
}
if ($criteria->getType() === Criteria::TYPE_MAX) {
$ideal = max($values);
} else {
$ideal = min($values);
}
$ideals[$criteria->getName()] = $ideal;
}
$this->idealValues = $ideals;
}
protected function normalize()
{
/** @var Alternative $alternative */
foreach ($this->alternatives as $name => $alternative) {
/** @var Criteria $criteria */
foreach ($this->criterias as $criteria) {
$modifiedValue = $alternative->getCriteriaValue($criteria-
>getName());
if ($criteria->getType() === Criteria::TYPE_MAX) {
$modifiedValue = $modifiedValue / $this->idealValues[$criteria-
>getName()];
} else {
$modifiedValue = $this->idealValues[$criteria->getName()] /
$modifiedValue;
}
$alternative->addCriteria($criteria, number_format($modifiedValue,
2));
}
}
}
protected function calculateWeighted()
{
/** @var Alternative $alternative */
foreach ($this->alternatives as $alternative) {
/** @var Criteria $criteria */
foreach ($this->criterias as $criteria) {
$modifiedValue = $alternative->getCriteriaValue($criteria-
>getName());

B-8
$modifiedValue *= $criteria->getWeight();
$alternative->addCriteria($criteria, number_format($modifiedValue,
2));
}
}
}
protected function findPositiveAndNegativeSets()
{
/** @var Alternative $alternative */
foreach ($this->alternatives as $alternative) {
/** @var Alternative $opponent */
foreach ($this->alternatives as $opponent) {
if ($alternative == $opponent) {
continue;
}
$positives = array();
$negatives = array();
/** @var Criteria $criteria */
foreach ($this->criterias as $criteria) {
if ($alternative->getCriteriaValue($criteria->getName()) >=
$opponent->getCriteriaValue($criteria->getName())) {
$positives[] = $criteria->getName();
} else {
$negatives[] = $criteria->getName();
}
}
$alternative->addToNegaitveSet($opponent->getName(), $negatives);
$alternative->addToPositiveSet($opponent->getName(), $positives);
}
}
}
protected function getAgreeAndDisagreeMatrixes()
{
$agreeMatrix = array();
$disagreeMatrix = array();
$row = 0;
/** @var Alternative $alternative */
foreach ($this->alternatives as $alternative) {
$column = 0;
/** @var Alternative $opponent */
foreach ($this->alternatives as $opponent) {
$agreeMatrix[$row][$column] = 0;
$disagreeMatrix[$row][$column] = 0;
if ($alternative != $opponent) {
$positives = $alternative->getPositivesFor($opponent->getName());
/** @var Criteria $criteria */

B-9
foreach ($this->criterias as $criteria) {
if (in_array($criteria->getName(), $positives)) {
$agreeMatrix[$row][$column] += $criteria->getWeight();
}
}
$negatives = $alternative->getNegativesFor($opponent->getName());
$maxDiff = 0;
/** @var Criteria $criteria */
foreach ($this->criterias as $criteria) {
$diff = abs($alternative->getCriteriaValue($criteria->getName()) -
$opponent->getCriteriaValue($criteria->getName()));
if ($diff > $maxDiff) {
$maxDiff = $diff;
}
}
$best = 0;
foreach ($negatives as $criteriaName) {
$diff = abs($alternative->getCriteriaValue($criteriaName) -
$opponent->getCriteriaValue($criteriaName));
if ($diff > $best) {
$best = $diff;
}
}
$disagreeMatrix[$row][$column] = number_format(@($best /
$maxDiff), 2);
}
$column++;
}
$row++;
}
$this->agreeMatrix = $agreeMatrix;
$this->disagreeMatrix = $disagreeMatrix;
}
protected function printMatrix($matrix)
{
$n = count($matrix);
for ($i = 0; $i < $n; $i++) {
for ($j = 0; $j < $n; $j++) {
echo $matrix[$i][$j] . ' ';
}
echo PHP_EOL;
}
}
protected function calculateOutrankingThresholds()
{
$n = count($this->agreeMatrix);

B-10
$values = array();
for ($i = 0; $i < $n; $i++) {
for ($j = 0; $j < $n; $j++) {
if ($i == $j) {
continue;
}
$values[] = $this->agreeMatrix[$i][$j];
}
}
$this->outrankingAgreeThreshold = number_format(array_sum($values) /
count($values), 2);
$values = array();
for ($i = 0; $i < $n; $i++) {
for ($j = 0; $j < $n; $j++) {
if ($i == $j) {
continue;
}
$values[] = $this->disagreeMatrix[$i][$j];
}
}
$this->outrankingDisagreeThreshold = number_format(array_sum($values) /
count($values), 2);
}
protected function getFinalMatrix()
{
$finalMatrix = array();
$n = count($this->agreeMatrix);
for ($i = 0; $i < $n; $i++) {
for ($j = 0; $j < $n; $j++) {
if ($i == $j) {
$finalMatrix[$i][$j] = 0;
}
if ($this->agreeMatrix[$i][$j] > $this->outrankingAgreeThreshold &&
$this->disagreeMatrix[$i][$j] < $this->outrankingDisagreeThreshold) {
$finalMatrix[$i][$j] = 1;
// i dominates j
$this->alternatives[$i]->addDominates($this->alternatives[$j]-
>getName());
} else {
// i is dominated by j
$finalMatrix[$i][$j] = 0;
}
}
}
$this->finalMatrix = $finalMatrix;
}

B-11
protected function printDecisionTable()
{
/** @var Alternative $alternative */
foreach ($this->alternatives as $alternative) {
echo $alternative->getName() . ': ';
foreach ($alternative->getCriteriaValues() as $name => $value) {
echo "[$name]" . ': ' . $value . ' ';
}
echo PHP_EOL;
}
}
protected function printPositiveNegativeSets()
{
/** @var Alternative $alternative */
foreach ($this->alternatives as $alternative) {
echo $alternative->getName() . ' positive sets:';
print_r($alternative->getPositiveSet());
echo PHP_EOL;
echo $alternative->getName() . ' negative sets:';
print_r($alternative->getNegativeSet());
echo PHP_EOL;
}
}
public function run($verbose = false)
{
if ($verbose) {
$this->printDecisionTable();
//echo PHP_EOL;
}
echo 'Bobot Nilai' . PHP_EOL;
$this->findIdealValues();
if ($verbose) {
//print_r($this->idealValues);
foreach($this->idealValues as $key => $value){
echo "$key = $value <br/>";
}
echo PHP_EOL;
}
echo 'Normalisasi' . PHP_EOL;
$this->normalize();
if ($verbose) {
$this->printDecisionTable();
echo PHP_EOL;
}
echo 'kalkulasi bobot' . PHP_EOL;
$this->calculateWeighted();

B-12
if ($verbose) {
$this->printDecisionTable();
echo PHP_EOL;
}
echo '' . PHP_EOL;
$this->findPositiveAndNegativeSets();
if ($verbose) {
$this->printPositiveNegativeSets();
}
echo PHP_EOL;
$this->getAgreeAndDisagreeMatrixes();
if ($verbose) {
echo 'concordance' . PHP_EOL;
$this->printMatrix($this->agreeMatrix);
echo PHP_EOL . PHP_EOL;
echo 'discordance' . PHP_EOL;
$this->printMatrix($this->disagreeMatrix);
echo PHP_EOL . PHP_EOL;
}
echo 'OUTRANKING' . PHP_EOL;
$this->calculateOutrankingThresholds();
if ($verbose) {
echo 'Agree threshold: ' . $this->outrankingAgreeThreshold . PHP_EOL;
echo 'Disagree threshold: ' . $this->outrankingDisagreeThreshold .
PHP_EOL;
}
echo PHP_EOL;
echo 'FINAL' . PHP_EOL;
$this->getFinalMatrix();
if ($verbose) {
$this->printMatrix($this->finalMatrix);
}
echo PHP_EOL;
$a =array();
$b =array();
$c =array();
$d =array();
echo 'Hasil' . PHP_EOL;
foreach ($this->alternatives as $alternative) {
$b[]= $alternative->getName();
//echo "<br>[" . $alternative->getName() ."] ";
$a[]=implode(', ', array_unique($alternative->getDominates()));
$c[]=count(array_count_values($a));
//echo ' Jumlah Total Angka 1: ' . implode(', ', array_unique($alternative-
>getDominates())) . PHP_EOL;
}

B-13
$j=count($b);
for ($i=0; $i < $j; $i++) {
if ($a[$i]=='') {
echo "<br> jumlah angka 1 dari ".$b[$i]." : 0";
} else {
echo "<br> jumlah angka 1 dari ".$b[$i]." : ".count(explode(", ",
$a[$i]));
}
}
}
public function printResult($voc = false)
{
if ($voc) {
$this->printDecisionTable();
//echo PHP_EOL;
}
$this->findIdealValues();
if ($voc) {
$this->idealValues;
}
$this->normalize();
if ($voc) {
$this->printDecisionTable();
}
$this->calculateWeighted();
if ($voc) {
$this->printDecisionTable();
}
$this->findPositiveAndNegativeSets();
if ($voc) {
$this->printPositiveNegativeSets();
}
//echo 'concordance dan discordance' . PHP_EOL;
$this->getAgreeAndDisagreeMatrixes();
if ($voc) {
$this->printMatrix($this->agreeMatrix);
$this->printMatrix($this->disagreeMatrix);
}
$this->calculateOutrankingThresholds();
if ($voc) {
$this->outrankingAgreeThreshold;
$this->outrankingDisagreeThreshold;
}
$this->getFinalMatrix();
if ($voc) {
$this->printMatrix($this->finalMatrix);

B-14
}
foreach ($this->alternatives as $alternative) {
$alternative->getName();
implode(', ', $alternative->getDominates());
}
$hasil =array();
$hasil2=array();
$hasil3=array();
$a=array();
$nama=array();
/** @var Alternative $alternative */
foreach ($this->alternatives as $alternative) {
$a[] =$alternative->getDominates();
$nama[]=$alternative->getName();
// echo "<br>[" . $alternative->getName() ."] ";
// echo ' Mengungguli: ' . implode(', ', $alternative->getDominates()) .
PHP_EOL;
// echo PHP_EOL;
}
$maxval=array();
for ($i=0; $i < count($nama) ; $i++) {
$maxval[]= count($a[$i]);
}
arsort($maxval);
$n=0;
foreach ($maxval as $key => $value) {
$n++;
$hasil[] = $nama[$key];
$hasil2[] = ' <a href="peta.php?info='.$nama[$key].'" type="button"
class="btn btn-info"><i class="fa fa-map"></i> Lihat Peta</a>';
$hasil3 =$maxval[$key];
}
return array($hasil,$hasil3,$hasil2);
// $maxval= max($a);
// $cari = array_search($maxval, $a);
// if (array_key_exists($cari, $nama)) {
// echo "<br><br>Paling Tinggi : <b>".$nama[$cari]."<b>";
// echo '<form action="peta.php" method="POST"><input type="hidden"
name="nama" value="'.$nama[$cari].'" /><br><button name="submit"
type="submit" class="btn btn-info">Lihat Peta</button></form>';
// }
// echo "<br>";
}
}

B-15

You might also like