摘要:
您选择您注册的模块。
每个模块都有多个组。
每个组代表给定模块的讲座。
每个组合应该只包含来自每个模块的一个组。复杂排列/组合
实施例:
COS 121个-3组
COS 132个-2组
这会给你6个选项:[1,1],[1,2],[2,1],[我需要使用每个组合来生成时间表,因此我使用一个数组来存储正在使用的当前组和总数组数:arrSubjects[subject,currentGroup,maxGroups]
从逻辑上说,你应该能够遍历这个阵列Ÿ利用每个组的组合。
我只是无法掌握这个解决方案,也许是因为我使用了错误的角度。任何帮助/建议真的很感激。
我目前的实施: 我对此很尴尬,因为它需要很多时间,但它的工作原理。 下面是伪代码的基础:
for (all the groups multiplied with eachother) do {
for (all the modules selected) do {
Select a random group between 1 and the nmr of groups
}
}
后,我必须摆脱所有重复的。
在此先感谢
的代码我目前工作:
arrPermutations[0,0]:=1;//Current group for 1st module
arrPermutations[0,1]:=3;//Max groups for 1st module
arrPermutations[1,0]:=1;
arrPermutations[1,1]:=3;
arrPermutations[2,0]:=1;//Current group for 3rd module
arrPermutations[2,1]:=3;//Max groups for 3rd module
iCurrent:=iMax; //2
while (arrPermutations[0,0]<=arrPermutations[0,1]) do
begin
//Display arrPermutations
if arrPermutations[iCurrent,0]=arrPermutations[iCurrent,1] then
begin
Inc(arrPermutations[iCurrent-1,0]);
for i := iCurrent to iMax do
arrPermutations[i,0]:=1;
iCurrent:=iMax;
end else
begin
Inc(arrPermutations[iCurrent,0]);
end;
end;
目前,我只有通过最后两组穿越。 以下是我在检查时得到的输出:
============运行1 ==============
模块,当前组,最大组
1,1,3
2,1,3
3,1,3
============运行2 ==============
模块,当前组,最大团
1,1,3-
2,1,3
3,2,3
============运行3 ===== =========
模块,当前组,最大组
1,1,3
2,1,3
3,3,3
============运行4 ============= =
模块,当前组,最大团
1,1,3-
2,2,3-
3,1,3
============运行5 === ===========
模块,当前组,最大团
1,1,3-
2,2,3-
3,2,3
======= =====运行6 ==============
模块,当前组,最大团
1,1,3-
2,2,3-
3,3,3-
============运行7 ===== =========
模块,当前组,最大团
1,1,3-
2,3,3
3,1,3
========= ===运行8 ==============
模块,当前组,最大团
1,1,3-
2,3,3
3,2,3
============ Run 9 ==============
模块,当前组,最大组
1,1,3
2,3 ,3
3,3,3
============运行10 ============== //////问题出在这里
模块,当前组,最大团
1,1,3-
2,4,3
3,1,3
Hi C一应俱全。感谢您的快速和彻底的答复。虽然我特意寻找顺序通过排列的方式,但我希望利用每个排列而不必存储排列。请看看我更新的帖子,以获得更好的理解。 – Hendrik
好吧,它听起来像你想要某种阵列。我修改了答案,如果您只是想遍历组合而不将它们全部存储起来。 –
嗨克里斯。该算法完美运行!我非常感谢你的帮助。你给我信心更频繁地使用计算器! – Hendrik