private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                btnHitung.Enabled = true;

                /*DataGridView dt = dataGridViewInput;
                 * double[,] d = new double[dataGridViewInput.RowCount, dataGridViewInput.ColumnCount  ];
                 * for(int i = 0;i<dt.ColumnCount;i++)
                 * {
                 *  for (int j = 0; j < dt.RowCount; j++)
                 *  {
                 *      d[ j,i] = double.Parse(dt.Rows[j].Cells[i].Value.ToString());
                 *  }
                 * }
                 *
                 * double[,] d = DatatabletoArray(dataGridViewInput);
                 * Matrix<double> lala = DenseMatrix.OfArray(d);
                 * double[,] ard = lala.ToArray();
                 * DataTable dat = ArraytoDatatable(ard);*/
                //dtCopy.DataSource =dat ;

                mtKriteria = DenseMatrix.OfArray(DatatabletoArray(dataGridViewInput));
                Matrix <double> mtKr = mtKriteria.Clone();
                mtKriteria = mtKriteria.Multiply(mtKriteria);
                if (CekKonsistensi(mtKr, mtKriteria))
                {
                    int w = (lstAlternatif.Count + 2) * 100;
                    int h = (lstAlternatif.Count) * 25 + 150;
                    lstDtGrid = new List <DataGridView>();
                    panIsi.Controls.Clear();
                    for (int i = 0; i < lstKriteria.Count; i++)
                    {
                        Panel pan = new Panel();
                        pan.BorderStyle = BorderStyle.Fixed3D;
                        pan.Width       = w;
                        pan.Height      = h;
                        pan.Left        = (i % 2) * w;
                        pan.Top         = i / 2 * h;
                        //pan.AutoSize = true;
                        panIsi.Controls.Add(pan);
                        Label lab = new Label();
                        lab.Text = lstKriteria[i];
                        lab.Left = 10;
                        lab.Top  = 10;
                        pan.Controls.Add(lab);
                        DataGridExample frm = new DataGridExample();
                        DataGridView    dt  = frm.dtExample;
                        dt.CellEndEdit += dataGridViewInput_CellEndEdit;
                        dt.Left         = 100;
                        dt.Top          = 75;
                        dt.AutoSize     = true;
                        dt.ColumnCount  = lstAlternatif.Count;
                        dt.Height       = 25 * lstAlternatif.Count;
                        dt.RowCount     = lstAlternatif.Count;
                        dt.Width        = 100 * lstAlternatif.Count;
                        dtNorm(dt);
                        pan.Controls.Add(dt);
                        AddLabelPanel(dt, lstAlternatif, pan);

                        lstDtGrid.Add(dt);
                    }
                }
                else
                {
                    MessageBox.Show("Maaf Tabel anda tidak Konsisten, silahkan diubah lagi");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Tolong diisi perbandingan kriteria yang benar dulu yaa");
            }
        }
        private void btnHitung_Click(object sender, EventArgs e)
        {
            try {
                List <String> lstCR = new List <string> {
                };
                Matrix <double>   mtAlternatif;
                Vector <double>[] arVect = new Vector <double> [lstDtGrid.Count];
                for (int i = 0; i < lstDtGrid.Count; i++)
                {
                    Matrix <double> Alter  = DenseMatrix.OfArray(DatatabletoArray(lstDtGrid[i]));
                    Matrix <double> Alter2 = Alter.Multiply(Alter);
                    if (CekKonsistensi(Alter, Alter2))
                    {
                        //lstCR.Add(lstAlternatif[i]);
                    }
                    Vector <double> y = Alter2.RowAbsoluteSums();
                    arVect[i] = y.Normalize(1);
                }

                if (lstCR.Count == 0)
                {
                    mtAlternatif = DenseMatrix.OfColumnVectors(arVect);
                    Vector <double> vcKrit = mtKriteria.RowSums().Normalize(1);
                    mtHasil = mtAlternatif.Multiply(vcKrit.ToColumnMatrix());
                    Vector <double> vcnorm = DenseMatrix.OfArray(DatatabletoArray(dtCost)).RowSums().Normalize(1);


                    int      a  = 1;
                    ListView ks = kesimpulan;
                    panHasil.Controls.Clear();
                    Label lab = new Label();
                    lab.Text = "Hasil Perhitungan";
                    lab.Left = 10;
                    lab.Top  = 10;
                    panHasil.Controls.Add(lab);
                    DataGridExample frm = new DataGridExample();
                    DataGridView    dt  = frm.dtExample;
                    dt.Left  = 100;
                    dt.Top   = 75;
                    dt.Width = 30;
                    dt.SendToBack();
                    //dt.AutoSize = true;
                    //dt.ColumnCount = 0;
                    dt.Height = 25 * lstAlternatif.Count;
                    //dt.RowCount = lstAlternatif.Count;
                    dt.Width = 100 * lstAlternatif.Count;
                    panHasil.Controls.Add(dt);
                    double[,] arHasil = mtHasil.ToArray();


                    double[] hasil = convert(arHasil);

                    //Tambahkan bagis Cost
                    double[] Hcost = vcnorm.ToArray();
                    for (int i = 0; i < hasil.Length; i++)
                    {
                        Hcost[i] = Hcost[i] / hasil[i];
                    }

                    hasil = Hcost;
                    double[]      colne    = (double[])hasil.Clone();
                    List <double> lsthasil = hasil.ToList();
                    lsthasil.Sort();
                    hasil = lsthasil.ToArray();

                    DataTable tab = ArraytoDatatable(hasil);
                    dt.DataSource = tab;
                    ks.Items.Clear();
                    int           count   = 0;
                    List <String> lstUrut = new List <string>();
                    for (int i = hasil.Length - 1; i >= 0; i--)
                    {
                        int    idex = Array.IndexOf(colne, hasil[i]);
                        String kata = lstAlternatif[idex];
                        colne[idex] = -1;
                        lstUrut.Add(kata);
                        if (count == 0)
                        {
                            ks.Items.Add("Menurut perhitungan AHP, Alternatif terbaik adalah " + kata + ", hasil : " + hasil[i]);
                        }
                        else if (count <= 3)
                        {
                            ks.Items.Add("Alternatif terbaik ke " + (count + 1) + " adalah " + kata + ", hasil : " + hasil[i]);
                        }
                        count++;
                        //if (count > 3) break;
                    }
                    AddLabelHasil(dt, lstUrut, panHasil);
                    panHasil.Controls.Add(ks);
                    //panel1.Hide();
                }
                else
                {
                    String Msg = "Ada Data yang tidak konsisten : ";

                    for (int i = 0; i < lstCR.Count; i++)
                    {
                        Msg += lstCR[i] + ", ";
                    }
                    MessageBox.Show(Msg);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ada data yang belum terisi atau kesalahan inputan, tolong diperiksa kembali");
            }
        }