Forum Discussion
Patrick2788
Dec 15, 2023Silver Contributor
Solving 'The Assignment Problem' with Lambda
The Setup The problem is simple. Given a 'cost matrix', assign tasks to workers to minimize total cost needed to complete the tasks. Workers may not perform more than 1 task. Assignment p...
- Dec 19, 2023
In attached file PQ Assignment2 generates the required rows only
Though, it's slower than djclements initial approach (PQ Assignment1)
Bhavya250203
Dec 15, 2023Copper Contributor
Really Interesting Problem!! My approach is similar to yours - generate all the permutations and filter for minimum total.
=LET(
workers, Workers,
tasks, Tasks,
matrix, Costs,
nWorkers, ROWS(workers),
nTasks, COLUMNS(tasks),
s, SEQUENCE(, nTasks),
div, nWorkers ^ s,
permuta, ROUNDUP(
(MOD(SEQUENCE(MAX(div)) - 1, div) + 1) / (div / nWorkers),
),
permut, FILTER(
permuta,
BYROW(permuta, LAMBDA(x, COLUMNS(UNIQUE(x, 1)))) = nTasks
),
mat, INDEX(matrix, permut, s),
Ttl, BYROW(mat, LAMBDA(x, SUM(x))),
arr, FILTER(permut, Ttl = MIN(Ttl)),
REDUCE(
tasks,
SEQUENCE(ROWS(arr)),
LAMBDA(a, b,
VSTACK(
a,
LET(
k, CHOOSEROWS(arr, b),
VSTACK(INDEX(workers, k), INDEX(matrix, k, s))
)
)
)
)
)
- __1980Dec 18, 2023Copper ContributorExcellent
- Patrick2788Dec 15, 2023Silver ContributorThis is excellent. I like the way you generated the permutations. It's similar to a method that was discussed in the 0-1 Knapsack discussion. It's short and very elegant.
I folded your formula into 'SolveX' and it handled the larger cost matrix with ease!- Bhavya250203Dec 16, 2023Copper Contributor
Patrick2788 Thank you!! Glad to hear it worked on larger matrix.