我应该用什么来实现c++中的加权二分匹配算法
What should I use to implement weighted bipartite matching algorithm in c++?
我有一个项目,它要求我将课程分发给学生。所有学生都要求一些课程,但他们只被允许获得一定数量的课程(可能是他们要求的,少于或只有0),所有课程都有配额,我需要找出是否存在完美匹配(所有配额都已满,学生得到了他们允许的)-如果存在,匹配的输出。
到目前为止,我只是获取输入并将其存储在对象中。这个项目有时间限制,我不知道从哪里开始。对这个项目有什么建议或方法吗?
我认为我应该实现二分匹配算法。我是c++的新手,所以我需要同时实现节点类和边缘类吗?还是应该使用邻接列表?哪一个跑得更快?
例如,一个学生要求上编号为3、4和5的课,但他可以上2节课,所以如果存在完全匹配的可能性,算法应该给出其中的2节课。
我所设想的二分问题是这样的,但我认为这很难实现。https://i.stack.imgur.com/wtJ6o.jpg
1.student wants 3 ,4 system allows him to take 2 lessons
2.student wants 1,2,3,4 system allows him to take 3 lessons
3.student wants 1,2,3,4 system allows him to take 2 lessons
4.student wants 1,3,5 system allows him to take 2 lessons
5.student wants 2,5 system allows him to take 1 lessons
1.lesson's quota = 2
2.lesson's quota = 1
3.lesson's quota = 2
4.lesson's quota = 3
5.lesson's quota = 2
I just wrote this ,this might not be the best example.
One possible solution is = 1 -> (3,4) 2->(1,2,4) 3->(3,4) 4->(1,5) 5->(5)
Another is = 1 -> (3,4) 2->(1,2,4) 3->(1,4) 4->(3,5) 5->(5)
可能还有更多,我不知道。
(学生->课程)
由于一个学生可以被分配多个课程,我认为这个问题不能用简单的最大二分匹配算法来解决。
这个问题是一种交通问题,课程是sources
,学生是destinations
。每门课程的配额是其capacity
,每个学生的demand
是系统允许他的课程数量。
编辑:
您可以通过以下修改来制定运输问题:
拆分课程,使每节课都有一个1的引号。因此,在你的例子中,应该有10节课。成本分配如下:
Demand: 2 3 2 2 1
St1 St2 St3 St4 St5
Less1.1 5 0 0 0 5
Less1.2 5 1 1 1 5 // cost for second dummy lesson is slightly high to differentiate.
Less2.1 5 0 0 5 0
Less3.1 0 0 0 0 5
Less3.2 1 1 1 1 5
Less4.1 0 0 0 5 5
Less4.2 1 1 1 5 5
Less4.3 2 2 2 5 5
Less5.1 5 5 5 0 0
Less5.2 5 5 5 1 1
相关文章:
- 基于ELO的团队匹配算法
- C++ 回文算法 - 无法与'operator<'匹配
- OPENCV:如何使用5点算法从来自不同相机的两个图像之间的特征匹配来计算必需矩阵
- 如何实现将前缀与字符串匹配的最快算法
- 使用STL算法查找集合中的所有匹配项
- 找到多组对象的最佳匹配的算法
- 对于字符串/句子不起作用的最接近的匹配算法
- 用于多个级联字符串的同步模式匹配算法
- 我应该用什么来实现c++中的加权二分匹配算法
- DNA模式匹配中最快的算法是什么
- 提高准确性的最佳图像匹配算法
- 游戏的匹配算法
- openCV立体匹配算法(立体BM和立体SGBM)是否可以处理垂直校正图像
- 字符串匹配算法的c++实现
- 在当前给定的通用场景中,我如何正确地为Hopcroft-Carp最大匹配算法构建图
- 使用块匹配算法获取纹理点云
- 字符串匹配算法
- 字符串完成和匹配算法
- 字符串匹配算法试图纠正它
- 字符串匹配算法的大O符号