include '../functions.inc.php';
include('../mysql-pdo.inc.php');
if(!isset($_GET['format']))
{
$_GET['format'] = 'html';
}
$title = "Results";
$scoreFunction = "avg(dUtilA)";
//$scoreFunction = "avg((dUtilA+dUtilB)/2)";
if(isset($_GET['v']) && $_GET['v'] == "qualifying")
{
$title = "Qualifying ".$title;
$table = "nego_results_qualifying";
}
if(isset($_GET['v']) && $_GET['v'] == "final")
{
$title = "Final ".$title;
$table = "nego_results_final";
$excludeSelfPlay = true;
$where = array();
if(isset($_GET['df']))
{
$where[] = "d.df IN (".preg_replace("/[^0-9.,]/", "", $_GET['df']).")";
}
if(isset($_GET['rv']))
{
$where[] = "d.rv IN (".preg_replace("/[^0-9.,]/", "", $_GET['rv']).")";
}
$where = implode(" AND ", $where);
if($where != "")
{
$table = "(SELECT r.* FROM $table r JOIN domain d ON r.domain = d.code WHERE $where) AS rt";
}
}
if(isset($_GET['v']) && $_GET['v'] == "test")
{
$title = "Test ".$title;
$table = "nego_results";
}
if(isset($_GET['v']) && $_GET['v'] == "extended")
{
$title = "Extended ".$title;
$table = "nego_results_extended";
}
if(isset($_GET['v']) && $_GET['v'] == "risk")
{
$excludeSelfPlay = true;
$title = "Risk ".$title;
$where = array();
$where[] = "agentA != 'agents2012.southampton.IAMhaggler2012'";
$where[] = "agentB != 'agents2012.southampton.IAMhaggler2012'";
$where[] = "agentA NOT LIKE 'agents2012.southampton.IAMcrazyHaggler2012%'";
$where[] = "agentB NOT LIKE 'agents2012.southampton.IAMcrazyHaggler2012%'";
if(isset($_GET['df']))
{
$where[] = "d.df IN (".preg_replace("/[^0-9.,]/", "", $_GET['df']).")";
}
if(isset($_GET['rv']))
{
$where[] = "d.rv IN (".preg_replace("/[^0-9.,]/", "", $_GET['rv']).")";
}
$where = implode(" AND ", $where);
$table = "nego_results_risk";
$table = "(SELECT r.* FROM $table r JOIN domain d ON r.domain = d.code WHERE $where) AS rt";
}
if(isset($_GET['v']) && $_GET['v'] == "thesis")
{
// $scoreFunction = "sum((lastAction = '(EndNegotiation)') AND (time < (179/180)) AND (bids % 2 = n)) / count(*) * 100";
$title = "Thesis ".$title;
$excludeSelfPlay = true;
$table = getTable();
}
if(isset($_GET['v']) && substr($_GET['v'], 0, 5) == "spite")
{
$title = "Spite ".$title;
$excludeSelfPlay = true;
$where = array();
$where[] = "(agentA NOT LIKE 'agents2012.southampton.IAMhaggler2012a%' OR agentA = 'agents2012.southampton.IAMhaggler2012a".$_GET['v'][5]."')";
$where[] = "(agentB NOT LIKE 'agents2012.southampton.IAMhaggler2012a%' OR agentB = 'agents2012.southampton.IAMhaggler2012a".$_GET['v'][5]."')";
$where = implode(" AND ", $where);
$table = "nego_results_spite";
$table = "(SELECT r.* FROM $table r WHERE $where) AS rt";
echo $table;
}
$domain = null;
$agentA = null;
$agentB = null;
if(isset($_GET['domain']) && $_GET['domain'] != '*')
{
$domain = $_GET['domain'];
}
if(isset($_GET['agentA']))
{
$agentA = $_GET['agentA'];
}
if(isset($_GET['agentB']))
{
$agentB = $_GET['agentB'];
}
if(isset($_GET['batchID']))
{
$batchID = $_GET['batchID'];
}
if(!is_null($domain)) {
if(!is_null($agentA)) {
if(!is_null($agentB)) {
$title .= " | " . renderAgent($agentA, false) . " vs " . renderAgent($agentB, false) . " in " . renderDomain($domain) . " Domain";
} else {
$title .= " | " . renderAgent($agentA, false) . " in domain " . renderDomain($domain);
}
} else {
$title .= " | " . renderDomain($domain) . " Domain";
}
} else {
if(!is_null($agentA)) {
if(!is_null($agentB)) {
$title .= " | " . renderAgent($agentA, false) . " vs " . renderAgent($agentB, false);
} else {
$title .= " | " . renderAgent($agentA, false);
}
} else {
}
}
if($_GET['format'] != 'tex')
{
outputHeader($title, "", "GENERIC");
}
$batchID = 'substring(id, 5, 2)';
$cols = $scoreFunction.' as Agent_Score, avg(dUtilB) as _Opponent_Score, count(*) as _Count';
//$cols = 'avg((dUtilA+dUtilB)/2) as Agent_Score, avg(dUtilB) as _Opponent_Score, count(*) as _Count';
function getTable()
{
$table = "nego_results_thesis";
$where = array();
$where[] = "agentA NOT LIKE 'agents2012.southampton.IAMcrazyHaggler2012%'";
$where[] = "agentB NOT LIKE 'agents2012.southampton.IAMcrazyHaggler2012%'";
if(isset($_GET['df']))
{
switch($_GET['df'])
{
case "0.50":
$where[] = "SUBSTR(domain, 1, 1) IN ('3', '6', '9')";
break;
case "0.75":
$where[] = "SUBSTR(domain, 1, 1) IN ('2', '5', '8')";
break;
case "1.00":
$where[] = "SUBSTR(domain, 1, 1) IN ('1', '4', '7')";
break;
}
}
if(isset($_GET['rv']))
{
switch($_GET['rv'])
{
case "0.00":
$where[] = "SUBSTR(domain, 1, 1) IN ('1', '2', '3')";
break;
case "0.25":
$where[] = "SUBSTR(domain, 1, 1) IN ('4', '5', '6')";
break;
case "0.50":
$where[] = "SUBSTR(domain, 1, 1) IN ('7', '8', '9')";
break;
}
}
if(isset($_GET['s']))
{
switch($_GET['s'])
{
case "S":
$where[] = "SUBSTR(domain, 2, 1) IN ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H')";
break;
case "M":
$where[] = "SUBSTR(domain, 2, 1) IN ('I', 'J', 'K', 'L', 'M', 'N', 'O', 'P')";
break;
case "L":
$where[] = "SUBSTR(domain, 2, 1) IN ('Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X')";
break;
}
}
if(isset($_GET['c']))
{
switch($_GET['c'])
{
case "H":
$where[] = "SUBSTR(domain, 2, 1) IN ('A', 'B', 'E', 'F', 'H', 'U', 'V', 'X')";
break;
case "M":
$where[] = "SUBSTR(domain, 2, 1) IN ('D', 'I', 'K', 'L', 'M', 'P', 'Q', 'W')";
break;
case "L":
$where[] = "SUBSTR(domain, 2, 1) IN ('C', 'G', 'J', 'N', 'O', 'R', 'S', 'T')";
break;
}
}
$where[] = "SUBSTR(id, 5, 2) < 3";
$where = implode(" AND ", $where);
//$table = "(SELECT r.* FROM $table r WHERE $where) AS rt";
$table = "(SELECT * FROM $table WHERE $where) AS rt";
return $table;
}
function average($q, $key, $extras='', $join='')
{
return 'SELECT '.$key.', avg(Agent_Score) AS Agent_Mean, var_samp(Agent_Score) AS Agent_Var, avg(_Opponent_Score) AS _Opponent_Mean, var_samp(_Opponent_Score) AS _Opponent_Var, count(_Opponent_Score) AS _Count'.$extras.' FROM ('.$q.') AS x'.$join.' GROUP BY '.$key.' ORDER BY Agent_Mean DESC, Agent_Var ASC';
}
function qualifyingText()
{
echo "
In order to generate these results, we gave each agent an opportunity to negotiate with each opponent (including in self-play) in each domain, and using both profiles. The domains included all those submitted by the participants, plus the Travel domain from ANAC2010, totalling 18 domains. Each negotiation was repeated 10 times, in order to produce statistically significant results. In total, this resulted in 52020 negotiations.
";
echo "To calculate the rank of each agent, we used Welch's t test to check for statistically significant differences between the agents' scores. In more detail, we computed this for each pair of agents, to determine, with 95% confidence, which agents beat a specific agent, and which agents are beaten by that agent. For example, an agent which is beaten by two agents, and beats 12 agents (out of a total of 17) is considered to have rank 3-5. That is, with 95% certainty, its true rank lies between 3 and 5 (inclusive).
";
echo "To select the qualifying agents, we identified all agents which have a possibility of a true rank in the top eight positions. Nine agents matched this criteria. The developers of IAMcrazyHaggler2012 (rank 7-9) chose to withdraw their entry from the final, leaving eight qualifying agents, highlighted in green in the table below.
";
echo "By selecting an agent or domain from the tables below, you can view the results in more detail. By navigating through these tables, you can select an agent, an opponent and a domain in order to view the scores achieved in individual negotiations. By clicking the 'show details' link next to a domain, you can view an illustration of the full outcome space and other domain characteristics. All of the outcomes from the qualifying round are also available to download as a CSV file.
";
echo "In the domain tables, the discounting factors (DF) and reservation values (RV) that were used in the qualifying round are shown. Note that for many of the domains which were not submitted with a discounting factor or reservation value, we have added these parameters.
";
}
function finalText()
{
echo "In order to generate these results, we gave each agent an opportunity to negotiate with each opponent (excluding in self-play) in each domain, and using both profiles. The domains included all 17 that were submitted by the participants this year, plus 5 from ANAC2011 and 2 from ANAC2010. Three variants of each of these 24 domains (with different discounting factors and reservation values) were used, totalling 72 domains. Each negotiation was repeated 10 times, in order to produce statistically significant results. In total, this resulted in 40320 negotiations.
";
echo "To calculate the rank of each agent, we used Welch's t test to check for statistically significant differences between the agents' scores. In more detail, we computed this for each pair of agents, to determine, with 95% confidence, which agents beat a specific agent, and which agents are beaten by that agent. For example, an agent which is beaten by two agents, and beats 12 agents (out of a total of 17) is considered to have rank 3-5. That is, with 95% certainty, its true rank lies between 3 and 5 (inclusive).
";
echo "By selecting an agent or domain from the tables below, you can view the results in more detail. By navigating through these tables, you can select an agent, an opponent and a domain in order to view the scores achieved in individual negotiations. By clicking the 'show details' link next to a domain, you can view an illustration of the full outcome space and other domain characteristics. All of the outcomes from the final round are also available to download as a CSV file (note that this file also includes self-play outcomes, but these are not included in the results reported on this site).
";
echo "In the domain tables, the discounting factors (DF) and reservation values (RV) that were used are shown.
";
}
if(!isset($_GET['v']))
{
echo "Presentation
";
echo "In the ANAC2012 Session of the ACAN2012 Workshop, the competition and its results were presented. The presentation slides are available in .pptx or .pdf format.
";
echo "Awards
";
echo "The following awards were presented:
";
echo "";
echo "Award | Agent | University | Team Members |
";
echo "1st Place | CUHKAgent | The Chinese University of Hong Kong | Jianye Hao, Ho-fung Leung |
";
echo "2nd Place | AgentLG | Bar-Ilan University | Luba Golosman |
";
echo "3rd Place | OMACagent | Maastricht University | Siqi Chen, Gerhard Weiss |
";
echo "3rd Place | TheNegotiator Reloaded | Delft University of Technology | Mark Hendrikx, Alex Dirkzwager |
";
echo "Best in Discounted Domains | CUHKAgent | The Chinese University of Hong Kong | Jianye Hao, Ho-fung Leung |
";
echo "Best in Undiscounted Domains | TheNegotiator Reloaded | Delft University of Technology | Mark Hendrikx, Alex Dirkzwager |
";
echo "Most Social Agent | IAMhaggler2012 | University of Southampton | Colin R. Williams, Valentin Robu, Enrico H. Gerding, Nicholas R. Jennings |
";
echo "
";
echo "Photos
";
echo "";
echo "
";
echo "
";
echo "
";
echo "
";
echo "
";
echo "
";
echo "
Photographer: Tim Baarslag
";
echo "
";
echo "Downloads
";
echo "Domain files and agent code (.zip)
";
echo "Detailed Results
";
echo "See the results of each round in more detail:
";
echo "";
}
else if($_GET['v'] == "qualifying" || $_GET['v'] == "final" || (isInternal() && ($_GET['v'] == "test" || $_GET['v'] == "extended" || $_GET['v'] == "risk" || substr($_GET['v'], 0, 5) == "spite" || $_GET['v'] == "thesis")))
{
if($_GET['format'] != 'tex')
{
echo "";
if(!is_null($domain)) {
if(!is_null($agentA)) {
if(!is_null($agentB)) {
echo "
";
echo "Selected domain: | ".renderDomain($domain)." | Show all domains | ".renderDomainInfoLink($domain)." |
";
echo "Selected agent: | ".renderAgent($agentA)." | |
";
echo "Selected opponent: | ".renderAgent($agentB)." | Show all opponents |
";
echo "
";
output(listAll($domain, $agentA, $agentB, 0), "Profile 1");
output(listAll($domain, $agentA, $agentB, 1), "Profile 2");
} else {
echo "
";
echo "Selected domain: | ".renderDomain($domain)." | Show all domains | ".renderDomainInfoLink($domain)." |
";
echo "Selected agent: | ".renderAgent($agentA)." | Show all agents |
";
echo "
";
output(listByOpponent($agentA, $domain));
}
} else {
echo "
";
echo "Selected domain: | ".renderDomain($domain)." | Show all domains | ".renderDomainInfoLink($domain)." |
";
echo "
";
output(listByAgent($domain));
}
//echo "
";
} else {
if(!is_null($agentA)) {
if(!is_null($agentB)) {
echo "
";
echo "Selected agent: | ".renderAgent($agentA)." | |
";
echo "Selected opponent: | ".renderAgent($agentB)." | Show all opponents |
";
echo "
";
output(listByDomain($agentA, $agentB));
} else {
echo "
";
output(listByOpponent($agentA));
output(listByDomain($agentA));
}
} else {
if($_GET['v'] == 'qualifying') {
qualifyingText();
} else {
finalText();
}
output(listByAgent());
output(listByDomain());
}
}
echo "
";
}
else
{
if(isset($domain) && $domain != '')
{
list($table, $heading) = output(listByAgent($domain));
latexTable('|c||c|r|', 'Scores in the '.renderDomainTex($domain).', with $95\%$ confidence intervals.', 'scores-'.$domain, $table, $heading);
}
elseif(isset($_GET['by']))
{
switch($_GET['by'])
{
case 'df':
$gvals = array(0.50, 0.75, 1.00);
$gheadings = '\delta = ';
$gkey = 'df';
$gname = 'discounting factor';
break;
case 'rv':
$gvals = array(0.0, 0.25, 0.50);
$gheadings = 'u_{\overline{\alpha}} = ';
$gkey = 'rv';
$gname = 'utility of conflict';
break;
case 's':
$gvals = array('S', 'M', 'L');
$gheadings = array('S' => '|O| \leq 200', 'M' => '200 < |O| \leq 3500', 'L' => '3500 < |0|');
$gkey = 's';
$gname = 'size';
break;
case 'c':
$gvals = array('L', 'M', 'H');
$gheadings = array('L' => 'C(O) \leq 0.22', 'M' => '0.22 < C(O) \leq 0.30', 'H' => '0.30 < C(O)');
$gkey = 'c';
$gname = 'competitiveness';
break;
}
list($t, $h) = output(listByAgent());
foreach($t as $row)
{
$agents[] = $row[1];
$s = explode(' ', $row[2], 2);
$scores[$row[1]]['mean'] = array($row[0], str_replace('$', '', $s[0]));
}
$heading = '\multirow{2}{*}{Agent}';
$heading .= ' & \multicolumn{8}{|c|}{Score (Rank)} \\\\'."\n";
$heading .= ' & \multicolumn{2}{|c|}{mean}';
foreach($gvals as $v)
{
$_GET[$gkey] = $v;
$table = getTable();
list($t, $h) = output(listByAgent());
foreach($t as $row)
{
$s = explode(' ', $row[2], 2);
$scores[$row[1]][$v.''] = array($row[0], str_replace('$', '', $s[0]));
}
if(is_array($gheadings))
{
$heading .= ' & \multicolumn{2}{|c|}{$'.$gheadings[$v].'$}';
}
else
{
$heading .= ' & \multicolumn{2}{|c|}{$'.$gheadings.sprintf('%.2f', $v).'$}';
}
}
$heading .= '\\\\'."\n";
foreach($agents as $agent)
{
$row = array();
$row[] = $agent;
array_unshift($gvals, 'mean');
foreach($gvals as $v)
{
if(substr($scores[$agent][$v.''][0], 0, 1) == '1')
{
$row[] = '{\bf '.$scores[$agent][$v.''][1].'}';
$row[] = '{\bf ('.$scores[$agent][$v.''][0].')}';
}
else
{
$row[] = $scores[$agent][$v.''][1];
$row[] = '('.$scores[$agent][$v.''][0].')';
}
}
array_shift($gvals);
$tagg[] = $row;
}
latexTable('|c||cc|cc|cc|cc|', 'Scores and ranks across all scenarios, grouped by '.$gname.', with winning scores marked in bold.', 'scores-by-'.str_replace(' ', '-', $gname), $tagg, $heading, '\small');
}
else
{
list($table, $heading) = output(listByAgent());
latexTable('|c||c|r|', 'Scores across all scenarios, with $95\%$ confidence intervals.', 'scores-all', $table, $heading);
}
}
}
if($_GET['format'] != 'tex')
{
outputFooter();
}
function welchAll($data) {
foreach($data as $a)
{
$above[$a[0]] = 0;
$below[$a[0]] = 0;
}
foreach($data as $a)
{
foreach($data as $b)
{
if(welch($a, $b)) {
$above[$b[0]]++;
$below[$a[0]]++;
}
}
}
return array(count($data), $above, $below);
}
function getT($i)
{
$tvals = array(12.7062047361747, 4.30265272974946, 3.18244630528371, 2.77644510519779, 2.57058183563631, 2.44691185114497, 2.36462425159279, 2.30600413520417, 2.26215716279820, 2.22813885198627, 2.20098516009164, 2.17881282966723, 2.16036865646279, 2.14478668791780, 2.13144954555977, 2.11990529922126, 2.10981557783331, 2.10092204024104, 2.09302405440831, 2.08596344726587, 2.07961384472768, 2.07387306790402, 2.06865761041905, 2.06389856162803, 2.05953855275330, 2.05552943864287, 2.05183051648028, 2.04840714179525, 2.04522964213270, 2.04227245630124, 2.03951344639641, 2.03693334346010, 2.03451529744934, 2.03224450931772, 2.03010792825034, 2.02809400098045, 2.02619246302911, 2.02439416391197, 2.02269092003676, 2.02107539030628, 2.01954097044138, 2.01808170281844, 2.01669219922783, 2.01536757444376, 2.01410338888085, 2.01289559891943, 2.01174051372977, 2.01063475762423, 2.00957523712924, 2.00855911210076, 2.00758377031583, 2.00664680506169, 2.00574599531787, 2.00487928818806, 2.00404478328915, 2.00324071884787, 2.00246545929101, 2.00171748414524, 2.00099537808826, 2.00029782201427, 1.99962358499493, 1.99897151703338, 1.99834054252075, 1.99772965431770, 1.99713790839200, 1.99656441895231, 1.99600835402530, 1.99546893142985, 1.99494541510723, 1.99443711177119, 1.99394336784563, 1.99346356666187, 1.99299712588986, 1.99254349518093, 1.99210215400225, 1.99167260964467, 1.99125439538838, 1.99084706881169, 1.99045021023014, 1.99006342125445, 1.98968632345691, 1.98931855713658, 1.98895978017516, 1.98860966697571, 1.98826790747722, 1.98793420623902, 1.98760828158908, 1.98728986483118, 1.98697869950629, 1.98667454070377, 1.98637715441862, 1.98608631695113, 1.98580181434582, 1.98552344186659, 1.98525100350549, 1.98498431152245, 1.98472318601398, 1.98446745450848, 1.98421695158642, 1.98397151852354);
return $tvals[min($i, 29)];
}
function welch($a, $b)
{
$X[] = $a[1];
$X[] = $b[1];
$var[] = $a[2];
$var[] = $b[2];
$n[] = $a[3];
$n[] = $b[3];
$varon[] = $var[0]/$n[0];
$varon[] = $var[1]/$n[1];
//$tvals = array(6.31375151467504, 2.91998558035373, 2.35336343480182, 2.13184678632665, 2.01504837333302, 1.94318028051530, 1.89457860509001, 1.85954803753090, 1.83311293265624, 1.81246112281168, 1.79588481870404, 1.78228755564932, 1.77093339598687, 1.76131013577489, 1.75305035569257, 1.74588367627625, 1.73960672607507, 1.73406360661754, 1.72913281152137, 1.72471824292079, 1.72074290281188, 1.71714437438024, 1.71387152774705, 1.71088207990943, 1.70814076125190, 1.70561791975927, 1.70328844572213, 1.70113093426593, 1.69912702653350, 1.69726088659396, 1.69551878254586, 1.69388874838371, 1.69236030903035, 1.69092425518686, 1.68957245778027, 1.68829771411681, 1.68709361959626, 1.68595446016672, 1.68487512171124, 1.68385101333563, 1.68287800213271, 1.68195235746754, 1.68107070320248, 1.68022997657216, 1.67942739265235, 1.67866041355688, 1.67792672164181, 1.67722419612432, 1.67655089261690, 1.67590502516311, 1.67528495042490, 1.67468915372601, 1.67411623670311, 1.67356490635215, 1.67303396528989, 1.67252230307558, 1.67202888846089, 1.67155276245484, 1.67109303210392, 1.67064886490453, 1.67021948377377, 1.66980416251198, 1.66940222170677, 1.66901302502399, 1.66863597584755, 1.66827051422767, 1.66791611410736, 1.66757228079659, 1.66723854866866, 1.66691447905590, 1.66659965832847, 1.66629369613152, 1.66599622377140, 1.66570689273403, 1.66542537332249, 1.66515135340464, 1.66488453725822, 1.66462464450659, 1.66437140913649, 1.66412457858962, 1.66388391292254, 1.66364918402906, 1.66342017491887, 1.66319667904888, 1.66297849970190, 1.66276544940906, 1.66255734941286, 1.66235402916680, 1.66215532586967, 1.66196108403010, 1.66177115506171, 1.66158539690322, 1.66140367366493, 1.66122585529662, 1.66105181727731, 1.66088144032486, 1.66071461012305, 1.66055121706575, 1.66039115601696, 1.66023432608549);
if($X[0] == $X[1]) {
return false;
}
$denom = sqrt($varon[0] + $varon[1]);
if($denom == 0) {
return ($X[0] > $X[1]);
}
$t = ($X[0] - $X[1]) / $denom;
$v = pow($varon[0] + $varon[1], 2) / ($varon[0]*$varon[0]/($n[0]-1) + $varon[1]*$varon[1]/($n[1]-1));
return getT(floor($v) - 1) < $t;
}
function output($table, $title="") {
if(count($table) == 0) return;
$keys = array_keys($table[0]);
if(in_array('Agent', $keys, true) && in_array('Agent_Mean', $keys, true) && in_array('Agent_Var', $keys, true) && in_array('_Count', $keys, true))
{
foreach($table as $row)
{
$data[$row[0]] = array($row[0], $row['Agent_Mean'], $row['Agent_Var'], $row['_Count']);
}
list($n, $above, $below) = welchAll($data);
}
if($_GET['format'] != 'tex')
{
echo "";
if($title != "")
{
echo "
$title
";
}
echo "
";
echo "";
if(isset($n)) echo "Rank | ";
foreach($keys as $key)
{
if(is_int($key)) continue;
if($key[0] == '_') continue;
echo "";
if($key == 'DF')
echo "DF";
elseif($key == 'RV')
echo "RV";
elseif($key == 'Agent_Mean')
echo "Mean Score";
elseif($key == 'Agent_Var')
echo "Variance";
//echo "Standard Deviation";
//echo "Standard Error";
else
echo str_replace('_', ' ', $key);
echo " | ";
if($key == "Domain") echo " | ";
}
echo "
";
foreach($table as $row)
{
if(isset($row['Agent']) && qualified($row['Agent']))
{
echo "";
}
else
{
echo "
";
}
if(isset($n)) {
if($above[$row[0]]+1 == $n-$below[$row[0]])
echo "".($above[$row[0]]+1)." | ";
else
echo " ".($above[$row[0]]+1)."-".($n-$below[$row[0]])." | ";
}
foreach($keys as $key)
{
if(is_int($key)) continue;
if($key[0] == '_') continue;
echo "";
echo renderCell($row[$key], $key);
echo " | ";
}
echo "
";
}
echo "
";
echo "
";
}
else
{
if(isset($n)) $heading[] = 'Rank';
foreach($keys as $key)
{
if(is_int($key)) continue;
if($key[0] == '_') continue;
if($key == 'Agent_Var') continue;
if($key == 'Agent_Mean')
{
$heading[] = "Score";
}
else
{
$heading[] = str_replace('_', ' ', $key);
}
}
foreach($table as $row)
{
$mrow = array();
if(isset($n)) {
if($above[$row[0]]+1 == $n-$below[$row[0]])
$mrow[] = ($above[$row[0]]+1);
else
$mrow[] = ($above[$row[0]]+1)."-".($n-$below[$row[0]]);
}
foreach($keys as $key)
{
if(is_int($key)) continue;
if($key[0] == '_') continue;
if($key == 'Agent_Var') continue;
$mrow[] = renderCellTex($row, $key);
}
$mtable[] = $mrow;
}
return array($mtable, $heading);
}
}
function renderCellTex($row, $key, $s=null) {
if(is_null($s)) $s = $row[$key];
if($key == "Agent_Mean")
{
return renderCellTex($row, '', $s).renderCellTex($row, 'Agent_Var');
}
if($key == "Agent_Var")
{
$s = getT($row['_Count'])*sqrt($s)/sqrt($row['_Count']);
}
switch($key) {
case "Domain":
return renderDomain($s);
case "Agent":
case "Opponent":
if($_GET['format'] == "tex")
return str_pad(renderAgent($s, false), 25);
else
return renderAgent($s);
default:
if(is_numeric($s)) {
$s = sprintf('%.3f', round($s, 3));
}
if($key == "Agent_Var")
{
return " {\\scriptsize $\\pm $s$}";
}
else
{
return "$$s$";
}
}
}
function renderCell($s, $key) {
// if($key == "Agent_Var")
// {
// $s = sqrt($s)/sqrt(10);
// }
switch($key) {
case "Domain":
return "".renderDomain($s)."".renderDomainInfoLink($s);
case "Agent":
case "Opponent":
return "".renderAgent($s)."";
default:
if(is_numeric($s)) {
if(round($s) == $s)
return $s;
if($s > 0.01)
return sprintf('%.3f', round($s, 3));
else
return sprintf('%.6f', round($s, 6));
//return "X".sprintf('%.10f', 1.96*sqrt(round($s, 10))/sqrt(10))."X";
}
return $s;
}
}
function renderDomain($s) {
$q = 'SELECT name FROM domain WHERE code = ?';
$d = query($q, array($s));
if(count($d) == 0) return "[$s]";
return $d[0]['name'];
}
function renderDomainTex($s) {
if(strlen($s) == 1)
{
$q = 'SELECT name FROM domain WHERE SUBSTR(code, 2, 1) = ? AND owner IS NULL';
}
else
{
$q = 'SELECT name, df, rv FROM domain WHERE code = ?';
}
$d = query($q, array($s));
if(count($d) == 0) return "[$s]";
if(strlen($s) == 1)
{
return $d[0]['name'].' Scenario (averaged over $\delta \in \{0.50, 0.75, 1.00\}, u_{\overline{\alpha}} \in \{0.00, 0.25, 0.50\}$)';
}
else
{
return $d[0]['name'].' Scenario (with $\delta='.sprintf('%.2f', $d[0]['df']).', u_{\overline{\alpha}}='.sprintf('%.2f', $d[0]['rv']).'$)';
}
}
function renderDomainInfoLink($s, $search='code') {
$q = 'SELECT year, id, link FROM domain WHERE '.$search.' = ?';
$d = query($q, array($s));
if(count($d) == 0) return "";
if($d[0]['year'] == "")
{
if($d[0]['link'] > 0)
{
return renderDomainInfoLink($d[0]['link'], 'id');
}
return "";
}
return "Show details";
}
function renderAgent($s, $includeInstitution=true) {
$s = modifyClassname($s);
$q = 'SELECT agentname, institution FROM users WHERE agentclass = ?';
$d = query($q, array($s));
if(count($d) == 0) return "{{$s}}";
if($includeInstitution)
{
return $d[0]['agentname'].', '.$d[0]['institution'];
}
else
{
return $d[0]['agentname'];
}
}
function qualified($s) {
$s = modifyClassname($s);
$q = 'SELECT qualified FROM users WHERE agentclass = ?';
$d = query($q, array($s));
if(count($d) == 0) return false;
return ($d[0]['qualified'] == 1);
}
function modifyClassname($s) {
if($s == "thenegotiatorreloaded.TheNegotiatorReloaded") return "travelingsalesman.TravelingSalesman";
if($s == "agents.OMAC_sp2012b.OMAC_sp2012b") return "agents.OMAC_sp2012.OMAC_sp2012";
if($s == "agents2012.southampton.IAMhaggler2012a0") return "agents2012.southampton.IAMhaggler2012";
return $s;
}
function rlink($s, $key) {
global $domain;
global $agentA;
global $agentB;
$lparts = array($domain, $agentA, $agentB);
if($lparts[0] == null)
$lparts[0] = "*";
switch($key) {
case "Domain":
$lparts[0] = $s; break;
case "Agent":
$lparts[1] = $s; break;
case "Opponent":
$lparts[2] = $s; break;
}
while(count($lparts) > 0 && $lparts[count($lparts)-1] == "") array_pop($lparts);
if(count($lparts) == 1 && $lparts[0] == "*") return "/results/".$_GET['v'].'/';
return "/results/".$_GET['v'].'/'.implode('/', $lparts);
}
function listByDomain($agentA = null, $agentB = null) {
global $cols;
global $table;
global $batchID;
$where = array();
$params = array();
if(!is_null($agentA)) {
$where[] = "agentA = ?";
$params[] = $agentA;
if(!is_null($agentB)) {
$where[] = "agentB = ?";
$params[] = $agentB;
}
}
$where = getWhere($where);
$q = "SELECT domain as Domain, $cols FROM $table $where GROUP BY domain, $batchID";
$q = average($q, 'Domain', ', DF, RV', ' JOIN domain d ON d.code = x.domain');
return query($q, $params);
}
function listByAgent($domain = null) {
global $cols;
global $table;
global $batchID;
$where = array();
$params = array();
if(!is_null($domain)) {
if(strlen($domain) == 1)
{
$where[] = "SUBSTR(domain, 2, 1) = ?";
}
else
{
$where[] = "domain = ?";
}
$params[] = $domain;
}
$where = getWhere($where);
$q = "SELECT agentA as Agent, $cols FROM $table $where GROUP BY agentA, $batchID";
$q = average($q, 'Agent');
return query($q, $params);
}
function listByOpponent($agent, $domain = null) {
global $cols;
global $table;
global $batchID;
$where = array();
$params = array();
$where[] = "agentA = ?";
$params[] = $agent;
if(!is_null($domain)) {
$where[] = "domain = ?";
$params[] = $domain;
}
$where = getWhere($where);
$q = "SELECT agentB as Opponent, $cols FROM $table $where GROUP BY agentB, $batchID";
$q = average($q, 'Opponent');
return query($q, $params);
}
function listAll($domain, $agentA, $agentB, $side) {
global $cols;
global $table;
$fullcols = preg_replace('/avg\(([a-zA-Z]+)\)/', '\1', $cols);
$fullcols = str_replace(', count(*) as _Count', ', SUBSTRING(id, 5, 2) as repetition', $fullcols);
$where = array();
$params = array();
$where[] = "agentA = ?";
$params[] = $agentA;
$where[] = "agentB = ?";
$params[] = $agentB;
$where[] = "domain = ?";
$params[] = $domain;
$where[] = "n = ?";
$params[] = $side;
$where = getWhere($where);
$q = "SELECT $fullcols FROM $table $where ORDER BY SUBSTRING(id, 5, 2)";
$params = array($agentA, $agentB, $domain, $side);
return query($q, $params);
}
function getWhere($where) {
global $excludeSelfPlay;
if($excludeSelfPlay)
{
$where[] = "agentA != agentB";
}
if(count($where) > 0)
{
return "WHERE ".implode(" AND ", $where);
}
else
{
return "";
}
}
/*
function outputDomainChooser($domain) {
echo "\n";
echo domainLink('(all)', $domain == null || $domain == '*');
foreach(array('C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8') as $d) {
echo domainLink($d, $domain == $d);
}
echo " \n";
}
function outputAgentAChooser($agentA) {
echo "\n";
echo domainLink('(all)', $agentA == null || $agentA == '*');
foreach(array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H') as $a) {
echo domainLink($a, $agentA == $a);
}
echo " \n";
}
function outputAgentBChooser($agentB) {
echo "\n";
echo domainLink('(all)', $agentB == null || $agentB == '*');
foreach(array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H') as $a) {
echo domainLink($a, $agentB == $a);
}
echo " \n";
}
function domainLink($str, $current) {
if($current) {
echo ''.$str.'';
} else {
echo ''.$str.'';
}
}
*/
?>
|