Skip to main content
. Author manuscript; available in PMC: 2020 Jul 25.
Published in final edited form as: Concurr Comput. 2019 Jun 24;32(2):e5403. doi: 10.1002/cpe.5403

Algorithm 4.

The Balance step of the TRTM

1: Input/Output: bucketList;
2: bucketList is a sorted data structure by descending cost (e.g., multiset)
3: Repeat
4:  bigRT ← firstElement(bucketList)
5:  smallRT ← lastElement(bucketList)
6:  improvement ← SingleBalance(bigRT, smalIRT)
7: if improvement ≠ ∅ then
8:   TransferSubtree(improvement, bigRT, smalIRT)
9:   update(bigRT, bucketList)
10:   update(smallRT, bucketList)
11: end if
12: until improvement ≠ ∅
13: return bucketList
4: function SingleBalance(bigRT, smallRT)
15:  improvement ← ∅
16:  imbal ← | TaskCost(bigRT) − TaskCost(smallRT) |
17: while (c ← NextDFSNode(bigRT)) ≠ ∅ and imbal ≠ 0 do
18:   newBigRT ← bigRT
19:   newSmallRT ← smallRT
20:   TransferSubtree(c, newBigRT, newSmallRT)
21:   newlmbal ← | TaskCost(newBigRT) − TaskCost(newSmallRT) |
22:   newMakespan ← max(TaskCost(newBigRT), TaskCost(newSmallRT))
23:   if newlmbal < imbal and newMakespan < TaskCost(bigRT) then
24:    improvement ← c
25:    imbal ← newlmbal
26:   end if
27: end while
28: return improvement
29: end function