Bon j’ai trouvé l’algorithme quivabien, merci a tous les participants. Merci aussi a KiniK pour son algorithme et a GuiHome qui m’a fourni l’algorithme ‘pas en code’ (mais d’une logique implacable, j’en reste impressionné). Voila l’algo qui va ben sortie de ma classe (c’est du PHP, c’était le langage le plus rapide pour développer pour moi):
(désolé pour la tabulation pourrie)
[code] // check if meetings has to be done
private function isDone($pMeetings)
{
if(count($pMeetings)==0)
return(true);
return(false);
}
// delete all meetings that have been assigned to results meetings found for a day
private function updateMeetings(&$pMeetings,$pRemovalList)
{
foreach($pMeetings as $sKey => $pValues)
foreach($pRemovalList as $sRemovalKey => $pRemovalValues)
if($pMeetings[$sKey][0]==$pRemovalList[$sRemovalKey][0] && $pMeetings[$sKey][1]==$pRemovalList[$sRemovalKey][1])
unset($pMeetings[$sKey]);
}
// delete all meeting that can’t be done this day
private function deleteTeamFromMeetingList(&$pMeetings)
{
reset($pMeetings);
$pData = current($pMeetings);
$sHomeTeam = $pData[0];
$sForeignTeam = $pData[1];
foreach($pMeetings as $sKey => $sValue)
if($pMeetings[$sKey][0]==$sHomeTeam || $pMeetings[$sKey][1]==$sHomeTeam || $pMeetings[$sKey][0]==$sForeignTeam ||$pMeetings[$sKey][1]==$sForeignTeam)
unset($pMeetings[$sKey]);
}
// get recursively the next available meeting
private function getNextMeetingDay(&$pMeetings,$iRecursion)
{
// no result found, so return false
if(count($pMeetings)===0)
return(false);
// get first result
reset($pMeetings);
$pFirstResult[$iRecursion] = current($pMeetings);
// recursion == 1 so only one result should be available
if($iRecursion==1)
return($pFirstResult);
$this->deleteTeamFromMeetingList($pMeetings);
$bFound = false;
// loop all meetings, to find a good result
while($bFound==false)
{
// create a working copy to find available meetings
$pWorkingCopy = $pMeetings;
// ask another time a meeting. In this recursion, we should find n - found meetings
$pSubResult = $this->getNextMeetingDay($pWorkingCopy,$iRecursion-1);
// no result found
if($pSubResult===false)
{
// if nothing found, delete current item, so we can test with the next one
array_shift($pMeetings);
// no results found, this solution isn’t good
if(count($pMeetings)==0)
return(false);
}
else
$bFound = true;
}
return($pFirstResult + $pSubResult);
}
private function createMatchesForSeason($pTeams, $iSeason, $iDeadLine)
{
$pMeetings = array();
$pMeetingResults = array();
$iNumberTeams = count($pTeams);
// the meeting function work only for pairs number of people
if(($iNumberTeams%2)==1)
{
$iNumberTeams++;
$pTeams[] = array(“sName” => “Nobody”);
}
// build the list of meetings
for($iCnt=0;$iCnt<count($pTeams);$iCnt++)
for($iCnt2=$iCnt+1;$iCnt2<count($pTeams);$iCnt2++)
$pMeetings[] = array($pTeams[$iCnt][“sName”],$pTeams[$iCnt2][“sName”]);
$iCnt = 0;
// build the results meeting
while(!$this->isDone($pMeetings))
{
$pWorkingCopy = $pMeetings;
$pMeetingResults[$iCnt] = $this->getNextMeetingDay($pWorkingCopy,$iNumberTeams/2);
// delete matches that have been planned
$this->updateMeetings($pMeetings,$pMeetingResults[$iCnt]);
$iCnt++;
}
print_r($pMeetingResults);
}[/code]