如何实现单讲座席位分配算法席位、算法、如何实现、讲座

2023-09-11 06:48:31 作者:回忆唤不回你的温柔

我们有大约1000个免费机位,为讲座在我们的单,并在2000年左右的座位要求(也许500名学生,要求各4处)。 我正在开发使用CakePHP,它可以让学生从1做出的心愿,并输入每块4讲座,与优先级为4(这然后进入一个MySQL数据库)

we have about 1000 free seats for our lectures at our uni, and around 2000 seats demanded (maybe 500 students demanding 4 places each). I'm developing a webapp with CakePHP, which lets students make a wishlist and enter 4 lectures per block, with priorities from 1 to 4. (This then goes into a MySQL-database)

现在,网络前端完成后,管理员操作(添加讲座,加讲师等)完成..唯一剩下的是写分配算法。

Now, the web frontend is done, the admin actions (add lectures, add lecturers, etc) are done.. the only thing left is writing the distribution algorithm.

我应该怎么做才好呢?一个MySQL脚本似乎是有用的,但MySQL的不是很友好,当涉及到循环和if-结构,是吗? 难道是聪明的地方导出数据,并让另一种语言处理这个问题?

How should I best do this? A MySQL-script seems useful, but mysql is not very friendly when it comes to loops and if-constructs, is it? Would it be smart to export the data somewhere and let another language handle the problem?

编辑:dnagirl要求对算法的详细信息: 我们没有对算法的业务规则。我们改编自别人在另一所大学,其中有我们只是适应现存规则(很贵)的应用程序。 他在做什么(什么我试图克隆,救大每学期的费用),是这样的:

dnagirl requested more info about the algorithm: We don't have business rules for the algorithm. We adapted an existing (very expensive) app from someone else at another university, which has rules we just adapted. What he is doing (and what I am trying to clone, to save the big per-semester fee), is this:

活动(讲座,演习等)都属于一个块(block是如国际政治,其中有大约四五个不同的事件) 学生可以申请每块最多4个事件,优先考虑1至4 在该算法每块的工作。对于每个块,分为学生分成不同的组,根据他们的排名。 (该排名是越高越好,正常的排名从0到20) 从组学生的最高排名,随机选择一个。给他一个位子,他选择与优先级1.如果这个事件是完全,给他他选择优先级2座事件;等,跌幅为4。 选择下一个学生,做同样的,直到每个学生本的排名有一个席位。然后,转到下一个较低的排名,并再次做的一切。当此块后,再次做一切与下一个块,直到所有的块完成。

我知道这个算法是不是最好的解决办法,但我想我就克隆它现在,也许在事后的改进工作中的逻辑/可能性。

I know this algorithm isn't the best solution, but I thought I'll just clone it for now, and maybe afterwards work on an improvement in the logic/possibilities.

推荐答案

您可能需要某种形式的遗传算法:

You probably want some sort of genetic algorithm:

创建了讲座的随机分布的学生 在计算分数(满足愿望高分,超额预定演讲产生一个点球,等等。) 请更改(如移动一学生不同的讲课)。如果分数的增加,保持它,否则拒收。 在保持迭代,直到没有变化可以发现,增加了比分:你已经找到了当地最低 重复整个事情几次来寻找其他局部极小。然后去最好的得分的解决方案。

您可能需要运行一些测试和调整评分权重,得到它的权利。

You'll have to run a few tests and tweak the scoring weights to get it right.

MySQL是不是真的很适合这一点;您更好地解决这个问题在PHP中,然后坚持一气呵成。如果性能不够好,你甚至可以考虑在C ++中实现它,但我建议你先试试PHP和看看它的速度不够快。它不象你要运行这个每2秒。

MySQL is not really very suitable for this; you better solve this in PHP and then persist in one go. If the performance isn't good enough, you might even consider implementing it in C++, but I suggest you try PHP first and see if it's fast enough. It's not like you're going to run this every 2 seconds.