Make the scheduler config check for available timeslots

Make the scheduler actually insert the timeslot/project/team data into the database
This commit is contained in:
james 2006-01-26 23:06:47 +00:00
parent 7b5d56ce60
commit eaa1444082
2 changed files with 98 additions and 37 deletions

View File

@ -66,11 +66,11 @@ function pick_random_move(&$team)
}
/* The cost function is:
+ 20 * each judge below the min for each team
+ 50 * each judge below the min for each team
+ 10 * each judge above the max for each team
+ 2 * each level of preference away from the
max level for each judge
+ 50 if the team doesn't have a chair.
+ 40 if the team doesn't have a chair.
+ 25 for each memember on the team that can't speak the language
of the judging team
@ -96,7 +96,7 @@ function compute_team_cost(&$teams, &$judges, $team_id)
$c = count($t['judges']);
$min = ($c < $t['min']) ? $t['min'] - $c : 0;
$max = ($c > $t['max']) ? $c - $t['max'] : 0;
$cost += $min * 20;
$cost += $min * 50;
$cost += $max * 10;
// TRACE("Under min=$min, over max=$max\n");
@ -128,7 +128,7 @@ function compute_team_cost(&$teams, &$judges, $team_id)
}
/* Huge penalty for a team without a willing chair */
if(!$have_chair) {
$cost += 50;
$cost += 40;
}
TRACE("Team $team_id, cost is $cost\n");
@ -271,7 +271,7 @@ function judges_assign_anneal($divisions, $categories, $languages, $judges, &$te
/* Anneal */
$temperature = 25.0;
while(1) {
$moves = 500;
$moves = 750;
for($m = 0; $m<$moves; $m++) {
/* Pick 2 moves at random */
$move = pick_random_move($team);
@ -523,29 +523,6 @@ echo "<a href=\"judges_teams_members.php\">".i18n("Manage Judge Members")."</a>"
echo "<br />";
echo "<br />";
print("Project Timeslots:<br>\n");
print("<table border=1><tr><td>Project ID</td>");
for($x=0;$x<$max_ts;$x++) {
print("<td>Slot ".($x + 1)."</td>");
}
print("</tr>");
while(list($proj_id, $projinfo) = each( $data['projects'] )) {
print("<tr><td>$proj_id</td>");
$last_slot = 1;
while(list($slot,$jteam) = each ($projinfo['timetable']) ) {
while($last_slot != $slot) {
print("<td>&nbsp;</td>");
$last_slot++;
}
print("<td>".($jteam+1)."</td>");
$last_slot++;
}
print("</tr>");
}
print("</table>");
$totalcost=0;
while(list($tn, $t) = each($team)) {
//team numbers start with 0 in the annealer, but we want them to start at 1, so just tn++ here.
@ -559,8 +536,10 @@ while(list($tn, $t) = each($team)) {
if(!$teamnums[$t['division']][$t['category']]) $teamnums[$t['division']][$t['category']]=1;
else $teamnums[$t['division']][$t['category']]++;
mysql_query("INSERT INTO judges_teams (num,name,autocreate_type_id,year) VALUES ('$tn','(Divisional) {$div[$t['division']]} - {$cat[$t['category']]} #{$teamnums[$t['division']][$t['category']]}','1','{$config['FAIRYEAR']}')");
mysql_query("INSERT INTO judges_teams (num,name,autocreate_type_id,year) VALUES ('$tn','(Divisional) {$div[$t['division']]} - {$cat[$t['category']]} #{$teamnums[$t['division']][$t['category']]} ({$t['language']})','1','{$config['FAIRYEAR']}')");
$team_id=mysql_insert_id();
//use tn-1 since we incremented it at the top :p
$team[$tn-1]['team_id']=$team_id;
while(list($key, $j) = each($t['judges']) ) {
$judge = $judges[$j];
@ -599,6 +578,61 @@ while(list($tn, $t) = each($team)) {
}
}
$available_timeslots=array();
$q=mysql_query("SELECT * FROM judges_timeslots WHERE year='".$config['FAIRYEAR']."' AND allowdivisional='yes' ORDER BY date,starttime");
while($r=mysql_Fetch_object($q))
{
$available_timeslots[]=array("id"=>$r->id,"date"=>$r->date,"starttime"=>substr($r->starttime,0,-3),"endtime"=>substr($r->endtime,0,-3));
}
print("Project Timeslots:<br>\n");
print("<table border=1><tr><td>Project ID</td>");
//FIXME:! max_ts is sometimes bigger than it should be (by 1 or 2)! whats going on??
for($x=0;$x<=$max_ts;$x++) {
print("<td>".$available_timeslots[$x]['starttime']."-".$available_timeslots[$x]['endtime']."</td>");
}
print("</tr>");
while(list($proj_id, $projinfo) = each( $data['projects'] )) {
print("<tr><td>$proj_id</td>");
$last_slot = 1;
while(list($slot,$jteam) = each ($projinfo['timetable']) ) {
while($last_slot != $slot) {
print("<td>&nbsp;</td>");
$last_slot++;
}
print("<td>".($jteam+1));
echo "<br />";
echo "tema_id=".$team[$jteam]['team_id'];
echo "<br />";
echo "proj_id=".$proj_id;
echo "<br />";
echo "ts_id=".$available_timeslots[$slot-1]['id'];
echo "<br />";
echo "</td>";
$last_slot++;
//add the link of the judge team to the timeslot
mysql_query("INSERT INTO judges_teams_timeslots_link (judges_teams_id,judges_timeslots_id,year) VALUES (
'".$team[$jteam]['team_id']."',
'".$available_timeslots[$slot-1]['id']."',
'".$config['FAIRYEAR']."')");
//now add the link of hte project to this judge team & timeslot
mysql_query("INSERT INTO judges_teams_timeslots_projects_link (judges_teams_id,judges_timeslots_id,projects_id,year) VALUES (
'".$team[$jteam]['team_id']."',
'".$available_timeslots[$slot-1]['id']."',
'".$proj_id."',
'".$config['FAIRYEAR']."')");
}
print("</tr>");
}
print("</table>");
echo "<br />";
echo "<br />";
echo "<b>Total 'cost' for all teams: $totalcost</b>";

View File

@ -92,14 +92,20 @@ while($catr=mysql_fetch_object($catq))
$divq=mysql_query("SELECT * FROM projectdivisions WHERE year='{$config['FAIRYEAR']}' ORDER BY id");
while($divr=mysql_fetch_object($divq))
{
$numq=mysql_query("SELECT COUNT(id) AS num FROM projects WHERE projectcategories_id='$catr->id' AND projectdivisions_id='$divr->id' AND year='{$config['FAIRYEAR']}'");
$numr=mysql_fetch_object($numq);
echo "<tr><td>".i18n($divr->division)."</td>";
echo "<td align=\"center\">$numr->num</td>";
$numteams=ceil($numr->num/$schedulerconfig['max_projects_per_team']*$schedulerconfig['num_times_judged']);
echo "<td align=\"center\">$numteams</td>";
$totalteams+=$numteams;
echo "</tr>";
$langq=mysql_query("SELECT * FROM languages WHERE active='Y'");
while($langr=mysql_fetch_object($langq))
{
$numq=mysql_query("SELECT COUNT(id) AS num FROM projects WHERE projectcategories_id='$catr->id' AND projectdivisions_id='$divr->id' AND year='{$config['FAIRYEAR']}' AND language='$langr->lang'");
$numr=mysql_fetch_object($numq);
echo "<tr><td>".i18n($divr->division)." ($langr->lang)</td>";
echo "<td align=\"center\">$numr->num</td>";
$numteams=ceil($numr->num/$schedulerconfig['max_projects_per_team']*$schedulerconfig['num_times_judged']);
if($numteams<$schedulerconfig['num_times_judged']) $numteams=$schedulerconfig['num_times_judged'];
echo "<td align=\"center\">$numteams</td>";
$totalteams+=$numteams;
echo "</tr>";
}
}
echo "</table>";
echo "<br />";
@ -203,10 +209,31 @@ if($notfoundawards)
if($foundawards)
echo happy(i18n("Found awards for: %1",array($foundawards)));
if($foundteams)
{
echo error(i18n("Found judging teams that are currently assigned to divisional awards: %1. These teams must be removed first",array($foundteams)));
echo "&nbsp;&nbsp;<a href=\"judges_teams.php\">".i18n("Judging Teams Manager")."</a>";
}
else
echo happy(i18n("No judging teams are assigned to divisional awards (good!)"));
//now check if we have enough timeslots available...
$q=mysql_query("SELECT COUNT(id) AS num FROM judges_timeslots WHERE year='".$config['FAIRYEAR']."' AND allowdivisional='yes'");
$r=mysql_fetch_object($q);
$numslots=$r->num;
if($numslots<$schedulerconfig['max_projects_per_team'])
{
echo error(i18n("You do not have enough judging timeslots available for divisional judging. Please create more timeslots first. Available: %1, Required: %2",array($numslots,$schedulerconfig['max_projects_per_team'])));
echo "&nbsp;&nbsp;<a href=\"judges_timeslots.php\">".i18n("Timeslot Manager")."</a>";
$ok=false;
}
else
{
echo happy(i18n("You have sufficient timeslots available. Available: %1, Required: %2",array($numslots,$schedulerconfig['max_projects_per_team'])));
}
//asdf
if($ok)
{
echo i18n("Everything looks in order, we're ready to create the divisional awards judging teams. Click 'Create Divisional Awards Judging Teams' below to start the scheduler. Please be patient as it may take 20-30 seconds to find an optimal solution to the judging team assignments");