PHP 随机团队日程生成器 - 循环调度程序
在新问题中提出这个问题得到负面反馈后......这是我修改后的问题。是的,这与我正在从事的项目相同,但我不清楚我是否需要基本上有一个循环类型的调度程序。
我正在开发循环式曲棍球联赛调度程序,并且需要一些帮助。
总体目标是最终管理员用户能够输入 3 个变量并让它执行循环式计划,直到达到 WEKS 计数器为止。以下是球队数量和比赛周数的示例。
$Teams = array('team1','team2','team3','team4','team5','team6','team7','team8');
$Weeks = 16;
目标是让它循环 16 次,每周进行 4 场比赛,每支球队每周比赛 1 次。循环赛算法应该让球队每周与不同的球队比赛,直到完成所有可能的组合,但不超过 16 周。如果我们只有 4 支球队或少于可能的组合,我们需要重新开始循环赛,直到达到周数。
编辑:
我大约 90% 完成了我需要这个脚本做的事情......但我坚持了一件事。我需要合并多维数组的帮助。
首先是层级。接下来是几周(均为第一周)。接下来是团体赛。
Array
(
[1] => Array
(
[1] => Array
(
[1] => Array
(
[home] => Whalers
[visitor] => Lumberjacks
)
[2] => Array
(
[home] => Team America
[visitor] => Wolfpack
)
)
)
[2] => Array
(
[1] => Array
(
[1] => Array
(
[home] => Warriors
[visitor] => Litchfield Builders
)
[2] => Array
(
[home] => Icemen
[visitor] => Nighthawks
)
)
)
[3] => Array
(
[1] => Array
(
[1] => Array
(
[home] => The Freeze
[visitor] => Devils Rejects
)
[2] => Array
(
[home] => Cobras
[visitor] => New Haven Raiders
)
[3] => Array
(
[home] => Crusaders
[visitor] => Whalers
)
[4] => Array
(
[home] => Blizzard
[visitor] => CT Redlines
)
)
)
)
我希望最终结果放弃层级并将所有同一周的游戏合并在一起,如下所示:
Array
(
[1] => Array
(
[1] => Array
(
[home] => Whalers
[visitor] => Lumberjacks
)
[2] => Array
(
[home] => Team America
[visitor] => Wolfpack
)
[3] => Array
(
[home] => Warriors
[visitor] => Litchfield Builders
)
[4] => Array
(
[home] => Icemen
[visitor] => Nighthawks
)
[5] => Array
(
[home] => The Freeze
[visitor] => Devils Rejects
)
[6] => Array
(
[home] => Cobras
[visitor] => New Haven Raiders
)
[6] => Array
(
[home] => Crusaders
[visitor] => Whalers
)
[8] => Array
(
[home] => Blizzard
[visitor] => CT Redlines
)
)
)
After getting negative feedback from asking this question in a new question... here is my revised question. Yes it is the same project I am working on, but I was unclear that I needed to basically have a Round Robin type of scheduler.
I'm working on a Round Robin Style Hockey League Scheduler, and need some help.
The overall goal is for the end admin user to be able to punch in 3 variables and have it perform a round Robin style schedule until the WEEKS counter has been hit. Below is an example of the amount of teams and the amount of weeks games are played.
$Teams = array('team1','team2','team3','team4','team5','team6','team7','team8');
$Weeks = 16;
The goal is to have it loop 16 times, making 4 games a week, having each team playing 1 time a week. The round robin algorithm should have teams playing different teams each week until all possibles combinations have been made, but not exceeding 16 weeks. In the event that we only have 4 teams or less teams than possible combinations, we would need to have the round robin start over again until the weeks number was hit.
EDIT:
I am about 90% into what I needed this script to do... but I am stuck on one thing. I need help with merging a multi-dimensional array.
First are the Tiers. Next are the Weeks (all are week 1). Then are the Games for the team match up.
Array
(
[1] => Array
(
[1] => Array
(
[1] => Array
(
[home] => Whalers
[visitor] => Lumberjacks
)
[2] => Array
(
[home] => Team America
[visitor] => Wolfpack
)
)
)
[2] => Array
(
[1] => Array
(
[1] => Array
(
[home] => Warriors
[visitor] => Litchfield Builders
)
[2] => Array
(
[home] => Icemen
[visitor] => Nighthawks
)
)
)
[3] => Array
(
[1] => Array
(
[1] => Array
(
[home] => The Freeze
[visitor] => Devils Rejects
)
[2] => Array
(
[home] => Cobras
[visitor] => New Haven Raiders
)
[3] => Array
(
[home] => Crusaders
[visitor] => Whalers
)
[4] => Array
(
[home] => Blizzard
[visitor] => CT Redlines
)
)
)
)
I want the end result to drop the tier and merge all same weeks games together to look like the following:
Array
(
[1] => Array
(
[1] => Array
(
[home] => Whalers
[visitor] => Lumberjacks
)
[2] => Array
(
[home] => Team America
[visitor] => Wolfpack
)
[3] => Array
(
[home] => Warriors
[visitor] => Litchfield Builders
)
[4] => Array
(
[home] => Icemen
[visitor] => Nighthawks
)
[5] => Array
(
[home] => The Freeze
[visitor] => Devils Rejects
)
[6] => Array
(
[home] => Cobras
[visitor] => New Haven Raiders
)
[6] => Array
(
[home] => Crusaders
[visitor] => Whalers
)
[8] => Array
(
[home] => Blizzard
[visitor] => CT Redlines
)
)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
也许是这样的?
我不太明白你是如何定义时间表的,所以如果你能解释一下,我会尽力提供帮助。
Maybe something like this?
I didn't really get how you define the schedule, so if you can explain this a bit, I'll try to help.
弹出一个,随机化,弹出另一个。这是你的游戏。如果剩下一个,则随机某个团队必须成为主力并在本周打两场比赛:
Pop one off, randomize, pop another. There's your game. If one is left over, some random team has to be a workhorse and play two games this week:
下面的问题是从上面复制的。
如果我弄错了,请纠正我,但如果所有球队都必须按相同的常规进行比赛,那么如果球队数量为奇数,是否有可能让所有球队参加相同数量的比赛? – Yoshi 2011 年 5 月 3 日 15:05
米歇尔,
您尝试配对的团队数量(在本例中为 8 个团队,持续 16 周)可能是一项艰巨的任务,并且只是“调度过程”的开始。一旦确定了正确、平衡的团队配对,这只是制定分发计划的开始。接下来,每周 4 个时段的列表包括:整个 16 周赛季中每个时段的星期几、开始时间和地点名称。评论:对你最有帮助的是获得一个8支球队的调度矩阵,其中有平衡的对手,以及主队和主队。离开状态。它对日程的质量有很大的影响。重要的是要均匀分配早晚时段,平等的主场和主场时间。客场地位,与对手平等的球队分配。大部分平衡是通过使用平衡团队配对矩阵来实现的。
在波士顿地区从事体育教学、教练和调度工作 35 年之后,我可以提供以下信息。为体育组织制定联赛或比赛日程似乎是许多人共同承担的一项永无止境的任务,并且随着参与者年龄的增长和联赛运营者的变化而一遍又一遍地重复,与制定日程相关的学习曲线对于那些参与其中的人来说非常重要。接管。
话虽如此,我还是惊讶于有多少受过高等教育的数学奇才参与其中,试图提出完美的解决方案(算法)来解决一个人的调度问题。我和一个朋友(数学/程序员天才)花了 3 年时间创建了一个软件,在为 4 到 22 个团队创建日程表时完美平衡了所有重要组件。我们了解到,没有一种算法可以处理添加到正常变量中的所有可能变量以创建平衡的时间表。我想说的是,“假设”的数量与数学排列和组合的数量一样多,这些排列和组合只涉及创建一个列出对手、主场和球队的球队矩阵。游戏的访客状态。
例如:让我们为 9 支球队每周打 4 场比赛创建一个完美平衡的时间表。九周后,所有球队都踢了8场比赛,都有1次轮空,所有球队在4个时段各踢了2场比赛,并且都被安排为主队4次,客队4次。
人们还想要什么呢?那么现在有趣的事情来了。因为你选择的4个时段每周六有2场比赛,每个周日有2场比赛,所以出现了第一个问题(赛程表创建、发布并下发后,来自2个不同球队的2名教练打电话说他们周六工作,你可以把我们的比赛改到周日吗?当然,我可以做一些更改,重新发布并重新分发
新的赛程表,几天后,另一位教练会打电话过来。说:“嘿,你把我的一些比赛移到了周六,我周六工作……,把它们移回来”,这次电话又响了,是另一支球队的教练,说他们正在参加第五周的比赛。最后,另一位教练打来电话,他说他的一名球员的父母周日下午教 CCD 课程,而他的球队有一半人在 CCD 课程中,并且想要转会。我们周日到周六的所有比赛都够了!
我的观点是,无论您做什么或日程安排多么完美,最好的解决方案是在分配比赛日期和时间之前找出尽可能多的球员/教练团队限制或限制。任何时间表的时段。这些不可预测的变数让完美的日程变得一团糟。当安排不合要求的日程安排时,人们确实会生气并抱怨。当赛程安排足够糟糕时,一些父母不会签下他们的孩子来参加第二年的比赛。当你有一个有两三个小孩的年轻家庭,而爸爸的工作限制了他的能力时,就会发生这种情况。当有一场清晨的比赛时,我想你可以看到妈妈的困难,因为这一切都落在了她的肩上。
对于那些刚接触日程安排的人来说,请坚持下去。当你获得收益后,随着时间的推移它会变得更好
处理问题的一点经验。如果您购买调度软件程序来计算团队配对,请小心。坚持看到他们创建的时间表的完整单循环。检查上述内容(关于平衡和分配)。
鲍勃·R
Question below copied from above.
Correct me if I get this wrong, but if all teams have to play on the same regular basis, is it even possible to have all teams play the same amount of matches, if there is an odd number of teams? – Yoshi May 3 '11 at 15:05
Michelle,
The number of teams you are trying to pair-up (in this case 8 teams for 16 weeks) can be a daunting task, and is just the beginning of the "scheduling process". Once the correct, balanced team pairings have been determined, it's just the beginning of putting a schedule together for distribution. Next, a list of the 4 weekly time slots includes the; day of the week, start time and location name for each time slot for the whole 16 week season. Comment: What would be most helpful for you is to get an 8 team scheduling matrix that has balanced opponent, and home & away status. It makes a big difference in the quality of a schedule. It's important to evenly distribute early and late time slots, equal home & away status, and equal team distribution with opponents. Most of the balance is accomplished by using a balanced team pair matrix.
After 35 years of teaching, coaching and scheduling sports in the Boston area, I can offer the following information. Creating league or game schedules for sports organizations seems to be a never ending task shared by many and is repeated over and over as the ages of the participants grow and those running the leagues change, the learning curve associated with creating schedules is significant for those who take over.
With that said, I am amazed at how many highly educated mathematical wizards are involved with trying to come up with the perfect solution (algorithm) that will solve one's scheduling problem. Myself and a friend (who is a mathematical/programmer genius) over a period of 3 years created software that perfectly balances all the important components when creating schedules for 4 to 22 teams. What we learned is that there is no algorithm that can handle all the possible variables that are added to the normal variables to create balanced schedules. What I am saying is there are just as many "what ifs" as there are mathematical permutations and combinations that deal with just creating a team matrix listing opponents and home & visitor status of games.
For example: Let's create a perfectly balanced schedule for an 9 team division playing 4 games a week. After nine weeks all teams have played played 8 games, all have had 1 bye, all have played two times in each of the 4 time slots, and all have been scheduled as the home team 4 times and the visitor team 4 times.
What more could anybody want? Well now comes the fun. Because the 4 time slots you chose has 2 games each Saturday, and 2 games each Sunday, the first problem pops up (after the schedules are created, published and passed out, when 2 coaches from 2 different teams call and say they work Saturdays, can you move our games to Sundays? Sure, I can do that. I'll just make the changes, re-publish and re-distribute the schedules.
After the new schedules are distributed, several days later, a different coach calls up and says, "Hey, you moved some of my games to Saturday, I work Saturdays.., move them back". The phone rings again. This time a it's a coach from another team and says they are in a tournament the 5th week of the schedule and can't play that week. Finally the last call comes in from yet another coach. He says the parents of one of his players teaches CCD classes Sunday afternoons, and half of his team is in the CCD class and wants to move all our Sunday games to Saturday. Enough!
My point is no matter what you do or how perfect a schedule is, the best solution is to find out as many of the player/coach team limitations or restrictions before you assign the playing days and time slots to any schedule. These unpredictable variables makes a mess out of a perfect schedule. People do get angry and complain when undesirable schedules are distributed. When a schedule is bad enough, some parents won't sign their youngster to play the following year. This happens when you have a young family with two or three small children, and Dad's work limits his ability to be there. When there is an early morning game, I think you can see the difficulty for Mom's when it all falls on her shoulders.
For those that are new to scheduling, stay with it. It gets better over time after you gain
a little experience dealing with the problems. If you purchase a scheduling software program to calculate team pairs, be careful. Insist on seeing a full single round robin of the schedule they create. Check for the things described above (about balance and distribution).
Bob R
给定一个团队表,比如说
团队 (
队名
);
和一张固定装置表
(
日期;
);
随着“玩”玩而分解的关系
(
固定装置_日期。
队名
);
然后,只需迭代每个日期,然后组队并随机选择一支在该日期还没有固定赛程的球队以及没有参加过所选球队(或最近没有参加过所选球队)的球队即可。
尽管更简单的解决方案是让 team[n] (其中 n 为 0...团队数量 -1)针对不同的 X 值玩 team[(n+(团队数量)) % X]。
Given a table of teams, say
team (
teamname
);
And a table of fixtures
fixture (
date;
);
With the relationship decomposed by 'playing'
playing (
fixture_date.
teamname
);
Then it's would simply be a matter of iterating through each date, then team and selecting a team at random who does not already have a fixture for that date, and who have not played the selected team (or not played the selected team recently).
Although a simpler solution would be to have team[n] (where n is 0....number of teams -1) play team[(n+(number of teams)) % X] for varying values of X.