Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Ryokuchaneko/5993210 to your computer and use it in GitHub Desktop.
Save Ryokuchaneko/5993210 to your computer and use it in GitHub Desktop.
コスト関数の定義。運賃総額と空港での待ち時間、レンタカーの追加料金を含めたコストを旅程ごとに算出する関数を定義する。
function schedulecost($sol, $origin, $people, $flights, $destination) {
$totalprice = 0;
$latestarrival = 0;
$earliestdep = 24*60;
$d = count($sol)/2;
for ($i = 0; $i < $d; $i++) {
$origin = $people[$i][1];
$outbound = $flights[$origin][$destination][$sol[$i*2]];
$returnf = $flights[$destination][$origin][$sol[$i*2+1]];
$totalprice += $outbound[2];
$totalprice += $returnf[2];
if ($latestarrival < getminutes($outbound[1])) {
$latestarrival = getminutes($outbound[1]);
}
if ($earliestdep > getminutes($returnf[0])) {
$earliestdep = getminutes($returnf[0]);
}
}
$totalwait = 0;
for ($i = 0; $i < $d; $i++) {
$origin = $people[$i][1];
$outbound = $flights[$origin][$destination][$sol[$i*2]];
$returnf = $flights[$destination][$origin][$sol[$i*2+1]];
$totalwait += $latestarrival - getminutes($outbound[1]);
$totalwait += getminutes($returnf[0]) - $earliestdep;
}
if ($latestarrival < $earliestdep) {
$totalprice += 50;
}
return $totalprice + $totalwait;
}
$totalcost = schedulecost($s, $origin, $people, $flights, $destination);
var_dump($totalcost);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment