0
我的函數遍歷多維數組並且必須滿足條件。該數組包含1和0。對於那些只能連續打印至少4個,最多9個,即允許1111或111111但不允許11或11111111111.在這些之間必須有至少12個零,例如1111000000000000111111。同樣在7套中,連續36個0。後者是我添加的約束,似乎沒有停止運行。這是一個花名冊工具,所以工作日= 7,maxconsecutivehours = 36由於我將這個函數添加到我的代碼中,它並沒有停止運行。 [VBA]
Dim i, j, m, counter1, counter2, counter3, counterA, remainder As Double
For i = 1 To UBound(posSolution, 1)
counter1 = 0
counter2 = 0
For j = 1 To UBound(posSolution, 2)
If posSolution(i, j) = 0 Then
Do Until posSolution(i, j) = 1
counter1 = counter1 + 1
Loop
counter2 = counter2 + 1
If counter1 >= maxConsecutiveHours Then
j = j + 24 * (workDays - counter2)
counter1 = 0
counter2 = 0
Else
remainder = maxConsecutiveHours - counter1
counter3 = j
Do Until posSolution(i, counter3) = 1
counter3 = counter3 - 1
Loop
Do While posSolution(i, counter3) = 1
counter3 = counter3 - 1
counterA = counterA + 1
Loop
If (counterA - remainder) >= minWorkHours Then
For m = (counter3 + counterA - remainder) To counter3 + counterA
posSolution(i, m) = 0
Next m
j = m + 24 * (workDays - counter2)
counter1 = 0
counter2 = 0
counter3 = 0
counterA = 0
End If
End If
End If
Next j
Next i
我感興趣的是理解爲什麼,因爲我加入此功能的代碼仍然在運行。