Replaced the timeslot scheduler. This one is much faster, but it doens't actually compute cost for the number of judges the student has in a row. But, because it's totally random in layout multiple judges in a row should happen very infrequently.

This commit is contained in:
dave 2006-08-08 06:51:07 +00:00
parent 03acd9d8fc
commit dcefe6cdad
2 changed files with 41 additions and 73 deletions

View File

@ -197,10 +197,10 @@ class annealer {
$last_cost = 0;
$last_cost_count = 0;
// if($this->num_buckets <= 1) {
// TRACE("Only one Bucket, nothing to anneal.\n");
// return;
// }
if($this->num_buckets <= 1) {
TRACE("Only one Bucket, nothing to anneal.\n");
return;
}
// $this->print_buckets();
while(1) {
$moves = $this->start_moves;

View File

@ -588,53 +588,13 @@ while($r=mysql_fetch_object($q)) {
$n_timeslots = count($available_timeslots);
$project_index = array();
function timeslot_pick_move($a)
{
global $n_timeslots;
/* Bucket id always 0 */
$b1 = 0;
$i1 = rand(0, count($a->bucket[0]) - 1);
/* Find the start and end of this project timeslots */
$i_s = floor($i1 / $n_timeslots) * $n_timeslots;
$i_e = $i_s + $n_timeslots - 1;
/* THe second number must be between $i_s and $i_e */
$b2 = 0;
while(1) {
$i2 = rand($i_s, $i_e);
if($i2 != $i1) break;
}
// TRACE("Move=($b1, $i1, $b2, $i2)\n");
return array($b1, $i1, $b2, $i2);
}
/* Computes the cost of everything, since we slice the data two
* ways we can't really use delta costs
* In this, the bucket_id will always be 1, because we don't
* actually use buckets */
function timeslot_cost_function($annealer, $bucket_id, $ids)
{
global $project_index;
global $jteam;
global $n_timeslots;
$cost = 0;
// print("Count $ids=".count($ids));
/* The pick_move function ensures that projects can't
* move out of a jteam so we dont' need to check that */
/* First, check to see if the project is being judged 3 or
* more times in a row, OR, if it has large gaps that aren't
at the end of the judging */
for($x=0; $x<count($project_index); $x++) {
/* I'm going to leave this here, for now, we shoudl do something like
* this at some point in evaluating projects, but right now
* the randomness is pretty good. */
/* for($x=0; $x<count($project_index); $x++) {
$i_start = $x * $n_timeslots;
$i_end = ($x+1) * $n_timeslots;
@ -646,43 +606,56 @@ function timeslot_cost_function($annealer, $bucket_id, $ids)
if($jteam_id == 0) {
$z_count++;
$r_count=0;
} else {
} else {*/
/* Do the z_count cost here so we don;t
* count any zcount cost for the end
* of the timetable */
if($z_count > 2) $cost += $z_count;
/* if($z_count > 2) $cost += $z_count;
$r_count++;
$z_count=0;
if($r_count > 2) $cost += $r_count;
}
}
}
*/
function timeslot_pick_move($a)
{
/* Use the existing pick move, but we want the item numbers
* in each bucket to always be the same */
list($b1, $i1, $b2, $i2) = $a->pick_move();
$i2 = $i1;
return array($b1, $i1, $b2, $i2);
}
function timeslot_cost_function($annealer, $bucket_id, $ids)
{
$cost = 0;
/* Check to make sure a judge isn't judging two projects
* at the same time */
$n_pids = count($project_index);
for($offset = 0; $offset < $n_timeslots; $offset++) {
for($x=0; $x<$n_pids-1; $x++) {
$o1 = $x * ($n_timeslots) + $offset;
$jteam_id1 = $ids[$o1];
if($jteam_id1 == 0) continue;
for($y=$x+1; $y<$n_pids; $y++) {
$o2 = $y * ($n_timeslots) + $offset;
$jteam_id2 = $ids[$o2];
if($jteam_id1 == $jteam_id2)
$cost += 50;
}
$n_pids = count($ids);
for($x=0; $x<$n_pids-1; $x++) {
$jteam_id1 = $ids[$x];
if($jteam_id1 == 0) continue;
for($y=$x+1; $y<$n_pids; $y++) {
$jteam_id2 = $ids[$y];
if($jteam_id1 == $jteam_id2)
$cost += 50;
}
}
return $cost;
}
$keys = array_keys($jdiv);
for($k=0; $k<count($keys); $k++) {
$jdiv_id = $keys[$k];
$pids = array_keys($jdiv[$jdiv_id]['projects']);
$n_projects = count($n_pids);
unset($project_rlookup);
$project_rlookup = array();
@ -691,28 +664,24 @@ for($k=0; $k<count($keys); $k++) {
$project_rlookup[$pids[$x]] = $x;
}
$project_index = $pids;
$current_jdiv = $jdiv_id;
printf(count($pids). " projects in this jdiv\n");
unset($jteams_ids);
$jteams_ids = array();
/* Pad to the correct length */
for($x=0; $x<($n_timeslots * count($pids)); $x++)
$jteams_ids[] = 0;
/* Fill out the jteam array with a jteam_id for each time the
* jteam_id is supposed to judge a project, then pad with 0 up
* to a length of num_project * n_timeslots */
* jteam_id is supposed to judge a project */
$jteams = $jdiv[$jdiv_id]['jteams'];
foreach($jteams as $jteam_id) {
$p = $jteam[$jteam_id]['projects'];
for($y=0;$y<count($jteam[$jteam_id]['projects']); $y++) {
$pid = $jteam[$jteam_id]['projects'][$y];
$idx = $project_rlookup[$pid];
$o = $n_timeslots * $idx;
for($o = $n_timeslots * $idx; ; $o++) {
for($o = $idx; ; $o+= $n_projects) {
if($jteams_ids[$o] != 0) continue;
$jteams_ids[$o] = $jteam_id;
@ -725,7 +694,7 @@ for($k=0; $k<count($keys); $k++) {
print("\n");
$e = 500 + 50 * ($data['effort'] / 1000);
$a = new annealer(1, 100, $e, 0.98, timeslot_cost_function, $jteams_ids);
$a = new annealer($n_timeslots, 100, $e, 0.98, timeslot_cost_function, $jteams_ids);
$a->set_pick_move(timeslot_pick_move);
$a->anneal();
@ -734,8 +703,7 @@ for($k=0; $k<count($keys); $k++) {
TRACE("Project $pid: ");
for($y=0;$y<$n_timeslots; $y++) {
$idx = ($x * $n_timeslots) + $y;
$jteam_id = $a->bucket[0][$idx];
$jteam_id = $a->bucket[$y][$x];
TRACE(($y+1).":$jteam_id ");
if($jteam_id == 0) continue;