From df681d08617bdd9299bc23be82e0d392820154db Mon Sep 17 00:00:00 2001 From: qinguoyi <1532979219@qq.com> Date: Thu, 8 Aug 2024 10:52:23 +0800 Subject: [PATCH] chore:clean up Signed-off-by: qinguoyi <1532979219@qq.com> --- .../core/spreadconstraint/select_groups.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/pkg/scheduler/core/spreadconstraint/select_groups.go b/pkg/scheduler/core/spreadconstraint/select_groups.go index 069d7096f..1140d6b4e 100755 --- a/pkg/scheduler/core/spreadconstraint/select_groups.go +++ b/pkg/scheduler/core/spreadconstraint/select_groups.go @@ -161,18 +161,6 @@ func findFeasiblePaths(groups []*GroupInfo, minConstraint, maxConstraint, target rootPath := new(dfsPath) var dfsFunc func(int, int) dfsFunc = func(sum, begin int) { - // directly check the sum - if len(groups) == minConstraint { - for _, group := range groups { - sum += group.value - rootPath.enqueue(group) - } - if sum >= target { - paths = append(paths, rootPath.next()) - } - return - } - if sum >= target && rootPath.length() >= minConstraint && rootPath.length() <= maxConstraint { paths = append(paths, rootPath.next()) return @@ -187,6 +175,12 @@ func findFeasiblePaths(groups []*GroupInfo, minConstraint, maxConstraint, target sum += groups[i].value rootPath.enqueue(groups[i]) dfsFunc(sum, i+1) + + // stop backtracking when we have to traverse all groups to satisfy the minimum constraint. + if len(groups) == minConstraint { + break + } + sum -= groups[i].value rootPath.popLast() }