kolanos7 Posted July 13, 2008 Share Posted July 13, 2008 Hi everyone, I am in a bit of a pickle trying to solve this one. I need to generate a randomized sports schedule for a 30 team league there are: 2 conferences, 15 teams each 6 divisions, 3 in each conference 5 teams per division 82 game schedule per team 15 matches per day (every team plays), over 82 days Each team plays every team in their division 8 times (32 matches) Each team plays every team in their conference (outside of their division) 4 times (40 matches) Each team plays each team in 2 of the 3 divisions in the opposing conference 1 time (10 matches) So each team has 32 intradivision matches, 40 interdivion/intraconference matches and 10 interconference matches This sounds do-able, but I am having a hell of a time trying to get this to work right. The technique I initially used is to set team, intradivision, intraconference and interconference pools. Then look for appropriate matchups from those pools at random, and when I've found one, remove the two teams involved from the pool. But I can't seem to get this to work right. Here's what my arrays look like: protected $teams = array( 1 => array('abbr' => 'ANA', 'div' => 2, 'conf' => 1, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 2 => array('abbr' => 'ATL', 'div' => 5, 'conf' => 2, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 3 => array('abbr' => 'BOS', 'div' => 4, 'conf' => 2, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 4 => array('abbr' => 'BUF', 'div' => 4, 'conf' => 2, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 5 => array('abbr' => 'CGY', 'div' => 1, 'conf' => 1, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 6 => array('abbr' => 'CAR', 'div' => 5, 'conf' => 2, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 7 => array('abbr' => 'CHI', 'div' => 3, 'conf' => 1, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 8 => array('abbr' => 'COL', 'div' => 1, 'conf' => 1, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 9 => array('abbr' => 'CBJ', 'div' => 3, 'conf' => 1, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 10 => array('abbr' => 'DAL', 'div' => 2, 'conf' => 1, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 11 => array('abbr' => 'DET', 'div' => 3, 'conf' => 1, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 12 => array('abbr' => 'EDM', 'div' => 1, 'conf' => 1, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 13 => array('abbr' => 'FLA', 'div' => 5, 'conf' => 2, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 14 => array('abbr' => 'LA', 'div' => 2, 'conf' => 1, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 15 => array('abbr' => 'MIN', 'div' => 1, 'conf' => 1, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 16 => array('abbr' => 'MTL', 'div' => 4, 'conf' => 2, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 17 => array('abbr' => 'NSH', 'div' => 3, 'conf' => 1, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 18 => array('abbr' => 'NJ', 'div' => 6, 'conf' => 2, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 19 => array('abbr' => 'NYI', 'div' => 6, 'conf' => 2, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 20 => array('abbr' => 'NYR', 'div' => 6, 'conf' => 2, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 21 => array('abbr' => 'OTT', 'div' => 4, 'conf' => 2, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 22 => array('abbr' => 'PHI', 'div' => 6, 'conf' => 2, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 23 => array('abbr' => 'PHX', 'div' => 2, 'conf' => 1, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 24 => array('abbr' => 'PIT', 'div' => 6, 'conf' => 2, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 25 => array('abbr' => 'SJ', 'div' => 2, 'conf' => 1, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 26 => array('abbr' => 'STL', 'div' => 3, 'conf' => 1, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 27 => array('abbr' => 'TB', 'div' => 5, 'conf' => 2, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 28 => array('abbr' => 'TOR', 'div' => 4, 'conf' => 2, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 29 => array('abbr' => 'VAN', 'div' => 1, 'conf' => 1, 'intrad' => 32, 'intrac' => 40, 'interc' => 10), 30 => array('abbr' => 'WAS', 'div' => 5, 'conf' => 2, 'intrad' => 32, 'intrac' => 40, 'interc' => 10) ); // Which teams belong to which conference protected $interconference = array( 1 => array(2=>2,3=>3,4=>4,6=>6,13=>13,16=>16,18=>18,19=>19,20=>20,21=>21,22=>22,24=>24,27=>27,28=>28,30=>30), 2 => array(1=>1,5=>5,7=>7,8=>8,9=>9,10=>10,11=>11,12=>12,14=>14,15=>15,17=>17,23=>23,25=>25,26=>26,29=>29) ); protected $intraconference = array( 1 => array(1=>1,7=>7,9=>9,10=>10,11=>11,14=>14,17=>17,23=>23,25=>25,26=>26), 2 => array(5=>5,7=>7,8=>8,9=>9,11=>11,12=>12,15=>15,17=>17,26=>26,29=>29), 3 => array(1=>1,5=>5,8=>8,10=>10,12=>12,14=>14,15=>15,23=>23,25=>25,29=>29), 4 => array(2=>2,6=>6,13=>13,18=>18,19=>19,20=>20,22=>22,24=>24,27=>27,30=>30), 5 => array(3=>3,4=>4,16=>16,18=>18,19=>19,20=>20,21=>21,22=>22,24=>24,28=>28), 6 => array(2=>2,3=>3,4=>4,6=>6,13=>13,16=>16,21=>21,27=>27,28=>28,30=>30) ); protected $intradivision = array( 1 => array(5=>5,8=>8,12=>12,15=>15,29=>29), 2 => array(1=>1,10=>10,14=>14,23=>23,25=>25), 3 => array(7=>7,9=>9,11=>11,17=>17,26=>26), 4 => array(3=>3,4=>4,16=>16,21=>21,28=>28), 5 => array(2=>2,6=>6,13=>13,27=>27,30=>30), 6 => array(18=>18,19=>19,20=>20,22=>22,24=>24) ); Any suggestions on how I should go about this? Is there a simple way to randomly generate a schedule like this? Please help! Thanks. Link to comment https://forums.phpfreaks.com/topic/114562-random-sports-season-scheduler/ Share on other sites More sharing options...
teynon Posted July 13, 2008 Share Posted July 13, 2008 Might I suggest using a database rather than arrays? Just to clean up data and allow easier grouping and calculations. I'm working on a solution for this one right now. Link to comment https://forums.phpfreaks.com/topic/114562-random-sports-season-scheduler/#findComment-589144 Share on other sites More sharing options...
BuckeyeTheDog Posted July 14, 2008 Share Posted July 14, 2008 Are you actually trying to create the schedule, or display the schedule that has been created? Link to comment https://forums.phpfreaks.com/topic/114562-random-sports-season-scheduler/#findComment-589207 Share on other sites More sharing options...
teynon Posted July 14, 2008 Share Posted July 14, 2008 Buckeye, he's trying to make the schedule. I am looking at the logic now, it is actually really freaking difficult, giving me a headache. I'm close to getting it though... I don't know if I can explain the logic though lmao Link to comment https://forums.phpfreaks.com/topic/114562-random-sports-season-scheduler/#findComment-589209 Share on other sites More sharing options...
kolanos7 Posted July 14, 2008 Author Share Posted July 14, 2008 teynon, Boy you aren't kidding the logic gets complicated. I've gone through five major revisions trying to solve this problem, and it just gets more convoluted. I've got it to a point now where it comes close to generating a schedule that meets the criteria above, but begins to run out of matchup options, which means somewhere the accounting is wrong (removing teams when they are no eligible for matchup types). When I get into the 60-80 day range, the slim pickings of matchup options start to make it break down. I compensate for this by having it go through problematic matchups and cleaning them up or correcting them after the schedule has been generated, but even that isn't 100%. To answer an earlier question, I'm looking to create the schedule into an array, which could then be inserted into a database. The only reason why I'm not using a datbase for this problem is because the SQL queries that would be needed would be almost as absurd as the code I'm writing. teynon, if you'd like to post your logic either in pseudo code or actual code, please do. I plan to post what I have so far as soon as I clean it up. Right now it is a very messy 200 lines. Link to comment https://forums.phpfreaks.com/topic/114562-random-sports-season-scheduler/#findComment-589231 Share on other sites More sharing options...
ninedoors Posted August 12, 2008 Share Posted August 12, 2008 kolanos7, Did you find a solution for this. I am currently trying to do the same thing you are and am having the same logic problems as you were. The more teams you use the crazier the script gets. I am trying to develop a class that will let the user input the number of games each team plays as well as the number of teams in the league or division. Let me know if you have worked out the solution for this as I would be interested to look at your logic. Any one have any thoughts on this topic? Nick Link to comment https://forums.phpfreaks.com/topic/114562-random-sports-season-scheduler/#findComment-614425 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.