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)
Lorenzo
Dec 18, 2023Silver Contributor
Looked at doing it w/o generating the unecessary rows* - that's been a disaster so far 😞
Attached is consequently djclements' approach, automated when it comes to joining tables
* > 2K with an input table of 25 rows
__1980
Dec 18, 2023Copper Contributor
=LET(
x,DROP(REDUCE(0,ROW(D6:D9),LAMBDA(a,d,VSTACK(a,LET(c,ROW(E6:E9)<>d,h,FILTER(ROW(E6:E9),c),
e,HSTACK(d,h,IF(MUNIT(3),,TOROW(h))),
v,IFNA(e,TAKE(e,1)),i,TOCOL(DROP(v,,2)),j,TAKE(v,,2),
HSTACK( SORTBY(VSTACK(j,j),MOD(SEQUENCE(ROWS(TAKE(v,,2))*2)-1,3)+1),FILTER(i,i))-5)))),1),v,INDEX(D6:F9,x,SEQUENCE(,3)),
s,BYROW(v,LAMBDA(a,SUM(a))),
VSTACK(D5:F5,INDEX(C6:C9,FILTER(x,s=MIN(s))),FILTER(v,s=MIN(s))))
x,DROP(REDUCE(0,ROW(D6:D9),LAMBDA(a,d,VSTACK(a,LET(c,ROW(E6:E9)<>d,h,FILTER(ROW(E6:E9),c),
e,HSTACK(d,h,IF(MUNIT(3),,TOROW(h))),
v,IFNA(e,TAKE(e,1)),i,TOCOL(DROP(v,,2)),j,TAKE(v,,2),
HSTACK( SORTBY(VSTACK(j,j),MOD(SEQUENCE(ROWS(TAKE(v,,2))*2)-1,3)+1),FILTER(i,i))-5)))),1),v,INDEX(D6:F9,x,SEQUENCE(,3)),
s,BYROW(v,LAMBDA(a,SUM(a))),
VSTACK(D5:F5,INDEX(C6:C9,FILTER(x,s=MIN(s))),FILTER(v,s=MIN(s))))