本文介绍了好的算法/技术来寻找重叠的对象属性值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想提出一个时间表的应用程序。最重要的类是:

I am making a timetabling application. The important classes are:

Period
    id: int
    clazz: Clazz
SubjectTeacher
    subject: String
    teacher: String
    clazz: Clazz
    AllocablePeriods: List<Period>

下面是示例数据,其中,简和约翰教授在一个班,和简在另一个类中。

Here is example data, where Jane and John teach at one class, and Jane in another class.

{sub435, Jane-Algebra-Class1, {1,2,3,4,5,6,7,8}}
{sub124, Jane-Calculus-Class2, {9,10,11,12,13,14,15,16}}
{sub875, John-English-Class1, {1,2,3,4,5,6,7}} //he cannot take #8


我的目的是要检测的可以互换每个 SubjectTeacher 。例如,在上面的例子中,简代数-1级约翰 - 英语 - 1类有潜在的掉期


My objective is to detect possible swaps for each SubjectTeacher. For example, in the above example, Jane-Algebra-Class1 and John-English-Class1 have potential swaps

{1,Jane-Algebra-Class1,John-English-Class1}
{2,Jane-Algebra-Class1,John-English-Class1}
...
{7,Jane-Algebra-Class1,John-English-Class1}

什么是好的算法/技术来检测所有可能的掉期交易的所有 SubjectTeacher S'

推荐答案

我预计 AllocablePeriods 的数量相对较少。那么你可以做的是遍历所有教师,遍历所有的时间,并添加每一个这样的阶段发展到了地图绘制一个周期标识符的教师,可以在此期间教:

I would expect that the number of AllocablePeriods is relatively small. Then what you can do is iterate over all teachers, iterate over all their periods and add each such period to a Map mapping a period identifier to the teachers that can teach during this period:

Map<Integer, List<String> > periodTeachersMap = new HashMap<Integer, List<String>>();
for (Teacher teacher: teachers) {
   for (AllocablePeriod period: teacher.getPeriods()) {
       if (periodTeachersMap.get(period.getId()) == null) {
           periodTeachersMap.put(period.getId(), new ArrayList<String>());
       }
       periodTeachersMap.get(period.getId()).add(teacher.getName());
   }
}

在这个周期中,你将有 periodTeachersMap 对每个时期的所有教师可以在其任教。如果你想对自己的,你可以很容易地从列表构建它们。我希望这会帮助你。

After this cycle you will have in periodTeachersMap for every period all the teachers that can teach in it. If you want the pairs themselves you can easily construct them from the List. I hope this will help you.

这篇关于好的算法/技术来寻找重叠的对象属性值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 12:54