0) && isset($topicReviewerAR[$t]) && (count($topicReviewerAR[$t] > 0))) { $topicScoreAR[$t] = count($topicReviewerAR[$t]) / $topPAR[$t]; } else $topicScoreAR[$t] = 0; } // Calculate paper scores foreach ($paperTopicAR as $paperid => $topiclist) { $score = 0; foreach ($topiclist as $topicid) { $score += $topicScoreAR[$topicid]; } $paperScoreAR[$paperid] = $score; } asort($paperScoreAR); // Calculate advocate scores foreach ($reviewerTopicAR as $reviewerid => $topiclist) { $score = 0; foreach ($topiclist as $topicid) { $score += $topicScoreAR[$topicid]; } $reviewerScoreAR[$reviewerid] = $score; } asort($reviewerScoreAR); // Iterate through papers (score low to high) assigning // advocates in order of their score foreach (array_keys($paperScoreAR) as $paperid) { // Skip if paper already has advocate if (!empty($pAR[$paperid])) { continue; } // Create a list of advocates for paper incl. scores $Rs = array(); if (isset($paperTopicAR[$paperid])) { foreach($paperTopicAR[$paperid] as $topicid) { if (isset($topicReviewerAR[$topicid])) { // may not have a reviewer for every topic foreach ($topicReviewerAR[$topicid] as $reviewerid) { if (!in_array($paperid."-".$reviewerid,$nAR) // advocate not in conflict && (count($aAR[$reviewerid]) < $ppa) ) // not enough papers yet { $Rs[$reviewerid] = $reviewerScoreAR[$reviewerid]; } } } } } // Assign advocate based on reviewer score high->low if (count($Rs) > 0) { if ($sortorder=="1") { arsort($Rs); } else { asort($Rs); } reset($Rs); $pAR[$paperid] = key($Rs); array_push($aAR[key($Rs)],$paperid); } } } oc_algoWeightedTopicMatch($papersPerAdvocate,1);