【发布时间】:2010-05-29 21:39:18
【问题描述】:
我一直在研究这种针对学生的通用分配算法。
它的伪代码(一个 Python 实现)是:
for a student in a dictionary of students:
for student preference in a set of preferences (ordered from 1 to 10):
let temp_project be the first preferred project
check if temp_project is available
if so, allocate it to him and make the project unavailable to others
break
很简单,这将尝试从最喜欢的项目开始分配项目。它的工作方式,在一组比如说 100 个项目中,你列出了 10 个你想做的事情。因此,第 10 个项目不会是“总体上最不受欢迎的”,而是他们选择的集合中最不受欢迎的项目,这还不错。
很明显,如果它不能分配一个项目,一个学生只是恢复到基本情况,即分配无,排名为 11。
我正在做的是根据排名的加权总和计算分配“质量”。因此,数字越低(即更受青睐的项目),分配质量就越好(即更多的学生拥有更受青睐的项目)。
这基本上就是我目前所拥有的。简单而有效。
现在我正在研究这个算法,它试图在本地最小化分配权重(这个伪代码有点乱,抱歉)。
这可能会起作用的唯一原因是因为我的“搜索空间”并不是特别大(请注意,这只是一个非常普遍的轶事观察)。由于该项目仅针对我的部门,因此我们有自己的限制。所以学生的数量不能超过100,偏好的数量不会超过10。
for student in a dictionary/list/whatever of students:
where i = 0
take the (i)st student, (i+1)nd student
for their ranks:
allocate the projects
and set local_weighting(N) to be sum(student_i.alloc_proj_rank, student_i+1.alloc_proj_rank)
these are the cases:
if N is 2 (i.e. both ranks are 1):
then i += 1 and
and continue above
if N > 2 (i.e. one or more ranks are greater than 1):
let temp_N be N:
pick student with lowest rank
and then move him to his next rank
and pick the other student and reallocate his project
temp_N is sum of the the ranks
if temp_N is < N:
then allocate those projects to the students
i += 1
and move on for the rest of the students
关于 cmets 的更新:
我正在尝试做的事情:
我试图在一次由两个学生组成的小组(即本地)之间实现“最低体重分配”
权重分配是学生分配的排名的总和。我们希望学生获得总体排名最高的项目。因此,如果学生 A 获得了他排名第 1 的项目,而学生 B 获得了她排名第 5 的项目,那么他们的本地分配权重为 6。如果我们将学生 A 移动到他的排名 2 的项目,因此,学生 B 移动到她的排名3 项目然后权重现在是 5。5
因此,我从我的学生集合开始,然后开始遍历他们
我从第一个和第二个学生开始,分配他们的项目
然后我如上所述计算重量。鉴于权重等于排名,如果两者都排名第 1,则权重为 2。这是最好的,我们想继续第二和第三个学生。
现在,如果权重大于 2,说明有一个或多个项目的排名大于 2,我们会尝试获得更好的版本。
因此我们选择排名最低的学生,然后将他/她降低一个等级(因此,如果他/她是 1 级,这会将他降低到 2 级)
然后我们尝试将另一个学生重新分配到另一个等级。
现在如果权重比以前的权重好,那么我们就让它成为新的权重,让他们拥有那些项目。如果情况更糟或相同,那么我们就转到下一个学生组合。
在本地,对于学生来说,这个东西一直在尝试,直到达到最小重量并且不能做得更好。
希望这能解释我想要做什么?
所以,问题:
这是对模拟退火的一种修改,但任何类型的 cmets 都将不胜感激。
我将如何跟踪哪个学生是 (i) 以及哪个学生是 (i+1)
如果我的学生总数为 100,那么 (i+1) = 101 就会出错,因为没有。我该如何规避呢?
任何可以立即发现的缺陷?
额外信息:
我的学生词典是这样设计的:
students[student_id] = Student(student_id, student_name, alloc_proj, alloc_proj_rank, preferences)
where preferences is in the form of a dictionary such that
preferences[rank] = {project_id}
【问题讨论】:
-
我不是很精通这个,但你的问题听起来很适合应用Branch and bound 算法。
标签: python algorithm allocation