mardi 24 novembre 2015

after count values . return to get by index php

can you give me tips.. when i calculate result from array Jakarta then i searching closest value from random numbers

if (random values closest from results array from Jakarta)

{

i can get index from closest value index Jakarta

}

can you give me ideas? please help me

 Array
(
[Jakarta] => Array
    (
        [0] => (0.01*1)*(0)= *1)/0.0084046089837094  Hasilnya Adalah =   0
        [1] => (0.01*1)*(0.0021881838074398)= *1)/0.0084046089837094  Hasilnya Adalah =   0.0026035521839043
        [2] => (0.01*1)*(0.0020120724346076)= *1)/0.0084046089837094  Hasilnya Adalah =   0.0023940107606524
        [3] => (0.01*1)*(0.0020491803278689)= *1)/0.0084046089837094  Hasilnya Adalah =   0.0024381625984513
        [4] => (0.01*1)*(0.0021551724137931)= *1)/0.0084046089837094  Hasilnya Adalah =   0.0025642744569919
    )

this is a where can i choose closest value Jakarta and random values . but i lost index from array

      Kota Selanjutnya Array
     (
     [0] => 0.65159539101629
     )

The values of Jakarta is

 0
 0.0026035521839043
 0.0023940107606524
 0.0024381625984513
 0.0024381625984513
 0.0023940107606524

then i want make a value random example 0.0043 then i hope closest result from value array Jakarta to random if value random closest value from jakarta

after closest from random and value Jakarta . now i can choose index array to closest from random values and value from Jakarta

paramater ($simpankota) is name from city

   public function autoRandom($simpankota)
   {
            $alfa=1.0;
            $beta=1.0;
            $semut=3;
            $rho=0.5;
            $tijawal=0.01;
            $paramaterindex=0;

        $simpankota2 = $simpankota;



        $simpankota3=$simpankota;
        foreach ($simpankota as $key => $value) {
          $array = array();
          $array1=array();
          $array2=array();
          $array3=array();
          $test1=array();
          $v=array();
          $test1 = array();
   $beban=array();

          foreach ($simpankota2 as $k => $v) {
                $berangkat=$value;
                $tujuankota=$v;


               $array1[]=parent::addProbabilitas1($berangkat, $tujuankota);
               $array3[] = $this-> getProbabilitas1() * $tijawal ;

               $test1[]=$this->getProbabilitas1();

               $d=array_sum ($test1);

               $a=$beban;
                 $akhirlah = $a ;



            $max = 1.000;
            $min = 0.001;
            for($i=0;$i<1;$i++)
            {
                print ("<br>");
                $range = $max-$min;
                $num = $min + $range * mt_rand(0, 32767)/32767;    
                $num = round($num, 2);    
                //print ((float) $num);
                $next=$num;
            }



         }        



          foreach ($simpankota2 as $k => $v) {
                $berangkat=$value;
                $tujuankota=$v;
            $array1[]=parent::addProbabilitas1($berangkat, $tujuankota);
            $array[] = $value . ' -> ' . $v .  ' ------ '  . "Jarak : ". $this->getProbabilitas1() . " TIJ" ;
            $array2[] =$tijawal .' * '. $this->getProbabilitas1() .' = '  . "Nilai Akhir : " .($this->getProbabilitas1() * $tijawal)." tij" ;
            $array3[] = $this-> getProbabilitas1() * $tijawal ;

            $test1[]=$this->getProbabilitas1();
            $beban[] ='('.$tijawal ."*". $alfa.')'.'*'. '('.$this->getProbabilitas1() .')= '."*".$alfa.')'.'/'. $d . '  Hasilnya Adalah =   '. (($tijawal*$alfa) * ($this->getProbabilitas1() * $alfa)) / $d  ;    
             $beban1[]= (($tijawal*$alfa) * ($this->getProbabilitas1() * $alfa)) / $d ;

            $hasilbeban = (($tijawal*$alfa) * ($this->getProbabilitas1() * $alfa)) / $d ;

            $temp = 0;
             $penjumlahan[] = $this->getProbabilitas1();

             echo '<pre>'.print_r(array_keys($penjumlahan))."</pre>";

             $simpankunciarray= array_keys($penjumlahan );

             $hasilbeban= array_sum($penjumlahan);

         $idx=0;    



         if ( $hasilbeban  > $next)
                 {
                     $hasil= $hasilbeban - $next;
                     $save=$hasil;
                 }
               else
                 {
                         $hasil = $next - $hasilbeban;
                         $save= $hasil;
                 }  
                 if ($temp == 0 )
                 { 
                     $temp= $save;
                     $cekindex[]=$save;

                 }
                 else if ($temp >= $save)
                 {
                     $temp= $save;
                         $cekindex[]=$save;
                 }

                 else if ($temp <= $save)
                 {
                     $temp=$save;
                 }


            }

           $next=array();
           $a[$value] = $array; 
           $b[$value] = $array2;
           $x[$value] = $beban;

           $next[$save]= $temp;

       echo "<pre>Kota Selanjutnya ".print_r($next,true)."</pre>";


        }
     echo "<pre>".print_r($x,true)."</pre>";

}

        public function addProbabilitas1 ($berangkat , $tujuankota)
        {


            $berangkat = urlencode($berangkat);
            $tujuankota = urlencode($tujuankota);

            $data = file_get_contents("http://ift.tt/1lIGnM7");
            $data = json_decode($data);

     //       echo "<pre>". print_r($data ,true) ."</pre>";

            //$waktu = 0;
            $jarak = 0;

            foreach ($data->rows[0]->elements as $road) {
                $jarak += $road->distance->text;



               if ($jarak != 0 )
                {
                   {
                    $jarak = 1 /  $jarak  ;
                    echo $jarak;
                   } 
                        if($jarak == 1)
                        {
                        echo $jarak = 0;
                        } 
                }
                else
                {
                 echo $jarak=0;
                }

            }





            $a[] = $this->simpanprobabilitas1 = $jarak;

          // return $a;


        }

         public function getProbabilitas1() {


        return $this->simpanprobabilitas1;

         }

last sorry for very bad english .




Aucun commentaire:

Enregistrer un commentaire