forked from science-ation/science-ation
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:
parent
03acd9d8fc
commit
dcefe6cdad
@ -197,10 +197,10 @@ class annealer {
|
|||||||
$last_cost = 0;
|
$last_cost = 0;
|
||||||
$last_cost_count = 0;
|
$last_cost_count = 0;
|
||||||
|
|
||||||
// if($this->num_buckets <= 1) {
|
if($this->num_buckets <= 1) {
|
||||||
// TRACE("Only one Bucket, nothing to anneal.\n");
|
TRACE("Only one Bucket, nothing to anneal.\n");
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
// $this->print_buckets();
|
// $this->print_buckets();
|
||||||
while(1) {
|
while(1) {
|
||||||
$moves = $this->start_moves;
|
$moves = $this->start_moves;
|
||||||
|
@ -588,53 +588,13 @@ while($r=mysql_fetch_object($q)) {
|
|||||||
$n_timeslots = count($available_timeslots);
|
$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
|
/* 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
|
* more times in a row, OR, if it has large gaps that aren't
|
||||||
at the end of the judging */
|
at the end of the judging */
|
||||||
|
/* I'm going to leave this here, for now, we shoudl do something like
|
||||||
for($x=0; $x<count($project_index); $x++) {
|
* 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_start = $x * $n_timeslots;
|
||||||
$i_end = ($x+1) * $n_timeslots;
|
$i_end = ($x+1) * $n_timeslots;
|
||||||
|
|
||||||
@ -646,43 +606,56 @@ function timeslot_cost_function($annealer, $bucket_id, $ids)
|
|||||||
if($jteam_id == 0) {
|
if($jteam_id == 0) {
|
||||||
$z_count++;
|
$z_count++;
|
||||||
$r_count=0;
|
$r_count=0;
|
||||||
} else {
|
} else {*/
|
||||||
/* Do the z_count cost here so we don;t
|
/* Do the z_count cost here so we don;t
|
||||||
* count any zcount cost for the end
|
* count any zcount cost for the end
|
||||||
* of the timetable */
|
* of the timetable */
|
||||||
if($z_count > 2) $cost += $z_count;
|
/* if($z_count > 2) $cost += $z_count;
|
||||||
$r_count++;
|
$r_count++;
|
||||||
$z_count=0;
|
$z_count=0;
|
||||||
if($r_count > 2) $cost += $r_count;
|
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
|
/* Check to make sure a judge isn't judging two projects
|
||||||
* at the same time */
|
* at the same time */
|
||||||
$n_pids = count($project_index);
|
$n_pids = count($ids);
|
||||||
for($offset = 0; $offset < $n_timeslots; $offset++) {
|
for($x=0; $x<$n_pids-1; $x++) {
|
||||||
for($x=0; $x<$n_pids-1; $x++) {
|
$jteam_id1 = $ids[$x];
|
||||||
$o1 = $x * ($n_timeslots) + $offset;
|
if($jteam_id1 == 0) continue;
|
||||||
$jteam_id1 = $ids[$o1];
|
for($y=$x+1; $y<$n_pids; $y++) {
|
||||||
if($jteam_id1 == 0) continue;
|
$jteam_id2 = $ids[$y];
|
||||||
for($y=$x+1; $y<$n_pids; $y++) {
|
if($jteam_id1 == $jteam_id2)
|
||||||
$o2 = $y * ($n_timeslots) + $offset;
|
$cost += 50;
|
||||||
$jteam_id2 = $ids[$o2];
|
|
||||||
if($jteam_id1 == $jteam_id2)
|
|
||||||
$cost += 50;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $cost;
|
return $cost;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$keys = array_keys($jdiv);
|
$keys = array_keys($jdiv);
|
||||||
for($k=0; $k<count($keys); $k++) {
|
for($k=0; $k<count($keys); $k++) {
|
||||||
$jdiv_id = $keys[$k];
|
$jdiv_id = $keys[$k];
|
||||||
$pids = array_keys($jdiv[$jdiv_id]['projects']);
|
$pids = array_keys($jdiv[$jdiv_id]['projects']);
|
||||||
|
$n_projects = count($n_pids);
|
||||||
|
|
||||||
unset($project_rlookup);
|
unset($project_rlookup);
|
||||||
$project_rlookup = array();
|
$project_rlookup = array();
|
||||||
@ -691,28 +664,24 @@ for($k=0; $k<count($keys); $k++) {
|
|||||||
$project_rlookup[$pids[$x]] = $x;
|
$project_rlookup[$pids[$x]] = $x;
|
||||||
}
|
}
|
||||||
|
|
||||||
$project_index = $pids;
|
|
||||||
|
|
||||||
$current_jdiv = $jdiv_id;
|
$current_jdiv = $jdiv_id;
|
||||||
|
|
||||||
printf(count($pids). " projects in this jdiv\n");
|
printf(count($pids). " projects in this jdiv\n");
|
||||||
unset($jteams_ids);
|
unset($jteams_ids);
|
||||||
$jteams_ids = array();
|
$jteams_ids = array();
|
||||||
|
/* Pad to the correct length */
|
||||||
for($x=0; $x<($n_timeslots * count($pids)); $x++)
|
for($x=0; $x<($n_timeslots * count($pids)); $x++)
|
||||||
$jteams_ids[] = 0;
|
$jteams_ids[] = 0;
|
||||||
|
|
||||||
/* Fill out the jteam array with a jteam_id for each time the
|
/* 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
|
* jteam_id is supposed to judge a project */
|
||||||
* to a length of num_project * n_timeslots */
|
|
||||||
$jteams = $jdiv[$jdiv_id]['jteams'];
|
$jteams = $jdiv[$jdiv_id]['jteams'];
|
||||||
foreach($jteams as $jteam_id) {
|
foreach($jteams as $jteam_id) {
|
||||||
$p = $jteam[$jteam_id]['projects'];
|
|
||||||
for($y=0;$y<count($jteam[$jteam_id]['projects']); $y++) {
|
for($y=0;$y<count($jteam[$jteam_id]['projects']); $y++) {
|
||||||
$pid = $jteam[$jteam_id]['projects'][$y];
|
$pid = $jteam[$jteam_id]['projects'][$y];
|
||||||
$idx = $project_rlookup[$pid];
|
$idx = $project_rlookup[$pid];
|
||||||
|
|
||||||
$o = $n_timeslots * $idx;
|
for($o = $idx; ; $o+= $n_projects) {
|
||||||
for($o = $n_timeslots * $idx; ; $o++) {
|
|
||||||
if($jteams_ids[$o] != 0) continue;
|
if($jteams_ids[$o] != 0) continue;
|
||||||
|
|
||||||
$jteams_ids[$o] = $jteam_id;
|
$jteams_ids[$o] = $jteam_id;
|
||||||
@ -725,7 +694,7 @@ for($k=0; $k<count($keys); $k++) {
|
|||||||
print("\n");
|
print("\n");
|
||||||
|
|
||||||
$e = 500 + 50 * ($data['effort'] / 1000);
|
$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->set_pick_move(timeslot_pick_move);
|
||||||
$a->anneal();
|
$a->anneal();
|
||||||
|
|
||||||
@ -734,8 +703,7 @@ for($k=0; $k<count($keys); $k++) {
|
|||||||
TRACE("Project $pid: ");
|
TRACE("Project $pid: ");
|
||||||
|
|
||||||
for($y=0;$y<$n_timeslots; $y++) {
|
for($y=0;$y<$n_timeslots; $y++) {
|
||||||
$idx = ($x * $n_timeslots) + $y;
|
$jteam_id = $a->bucket[$y][$x];
|
||||||
$jteam_id = $a->bucket[0][$idx];
|
|
||||||
TRACE(($y+1).":$jteam_id ");
|
TRACE(($y+1).":$jteam_id ");
|
||||||
|
|
||||||
if($jteam_id == 0) continue;
|
if($jteam_id == 0) continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user