ninedoors Posted August 20, 2008 Share Posted August 20, 2008 First off, I'm not sure if this is in the right section, so if it isn't then I'm sure a Mod will move it for me. I have been working on creating a script that will schedule games for a hockey league I run. So far I have been able to get the schedule filled out so that each team plays each other equally or as equally as they can. My inputs were the number of teams in the league and the number of games each team plays. Also moved the teams around in each game to get equal home and away games for each team. That part went fine but now I am running in to a bit of a problem with the actually scheduling of the game times. So far I have created a temp table that holds all the possible game dates, times and locations. So a couple rows of the table would be: 2008-10-01, 9:00 pm, IRC Rink 2008-10-01, 10:00 pm, IRC Rink 2008-10-01, 11:00 pm, IRC Rink 2008-10-03 9:30 pm, IRC Rink....and so on, so that every date/time is in the table. My problem is coming with trying to get it so that each team will have an equal amount of 9 pm games as they do 11 pm games. Does anyone have any ideas on how they would go about do such a thing. Thanks for the input. Nick Link to comment https://forums.phpfreaks.com/topic/120555-making-league-schedule-times-even-for-all-teams/ Share on other sites More sharing options...
webref.eu Posted August 20, 2008 Share Posted August 20, 2008 As no-one has commented so far, I thought I'd just say that yes, this does seem a hard problem. Have you had any thoughts at all about possible techniques? In some way you will have to remember what has been assigned and then assign the next game accordingly? Perhaps assigning sequentially in order of time? So if possible for each "match" assign 1 time slot later each time so you assign all possible times sequentially and then just repeat the loop, i.e. if there are four time slots you keep looping through the 4 slots. I know this doesn't make much sense but I just thought I'd make some kind of answer and more experienced people may view the post. Rgds Link to comment https://forums.phpfreaks.com/topic/120555-making-league-schedule-times-even-for-all-teams/#findComment-621279 Share on other sites More sharing options...
ninedoors Posted August 20, 2008 Author Share Posted August 20, 2008 Thanks for the response webref. I have tried that already but with no luck. I will try to explain what I did and you can maybe see where I went wrong. In my example I used 4 different game times. For the first 4 games of the season I just slotted the game times in as for the first week it won't matter who gets whats game. When I inserted each start time I also recorded it in a temp table that had 2 columns, team_id (for this example teams 1 thru 8 ) and team_sum. I used team_sum to keep the total starting time for that team. Meaning when team one has a starting time of 10 pm they would get team_sum + 10. If you still follow me, on the next loop I would pull the next 4 games as well as each teams' team_sum. If team1 was playing team8 then that games sum would be team_sum(1) + team_sum( 8 ). I would do that for all 4 games and tehn order them least to highest. The game with the lowest sum would get the highest(lastest) starting time. And so on for all 4 games. My hope was all the teams would end up at the end of the schedule with similar sums. And therfore the saem average starting times. This did work as I ended up with my lowest team with 489 and my highest team with 510. Which isn't bad except it didn't work as a couple teams just ended up having a bunch of the lastest games and a bunch of the earliest games. Let me know if that confused the hell out of you. I understand why thi smethod didn't work but I am looking for one that will! Nick Link to comment https://forums.phpfreaks.com/topic/120555-making-league-schedule-times-even-for-all-teams/#findComment-621301 Share on other sites More sharing options...
akitchin Posted August 20, 2008 Share Posted August 20, 2008 this is a difficult question, since obviously you can only cater to one team's needs at a time. you may be better off throwing the outliers in your current method (those with the greatest and least double team sums) into the median time slots. this will force the outliers closer to the centre, while putting the ones closer to the median value farther out towards the centre, perhaps evening out the times a little more. unfortunately that might be the closest thing you get without some serious number crunching. the other way i would think of doing it is the following: definitions first - sequential slot means the next time slot that a team wants (ie. team 1 played 9PM last time, they're due for a 10PM next; 10PM is their sequential slot). game slot means the next available game time, regardless of rink. 1. select the next four games' teams, along with their sequential slot. 2. start by assigning the first available game slot to a game that involves a team whose sequential slot matches this one. 3. if in (2) above there are more than one team whose sequential slot match the game slot, give it to the game with the sum of sequential slots matching the game slot the closest (ie. a 9PM and 10PM would match closer than a 9PM and 11PM). 4. repeat numbers 2 and 3 above until you're out of games to assign. if you no longer have any matches to the game slots, assign by sequential slot sums as before. does that make sense? i'm not even sure if that would get you any closer to even distributions, but it should in principle be a slight improvement over your current method. Link to comment https://forums.phpfreaks.com/topic/120555-making-league-schedule-times-even-for-all-teams/#findComment-621362 Share on other sites More sharing options...
ninedoors Posted August 20, 2008 Author Share Posted August 20, 2008 Thank you akitchin for your reply. I will give your idea a try and let you know how it works out. I started to think about this after I wrote my initial post and I am thinking that the only way to get it perfect everytime is you would need some kind of permutations algorithm that would take every action and work out the next and next and so on until it ran the course of the season. Do this to every possible action and then pick the one that works. Not sure if this makes sense but I am thinking if it worked like a grand master chess robot which works out every possible move and there out comes and then chooses the best one. But there are scheduling software programs out there, does anyone know anyone have this software code to look at or any that I could look at to see the logic behind it. Thanks Nick Link to comment https://forums.phpfreaks.com/topic/120555-making-league-schedule-times-even-for-all-teams/#findComment-621381 Share on other sites More sharing options...
akitchin Posted August 20, 2008 Share Posted August 20, 2008 don't forget to consider that you've already run a combination function against the teams to decide on the games draw. assuming this is separate to the scheduling, it might be the case that it's not possible to get it perfect everytime - with the compounding of both runs, the probability of successfully distributed game times could be vanishingly low. it might be easiest to settle for "good enough" and manually adjust the schedule if and when you receive any complaints. Link to comment https://forums.phpfreaks.com/topic/120555-making-league-schedule-times-even-for-all-teams/#findComment-621392 Share on other sites More sharing options...
ninedoors Posted August 20, 2008 Author Share Posted August 20, 2008 Ya, I was thinking that would be the case, but close is good enough for me. I'll just make sure my team has the most early games Nick Link to comment https://forums.phpfreaks.com/topic/120555-making-league-schedule-times-even-for-all-teams/#findComment-621396 Share on other sites More sharing options...
akitchin Posted August 20, 2008 Share Posted August 20, 2008 Ya, I was thinking that would be the case, but close is good enough for me. I'll just make sure my team has the most early games Nick as long as you win, what does it matter who and how many others lose? Link to comment https://forums.phpfreaks.com/topic/120555-making-league-schedule-times-even-for-all-teams/#findComment-621398 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.