function annealingoptimize($domain, $origin, $people, $flights, $destination, $T=10000.0, $cool=0.95, $step=1) {
    $vec = array();
     for($s = 0; $s < count($domain); $s++) {
        $vec[] = rand($domain[$s][0], $domain[$s][1]);
    }

    while ( $T > 0.1 ) {
        $i = rand(0, (count($domain) - 1) );
        $dir = rand( -$step, $step);
        $vecb = $vec;
        $vecb[$i] += $dir;
        if($vecb[$i] < $domain[$i][0]){
            $vecb[$i] = $domain[$i][0];
        } elseif ($vecb[$i] > $domain[$i][1]) {
            $vecb[$i] = $domain[$i][1];
        }

        $ea = schedulecost($vec, $origin, $people, $flights, $destination);
        $eb = schedulecost($vecb, $origin, $people, $flights, $destination);
        $p =  exp(-abs($eb-$ea)/$T);
        $rand = rand(1,10000)/10000;
        if (($eb < $ea) || ($rand < $p)) {
            var_dump('A');
            $vec = $vecb;
        }
         $T = $T*$cool;
    }
    return $vec;
}

$result = annealingoptimize($domain, $origin, $people, $flights, $destination, $T=10000.0, $cool=0.95, $step=1);
var_dump($result);
$cost = schedulecost($result, $origin, $people, $flights, $destination);
var_dump($cost);
$schedule = printschedule($result, $people, $flights, $destination);