Skip to content

Commit

Permalink
Merge pull request #2 from CDDLeiden/fix_balancing_bug
Browse files Browse the repository at this point in the history
Fix balancing bug
  • Loading branch information
HellevdM authored Jun 4, 2024
2 parents 8d6eef1 + f3547f0 commit 54207c8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/gbmtsplits/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ def _merge_clusters_with_balancing_mapping(
# Constraints forcing each cluster to be in one and only one ML_subset
for c in range(N):
prob += LpAffineExpression([(x[c+m*N],+1) for m in range(S)]) == 1

# Constraints forcing each ML_subset to be non-empty
for m in range(S):
prob += LpAffineExpression([(x[i],+1) for i in range(m*N,(m+1)*N)]) >= 1

# If preassigned_clusters is pro[int, int]vided, add the constraints to the model to force the clusters
# to be assigned to the ML subset preassigned_clusters[t]
Expand All @@ -498,8 +502,8 @@ def _merge_clusters_with_balancing_mapping(
for m in range(S):
for t in range(M):
cs = [c for c in range(N) if A[t,c] != 0]
prob += LpAffineExpression([(x[c+m*N],A[t,c]) for c in cs]) - X[t] <= fractional_sizes[m]
prob += LpAffineExpression([(x[c+m*N],A[t,c]) for c in cs]) + X[t] >= fractional_sizes[m]
prob += LpAffineExpression([(x[c+m*N],A[t,c]) for c in cs]) - X[m*M+t] <= fractional_sizes[m]
prob += LpAffineExpression([(x[c+m*N],A[t,c]) for c in cs]) + X[m*M+t] >= fractional_sizes[m]

# Solve the model
prob.solve(PULP_CBC_CMD(gapAbs = absolute_gap, timeLimit = time_limit_seconds, threads = max_N_threads, msg=False))
Expand Down

0 comments on commit 54207c8

Please sign in to comment.