How to minimize total sum of values in pandas dataframe under additional requirements

145 Views Asked by At

via Google Distance Matrix API I am able to caclulate all driving times in seconds between addresses of each of my personnel and each of my customers (fake data in this example). I put this into a pivoted dataframe after calculating it. So now I have on the x-axis all the customers, on the y-axis all my personnel while the driving time in seconds are the values in the cells (The data is of course also available unpivoted with customers and personnel in a column each and the driving time in another column).

Now I want to calculate the optimal allocation of my personnel to the customers, thus minimizing the seconds of driving time over all. Important requirement: Certain customers need 2, other customers need 3 personnel assigned. 1 Personnel can only ever be allocated to 1 customer tho (that is referenced in the column "Versorgung".)

I am sure there is a mathematic solution to it but I just can't figure out how to solve it. Thank you in advance.

Dataframe (unpivoted)
enter image description here

Pivoted Dataframe with seconds of driving time as values
enter image description here

0

There are 0 best solutions below