364 lines
13 KiB
PHP
364 lines
13 KiB
PHP
<?php if (!defined('BASEPATH')) {
|
|
exit('No direct script access allowed');
|
|
}
|
|
|
|
class Cluster extends CI_Controller
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
header('Cache-Control: no-cache, must-revalidate, max-age=0');
|
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
|
header('Pragma: no-cache');
|
|
|
|
$this->load->helper('url');
|
|
$this->load->helper('vic_helper');
|
|
$this->load->helper('my_helper');
|
|
$this->load->helper('vic_convert_helper');
|
|
$this->load->model('m_vic');
|
|
$this->load->model('clustermodel');
|
|
$this->load->model('model');
|
|
|
|
date_default_timezone_set('Asia/Jakarta');
|
|
$this->load->helper('url');
|
|
$this->load->helper('vic_helper');
|
|
$this->load->helper('my_helper');
|
|
$this->load->helper('vic_convert_helper');
|
|
$this->load->model('m_vic');
|
|
if ($this->session->userdata('login') != 'login') {
|
|
redirect('auth');
|
|
}
|
|
}
|
|
|
|
public function iterasi_kmeans_hasil()
|
|
{
|
|
$tahun = $_GET['tahun'];
|
|
if ($tahun == 1) {
|
|
$t = '';
|
|
} else {
|
|
$t = "where predikat.tahun='$tahun'";
|
|
}
|
|
$data_hasil = $this->clustermodel->selectdata("predikat INNER JOIN alternatif on predikat.alternatif_id = alternatif.alternatif_id $t");
|
|
$ting = $this->clustermodel->selectdata("hasil where predikat='Sangat Rawan'");
|
|
$sed = $this->clustermodel->selectdata("hasil where predikat='Tidak Rawan'");
|
|
$ren = $this->clustermodel->selectdata("hasil where predikat='Rawan'");
|
|
|
|
$data = array(
|
|
'title' => 'iterasi Kmeans hasil',
|
|
'data_hasil' => $data_hasil,
|
|
'tin' => $ting,
|
|
'sed' => $sed,
|
|
'ren' => $ren,
|
|
'user' => $this->m_vic->get_data('admin'),
|
|
'predik' => $this->m_vic->get_data('predikat'),
|
|
'tes' => $this->m_vic->get_data('tes'),
|
|
);
|
|
|
|
$data['q'] = $this->db->query('select * from centroid_temp group by iterasi');
|
|
|
|
$this->load->view('cluster/iterasi_kmeans_hasil', $data);
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
|
|
$sesinya = $this->session->userdata('login');
|
|
|
|
$this->load->model('model');
|
|
$data = array(
|
|
'title' => '.:: Selamat Datang cluster ::. ',
|
|
'nama' => $sesinya['nama'],
|
|
'petunjuk' => $this->model->getPetunjuk(),
|
|
'wewenang' => $this->model->getWewenang(),
|
|
'titlesistem' => $this->model->getTitle(),
|
|
);
|
|
|
|
$this->load->view('cluster/header', $data);
|
|
$this->load->view('cluster/dashboard');
|
|
$this->load->view('cluster/footer');
|
|
|
|
}
|
|
|
|
public function pilih_cluster()
|
|
{
|
|
$d_tahun = $this->input->post('k_tahun');
|
|
$data_tahun = $this->m_vic->selecttahun('kriteria');
|
|
$data['mam'] = $this->m_vic->SelectMAMAM('kriteria');
|
|
$data['tes'] = $this->m_vic->get_data('tes');
|
|
$data['user'] = $this->m_vic->get_data('admin');
|
|
$data['alternatif'] = $this->m_vic->selectbaru('alternatif');
|
|
$data['kriteria'] = $this->m_vic->selectkritalt('kriteria');
|
|
$data['alter'] = $this->m_vic->get_data('alternatif');
|
|
$data['krit'] = $this->m_vic->get_data('kriteria');
|
|
$data['title'] = "Cluster";
|
|
$data['tahun'] = $d_tahun;
|
|
$data['data_tahun'] = $data_tahun;
|
|
|
|
$this->load->view('cluster/pilih_cluster', $data);
|
|
|
|
}
|
|
public function normalisasi()
|
|
{
|
|
|
|
$data_tahun = $this->m_vic->selecttahun('kriteria');
|
|
$data['mam'] = $this->m_vic->SelectMAMAM('kriteria');
|
|
$data['tes'] = $this->m_vic->get_data('tes');
|
|
$data['user'] = $this->m_vic->get_data('admin');
|
|
$data['alternatif'] = $this->m_vic->selectbaru('alternatif');
|
|
$data['alter'] = $this->m_vic->get_data('alternatif');
|
|
$data['krit'] = $this->m_vic->get_data('kriteria');
|
|
$data['title'] = "Cluster";
|
|
$data['data_tahun'] = $data_tahun;
|
|
|
|
$this->load->view('cluster/normalisasi', $data);
|
|
|
|
}
|
|
|
|
public function awal()
|
|
{
|
|
|
|
$data_tahun = $this->m_vic->selecttahun('kriteria');
|
|
$data['mam'] = $this->m_vic->SelectMAMAM('kriteria');
|
|
$data['tes'] = $this->m_vic->get_data('tes');
|
|
$data['user'] = $this->m_vic->get_data('admin');
|
|
$data['alternatif'] = $this->m_vic->selectbaru('alternatif');
|
|
$data['kriteria'] = $this->m_vic->selectkritalt('kriteria');
|
|
$data['alter'] = $this->m_vic->get_data('alternatif');
|
|
$data['krit'] = $this->m_vic->get_data('kriteria');
|
|
$data['title'] = "Cluster";
|
|
$data['data_tahun'] = $data_tahun;
|
|
|
|
$this->load->view('cluster/awal', $data);
|
|
|
|
}
|
|
public function cluster()
|
|
{
|
|
$tes = $this->input->post('coba');
|
|
if ($tes == 1) {
|
|
$data['n_tahun'] = $this->input->post('n_tahun');
|
|
$data['coba'] = $this->input->post('coba');
|
|
$data['n_c1'] = $this->input->post('n_c1');
|
|
$data['n_c2'] = $this->input->post('n_c2');
|
|
$data['n_c3'] = $this->input->post('n_c3');
|
|
} elseif ($tes == 2) {
|
|
$data['n_tahun'] = $this->input->post('n_tahun');
|
|
$data['coba'] = $this->input->post('coba');
|
|
$data['x1'] = $this->input->post('x1');
|
|
$data['y1'] = $this->input->post('y1');
|
|
$data['z1'] = $this->input->post('z1');
|
|
|
|
$data['x2'] = $this->input->post('x2');
|
|
$data['y2'] = $this->input->post('y2');
|
|
$data['z2'] = $this->input->post('z2');
|
|
|
|
$data['x3'] = $this->input->post('x3');
|
|
$data['y3'] = $this->input->post('y3');
|
|
$data['z3'] = $this->input->post('z3');
|
|
}
|
|
|
|
$data_tahun = $this->m_vic->selecttahun('kriteria');
|
|
$data['mam'] = $this->m_vic->SelectMAMAM('kriteria');
|
|
$data['tes'] = $this->m_vic->get_data('tes');
|
|
$data['user'] = $this->m_vic->get_data('admin');
|
|
$data['alternatif'] = $this->m_vic->selectbaru('alternatif');
|
|
$data['kriteria'] = $this->m_vic->selectkritalt('kriteria');
|
|
$data['alter'] = $this->m_vic->get_data('alternatif');
|
|
$data['krit'] = $this->m_vic->get_data('kriteria');
|
|
$data['title'] = "Cluster";
|
|
$data['data_tahun'] = $data_tahun;
|
|
|
|
$this->load->view('cluster/cluster', $data);
|
|
|
|
}
|
|
public function detail()
|
|
{
|
|
|
|
$data['user'] = $this->m_vic->get_data('admin');
|
|
$data['title'] = "Detail";
|
|
|
|
$this->load->view('cluster/detail', $data);
|
|
|
|
}
|
|
//proses Normalisasi
|
|
public function normali()
|
|
{
|
|
$d_tahun = $this->input->post('n_tahun');
|
|
$hapus = "DELETE from normalisasi where tahun=$d_tahun";
|
|
$this->db->query($hapus);
|
|
$data_tahun = $this->m_vic->selecttahun('kriteria');
|
|
$mam = $this->db->query('SELECT alternatif_id,c1c,c2c,c3c,tahun,MAX(c1c),MAX(c2c),MAX(c3c),AVG(c1c),AVG(c2c),AVG(c3c),MIN(c1c),MIN(c2c),MIN(c3c) from kriteria where tahun=' . $d_tahun);
|
|
$data['user'] = $this->m_vic->get_data('admin');
|
|
$data['tes'] = $this->m_vic->get_data('tes');
|
|
$table_kriteria = "SELECT * FROM kriteria where tahun=$d_tahun";
|
|
$krit = $this->db->query($table_kriteria);
|
|
|
|
$data['title'] = "Cluster";
|
|
$data['data_tahun'] = $data_tahun;
|
|
|
|
foreach ($mam->result_array() as $mx) {
|
|
$al_id = $mx['alternatif_id'];
|
|
$bobot = $mx['c2c'];
|
|
$max = $mx['MAX(c2c)'];
|
|
$min = $mx['MIN(c2c)'];
|
|
|
|
$nor1 = ($mx['c1c'] - $mx['MIN(c1c)']) / ($mx['MAX(c1c)'] - $mx['MIN(c1c)']);
|
|
$nor2 = ($mx['c2c'] - $mx['MIN(c2c)']) / ($mx['MAX(c2c)'] - $mx['MIN(c2c)']);
|
|
$nor3 = ($mx['c3c'] - $mx['MIN(c3c)']) / ($mx['MAX(c3c)'] - $mx['MIN(c3c)']);
|
|
}
|
|
foreach ($krit->result_array() as $kr_1) {
|
|
$al_tahun = $kr_1['tahun'];
|
|
$bobot2 = $kr_1['c2c'];
|
|
$al_id = $kr_1['alternatif_id'];
|
|
$nor1 = ($kr_1['c1c'] - $mx['MIN(c1c)']) / ($mx['MAX(c1c)'] - $mx['MIN(c1c)']);
|
|
$nor1hasil = round($nor1, 6);
|
|
$nor2 = ($kr_1['c2c'] - $mx['MIN(c2c)']) / ($mx['MAX(c2c)'] - $mx['MIN(c2c)']);
|
|
$nor2hasil = round($nor2, 6);
|
|
$nor3 = ($kr_1['c3c'] - $mx['MIN(c3c)']) / ($mx['MAX(c3c)'] - $mx['MIN(c3c)']);
|
|
$nor3hasil = round($nor3, 6);
|
|
$q = "insert into normalisasi(alternatif_id,c1c,c2c,c3c,tahun) values('" . $al_id . "','" . $nor1hasil . "','" . $nor2hasil . "','" . $nor3hasil . "','" . $al_tahun . "')";
|
|
$this->db->query($q);
|
|
}
|
|
$data['alternatif'] = $this->m_vic->selectbaru('alternatif');
|
|
$this->load->view('cluster/normalisasi', $data);
|
|
|
|
}
|
|
|
|
public function iterasi_kmeans()
|
|
{
|
|
$dat = $this->input->post('k_tahun');
|
|
//pilihan centroid awal
|
|
$x1 = $this->input->post('x1');
|
|
$y1 = $this->input->post('y1');
|
|
$z1 = $this->input->post('z1');
|
|
|
|
$x2 = $this->input->post('x2');
|
|
$y2 = $this->input->post('y2');
|
|
$z2 = $this->input->post('z2');
|
|
|
|
$x3 = $this->input->post('x3');
|
|
$y3 = $this->input->post('y3');
|
|
$z3 = $this->input->post('z3');
|
|
|
|
if ($dat == 1) {
|
|
$tahun = '';
|
|
} else {
|
|
$tahun = "where tahun='$dat'";
|
|
}
|
|
$data['alternatif'] = $this->m_vic->selectya("$tahun");
|
|
$data['kriteria'] = $this->m_vic->selectkrtitahun("$tahun");
|
|
$data['user'] = $this->m_vic->get_data('admin');
|
|
$data['tes'] = $this->m_vic->get_data('tes');
|
|
$data['mam'] = $this->m_vic->SelectMAM('kriteria where tahun=' . $dat);
|
|
$data['tahun'] = $dat;
|
|
$data['title'] = 'iterasi Kmeans';
|
|
|
|
$data['x1'] = $x1;
|
|
$data['x2'] = $x2;
|
|
$data['x3'] = $x3;
|
|
|
|
$data['y1'] = $y1;
|
|
$data['y2'] = $y2;
|
|
$data['y3'] = $y3;
|
|
|
|
$data['z1'] = $z1;
|
|
$data['z2'] = $z2;
|
|
$data['z3'] = $z3;
|
|
|
|
$this->load->view('cluster/iterasi_kmeans', $data);
|
|
|
|
}
|
|
|
|
public function iterasi_kmeans_lanjut()
|
|
{
|
|
$t = $_GET['tahun'];
|
|
if ($t == 1) {
|
|
$tahun = '';
|
|
} else {
|
|
$tahun = "where tahun='$t'";
|
|
}
|
|
|
|
if ($t == 1) {
|
|
$ta = '1';
|
|
} else {
|
|
$ta = $t;
|
|
}
|
|
|
|
$data['alternatif'] = $this->m_vic->selectya("$tahun");
|
|
$data['kriteria'] = $this->m_vic->selectkrtitahun("$tahun");
|
|
$data['user'] = $this->m_vic->get_data('admin');
|
|
$data['tes'] = $this->m_vic->get_data('tes');
|
|
$hasil_cen = $this->m_vic->get_data('hasil_centroid');
|
|
$data['predikat'] = $this->m_vic->get_data('predikat');
|
|
$data['title'] = 'iterasi kmeans lanjut';
|
|
|
|
$id = "";
|
|
$id = $this->db->query('select max(nomor) as m from hasil_centroid');
|
|
foreach ($id->result() as $i) {
|
|
$id = $i->m;
|
|
}
|
|
$this->db->where('nomor', $id);
|
|
$data['centroid'] = $this->db->get('hasil_centroid');
|
|
$data['id'] = $id + 1;
|
|
|
|
$it = "";
|
|
$it = $this->db->query('select max(iterasi) as it from centroid_temp');
|
|
foreach ($it->result() as $i) {
|
|
$it = $i->it;
|
|
}
|
|
$data['no_k'] = $it;
|
|
$it_temp = $it - 1;
|
|
$this->db->where('iterasi', $it_temp);
|
|
$it_sebelum = $this->db->get('centroid_temp');
|
|
$c1_sebelum = array();
|
|
$c2_sebelum = array();
|
|
$c2_sebelum = array();
|
|
$no = 0;
|
|
foreach ($it_sebelum->result() as $it_prev) {
|
|
$c1_sebelum[$no] = $it_prev->c1;
|
|
$c2_sebelum[$no] = $it_prev->c2;
|
|
$c3_sebelum[$no] = $it_prev->c3;
|
|
$no++;
|
|
}
|
|
|
|
$this->db->where('iterasi', $it);
|
|
$it_sesesudah = $this->db->get('centroid_temp');
|
|
$c1_sesesudah = array();
|
|
$c2_sesesudah = array();
|
|
$c2_sesesudah = array();
|
|
$no = 0;
|
|
foreach ($it_sesesudah->result() as $it_next) {
|
|
$c1_sesesudah[$no] = $it_next->c1;
|
|
$c2_sesesudah[$no] = $it_next->c2;
|
|
$c3_sesesudah[$no] = $it_next->c3;
|
|
$no++;
|
|
}
|
|
|
|
|
|
|
|
if ($c1_sebelum == $c1_sesesudah && $c2_sebelum && $c2_sesesudah && $c2_sebelum == $c2_sesesudah) {
|
|
?>
|
|
<script>
|
|
alert("Proses iterasi berakhir pada tahap ke-<?php echo $it; ?>");
|
|
</script>
|
|
<?php
|
|
|
|
echo "<meta http-equiv='refresh' content='0; url=" . base_url() . "cluster/iterasi_kmeans_hasil?tahun=$ta'>";
|
|
} else {
|
|
$delete = "delete from predikat where tahun='$ta'";
|
|
$this->db->query($delete);
|
|
$this->load->view('cluster/iterasi_kmeans_lanjut', $data);
|
|
|
|
}
|
|
}
|
|
|
|
function logout()
|
|
{
|
|
$this->session->sess_destroy();
|
|
redirect('');
|
|
}
|
|
|
|
}
|
|
|