Created
July 15, 2013 13:05
-
-
Save Ryokuchaneko/5999777 to your computer and use it in GitHub Desktop.
ランダムサーチによる最小コストの旅程を求める関数。コスト関数を入れ替えれば旅程以外の問題でも最小、最大をランダムサーチによって求めることができる。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function randomoptimize($domain, $origin, $people, $flights, $destination) { | |
$best = 999999999; | |
$bestr = 'null'; | |
for($i = 0; $i < 10000; $i++) { | |
$r = array(); | |
for($s = 0; $s < count($domain); $s++) { | |
$r[] = rand($domain[$s][0], $domain[$s][1]); | |
} | |
$cost = schedulecost($r, $origin, $people, $flights, $destination); | |
if ($cost < $best) { | |
$best = $cost; | |
$bestr = $r; | |
} | |
} | |
return $bestr; | |
} | |
$domain = array(); | |
for ($i = 0; $i < count($people)*2; $i++) { | |
$domain[] = array(0, 9); | |
} | |
$result = randomoptimize($domain, $origin, $people, $flights, $destination); | |
$schedule = printschedule($result, $people, $flights, $destination); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment