摘要:
您選擇您註冊的模塊。
每個模塊都有多個組。
每個組代表給定模塊的講座。
每個組合應該只包含來自每個模塊的一個組。複雜排列/組合
實施例:
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